diff --git a/src-ts/config/environments/environment.default.config.ts b/src-ts/config/environments/environment.default.config.ts index f13c4b38d..df2a0d870 100644 --- a/src-ts/config/environments/environment.default.config.ts +++ b/src-ts/config/environments/environment.default.config.ts @@ -16,7 +16,6 @@ export const EnvironmentConfigDefault: GlobalConfig = { V5: 'https://api.topcoder-dev.com/v5', }, ENV: AppHostEnvironment.default, - LEARN_SRC: 'https://fcc.topcoder-dev.com:4431', LOGGING: { PUBLIC_TOKEN: 'puba0825671e469d16f940c5a30dc738f11', SERVICE: 'platform-ui', diff --git a/src-ts/config/environments/environment.dev.config.ts b/src-ts/config/environments/environment.dev.config.ts index 2bebd3fdc..90321d253 100644 --- a/src-ts/config/environments/environment.dev.config.ts +++ b/src-ts/config/environments/environment.dev.config.ts @@ -12,7 +12,6 @@ export const EnvironmentConfigDev: GlobalConfig = { }, DISABLED_TOOLS: [], ENV: AppHostEnvironment.dev, - LEARN_SRC: 'https://freecodecamp.topcoder-dev.com', // TODO: Move stripe creds to .env file STRIPE: { ADMIN_TOKEN: diff --git a/src-ts/config/environments/environment.prod.config.ts b/src-ts/config/environments/environment.prod.config.ts index e1badd2fc..8c2300170 100644 --- a/src-ts/config/environments/environment.prod.config.ts +++ b/src-ts/config/environments/environment.prod.config.ts @@ -19,7 +19,6 @@ export const EnvironmentConfigProd: GlobalConfig = { }, DISABLED_TOOLS: [ ], ENV: AppHostEnvironment.prod, - LEARN_SRC: 'https://freecodecamp.topcoder.com', // TODO: Move stripe creds to .env file STRIPE: { ADMIN_TOKEN: diff --git a/src-ts/config/environments/index.ts b/src-ts/config/environments/index.ts index 77ac1fb73..d16f89f8a 100644 --- a/src-ts/config/environments/index.ts +++ b/src-ts/config/environments/index.ts @@ -1 +1,2 @@ +export * from './app-host-environment.enum' export { default as EnvironmentConfig } from './environment.config' diff --git a/src-ts/lib/global-config.model.ts b/src-ts/lib/global-config.model.ts index cbd027053..ddf9b8ce4 100644 --- a/src-ts/lib/global-config.model.ts +++ b/src-ts/lib/global-config.model.ts @@ -11,7 +11,6 @@ export interface GlobalConfig { } DISABLED_TOOLS?: Array ENV: string - LEARN_SRC: string, LOGGING: { PUBLIC_TOKEN: string SERVICE: string diff --git a/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx b/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx index 0208cd571..407eb0f54 100644 --- a/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx +++ b/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx @@ -45,15 +45,15 @@ import { TitleNav } from './title-nav' const FreeCodeCamp: FC<{}> = () => { const { - profile, initialized: profileReady, + isLoggedIn, + profile, }: ProfileContextData = useContext(profileContext) - const isLoggedIn: boolean = !!profile const navigate: NavigateFunction = useNavigate() const routeParams: Params = useParams() - const providerParam: string = routeParams.provider ?? '' + const [certificationParam, setCourseParam]: [string, Dispatch>] = useState(routeParams.certification ?? '') const [moduleParam, setModuleParam]: [string, Dispatch>] = useState(routeParams.module ?? '') const [lessonParam, setLessonParam]: [string, Dispatch>] = useState(routeParams.lesson ?? '') @@ -178,7 +178,8 @@ const FreeCodeCamp: FC<{}> = () => { lesson.course.certificationId, lesson.course.id, currentLesson - ).then(setCertificateProgress) + ) + .then(setCertificateProgress) } else { // TODO: remove this delay!! // TEMP_FIX: delay this api call to allow for previous "completeLesson" call to write in the api @@ -297,7 +298,7 @@ const FreeCodeCamp: FC<{}> = () => { if (lessonPath !== lessonParam) { setLessonParam(lessonPath) } - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, [ // DO NOT UPDATE THIS DEPS ARRAY!! // we do not care about changes to the other deps diff --git a/src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx b/src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx index 43127f620..139b87182 100755 --- a/src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx +++ b/src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx @@ -1,6 +1,6 @@ import { FC, memo, MutableRefObject, useEffect, useRef } from 'react' -import { EnvironmentConfig } from '../../../../config' +import { LearnConfig } from '../../learn-config' import { LearnLessonMeta } from '../../learn-lib' import styles from './FccFrame.module.scss' @@ -33,14 +33,14 @@ const FccFrame: FC = (props: FccFrameProps) => { } if (!frameIsReady.current) { - Object.assign(frameRef.current, { src: `${EnvironmentConfig.LEARN_SRC}/${props.lesson.lessonUrl}` }) + Object.assign(frameRef.current, { src: `${LearnConfig.CLIENT}/${props.lesson.lessonUrl}` }) } else { frameRef.current.contentWindow.postMessage(JSON.stringify({ data: { path: `/${lessonUrl}` }, event: 'fcc:url:update', }), '*') } - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, [ lessonUrl, ]) @@ -52,7 +52,7 @@ const FccFrame: FC = (props: FccFrameProps) => { const handleEvent: (event: any) => void = (event: any) => { const { data: jsonData, origin }: { data: string, origin: string } = event - if (origin.indexOf(EnvironmentConfig.LEARN_SRC) === -1) { + if (origin.indexOf(LearnConfig.CLIENT) === -1) { return } diff --git a/src-ts/tools/learn/learn-config/index.ts b/src-ts/tools/learn/learn-config/index.ts new file mode 100644 index 000000000..c7fcedcee --- /dev/null +++ b/src-ts/tools/learn/learn-config/index.ts @@ -0,0 +1 @@ +export { default as LearnConfig } from './learn.config' diff --git a/src-ts/tools/learn/learn-config/learn-config.model.ts b/src-ts/tools/learn/learn-config/learn-config.model.ts new file mode 100644 index 000000000..783fe51ff --- /dev/null +++ b/src-ts/tools/learn/learn-config/learn-config.model.ts @@ -0,0 +1,4 @@ +export interface LearnConfigModel { + API: string + CLIENT: string +} diff --git a/src-ts/tools/learn/learn-config/learn.bsouza.config.ts b/src-ts/tools/learn/learn-config/learn.bsouza.config.ts new file mode 100644 index 000000000..d9d1241b3 --- /dev/null +++ b/src-ts/tools/learn/learn-config/learn.bsouza.config.ts @@ -0,0 +1,6 @@ +import { LearnConfigModel } from './learn-config.model' +import { LearnConfigDefault } from './learn.default.config' + +export const LearnConfigBsouza: LearnConfigModel = { + ...LearnConfigDefault, +} diff --git a/src-ts/tools/learn/learn-config/learn.config.ts b/src-ts/tools/learn/learn-config/learn.config.ts new file mode 100644 index 000000000..c11e111ac --- /dev/null +++ b/src-ts/tools/learn/learn-config/learn.config.ts @@ -0,0 +1,31 @@ +import { AppHostEnvironment } from '../../../config' + +import { LearnConfigModel } from './learn-config.model' +import { LearnConfigBsouza } from './learn.bsouza.config' +import { LearnConfigDefault } from './learn.default.config' +import { LearnConfigDev } from './learn.dev.config' +import { LearnConfigProd } from './learn.prod.config' + +function getConfig(): LearnConfigModel { + + switch (process.env.REACT_APP_HOST_ENV) { + + case AppHostEnvironment.bsouza: + return LearnConfigBsouza + + case AppHostEnvironment.dev: + return LearnConfigDev + + case AppHostEnvironment.prod: + return LearnConfigProd + + default: + return LearnConfigDefault + } +} + +const LearnConfig: LearnConfigModel = { + ...getConfig(), +} + +export default LearnConfig diff --git a/src-ts/tools/learn/learn-config/learn.default.config.ts b/src-ts/tools/learn/learn-config/learn.default.config.ts new file mode 100644 index 000000000..36ca36697 --- /dev/null +++ b/src-ts/tools/learn/learn-config/learn.default.config.ts @@ -0,0 +1,6 @@ +import { LearnConfigModel } from './learn-config.model' + +export const LearnConfigDefault: LearnConfigModel = { + API: 'http://localhost:3001/v5/learning-paths', + CLIENT: 'https://fcc.topcoder-dev.com:4431', +} diff --git a/src-ts/tools/learn/learn-config/learn.dev.config.ts b/src-ts/tools/learn/learn-config/learn.dev.config.ts new file mode 100644 index 000000000..8ee03c5fe --- /dev/null +++ b/src-ts/tools/learn/learn-config/learn.dev.config.ts @@ -0,0 +1,6 @@ +import { LearnConfigModel } from './learn-config.model' + +export const LearnConfigDev: LearnConfigModel = { + API: 'https://api.topcoder-dev.com/v5/learning-paths', + CLIENT: 'https://freecodecamp.topcoder-dev.com', +} diff --git a/src-ts/tools/learn/learn-config/learn.prod.config.ts b/src-ts/tools/learn/learn-config/learn.prod.config.ts new file mode 100644 index 000000000..ab162a8f8 --- /dev/null +++ b/src-ts/tools/learn/learn-config/learn.prod.config.ts @@ -0,0 +1,6 @@ +import { LearnConfigModel } from './learn-config.model' + +export const LearnConfigProd: LearnConfigModel = { + API: 'https://api.topcoder.com/v5/learning-paths', + CLIENT: 'https://freecodecamp.topcoder.com', +} diff --git a/src-ts/tools/learn/learn-lib/all-certifications-provider/all-certifications-functions/all-certifications.store.ts b/src-ts/tools/learn/learn-lib/all-certifications-provider/all-certifications-functions/all-certifications.store.ts index e42c28e5f..e2bff31be 100755 --- a/src-ts/tools/learn/learn-lib/all-certifications-provider/all-certifications-functions/all-certifications.store.ts +++ b/src-ts/tools/learn/learn-lib/all-certifications-provider/all-certifications-functions/all-certifications.store.ts @@ -1,5 +1,5 @@ import { xhrGetAsync } from '../../../../../lib/functions' -import { getPath } from '../../learn-url.config' +import { learnUrlGet } from '../../functions' import { LearnCertification } from './learn-certification.model' @@ -7,9 +7,11 @@ export function getAsync( providerName: string = 'freeCodeCamp', certificationId?: string ): Promise> { - return xhrGetAsync>(getPath( + + const url: string = learnUrlGet( 'certifications', ...(certificationId ? [certificationId] : []), `?providerName=${providerName}` - )) + ) + return xhrGetAsync>(url) } diff --git a/src-ts/tools/learn/learn-lib/courses-provider/courses-functions/course.store.ts b/src-ts/tools/learn/learn-lib/courses-provider/courses-functions/course.store.ts index 188007aed..5f9f5e817 100755 --- a/src-ts/tools/learn/learn-lib/courses-provider/courses-functions/course.store.ts +++ b/src-ts/tools/learn/learn-lib/courses-provider/courses-functions/course.store.ts @@ -1,11 +1,13 @@ -import { xhrGetAsync } from '../../../../../lib/functions' -import { getPath } from '../../learn-url.config' +import { xhrGetAsync } from '../../../../../lib' +import { learnUrlGet } from '../../functions' import { LearnCourse } from './learn-course.model' -export function getCourseAsync(provider: string, certification: string): Promise { - return xhrGetAsync>(getPath( - 'courses', - `?certification=${certification}&provider=${provider}`, - )).then(courses => courses[0]) +export function getAsync(provider: string, certification: string): + Promise { + + const url: string = learnUrlGet('courses', `?certification=${certification}&provider=${provider}`) + + return xhrGetAsync>(url) + .then(courses => courses[0]) } diff --git a/src-ts/tools/learn/learn-lib/courses-provider/courses-functions/index.ts b/src-ts/tools/learn/learn-lib/courses-provider/courses-functions/index.ts index 44fa2a116..e6c6a0a63 100755 --- a/src-ts/tools/learn/learn-lib/courses-provider/courses-functions/index.ts +++ b/src-ts/tools/learn/learn-lib/courses-provider/courses-functions/index.ts @@ -1,2 +1,2 @@ -export * from './course.store' +export { getAsync as courseGetAsync } from './course.store' export * from './learn-course.model' diff --git a/src-ts/tools/learn/learn-lib/courses-provider/courses.provider.tsx b/src-ts/tools/learn/learn-lib/courses-provider/courses.provider.tsx index 8b8ebe630..5c001c51f 100644 --- a/src-ts/tools/learn/learn-lib/courses-provider/courses.provider.tsx +++ b/src-ts/tools/learn/learn-lib/courses-provider/courses.provider.tsx @@ -1,6 +1,6 @@ import { Dispatch, SetStateAction, useEffect, useState } from 'react' -import { getCourseAsync } from './courses-functions' +import { courseGetAsync } from './courses-functions' import { CoursesProviderData } from './courses-provider-data.model' export function useCourses(provider: string, certification?: string): CoursesProviderData { @@ -32,7 +32,7 @@ export function useCourses(provider: string, certification?: string): CoursesPro loading: true, })) - getCourseAsync(provider, certification) + courseGetAsync(provider, certification) .then((course) => { if (!mounted) { return diff --git a/src-ts/tools/learn/learn-lib/functions/index.ts b/src-ts/tools/learn/learn-lib/functions/index.ts new file mode 100644 index 000000000..17d368232 --- /dev/null +++ b/src-ts/tools/learn/learn-lib/functions/index.ts @@ -0,0 +1 @@ +export { get as learnUrlGet } from './learn-url.functions' diff --git a/src-ts/tools/learn/learn-lib/functions/learn-url.functions.ts b/src-ts/tools/learn/learn-lib/functions/learn-url.functions.ts new file mode 100755 index 000000000..492d60c5d --- /dev/null +++ b/src-ts/tools/learn/learn-lib/functions/learn-url.functions.ts @@ -0,0 +1,10 @@ +import { LearnConfig } from '../../learn-config' + +export function get(...parts: Array): string { + return [ + LearnConfig.API, + ...parts, + ] + .filter(Boolean) + .join('/') +} diff --git a/src-ts/tools/learn/learn-lib/learn-url.config.ts b/src-ts/tools/learn/learn-lib/learn-url.config.ts deleted file mode 100755 index bd7b41d02..000000000 --- a/src-ts/tools/learn/learn-lib/learn-url.config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { EnvironmentConfig } from '../../../config' - -export function getPath(...parts: Array): string { - return [learnPath, ...parts].filter(Boolean).join('/') -} - -const learnPath: string = `${EnvironmentConfig.API.V5}/learning-paths` diff --git a/src-ts/tools/learn/learn-lib/lesson-provider/lesson.provider.tsx b/src-ts/tools/learn/learn-lib/lesson-provider/lesson.provider.tsx index 0e692a798..3a42f0a11 100644 --- a/src-ts/tools/learn/learn-lib/lesson-provider/lesson.provider.tsx +++ b/src-ts/tools/learn/learn-lib/lesson-provider/lesson.provider.tsx @@ -1,6 +1,6 @@ import { Dispatch, SetStateAction, useEffect, useState } from 'react' -import { getCourseAsync } from '../courses-provider/courses-functions' +import { courseGetAsync } from '../courses-provider' import { LearnLesson } from './learn-lesson.model' import { LearnModule } from './learn-module.model' @@ -35,43 +35,45 @@ export function useLessonProvider( loading: true, })) - getCourseAsync(provider, course).then((courseData) => { - if (!mounted) { - return - } + courseGetAsync(provider, course) + .then((courseData) => { - const moduleData: LearnModule|undefined = courseData?.modules.find(m => m.key === module) - const lessonData: LearnLesson|undefined = moduleData?.lessons.find(l => l.dashedName === lesson) + if (!mounted) { + return + } - const lessonUrl: string = [ - 'learn', - courseData?.key ?? course, - module, - lesson, - ].filter(Boolean).join('/') + const moduleData: LearnModule | undefined = courseData?.modules.find(m => m.key === module) + const lessonData: LearnLesson | undefined = moduleData?.lessons.find(l => l.dashedName === lesson) - setState((prevState) => ({ - ...prevState, - lesson: lessonData && { - ...lessonData, - course: { - certification: courseData?.certification ?? '', - certificationId: courseData?.certificationId ?? '', - id: courseData?.id ?? '', - title: courseData?.title ?? '', - }, - lessonUrl, - module: { - dashedName: moduleData?.meta.dashedName ?? '', - title: moduleData?.meta.name ?? '', + const lessonUrl: string = [ + 'learn', + courseData?.key ?? course, + module, + lesson, + ].filter(Boolean).join('/') + + setState((prevState) => ({ + ...prevState, + lesson: lessonData && { + ...lessonData, + course: { + certification: courseData?.certification ?? '', + certificationId: courseData?.certificationId ?? '', + id: courseData?.id ?? '', + title: courseData?.title ?? '', + }, + lessonUrl, + module: { + dashedName: moduleData?.meta.dashedName ?? '', + title: moduleData?.meta.name ?? '', + }, }, - }, - loading: false, - ready: true, - })) - }) + loading: false, + ready: true, + })) + }) - return () => {mounted = false} + return () => { mounted = false } }, [provider, course, module, lesson]) return state diff --git a/src-ts/tools/learn/learn-lib/resource-provider-provider/resource-provider-functions/resource-provider.store.ts b/src-ts/tools/learn/learn-lib/resource-provider-provider/resource-provider-functions/resource-provider.store.ts index e93341bd7..c651b9d0f 100755 --- a/src-ts/tools/learn/learn-lib/resource-provider-provider/resource-provider-functions/resource-provider.store.ts +++ b/src-ts/tools/learn/learn-lib/resource-provider-provider/resource-provider-functions/resource-provider.store.ts @@ -1,10 +1,10 @@ import { xhrGetAsync } from '../../../../../lib/functions' -import { getPath } from '../../learn-url.config' +import { learnUrlGet } from '../../functions' import { ResourceProvider } from './resource-provider.model' -export function getResourceProvidersAsync(): Promise|undefined> { - return xhrGetAsync>(getPath( - 'providers' - )) +export function getResourceProvidersAsync(): Promise | undefined> { + + const url: string = learnUrlGet('providers') + return xhrGetAsync>(url) } diff --git a/src-ts/tools/learn/learn-lib/user-certifications-provider/user-certifications-functions/user-certification-progress.store.ts b/src-ts/tools/learn/learn-lib/user-certifications-provider/user-certifications-functions/user-certification-progress.store.ts index 660960090..0cc827b42 100755 --- a/src-ts/tools/learn/learn-lib/user-certifications-provider/user-certifications-functions/user-certification-progress.store.ts +++ b/src-ts/tools/learn/learn-lib/user-certifications-provider/user-certifications-functions/user-certification-progress.store.ts @@ -1,33 +1,39 @@ import { xhrGetAsync, xhrPostAsync, xhrPutAsync } from '../../../../../lib/functions' -import { getPath } from '../../learn-url.config' +import { learnUrlGet } from '../../functions' import { LearnUserCertificationProgress } from './learn-user-certification-progress.model' import { UserCertificationUpdateProgressActions } from './user-certification-update-progress-actions.enum' +const certProgressPath: string = 'certification-progresses' + export function getAsync(userId: number, provider?: string, certification?: string): Promise> { - return xhrGetAsync>(getPath( - 'certification-progresses', - [ - `?userId=${userId}`, - provider && `provider=${provider}`, - certification && `certification=${certification}`, - ].filter(Boolean).join('&'), - )) + + const params: string = [ + `?userId=${userId}`, + provider && `provider=${provider}`, + certification && `certification=${certification}`, + ] + .filter(Boolean) + .join('&') + + const url: string = learnUrlGet(certProgressPath, params) + + return xhrGetAsync>(url) } export function startAsync(userId: number, certificationId: string, courseId: string, data: any): Promise { - return xhrPostAsync<{}, LearnUserCertificationProgress>(getPath( - 'certification-progresses', - `${userId}`, - certificationId, - courseId, - ), {}, {params: data}) + + const url: string = learnUrlGet(certProgressPath, `${userId}`, certificationId, courseId) + return xhrPostAsync<{}, LearnUserCertificationProgress>(url, {}, { params: data }) } -export function updateAsync(certificationProgressId: string, action: UserCertificationUpdateProgressActions, data: any): Promise { - return xhrPutAsync<{}, LearnUserCertificationProgress>(getPath( - 'certification-progresses', - certificationProgressId, - action - ), {}, {params: data}) +export function updateAsync( + certificationProgressId: string, + action: UserCertificationUpdateProgressActions, + data: any +): Promise { + + const url: string = learnUrlGet(certProgressPath, certificationProgressId, action) + + return xhrPutAsync<{}, LearnUserCertificationProgress>(url, {}, { params: data }) } diff --git a/src-ts/tools/learn/learn-lib/user-completed-certifications-provider/user-completed-certifications-functions/user-completed-certification.store.ts b/src-ts/tools/learn/learn-lib/user-completed-certifications-provider/user-completed-certifications-functions/user-completed-certification.store.ts index 7c445ead7..96e844d21 100644 --- a/src-ts/tools/learn/learn-lib/user-completed-certifications-provider/user-completed-certifications-functions/user-completed-certification.store.ts +++ b/src-ts/tools/learn/learn-lib/user-completed-certifications-provider/user-completed-certifications-functions/user-completed-certification.store.ts @@ -1,11 +1,10 @@ import { xhrGetAsync } from '../../../../../lib/functions' -import { getPath } from '../../learn-url.config' +import { learnUrlGet } from '../../functions' import { LearnUserCompletedCertification } from './user-completed-certification.model' export function getAsync(userId: number): Promise> { - return xhrGetAsync>(getPath( - 'completed-certifications', - `${userId}`, - )) + + const url: string = learnUrlGet('completed-certifications', `${userId}`) + return xhrGetAsync>(url) }