@flowselections/floriday-authenticatie-module 1.0.54 → 1.0.56

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":"FlorydaySettingsCard.d.ts","sourceRoot":"","sources":["../../../src/components/settings/FlorydaySettingsCard.tsx"],"names":[],"mappings":"AA8EA,wBAAgB,oBAAoB,gCAqHnC"}
1
+ {"version":3,"file":"FlorydaySettingsCard.d.ts","sourceRoot":"","sources":["../../../src/components/settings/FlorydaySettingsCard.tsx"],"names":[],"mappings":"AA4EA,wBAAgB,oBAAoB,gCAqHnC"}
@@ -5,7 +5,7 @@ import { ChevronDown } from "lucide-react";
5
5
  import { useServerFn } from "@tanstack/react-start";
6
6
  import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
7
7
  import { Card, Button, Input, Label, Badge, Tabs, TabsList, TabsTrigger, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, toast, } from "@flowselections/core";
8
- import { listFlorydayConnections, upsertFlorydayConnection, testFlorydayConnection, deleteFlorydayConnection, getFlorydaySettings, setFlorydayActiveEnvironment, listFlorydayWarehouses, updateFlorydayPublishingSettings, validateGln, syncFlorydayConnections, getFlorydaySyncStatus, getFlorydayShellHostStatus, } from "../../lib/floriday.functions.js";
8
+ import { listFlorydayConnections, upsertFlorydayConnection, testFlorydayConnection, deleteFlorydayConnection, getFlorydaySettings, setFlorydayActiveEnvironment, getFlorydayOwnConfigStatus, updateFlorydayPublishingSettings, syncFlorydayConnections, getFlorydaySyncStatus, getFlorydayShellHostStatus, } from "../../lib/floriday.functions.js";
9
9
  import { syncFlorydayTradeItems, syncFlorydaySalesOrders, syncFlorydayCustomerOrganizations, syncFlorydayCarriers, syncFlorydayFulfillmentOrders, syncFlorydayCustomerStickers, syncFlorydayWarehouses, syncFlorydayPackings, syncFlorydayDeliveryLocations, syncFlorydayClockSupplies, syncFlorydayDeliveryOrders, syncFlorydayClockPresales, syncFlorydayContracts, syncFlorydayBlanketOrders, syncFlorydayAdditionalServices, syncFlorydayCommercialServiceTypes, syncFlorydayCollections, syncFlorydayPriceGroups, syncFlorydayDeliveryConditionSets, syncFlorydaySalesStrategies, syncFlorydayBaseItems, syncFlorydayContractTradeItemGroups, syncFlorydayCatalogPrices, } from "../../lib/floriday-sync.functions.js";
10
10
  import { FlorydayCredentialStatusBanner } from "../floriday/FlorydayCredentialStatusBanner.js";
