"use client"; import { useActionState, useState, type ReactNode } from "react"; import type { FormState } from "@/app/actions/types"; import { AlertIcon, TrashIcon } from "./icons"; import { TextField } from "./settings-fields"; import { PlateBody, PlateFooter } from "./settings-plate"; import { Alert, Button } from "./ui"; /** Deleting something for good: one red cap opens the type-to-confirm form, whose red cap does it. */ export function DeleteZone({ action, confirmText, title, description, consequence, openLabel, confirmLabel, }: { action: (prev: FormState, formData: FormData) => Promise; /** What has to be typed to confirm; posted as `confirm`. */ confirmText: string; title: string; description: string; /** What goes with it, said in red once the form is open. */ consequence: ReactNode; openLabel: string; confirmLabel: string; }) { const [state, formAction, pending] = useActionState(action, undefined); const [confirm, setConfirm] = useState(""); const [open, setOpen] = useState(false); return ( <>

{title}

{description}

{!open && ( )}
{open && (

{consequence}

setConfirm(e.target.value)} autoFocus /> {state?.error && {state.error}}
)} ); }