Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

InviteByEmailSection.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // @flow
  2. import React, { useState } from 'react';
  3. import { translate } from '../../../../base/i18n';
  4. import {
  5. Icon,
  6. IconArrowDownSmall,
  7. IconCopy,
  8. IconEmail,
  9. IconGoogle,
  10. IconOutlook,
  11. IconYahoo
  12. } from '../../../../base/icons';
  13. import { Tooltip } from '../../../../base/tooltip';
  14. import { copyText } 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. * Toggles the email invite drawer.
  48. *
  49. * @returns {void}
  50. */
  51. function _onToggleActiveState() {
  52. setIsActive(!isActive);
  53. }
  54. /**
  55. * Renders clickable elements that each open an email client
  56. * containing a conference invite.
  57. *
  58. * @returns {React$Element<any>}
  59. */
  60. function renderEmailIcons() {
  61. const PROVIDER_MAPPING = [
  62. {
  63. icon: IconEmail,
  64. tooltipKey: 'addPeople.defaultEmail',
  65. url: `mailto:?subject=${encodedInviteSubject}&body=${encodedInviteText}`
  66. },
  67. {
  68. icon: IconGoogle,
  69. tooltipKey: 'addPeople.googleEmail',
  70. url: `https://mail.google.com/mail/?view=cm&fs=1&su=${encodedInviteSubject}&body=${encodedInviteText}`
  71. },
  72. {
  73. icon: IconOutlook,
  74. tooltipKey: 'addPeople.outlookEmail',
  75. // eslint-disable-next-line max-len
  76. url: `https://outlook.office.com/mail/deeplink/compose?subject=${encodedInviteSubject}&body=${encodedInviteText}`
  77. },
  78. {
  79. icon: IconYahoo,
  80. tooltipKey: 'addPeople.yahooEmail',
  81. url: `https://compose.mail.yahoo.com/?To=&Subj=${encodedInviteSubject}&Body=${encodedInviteText}`
  82. }
  83. ];
  84. return (
  85. <>
  86. {
  87. PROVIDER_MAPPING.map(({ icon, tooltipKey, url }, idx) => (
  88. <Tooltip
  89. content = { t(tooltipKey) }
  90. key = { idx }
  91. position = 'top'>
  92. <a
  93. className = 'provider-icon'
  94. href = { url }
  95. rel = 'noopener noreferrer'
  96. target = '_blank'>
  97. <Icon src = { icon } />
  98. </a>
  99. </Tooltip>
  100. ))
  101. }
  102. </>
  103. );
  104. }
  105. return (
  106. <>
  107. <div>
  108. <div
  109. className = { `invite-more-dialog email-container${isActive ? ' active' : ''}` }
  110. onClick = { _onToggleActiveState }>
  111. <span>{t('addPeople.shareInvite')}</span>
  112. <Icon src = { IconArrowDownSmall } />
  113. </div>
  114. <div className = { `invite-more-dialog icon-container${isActive ? ' active' : ''}` }>
  115. <Tooltip
  116. content = { t('addPeople.copyInvite') }
  117. position = 'top'>
  118. <div
  119. className = 'copy-invite-icon'
  120. onClick = { _onCopyText }>
  121. <Icon src = { IconCopy } />
  122. </div>
  123. </Tooltip>
  124. {renderEmailIcons()}
  125. </div>
  126. </div>
  127. </>
  128. );
  129. }
  130. export default translate(InviteByEmailSection);