-
Notifications
You must be signed in to change notification settings - Fork 106
/
VerificationPage.tsx
350 lines (328 loc) · 9.87 KB
/
VerificationPage.tsx
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
import { useCallback, useState } from 'react'
import {
ID,
Name,
ProfilePictureSizes,
SquareSizes,
Status,
BooleanKeys,
InstagramProfile,
TwitterProfile,
TikTokProfile
} from '@audius/common'
import {
Button,
ButtonSize,
ButtonType,
IconNote,
IconValidationX
} from '@audius/stems'
import cn from 'classnames'
import { useRecord, make, TrackEvent } from 'common/store/analytics/actions'
import DynamicImage from 'components/dynamic-image/DynamicImage'
import { InstagramAuthButton } from 'components/instagram-auth/InstagramAuthButton'
import LoadingSpinner from 'components/loading-spinner/LoadingSpinner'
import Page from 'components/page/Page'
import { TikTokAuthButton } from 'components/tiktok-auth/TikTokAuthButton'
import { TwitterAuthButton } from 'components/twitter-auth/TwitterAuthButton'
import UserBadges from 'components/user-badges/UserBadges'
import { useRemoteVar } from 'hooks/useRemoteConfig'
import { useUserProfilePicture } from 'hooks/useUserProfilePicture'
import { profilePage } from 'utils/route'
import { SettingsPageProps } from './SettingsPage'
import settingsPageStyles from './SettingsPage.module.css'
import styles from './VerificationPage.module.css'
const messages = {
title: 'VERIFICATION',
instructions:
'Getting verified on Audius is easy! Just link your verified Instagram, TikTok or legacy verified Twitter account and you’ll be verified immediately.',
warning: (
<span>
{'Your Audius handle must '}
<b>exactly</b> {' match the verified handle you’re connecting.'}
</span>
),
failure: 'Sorry, unable to retrieve information',
errorHandle: 'Sorry, your handle does not match',
errorVerifiedTwitter: 'Your Twitter account isn’t legacy verified',
errorVerifiedInstagram: 'Your Instagram account isn’t verified',
errorVerifiedTikTok: 'Your TikTok account isn’t verified',
backToMusic: 'Back To The Music',
verified: "YOU'RE VERIFIED!",
twitterVerify: 'Verify with Twitter',
instagramVerify: 'Verify with Instagram',
tiktokVerify: 'Verify with TikTok'
}
type VerifyBodyProps = {
handle: string
onClick: () => void
onFailure: () => void
onTwitterLogin: (uuid: string, profile: TwitterProfile) => void
onInstagramLogin: (uuid: string, profile: InstagramProfile) => void
onTikTokLogin: (uuid: string, profile: TikTokProfile) => void
error?: string
}
const VerifyBody = (props: VerifyBodyProps) => {
const isTwitterEnabled = useRemoteVar(
BooleanKeys.DISPLAY_TWITTER_VERIFICATION_WEB_AND_DESKTOP
)
const isInstagramEnabled = useRemoteVar(
BooleanKeys.DISPLAY_INSTAGRAM_VERIFICATION_WEB_AND_DESKTOP
)
const isTikTokEnabled = useRemoteVar(
BooleanKeys.DISPLAY_TIKTOK_VERIFICATION_WEB_AND_DESKTOP
)
const record = useRecord()
const { handle, onClick } = props
const handleClickTwitter = useCallback(() => {
onClick()
const trackEvent: TrackEvent = make(Name.SETTINGS_START_TWITTER_OAUTH, {
handle
})
record(trackEvent)
}, [record, onClick, handle])
const handleClickInstagram = useCallback(() => {
onClick()
const trackEvent: TrackEvent = make(Name.SETTINGS_START_INSTAGRAM_OAUTH, {
handle
})
record(trackEvent)
}, [record, onClick, handle])
const handleClickTikTok = useCallback(() => {
onClick()
const trackEvent: TrackEvent = make(Name.SETTINGS_START_TIKTOK_OAUTH, {
handle
})
record(trackEvent)
}, [record, onClick, handle])
return (
<div className={styles.container}>
<div className={styles.text}>{messages.instructions}</div>
<div className={cn(styles.text, styles.warning)}>{messages.warning}</div>
<div className={styles.btnContainer}>
{isTwitterEnabled ? (
<TwitterAuthButton
onClick={handleClickTwitter}
onSuccess={props.onTwitterLogin}
onFailure={props.onFailure}
className={styles.socialButton}
containerClassName={styles.socialButton}
text={messages.twitterVerify}
/>
) : null}
{isInstagramEnabled ? (
<InstagramAuthButton
onClick={handleClickInstagram}
onSuccess={props.onInstagramLogin}
onFailure={props.onFailure}
text={messages.instagramVerify}
className={styles.socialButton}
containerClassName={styles.socialButton}
/>
) : null}
{isTikTokEnabled ? (
<TikTokAuthButton
onClick={handleClickTikTok}
onFailure={props.onFailure}
onSuccess={props.onTikTokLogin}
text={messages.tiktokVerify}
className={styles.socialButton}
/>
) : null}
</div>
{props.error && (
<div className={styles.error}>
<IconValidationX className={styles.validationIcon} />
{props.error}
</div>
)}
</div>
)
}
const LoadingBody = () => {
return (
<div className={styles.container}>
<LoadingSpinner className={styles.loadingContainer} />
</div>
)
}
type SuccessBodyProps = {
userId: ID
handle: string
name: string
profilePictureSizes: ProfilePictureSizes | null
goToRoute: (route: string) => void
}
const SuccessBody = ({
handle,
userId,
name,
profilePictureSizes,
goToRoute
}: SuccessBodyProps) => {
const profilePicture = useUserProfilePicture(
userId,
profilePictureSizes,
SquareSizes.SIZE_150_BY_150
)
const onClick = useCallback(() => {
goToRoute(profilePage(handle))
}, [goToRoute, handle])
return (
<div className={styles.container}>
<i
className={cn(
'emoji face-with-party-horn-and-party-hat',
styles.verifiedIcon
)}
/>
<div className={styles.verified}>{messages.verified}</div>
<DynamicImage
image={profilePicture}
wrapperClassName={styles.profilePicture}
/>
<div className={styles.displayName}>
{name}
<UserBadges
userId={userId}
badgeSize={12}
className={styles.iconVerified}
/>
</div>
<div className={styles.handle}>{`@${handle}`}</div>
<Button
type={ButtonType.COMMON_ALT}
className={styles.successBtn}
textClassName={styles.btnText}
size={ButtonSize.MEDIUM}
text={messages.backToMusic}
onClick={onClick}
rightIcon={<IconNote className={styles.noteIcon} />}
/>
</div>
)
}
const VerificationPage = ({
handle,
userId,
name,
profilePictureSizes,
goToRoute,
onTwitterLogin,
onInstagramLogin,
onTikTokLogin
}: SettingsPageProps) => {
const [error, setError] = useState('')
const [status, setStatus] = useState('')
const record = useRecord()
const onClick = useCallback(() => setStatus(Status.LOADING), [setStatus])
const onFailure = useCallback(() => {
setError(messages.failure)
setStatus(Status.ERROR)
}, [setError, setStatus])
const instagramLogin = useCallback(
(uuid: string, profile: InstagramProfile) => {
if (!profile.is_verified) {
setError(messages.errorVerifiedInstagram)
setStatus(Status.ERROR)
} else if (profile.username.toLowerCase() !== handle.toLowerCase()) {
setError(messages.errorHandle)
setStatus(Status.ERROR)
} else {
onInstagramLogin(uuid, profile)
setStatus(Status.SUCCESS)
}
const trackEvent: TrackEvent = make(
Name.SETTINGS_COMPLETE_INSTAGRAM_OAUTH,
{ is_verified: profile.is_verified, handle, username: profile.username }
)
record(trackEvent)
},
[handle, onInstagramLogin, setError, record]
)
const twitterLogin = useCallback(
(uuid: string, profile: TwitterProfile) => {
if (!profile.verified) {
setError(messages.errorVerifiedTwitter)
setStatus(Status.ERROR)
} else if (profile.screen_name.toLowerCase() !== handle.toLowerCase()) {
setError(messages.errorHandle)
setStatus(Status.ERROR)
} else {
onTwitterLogin(uuid, profile)
setStatus(Status.SUCCESS)
}
const trackEvent: TrackEvent = make(
Name.SETTINGS_COMPLETE_TWITTER_OAUTH,
{
is_verified: profile.verified,
handle,
screen_name: profile.screen_name
}
)
record(trackEvent)
},
[handle, onTwitterLogin, setError, record]
)
const tikTokLogin = useCallback(
(uuid: string, profile: TikTokProfile) => {
if (!profile.is_verified) {
setError(messages.errorVerifiedTikTok)
setStatus(Status.ERROR)
} else if (profile.username.toLowerCase() !== handle.toLowerCase()) {
setError(messages.errorHandle)
setStatus(Status.ERROR)
} else {
onTikTokLogin(uuid, profile)
setStatus(Status.SUCCESS)
}
const trackEvent: TrackEvent = make(Name.SETTINGS_COMPLETE_TIKTOK_OAUTH, {
is_verified: profile.is_verified,
handle,
username: profile.username
})
record(trackEvent)
},
[handle, onTikTokLogin, setError, record]
)
let body
if (status === Status.LOADING) {
body = <LoadingBody />
} else if (status === '' || status === Status.ERROR) {
body = (
<VerifyBody
handle={handle}
onClick={onClick}
onFailure={onFailure}
onInstagramLogin={instagramLogin}
onTwitterLogin={twitterLogin}
onTikTokLogin={tikTokLogin}
error={error}
/>
)
} else {
body = (
<SuccessBody
userId={userId}
handle={handle}
name={name}
profilePictureSizes={profilePictureSizes}
goToRoute={goToRoute}
/>
)
}
return (
<Page
title={messages.title}
contentClassName={settingsPageStyles.pageContent}
containerClassName={settingsPageStyles.page}
>
<div
className={cn(settingsPageStyles.bodyContainer, styles.bodyContainer)}
>
{body}
</div>
</Page>
)
}
export default VerificationPage