2020-04-01 07:47:51 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
/* eslint-disable react/jsx-no-bind */
|
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
import React, { useState } from 'react';
|
2020-04-01 07:47:51 +00:00
|
|
|
|
2021-07-15 13:12:06 +00:00
|
|
|
import { isIosMobileBrowser } from '../../../../base/environment/utils';
|
2020-04-01 07:47:51 +00:00
|
|
|
import { translate } from '../../../../base/i18n';
|
|
|
|
import {
|
|
|
|
Icon,
|
|
|
|
IconArrowDownSmall,
|
|
|
|
IconCopy,
|
|
|
|
IconEmail,
|
|
|
|
IconGoogle,
|
|
|
|
IconOutlook,
|
|
|
|
IconYahoo
|
|
|
|
} from '../../../../base/icons';
|
2021-02-04 13:24:25 +00:00
|
|
|
import { Tooltip } from '../../../../base/tooltip';
|
2021-04-15 10:52:11 +00:00
|
|
|
import { copyText } from '../../../../base/util';
|
2020-04-01 07:47:51 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The encoded invitation subject.
|
|
|
|
*/
|
|
|
|
inviteSubject: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The encoded invitation text to be sent.
|
|
|
|
*/
|
|
|
|
inviteText: string,
|
|
|
|
|
2021-07-15 13:12:06 +00:00
|
|
|
/**
|
|
|
|
* The encoded no new-lines iOS invitation text to be sent on default mail.
|
|
|
|
*/
|
|
|
|
inviteTextiOS: string,
|
|
|
|
|
2020-04-01 07:47:51 +00:00
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that renders email invite options.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
2021-07-15 13:12:06 +00:00
|
|
|
function InviteByEmailSection({ inviteSubject, inviteText, inviteTextiOS, t }: Props) {
|
2020-04-01 07:47:51 +00:00
|
|
|
const [ isActive, setIsActive ] = useState(false);
|
|
|
|
const encodedInviteSubject = encodeURIComponent(inviteSubject);
|
|
|
|
const encodedInviteText = encodeURIComponent(inviteText);
|
2021-07-15 13:12:06 +00:00
|
|
|
const encodedInviteTextiOS = encodeURIComponent(inviteTextiOS);
|
|
|
|
|
|
|
|
const encodedDefaultEmailText = isIosMobileBrowser() ? encodedInviteTextiOS : encodedInviteText;
|
2020-04-01 07:47:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies the conference invitation to the clipboard.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _onCopyText() {
|
|
|
|
copyText(inviteText);
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
/**
|
|
|
|
* Copies the conference invitation to the clipboard.
|
|
|
|
*
|
|
|
|
* @param {Object} e - The key event to handle.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _onCopyTextKeyPress(e) {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
copyText(inviteText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 07:47:51 +00:00
|
|
|
/**
|
|
|
|
* Toggles the email invite drawer.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _onToggleActiveState() {
|
|
|
|
setIsActive(!isActive);
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
/**
|
|
|
|
* Toggles the email invite drawer.
|
|
|
|
*
|
|
|
|
* @param {Object} e - The key event to handle.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _onToggleActiveStateKeyPress(e) {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
setIsActive(!isActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 07:47:51 +00:00
|
|
|
/**
|
|
|
|
* Renders clickable elements that each open an email client
|
|
|
|
* containing a conference invite.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
|
|
|
function renderEmailIcons() {
|
|
|
|
const PROVIDER_MAPPING = [
|
|
|
|
{
|
|
|
|
icon: IconEmail,
|
|
|
|
tooltipKey: 'addPeople.defaultEmail',
|
2021-07-15 13:12:06 +00:00
|
|
|
url: `mailto:?subject=${encodedInviteSubject}&body=${encodedDefaultEmailText}`
|
2020-04-01 07:47:51 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: IconGoogle,
|
|
|
|
tooltipKey: 'addPeople.googleEmail',
|
|
|
|
url: `https://mail.google.com/mail/?view=cm&fs=1&su=${encodedInviteSubject}&body=${encodedInviteText}`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: IconOutlook,
|
|
|
|
tooltipKey: 'addPeople.outlookEmail',
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
url: `https://outlook.office.com/mail/deeplink/compose?subject=${encodedInviteSubject}&body=${encodedInviteText}`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: IconYahoo,
|
|
|
|
tooltipKey: 'addPeople.yahooEmail',
|
|
|
|
url: `https://compose.mail.yahoo.com/?To=&Subj=${encodedInviteSubject}&Body=${encodedInviteText}`
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{
|
|
|
|
PROVIDER_MAPPING.map(({ icon, tooltipKey, url }, idx) => (
|
|
|
|
<Tooltip
|
|
|
|
content = { t(tooltipKey) }
|
|
|
|
key = { idx }
|
|
|
|
position = 'top'>
|
2021-04-15 10:52:11 +00:00
|
|
|
<a
|
2021-06-10 12:48:44 +00:00
|
|
|
aria-label = { t(tooltipKey) }
|
2021-04-15 10:52:11 +00:00
|
|
|
className = 'provider-icon'
|
|
|
|
href = { url }
|
|
|
|
rel = 'noopener noreferrer'
|
|
|
|
target = '_blank'>
|
2020-04-01 07:47:51 +00:00
|
|
|
<Icon src = { icon } />
|
2021-04-15 10:52:11 +00:00
|
|
|
</a>
|
2020-04-01 07:47:51 +00:00
|
|
|
</Tooltip>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<div
|
2021-06-10 12:48:44 +00:00
|
|
|
aria-expanded = { isActive }
|
|
|
|
aria-label = { t('addPeople.shareInvite') }
|
2020-04-01 07:47:51 +00:00
|
|
|
className = { `invite-more-dialog email-container${isActive ? ' active' : ''}` }
|
2021-06-10 12:48:44 +00:00
|
|
|
onClick = { _onToggleActiveState }
|
|
|
|
onKeyPress = { _onToggleActiveStateKeyPress }
|
|
|
|
role = 'button'
|
|
|
|
tabIndex = { 0 }>
|
2020-04-01 07:47:51 +00:00
|
|
|
<span>{t('addPeople.shareInvite')}</span>
|
|
|
|
<Icon src = { IconArrowDownSmall } />
|
|
|
|
</div>
|
|
|
|
<div className = { `invite-more-dialog icon-container${isActive ? ' active' : ''}` }>
|
|
|
|
<Tooltip
|
|
|
|
content = { t('addPeople.copyInvite') }
|
|
|
|
position = 'top'>
|
|
|
|
<div
|
2021-06-10 12:48:44 +00:00
|
|
|
aria-label = { t('addPeople.copyInvite') }
|
2020-04-01 07:47:51 +00:00
|
|
|
className = 'copy-invite-icon'
|
2021-06-10 12:48:44 +00:00
|
|
|
onClick = { _onCopyText }
|
|
|
|
onKeyPress = { _onCopyTextKeyPress }
|
|
|
|
role = 'button'
|
|
|
|
tabIndex = { 0 }>
|
2020-04-01 07:47:51 +00:00
|
|
|
<Icon src = { IconCopy } />
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
{renderEmailIcons()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(InviteByEmailSection);
|