InviteesTable.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React, { createRef, PureComponent } from 'react';
  2. import { Invitee } from 'app/types';
  3. export interface Props {
  4. invitees: Invitee[];
  5. revokeInvite: (code: string) => void;
  6. }
  7. export default class InviteesTable extends PureComponent<Props> {
  8. private copyUrlRef = createRef<HTMLTextAreaElement>();
  9. copyToClipboard = () => {
  10. const node = this.copyUrlRef.current;
  11. if (node) {
  12. node.select();
  13. document.execCommand('copy');
  14. }
  15. };
  16. render() {
  17. const { invitees, revokeInvite } = this.props;
  18. return (
  19. <table className="filter-table form-inline">
  20. <thead>
  21. <tr>
  22. <th>Email</th>
  23. <th>Name</th>
  24. <th />
  25. <th style={{ width: '34px' }} />
  26. </tr>
  27. </thead>
  28. <tbody>
  29. {invitees.map((invitee, index) => {
  30. return (
  31. <tr key={`${invitee.id}-${index}`}>
  32. <td>{invitee.email}</td>
  33. <td>{invitee.name}</td>
  34. <td className="text-right">
  35. <button className="btn btn-inverse btn-mini" onClick={this.copyToClipboard}>
  36. <textarea
  37. readOnly={true}
  38. value={invitee.url}
  39. style={{ position: 'absolute', right: -1000 }}
  40. ref={this.copyUrlRef}
  41. />
  42. <i className="fa fa-clipboard" /> Copy Invite
  43. </button>
  44. &nbsp;
  45. </td>
  46. <td>
  47. <button className="btn btn-danger btn-mini" onClick={() => revokeInvite(invitee.code)}>
  48. <i className="fa fa-remove" />
  49. </button>
  50. </td>
  51. </tr>
  52. );
  53. })}
  54. </tbody>
  55. </table>
  56. );
  57. }
  58. }