@@ -14,6 +14,7 @@ import {
14
14
CoursesProviderData ,
15
15
LearnLesson ,
16
16
LearnModule ,
17
+ LearnMyModuleProgress ,
17
18
LessonProviderData ,
18
19
MyCertificationProgressProviderData ,
19
20
MyCertificationProgressStatus ,
@@ -175,6 +176,53 @@ const FreeCodeCamp: FC<{}> = () => {
175
176
}
176
177
}
177
178
179
+ /**
180
+ * Handle the navigation away from the last step of the course in the FCC frame
181
+ * @returns
182
+ */
183
+ function handleFccLastLessonNavigation ( ) : void {
184
+ if ( ! certificateProgress ) {
185
+ return
186
+ }
187
+
188
+ // course is completed, return user to course completed screen
189
+ if ( certificateProgress . courseProgressPercentage === 100 ) {
190
+ const completedPath : string = getCertificationCompletedPath (
191
+ providerParam ,
192
+ certificationParam
193
+ )
194
+
195
+ navigate ( completedPath )
196
+ return
197
+ }
198
+
199
+ // course is not completed yet,
200
+ // so we find the first incomplete lesson
201
+ // and redirect user to it for a continuous flow
202
+ const firstIncompleteModule : LearnMyModuleProgress | undefined = certificateProgress . modules . find ( m => m . completedPercentage !== 100 )
203
+ const moduleLessons : Array < LearnLesson > | undefined = courseData ?. modules . find ( m => m . key === firstIncompleteModule ?. module ) ?. lessons
204
+ if ( ! firstIncompleteModule || ! moduleLessons ) {
205
+ // case unknown, return
206
+ return
207
+ }
208
+
209
+ const completedLessons : Array < string > = firstIncompleteModule . completedLessons . map ( l => l . dashedName )
210
+ const firstIncompleteLesson : LearnLesson | undefined = moduleLessons . find ( l => ! completedLessons . includes ( l . dashedName ) )
211
+ if ( ! firstIncompleteLesson ) {
212
+ // case unknown, return
213
+ return
214
+ }
215
+
216
+ const nextLessonPath : string = getFccLessonPath (
217
+ providerParam ,
218
+ certificationParam ,
219
+ firstIncompleteModule . module ?? '' ,
220
+ firstIncompleteLesson . dashedName ?? ''
221
+ )
222
+
223
+ navigate ( nextLessonPath )
224
+ }
225
+
178
226
useEffect ( ( ) => {
179
227
if (
180
228
certificateProgress &&
@@ -270,6 +318,7 @@ const FreeCodeCamp: FC<{}> = () => {
270
318
lesson = { lesson }
271
319
onFccLessonChange = { handleFccLessonReady }
272
320
onFccLessonComplete = { handleFccLessonComplete }
321
+ onFccLastLessonNavigation = { handleFccLastLessonNavigation }
273
322
/>
274
323
</ div >
275
324
</ div >
0 commit comments