Skip to content

TCA-790 - use localstorage flag for showing survey #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src-ts/tools/learn/course-completed/CourseCompletedPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useContext, useEffect } from 'react'
import { Dispatch, FC, SetStateAction, useContext, useEffect } from 'react'
import { NavigateFunction, Params, useNavigate, useParams } from 'react-router-dom'

import { EnvironmentConfig } from '../../../config'
Expand All @@ -9,6 +9,7 @@ import {
LoadingSpinner,
profileContext,
ProfileContextData,
surveyTriggerForUser,
textFormatGetSafeString,
} from '../../../lib'
import {
Expand All @@ -21,11 +22,13 @@ import {
useLearnBreadcrumb,
UserCertificationProgressProviderData,
UserCertificationProgressStatus,
useShowSurvey,
} from '../learn-lib'
import { getCertificatePath, getCoursePath, LEARN_PATHS, rootRoute } from '../learn.routes'

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

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

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

const [showSurvey, setShowSurvey]: [
string,
Dispatch<SetStateAction<string>>
] = useShowSurvey()

const {
course: courseData,
ready: courseDataReady,
Expand Down Expand Up @@ -87,6 +95,13 @@ const CourseCompletedPage: FC<{}> = () => {
ready,
])

useEffect(() => {
if (ready && showSurvey === certificationParam) {
surveyTriggerForUser(LearnConfig.SURVEY.COMPLETED_FIRST_MODULE, profile?.userId)
setShowSurvey('')
}
}, [ready, showSurvey, certificationParam]);

return (
<>
<LoadingSpinner hide={ready} />
Expand Down
23 changes: 19 additions & 4 deletions src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ import {
UserCertificationProgressStatus,
userCertificationProgressUpdateAsync,
UserCertificationUpdateProgressActions,
useShowSurvey,
} from '../learn-lib'
import { getCertificationCompletedPath, getCoursePath, getLessonPathFromModule } from '../learn.routes'

import { FccFrame } from './fcc-frame'
import { FccSidebar } from './fcc-sidebar'
import { TitleNav } from './title-nav'
import styles from './FreeCodeCamp.module.scss'
import { LearnConfig } from '../learn-config'

const FreeCodeCamp: FC<{}> = () => {

Expand All @@ -66,6 +68,11 @@ const FreeCodeCamp: FC<{}> = () => {
const [lessonParam, setLessonParam]: [string, Dispatch<SetStateAction<string>>]
= useState(textFormatGetSafeString(routeParams.lesson))

const [showSurvey, setShowSurvey]: [
string,
Dispatch<SetStateAction<string>>
] = useShowSurvey()

const {
certificationProgress: certificateProgress,
setCertificateProgress,
Expand Down Expand Up @@ -235,7 +242,6 @@ const FreeCodeCamp: FC<{}> = () => {
currentLesson,
)
.then((progress: LearnUserCertificationProgress) => {

setCertificateProgress(progress)
handleSurvey(certWasInProgress, progress)

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

/**
Expand Down Expand Up @@ -450,6 +454,17 @@ const FreeCodeCamp: FC<{}> = () => {
isLoggedIn,
])

useEffect(() => {
if (ready && showSurvey === certificationParam) {
surveyTriggerForUser(LearnConfig.SURVEY.COMPLETED_FIRST_MODULE, profile?.userId)
setShowSurvey('')
}
}, [
ready,
showSurvey,
certificationParam,
]);

return (
<>
<LoadingSpinner hide={ready} />
Expand Down
3 changes: 3 additions & 0 deletions src-ts/tools/learn/learn-config/learn-config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export interface LearnConfigModel {
value: string,
}
CLIENT: string
SURVEY: {
COMPLETED_FIRST_MODULE: string
}
}
3 changes: 3 additions & 0 deletions src-ts/tools/learn/learn-config/learn.default.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ export const LearnConfigDefault: LearnConfigModel = {
value: 'certificate-container',
},
CLIENT: 'https://fcc.topcoder-dev.com:4431',
SURVEY: {
COMPLETED_FIRST_MODULE: 'TCA First Module Completed',
}
}
1 change: 1 addition & 0 deletions src-ts/tools/learn/learn-lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export * from './data-providers'
export * from './learn-breadcrumb-provider'
export * from './learn-swr'
export * from './my-course-card'
export * from './survey'
export * from './svgs'
export * from './wave-hero'
1 change: 1 addition & 0 deletions src-ts/tools/learn/learn-lib/survey/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './use-show-survey'
9 changes: 9 additions & 0 deletions src-ts/tools/learn/learn-lib/survey/use-show-survey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Dispatch, SetStateAction } from "react"
import { useLocalStorage } from "../../../../lib"

export const useShowSurvey = (): [
string,
Dispatch<SetStateAction<string>>
] => {
return useLocalStorage<string>('tca-show-survey', '');
}