move user delete to api endpoint

This commit is contained in:
Gregor Vostrak
2026-05-27 18:56:57 +02:00
committed by Constantin Graf
parent fe4e903203
commit d0334bd730
4 changed files with 141 additions and 27 deletions

View File

@@ -57,6 +57,29 @@ export function useUpdateUserMutation() {
});
}
export function useDeleteUserMutation() {
const { addNotification } = useNotificationsStore();
return useMutation({
mutationFn: async (userId: string) => {
try {
await api.deleteUser(undefined, { params: { user: userId } });
} catch (error) {
if (!axios.isAxiosError(error) || error.response?.status !== 422) {
addNotification(
'error',
'Failed to delete account',
axios.isAxiosError(error)
? (error.response?.data?.message ?? 'Please try again later.')
: 'Please try again later.'
);
}
throw error;
}
},
});
}
export function useResendUserEmailVerificationMutation() {
const { handleApiRequestNotifications } = useNotificationsStore();