@flowselections/floriday-klanten-module 1.0.97 → 1.0.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"BulkStickerUploadDialog.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/BulkStickerUploadDialog.tsx"],"names":[],"mappings":"AA2BA,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAiDF,wBAAgB,uBAAuB,CAAC,EACtC,WAAW,EACX,QAAQ,EACR,MAAM,GACP,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,+BAgdA"}
1
+ {"version":3,"file":"BulkStickerUploadDialog.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/BulkStickerUploadDialog.tsx"],"names":[],"mappings":"AA4BA,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAiDF,wBAAgB,uBAAuB,CAAC,EACtC,WAAW,EACX,QAAQ,EACR,MAAM,GACP,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,+BAqeA"}
@@ -7,6 +7,7 @@ import { toast } from "sonner";
7
7
  import { supabase } from "../../integrations/supabase/client.js";
8
8
  import { ALLOWED_STICKER_MIME, commitStickerBatch, discardStickerBatch, suggestStickerMatches, } from "../../lib/customer-stickers.functions.js";
9
9
  import { friendlyError } from "../../lib/errors.js";
10
+ import { inPorties, teVeelStickerBestanden } from "../../lib/sticker-porties.js";
10
11
  import { SearchableSelect } from "./SearchableSelect.js";
11
12
  const BUCKET = "customer-stickers";
12
13
  const MAX_SIZE = 10 * 1024 * 1024;
