@@ -223,6 +223,10 @@ const FreeCodeCamp: FC<{}> = () => {
223
223
return
224
224
}
225
225
226
+ // get the current module as it exists before it's completed
227
+ const currentModule : LearnModuleProgress | undefined = getModuleFromProgress ( certificateProgress )
228
+ const certWasInProgress : boolean = currentModule ?. moduleStatus !== LearnModuleStatus . completed
229
+
226
230
userCertificationProgressUpdateAsync (
227
231
certificateProgress . id ,
228
232
UserCertificationUpdateProgressActions . completeLesson ,
@@ -231,14 +235,8 @@ const FreeCodeCamp: FC<{}> = () => {
231
235
. then ( ( progress : LearnUserCertificationProgress ) => {
232
236
233
237
setCertificateProgress ( progress )
238
+ handleSurvey ( certWasInProgress , progress )
234
239
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
240
} )
243
241
// eslint-disable-next-line react-hooks/exhaustive-deps
244
242
} , [
@@ -247,6 +245,37 @@ const FreeCodeCamp: FC<{}> = () => {
247
245
moduleParam ,
248
246
] )
249
247
248
+ function getModuleFromProgress ( certProgress : LearnUserCertificationProgress ) :
249
+ LearnModuleProgress | undefined {
250
+
251
+ return certProgress . modules . find ( m => m . module === moduleParam )
252
+ }
253
+
254
+ function handleSurvey ( certWasInProgress : boolean , progress : LearnUserCertificationProgress ) : void {
255
+
256
+ // if the current module wasn't in progress, there's nothing to do
257
+ if ( ! certWasInProgress ) {
258
+ return
259
+ }
260
+
261
+ // if the updated module isn't completed now, there's nothing to do
262
+ const moduleResult : LearnModuleProgress | undefined = getModuleFromProgress ( progress )
263
+ if ( moduleResult ?. moduleStatus !== LearnModuleStatus . completed ) {
264
+ return
265
+ }
266
+
267
+ // if there are any other modules that have been completed, there's nothing to do
268
+ if ( progress . modules
269
+ . some ( m => m . module !== moduleParam && m . moduleStatus === LearnModuleStatus . completed )
270
+ ) {
271
+ return
272
+ }
273
+
274
+ // this is the last lesson to be completed in the first module completed,
275
+ // so it's good to show the trigger
276
+ surveyTriggerForUser ( 'TCA First Module Completed' , profile ?. userId )
277
+ }
278
+
250
279
/**
251
280
* Handle the navigation away from the last step of the course in the FCC frame
252
281
* @returns
0 commit comments