11
11
  export function FlorydaySettingsCard() {
@@ -109,65 +109,43 @@ function ShellHostStatus() {
109
109
  }
110
110
  function PublishingSettings({ env, connection, }) {
111
111
  const qc = useQueryClient();
112
- const listWarehouses = useServerFn(listFlorydayWarehouses);
112
+ const getStatus = useServerFn(getFlorydayOwnConfigStatus);
113
113
  const updateSettings = useServerFn(updateFlorydayPublishingSettings);
114
- const [gln, setGln] = useState(connection?.gln_code ?? "");
115
- const [warehouseId, setWarehouseId] = useState(connection?.preferred_warehouse_id ?? "");
116
- const warehousesQuery = useQuery({
117
- queryKey: ["floriday-warehouses", env],
118
- queryFn: () => listWarehouses({ data: { environment: env } }),
114
+ const [warehouseId, setWarehouseId] = useState("");
115
+ const statusQuery = useQuery({
116
+ queryKey: ["floriday-own-config", env],
117
+ queryFn: () => getStatus({ data: { environment: env } }),
119
118
  enabled: Boolean(connection),
120
119
  });
121
- const warehouses = warehousesQuery.data?.ok && Array.isArray(warehousesQuery.data.warehouses)
122
- ? warehousesQuery.data.warehouses
123
- : [];
124
- const warehousesError = warehousesQuery.data && !warehousesQuery.data.ok ? warehousesQuery.data.error : null;
125
- // Auto-preselect het default-magazijn van Floriday wanneer de gebruiker
126
- // nog geen keuze heeft gemaakt.
120
+ const status = statusQuery.data;
127
121
  useEffect(() => {
128
- if (warehouseId)
129
- return;
130
- if (!warehouses.length)
131
- return;
132
- const def = warehouses.find((w) => w.isDefault) ?? warehouses[0];
133
- if (def)
134
- setWarehouseId(def.id);
135
- // eslint-disable-next-line react-hooks/exhaustive-deps
136
- }, [warehouses.length]);
122
+ setWarehouseId(status?.preferredWarehouseId ?? "");
123
+ }, [status?.preferredWarehouseId]);
137
124
  const saveMutation = useMutation({
138
- mutationFn: () => {
139
- const selected = warehouses.find((w) => w.id === warehouseId);
140
- return updateSettings({
141
- data: {
142
- environment: env,
143
- gln_code: gln,
144
- preferred_warehouse_id: warehouseId || null,
145
- preferred_warehouse_name: selected?.name ?? null,
146
- },
147
- });
148
- },
125
+ mutationFn: () => updateSettings({ data: { environment: env, preferred_warehouse_id: warehouseId } }),
149
126
  onSuccess: () => {
150
- toast.success("Publicatie-instellingen opgeslagen");
127
+ toast.success("Voorkeursmagazijn opgeslagen");
128
+ qc.invalidateQueries({ queryKey: ["floriday-own-config", env] });
151
129
  qc.invalidateQueries({ queryKey: ["floriday-connections"] });
152
130
  },
153
131
  onError: (e) => toast.error(e?.message ?? "Opslaan mislukt"),
154
132
  });
155
133
  if (!connection) {
156
- return (_jsx("p", { className: "text-xs text-muted-foreground", children: "Sla eerst je verbindingsgegevens op om publicatie-instellingen te beheren." }));
134
+ return (_jsx("p", { className: "text-xs text-muted-foreground", children: "Sla eerst je verbindingsgegevens op om publicatie-instellingen te zien." }));
135
+ }
136
+ if (statusQuery.isLoading) {
137
+ return _jsx("p", { className: "text-xs text-muted-foreground", children: "Gegevens uit Floriday laden\u2026" });
138
+ }
139
+ if (statusQuery.error || !status) {
140
+ return (_jsxs("p", { className: "text-[11px] text-destructive", children: ["Publicatie-instellingen niet beschikbaar: ", String(statusQuery.error?.message ?? "onbekende fout")] }));
157
141
  }
158
- const glnError = gln.trim() ? validateGln(gln) : null;
159
- return (_jsxs("div", { className: "rounded-lg border border-border/60 bg-card p-4 space-y-4", children: [_jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: `${env}-gln`, className: "text-xs", children: "GLN-code organisatie" }), _jsx(Input, { id: `${env}-gln`, value: gln, onChange: (e) => setGln(e.target.value.replace(/\s+/g, "")), placeholder: "Bijv. 8712345000005", inputMode: "numeric", maxLength: 13, autoComplete: "off", "aria-invalid": Boolean(glnError) }), glnError ? (_jsx("p", { className: "text-[11px] text-red-600", children: glnError })) : (_jsx("p", { className: "text-[11px] text-muted-foreground", children: "De Global Location Number van je organisatie in Floriday (13 cijfers)." }))] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: `${env}-warehouse`, className: "text-xs", children: "Voorkeursmagazijn" }), _jsxs(Select, { value: warehouseId || undefined, onValueChange: setWarehouseId, children: [_jsx(SelectTrigger, { id: `${env}-warehouse`, children: _jsx(SelectValue, { placeholder: warehousesQuery.isLoading
160
- ? "Magazijnen laden…"
161
- : warehouses.length === 0
162
- ? "Geen magazijnen beschikbaar"
163
- : "Kies een magazijn", children: (() => {
164
- const selected = warehouses.find((w) => w.id === warehouseId);
165
- if (!selected)
166
- return null;
167
- return (_jsxs("span", { className: "flex items-baseline gap-2 truncate", children: [_jsx("span", { className: "truncate", children: selected.name }), selected.gln && (_jsx("span", { className: "text-[11px] text-muted-foreground font-mono", children: selected.gln }))] }));
168
- })() }) }), _jsx(SelectContent, { children: warehouses.map((w) => (_jsx(SelectItem, { value: w.id, children: _jsxs("div", { className: "flex flex-col", children: [_jsx("span", { children: w.name }), w.gln && (_jsx("span", { className: "text-[11px] text-muted-foreground font-mono", children: w.gln }))] }) }, w.id))) })] }), _jsx("p", { className: "text-[11px] text-muted-foreground", children: "Alleen magazijnen die in Floriday aan je organisatie gekoppeld zijn." }), warehousesError && (_jsxs("p", { className: "text-[11px] text-red-600", children: ["Magazijnen niet beschikbaar: ", warehousesError] }))] }), _jsx("div", { children: _jsx(Button, { size: "sm", onClick: () => saveMutation.mutate(), disabled: saveMutation.isPending ||
169
- Boolean(glnError) ||
170
- (!gln.trim() && !warehouseId), children: saveMutation.isPending ? "Opslaan…" : "Instellingen opslaan" }) })] }));
142
+ const gln = status.gln;
143
+ const wh = status.warehouse;
144
+ const own = status.ownWarehouses;
145
+ const showChoice = own.length > 1 || wh?.kind === "missing" || wh?.kind === "choice_needed";
146
+ const dirty = Boolean(warehouseId) && warehouseId !== (status.preferredWarehouseId ?? "");
147
+ const current = own.find((w) => w.id === status.preferredWarehouseId);
148
+ return (_jsxs("div", { className: "rounded-lg border border-border/60 bg-card p-4 space-y-4", children: [_jsxs("div", { className: "space-y-1", children: [_jsx(Label, { className: "text-xs", children: "GLN-code organisatie" }), _jsx("p", { className: "font-mono text-sm", children: status.storedGln ?? "—" }), _jsx("p", { className: "text-[11px] text-muted-foreground", children: "Automatisch uit Floriday." }), gln?.kind === "mismatch" && (_jsxs("p", { className: "text-[11px] text-destructive", children: ["GLN in Floriday (", gln.fromFloriday, ") wijkt af van de opgeslagen GLN (", gln.stored, "); waarschijnlijk is er met een ander account gekoppeld. De opgeslagen waarde is niet overschreven."] })), gln?.kind === "unavailable" && (_jsx("p", { className: "text-[11px] text-muted-foreground", children: "GLN niet beschikbaar in Floriday." })), gln?.kind === "invalid" && (_jsxs("p", { className: "text-[11px] text-destructive", children: ["De GLN in Floriday (", gln.fromFloriday, ") is ongeldig en is niet opgeslagen: ", gln.error] }))] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { htmlFor: `${env}-warehouse`, className: "text-xs", children: "Voorkeursmagazijn" }), wh?.kind === "none" ? (_jsx("p", { className: "text-[11px] text-destructive", children: "Er zijn geen eigen magazijnen in Floriday voor deze koppeling." })) : !showChoice ? (_jsxs("p", { className: "text-sm", children: [current?.name ?? status.preferredWarehouseName ?? "—", current?.gln && (_jsx("span", { className: "ml-2 text-[11px] text-muted-foreground font-mono", children: current.gln }))] })) : (_jsxs(Select, { value: warehouseId || undefined, onValueChange: setWarehouseId, children: [_jsx(SelectTrigger, { id: `${env}-warehouse`, children: _jsx(SelectValue, { placeholder: "Kies een magazijn" }) }), _jsx(SelectContent, { children: own.map((w) => (_jsx(SelectItem, { value: w.id, children: _jsxs("div", { className: "flex flex-col", children: [_jsxs("span", { children: [w.name, w.isDefault ? " (standaard in Floriday)" : ""] }), w.gln && (_jsx("span", { className: "text-[11px] text-muted-foreground font-mono", children: w.gln }))] }) }, w.id))) })] })), wh?.kind === "fill" && wh.reason === "single" && (_jsx("p", { className: "text-[11px] text-muted-foreground", children: "Automatisch: het enige eigen magazijn." })), wh?.kind === "fill" && wh.reason === "default" && (_jsx("p", { className: "text-[11px] text-muted-foreground", children: "Automatisch: standaardmagazijn in Floriday." })), wh?.kind === "choice_needed" && (_jsx("p", { className: "text-[11px] text-destructive", children: "Keuze nodig: er zijn meerdere eigen magazijnen." })), wh?.kind === "missing" && (_jsx("p", { className: "text-[11px] text-destructive", children: "Gekozen magazijn niet meer beschikbaar in Floriday, kies opnieuw." }))] }), showChoice && dirty && (_jsx("div", { children: _jsx(Button, { size: "sm", onClick: () => saveMutation.mutate(), disabled: saveMutation.isPending, children: saveMutation.isPending ? "Opslaan…" : "Instellingen opslaan" }) }))] }));
171
149
  }
172
150
  function formatRelative(iso) {
173
151
  if (!iso)
package/dist-lib/index.js CHANGED
@@ -27,7 +27,7 @@ export const floridayAuthenticatieModule = {
27
27
  },
28
28
  {
29
29
  label: "Logboek",
30
- href: "/floriday-logboek",
30
+ href: "/floriday-connection/logboek",
31
31
  icon: ScrollText,
32
32
  },
33
33
  ],