import { useMutation, useQueryClient } from "@tanstack/react-query" import { Trash2 } from "lucide-react" import { useState } from "react" import { useForm } from "react-hook-form" import { UsersService } from "@/client" import { Button } from "@/components/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { DropdownMenuItem } from "@/components/ui/dropdown-menu" import { LoadingButton } from "@/components/ui/loading-button" import useCustomToast from "@/hooks/useCustomToast" import { handleError } from "@/utils" interface DeleteUserProps { id: string onSuccess: () => void } const DeleteUser = ({ id, onSuccess }: DeleteUserProps) => { const [isOpen, setIsOpen] = useState(false) const queryClient = useQueryClient() const { showSuccessToast, showErrorToast } = useCustomToast() const { handleSubmit } = useForm() const deleteUser = async (id: string) => { await UsersService.deleteUser({ userId: id }) } const mutation = useMutation({ mutationFn: deleteUser, onSuccess: () => { showSuccessToast("The user was deleted successfully") setIsOpen(false) onSuccess() }, onError: handleError.bind(showErrorToast), onSettled: () => { queryClient.invalidateQueries() }, }) const onSubmit = async () => { mutation.mutate(id) } return ( e.preventDefault()} onClick={() => setIsOpen(true)} > Delete User
Delete User All items associated with this user will also be{" "} permanently deleted. Are you sure? You will not be able to undo this action. Delete
) } export default DeleteUser