Skip to content

TCA-1278, TCA-1279 - Cert page fixes -> rc-3.1 #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 26, 2023
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
8 changes: 5 additions & 3 deletions src-ts/lib/loading-spinner/LoadingSpinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Centered Loading Spinner with back overlay
*/
import { FC } from 'react'
import { FC, forwardRef, RefAttributes } from 'react'
import { PuffLoader } from 'react-spinners'
import classNames from 'classnames'

Expand All @@ -19,21 +19,23 @@ export interface LoadingSpinnerProps {
type?: LoadingSpinnerType
}

const LoadingSpinner: FC<LoadingSpinnerProps> = (props: LoadingSpinnerProps) => {
const LoadingSpinner: FC<LoadingSpinnerProps & RefAttributes<HTMLDivElement>>
= forwardRef<HTMLDivElement, LoadingSpinnerProps>((props, ref) => {
if (!!props.hide) {
return <></>
}

const isOverlay: boolean = props.type === 'Overlay'
return (
<div
ref={ref}
className={
classNames(styles['loading-spinner'], styles.show, { [styles.overlay]: isOverlay }, props.className)
}
>
<PuffLoader color='#2196f3' loading size={100} />
</div>
)
}
})

export default LoadingSpinner
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const CertificationDetailsPage: FC<{}> = () => {
/>
</>
)
) : <></>
) : undefined
}

function renderSidebar(): ReactNode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
FC,
forwardRef,
MutableRefObject,
ReactNode,
RefAttributes,
useMemo,
useRef,
} from 'react'
Expand Down Expand Up @@ -33,7 +35,8 @@ interface CertificateViewProps {
provider: string
}

const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps) => {
const CertificateView: FC<CertificateViewProps & RefAttributes<HTMLDivElement>>
= forwardRef<HTMLDivElement, CertificateViewProps>((props, ref) => {
const coursePath: string = getCoursePath(props.provider, props.certification)
const certificateElRef: MutableRefObject<HTMLDivElement | any> = useRef()

Expand Down Expand Up @@ -110,6 +113,7 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)
</PageTitle>

<CertificatePageLayout
ref={ref}
certificateElRef={certificateElRef}
fallbackBackUrl={coursePath}
fullScreenCertLayout={!certificateNotFoundError && props.fullScreenCertLayout}
Expand All @@ -127,6 +131,6 @@ const CertificateView: FC<CertificateViewProps> = (props: CertificateViewProps)
</CertificatePageLayout>
</>
)
}
})

export default CertificateView
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react'
import {
Dispatch,
FC,
MutableRefObject,
SetStateAction,
useEffect,
useLayoutEffect,
useRef,
useState,
} from 'react'
import { Params, useParams } from 'react-router-dom'

import {
Expand All @@ -7,8 +16,10 @@ import {
UserProfile,
} from '../../../../lib'
import { CertificateView } from '../certificate-view'
import { hideSiblings } from '../../learn-lib'

const UserCertificate: FC<{}> = () => {
const elRef: MutableRefObject<HTMLElement | any> = useRef()

const routeParams: Params<string> = useParams()

Expand All @@ -31,16 +42,27 @@ const UserCertificate: FC<{}> = () => {
}
}, [routeParams.memberHandle, setProfileReady])

useLayoutEffect(() => {
const el: HTMLElement = elRef.current
if (!el) {
return
}

hideSiblings(el)
hideSiblings(el.parentElement as HTMLElement)
}, [])

