feat: spa account deletion
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { z } from "zod"
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
|
||||
import { diaryEntryDtoSchema, paginatedSchema } from "@/lib/api/common"
|
||||
import { get, post, put, putForm } from "@/lib/api/client"
|
||||
import { delWithBody, get, post, put, putForm } from "@/lib/api/client"
|
||||
|
||||
export const userSummaryDtoSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
@@ -228,3 +228,23 @@ export function useUpdateProfileFields() {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export type DeleteAccountRequest = { password: string }
|
||||
|
||||
export function useDeleteOwnAccount() {
|
||||
return useMutation({
|
||||
mutationFn: (data: DeleteAccountRequest) => delWithBody("/users/me", data),
|
||||
})
|
||||
}
|
||||
|
||||
export function useAdminDeleteUser() {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ id, password }: DeleteAccountRequest & { id: string }) =>
|
||||
delWithBody(`/users/${id}`, { password }),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: userKeys.all })
|
||||
qc.invalidateQueries({ queryKey: ["activity-feed"] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user