1- import { useMutation } from '@tanstack/react-query' ;
1+ import { useMutation , useQueryClient } from '@tanstack/react-query' ;
22import { useForm } from 'react-hook-form' ;
33import { z } from 'zod' ;
44import { zodResolver } from '@hookform/resolvers/zod' ;
@@ -20,6 +20,8 @@ import { labels } from '../lib/labels';
2020import { applyZodErrorsToForm } from '../lib/form' ;
2121import { useToastNotification } from './useToastNotification' ;
2222import { webappUrl } from '../lib/constants' ;
23+ import { useUserExperiencesByType } from '../features/profile/hooks/useUserExperiencesByType' ;
24+ import { useAuthContext } from '../contexts/AuthContext' ;
2325
2426export const userExperienceInputBaseSchema = z
2527 . object ( {
@@ -28,7 +30,7 @@ export const userExperienceInputBaseSchema = z
2830 description : z . string ( ) . max ( 5000 ) . optional ( ) ,
2931 subtitle : z . string ( ) . max ( 1000 ) . optional ( ) ,
3032 startedAt : z . date ( { message : 'Start date is required.' } ) ,
31- endedAt : z . date ( ) . optional ( ) ,
33+ endedAt : z . date ( ) . optional ( ) . nullable ( ) ,
3234 current : z . boolean ( ) . default ( false ) ,
3335 companyId : z . string ( ) . nullable ( ) . optional ( ) . default ( null ) ,
3436 customCompanyName : z
@@ -75,6 +77,12 @@ const useUserExperienceForm = ({
7577} : {
7678 defaultValues : BaseUserExperience ;
7779} ) => {
80+ const qc = useQueryClient ( ) ;
81+ const { user } = useAuthContext ( ) ;
82+ const { queryKey : experienceQueryKey } = useUserExperiencesByType (
83+ defaultValues . type ,
84+ user ?. id ,
85+ ) ;
7886 const dirtyFormRef = useRef < ReturnType < typeof useDirtyForm > | null > ( null ) ;
7987 const router = useRouter ( ) ;
8088 const { displayToast } = useToastNotification ( ) ;
@@ -88,10 +96,11 @@ const useUserExperienceForm = ({
8896 type === UserExperienceType . Work
8997 ? upsertUserWorkExperience ( data as UserExperienceWork , id )
9098 : upsertUserGeneralExperience ( data , id ) ,
91- onSuccess : ( ) => {
99+ onSuccess : ( _ , vars ) => {
100+ methods . reset ( vars ) ;
92101 dirtyFormRef . current ?. allowNavigation ( ) ;
102+ qc . invalidateQueries ( { queryKey : experienceQueryKey } ) ;
93103 router . push ( `${ webappUrl } settings/profile/experience/${ type } ` ) ;
94- methods . reset ( ) ;
95104 } ,
96105 onError : ( error : ApiErrorResult ) => {
97106 if (
0 commit comments