1 import { c } from 'ttag';
3 import { useUser } from '@proton/account/user/hooks';
4 import { NewUpsellModal, useUpsellConfig } from '@proton/components';
5 import useModalState from '@proton/components/components/modalTwo/useModalState';
6 import Toggle from '@proton/components/components/toggle/Toggle';
7 import UpsellModal from '@proton/components/components/upsell/modal/UpsellModal';
8 import useOneDollarConfig from '@proton/components/components/upsell/useOneDollarPromo';
9 import useApi from '@proton/components/hooks/useApi';
10 import useEventManager from '@proton/components/hooks/useEventManager';
11 import useNotifications from '@proton/components/hooks/useNotifications';
12 import useToggle from '@proton/components/hooks/useToggle';
13 import { useLoading } from '@proton/hooks';
14 import { updatePMSignature } from '@proton/shared/lib/api/mailSettings';
15 import { APP_UPSELL_REF_PATH, MAIL_APP_NAME, MAIL_UPSELL_PATHS, UPSELL_COMPONENT } from '@proton/shared/lib/constants';
16 import { getUpsellRef, useNewUpsellModalVariant } from '@proton/shared/lib/helpers/upsell';
17 import type { MailSettings, UserSettings } from '@proton/shared/lib/interfaces';
18 import { getProtonMailSignature } from '@proton/shared/lib/mail/signature';
19 import signatureImg from '@proton/styles/assets/img/illustrations/new-upsells-img/tools.svg';
23 mailSettings?: Partial<MailSettings>;
24 userSettings?: Partial<UserSettings>;
27 const PMSignature = ({ id, mailSettings = {}, userSettings = {} }: Props) => {
28 const { call } = useEventManager();
29 const { createNotification } = useNotifications();
31 const [loading, withLoading] = useLoading();
32 const { state, toggle } = useToggle(!!mailSettings.PMSignature);
33 const [user] = useUser();
35 const hasPaidMail = user.hasPaidMail;
37 const upsellRef = getUpsellRef({
38 app: APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH,
39 component: UPSELL_COMPONENT.MODAL,
40 feature: MAIL_UPSELL_PATHS.MAIL_FOOTER,
44 const [upsellModalProps, handleUpsellModalDisplay, renderUpsellModal] = useModalState();
46 const handleChange = async (checked: number) => {
47 await api(updatePMSignature(checked));
50 createNotification({ text: c('Success').t`Preference saved` });
53 const oneDollarConfig = useOneDollarConfig();
54 const upsellConfig = useUpsellConfig({ upsellRef, ...oneDollarConfig });
56 const displayNewUpsellModalsVariant = useNewUpsellModalVariant();
58 const modal = displayNewUpsellModalsVariant ? (
60 titleModal={c('Title').t`Personalize your email footer`}
61 description={c('Description').t`Make your email footer your own — showcase your unique brand, not ours.`}
62 modalProps={upsellModalProps}
63 illustration={signatureImg}
64 sourceEvent="BUTTON_MAIL_FOOTER"
69 title={c('Title').t`Personalise your e-mail footer`}
70 description={c('Description')
71 .t`To remove the ${MAIL_APP_NAME} footer, upgrade and unlock even more premium features.`}
72 modalProps={upsellModalProps}
73 sourceEvent="BUTTON_MAIL_FOOTER"
75 'unlimited-folders-and-labels',
76 'search-message-content',
78 'more-email-addresses',
79 'custom-email-domains',
86 <div className="flex flex-1">
88 className="border-container flex-1 pr-4 py-2 mb-4"
89 // eslint-disable-next-line react/no-danger
90 dangerouslySetInnerHTML={{
91 __html: getProtonMailSignature({
92 isReferralProgramLinkEnabled: !!mailSettings.PMSignatureReferralLink,
93 referralProgramUserLink: userSettings.Referral?.Link,
97 <div className="ml-0 md:ml-2 pt-2" data-testid="settings:identity-section:signature-toggle">
102 onChange={({ target }) => {
104 withLoading(handleChange(+target.checked));
106 handleUpsellModalDisplay(true);
112 {renderUpsellModal && modal}
117 export default PMSignature;