Skip to content

Commit a3be4d0

Browse files
committed
TCA-790 - use localstorage flag for showing survey
1 parent df67f69 commit a3be4d0

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

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

Lines changed: 15 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,7 +9,9 @@ import {
99
LoadingSpinner,
1010
profileContext,
1111
ProfileContextData,
12+
surveyTriggerForUser,
1213
textFormatGetSafeString,
14+
useLocalStorage,
1315
} from '../../../lib'
1416
import {
1517
AllCertificationsProviderData,
@@ -36,6 +38,11 @@ const CourseCompletedPage: FC<{}> = () => {
3638
const certificationParam: string = textFormatGetSafeString(routeParams.certification)
3739
const coursePath: string = getCoursePath(providerParam, certificationParam)
3840

41+
const [showSurvey, setShowSurvey]: [
42+
string,
43+
Dispatch<SetStateAction<string>>
44+
] = useLocalStorage<string>('tca-show-survey', '')
45+
3946
const {
4047
course: courseData,
4148
ready: courseDataReady,
@@ -87,6 +94,13 @@ const CourseCompletedPage: FC<{}> = () => {
8794
ready,
8895
])
8996

97+
useEffect(() => {
98+
if (ready && showSurvey === certificationParam) {
99+
surveyTriggerForUser('TCA First Module Completed', profile?.userId)
100+
setShowSurvey('')
101+
}
102+
}, [ready, showSurvey, certificationParam]);
103+
90104
return (
91105
<>
92106
<LoadingSpinner hide={ready} />

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ProfileContextData,
2121
surveyTriggerForUser,
2222
textFormatGetSafeString,
23+
useLocalStorage,
2324
} from '../../../lib'
2425
import {
2526
CoursesProviderData,
@@ -66,6 +67,11 @@ const FreeCodeCamp: FC<{}> = () => {
6667
const [lessonParam, setLessonParam]: [string, Dispatch<SetStateAction<string>>]
6768
= useState(textFormatGetSafeString(routeParams.lesson))
6869

70+
const [showSurvey, setShowSurvey]: [
71+
string,
72+
Dispatch<SetStateAction<string>>
73+
] = useLocalStorage<string>('tca-show-survey', '')
74+
6975
const {
7076
certificationProgress: certificateProgress,
7177
setCertificateProgress,
@@ -235,7 +241,6 @@ const FreeCodeCamp: FC<{}> = () => {
235241
currentLesson,
236242
)
237243
.then((progress: LearnUserCertificationProgress) => {
238-
239244
setCertificateProgress(progress)
240245
handleSurvey(certWasInProgress, progress)
241246

@@ -277,9 +282,7 @@ const FreeCodeCamp: FC<{}> = () => {
277282
// so it's time to trigger the survey
278283
// NOTE: We have to add a delay, otherwise the survey closes when the user
279284
// is automatically redirected to the next lesson.
280-
setTimeout(async () => {
281-
surveyTriggerForUser('TCA First Module Completed', profile?.userId)
282-
}, 1000)
285+
setShowSurvey(certificationParam)
283286
}
284287

285288
/**
@@ -450,6 +453,16 @@ const FreeCodeCamp: FC<{}> = () => {
450453
isLoggedIn,
451454
])
452455

456+
useEffect(() => {
457+
if (ready && showSurvey === certificationParam) {
458+
surveyTriggerForUser('TCA First Module Completed', profile?.userId)
459+
setShowSurvey('')
460+
}
461+
}, [
462+
showSurvey,
463+
certificationParam,
464+
]);
465+
453466
return (
454467
<>
455468
<LoadingSpinner hide={ready} />

0 commit comments

Comments
 (0)