Skip to content

Commit 81ba885

Browse files
Merge pull request #436 from topcoder-platform/TCA-790_assessments
TCA-790 Delay all calls to the survey -> dev
2 parents af3fa18 + bc91e20 commit 81ba885

File tree

7 files changed

+57
-21
lines changed

7 files changed

+57
-21
lines changed

src-ts/tools/learn/course-completed/CourseCompletedPage.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, useContext, useEffect } from 'react'
1+
import { Dispatch, FC, SetStateAction, useContext, useEffect } from 'react'
22
import { NavigateFunction, Params, useNavigate, useParams } from 'react-router-dom'
33

44
import { EnvironmentConfig } from '../../../config'
@@ -9,6 +9,7 @@ import {
99
LoadingSpinner,
1010
profileContext,
1111
ProfileContextData,
12+
surveyTriggerForUser,
1213
textFormatGetSafeString,
1314
} from '../../../lib'
1415
import {
@@ -21,11 +22,13 @@ import {
2122
useLearnBreadcrumb,
2223
UserCertificationProgressProviderData,
2324
UserCertificationProgressStatus,
25+
useShowSurvey,
2426
} from '../learn-lib'
2527
import { getCertificatePath, getCoursePath, LEARN_PATHS, rootRoute } from '../learn.routes'
2628

2729
import { ReactComponent as StarsSvg } from './stars.svg'
2830
import styles from './CourseCompletedPage.module.scss'
31+
import { LearnConfig } from '../learn-config'
2932

3033
const CourseCompletedPage: FC<{}> = () => {
3134

@@ -36,6 +39,11 @@ const CourseCompletedPage: FC<{}> = () => {
3639
const certificationParam: string = textFormatGetSafeString(routeParams.certification)
3740
const coursePath: string = getCoursePath(providerParam, certificationParam)
3841

42+
const [showSurvey, setShowSurvey]: [
43+
string,
44+
Dispatch<SetStateAction<string>>
45+
] = useShowSurvey()
46+
3947
const {
4048
course: courseData,
4149
ready: courseDataReady,
@@ -87,6 +95,13 @@ const CourseCompletedPage: FC<{}> = () => {
8795
ready,
8896
])
8997

98+
useEffect(() => {
99+
if (ready && showSurvey === certificationParam) {
100+
surveyTriggerForUser(LearnConfig.SURVEY.COMPLETED_FIRST_MODULE, profile?.userId)
101+
setShowSurvey('')
102+
}
103+
}, [ready, showSurvey, certificationParam]);
104+
90105
return (
91106
<>
92107
<LoadingSpinner hide={ready} />

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { debounce } from 'lodash'
12
import {
23
Dispatch,
34
FC,
@@ -38,14 +39,15 @@ import {
3839
UserCertificationProgressStatus,
3940
userCertificationProgressUpdateAsync,
4041
UserCertificationUpdateProgressActions,
42+
useShowSurvey,
4143
} from '../learn-lib'
4244
import { getCertificationCompletedPath, getCoursePath, getLessonPathFromModule } from '../learn.routes'
4345

4446
import { FccFrame } from './fcc-frame'
4547
import { FccSidebar } from './fcc-sidebar'
4648
import { TitleNav } from './title-nav'
4749
import styles from './FreeCodeCamp.module.scss'
48-
import { debounce } from 'lodash'
50+
import { LearnConfig } from '../learn-config'
4951

5052
const 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,
@@ -212,6 +219,7 @@ const FreeCodeCamp: FC<{}> = () => {
212219
profile?.userId,
213220
])
214221

222+
// eslint-disable-next-line react-hooks/exhaustive-deps
215223
const handleFccLessonComplete: (challengeUuid: string) => void = useCallback(debounce((challengeUuid: string) => {
216224

217225
const currentLesson: { [key: string]: string } = {
@@ -234,7 +242,6 @@ const FreeCodeCamp: FC<{}> = () => {
234242
currentLesson,
235243
)
236244
.then((progress: LearnUserCertificationProgress) => {
237-
238245
setCertificateProgress(progress)
239246
handleSurvey(certWasInProgress, progress)
240247

@@ -274,30 +281,16 @@ const FreeCodeCamp: FC<{}> = () => {
274281

275282
// This is the last lesson to be completed in the first module completed,
276283
// so it's time to trigger the survey
277-
const surveyTrigger: string = 'TCA First Module Completed'
278-
279-
// If there is only one assessment in a cert (e.g. Data Analysis w/Python),
280-
// the cert is also completed, which redirects the user to the cert page.
281-
// So the survey needs to be delayed so that it appears on the completed
282-
// cert page instead of the current lesson.
283-
284-
// NOTE: we can't use the cert's status here bc it doesn't get set to
285-
// completed until the UI notices the cert is complete and initiates
286-
// the completion. And we have to use >= instead of === because it's
287-
// possible TCA data isn't in sync w/the latest FCC curriculum.
288-
if (progress.certificationProgressPercentage >= 100) {
289-
setTimeout(async () => {
290-
surveyTriggerForUser(surveyTrigger, profile?.userId)
291-
}, 1000)
292-
} else {
293-
surveyTriggerForUser(surveyTrigger, profile?.userId)
294-
}
284+
// NOTE: We have to add a delay, otherwise the survey closes when the user
285+
// is automatically redirected to the next lesson.
286+
setShowSurvey(certificationParam)
295287
}
296288

297289
/**
298290
* Handle the navigation away from the last step of the course in the FCC frame
299291
* @returns
300292
*/
293+
// eslint-disable-next-line react-hooks/exhaustive-deps
301294
const handleFccLastLessonNavigation: () => void = useCallback(debounce(() => {
302295

303296
if (!certificateProgress) {
@@ -461,6 +454,17 @@ const FreeCodeCamp: FC<{}> = () => {
461454
isLoggedIn,
462455
])
463456

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+
464468
return (
465469
<>
466470
<LoadingSpinner hide={ready} />

src-ts/tools/learn/learn-config/learn-config.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ export interface LearnConfigModel {
77
value: string,
88
}
99
CLIENT: string
10+
SURVEY: {
11+
COMPLETED_FIRST_MODULE: string
12+
}
1013
}

src-ts/tools/learn/learn-config/learn.default.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ export const LearnConfigDefault: LearnConfigModel = {
1111
value: 'certificate-container',
1212
},
1313
CLIENT: 'https://fcc.topcoder-dev.com:4431',
14+
SURVEY: {
15+
COMPLETED_FIRST_MODULE: 'TCA First Module Completed',
16+
}
1417
}

src-ts/tools/learn/learn-lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export * from './data-providers'
77
export * from './learn-breadcrumb-provider'
88
export * from './learn-swr'
99
export * from './my-course-card'
10+
export * from './survey'
1011
export * from './svgs'
1112
export * from './wave-hero'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './use-show-survey'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Dispatch, SetStateAction } from "react"
2+
import { useLocalStorage } from "../../../../lib"
3+
4+
export const useShowSurvey = (): [
5+
string,
6+
Dispatch<SetStateAction<string>>
7+
] => {
8+
return useLocalStorage<string>('tca-show-survey', '');
9+
}

0 commit comments

Comments
 (0)