@@ -39,13 +39,15 @@ import {
3939 UserCertificationProgressStatus ,
4040 userCertificationProgressUpdateAsync ,
4141 UserCertificationUpdateProgressActions ,
42+ useShowSurvey ,
4243} from '../learn-lib'
4344import { getCertificationCompletedPath , getCoursePath , getLessonPathFromModule } from '../learn.routes'
4445
4546import { FccFrame } from './fcc-frame'
4647import { FccSidebar } from './fcc-sidebar'
4748import { TitleNav } from './title-nav'
4849import styles from './FreeCodeCamp.module.scss'
50+ import { LearnConfig } from '../learn-config'
4951
5052const FreeCodeCamp : FC < { } > = ( ) => {
5153
@@ -66,6 +68,11 @@ const FreeCodeCamp: FC<{}> = () => {
6668 const [ lessonParam , setLessonParam ] : [ string , Dispatch < SetStateAction < string > > ]
6769 = useState ( textFormatGetSafeString ( routeParams . lesson ) )
6870
71+ const [ showSurvey , setShowSurvey ] : [
72+ string ,
73+ Dispatch < SetStateAction < string > >
74+ ] = useShowSurvey ( )
75+
6976 const {
7077 certificationProgress : certificateProgress ,
7178 setCertificateProgress,
@@ -235,7 +242,6 @@ const FreeCodeCamp: FC<{}> = () => {
235242 currentLesson ,
236243 )
237244 . then ( ( progress : LearnUserCertificationProgress ) => {
238-
239245 setCertificateProgress ( progress )
240246 handleSurvey ( certWasInProgress , progress )
241247
@@ -277,9 +283,7 @@ const FreeCodeCamp: FC<{}> = () => {
277283 // so it's time to trigger the survey
278284 // NOTE: We have to add a delay, otherwise the survey closes when the user
279285 // is automatically redirected to the next lesson.
280- setTimeout ( async ( ) => {
281- surveyTriggerForUser ( 'TCA First Module Completed' , profile ?. userId )
282- } , 1000 )
286+ setShowSurvey ( certificationParam )
283287 }
284288
285289 /**
@@ -450,6 +454,17 @@ const FreeCodeCamp: FC<{}> = () => {
450454 isLoggedIn ,
451455 ] )
452456
457+ useEffect ( ( ) => {
458+ if ( ready && showSurvey === certificationParam ) {
459+ surveyTriggerForUser ( LearnConfig . SURVEY . COMPLETED_FIRST_MODULE , profile ?. userId )
460+ setShowSurvey ( '' )
461+ }
462+ } , [
463+ ready ,
464+ showSurvey ,
465+ certificationParam ,
466+ ] ) ;
467+
453468 return (
454469 < >
455470 < LoadingSpinner hide = { ready } />
0 commit comments