import { zodResolver } from "@hookform/resolvers/zod"; import { t, Trans } from "@lingui/macro"; import { Button, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, Input, } from "@reactive-resume/ui"; import { useForm } from "react-hook-form"; import { useNavigate } from "react-router-dom"; import { useCounter } from "usehooks-ts"; import { z } from "zod"; import { useToast } from "@/client/hooks/use-toast"; import { useLogout } from "@/client/services/auth"; import { useDeleteUser } from "@/client/services/user"; const formSchema = z.object({ deleteConfirm: z.literal("delete"), }); type FormValues = z.infer; export const DangerZoneSettings = () => { const { toast } = useToast(); const navigate = useNavigate(); const { logout } = useLogout(); const { count, increment } = useCounter(0); const { deleteUser, loading } = useDeleteUser(); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { deleteConfirm: "" as FormValues["deleteConfirm"], }, }); const onDelete = async () => { // On the first click, increment the counter increment(); // On the second click, delete the account if (count === 1) { await Promise.all([deleteUser(), logout()]); toast({ variant: "success", title: t`Your account and all your data has been deleted successfully. Goodbye!`, }); navigate("/"); } }; return (

{t`Danger Zone`}

In this section, you can delete your account and all the data associated to your user, but please keep in mind that{" "} this action is irreversible.

( {t`Delete Account`} Type delete to confirm deleting your account. )} />
); };