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 @@ -6,7 +6,6 @@ import { TCACertification } from '../../learn-lib'
import styles from './EnrolledModal.module.scss'

interface EnrolledModalProps {
certification: TCACertification
isOpen: boolean
onClose: () => void
}
Expand All @@ -29,10 +28,7 @@ const EnrolledModal: FC<EnrolledModalProps> = (props: EnrolledModalProps) => {
>
<>
<h2 className='details'>
You have Successfully Enrolled in the
{' '}
{props.certification.title}
!
You have successfully enrolled!
</h2>
<Button buttonStyle='outline' label='Close' onClick={props.onClose} />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SetStateAction,
useCallback,
useContext,
useEffect,
useLayoutEffect,
useRef,
useState,
Expand All @@ -27,7 +28,6 @@ import {
useGetTCACertification,
useGetTCACertificationProgress,
useTCACertificationCheckCompleted,
useTcaCertificationModal,
} from '../../learn-lib'
import { perks } from '../certification-details-modal/certif-details-content/data'
import { PerksSection } from '../perks-section'
Expand Down Expand Up @@ -60,6 +60,7 @@ const EnrollmentPage: FC<{}> = () => {
const {
progress,
ready: progressReady,
refetch: refetchProgress,
setCertificateProgress,
}: TCACertificationProgressProviderData = useGetTCACertificationProgress(
profile?.userId as unknown as string,
Expand All @@ -72,17 +73,14 @@ const EnrollmentPage: FC<{}> = () => {
const firstResourceProgress: TCACertificationProgress['resourceProgresses'][0] | undefined
= progress?.resourceProgresses?.[0]

const { certification: tcaCertificationName }: TCACertificationCheckCompleted = useTCACertificationCheckCompleted(
const {
ready: certCheckReady,
}: TCACertificationCheckCompleted = useTCACertificationCheckCompleted(
firstResourceProgress?.resourceProgressType ?? '',
firstResourceProgress?.resourceProgressId ?? '',
{ enabled: !!firstResourceProgress?.resourceProgressType },
)

const tcaCertificationCompletedModal: ReactNode = useTcaCertificationModal(
tcaCertificationName,
navToCertificationDetails,
)

if (ready && profile && !userInfo.current) {
userInfo.current = { ...profile }
}
Expand Down Expand Up @@ -119,11 +117,18 @@ const EnrollmentPage: FC<{}> = () => {

function closeEnrolledModal(): void {
setIsEnrolledModalOpen(false)
if (!tcaCertificationCompletedModal) {
navToCertificationDetails()
}
}

useEffect(() => {
if (!certCheckReady || isEnrolledModalOpen) {
return
}

refetchProgress()
navToCertificationDetails()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [certCheckReady, isEnrolledModalOpen])

function renderMainContent(): ReactNode {
return ready ? (
<>
Expand All @@ -135,10 +140,8 @@ const EnrollmentPage: FC<{}> = () => {

<EnrolledModal
isOpen={isEnrolledModalOpen}
certification={certification}
onClose={closeEnrolledModal}
/>
{!isEnrolledModalOpen && tcaCertificationCompletedModal}
</>
) : null
}
Expand Down