-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogInModal.tsx
More file actions
141 lines (126 loc) · 4.15 KB
/
Copy pathLogInModal.tsx
File metadata and controls
141 lines (126 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { useRouter } from 'next/router';
import { signOut, useSession } from 'next-auth/react';
import { FC, useContext } from 'react';
import { TRouter } from '@uxcore/local-types/global';
import { setRedirectCookie } from '@uxcore/lib/cookies';
import decisionTable from '@uxcore/data/decisionTable';
import DiscordIcon from '@uxcore/assets/icons/DiscordIcon';
import GoogleIcon from '@uxcore/assets/icons/GoogleIcon';
import LinkedInIcon from '@uxcore/assets/icons/LinkedInIcon';
import MailRuIcon from '@uxcore/assets/icons/MailRuIcon';
import XIcon from '@uxcore/assets/icons/XIcon';
import YandexIcon from '@uxcore/assets/icons/YandexIcon';
import Button from '@uxcore/components/Button';
import { GlobalContext } from '@uxcore/components/Context/GlobalContext';
import MagicLinkEmailForm from '@uxcore/components/LogIn/MagicLinkEmailForm';
import Modal from '@uxcore/components/Modal';
import {
handleMixpanelSignUp,
trackLogInSource,
} from '@uxcore/lib/mixpanel';
import styles from './LogInModal.module.scss';
type LoginModalProps = {
setShowModal: (showModal: boolean) => void;
source?: string;
};
const LogInModal: FC<LoginModalProps> = ({ setShowModal, source }) => {
const { locale } = useRouter() as TRouter;
const { accountData } = useContext(GlobalContext);
const router = useRouter();
const isProduction = process.env.NEXT_PUBLIC_ENV === 'prod';
const { data: session } = useSession();
const {
singInWithGoogle,
signInWithLinkedIn,
signInWithDiscord,
signInWithTwitter,
signInWithMailRu,
signInWithYandex,
loginText,
cancelBtn,
login,
} = decisionTable[locale];
const handleClose = () => {
setShowModal(false);
};
const handleProviderSignIn = async (
provider: string,
logInSource: string,
) => {
const returnTo = router.asPath;
setRedirectCookie(returnTo);
if (session && accountData === null) {
await signOut({ redirect: false });
localStorage.removeItem('accessToken');
localStorage.removeItem('provider');
sessionStorage.clear();
router.replace(`/auth?provider=${provider}`);
handleMixpanelSignUp(provider);
trackLogInSource(logInSource);
return;
}
router.push(`/auth?provider=${provider}`);
handleMixpanelSignUp(provider);
trackLogInSource(logInSource);
};
return (
<Modal
onClick={handleClose}
wrapperClassName={styles.loginWrapper}
bodyClassName={styles.loginBody}
dataCy={'login-modal'}
>
<div className={styles.contentWrapper}>
<h1 className={styles.title}>{login}</h1>
<span className={styles.description}>{loginText}</span>
<div className={styles.buttonWrapper}>
<a
onClick={() => handleProviderSignIn('google', source)}
className={styles.link}
>
<GoogleIcon /> <span>{singInWithGoogle}</span>
</a>
{!isProduction && (
<a
onClick={() => handleProviderSignIn('linkedin', source)}
className={styles.link}
>
<LinkedInIcon /> <span>{signInWithLinkedIn}</span>
</a>
)}
<a
onClick={() => handleProviderSignIn('discord', source)}
className={styles.link}
>
<DiscordIcon /> <span>{signInWithDiscord}</span>
</a>
<a
onClick={() => handleProviderSignIn('twitter', source)}
className={styles.link}
>
<XIcon /> <span>{signInWithTwitter}</span>
</a>
<a
onClick={() => handleProviderSignIn('mailru', source)}
className={styles.link}
>
<MailRuIcon /> <span>{signInWithMailRu}</span>
</a>
<a
onClick={() => handleProviderSignIn('yandex', source)}
className={styles.link}
>
<YandexIcon /> <span>{signInWithYandex}</span>
</a>
<MagicLinkEmailForm />
<Button
label={cancelBtn}
onClick={handleClose}
className={styles.cancelBtn}
/>
</div>
</div>
</Modal>
);
};
export default LogInModal;