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.

InviteByEmailSection.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // @flow
  2. import Tooltip from '@atlaskit/tooltip';
  3. import React, { useState } from 'react';
  4. import { translate } from '../../../../base/i18n';
  5. import {
  6. Icon,
  7. IconArrowDownSmall,
  8. IconCopy,
  9. IconEmail,
  10. IconGoogle,
  11. IconOutlook,
  12. IconYahoo
  13. } from '../../../../base/icons';
  14. import { copyText, openURLInBrowser } from '../../../../base/util';
  15. type Props = {
  16. /**
  17. * The encoded invitation subject.
  18. */
  19. inviteSubject: string,
  20. /**
  21. * The encoded invitation text to be sent.
  22. */
  23. inviteText: string,
  24. /**
  25. * Invoked to obtain translated strings.
  26. */
  27. t: Function,
  28. };
  29. /**
  30. * Component that renders email invite options.
  31. *
  32. * @returns {React$Element<any>}
  33. */
  34. function InviteByEmailSection({ inviteSubject, inviteText, t }: Props) {
  35. const [ isActive, setIsActive ] = useState(false);
  36. const encodedInviteSubject = encodeURIComponent(inviteSubject);
  37. const encodedInviteText = encodeURIComponent(inviteText);
  38. /**
  39. * Copies the conference invitation to the clipboard.
  40. *
  41. * @returns {void}
  42. */
  43. function _onCopyText() {
  44. copyText(inviteText);
  45. }
  46. /**
  47. * Opens an email provider containing the conference invite.
  48. *
  49. * @param {string} url - The url to be opened.
  50. * @returns {Function}
  51. */
  52. function _onSelectProvider(url) {
  53. return function() {
  54. openURLInBrowser(url, true);
  55. };
  56. }
  57. /**
  58. * Toggles the email invite drawer.
  59. *
  60. * @returns {void}
  61. */
  62. function _onToggleActiveState() {
  63. setIsActive(!isActive);
  64. }
  65. /**
  66. * Renders clickable elements that each open an email client
  67. * containing a conference invite.
  68. *
  69. * @returns {React$Element<any>}
  70. */
  71. function renderEmailIcons() {
  72. const PROVIDER_MAPPING = [
  73. {
  74. icon: IconEmail,
  75. tooltipKey: 'addPeople.defaultEmail',
  76. url: `mailto:?subject=${encodedInviteSubject}&body=${encodedInviteText}`
  77. },
  78. {
  79. icon: IconGoogle,
  80. tooltipKey: 'addPeople.googleEmail',
  81. url: `https://mail.google.com/mail/?view=cm&fs=1&su=${encodedInviteSubject}&body=${encodedInviteText}`
  82. },
  83. {
  84. icon: IconOutlook,
  85. tooltipKey: 'addPeople.outlookEmail',
  86. // eslint-disable-next-line max-len
  87. url: `https://outlook.office.com/mail/deeplink/compose?subject=${encodedInviteSubject}&body=${encodedInviteText}`
  88. },
  89. {
  90. icon: IconYahoo,
  91. tooltipKey: 'addPeople.yahooEmail',
  92. url: `https://compose.mail.yahoo.com/?To=&Subj=${encodedInviteSubject}&Body=${encodedInviteText}`
  93. }
  94. ];
  95. return (
  96. <>
  97. {
  98. PROVIDER_MAPPING.map(({ icon, tooltipKey, url }, idx) => (
  99. <Tooltip
  100. content = { t(tooltipKey) }
  101. key = { idx }
  102. position = 'top'>
  103. <div
  104. onClick = { _onSelectProvider(url) }>
  105. <Icon src = { icon } />
  106. </div>
  107. </Tooltip>
  108. ))
  109. }
  110. </>
  111. );
  112. }
  113. return (
  114. <>
  115. <div>
  116. <div
  117. className = { `invite-more-dialog email-container${isActive ? ' active' : ''}` }
  118. onClick = { _onToggleActiveState }>
  119. <span>{t('addPeople.shareInvite')}</span>
  120. <Icon src = { IconArrowDownSmall } />
  121. </div>
  122. <div className = { `invite-more-dialog icon-container${isActive ? ' active' : ''}` }>
  123. <Tooltip
  124. content = { t('addPeople.copyInvite') }
  125. position = 'top'>
  126. <div
  127. className = 'copy-invite-icon'
  128. onClick = { _onCopyText }>
  129. <Icon src = { IconCopy } />
  130. </div>
  131. </Tooltip>
  132. {renderEmailIcons()}
  133. </div>
  134. </div>
  135. </>
  136. );
  137. }
  138. export default translate(InviteByEmailSection);