2022-10-31 07:56:26 +00:00
|
|
|
import { Theme } from '@mui/material';
|
|
|
|
import React from 'react';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2020-04-01 07:47:51 +00:00
|
|
|
|
2021-07-15 13:12:06 +00:00
|
|
|
import { isIosMobileBrowser } from '../../../../base/environment/utils';
|
2022-10-31 07:56:26 +00:00
|
|
|
import Icon from '../../../../base/icons/components/Icon';
|
2020-04-01 07:47:51 +00:00
|
|
|
import {
|
|
|
|
IconCopy,
|
2022-10-31 07:56:26 +00:00
|
|
|
IconEnvelope,
|
2020-04-01 07:47:51 +00:00
|
|
|
IconGoogle,
|
2022-10-31 07:56:26 +00:00
|
|
|
IconOffice365,
|
2020-04-01 07:47:51 +00:00
|
|
|
IconYahoo
|
2022-10-31 07:56:26 +00:00
|
|
|
} from '../../../../base/icons/svg';
|
|
|
|
// eslint-disable-next-line lines-around-comment
|
|
|
|
// @ts-ignore
|
2021-02-04 13:24:25 +00:00
|
|
|
import { Tooltip } from '../../../../base/tooltip';
|
2022-10-06 08:11:06 +00:00
|
|
|
import { copyText } from '../../../../base/util/copyText.web';
|
2020-04-01 07:47:51 +00:00
|
|
|
|
2022-10-31 07:56:26 +00:00
|
|
|
interface IProps {
|
2020-04-01 07:47:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The encoded invitation subject.
|
|
|
|
*/
|
2022-10-31 07:56:26 +00:00
|
|
|
inviteSubject: string;
|
2020-04-01 07:47:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The encoded invitation text to be sent.
|
|
|
|
*/
|
2022-10-31 07:56:26 +00:00
|
|
|
inviteText: string;
|
2020-04-01 07:47:51 +00:00
|
|
|
|
2021-07-15 13:12:06 +00:00
|
|
|
/**
|
|
|
|
* The encoded no new-lines iOS invitation text to be sent on default mail.
|
|
|
|
*/
|
2022-10-31 07:56:26 +00:00
|
|
|
inviteTextiOS: string;
|
|
|
|
}
|
2021-07-15 13:12:06 +00:00
|
|
|
|
2022-10-31 07:56:26 +00:00
|
|
|
const useStyles = makeStyles()((theme: Theme) => {
|
|
|
|
return {
|
|
|
|
container: {
|
|
|
|
marginTop: theme.spacing(4)
|
|
|
|
},
|
|
|
|
|
|
|
|
label: {
|
|
|
|
marginBottom: theme.spacing(2)
|
|
|
|
},
|
|
|
|
|
|
|
|
iconRow: {
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'space-between'
|
|
|
|
},
|
|
|
|
|
|
|
|
iconContainer: {
|
|
|
|
display: 'block',
|
|
|
|
padding: theme.spacing(2),
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
|
|
|
'& svg>path': {
|
|
|
|
fill: theme.palette.icon01
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2020-04-01 07:47:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that renders email invite options.
|
|
|
|
*
|
2022-10-31 07:56:26 +00:00
|
|
|
* @returns {ReactNode}
|
2020-04-01 07:47:51 +00:00
|
|
|
*/
|
2022-10-31 07:56:26 +00:00
|
|
|
function InviteByEmailSection({ inviteSubject, inviteText, inviteTextiOS }: IProps) {
|
|
|
|
const { classes } = useStyles();
|
|
|
|
const { t } = useTranslation();
|
2020-04-01 07:47:51 +00:00
|
|
|
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}
|
|
|
|
*/
|
2022-10-31 07:56:26 +00:00
|
|
|
function _onCopyTextKeyPress(e: React.KeyboardEvent) {
|
2021-06-10 12:48:44 +00:00
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
copyText(inviteText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 07:47:51 +00:00
|
|
|
/**
|
|
|
|
* Renders clickable elements that each open an email client
|
|
|
|
* containing a conference invite.
|
|
|
|
*
|
2022-10-31 07:56:26 +00:00
|
|
|
* @returns {ReactNode}
|
2020-04-01 07:47:51 +00:00
|
|
|
*/
|
|
|
|
function renderEmailIcons() {
|
|
|
|
const PROVIDER_MAPPING = [
|
|
|
|
{
|
2022-10-31 07:56:26 +00:00
|
|
|
icon: IconEnvelope,
|
2020-04-01 07:47:51 +00:00
|
|
|
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}`
|
|
|
|
},
|
|
|
|
{
|
2022-10-31 07:56:26 +00:00
|
|
|
icon: IconOffice365,
|
2020-04-01 07:47:51 +00:00
|
|
|
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) }
|
2022-10-31 07:56:26 +00:00
|
|
|
className = { classes.iconContainer }
|
2021-04-15 10:52:11 +00:00
|
|
|
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 (
|
|
|
|
<>
|
2022-10-31 07:56:26 +00:00
|
|
|
<div className = { classes.container }>
|
|
|
|
<p className = { classes.label }>{t('addPeople.shareInvite')}</p>
|
|
|
|
<div className = { classes.iconRow }>
|
2020-04-01 07:47:51 +00:00
|
|
|
<Tooltip
|
|
|
|
content = { t('addPeople.copyInvite') }
|
|
|
|
position = 'top'>
|
|
|
|
<div
|
2021-06-10 12:48:44 +00:00
|
|
|
aria-label = { t('addPeople.copyInvite') }
|
2022-10-31 07:56:26 +00:00
|
|
|
className = { classes.iconContainer }
|
|
|
|
// eslint-disable-next-line react/jsx-no-bind
|
2021-06-10 12:48:44 +00:00
|
|
|
onClick = { _onCopyText }
|
2022-10-31 07:56:26 +00:00
|
|
|
// eslint-disable-next-line react/jsx-no-bind
|
2021-06-10 12:48:44 +00:00
|
|
|
onKeyPress = { _onCopyTextKeyPress }
|
|
|
|
role = 'button'
|
|
|
|
tabIndex = { 0 }>
|
2020-04-01 07:47:51 +00:00
|
|
|
<Icon src = { IconCopy } />
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
{renderEmailIcons()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-31 07:56:26 +00:00
|
|
|
export default InviteByEmailSection;
|