6
6
SetStateAction ,
7
7
useCallback ,
8
8
useContext ,
9
+ useEffect ,
9
10
useLayoutEffect ,
10
11
useRef ,
11
12
useState ,
@@ -27,7 +28,6 @@ import {
27
28
useGetTCACertification ,
28
29
useGetTCACertificationProgress ,
29
30
useTCACertificationCheckCompleted ,
30
- useTcaCertificationModal ,
31
31
} from '../../learn-lib'
32
32
import { perks } from '../certification-details-modal/certif-details-content/data'
33
33
import { PerksSection } from '../perks-section'
@@ -60,6 +60,7 @@ const EnrollmentPage: FC<{}> = () => {
60
60
const {
61
61
progress,
62
62
ready : progressReady ,
63
+ refetch : refetchProgress ,
63
64
setCertificateProgress,
64
65
} : TCACertificationProgressProviderData = useGetTCACertificationProgress (
65
66
profile ?. userId as unknown as string ,
@@ -72,17 +73,14 @@ const EnrollmentPage: FC<{}> = () => {
72
73
const firstResourceProgress : TCACertificationProgress [ 'resourceProgresses' ] [ 0 ] | undefined
73
74
= progress ?. resourceProgresses ?. [ 0 ]
74
75
75
- const { certification : tcaCertificationName } : TCACertificationCheckCompleted = useTCACertificationCheckCompleted (
76
+ const {
77
+ ready : certCheckReady ,
78
+ } : TCACertificationCheckCompleted = useTCACertificationCheckCompleted (
76
79
firstResourceProgress ?. resourceProgressType ?? '' ,
77
80
firstResourceProgress ?. resourceProgressId ?? '' ,
78
81
{ enabled : ! ! firstResourceProgress ?. resourceProgressType } ,
79
82
)
80
83
81
- const tcaCertificationCompletedModal : ReactNode = useTcaCertificationModal (
82
- tcaCertificationName ,
83
- navToCertificationDetails ,
84
- )
85
-
86
84
if ( ready && profile && ! userInfo . current ) {
87
85
userInfo . current = { ...profile }
88
86
}
@@ -119,11 +117,18 @@ const EnrollmentPage: FC<{}> = () => {
119
117
120
118
function closeEnrolledModal ( ) : void {
121
119
setIsEnrolledModalOpen ( false )
122
- if ( ! tcaCertificationCompletedModal ) {
123
- navToCertificationDetails ( )
124
- }
125
120
}
126
121
122
+ useEffect ( ( ) => {
123
+ if ( ! certCheckReady || isEnrolledModalOpen ) {
124
+ return
125
+ }
126
+
127
+ refetchProgress ( )
128
+ navToCertificationDetails ( )
129
+ // eslint-disable-next-line react-hooks/exhaustive-deps
130
+ } , [ certCheckReady , isEnrolledModalOpen ] )
131
+
127
132
function renderMainContent ( ) : ReactNode {
128
133
return ready ? (
129
134
< >
@@ -135,10 +140,8 @@ const EnrollmentPage: FC<{}> = () => {
135
140
136
141
< EnrolledModal
137
142
isOpen = { isEnrolledModalOpen }
138
- certification = { certification }
139
143
onClose = { closeEnrolledModal }
140
144
/>
141
- { ! isEnrolledModalOpen && tcaCertificationCompletedModal }
142
145
</ >
143
146
) : null
144
147
}
0 commit comments