@@ -17,6 +17,7 @@ import {
1717 LoadingSpinner ,
1818 profileContext ,
1919 ProfileContextData ,
20+ surveyTriggerForUser ,
2021 textFormatGetSafeString ,
2122} from '../../../lib'
2223import {
@@ -203,43 +204,55 @@ const FreeCodeCamp: FC<{}> = () => {
203204 } , 500 )
204205 }
205206 // eslint-disable-next-line react-hooks/exhaustive-deps
206- } , [ ] )
207+ } , [
208+ certificateProgress ,
209+ lesson ?. course . certificationId ,
210+ lesson ?. course . id ,
211+ profile ?. userId ,
212+ ] )
207213
208214 const handleFccLessonComplete : ( challengeUuid : string ) => void = useCallback ( ( challengeUuid : string ) => {
215+
209216 const currentLesson : { [ key : string ] : string } = {
210217 lesson : lessonParam ,
211218 module : moduleParam ,
212219 uuid : challengeUuid ,
213220 }
214- if ( certificateProgress ) {
215- userCertificationProgressUpdateAsync (
216- certificateProgress . id ,
217- UserCertificationUpdateProgressActions . completeLesson ,
218- currentLesson ,
219- )
220- . then ( ( progress : LearnUserCertificationProgress ) => {
221221
222- setCertificateProgress ( progress )
222+ if ( ! certificateProgress ) {
223+ return
224+ }
223225
224- // if this is the last lesson of the first module, show the survey
225- const firstModule : LearnModuleProgress = progress . modules [ 0 ]
226+ userCertificationProgressUpdateAsync (
227+ certificateProgress . id ,
228+ UserCertificationUpdateProgressActions . completeLesson ,
229+ currentLesson ,
230+ )
231+ . then ( ( progress : LearnUserCertificationProgress ) => {
226232
227- if ( moduleParam === firstModule . module
228- && firstModule . moduleStatus === LearnModuleStatus . completed ) {
233+ setCertificateProgress ( progress )
229234
230- // TODO: use the Sprig SDK to send the event w/the user
231- window . Sprig ( 'track' , 'TCA First Module Completed' )
232- }
233- } )
234- }
235+ // if this is the last lesson of the first module, show the survey
236+ const firstModule : LearnModuleProgress = progress . modules [ 0 ]
237+ if ( moduleParam === firstModule . module
238+ && firstModule . moduleStatus === LearnModuleStatus . completed ) {
239+
240+ surveyTriggerForUser ( 'TCA First Module Completed' , profile ?. userId )
241+ }
242+ } )
235243 // eslint-disable-next-line react-hooks/exhaustive-deps
236- } , [ ] )
244+ } , [
245+ certificateProgress ,
246+ lessonParam ,
247+ moduleParam ,
248+ ] )
237249
238250 /**
239251 * Handle the navigation away from the last step of the course in the FCC frame
240252 * @returns
241253 */
242254 const handleFccLastLessonNavigation : ( ) => void = useCallback ( ( ) => {
255+
243256 if ( ! certificateProgress ) {
244257 return
245258 }
@@ -284,7 +297,12 @@ const FreeCodeCamp: FC<{}> = () => {
284297
285298 navigate ( nextLessonPath )
286299 // eslint-disable-next-line react-hooks/exhaustive-deps
287- } , [ ] )
300+ } , [
301+ certificateProgress ,
302+ certificationParam ,
303+ courseData ?. modules ,
304+ providerParam ,
305+ ] )
288306
289307 useEffect ( ( ) => {
290308
@@ -315,13 +333,13 @@ const FreeCodeCamp: FC<{}> = () => {
315333 )
316334 navigate ( completedPath )
317335 } )
336+ // eslint-disable-next-line react-hooks/exhaustive-deps
318337 } , [
319338 certificateProgress ,
320339 certificationParam ,
321- navigate ,
322- providerParam ,
323340 profile ?. handle ,
324- setCertificateProgress ,
341+ profile ?. userId ,
342+ providerParam ,
325343 ] )
326344
327345 useEffect ( ( ) => {
@@ -341,13 +359,13 @@ const FreeCodeCamp: FC<{}> = () => {
341359 navigate ( lessonPath )
342360 }
343361 }
362+ // eslint-disable-next-line react-hooks/exhaustive-deps
344363 } , [
345364 certificationParam ,
346365 courseData ,
347366 courseDataReady ,
348367 lessonParam ,
349368 moduleParam ,
350- navigate ,
351369 providerParam ,
352370 ] )
353371
0 commit comments