InviteeRow.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React, { createRef, PureComponent } from 'react';
  2. import { connect } from 'react-redux';
  3. import { Invitee } from 'app/types';
  4. import { revokeInvite } from './state/actions';
  5. export interface Props {
  6. invitee: Invitee;
  7. revokeInvite: typeof revokeInvite;
  8. }
  9. class InviteeRow extends PureComponent<Props> {
  10. private copyUrlRef = createRef<HTMLTextAreaElement>();
  11. copyToClipboard = () => {
  12. const node = this.copyUrlRef.current;
  13. if (node) {
  14. node.select();
  15. document.execCommand('copy');
  16. }
  17. };
  18. render() {
  19. const { invitee, revokeInvite } = this.props;
  20. return (
  21. <tr>
  22. <td>{invitee.email}</td>
  23. <td>{invitee.name}</td>
  24. <td className="text-right">
  25. <button className="btn btn-inverse btn-small" onClick={this.copyToClipboard}>
  26. <textarea
  27. readOnly={true}
  28. value={invitee.url}
  29. style={{ position: 'absolute', right: -1000 }}
  30. ref={this.copyUrlRef}
  31. />
  32. Copy Invite
  33. </button>
  34. &nbsp;
  35. </td>
  36. <td>
  37. <button className="btn btn-danger btn-small" onClick={() => revokeInvite(invitee.code)}>
  38. <i className="fa fa-remove" />
  39. </button>
  40. </td>
  41. </tr>
  42. );
  43. }
  44. }
  45. const mapDispatchToProps = {
  46. revokeInvite,
  47. };
  48. export default connect(
  49. () => {
  50. return {};
  51. },
  52. mapDispatchToProps
  53. )(InviteeRow);