fix(web): handle delete failure in confirm dialog (no unhandled rejection)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,9 +20,18 @@ export function DeleteObjectDialog({ id }: { id: string }) {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const del = useDeleteObject();
|
const del = useDeleteObject();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const [error, setError] = useState(false);
|
||||||
|
|
||||||
const onConfirm = async () => {
|
const onConfirm = async () => {
|
||||||
|
setError(false);
|
||||||
|
try {
|
||||||
await del.mutateAsync(id);
|
await del.mutateAsync(id);
|
||||||
|
} catch {
|
||||||
|
// Keep the dialog open so the user can retry or cancel; never let the
|
||||||
|
// rejected mutation escape as an unhandled promise rejection.
|
||||||
|
setError(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
navigate("/objects");
|
navigate("/objects");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -39,6 +48,11 @@ export function DeleteObjectDialog({ id }: { id: string }) {
|
|||||||
<AlertDialogContent>
|
<AlertDialogContent>
|
||||||
<AlertDialogTitle>{t("actions.delete")}</AlertDialogTitle>
|
<AlertDialogTitle>{t("actions.delete")}</AlertDialogTitle>
|
||||||
<AlertDialogDescription>{t("actions.confirmDelete")}</AlertDialogDescription>
|
<AlertDialogDescription>{t("actions.confirmDelete")}</AlertDialogDescription>
|
||||||
|
{error && (
|
||||||
|
<p role="alert" className="text-sm text-red-600">
|
||||||
|
{t("form.rejected")}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
<AlertDialogCancel>{t("form.cancel")}</AlertDialogCancel>
|
<AlertDialogCancel>{t("form.cancel")}</AlertDialogCancel>
|
||||||
<AlertDialogAction onClick={onConfirm}>
|
<AlertDialogAction onClick={onConfirm}>
|
||||||
|
|||||||
Reference in New Issue
Block a user