@@ -17,15 +17,14 @@ import {
1717} from '../../api/generatedTypes/graphql' ;
1818import LoadingSpinner from '../../../common/components/spinner/LoadingSpinner' ;
1919import enrolOccurrenceMutation from '../mutations/enrolOccurrenceMutation' ;
20- import { saveChildEvents } from '../state/EventActions' ;
2120import ErrorMessage from '../../../common/components/error/Error' ;
2221import getEventOrEventGroupOccurrenceRefetchQueries from '../getEventOrEventGroupOccurrenceRefetchQueries' ;
2322import { GQLErrors } from './EnrolConstants' ;
2423import Enrol from './Enrol' ;
2524import useGetPathname from '../../../common/route/utils/useGetPathname' ;
26- import { publicSvgIconPaths } from '../../../public_files' ;
27- import Icon from '../../../common/components/icon/Icon' ;
2825import graphqlClient from '../../api/client' ;
26+ import { useProfileContext } from '../../profile/hooks/useProfileContext' ;
27+ import { handleEnrolCompleted } from './handleEnrolCompleted' ;
2928
3029function containsAlreadyJoinedError (
3130 errors : ReadonlyArray < GraphQLFormattedError >
@@ -52,6 +51,7 @@ const EnrolPage = () => {
5251 i18n : { language } ,
5352 } = useTranslation ( ) ;
5453 const dispatch = useDispatch ( ) ;
54+ const { refetchProfile } = useProfileContext ( ) ;
5555 const params = useParams < {
5656 childId : string ;
5757 eventId : string ;
@@ -91,28 +91,15 @@ const EnrolPage = () => {
9191 childId,
9292 eventGroupId : data ?. occurrence ?. event ?. eventGroup ?. id ,
9393 } ) ,
94- onCompleted : ( data ) => {
95- if ( data ?. enrolOccurrence ?. enrolment ?. child ?. occurrences ?. edges ) {
96- dispatch (
97- saveChildEvents ( {
98- childId,
99- occurrences : data . enrolOccurrence . enrolment . child . occurrences ,
100- } )
101- ) ;
102- toast . success (
103- < div >
104- < Icon
105- src = { publicSvgIconPaths [ 'tada' ] }
106- className = { styles . tadaIcon }
107- />
108- < h1 > { t ( 'enrollment.successToast.heading' ) } </ h1 >
109- < p > { t ( 'enrollment.successToast.paragraph' ) } </ p >
110- </ div >
111- ) ;
112- }
113-
114- goToOccurrence ( ) ;
115- } ,
94+ awaitRefetchQueries : true ,
95+ onCompleted : async ( data ) =>
96+ handleEnrolCompleted ( data , {
97+ childId,
98+ dispatch,
99+ refetchProfile,
100+ goToOccurrence,
101+ t,
102+ } ) ,
116103 onError : ( error ) => {
117104 if ( containsAlreadyJoinedError ( error . graphQLErrors ) ) {
118105 goToOccurrence ( ) ;
0 commit comments