11import { 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'
75import {
86 CertificateNotFoundContent ,
97 CertificatePageLayout ,
@@ -15,40 +13,46 @@ import {
1513} from '../../learn-lib'
1614import { getTCACertificationPath , getTCACertificationValidationUrl , getUserTCACertificateSsr } from '../../learn.routes'
1715import { 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}
0 commit comments