import { Button, DialogTitle, Text } from "@chakra-ui/react" import { useMutation, useQueryClient } from "@tanstack/react-query" import { useState } from "react" import { useForm } from "react-hook-form" import { FiTrash2 } from "react-icons/fi" import { UsersService } from "../../client" import { DialogActionTrigger, DialogBody, DialogCloseTrigger, DialogContent, DialogFooter, DialogHeader, DialogRoot, DialogTrigger, } from "../../components/ui/dialog" import useCustomToast from "../../hooks/useCustomToast" const DeleteUser = ({ id }: { id: string }) => { const [isOpen, setIsOpen] = useState(false) const queryClient = useQueryClient() const { showSuccessToast, showErrorToast } = useCustomToast() const { handleSubmit, formState: { isSubmitting }, } = 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) }, onError: () => { showErrorToast("An error occurred while deleting the user") }, onSettled: () => { queryClient.invalidateQueries() }, }) const onSubmit = async () => { mutation.mutate(id) } return ( setIsOpen(open)} >
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.
) } export default DeleteUser