-
Notifications
You must be signed in to change notification settings - Fork 106
/
ProfileAuto.tsx
505 lines (478 loc) · 14.7 KB
/
ProfileAuto.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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
import { useCallback, useEffect, useState } from 'react'
import type { Name } from '@audius/common'
import { BooleanKeys } from '@audius/common'
import type { NativeStackScreenProps } from '@react-navigation/native-stack'
import * as signOnActions from 'common/store/pages/signon/actions'
import {
getEmailField,
getHandleField
} from 'common/store/pages/signon/selectors'
import { EditingStatus } from 'common/store/pages/signon/types'
import type { EditableField } from 'common/store/pages/signon/types'
import { Animated, View, TouchableOpacity } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'
import { useDispatch, useSelector } from 'react-redux'
import IconImage from 'app/assets/images/iconImage.svg'
import IconInstagram from 'app/assets/images/iconInstagram.svg'
import IconTwitter from 'app/assets/images/iconTwitterBird.svg'
import IconUser from 'app/assets/images/iconUser.svg'
import IconVerified from 'app/assets/images/iconVerified.svg'
import { Text } from 'app/components/core'
import LoadingSpinner from 'app/components/loading-spinner'
import { SocialButton } from 'app/components/social-button'
import { TikTokAuthButton } from 'app/components/tiktok-auth'
import { useRemoteVar } from 'app/hooks/useRemoteConfig'
import { useToast } from 'app/hooks/useToast'
import { track, make } from 'app/services/analytics'
import * as oauthActions from 'app/store/oauth/actions'
import {
getInstagramError,
getInstagramInfo,
getTikTokError,
getTikTokInfo,
getTwitterError,
getTwitterInfo,
getAbandoned
} from 'app/store/oauth/selectors'
import { makeStyles } from 'app/styles'
import { EventNames } from 'app/types/analytics'
import { useThemeColors } from 'app/utils/theme'
import SignupHeader from './SignupHeader'
import type { SignOnStackParamList } from './types'
const useStyles = makeStyles(({ palette, spacing }) => ({
screen: {
width: '100%',
height: '100%',
backgroundColor: palette.staticWhite
},
container: {
alignItems: 'center',
padding: spacing(7),
height: '100%'
},
header: {
color: palette.secondary,
textAlign: 'center',
paddingBottom: spacing(2)
},
socialButtonContainer: {
marginBottom: spacing(2)
},
tile: {
width: '100%',
backgroundColor: palette.neutralLight10,
borderWidth: 1,
borderColor: palette.neutralLight7,
borderRadius: 8,
padding: spacing(4),
marginBottom: spacing(6)
},
tileHeader: { marginBottom: spacing(1), textTransform: 'uppercase' },
tileListItem: {
marginTop: spacing(2),
flexDirection: 'row',
alignItems: 'center'
},
tileListItemText: {
flex: 1,
lineHeight: 21
},
tileListItemIconCircle: {
marginRight: spacing(2),
height: 24,
width: 24,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: palette.secondary,
borderRadius: 100
},
verifiedIcon: {
marginRight: spacing(4)
},
manualButton: {
marginTop: 'auto',
marginBottom: spacing(7)
},
manualButtonText: {
color: palette.secondaryLight2
},
loadingIcon: {
alignItems: 'center',
marginTop: 48,
height: 48
}
}))
const messages = {
instagramButton: 'Complete with Instagram',
twitterButton: 'Complete with Twitter',
tiktokButton: 'Complete with TikTok',
header: 'Quickly Complete Your Account by Linking Your Other Socials',
importTileHeader: 'We will import these details',
importTileItemHandle: 'Handle & Display Name',
importTileItemPicture: 'Profile Picture & Cover Photo',
verifiedTileHeader: 'Verified?',
verifiedTileContent:
'If the linked account is verified, your Audius account will be verified to match!',
manual: "I'd rather fill out my profile manually",
error: 'Something went wrong, please try again'
}
let didAnimation = false
const FormTitle = () => {
const styles = useStyles()
let opacity = new Animated.Value(1)
if (!didAnimation) {
opacity = new Animated.Value(0)
Animated.timing(opacity, {
toValue: 1,
duration: 500,
useNativeDriver: true
}).start(() => {
didAnimation = true
})
}
return (
<Animated.View style={{ opacity }}>
<Text variant={'h1'} style={styles.header}>
{messages.header}
</Text>
</Animated.View>
)
}
type ProfileAutoProps = NativeStackScreenProps<
SignOnStackParamList,
'ProfileAuto'
>
const ProfileAuto = ({ navigation }: ProfileAutoProps) => {
const styles = useStyles()
const dispatch = useDispatch()
const { toast } = useToast()
const { neutralLight4, staticWhite } = useThemeColors()
const twitterInfo = useSelector(getTwitterInfo)
const twitterError = useSelector(getTwitterError)
const instagramInfo = useSelector(getInstagramInfo)
const instagramError = useSelector(getInstagramError)
const tikTokInfo = useSelector(getTikTokInfo)
const tikTokError = useSelector(getTikTokError)
const abandoned = useSelector(getAbandoned)
const handleField: EditableField = useSelector(getHandleField)
const emailField: EditableField = useSelector(getEmailField)
const isTwitterEnabled = useRemoteVar(
BooleanKeys.DISPLAY_TWITTER_VERIFICATION
)
const isInstagramEnabled = useRemoteVar(
BooleanKeys.DISPLAY_INSTAGRAM_VERIFICATION
)
const isTikTokEnabled = useRemoteVar(BooleanKeys.DISPLAY_TIKTOK_VERIFICATION)
const [isLoading, setIsLoading] = useState(false)
const [hasNavigatedAway, setHasNavigatedAway] = useState(false)
const [didValidateHandle, setDidValidateHandle] = useState(false)
const validateHandle = useCallback(
(handle: string, verified: boolean) => {
dispatch(signOnActions.validateHandle(handle, verified))
},
[dispatch]
)
const trackOAuthComplete = useCallback(
(
eventName:
| Name.CREATE_ACCOUNT_COMPLETE_TWITTER
| Name.CREATE_ACCOUNT_COMPLETE_INSTAGRAM
| Name.CREATE_ACCOUNT_COMPLETE_TIKTOK,
handle: string,
isVerified: boolean
) => {
track(
make({
eventName,
isVerified,
emailAddress: emailField.value,
handle
})
)
},
[emailField]
)
const setOAuthInfo = useCallback(() => {
if (twitterInfo) {
dispatch(
signOnActions.setTwitterProfile(
twitterInfo.twitterId,
twitterInfo.profile,
twitterInfo.profile.profile_image_url_https
? {
// Replace twitter's returned image (which may vary) with the hd one
uri: twitterInfo.profile.profile_image_url_https.replace(
/_(normal|bigger|mini)/g,
''
),
name: 'ProfileImage',
type: 'image/jpeg'
}
: null,
twitterInfo.profile.profile_banner_url
? {
uri: twitterInfo.profile.profile_banner_url,
name: 'ProfileBanner',
type: 'image/png'
}
: null
)
)
} else if (instagramInfo) {
dispatch(
signOnActions.setInstagramProfile(
instagramInfo.instagramId,
instagramInfo.profile,
instagramInfo.profile.profile_pic_url_hd
? {
uri: instagramInfo.profile.profile_pic_url_hd,
name: 'ProfileImage',
type: 'image/jpeg'
}
: null
)
)
} else if (tikTokInfo) {
dispatch(
signOnActions.setTikTokProfile(
tikTokInfo.uuid,
tikTokInfo.profile,
tikTokInfo.profile.avatar_large_url
? {
uri: tikTokInfo.profile.avatar_large_url,
name: 'ProfileImage',
type: 'image/jpeg'
}
: null
)
)
}
}, [dispatch, twitterInfo, instagramInfo, tikTokInfo])
const signUp = useCallback(() => {
dispatch(signOnActions.signUp())
}, [dispatch])
const handleProfileSet = useCallback(
({
completeEvent,
handle,
verified,
requiresUserReview
}: {
completeEvent:
| Name.CREATE_ACCOUNT_COMPLETE_TWITTER
| Name.CREATE_ACCOUNT_COMPLETE_INSTAGRAM
| Name.CREATE_ACCOUNT_COMPLETE_TIKTOK
handle: string
verified: boolean
requiresUserReview: boolean
}) => {
if (handleField.status !== EditingStatus.SUCCESS && !didValidateHandle) {
validateHandle(handle, verified)
setDidValidateHandle(true)
} else if (
handleField.status === EditingStatus.FAILURE ||
requiresUserReview
) {
trackOAuthComplete(completeEvent, handle, verified)
setOAuthInfo()
navigation.push('ProfileManual')
setHasNavigatedAway(true)
setIsLoading(false)
} else if (handleField.status === EditingStatus.SUCCESS) {
trackOAuthComplete(completeEvent, handle, verified)
setOAuthInfo()
signUp()
track(
make({
eventName: EventNames.CREATE_ACCOUNT_COMPLETE_PROFILE,
emailAddress: emailField.value,
handle
})
)
navigation.push('FirstFollows')
setHasNavigatedAway(true)
setIsLoading(false)
}
},
[
handleField,
emailField,
didValidateHandle,
validateHandle,
setOAuthInfo,
signUp,
navigation,
trackOAuthComplete
]
)
useEffect(() => {
if (!hasNavigatedAway) {
if (twitterInfo) {
handleProfileSet({
completeEvent: EventNames.CREATE_ACCOUNT_COMPLETE_TWITTER,
handle: twitterInfo.profile.screen_name,
verified: twitterInfo.profile.verified,
requiresUserReview: twitterInfo.requiresUserReview
})
} else if (instagramInfo) {
handleProfileSet({
completeEvent: EventNames.CREATE_ACCOUNT_COMPLETE_INSTAGRAM,
handle: instagramInfo.profile.username,
verified: instagramInfo.profile.is_verified,
requiresUserReview: instagramInfo.requiresUserReview
})
} else if (tikTokInfo) {
handleProfileSet({
completeEvent: EventNames.CREATE_ACCOUNT_COMPLETE_TIKTOK,
handle: tikTokInfo.profile.username,
verified: tikTokInfo.profile.is_verified,
requiresUserReview: tikTokInfo.requiresUserReview
})
}
}
}, [
hasNavigatedAway,
twitterInfo,
instagramInfo,
tikTokInfo,
handleProfileSet
])
useEffect(() => {
if (twitterError || instagramError || tikTokError) {
setIsLoading(false)
toast({ content: messages.error })
}
}, [twitterError, instagramError, tikTokError, toast])
const handleTwitterPress = () => {
setIsLoading(true)
dispatch(oauthActions.setTwitterError(null))
dispatch(oauthActions.twitterAuth())
track(
make({
eventName: EventNames.CREATE_ACCOUNT_START_TWITTER,
emailAddress: emailField.value
})
)
}
const handleInstagramPress = () => {
setIsLoading(true)
dispatch(oauthActions.setInstagramError(null))
dispatch(oauthActions.instagramAuth())
track(
make({
eventName: EventNames.CREATE_ACCOUNT_START_INSTAGRAM,
emailAddress: emailField.value
})
)
}
const handleTikTokPress = () => {
dispatch(oauthActions.setTikTokError(null))
setIsLoading(true)
track(
make({
eventName: EventNames.CREATE_ACCOUNT_START_TIKTOK,
emailAddress: emailField.value
})
)
}
const handlePressManual = useCallback(() => {
navigation.push('ProfileManual')
}, [navigation])
useEffect(() => {
if (abandoned) {
setIsLoading(false)
}
}, [abandoned])
return (
<SafeAreaView style={styles.screen}>
<SignupHeader />
<View style={styles.container}>
{isLoading ? (
<View style={styles.loadingIcon}>
<LoadingSpinner fill={neutralLight4} />
</View>
) : (
<>
<FormTitle />
<View style={styles.tile}>
<Text variant={'h3'} style={styles.tileHeader}>
{messages.importTileHeader}
</Text>
<View style={[styles.tileListItem]}>
<View style={styles.tileListItemIconCircle}>
<IconUser fill={staticWhite} height={16} width={16} />
</View>
<Text variant={'h4'} noGutter style={styles.tileListItemText}>
{messages.importTileItemHandle}
</Text>
</View>
<View style={[styles.tileListItem]}>
<View style={styles.tileListItemIconCircle}>
<IconImage fill={staticWhite} height={16} width={16} />
</View>
<Text variant={'h4'} noGutter style={styles.tileListItemText}>
{messages.importTileItemPicture}
</Text>
</View>
</View>
{isTwitterEnabled ? (
<SocialButton
color={'#1BA1F1'}
fullWidth
icon={IconTwitter}
onPress={handleTwitterPress}
styles={{ root: styles.socialButtonContainer }}
title={messages.twitterButton}
/>
) : null}
{isInstagramEnabled ? (
<SocialButton
fullWidth
icon={IconInstagram}
onPress={handleInstagramPress}
styles={{ root: styles.socialButtonContainer }}
title={messages.instagramButton}
/>
) : null}
{isTikTokEnabled ? (
<TikTokAuthButton
onPress={handleTikTokPress}
styles={{ root: styles.socialButtonContainer }}
title={messages.tiktokButton}
/>
) : null}
<View style={[styles.tile, { marginTop: 16 }]}>
<Text variant={'h3'} style={styles.tileHeader}>
{messages.verifiedTileHeader}
</Text>
<View style={[styles.tileListItem]}>
<IconVerified
height={24}
width={24}
style={styles.verifiedIcon}
/>
<Text variant={'h4'} noGutter style={styles.tileListItemText}>
{messages.verifiedTileContent}
</Text>
</View>
</View>
<TouchableOpacity
activeOpacity={0.6}
onPress={handlePressManual}
style={styles.manualButton}
>
<Text
fontSize='medium'
weight='medium'
style={styles.manualButtonText}
>
{messages.manual}
</Text>
</TouchableOpacity>
</>
)}
</View>
</SafeAreaView>
)
}
export default ProfileAuto