Skip to content

Commit 27a7fac

Browse files
committed
cleanup unused routes & views, update urls for certificate btn
1 parent 957b150 commit 27a7fac

File tree

9 files changed

+46
-159
lines changed

9 files changed

+46
-159
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function useTCACertificationEnrollment(
3131
enrollment: data,
3232
error: !!error,
3333
loading: !data,
34-
ready: !!data,
34+
ready: !!data || !!error,
3535
}
3636
}
3737

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ const UserCertificate: LazyLoadedComponent = lazyLoad(() => import('./course-cer
2020
const FreeCodeCamp: LazyLoadedComponent = lazyLoad(() => import('./free-code-camp'), 'FreeCodeCamp')
2121
const MyLearning: LazyLoadedComponent = lazyLoad(() => import('./my-learning'), 'MyLearning')
2222
const LandingLearn: LazyLoadedComponent = lazyLoad(() => import('./Learn'))
23-
const MyTCACertificate: LazyLoadedComponent = lazyLoad(() => import('./tca-certificate'), 'MyTCACertificate')
24-
const UserTCACertificate: LazyLoadedComponent = lazyLoad(() => import('./tca-certificate'), 'UserTCACertificate')
23+
const UserTCACertificate: LazyLoadedComponent = lazyLoad(() => import('./tca-certificate'), 'CertificateView')
2524

2625
const ValidateTCACertificate: LazyLoadedComponent
2726
= lazyLoad(() => import('./tca-certificate'), 'UuidCertificationView')
@@ -121,12 +120,6 @@ export function getTCACertificationEnrollPath(certification: string): string {
121120

122121
export function getTCACertificateUrl(
123122
certification: string,
124-
): string {
125-
return `${getTCACertificationPath(certification)}${LEARN_PATHS.certificate}`
126-
}
127-
128-
export function getUserTCACertificateUrl(
129-
certification: string,
130123
handle: string,
131124
): string {
132125
return `${getTCACertificationPath(certification)}/${handle}${LEARN_PATHS.certificate}`
@@ -212,12 +205,6 @@ export const learnRoutes: ReadonlyArray<PlatformRoute> = [
212205
id: 'My Learning',
213206
route: 'my-learning',
214207
},
215-
{
216-
children: [],
217-
element: <MyTCACertificate />,
218-
id: 'My TCA Certification',
219-
route: 'tca-certifications/:certification/certificate',
220-
},
221208
{
222209
children: [],
223210
element: <UserTCACertificate />,

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

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { FC, MutableRefObject, ReactNode, useRef } from 'react'
2+
import { Params, useParams } from 'react-router-dom'
23

3-
import {
4-
LoadingSpinner,
5-
UserProfile,
6-
} from '../../../../lib'
4+
import { LoadingSpinner } from '../../../../lib'
75
import {
86
CertificateNotFoundContent,
97
CertificatePageLayout,
@@ -15,40 +13,46 @@ import {
1513
} from '../../learn-lib'
1614
import { getTCACertificationPath, getTCACertificationValidationUrl, getUserTCACertificateSsr } from '../../learn.routes'
1715
import { CertificateNotFound } from '../certificate-not-found'
16+
import { useGetUserProfile, UseGetUserProfileData } from '../user-certification-view/use-get-user-profile'
1817

19-
interface CertificateViewProps {
20-
certification: string,
21-
fullScreenCertLayout?: boolean,
22-
profile: UserProfile,
23-
}
24-
25-
const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps) => {
18+
const CertificateView: FC<{}> = () => {
2619

27-
const tcaCertificationPath: string = getTCACertificationPath(props.certification)
2820
const certificateElRef: MutableRefObject<HTMLDivElement | any> = useRef()
2921

22+
const routeParams: Params<string> = useParams()
23+
const {
24+
isOwnProfile,
25+
ready: profileReady,
26+
}: UseGetUserProfileData = useGetUserProfile(routeParams.memberHandle)
27+
28+
const userHandle: string = `${routeParams.memberHandle}`
29+
const certificationParam: string = routeParams.certification ?? ''
30+
31+
32+
const tcaCertificationPath: string = getTCACertificationPath(certificationParam)
33+
3034
const {
3135
certification,
3236
enrollment,
3337
error: hasValidationError,
3438
ready,
3539
}: TCACertificationValidationData
36-
= useValidateTCACertification(props.certification, props.profile.handle)
40+
= useValidateTCACertification(certificationParam, userHandle)
3741

3842
const hasCompletedTheCertification: boolean = !!certification && !!enrollment && !hasValidationError
39-
const certificateNotFoundError: boolean = ready && !hasCompletedTheCertification
43+
const certificateNotFoundError: boolean = profileReady && ready && !hasCompletedTheCertification
4044

4145
function getCertTitle(user: string): string {
4246
return `${user} - ${certification?.title}`
4347
}
4448

4549
const certUrl: string = getUserTCACertificateSsr(
46-
props.certification,
47-
props.profile.handle,
48-
getCertTitle(props.profile.handle),
50+
certificationParam,
51+
userHandle,
52+
getCertTitle(userHandle),
4953
)
5054

51-
const certificationTitle: string = getCertTitle(enrollment?.userName || props.profile.handle)
55+
const certificationTitle: string = getCertTitle(enrollment?.userName || userHandle)
5256

5357
const validateLink: string = getTCACertificationValidationUrl(enrollment?.completionUuid as string)
5458

@@ -62,7 +66,7 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)
6266
certification={certification as TCACertification}
6367
completionUuid={enrollment?.completionUuid ?? ''}
6468
userName={enrollment?.userName}
65-
tcHandle={props.profile.handle}
69+
tcHandle={userHandle}
6670
completedDate={enrollment?.completedAt as string}
6771
certificateElRef={certificateElRef}
6872
validateLink={validateLink}
@@ -78,21 +82,23 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)
7882

7983
<LoadingSpinner hide={ready} />
8084

81-
<CertificatePageLayout
82-
certificateElRef={certificateElRef}
83-
fallbackBackUrl={tcaCertificationPath}
84-
fullScreenCertLayout={!certificateNotFoundError && props.fullScreenCertLayout}
85-
isCertificateCompleted={hasCompletedTheCertification}
86-
isReady={ready}
87-
ssrUrl={certUrl}
88-
title={certificationTitle}
89-
className={certificateNotFoundError ? 'cert-not-found-layout' : ''}
90-
afterContent={certificateNotFoundError && (
91-
<CertificateNotFoundContent className='desktop-hide' />
92-
)}
93-
>
94-
{renderCertificate()}
95-
</CertificatePageLayout>
85+
{profileReady && (
86+
<CertificatePageLayout
87+
certificateElRef={certificateElRef}
88+
fallbackBackUrl={tcaCertificationPath}
89+
fullScreenCertLayout={!certificateNotFoundError && !isOwnProfile}
90+
isCertificateCompleted={hasCompletedTheCertification}
91+
isReady={ready}
92+
ssrUrl={certUrl}
93+
title={certificationTitle}
94+
className={certificateNotFoundError ? 'cert-not-found-layout' : ''}
95+
afterContent={certificateNotFoundError && (
96+
<CertificateNotFoundContent className='desktop-hide' />
97+
)}
98+
>
99+
{renderCertificate()}
100+
</CertificatePageLayout>
101+
)}
96102
</>
97103
)
98104
}
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
export * from './user-certification-view'
22

33
// used only by SSR
4-
// TODO: merge this into one component?
5-
export * from './my-certificate'
64
export * from './certificate-view'
7-
8-
// deprecated
9-
// TODO: remove?
10-
export * from './user-certificate'

src-ts/tools/learn/tca-certificate/my-certificate/MyTCACertificate.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

src-ts/tools/learn/tca-certificate/my-certificate/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src-ts/tools/learn/tca-certificate/user-certificate/UserTCACertificate.tsx

Lines changed: 0 additions & 54 deletions
This file was deleted.

src-ts/tools/learn/tca-certificate/user-certificate/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src-ts/tools/learn/welcome/tc-certifications/cert-card/TCCertCard.tsx

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

4-
import { Button, ButtonStyle, IconSolid, ProgressBar, useCheckIsMobile } from '../../../../../lib'
4+
import { Button, ButtonStyle, IconSolid, ProgressBar } from '../../../../../lib'
55
import {
66
CertificateBadgeIcon,
77
CompletionTimeRange,
@@ -12,7 +12,7 @@ import {
1212
TCACertificationProgress,
1313
TCACertificationProviderBase,
1414
} from '../../../learn-lib'
15-
import { getTCACertificateUrl, getTCACertificationPath } from '../../../learn.routes'
15+
import { getTCACertificationPath, getTCAUserCertificationUrl } from '../../../learn.routes'
1616

1717
import styles from './TCCertCard.module.scss'
1818

@@ -29,7 +29,6 @@ const getCtaBtn: (style: ButtonStyle, label: string, route: string) => ReactNode
2929
const EXCERPT_TEXT_LEN: number = 165
3030

3131
const TCCertCard: FC<TCCertCardProps> = (props: TCCertCardProps) => {
32-
const isMobile: boolean = useCheckIsMobile()
3332

3433
const desc: string = props.certification.description.slice(0, EXCERPT_TEXT_LEN)
3534

@@ -49,10 +48,11 @@ const TCCertCard: FC<TCCertCardProps> = (props: TCCertCardProps) => {
4948
}
5049

5150
if (isCompleted) {
51+
const certificatePath: string = getTCAUserCertificationUrl(dashedName, props.progress?.userHandle as string)
5252
return (
5353
<div className={styles.completedCTAs}>
5454
<div className={styles.certCTAButtons}>
55-
{getCtaBtn('primary', 'View Certificate', getTCACertificateUrl(dashedName))}
55+
{getCtaBtn('primary', 'View Certificate', certificatePath)}
5656
{getCtaBtn('secondary', 'Details', getTCACertificationPath(dashedName))}
5757
</div>
5858
</div>

0 commit comments

Comments
 (0)