Skip to content

Commit a19ad96

Browse files
TCA-755 #comment Update the trigger to run the first time any module is completed
1 parent 375a554 commit a19ad96

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ const FreeCodeCamp: FC<{}> = () => {
223223
return
224224
}
225225

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+
226230
userCertificationProgressUpdateAsync(
227231
certificateProgress.id,
228232
UserCertificationUpdateProgressActions.completeLesson,
@@ -231,14 +235,8 @@ const FreeCodeCamp: FC<{}> = () => {
231235
.then((progress: LearnUserCertificationProgress) => {
232236

233237
setCertificateProgress(progress)
238+
handleSurvey(certWasInProgress, progress)
234239

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-
}
242240
})
243241
// eslint-disable-next-line react-hooks/exhaustive-deps
244242
}, [
@@ -247,6 +245,37 @@ const FreeCodeCamp: FC<{}> = () => {
247245
moduleParam,
248246
])
249247

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+
250279
/**
251280
* Handle the navigation away from the last step of the course in the FCC frame
252281
* @returns

0 commit comments

Comments
 (0)