;
children: React.ReactNode | ((state: ActionResult) => React.ReactNode);
submitLabel?: string;
extraActions?: React.ReactNode;
className?: string;
}) {
const [state, formAction] = useActionState(action, null);
const [visible, setVisible] = useState(false);
useEffect(() => {
if (!state) return;
setVisible(true);
if (state.ok) {
const t = setTimeout(() => setVisible(false), 4000);
return () => clearTimeout(t);
}
}, [state]);
return (
);
}
/** Knopf mit Rückfrage (z. B. Löschen). `inForm`: sitzt in einem anderen Formular und nutzt dessen Felder. */
export function ConfirmButton({
action,
confirm,
children,
className = "sm-btn sm-btn--ghost",
hidden,
title,
inForm,
}: {
action: (fd: FormData) => Promise;
confirm: string;
children: React.ReactNode;
className?: string;
hidden?: Record;
title?: string;
inForm?: boolean;
}) {
const [armed, setArmed] = useState(false);
const inner = armed ? (
{confirm}
) : (
);
if (inForm) return inner;
return (
);
}