({ type }: { type: UserExperienceType })
| 12 | import { LogEvent } from '../lib/log'; |
| 13 | |
| 14 | const useRemoveExperience = ({ type }: { type: UserExperienceType }) => { |
| 15 | const { user } = useAuthContext(); |
| 16 | const { logEvent } = useLogContext(); |
| 17 | const router = useRouter(); |
| 18 | const { displayToast } = useToastNotification(); |
| 19 | const userId = user?.id ?? ''; |
| 20 | const { queryKey: experienceQueryKey } = useUserExperiencesByType( |
| 21 | type, |
| 22 | userId, |
| 23 | ); |
| 24 | const qc = useQueryClient(); |
| 25 | const { mutate, isPending } = useMutation({ |
| 26 | mutationFn: (id: string) => removeUserExperience(id), |
| 27 | onSuccess: (_, id) => { |
| 28 | logEvent({ |
| 29 | event_name: LogEvent.RemoveExperience, |
| 30 | target_type: type, |
| 31 | target_id: id, |
| 32 | }); |
| 33 | router.push(`${webappUrl}settings/profile/experience/${type}`); |
| 34 | qc.invalidateQueries({ queryKey: experienceQueryKey }); |
| 35 | qc.invalidateQueries({ |
| 36 | queryKey: generateQueryKey(RequestKey.UserExperience, user, 'profile'), |
| 37 | exact: false, |
| 38 | }); |
| 39 | }, |
| 40 | onError: () => { |
| 41 | displayToast(labels.error.generic || 'Failed to delete experience'); |
| 42 | }, |
| 43 | }); |
| 44 | |
| 45 | return { removeExperience: mutate, isPending }; |
| 46 | }; |
| 47 | |
| 48 | export default useRemoveExperience; |
no test coverage detected