Skip to content

Commit 2e8c595

Browse files
authored
Merge pull request #302 from topcoder-platform/TCA-318_trigger-cert
TCA-318 Trigger Cert Image Generation on Course Completion -> dev
2 parents d572ed0 + 3ee6df6 commit 2e8c595

File tree

8 files changed

+82
-24
lines changed

8 files changed

+82
-24
lines changed

src-ts/tools/learn/course-certificate/certificate-view/certificate/Certificate.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import classNames from 'classnames'
22
import { FC, MutableRefObject } from 'react'
33

4+
import { LearnConfig } from '../../../learn-config'
45
import { LearnCertificateTrackType } from '../../../learn-lib'
56

67
import { CertificateBgPattern } from './certificate-bg-pattern'
@@ -13,18 +14,27 @@ import { ReactComponent as FccLogoSvg } from './vendor-fcc-logo.svg'
1314
interface CertificateProps {
1415
completedDate?: string
1516
course?: string
16-
elRef?: MutableRefObject<HTMLElement|any>
17+
elRef?: MutableRefObject<HTMLElement | any>
1718
provider?: string
1819
tcHandle?: string
1920
type?: LearnCertificateTrackType
2021
userName?: string
2122
}
2223

2324
const Certificate: FC<CertificateProps> = (props: CertificateProps) => {
25+
2426
const certificateType: LearnCertificateTrackType = props.type ?? 'DEV'
2527

28+
const elementSelector: { [attr: string]: string } = {
29+
[LearnConfig.CERT_ELEMENT_SELECTOR.attribute]: LearnConfig.CERT_ELEMENT_SELECTOR.value,
30+
}
31+
2632
return (
27-
<div className={styles['wrap']} ref={props.elRef}>
33+
<div
34+
{...elementSelector}
35+
className={styles['wrap']}
36+
ref={props.elRef}
37+
>
2838
<div className={classNames(styles['details'], `theme-${certificateType.toLowerCase()}`)}>
2939
<h2 className='details grad'>Topcoder Academy</h2>
3040
<h3>Certificate of Course Completion</h3>

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
useCourses,
2828
useLearnBreadcrumb,
2929
useLessonProvider,
30+
userCertificationProgressCompleteCourseAsync,
3031
UserCertificationProgressProviderData,
3132
userCertificationProgressStartAsync,
3233
UserCertificationProgressStatus,
@@ -257,26 +258,34 @@ const FreeCodeCamp: FC<{}> = () => {
257258
}
258259

259260
useEffect(() => {
261+
262+
// if we don't yet have the user's handle,
263+
// or if the cert isn't complete,
264+
// or the cert isn't in progress,
265+
// there's nothing to do
260266
if (
261-
certificateProgress &&
262-
certificateProgress.certificationProgressPercentage === 100 &&
263-
certificateProgress.status === UserCertificationProgressStatus.inProgress
267+
!profile?.handle
268+
|| certificateProgress?.certificationProgressPercentage !== 100
269+
|| certificateProgress?.status !== UserCertificationProgressStatus.inProgress
264270
) {
265-
userCertificationProgressUpdateAsync(
266-
certificateProgress.id,
267-
UserCertificationUpdateProgressActions.completeCertificate,
268-
{}
269-
)
270-
.then(setCertificateProgress)
271-
.then(() => {
272-
const completedPath: string = getCertificationCompletedPath(
273-
providerParam,
274-
certificationParam
275-
)
276-
277-
navigate(completedPath)
278-
})
271+
return
279272
}
273+
274+
// it's safe to complete the course
275+
userCertificationProgressCompleteCourseAsync(
276+
certificateProgress.id,
277+
certificationParam,
278+
profile.handle,
279+
providerParam,
280+
)
281+
.then(setCertificateProgress)
282+
.then(() => {
283+
const completedPath: string = getCertificationCompletedPath(
284+
providerParam,
285+
certificationParam
286+
)
287+
navigate(completedPath)
288+
})
280289
}, [
281290
certificateProgress,
282291
certificationParam,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
export interface LearnConfigModel {
22
API: string
3+
CERT_ELEMENT_SELECTOR: {
4+
attribute: string,
5+
value: string,
6+
}
37
CLIENT: string
48
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@ import { LearnConfigModel } from './learn-config.model'
22

33
export const LearnConfigDefault: LearnConfigModel = {
44
API: 'http://localhost:3001/v5/learning-paths',
5+
CERT_ELEMENT_SELECTOR: {
6+
attribute: 'data-id',
7+
value: 'certificate-container',
8+
},
59
CLIENT: 'https://fcc.topcoder-dev.com:4431',
610
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { LearnConfigModel } from './learn-config.model'
2+
import { LearnConfigDefault } from './learn.default.config'
23

34
export const LearnConfigDev: LearnConfigModel = {
5+
...LearnConfigDefault,
46
API: 'https://api.topcoder-dev.com/v5/learning-paths',
57
CLIENT: 'https://freecodecamp.topcoder-dev.com',
68
}

src-ts/tools/learn/learn-lib/user-certifications-provider/user-certifications-functions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './learn-module-progress.model'
33
export * from './user-certification-progress-status.enum'
44
export * from './user-certification-update-progress-actions.enum'
55
export {
6+
completeCourse as userCertificationProgressCompleteCourseAsync,
67
getAsync as userCertificationProgressGetAsync,
78
startAsync as userCertificationProgressStartAsync,
89
updateAsync as userCertificationProgressUpdateAsync

src-ts/tools/learn/learn-lib/user-certifications-provider/user-certifications-functions/user-certification-progress.store.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
1+
import { LearnConfig } from '../../../learn-config'
2+
import { getUserCertificatePath } from '../../../learn.routes'
13
import { learnUrlGet, learnXhrGetAsync, learnXhrPostAsync, learnXhrPutAsync } from '../../functions'
24

35
import { LearnUserCertificationProgress } from './learn-user-certification-progress.model'
46
import { UserCertificationUpdateProgressActions } from './user-certification-update-progress-actions.enum'
57

68
const certProgressPath: string = 'certification-progresses'
79

10+
export function completeCourse(
11+
certificationProgressId: string,
12+
certification: string,
13+
handle: string,
14+
provider: string,
15+
): Promise<LearnUserCertificationProgress> {
16+
17+
// construct the certificate params
18+
const certificateElement: string = `[${LearnConfig.CERT_ELEMENT_SELECTOR.attribute}=${LearnConfig.CERT_ELEMENT_SELECTOR.value}]`
19+
const certificateUrl: string = getUserCertificatePath(provider, certification, handle)
20+
21+
return updateAsync(
22+
certificationProgressId,
23+
UserCertificationUpdateProgressActions.completeCertificate,
24+
{
25+
certificateElement,
26+
certificateUrl,
27+
}
28+
)
29+
}
30+
831
export function getAsync(userId: number, provider?: string, certification?: string): Promise<Array<LearnUserCertificationProgress>> {
932

1033
const params: string = [

src-ts/tools/learn/learn.routes.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import { default as Learn, toolTitle } from './Learn'
88
import { MyLearning } from './my-learning'
99
import { WelcomePage } from './welcome'
1010

11+
export function getAuthenticateAndStartCourseRoute(): string {
12+
return `${authUrlLogin()}${encodeURIComponent(`?${LEARN_PATHS.startCourseRouteFlag}`)}`
13+
}
14+
1115
export function getCoursePath(provider: string, certification: string): string {
1216
return `${rootRoute}/${provider}/${certification}`
1317
}
1418

1519
export function getCertificatePath(provider: string, certification: string): string {
16-
return `${getCoursePath(provider, certification)}/certificate`
20+
return `${getCoursePath(provider, certification)}${LEARN_PATHS.certificate}`
1721
}
1822

1923
export function getCertificationCompletedPath(provider: string, certification: string): string {
@@ -40,7 +44,12 @@ export function getLessonPathFromModule(
4044
return `${getCoursePath(provider, certification)}/${module}/${lesson}`
4145
}
4246

47+
export function getUserCertificatePath(provider: string, certification: string, handle: string): string {
48+
return `${window.location.origin}${getCoursePath(provider, certification)}/${handle}${LEARN_PATHS.certificate}`
49+
}
50+
4351
export enum LEARN_PATHS {
52+
certificate = '/certificate',
4453
completed = '/learn/completed',
4554
myCertificate = '/learn/my-certificate',
4655
myLearning = '/learn/my-learning',
@@ -49,10 +58,6 @@ export enum LEARN_PATHS {
4958
startCourseRouteFlag = 'start-course',
5059
}
5160

52-
export function getAuthenticateAndStartCourseRoute(): string {
53-
return `${authUrlLogin()}${encodeURIComponent(`?${LEARN_PATHS.startCourseRouteFlag}`)}`
54-
}
55-
5661
export const rootRoute: string = LEARN_PATHS.root
5762
export const absoluteRootRoute: string = `${window.location.origin}${LEARN_PATHS.root}`
5863

0 commit comments

Comments
 (0)