Skip to content

Commit a0bad7d

Browse files
authored
Merge pull request #497 from topcoder-platform/TCA-955-updates
TCA-955 short URLs support via `completionUuid`
2 parents 9b086f4 + d67c036 commit a0bad7d

File tree

9 files changed

+61
-24
lines changed

9 files changed

+61
-24
lines changed

src-ts/tools/learn/learn-lib/data-providers/tca-certifications-provider/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export * from './tca-certification'
1616
export * from './tca-certification-progress'
1717
export * from './tca-certification-enrollment-base.model'
1818
export * from './tca-certification-validation'
19+
export * from './tca-certification-enrollment'

src-ts/tools/learn/learn-lib/data-providers/tca-certifications-provider/tca-certification-enrollment-base.model.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import { TCACertification } from './tca-certification.model'
2+
13
export interface TCACertificationEnrollmentBase {
24
id: number
35
topcoderCertificationId: number
6+
topcoderCertification?: TCACertification
47
userId: string
58
userHandle: string
69
userName: string
710
status: 'enrolled'
8-
completedAt: null | Date
11+
completedAt: null | Date | string
912
completionUuid: undefined | null | string
1013
createdAt: Date
1114
updatedAt: Date
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './tca-enrollment-provider'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import useSWR, { SWRConfiguration, SWRResponse } from 'swr'
2+
3+
import { learnUrlGet } from '../../../functions'
4+
import { useSwrCache } from '../../../learn-swr'
5+
import { TCACertificationEnrollmentProviderData } from '../tca-certification-progress'
6+
7+
export function useTCACertificationEnrollment(
8+
id: string, // note id | completionUuid both are supported by the API
9+
): TCACertificationEnrollmentProviderData {
10+
11+
const url: string = learnUrlGet(
12+
'certification-enrollment',
13+
id,
14+
)
15+
16+
const swrCacheConfig: SWRConfiguration = useSwrCache(url)
17+
18+
const { data, error }: SWRResponse = useSWR(url, {
19+
...swrCacheConfig,
20+
})
21+
22+
return {
23+
enrollment: data,
24+
error: !!error,
25+
loading: !data,
26+
ready: !!data,
27+
}
28+
}

src-ts/tools/learn/learn-lib/data-providers/tca-certifications-provider/tca-certification-progress/tca-certification-progress-data.model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { TCACertificationEnrollmentBase } from '../tca-certification-enrollment-base.model'
2+
13
import { TCACertificationProgress } from './tca-certification-progress.model'
24

35
export interface TCACertificationProgressProviderData {
@@ -10,7 +12,7 @@ export interface TCACertificationProgressProviderData {
1012
}
1113

1214
export interface TCACertificationEnrollmentProviderData {
13-
enrollment: TCACertificationProgress | undefined
15+
enrollment: TCACertificationEnrollmentBase | TCACertificationProgress | undefined
1416
error: boolean
1517
loading: boolean
1618
ready: boolean

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ export function getUserTCACertificateUrl(
127127
}
128128

129129
export function getTCACertificationValidationUrl(
130-
certification: string,
131-
handle: string,
130+
completionUuid: string,
132131
): string {
133-
return `${EnvironmentConfig.TOPCODER_URLS.TCA}/${LEARN_PATHS.tcaCertifications}/${certification}/${handle}`
132+
return `${EnvironmentConfig.TOPCODER_URLS.TCA}/${LEARN_PATHS.root}/${completionUuid}`
134133
}
135134

136135
export function getAuthenticateAndEnrollRoute(): string {
@@ -209,8 +208,8 @@ export const learnRoutes: ReadonlyArray<PlatformRoute> = [
209208
{
210209
children: [],
211210
element: <ValidateTCACertificate />,
212-
id: 'Validate TCA Certification',
213-
route: 'tca-certifications/:certification/:memberHandle',
211+
id: 'Validate TCA Certification - aka hiring manager view',
212+
route: ':completionUuid',
214213
},
215214
],
216215
element: <LandingLearn />,

src-ts/tools/learn/tca-certificate/certificate-view/CertificateView.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)
100100

101101
const handlePrint: () => Promise<void> = useCertificatePrint(certificateElRef, certificationTitle)
102102

103-
// TODO: update this to use `completionUuid`
104-
const validateLink: string = getTCACertificationValidationUrl(props.certification, props.profile.handle)
103+
const validateLink: string = getTCACertificationValidationUrl(enrollment?.completionUuid as string)
105104

106105
const handleLinkClick: () => void = useCallback(() => {
107106
window.open(validateLink, 'blank')
@@ -137,7 +136,7 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)
137136
completionUuid={enrollment?.completionUuid}
138137
userName={enrollment?.userName}
139138
tcHandle={props.profile.handle}
140-
completedDate={completedCertificate?.completedDate ?? ''}
139+
completedDate={enrollment?.completedAt as string}
141140
elRef={certificateElRef}
142141
validateLink={validateLink}
143142
viewStyle={props.viewStyle}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const Certificate: FC<CertificateProps> = (props: CertificateProps) => {
2727

2828
const displaySignature: boolean = props.displaySignature ?? true
2929

30+
const completedDate: string = moment(props.completedDate || new Date())
31+
.format('MMM D, YYYY')
32+
3033
// TODO: revisit this when certs expirations are defined, now just +1 year
3134
const expireDate: string = moment(props.completedDate || new Date())
3235
.add(1, 'year')
@@ -76,7 +79,7 @@ const Certificate: FC<CertificateProps> = (props: CertificateProps) => {
7679
/>
7780
<div className={styles.certInfoLeftData}>
7881
<span>Date of certification</span>
79-
<span className='ultra-small-medium'>{props.completedDate}</span>
82+
<span className='ultra-small-medium'>{completedDate}</span>
8083
<span>Valid through</span>
8184
<span className={classNames('ultra-small-medium', styles.gridSeparator)}>
8285
{expireDate}

src-ts/tools/learn/tca-certificate/validate-certificate/ValidateTCACertificate.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import {
1616
import {
1717
CourseBadge,
1818
TCACertificateType,
19-
TCACertificationValidationData,
20-
useValidateTCACertification,
19+
TCACertification,
20+
TCACertificationEnrollmentProviderData,
21+
useTCACertificationEnrollment,
2122
} from '../../learn-lib'
2223
import { EnvironmentConfig } from '../../../../config'
2324
import { Certificate } from '../certificate-view/certificate'
@@ -36,13 +37,13 @@ const ValidateTCACertificate: FC<{}> = () => {
3637

3738
const [profileReady, setProfileReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
3839

39-
// Fetch Enrollment status & progress
4040
const {
41-
certification,
4241
enrollment,
4342
ready: certReady,
44-
}: TCACertificationValidationData
45-
= useValidateTCACertification(routeParams.certification as string, routeParams.memberHandle as string)
43+
}: TCACertificationEnrollmentProviderData
44+
= useTCACertificationEnrollment(routeParams.completionUuid as string)
45+
46+
const certification: TCACertification | undefined = enrollment?.topcoderCertification
4647

4748
const courses: any = certification?.certificationResources
4849

@@ -51,25 +52,25 @@ const ValidateTCACertificate: FC<{}> = () => {
5152

5253
const coursesGridItems: ReactNode[] | undefined
5354
= useMemo(() => courses?.map((course: any) => (
54-
<div className={styles.courseCard}>
55+
<div className={styles.courseCard} key={course.freeCodeCampCertification.fccId}>
5556
<CourseBadge type={certification?.certificationCategory.track as TCACertificateType} />
5657
<p className='body-main-bold'>{course.freeCodeCampCertification.title}</p>
5758
</div>
5859
)), [courses, certification])
5960

6061
// TODO: update this to use `completionUuid`
6162
const validateLink: string
62-
= getTCACertificationValidationUrl(routeParams.certification as string, routeParams.memberHandle as string)
63+
= getTCACertificationValidationUrl(routeParams.completionUuid as string)
6364

6465
useEffect(() => {
65-
if (routeParams.memberHandle) {
66-
profileGetPublicAsync(routeParams.memberHandle)
66+
if (enrollment?.userHandle) {
67+
profileGetPublicAsync(enrollment.userHandle)
6768
.then(userProfile => {
6869
setProfile(userProfile)
6970
setProfileReady(true)
7071
})
7172
}
72-
}, [routeParams.memberHandle, setProfileReady])
73+
}, [enrollment, setProfileReady])
7374

7475
function visitFullProfile(): void {
7576
window.open(`${EnvironmentConfig.TOPCODER_URLS.USER_PROFILE}/${profile?.handle}`, '_blank')
@@ -84,7 +85,6 @@ const ValidateTCACertificate: FC<{}> = () => {
8485
<div
8586
className={classNames(
8687
styles.hero,
87-
// TODO: check on API response if category is expanded
8888
styles[`hero-${certification.certificationCategory?.track.toLowerCase() || 'dev'}`],
8989
)}
9090
>
@@ -127,8 +127,9 @@ const ValidateTCACertificate: FC<{}> = () => {
127127
<div className={styles.heroCert}>
128128
<Certificate
129129
certification={certification}
130-
completedDate={enrollment?.completedAt as unknown as string || '1.1.2023'}
130+
completedDate={enrollment?.completedAt as unknown as string}
131131
userName={enrollment?.userName}
132+
completionUuid={routeParams.completionUuid}
132133
validateLink={validateLink}
133134
viewStyle='small-container'
134135
/>

0 commit comments

Comments
 (0)