|
1 |
| -import { FC, MutableRefObject, useCallback, useEffect, useMemo, useRef } from 'react' |
2 |
| -import classNames from 'classnames' |
3 |
| - |
4 | 1 | import {
|
5 |
| - FacebookSocialShareBtn, |
6 |
| - fileDownloadCanvasAsImage, |
7 |
| - IconOutline, |
8 |
| - LinkedinSocialShareBtn, |
9 |
| - LoadingSpinner, |
10 |
| - NavigateBackFunction, |
11 |
| - TwitterSocialShareBtn, |
12 |
| - useNavigateBack, |
13 |
| - UserProfile, |
14 |
| -} from '../../../../lib' |
| 2 | + FC, |
| 3 | + MutableRefObject, |
| 4 | + useEffect, |
| 5 | + useMemo, |
| 6 | + useRef, |
| 7 | +} from 'react' |
| 8 | + |
15 | 9 | import {
|
16 |
| - ActionButton, |
17 | 10 | AllCertificationsProviderData,
|
| 11 | + CertificatePageLayout, |
18 | 12 | CoursesProviderData,
|
19 |
| - useCertificateCanvas, |
20 |
| - useCertificatePrint, |
21 |
| - useCertificateScaling, |
22 | 13 | useGetCertification,
|
23 | 14 | useGetCourses,
|
24 | 15 | useGetUserCompletedCertifications,
|
25 | 16 | UserCompletedCertificationsProviderData,
|
26 | 17 | } from '../../learn-lib'
|
27 |
| -import { getCoursePath, getUserCertificateSsr } from '../../learn.routes' |
28 |
| - |
29 |
| -import { Certificate } from './certificate' |
30 |
| -import styles from './CertificateView.module.scss' |
| 18 | +import { |
| 19 | + getCoursePath, |
| 20 | + getUserCertificateSsr, |
| 21 | +} from '../../learn.routes' |
| 22 | +import { UserProfile } from '../../../../lib' |
31 | 23 |
|
32 |
| -export type CertificateViewStyle = 'large-container' |
| 24 | +import Certificate from './certificate/Certificate' |
33 | 25 |
|
34 | 26 | interface CertificateViewProps {
|
35 |
| - certification: string, |
36 |
| - hideActions?: boolean, |
| 27 | + certification: string |
| 28 | + fullScreenCertLayout?: boolean |
37 | 29 | onCertificationNotCompleted: () => void
|
38 |
| - profile: UserProfile, |
39 |
| - provider: string, |
40 |
| - viewStyle?: CertificateViewStyle |
| 30 | + profile: UserProfile |
| 31 | + provider: string |
41 | 32 | }
|
42 | 33 |
|
43 | 34 | const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps) => {
|
44 |
| - |
45 |
| - const navigateBack: NavigateBackFunction = useNavigateBack() |
46 | 35 | const coursePath: string = getCoursePath(props.provider, props.certification)
|
47 | 36 | const certificateElRef: MutableRefObject<HTMLDivElement | any> = useRef()
|
48 |
| - const certificateWrapRef: MutableRefObject<HTMLDivElement | any> = useRef() |
49 | 37 |
|
50 | 38 | const userName: string = useMemo(() => (
|
51 | 39 | [props.profile.firstName, props.profile.lastName].filter(Boolean)
|
@@ -94,95 +82,32 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)
|
94 | 82 | completedCertificateReady && courseReady && certificateReady
|
95 | 83 | ), [certificateReady, completedCertificateReady, courseReady])
|
96 | 84 |
|
97 |
| - const readyAndCompletedCertification: boolean = useMemo(() => ( |
98 |
| - ready && hasCompletedTheCertification |
99 |
| - ), [hasCompletedTheCertification, ready]) |
100 |
| - |
101 |
| - useCertificateScaling(ready ? certificateWrapRef : undefined, 880, 880) |
102 |
| - |
103 |
| - const handleBackBtnClick: () => void = useCallback(() => { |
104 |
| - navigateBack(coursePath) |
105 |
| - }, [coursePath, navigateBack]) |
106 |
| - |
107 |
| - const getCertificateCanvas: () => Promise<HTMLCanvasElement | void> = useCertificateCanvas(certificateElRef) |
108 |
| - |
109 |
| - const handleDownload: () => Promise<void> = useCallback(async () => { |
110 |
| - |
111 |
| - const canvas: HTMLCanvasElement | void = await getCertificateCanvas() |
112 |
| - if (!!canvas) { |
113 |
| - fileDownloadCanvasAsImage(canvas, `${certificationTitle}.png`) |
114 |
| - } |
115 |
| - |
116 |
| - }, [certificationTitle, getCertificateCanvas]) |
117 |
| - |
118 |
| - const handlePrint: () => Promise<void> = useCertificatePrint(certificateElRef, certificationTitle) |
119 |
| - |
120 | 85 | useEffect(() => {
|
121 | 86 | if (ready && !hasCompletedTheCertification) {
|
122 | 87 | props.onCertificationNotCompleted()
|
123 | 88 | }
|
124 | 89 | }, [coursePath, hasCompletedTheCertification, props, ready])
|
125 | 90 |
|
126 | 91 | return (
|
127 |
| - <> |
128 |
| - <LoadingSpinner hide={ready} /> |
129 |
| - |
130 |
| - {ready && readyAndCompletedCertification && ( |
131 |
| - <div className={styles.wrap}> |
132 |
| - <div className={styles['content-wrap']}> |
133 |
| - {!props.hideActions && ( |
134 |
| - <div className={styles['btns-wrap']}> |
135 |
| - <ActionButton |
136 |
| - icon={<IconOutline.ChevronLeftIcon />} |
137 |
| - onClick={handleBackBtnClick} |
138 |
| - /> |
139 |
| - </div> |
140 |
| - )} |
141 |
| - <div |
142 |
| - className={classNames(styles['certificate-wrap'], props.viewStyle)} |
143 |
| - ref={certificateWrapRef} |
144 |
| - > |
145 |
| - <div className={styles.certifInnerWrap}> |
146 |
| - <Certificate |
147 |
| - course={course?.title} |
148 |
| - userName={userName} |
149 |
| - tcHandle={props.profile.handle} |
150 |
| - provider={course?.resourceProvider.name} |
151 |
| - completedDate={completedCertificate?.completedDate ?? ''} |
152 |
| - elRef={certificateElRef} |
153 |
| - type={certificate?.certificationCategory.track} |
154 |
| - viewStyle={props.viewStyle} |
155 |
| - /> |
156 |
| - </div> |
157 |
| - </div> |
158 |
| - {!props.hideActions && ( |
159 |
| - <div className={styles['btns-wrap']}> |
160 |
| - <ActionButton |
161 |
| - icon={<IconOutline.PrinterIcon />} |
162 |
| - onClick={handlePrint} |
163 |
| - /> |
164 |
| - <ActionButton |
165 |
| - icon={<IconOutline.DownloadIcon />} |
166 |
| - onClick={handleDownload} |
167 |
| - /> |
168 |
| - <FacebookSocialShareBtn |
169 |
| - className={styles['share-btn']} |
170 |
| - shareUrl={certUrl} |
171 |
| - /> |
172 |
| - <LinkedinSocialShareBtn |
173 |
| - className={styles['share-btn']} |
174 |
| - shareUrl={certUrl} |
175 |
| - /> |
176 |
| - <TwitterSocialShareBtn |
177 |
| - className={styles['share-btn']} |
178 |
| - shareUrl={certUrl} |
179 |
| - /> |
180 |
| - </div> |
181 |
| - )} |
182 |
| - </div> |
183 |
| - </div> |
184 |
| - )} |
185 |
| - </> |
| 92 | + <CertificatePageLayout |
| 93 | + certificateElRef={certificateElRef} |
| 94 | + fallbackBackUrl={coursePath} |
| 95 | + fullScreenCertLayout={props.fullScreenCertLayout} |
| 96 | + isCertificateCompleted={hasCompletedTheCertification} |
| 97 | + isReady={ready} |
| 98 | + ssrUrl={certUrl} |
| 99 | + title={certificationTitle} |
| 100 | + > |
| 101 | + <Certificate |
| 102 | + completedDate={completedCertificate?.completedDate ?? ''} |
| 103 | + course={course?.title} |
| 104 | + elRef={certificateElRef} |
| 105 | + provider={course?.resourceProvider.name} |
| 106 | + tcHandle={props.profile.handle} |
| 107 | + type={certificate?.certificationCategory.track} |
| 108 | + userName={userName} |
| 109 | + /> |
| 110 | + </CertificatePageLayout> |
186 | 111 | )
|
187 | 112 | }
|
188 | 113 |
|
|
0 commit comments