1 import { c } from 'ttag';
3 import { SYNC_G_OAUTH_SCOPES, SYNC_SUCCESS_NOTIFICATION } from '@proton/activation/src/constants';
4 import useOAuthPopup from '@proton/activation/src/hooks/useOAuthPopup';
5 import type { EASY_SWITCH_SOURCES, OAuthProps } from '@proton/activation/src/interface';
6 import { ImportProvider } from '@proton/activation/src/interface';
7 import { useEasySwitchDispatch, useEasySwitchSelector } from '@proton/activation/src/logic/store';
8 import { changeCreateLoadingState, createSyncItem } from '@proton/activation/src/logic/sync/sync.actions';
9 import { selectCreateSyncState } from '@proton/activation/src/logic/sync/sync.selectors';
10 import { Button } from '@proton/atoms';
11 import type { ModalProps } from '@proton/components/components/modalTwo/Modal';
12 import ModalTwo from '@proton/components/components/modalTwo/Modal';
13 import ModalContent from '@proton/components/components/modalTwo/ModalContent';
14 import ModalHeader from '@proton/components/components/modalTwo/ModalHeader';
16 import GmailSyncModalAnimation from './GmailSyncModalAnimation';
17 import SignInWithGoogle from './SignInWithGoogle';
19 interface Props extends ModalProps {
20 source: EASY_SWITCH_SOURCES;
21 reduceHeight?: boolean;
22 onSyncCallback?: (hasError: boolean) => void;
23 onSyncSkipCallback?: () => void;
27 const GmailSyncModal = ({ onSyncCallback, onSyncSkipCallback, source, reduceHeight, noSkip, ...rest }: Props) => {
28 const dispatch = useEasySwitchDispatch();
29 const syncState = useEasySwitchSelector(selectCreateSyncState);
30 const loading = syncState === 'pending';
32 const { triggerOAuthPopup, loadingConfig } = useOAuthPopup({
33 errorMessage: c('loc_nightly:Error').t`Your sync will not be processed.`,
36 const handleGoogleSync = () => {
38 provider: ImportProvider.GOOGLE,
39 scope: SYNC_G_OAUTH_SCOPES.join(' '),
40 callback: async (oAuthProps: OAuthProps) => {
41 const { Code, Provider, RedirectUri } = oAuthProps;
42 dispatch(changeCreateLoadingState('pending'));
43 const res = await dispatch(
49 notification: SYNC_SUCCESS_NOTIFICATION,
53 const hasError = res.type.endsWith('rejected');
57 onSyncCallback?.(hasError);
62 const handleSyncSkip = () => {
63 onSyncSkipCallback?.();
67 const handleClose = () => {
68 onSyncSkipCallback?.();
73 <ModalTwo size="xlarge" fullscreenOnMobile {...rest} onClose={handleClose}>
75 <ModalContent className="m-8 mt-0 flex flex-row items-center flex-nowrap gap-7">
76 <div className="flex flex-column flex-1 gap-7">
77 <h1 className="text-break text-4xl">
78 <strong>{c('Gmail forwarding').t`Automatically forward`}</strong>
80 <br className="lg:hidden" />
81 {c('Gmail forwarding').t`Gmail messages to your inbox`}
83 <div className="lg:hidden grow-2">
84 <GmailSyncModalAnimation reduceHeight={reduceHeight} />
86 <div className="flex flex-column items-center gap-4">
88 onClick={handleGoogleSync}
90 disabled={loadingConfig}
94 <Button shape="ghost" color="norm" fullWidth onClick={handleSyncSkip}>{c('Action')
99 <div className="hidden lg:block w-6/10">
100 <GmailSyncModalAnimation reduceHeight={reduceHeight} />
107 export default GmailSyncModal;