@@ -146,6 +146,7 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
146
146
trackPageView,
147
147
trackYppOptIn,
148
148
identifyUser,
149
+ trackYppReqsNotMet,
149
150
trackClickAuthModalSignUpButton,
150
151
trackClickAuthModalSignInButton,
151
152
} = useSegmentAnalytics ( )
@@ -154,9 +155,10 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
154
155
155
156
const { displaySnackbar } = useSnackbar ( )
156
157
157
- const { handleAuthorizeClick, alreadyRegisteredChannel } = useYppGoogleAuth ( {
158
- channelsLoaded,
159
- } )
158
+ const { handleAuthorizeClick, ytRequirementsErrors, setYtRequirementsErrors, alreadyRegisteredChannel } =
159
+ useYppGoogleAuth ( {
160
+ channelsLoaded,
161
+ } )
160
162
161
163
useEffect ( ( ) => {
162
164
if ( searchParams . get ( 'utm_source' ) ) {
@@ -173,11 +175,18 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
173
175
} , [ trackPageView , yppModalOpenName ] )
174
176
175
177
const handleClose = useCallback ( ( ) => {
178
+ setYtRequirementsErrors ( [ ] )
176
179
setReferrerId ( null )
177
180
setYppModalOpenName ( null )
178
181
setSelectedChannelId ( null )
179
182
setShouldContinueYppFlowAfterLogin ( false )
180
- } , [ setYppModalOpenName , setReferrerId , setSelectedChannelId , setShouldContinueYppFlowAfterLogin ] )
183
+ } , [
184
+ setYppModalOpenName ,
185
+ setReferrerId ,
186
+ setSelectedChannelId ,
187
+ setShouldContinueYppFlowAfterLogin ,
188
+ setYtRequirementsErrors ,
189
+ ] )
181
190
182
191
const handleGoBack = useCallback ( ( ) => {
183
192
if ( yppModalOpenName === 'ypp-sync-options' ) {
@@ -190,9 +199,10 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
190
199
191
200
const handleSelectChannel = useCallback (
192
201
( selectedChannelId : string ) => {
202
+ setYtRequirementsErrors ( [ ] )
193
203
setSelectedChannelId ( selectedChannelId )
194
204
} ,
195
- [ setSelectedChannelId ]
205
+ [ setSelectedChannelId , setYtRequirementsErrors ]
196
206
)
197
207
198
208
const createOrUpdateChannel = useCreateEditChannelSubmit ( )
@@ -340,6 +350,13 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
340
350
}
341
351
} , [ channel , detailsFormMethods , referrerId ] )
342
352
353
+ useEffect ( ( ) => {
354
+ if ( ytRequirementsErrors ?. length ) {
355
+ trackPageView ( 'YPP Reqs Not Met' )
356
+ trackYppReqsNotMet ( ytRequirementsErrors , utmSource , utmCampaign )
357
+ }
358
+ } , [ trackPageView , trackYppReqsNotMet , utmCampaign , utmSource , ytRequirementsErrors ] )
359
+
343
360
const selectedChannel = useMemo ( ( ) => {
344
361
if ( ! unSyncedChannels || ! selectedChannelId ) {
345
362
return null
@@ -364,6 +381,13 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
364
381
setSelectedChannelId ( yppUnsyncedChannels [ 0 ] . id )
365
382
}
366
383
384
+ if ( ytRequirementsErrors . length ) {
385
+ return {
386
+ text : 'Close' ,
387
+ onClick : handleClose ,
388
+ }
389
+ }
390
+
367
391
if ( yppUnsyncedChannels && yppUnsyncedChannels . length > 1 ) {
368
392
return {
369
393
text : 'Select channel' ,
@@ -383,11 +407,13 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
383
407
}
384
408
385
409
return {
386
- title : 'Requirements' ,
387
- description :
388
- 'Before you can apply to the program, make sure your YouTube channel meets the below conditions.' ,
410
+ headerIcon : ytRequirementsErrors . length ? < SvgAlertsError32 /> : undefined ,
411
+ title : ytRequirementsErrors . length ? 'Authorization failed' : 'Requirements' ,
412
+ description : ytRequirementsErrors . length
413
+ ? 'Looks like the YouTube channel you selected does not meet all conditions to be enrolled in the program. You can select another one or try again at a later time.'
414
+ : 'Before you can apply to the program, make sure your YouTube channel meets the below conditions.' ,
389
415
primaryButton : getPrimaryButton ( ) ,
390
- component : < YppAuthorizationRequirementsStep /> ,
416
+ component : < YppAuthorizationRequirementsStep requirmentsErrorCodes = { ytRequirementsErrors } /> ,
391
417
}
392
418
}
393
419
@@ -467,6 +493,7 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
467
493
handleSelectChannel ,
468
494
alreadyRegisteredChannel ?. channelTitle ,
469
495
alreadyRegisteredChannel ?. ownerMemberHandle ,
496
+ ytRequirementsErrors ,
470
497
isLoading ,
471
498
yppCurrentChannel ,
472
499
yppUnsyncedChannels ,
@@ -484,7 +511,7 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
484
511
const isLoadingModal = yppModalOpenName === 'ypp-fetching-data' || yppModalOpenName === 'ypp-speaking-to-backend'
485
512
486
513
const secondaryButton : DialogButtonProps | undefined = useMemo ( ( ) => {
487
- if ( isLoadingModal ) return
514
+ if ( isLoadingModal || ytRequirementsErrors . length ) return
488
515
489
516
if ( yppModalOpenName === 'ypp-requirements' && isLoggedIn ) return
490
517
@@ -517,6 +544,7 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
517
544
}
518
545
} , [
519
546
isLoadingModal ,
547
+ ytRequirementsErrors . length ,
520
548
yppModalOpenName ,
521
549
isLoggedIn ,
522
550
isSubmitting ,
@@ -540,7 +568,8 @@ export const YppAuthorizationModal: FC<YppAuthorizationModalProps> = ({ unSynced
540
568
primaryButton = { authorizationStep ?. primaryButton }
541
569
secondaryButton = { secondaryButton }
542
570
additionalActionsNode = {
543
- ! isLoadingModal && (
571
+ ! isLoadingModal &&
572
+ ! ytRequirementsErrors . length && (
544
573
< Button variant = "tertiary" disabled = { isSubmitting } onClick = { handleClose } >
545
574
Cancel
546
575
</ Button >
0 commit comments