@flowselections/floriday-verkoop-module 1.0.147 → 1.0.149

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":"CreateOrderPage.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/CreateOrderPage.tsx"],"names":[],"mappings":"AA2FA,wBAAgB,eAAe,gCAusC9B"}
1
+ {"version":3,"file":"CreateOrderPage.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/CreateOrderPage.tsx"],"names":[],"mappings":"AA2FA,wBAAgB,eAAe,gCAitC9B"}
@@ -537,7 +537,8 @@ export function CreateOrderPage() {
537
537
  },
538
538
  });
539
539
  // ---- Afhaallocatie: één eigen locatie → die; anders de laatst gebruikte
540
- // bij deze klant (uit bestaande orders), mits die nog actief in de lijst staat.
540
+ // bij deze klant (uit bestaande orders), mits die nog actief in de lijst staat;
541
+ // anders de standaard eigen afhaallocatie uit Instellingen.
541
542
  const fetchLastPickup = useServerFn(getLastPickupLocationCO);
542
543
  const lastPickupQ = useQuery({
543
544
  queryKey: ["co-last-pickup", customerId],
@@ -568,8 +569,12 @@ export function CreateOrderPage() {
568
569
  setPickupLocationId(last);
569
570
  setPickupFromLast(true);
570
571
  }
571
- else if (pickupFromLast) {
572
- setPickupLocationId(null);
572
+ else {
573
+ const def = pickupLocations.find((l) => l.isDefault);
574
+ if (def && (!pickupLocationId || pickupFromLast))
575
+ setPickupLocationId(def.id);
576
+ else if (pickupFromLast)
577
+ setPickupLocationId(null);
573
578
  setPickupFromLast(false);
574
579
  }
575
580
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -677,7 +682,9 @@ export function CreateOrderPage() {
677
682
  label: l.name || deliveryAddr(l) || "Locatie",
678
683
  hint: l.name ? deliveryAddr(l) : undefined,
679
684
  badge: l.is_primary ? "Standaard" : null,
680
- })), onChange: (v) => { setDeliveryLocationId(v); setDeliveryEditOpen(false); } }))] }), _jsxs("div", { className: "space-y-1.5", children: [_jsxs(Label, { className: fieldLabel, children: ["Afhaallocatie ", _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(SearchableSelect, { value: pickupLocationId, placeholder: pickupLocations.length ? "Kies eigen locatie…" : "Geen eigen locaties bekend", disabled: pickupLocations.length === 0, allowClear: false, options: pickupLocations.map((l) => ({ value: l.id, label: l.name })), onChange: (v) => { pickupTouched.current = true; setPickupFromLast(false); setPickupLocationId(v); } }), pickupFromLast && _jsx("div", { className: "text-xs text-muted-foreground", children: "Laatst gebruikt bij deze klant" })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { className: fieldLabel, children: "Vervoerder" }), isReservation ? (_jsx("div", { className: "flex h-9 items-center rounded-md border border-border bg-muted/40 px-3 text-sm text-muted-foreground", children: "Wordt gekozen bij de verzending" })) : (_jsx(SearchableSelect, { value: ownTransport ? "__own__" : carrierId ?? "__auto__", placeholder: !deliveryLocationId ? "Kies eerst een afleverlocatie" : "Automatisch", disabled: !deliveryLocationId, allowClear: false, options: [
685
+ })), onChange: (v) => { setDeliveryLocationId(v); setDeliveryEditOpen(false); } }))] }), _jsxs("div", { className: "space-y-1.5", children: [_jsxs(Label, { className: fieldLabel, children: ["Afhaallocatie ", _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(SearchableSelect, { value: pickupLocationId, placeholder: pickupLocations.length ? "Kies eigen locatie…" : "Geen eigen locaties bekend", disabled: pickupLocations.length === 0, allowClear: false, options: pickupLocations.map((l) => ({ value: l.id, label: l.name, badge: l.isDefault ? "Standaard" : null })), onChange: (v) => { pickupTouched.current = true; setPickupFromLast(false); setPickupLocationId(v); } }), pickupFromLast && _jsx("div", { className: "text-xs text-muted-foreground", children: "Laatst gebruikt bij deze klant" }), pickupQ.isSuccess && pickupLocations.length === 0 && (_jsx("div", { className: "text-xs text-muted-foreground", children: pickupQ.data?.source === "floriday"
686
+ ? "Geen eigen Floriday-warehouses gevonden. Controleer de Floriday-synchronisatie."
687
+ : "Geen Floriday-koppeling: voeg een afhaallocatie toe via Instellingen → Afhaallocaties." }))] }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { className: fieldLabel, children: "Vervoerder" }), isReservation ? (_jsx("div", { className: "flex h-9 items-center rounded-md border border-border bg-muted/40 px-3 text-sm text-muted-foreground", children: "Wordt gekozen bij de verzending" })) : (_jsx(SearchableSelect, { value: ownTransport ? "__own__" : carrierId ?? "__auto__", placeholder: !deliveryLocationId ? "Kies eerst een afleverlocatie" : "Automatisch", disabled: !deliveryLocationId, allowClear: false, options: [
681
688
  { value: "__auto__", label: preview?.carrierId && !carrierId && !ownTransport ? `Automatisch: ${carrierName(preview.carrierId) ?? "onbekend"}` : "Automatisch" },
682
689
  { value: "__own__", label: "Eigen vervoer / zelf afleveren" },
683
690
  ...carriers.map((c) => ({ value: c.id, label: c.name })),
@@ -0,0 +1,2 @@
1
+ export declare function PickupLocationsSettingsCard(): import("react").JSX.Element;
2
+ //# sourceMappingURL=PickupLocationsSettings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PickupLocationsSettings.d.ts","sourceRoot":"","sources":["../../../src/components/verkoop/PickupLocationsSettings.tsx"],"names":[],"mappings":"AA4DA,wBAAgB,2BAA2B,gCAwM1C"}
@@ -0,0 +1,91 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Instellingenkaart: eigen afhaallocaties (tuinen) voor accounts zonder
3
+ // Floriday-koppeling. Met een actieve koppeling komen de afhaallocaties alleen
4
+ // uit de Floriday-warehouses en worden deze eigen locaties niet gebruikt.
5
+ import { useState } from "react";
6
+ import { useQuery, useQueryClient } from "@tanstack/react-query";
7
+ import { useServerFn } from "@tanstack/react-start";
8
+ import { Badge, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, Label, Switch, toast, } from "@flowselections/core";
9
+ import { Info, MapPin, Pencil, Plus, Trash2 } from "lucide-react";
10
+ import { ConfirmDialog } from "./ConfirmDialog.js";
11
+ import { archiveOwnPickupLocation, listOwnPickupLocations, saveOwnPickupLocation, } from "../../lib/pickup-locations.functions.js";
12
+ const EMPTY = { id: null, name: "", addressLine: "", postalCode: "", city: "", country: "NL", gln: "", isDefault: false };
13
+ function toDraft(l) {
14
+ return {
15
+ id: l.id,
16
+ name: l.name,
17
+ addressLine: l.addressLine ?? "",
18
+ postalCode: l.postalCode ?? "",
19
+ city: l.city ?? "",
20
+ country: l.country ?? "",
21
+ gln: l.gln ?? "",
22
+ isDefault: l.isDefault,
23
+ };
24
+ }
25
+ export function PickupLocationsSettingsCard() {
26
+ const list = useServerFn(listOwnPickupLocations);
27
+ const save = useServerFn(saveOwnPickupLocation);
28
+ const archive = useServerFn(archiveOwnPickupLocation);
29
+ const qc = useQueryClient();
30
+ const query = useQuery({ queryKey: ["own-pickup-locations"], queryFn: () => list() });
31
+ const items = query.data?.items ?? [];
32
+ const [draft, setDraft] = useState(null);
33
+ const [saving, setSaving] = useState(false);
34
+ const [toRemove, setToRemove] = useState(null);
35
+ async function refresh() {
36
+ await Promise.all([
37
+ qc.invalidateQueries({ queryKey: ["own-pickup-locations"] }),
38
+ qc.invalidateQueries({ queryKey: ["co-pickup"] }),
39
+ ]);
40
+ }
41
+ async function submit() {
42
+ if (!draft)
43
+ return;
44
+ if (!draft.name.trim()) {
45
+ toast.error("Naam is verplicht");
46
+ return;
47
+ }
48
+ setSaving(true);
49
+ try {
50
+ await save({
51
+ data: {
52
+ id: draft.id,
53
+ name: draft.name,
54
+ addressLine: draft.addressLine,
55
+ postalCode: draft.postalCode,
56
+ city: draft.city,
57
+ country: draft.country,
58
+ gln: draft.gln,
59
+ isDefault: draft.isDefault,
60
+ },
61
+ });
62
+ toast.success("Afhaallocatie opgeslagen");
63
+ setDraft(null);
64
+ await refresh();
65
+ }
66
+ catch (e) {
67
+ toast.error(e?.issues?.[0]?.message ?? e?.message ?? "Opslaan mislukt");
68
+ }
69
+ finally {
70
+ setSaving(false);
71
+ }
72
+ }
73
+ async function remove(l) {
74
+ try {
75
+ await archive({ data: { id: l.id } });
76
+ toast.success("Afhaallocatie verwijderd");
77
+ await refresh();
78
+ }
79
+ catch (e) {
80
+ toast.error(e?.message ?? "Verwijderen mislukt");
81
+ }
82
+ }
83
+ const set = (patch) => setDraft((d) => (d ? { ...d, ...patch } : d));
84
+ return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsxs(CardTitle, { className: "flex items-center gap-2", children: [_jsx(MapPin, { className: "h-5 w-5" }), " Afhaallocaties"] }), _jsx(CardDescription, { children: "Eigen locaties (tuinen) waar orders worden opgehaald. Worden alleen gebruikt als dit account niet met Floriday is gekoppeld; met Floriday komen de afhaallocaties uit je Floriday-warehouses." })] }), _jsxs(CardContent, { className: "space-y-4", children: [query.data?.source === "floriday" && (_jsxs("div", { className: "flex items-start gap-2 rounded-md border border-border bg-muted/40 p-3 text-sm text-muted-foreground", children: [_jsx(Info, { className: "mt-0.5 h-4 w-4 shrink-0" }), _jsx("span", { children: "Floriday is gekoppeld: nieuwe orders gebruiken de Floriday-warehouses. Deze locaties worden pas gebruikt als er geen actieve Floriday-koppeling meer is." })] })), query.isLoading ? (_jsx("p", { className: "text-sm text-muted-foreground", children: "Laden..." })) : query.isError ? (_jsxs("div", { className: "space-y-2", children: [_jsx("p", { className: "text-sm text-destructive", children: query.error?.message ?? "Laden mislukt" }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => query.refetch(), children: "Opnieuw proberen" })] })) : items.length === 0 ? (_jsx("p", { className: "text-sm text-muted-foreground", children: "Nog geen eigen afhaallocaties." })) : (_jsx("div", { className: "rounded-md border divide-y", children: items.map((l) => (_jsxs("div", { className: "flex items-center justify-between gap-3 p-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex items-center gap-2 text-sm font-medium", children: [_jsx("span", { className: "truncate", children: l.name }), l.isDefault && _jsx(Badge, { variant: "secondary", children: "Standaard" })] }), _jsxs("div", { className: "truncate text-xs text-muted-foreground", children: [[l.addressLine, [l.postalCode, l.city].filter(Boolean).join(" "), l.country]
85
+ .filter(Boolean)
86
+ .join(", ") || "Geen adres", l.gln && ` · GLN ${l.gln}`] })] }), _jsxs("div", { className: "flex shrink-0 gap-1", children: [_jsx(Button, { size: "icon", variant: "ghost", "aria-label": "Bewerken", onClick: () => setDraft(toDraft(l)), children: _jsx(Pencil, { className: "h-4 w-4" }) }), _jsx(Button, { size: "icon", variant: "ghost", "aria-label": "Verwijderen", onClick: () => setToRemove(l), children: _jsx(Trash2, { className: "h-4 w-4" }) })] })] }, l.id))) })), _jsxs(Button, { size: "sm", variant: "outline", disabled: query.isError, onClick: () => setDraft({ ...EMPTY, isDefault: items.length === 0 }), children: [_jsx(Plus, { className: "mr-1 h-4 w-4" }), " Afhaallocatie toevoegen"] })] }), _jsx(Dialog, { open: draft !== null, onOpenChange: (o) => !o && !saving && setDraft(null), children: _jsxs(DialogContent, { children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: draft?.id ? "Afhaallocatie bewerken" : "Afhaallocatie toevoegen" }), _jsx(DialogDescription, { children: "Wordt getoond bij \"Nieuwe bestelling\" en op het ophaaladres van de order." })] }), draft && (_jsxs("div", { className: "grid gap-3", children: [_jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { htmlFor: "pl-name", children: "Naam *" }), _jsx(Input, { id: "pl-name", value: draft.name, onChange: (e) => set({ name: e.target.value }), placeholder: "Bijv. Tuin Naaldwijk" })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { htmlFor: "pl-line", children: "Adres" }), _jsx(Input, { id: "pl-line", value: draft.addressLine, onChange: (e) => set({ addressLine: e.target.value }), placeholder: "Straat en huisnummer" })] }), _jsxs("div", { className: "grid grid-cols-[120px_minmax(0,1fr)_80px] gap-2", children: [_jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { htmlFor: "pl-pc", children: "Postcode" }), _jsx(Input, { id: "pl-pc", value: draft.postalCode, onChange: (e) => set({ postalCode: e.target.value }) })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { htmlFor: "pl-city", children: "Plaats" }), _jsx(Input, { id: "pl-city", value: draft.city, onChange: (e) => set({ city: e.target.value }) })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { htmlFor: "pl-country", children: "Land" }), _jsx(Input, { id: "pl-country", value: draft.country, onChange: (e) => set({ country: e.target.value }) })] })] }), _jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { htmlFor: "pl-gln", children: "GLN (optioneel)" }), _jsx(Input, { id: "pl-gln", inputMode: "numeric", value: draft.gln, onChange: (e) => set({ gln: e.target.value }), placeholder: "13 cijfers" })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Switch, { id: "pl-default", checked: draft.isDefault, onCheckedChange: (v) => set({ isDefault: v }) }), _jsx(Label, { htmlFor: "pl-default", children: "Standaard afhaallocatie" })] })] })), _jsxs(DialogFooter, { children: [_jsx(Button, { variant: "outline", disabled: saving, onClick: () => setDraft(null), children: "Annuleren" }), _jsx(Button, { disabled: saving, onClick: submit, children: saving ? "Opslaan..." : "Opslaan" })] })] }) }), _jsx(ConfirmDialog, { open: toRemove !== null, onOpenChange: (o) => !o && setToRemove(null), title: "Afhaallocatie verwijderen?", description: toRemove ? `"${toRemove.name}" is daarna niet meer te kiezen bij nieuwe orders. Bestaande orders houden hun ophaaladres.` : undefined, confirmLabel: "Verwijderen", destructive: true, onConfirm: () => {
87
+ if (toRemove)
88
+ remove(toRemove);
89
+ setToRemove(null);
90
+ } })] }));
91
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKvD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAIvE,eAAO,MAAM,qBAAqB,EAAE,UAsBnC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAMvD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAIvE,eAAO,MAAM,qBAAqB,EAAE,UAuBnC,CAAC"}
package/dist-lib/index.js CHANGED
@@ -2,6 +2,7 @@ import { ShoppingCart, ListOrdered } from "lucide-react";
2
2
  import { ProductDimensionsSettingsCard } from "./components/verkoop/ProductDimensionsSettings.js";
3
3
  import { InvoiceSignoffSettingsCard } from "./components/verkoop/InvoiceSignoffSettings.js";
4
4
  import { FloridaySyncSettingsCard } from "./components/verkoop/FloridaySyncSettings.js";
5
+ import { PickupLocationsSettingsCard } from "./components/verkoop/PickupLocationsSettings.js";
5
6
  export * from "./_core-safelist.js";
6
7
  export { VerkoopOrdersPage } from "./components/verkoop/VerkoopOrdersPage.js";
7
8
  export { SalesOrderDetailPage } from "./components/verkoop/SalesOrderDetailPage.js";
@@ -26,5 +27,6 @@ export const floridayVerkoopModule = {
26
27
  { component: ProductDimensionsSettingsCard, order: 20 },
27
28
  { component: InvoiceSignoffSettingsCard, order: 25 },
28
29
  { component: FloridaySyncSettingsCard, order: 15 },
30
+ { component: PickupLocationsSettingsCard, order: 18 },
29
31
  ],
30
32
  };