66 SetStateAction ,
77 useCallback ,
88 useContext ,
9+ useEffect ,
910 useLayoutEffect ,
1011 useRef ,
1112 useState ,
@@ -27,7 +28,6 @@ import {
2728 useGetTCACertification ,
2829 useGetTCACertificationProgress ,
2930 useTCACertificationCheckCompleted ,
30- useTcaCertificationModal ,
3131} from '../../learn-lib'
3232import { perks } from '../certification-details-modal/certif-details-content/data'
3333import { PerksSection } from '../perks-section'
@@ -60,6 +60,7 @@ const EnrollmentPage: FC<{}> = () => {
6060 const {
6161 progress,
6262 ready : progressReady ,
63+ refetch : refetchProgress ,
6364 setCertificateProgress,
6465 } : TCACertificationProgressProviderData = useGetTCACertificationProgress (
6566 profile ?. userId as unknown as string ,
@@ -72,17 +73,14 @@ const EnrollmentPage: FC<{}> = () => {
7273 const firstResourceProgress : TCACertificationProgress [ 'resourceProgresses' ] [ 0 ] | undefined
7374 = progress ?. resourceProgresses ?. [ 0 ]
7475
75- const { certification : tcaCertificationName } : TCACertificationCheckCompleted = useTCACertificationCheckCompleted (
76+ const {
77+ ready : certCheckReady ,
78+ } : TCACertificationCheckCompleted = useTCACertificationCheckCompleted (
7679 firstResourceProgress ?. resourceProgressType ?? '' ,
7780 firstResourceProgress ?. resourceProgressId ?? '' ,
7881 { enabled : ! ! firstResourceProgress ?. resourceProgressType } ,
7982 )
8083
81- const tcaCertificationCompletedModal : ReactNode = useTcaCertificationModal (
82- tcaCertificationName ,
83- navToCertificationDetails ,
84- )
85-
8684 if ( ready && profile && ! userInfo . current ) {
8785 userInfo . current = { ...profile }
8886 }
@@ -119,11 +117,18 @@ const EnrollmentPage: FC<{}> = () => {
119117
120118 function closeEnrolledModal ( ) : void {
121119 setIsEnrolledModalOpen ( false )
122- if ( ! tcaCertificationCompletedModal ) {
123- navToCertificationDetails ( )
124- }
125120 }
126121
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+
127132 function renderMainContent ( ) : ReactNode {
128133 return ready ? (
129134 < >
@@ -135,10 +140,8 @@ const EnrollmentPage: FC<{}> = () => {
135140
136141 < EnrolledModal
137142 isOpen = { isEnrolledModalOpen }
138- certification = { certification }
139143 onClose = { closeEnrolledModal }
140144 />
141- { ! isEnrolledModalOpen && tcaCertificationCompletedModal }
142145 </ >
143146 ) : null
144147 }
0 commit comments