You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CopyMeetingLinkSection.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // @flow
  2. import React, { useState } from 'react';
  3. import { translate } from '../../../../base/i18n';
  4. import { Icon, IconCheck, IconCopy } from '../../../../base/icons';
  5. import { copyText } from './utils';
  6. type Props = {
  7. /**
  8. * Invoked to obtain translated strings.
  9. */
  10. t: Function,
  11. /**
  12. * The URL of the conference.
  13. */
  14. url: string
  15. };
  16. /**
  17. * Component meant to enable users to copy the conference URL.
  18. *
  19. * @returns {React$Element<any>}
  20. */
  21. function CopyMeetingLinkSection({ t, url }: Props) {
  22. const [ isClicked, setIsClicked ] = useState(false);
  23. const [ isHovered, setIsHovered ] = useState(false);
  24. /**
  25. * Click handler for the element.
  26. *
  27. * @returns {void}
  28. */
  29. function onClick() {
  30. setIsHovered(false);
  31. if (copyText(url)) {
  32. setIsClicked(true);
  33. setTimeout(() => {
  34. setIsClicked(false);
  35. }, 2500);
  36. }
  37. }
  38. /**
  39. * Hover handler for the element.
  40. *
  41. * @returns {void}
  42. */
  43. function onHoverIn() {
  44. if (!isClicked) {
  45. setIsHovered(true);
  46. }
  47. }
  48. /**
  49. * Hover handler for the element.
  50. *
  51. * @returns {void}
  52. */
  53. function onHoverOut() {
  54. setIsHovered(false);
  55. }
  56. /**
  57. * Renders the content of the link based on the state.
  58. *
  59. * @returns {React$Element<any>}
  60. */
  61. function renderLinkContent() {
  62. if (isClicked) {
  63. return (
  64. <>
  65. <div className = 'invite-more-dialog copy-link-text selected'>
  66. {t('addPeople.linkCopied')}
  67. </div>
  68. <Icon src = { IconCheck } />
  69. </>
  70. );
  71. }
  72. const displayUrl = decodeURI(url.replace(/^https?:\/\//i, ''));
  73. return (
  74. <>
  75. <div className = 'invite-more-dialog invite-more-dialog-conference-url copy-link-text'>
  76. {isHovered ? t('addPeople.copyLink') : displayUrl}
  77. </div>
  78. <Icon src = { IconCopy } />
  79. </>
  80. );
  81. }
  82. return (
  83. <>
  84. <span>{t('addPeople.shareLink')}</span>
  85. <div
  86. className = { `invite-more-dialog copy-link${isClicked ? ' clicked' : ''}` }
  87. onClick = { onClick }
  88. onMouseOut = { onHoverOut }
  89. onMouseOver = { onHoverIn }>
  90. { renderLinkContent() }
  91. </div>
  92. </>
  93. );
  94. }
  95. export default translate(CopyMeetingLinkSection);