您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InviteByEmailSection.js 4.4KB

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