feat(studio): improve organize imports UX with validation limits and translations
This commit is contained in:
1 parent
d2572757cd
commit
8707c0d8fe
3 files changed
+84
-23
No files matched your search
@@ -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({
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="flex h-[90vh] max-h-[90vh] w-[800px] max-w-[95vw] flex-col overflow-hidden p-0">
|
||||
<DialogHeader className="flex-none border-b px-4 py-3">
|
||||
<DialogTitle className="flex items-center gap-2 text-sm font-semibold">
|
||||
<FolderTree className="h-4 w-4" />
|
||||
{t("title")}
|
||||
{totalSelected > 0 && !loading && (
|
||||
<Badge variant="secondary" className="text-[10px]">
|
||||
{t("itemsBadge", { count: totalSelected })}
|
||||
</Badge>
|
||||
)}
|
||||
</DialogTitle>
|
||||
<DialogTitle className="flex items-center gap-2 text-sm font-semibold">
|
||||
<FolderTree className="h-4 w-4" />
|
||||
{t("title")}
|
||||
{totalSelected > 0 && !loading && (
|
||||
<Badge variant="secondary" className="text-[10px]">
|
||||
{t("itemsBadge", { count: totalSelected })}
|
||||
</Badge>
|
||||
)}
|
||||
<div className="flex-1 text-[10px] text-muted-foreground ml-2">
|
||||
{moveMode
|
||||
? t("tipMove")
|
||||
: t("tipCreate")}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground ml-2">{t("limitHint")}</p>
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-4">
|
||||
@@ -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);
|
||||
}}
|
||||
>
|
||||
<Plus className="h-3.5 w-3.5" />
|
||||
{t("modeCreate")}
|
||||
</Button>
|
||||
<Button
|
||||
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(true)}
|
||||
>
|
||||
<ArrowRight className="h-3.5 w-3.5" />
|
||||
{t("modeMove")}
|
||||
</Button>
|
||||
</div>
|
||||
@@ -656,7 +686,7 @@ export function OrganizeImportsDialog({
|
||||
{/* Batch Actions Bar */}
|
||||
<div className="flex flex-wrap items-center gap-2 border-t pt-2.5">
|
||||
<span className="text-[10px] font-medium text-muted-foreground">
|
||||
Batch:
|
||||
{t("batchLabel")}
|
||||
</span>
|
||||
<Select
|
||||
value={batchLayout}
|
||||
@@ -673,7 +703,7 @@ export function OrganizeImportsDialog({
|
||||
<SelectContent>
|
||||
{CATALOG_LAYOUTS.map((l) => (
|
||||
<SelectItem key={l} value={l} className="text-xs">
|
||||
{l}
|
||||
{l === "default_3x3" ? t("layoutFallbackDefault3x3") : l}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
@@ -936,8 +966,11 @@ export function OrganizeImportsDialog({
|
||||
{thumb.alreadyPlaced ? (
|
||||
<span className="max-w-14 truncate text-[8px] text-muted-foreground">
|
||||
{thumb.sourcePageCaption
|
||||
? thumb.sourcePageCaption.replace(/^Imp /, "")
|
||||
: "moved"}
|
||||
? thumb.sourcePageCaption.replace(
|
||||
new RegExp(`^${t("impPrefix")}`),
|
||||
"",
|
||||
)
|
||||
: t("isMoved")}
|
||||
</span>
|
||||
) : (
|
||||
<span className="max-w-14 truncate text-[8px] text-muted-foreground">
|
||||
|
||||
+15
-1
@@ -2251,7 +2251,21 @@
|
||||
"searchGroups": "Filter import groups...",
|
||||
"visualPreview": "Preview",
|
||||
"resetAll": "Reset overrides",
|
||||
"onlyUnplaced": "Only show unplaced items"
|
||||
"onlyUnplaced": "Only show unplaced items",
|
||||
"errorMaxItems": "Max 1000 items per run. Reduce selection.",
|
||||
"errorMaxGroups": "Max {count} groups per run. Reduce selection.",
|
||||
"errorNoName": "Every approved page needs a name",
|
||||
"tipMove": "Tip: Pick a destination page below to move furniture.",
|
||||
"tipCreate": "Tip: Pick this mode to create new pages.",
|
||||
"limitHint": "Max 1000 items and 50 groups per run.",
|
||||
"errorFailed": "Failed to organize imports",
|
||||
"successMove": "Moved {moved} offer{moved, plural, one {} other {s}}{added, plural, =0 {} other {, added {added} new}} to \"{destination}\"",
|
||||
"successCreate": "Created {count, plural, one {1 page} other {# pages}} with {moved} moved and {added} added furniture",
|
||||
"batchLabel": "Batch:",
|
||||
"layoutFallbackDefault3x3": "3x3",
|
||||
"itemsUnit": "items",
|
||||
"impPrefix": "Imp ",
|
||||
"isMoved": "moved"
|
||||
}
|
||||
},
|
||||
"bulk": {
|
||||
|
||||
+15
-1
@@ -2013,7 +2013,21 @@
|
||||
"searchGroups": "Filter importgroepen...",
|
||||
"visualPreview": "Voorbeeld",
|
||||
"resetAll": "Wijzigingen herstellen",
|
||||
"onlyUnplaced": "Toon alleen ongeplaatste items"
|
||||
"onlyUnplaced": "Toon alleen ongeplaatste items",
|
||||
"errorMaxItems": "Maximaal 1000 items per run. Verlaag de selectie.",
|
||||
"errorMaxGroups": "Maximaal {count} groepen per run. Verlaag de selectie.",
|
||||
"errorNoName": "Elke goedgekeurde pagina heeft een naam nodig",
|
||||
"tipMove": "Tip: Kies de doelpagina in het vak hieronder om meubels te verplaatsen.",
|
||||
"tipCreate": "Tip: Kies deze modus om nieuwe pagina's aan te maken.",
|
||||
"limitHint": "Maximaal 1000 items en 50 groepen per run.",
|
||||
"errorFailed": "Kon imports niet organiseren",
|
||||
"successMove": "{moved} item{moved, plural, one { verplaatst} other {s verplaatst}}{added, plural, =0 {} other {, {added} nieuw toegevoegd}} naar \"{destination}\"",
|
||||
"successCreate": "{count, plural, one {1 pagina} other {# pagina's}} aangemaakt met {moved} verplaatste en {added} toegevoegde meubels",
|
||||
"batchLabel": "Batch:",
|
||||
"layoutFallbackDefault3x3": "3x3",
|
||||
"itemsUnit": "items",
|
||||
"impPrefix": "Imp ",
|
||||
"isMoved": "verplaatst"
|
||||
}
|
||||
},
|
||||
"bulk": {
|
||||
|
||||
Reference in new issue
Block a user