import { FormEventHandler, useRef, useState } from "react"; import { InputError } from "@/components/ui/input-error"; import { useForm } from "@inertiajs/react"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export default function DeleteUserForm({ className = "", }: { className?: string; }) { const [open, setOpen] = useState(false); const passwordInput = useRef(null); const { data, setData, delete: destroy, processing, reset, errors, } = useForm({ password: "", }); const deleteUser: FormEventHandler = (e) => { e.preventDefault(); destroy(route("profile.destroy"), { preserveScroll: true, onSuccess: () => closeModal(), onError: () => passwordInput.current?.focus(), onFinish: () => reset(), }); }; const closeModal = () => { reset(); }; return (
Are you sure you want to delete your account? Once your account is deleted, all of its resources and data will be permanently deleted. Please enter your password to confirm you would like to permanently delete your account.
setData("password", e.target.value) } placeholder="Password" />
setOpen(false)}> Cancel Delete Account
); }