feat(catalog): undo bulk offer edits with guarded history restoration
CI / check (push) Successful in 2m1s
CI / deploy (push) Successful in 18s
CI / publish-container (push) Successful in 1m28s

This commit is contained in:
Simo committed 2026-09-11 10:47:46 +02:00
1 parent 13bd3695cb
commit c5a2b44807
33 files changed
+1399 -116

No files matched your search

@@ -4,7 +4,11 @@ import { ArrowRight, Loader2, SlidersHorizontal } from "lucide-react";
import { useTranslations } from "next-intl";
import { useRef, useState } from "react";
import { toast } from "sonner";
import { applyBulkOffers, previewBulkOffers } from "@/actions/catalog-bulk";
import {
applyBulkOffers,
previewBulkOffers,
undoBulkOffers,
} from "@/actions/catalog-bulk";
import { MovePageCombobox } from "@/app/admin/catalog/[id]/catalog-items-table/field-helpers";
import { POINTS_TYPES } from "@/app/admin/catalog/[id]/catalog-items-table/types";
import {
@@ -174,7 +178,34 @@ export function BulkOfferEditor({
setPreview(null);
return;
}
toast.success(t("success", { count: result.data.changedCount }));
toast.success(t("success", { count: result.data.changedCount }), {
duration: 15000,
description: t("undoHint"),
action: result.data.historyIds.length
? {
label: t("undo"),
onClick: async () => {
if (busyRef.current || (beforeEdit && !beforeEdit())) return;
busyRef.current = true;
try {
const restored = await undoBulkOffers(result.data.historyIds);
if (!restored.ok) {
toast.error(restored.error);
return;
}
toast.success(
t("undoSuccess", { count: restored.data.changedCount }),
);
await onApplied();
} catch {
toast.error(t("requestFailed"));
} finally {
busyRef.current = false;
}
},
}
: undefined,
});
setOpen(false);
await onApplied();
} catch {