return (
<>
<LoadingSpinner hide={profileReady} />
<LoadingSpinner hide={profileReady} ref={elRef} />

{profileReady && profile && (
<CertificateView
certification={certificationParam}
profile={profile}
provider={providerParam}
fullScreenCertLayout
ref={elRef}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
FC,
forwardRef,
MutableRefObject,
ReactNode,
RefAttributes,
useCallback,
useLayoutEffect,
useRef,
Expand Down Expand Up @@ -42,7 +44,8 @@ interface CertificatePageLayoutProps {
title?: string
}

const CertificatePageLayout: FC<CertificatePageLayoutProps> = (props: CertificatePageLayoutProps) => {
const CertificatePageLayout: FC<CertificatePageLayoutProps & RefAttributes<HTMLDivElement>>
= forwardRef<HTMLDivElement, CertificatePageLayoutProps>((props, ref) => {
const [queryParams]: [URLSearchParams, any] = useSearchParams()
const viewStyle: CertificatePageLayoutStyle = queryParams.get(getViewStyleParamKey()) as CertificatePageLayoutStyle

Expand Down Expand Up @@ -78,6 +81,12 @@ const CertificatePageLayout: FC<CertificatePageLayoutProps> = (props: Certificat
const handlePrint: () => Promise<void>
= useCertificatePrint(props.certificateElRef, props.title ?? '')

if (typeof ref === 'function') {
ref(wrapElRef.current)
} else if (ref && Object.prototype.hasOwnProperty.call(ref, 'current')) {
ref.current = wrapElRef.current
}

useLayoutEffect(() => {
const el: HTMLElement = wrapElRef.current
if (props.fullScreenCertLayout !== true || !el) {
Expand All @@ -93,57 +102,59 @@ const CertificatePageLayout: FC<CertificatePageLayoutProps> = (props: Certificat
<>
<LoadingSpinner hide={props.isReady} />

{props.isReady && (
<div className={classNames(styles.wrap, props.className)} ref={wrapElRef}>
<div className={styles['content-wrap']}>
{!props.fullScreenCertLayout && (
<div className={styles['btns-wrap']}>
<ActionButton
icon={<IconOutline.ChevronLeftIcon />}
onClick={handleBackBtnClick}
/>
</div>
)}
<div
className={classNames(styles['certificate-wrap'], viewStyle)}
ref={certificateWrapRef}
>
<div className={styles.certifInnerWrap}>
{props.children}
</div>
</div>
{!props.fullScreenCertLayout && (
<div className={classNames(styles.wrap, props.className)} ref={wrapElRef}>
{props.isReady && (
<>
<div className={styles['content-wrap']}>
{!props.fullScreenCertLayout && (
<div className={styles['btns-wrap']}>
<ActionButton
icon={<IconOutline.ChevronLeftIcon />}
onClick={handleBackBtnClick}
/>
</div>
)}
<div
className={
classNames(
styles['btns-wrap'],
(!props.isCertificateCompleted || props.disableActions) && styles.disabled,
)
}
className={classNames(styles['certificate-wrap'], viewStyle)}
ref={certificateWrapRef}
>
<ActionButton
icon={<IconOutline.PrinterIcon />}
onClick={handlePrint}
/>
<ActionButton
icon={<IconOutline.DownloadIcon />}
onClick={handleDownload}
/>
<ActionButton
icon={<IconOutline.ShareIcon />}
onClick={shareModal.show}
>
Share certificate
</ActionButton>
<div className={styles.certifInnerWrap}>
{props.children}
</div>
</div>
)}
</div>
{props.afterContent}
{shareModal.modal}
</div>
)}
{!props.fullScreenCertLayout && (
<div
className={
classNames(
styles['btns-wrap'],
(!props.isCertificateCompleted || props.disableActions) && styles.disabled,
)
}
>
<ActionButton
icon={<IconOutline.PrinterIcon />}
onClick={handlePrint}
/>
<ActionButton
icon={<IconOutline.DownloadIcon />}
onClick={handleDownload}
/>
<ActionButton
icon={<IconOutline.ShareIcon />}
onClick={shareModal.show}
>
Share certificate
</ActionButton>
</div>
)}
</div>
{props.afterContent}
{shareModal.modal}
</>
)}
</div>
</>
)
}
})

export default CertificatePageLayout