Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './tca-certification'
export * from './tca-certification-progress'
export * from './tca-certification-enrollment-base.model'
export * from './tca-certification-validation'
export * from './tca-certification-enrollment'
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { TCACertification } from './tca-certification.model'

export interface TCACertificationEnrollmentBase {
id: number
topcoderCertificationId: number
topcoderCertification?: TCACertification
userId: string
userHandle: string
userName: string
status: 'enrolled'
completedAt: null | Date
completedAt: null | Date | string
completionUuid: undefined | null | string
createdAt: Date
updatedAt: Date
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tca-enrollment-provider'
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import useSWR, { SWRConfiguration, SWRResponse } from 'swr'

import { learnUrlGet } from '../../../functions'
import { useSwrCache } from '../../../learn-swr'
import { TCACertificationEnrollmentProviderData } from '../tca-certification-progress'

export function useTCACertificationEnrollment(
id: string, // note id | completionUuid both are supported by the API
): TCACertificationEnrollmentProviderData {

const url: string = learnUrlGet(
'certification-enrollment',
id,
)

const swrCacheConfig: SWRConfiguration = useSwrCache(url)

const { data, error }: SWRResponse = useSWR(url, {
...swrCacheConfig,
})

return {
enrollment: data,
error: !!error,
loading: !data,
ready: !!data,
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TCACertificationEnrollmentBase } from '../tca-certification-enrollment-base.model'

import { TCACertificationProgress } from './tca-certification-progress.model'

export interface TCACertificationProgressProviderData {
Expand All @@ -10,7 +12,7 @@ export interface TCACertificationProgressProviderData {
}

export interface TCACertificationEnrollmentProviderData {
enrollment: TCACertificationProgress | undefined
enrollment: TCACertificationEnrollmentBase | TCACertificationProgress | undefined
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vas3a please take a look at this.
The progress provider you wrote recently needs to be updatated to extend TCACertificationEnrollmentBase in tca-certification-progress.model.ts. It is misleading to call the progress - enrollment.

useTCACertificationEnrollment hook uses that interface thus I added the OR here but we need to remove TCACertificationProgress as there are some lint errors. Not breaking, just FYI.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kkartunov ! TCACertificationEnrollmentProviderData is not used anymore. I need to remove it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, we good now. You can do so in some of your next PRs and clean up, thanks for checking.

error: boolean
loading: boolean
ready: boolean
Expand Down
9 changes: 4 additions & 5 deletions src-ts/tools/learn/learn.routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,9 @@ export function getUserTCACertificateUrl(
}

export function getTCACertificationValidationUrl(
certification: string,
handle: string,
completionUuid: string,
): string {
return `${EnvironmentConfig.TOPCODER_URLS.TCA}/${LEARN_PATHS.tcaCertifications}/${certification}/${handle}`
return `${EnvironmentConfig.TOPCODER_URLS.TCA}/${LEARN_PATHS.root}/${completionUuid}`
}

export function getAuthenticateAndEnrollRoute(): string {
Expand Down Expand Up @@ -209,8 +208,8 @@ export const learnRoutes: ReadonlyArray<PlatformRoute> = [
{
children: [],
element: <ValidateTCACertificate />,
id: 'Validate TCA Certification',
route: 'tca-certifications/:certification/:memberHandle',
id: 'Validate TCA Certification - aka hiring manager view',
route: ':completionUuid',
},
],
element: <LandingLearn />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)

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

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

const handleLinkClick: () => void = useCallback(() => {
window.open(validateLink, 'blank')
Expand Down Expand Up @@ -137,7 +136,7 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)
completionUuid={enrollment?.completionUuid}
userName={enrollment?.userName}
tcHandle={props.profile.handle}
completedDate={completedCertificate?.completedDate ?? ''}
completedDate={enrollment?.completedAt as string}
elRef={certificateElRef}
validateLink={validateLink}
viewStyle={props.viewStyle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const Certificate: FC<CertificateProps> = (props: CertificateProps) => {

const displaySignature: boolean = props.displaySignature ?? true

const completedDate: string = moment(props.completedDate || new Date())
.format('MMM D, YYYY')

// TODO: revisit this when certs expirations are defined, now just +1 year
const expireDate: string = moment(props.completedDate || new Date())
.add(1, 'year')
Expand Down Expand Up @@ -76,7 +79,7 @@ const Certificate: FC<CertificateProps> = (props: CertificateProps) => {
/>
<div className={styles.certInfoLeftData}>
<span>Date of certification</span>
<span className='ultra-small-medium'>{props.completedDate}</span>
<span className='ultra-small-medium'>{completedDate}</span>
<span>Valid through</span>
<span className={classNames('ultra-small-medium', styles.gridSeparator)}>
{expireDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import {
import {
CourseBadge,
TCACertificateType,
TCACertificationValidationData,
useValidateTCACertification,
TCACertification,
TCACertificationEnrollmentProviderData,
useTCACertificationEnrollment,
} from '../../learn-lib'
import { EnvironmentConfig } from '../../../../config'
import { Certificate } from '../certificate-view/certificate'
Expand All @@ -36,13 +37,13 @@ const ValidateTCACertificate: FC<{}> = () => {

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

// Fetch Enrollment status & progress
const {
certification,
enrollment,
ready: certReady,
}: TCACertificationValidationData
= useValidateTCACertification(routeParams.certification as string, routeParams.memberHandle as string)
}: TCACertificationEnrollmentProviderData
= useTCACertificationEnrollment(routeParams.completionUuid as string)

const certification: TCACertification | undefined = enrollment?.topcoderCertification

const courses: any = certification?.certificationResources

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

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

// TODO: update this to use `completionUuid`
const validateLink: string
= getTCACertificationValidationUrl(routeParams.certification as string, routeParams.memberHandle as string)
= getTCACertificationValidationUrl(routeParams.completionUuid as string)

useEffect(() => {
if (routeParams.memberHandle) {
profileGetPublicAsync(routeParams.memberHandle)
if (enrollment?.userHandle) {
profileGetPublicAsync(enrollment.userHandle)
.then(userProfile => {
setProfile(userProfile)
setProfileReady(true)
})
}
}, [routeParams.memberHandle, setProfileReady])
}, [enrollment, setProfileReady])

function visitFullProfile(): void {
window.open(`${EnvironmentConfig.TOPCODER_URLS.USER_PROFILE}/${profile?.handle}`, '_blank')
Expand All @@ -84,7 +85,6 @@ const ValidateTCACertificate: FC<{}> = () => {
<div
className={classNames(
styles.hero,
// TODO: check on API response if category is expanded
styles[`hero-${certification.certificationCategory?.track.toLowerCase() || 'dev'}`],
)}
>
Expand Down Expand Up @@ -127,8 +127,9 @@ const ValidateTCACertificate: FC<{}> = () => {
<div className={styles.heroCert}>
<Certificate
certification={certification}
completedDate={enrollment?.completedAt as unknown as string || '1.1.2023'}
completedDate={enrollment?.completedAt as unknown as string}
userName={enrollment?.userName}
completionUuid={routeParams.completionUuid}
validateLink={validateLink}
viewStyle='small-container'
/>
Expand Down