diff --git a/src/components/admin/studio/organize-imports-dialog.tsx b/src/components/admin/studio/organize-imports-dialog.tsx index 22725556..48a31322 100644 --- a/src/components/admin/studio/organize-imports-dialog.tsx +++ b/src/components/admin/studio/organize-imports-dialog.tsx @@ -1,6 +1,7 @@ "use client"; import { + ArrowRight, Eye, Folder, FolderTree, @@ -304,6 +305,10 @@ export function OrganizeImportsDialog({ const handleCreate = async () => { if (isCreating) return; + if (totalSelected > 1000) { + toast.error(t("errorMaxItems")); + return; + } if (moveMode && destinationPageId == null) { toast.error(t("chooseDestination")); return; @@ -325,11 +330,20 @@ export function OrganizeImportsDialog({ credits: freeMode ? 0 : credits, points: freeMode ? 0 : points, pointsType: freeMode ? 0 : pointsType, + amount: 1, })), }; }); + + // Frontend validation for group count + const MAX_GROUPS = 50; + if (payload.length > MAX_GROUPS) { + toast.error(t("errorMaxGroups", { count: MAX_GROUPS })); + return; + } + if (payload.length === 0 || payload.some((g) => !g.caption)) { - toast.error("Every approved page needs a name"); + toast.error(t("errorNoName")); return; } setIsCreating(true); @@ -341,20 +355,28 @@ export function OrganizeImportsDialog({ const moved = created.reduce((sum, c) => sum + c.moved, 0); const added = created.reduce((sum, c) => sum + c.added, 0); toast.success( - `Moved ${moved} offer${moved === 1 ? "" : "s"}${ - added > 0 ? `, added ${added} new` : "" - } to "${destinationCaption ?? "page"}"`, + t("successMove", { + moved, + added, + destination: destinationCaption ?? "page", + }), ); } else { + const moved = created.reduce((sum, c) => sum + c.moved, 0); + const added = created.reduce((sum, c) => sum + c.added, 0); toast.success( - `Created ${created.length} page${created.length === 1 ? "" : "s"}`, + t("successCreate", { + count: created.length, + moved, + added, + }), ); } onOpenChange(false); router.refresh(); } catch (error) { console.error("[OrganizeImports] create failed:", error); - toast.error("Failed to organize imports"); + toast.error(t("errorFailed")); } finally { setIsCreating(false); } @@ -365,15 +387,21 @@ export function OrganizeImportsDialog({ - - - {t("title")} - {totalSelected > 0 && !loading && ( - - {t("itemsBadge", { count: totalSelected })} - - )} - + + + {t("title")} + {totalSelected > 0 && !loading && ( + + {t("itemsBadge", { count: totalSelected })} + + )} +
+ {moveMode + ? t("tipMove") + : t("tipCreate")} +
+

{t("limitHint")}

+
@@ -460,22 +488,24 @@ export function OrganizeImportsDialog({ type="button" variant={!moveMode ? "default" : "outline"} size="sm" - className="h-6 px-2 text-[10px]" + className={cn("h-7 px-3 text-[11px] gap-1.5", !moveMode && "ring-2 ring-primary ring-offset-1")} onClick={() => { setMoveMode(false); setDestinationPageId(null); setDestinationCaption(null); }} > + {t("modeCreate")}
@@ -656,7 +686,7 @@ export function OrganizeImportsDialog({ {/* Batch Actions Bar */}
- Batch: + {t("batchLabel")}