@@ -89,6 +90,11 @@ export function BulkStickerUploadDialog({ customerKey, products, onDone, }) {
89
90
  toast.error(`${tooBig.length} bestand(en) zijn groter dan 10 MB en worden overgeslagen.`);
90
91
  if (files.length === 0)
91
92
  return;
93
+ const teVeel = teVeelStickerBestanden(files.length);
94
+ if (teVeel) {
95
+ toast.error(teVeel);
96
+ return;
97
+ }
92
98
  const id = crypto.randomUUID();
93
99
  setBatchId(id);
94
100
  setPhase("uploading");
@@ -126,43 +132,55 @@ export function BulkStickerUploadDialog({ customerKey, products, onDone, }) {
126
132
  return;
127
133
  }
128
134
  setPhase("matching");
129
- try {
130
- const res = await suggest({
131
- data: {
132
- files: staged.map((s) => ({
133
- fileId: s.fileId,
134
- fileName: s.fileName,
135
- thumbnail: s.thumbnail,
136
- })),
137
- products: products.map((p) => ({
138
- key: p.key,
139
- name: p.name,
140
- code: p.code,
141
- vbn: p.vbn,
142
- botanical: p.botanical,
143
- })),
144
- },
145
- });
146
- if (res.aiError)
147
- toast.warning(res.aiError);
148
- const byId = new Map(res.suggestions.map((s) => [s.fileId, s]));
149
- setRows((prev) => prev.map((r) => {
150
- const s = byId.get(r.fileId);
151
- return s
152
- ? {
153
- ...r,
154
- tradeItemKey: s.tradeItemKey,
155
- confidence: s.confidence,
156
- reason: s.reason,
157
- replaceExisting: s.tradeItemKey
158
- ? (productByKey.get(s.tradeItemKey)?.hasSticker ?? false)
159
- : false,
160
- }
161
- : r;
162
- }));
135
+ const porties = inPorties(staged);
136
+ setProgress({ done: 1, total: porties.length });
137
+ let deelMislukt = false;
138
+ for (let i = 0; i < porties.length; i++) {
139
+ setProgress({ done: i + 1, total: porties.length });
140
+ try {
141
+ const res = await suggest({
142
+ data: {
143
+ files: porties[i].map((s) => ({
144
+ fileId: s.fileId,
145
+ fileName: s.fileName,
146
+ thumbnail: s.thumbnail,
147
+ })),
148
+ products: products.map((p) => ({
149
+ key: p.key,
150
+ name: p.name,
151
+ code: p.code,
152
+ vbn: p.vbn,
153
+ botanical: p.botanical,
154
+ })),
155
+ },
156
+ });
157
+ if (res.aiError)
158
+ toast.warning(res.aiError);
159
+ const byId = new Map(res.suggestions.map((s) => [s.fileId, s]));
160
+ setRows((prev) => prev.map((r) => {
161
+ const s = byId.get(r.fileId);
162
+ return s
163
+ ? {
164
+ ...r,
165
+ tradeItemKey: s.tradeItemKey,
166
+ confidence: s.confidence,
167
+ reason: s.reason,
168
+ replaceExisting: s.tradeItemKey
169
+ ? (productByKey.get(s.tradeItemKey)?.hasSticker ?? false)
170
+ : false,
171
+ }
172
+ : r;
173
+ }));
174
+ }
175
+ catch (e) {
176
+ console.error("Automatisch koppelen van stickers mislukt (portie", i + 1, ")", e);
177
+ deelMislukt = true;
178
+ }
163
179
  }
164
- catch (e) {
165
- toast.error(friendlyError(e, "AI-herkenning mislukt — koppel de stickers handmatig."));
180
+ if (deelMislukt) {
181
+ toast.error(porties.length > 1
182
+ ? "Een deel van de stickers kon niet automatisch gekoppeld worden. Koppel die handmatig."
183
+ : "De stickers konden niet automatisch gekoppeld worden. Koppel ze handmatig.");
166
184
  }
167
185
  setPhase("review");
168
186
  };
@@ -235,7 +253,9 @@ export function BulkStickerUploadDialog({ customerKey, products, onDone, }) {
235
253
  void handleFiles(e.dataTransfer.files);
236
254
  }, children: [_jsx("p", { className: "text-sm text-muted-foreground mb-4", children: "Sleep een map of losse stickerbestanden hierheen (PDF, PNG, JPG of SVG, max. 10 MB per bestand)." }), _jsxs("div", { className: "flex justify-center gap-2", children: [_jsxs(Button, { type: "button", onClick: () => folderRef.current?.click(), children: [_jsx(FolderOpen, { className: "h-4 w-4 mr-1.5" }), "Map kiezen"] }), _jsx(Button, { type: "button", variant: "outline", onClick: () => filesRef.current?.click(), children: "Bestanden kiezen" })] })] })), (phase === "uploading" || phase === "matching") && (_jsxs("div", { className: "flex items-center gap-3 p-10 justify-center text-sm text-muted-foreground", children: [_jsx(Loader2, { className: "h-4 w-4 animate-spin" }), phase === "uploading"
237
255
  ? `Bestanden uploaden… ${progress.done}/${progress.total}`
238
- : "AI zoekt bij elke sticker het juiste product…"] })), (phase === "review" || phase === "saving") && (_jsx("div", { className: "max-h-[60vh] overflow-auto", children: _jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { className: "sticky top-0 bg-background", children: _jsxs("tr", { className: "border-b text-left", children: [_jsx("th", { className: "py-2 w-56", children: "Sticker" }), _jsx("th", { className: "py-2", children: "Bestand" }), _jsx("th", { className: "py-2 w-[340px]", children: "Product" }), _jsx("th", { className: "py-2 w-32", children: "Zekerheid" }), _jsx("th", { className: "py-2 w-40", children: "Bestaand" }), _jsx("th", { className: "py-2 w-10" })] }) }), _jsx("tbody", { children: rows.map((r) => {
256
+ : progress.total > 1
257
+ ? `Koppelen ${progress.done} van ${progress.total}…`
258
+ : "AI zoekt bij elke sticker het juiste product…"] })), (phase === "review" || phase === "saving") && (_jsx("div", { className: "max-h-[60vh] overflow-auto", children: _jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { className: "sticky top-0 bg-background", children: _jsxs("tr", { className: "border-b text-left", children: [_jsx("th", { className: "py-2 w-56", children: "Sticker" }), _jsx("th", { className: "py-2", children: "Bestand" }), _jsx("th", { className: "py-2 w-[340px]", children: "Product" }), _jsx("th", { className: "py-2 w-32", children: "Zekerheid" }), _jsx("th", { className: "py-2 w-40", children: "Bestaand" }), _jsx("th", { className: "py-2 w-10" })] }) }), _jsx("tbody", { children: rows.map((r) => {
239
259
  const product = r.tradeItemKey ? productByKey.get(r.tradeItemKey) : null;
240
260
  const dup = r.tradeItemKey ? duplicates.has(r.tradeItemKey) : false;
241
261
  return (_jsxs("tr", { className: "border-b align-middle", children: [_jsx("td", { className: "py-2", children: r.thumbnail ? (_jsx("button", { type: "button", className: "block cursor-zoom-in", title: "Klik om te vergroten", onClick: () => setPreviewRow(r), children: _jsx("img", { src: r.thumbnail, alt: r.fileName, className: "h-44 w-44 rounded border object-contain bg-white hover:ring-2 hover:ring-primary/50" }) })) : (_jsx("div", { className: "h-44 w-44 rounded border bg-muted flex items-center justify-center", children: _jsx(FileText, { className: "h-6 w-6 text-muted-foreground" }) })) }), _jsxs("td", { className: "py-2 pr-3", children: [_jsx("div", { className: "truncate max-w-[220px]", title: r.fileName, children: r.fileName }), r.reason && (_jsx("div", { className: "text-xs text-muted-foreground truncate max-w-[220px]", children: r.reason }))] }), _jsxs("td", { className: "py-2 pr-3", children: [_jsx(SearchableSelect, { value: r.tradeItemKey ?? "", options: productOptions, placeholder: "Kies product\u2026", triggerClassName: "w-full", onValueChange: (v) => setRows((prev) => prev.map((x) => x.fileId === r.fileId