|
1 | | -import { FC } from 'react' |
2 | | -import { Params, useParams } from 'react-router-dom' |
| 1 | +import { FC, useLayoutEffect } from 'react' |
| 2 | +import { NavigateFunction, Params, useNavigate, useParams } from 'react-router-dom' |
3 | 3 |
|
| 4 | +import { LoadingSpinner } from '../../../../lib' |
4 | 5 | import { |
5 | 6 | TCACertification, |
6 | 7 | TCACertificationEnrollmentProviderData, |
7 | 8 | useTCACertificationEnrollment, |
8 | 9 | } from '../../learn-lib' |
| 10 | +import { getTCAUserCertificationUrl } from '../../learn.routes' |
9 | 11 |
|
10 | | -import { useGetUserProfile, UseGetUserProfileData } from './use-get-user-profile' |
11 | 12 | import UserCertificationViewBase from './UserCertificationViewBase' |
12 | 13 |
|
13 | 14 | const UuidCertificationView: FC<{}> = () => { |
14 | | - |
| 15 | + const navigate: NavigateFunction = useNavigate() |
15 | 16 | const routeParams: Params<string> = useParams() |
16 | 17 |
|
17 | 18 | const { |
18 | 19 | enrollment, |
19 | 20 | error: enrollmentError, |
| 21 | + ready: enrollmentReady, |
20 | 22 | }: TCACertificationEnrollmentProviderData |
21 | 23 | = useTCACertificationEnrollment(routeParams.completionUuid as string) |
22 | 24 |
|
23 | | - const { profile }: UseGetUserProfileData = useGetUserProfile(enrollment?.userHandle) |
24 | | - |
25 | 25 | const certification: TCACertification | undefined = enrollment?.topcoderCertification |
26 | 26 |
|
| 27 | + useLayoutEffect(() => { |
| 28 | + if (enrollmentReady && enrollment) { |
| 29 | + navigate( |
| 30 | + getTCAUserCertificationUrl( |
| 31 | + certification?.dashedName as string, |
| 32 | + enrollment.userHandle, |
| 33 | + ), |
| 34 | + ) |
| 35 | + } |
| 36 | + }, [certification?.dashedName, enrollment, enrollmentReady, navigate]) |
| 37 | + |
27 | 38 | return ( |
28 | | - <UserCertificationViewBase |
29 | | - enrollment={enrollment} |
30 | | - certification={certification} |
31 | | - profile={profile} |
32 | | - enrollmentError={enrollmentError} |
33 | | - /> |
| 39 | + <> |
| 40 | + <LoadingSpinner hide={enrollmentReady} /> |
| 41 | + {enrollmentReady && enrollmentError && ( |
| 42 | + <UserCertificationViewBase |
| 43 | + enrollment={enrollment} |
| 44 | + certification={certification} |
| 45 | + profile={{} as any} |
| 46 | + enrollmentError={enrollmentError} |
| 47 | + /> |
| 48 | + )} |
| 49 | + </> |
34 | 50 | ) |
35 | 51 | } |
36 | 52 |
|
|
0 commit comments