@flowselections/floriday-klanten-module 1.0.64 → 1.0.67
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.
- package/dist-lib/components/klanten/CarrierAdminCard.d.ts +3 -0
- package/dist-lib/components/klanten/CarrierAdminCard.d.ts.map +1 -0
- package/dist-lib/components/klanten/CarrierAdminCard.js +23 -0
- package/dist-lib/components/klanten/CarrierPicker.d.ts +221 -0
- package/dist-lib/components/klanten/CarrierPicker.d.ts.map +1 -0
- package/dist-lib/components/klanten/CarrierPicker.js +74 -0
- package/dist-lib/components/klanten/CustomerCarrierCard.d.ts +5 -0
- package/dist-lib/components/klanten/CustomerCarrierCard.d.ts.map +1 -0
- package/dist-lib/components/klanten/CustomerCarrierCard.js +36 -0
- package/dist-lib/components/klanten/DeliveryLocationsTab.d.ts.map +1 -1
- package/dist-lib/components/klanten/DeliveryLocationsTab.js +38 -45
- package/dist-lib/components/klanten/KlantDetail.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantDetail.js +2 -1
- package/dist-lib/components/klanten/KlantFormulier.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantFormulier.js +8 -12
- package/dist-lib/components/klanten/KlantenOverzicht.d.ts.map +1 -1
- package/dist-lib/components/klanten/KlantenOverzicht.js +7 -3
- package/dist-lib/integrations/supabase/types.d.ts +1357 -28
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/carrier-choice.d.ts +60 -0
- package/dist-lib/lib/carrier-choice.d.ts.map +1 -0
- package/dist-lib/lib/carrier-choice.js +68 -0
- package/dist-lib/lib/carriers.functions.d.ts +82 -0
- package/dist-lib/lib/carriers.functions.d.ts.map +1 -0
- package/dist-lib/lib/carriers.functions.js +180 -0
- package/dist-lib/lib/countries.d.ts +2 -0
- package/dist-lib/lib/countries.d.ts.map +1 -1
- package/dist-lib/lib/countries.js +2 -0
- package/dist-lib/lib/customer-schemas.d.ts +108 -2
- package/dist-lib/lib/customer-schemas.d.ts.map +1 -1
- package/dist-lib/lib/customer-schemas.js +15 -1
- package/dist-lib/lib/customers.functions.d.ts +4 -1
- package/dist-lib/lib/customers.functions.d.ts.map +1 -1
- package/dist-lib/lib/customers.functions.js +7 -0
- package/dist-lib/lib/delivery-locations.functions.d.ts +2 -2
- package/dist-lib/lib/delivery-locations.functions.d.ts.map +1 -1
- package/dist-lib/lib/delivery-locations.functions.js +31 -38
- package/dist-lib/lib/price-groups-local.functions.d.ts.map +1 -1
- package/dist-lib/lib/price-groups-local.functions.js +4 -1
- package/dist-lib/lib/twinfield-adopt.functions.d.ts +2 -1
- package/dist-lib/lib/twinfield-adopt.functions.d.ts.map +1 -1
- package/dist-lib/lib/twinfield-adopt.functions.js +2 -2
- package/dist-lib/lib/twinfield-customer-defaults.server.js +2 -2
- package/package.json +11 -3
- package/schema/klanten.sql +514 -48
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CarrierAdminCard.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/CarrierAdminCard.tsx"],"names":[],"mappings":"AAQA,mHAAmH;AACnH,wBAAgB,gBAAgB,uCAI/B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { useServerFn } from "@tanstack/react-start";
|
|
5
|
+
import { useCustomerDefaults } from "./useCustomerDefaults.js";
|
|
6
|
+
import { previewCountryFixes, reviewAutoCarrierLocations } from "../../lib/carriers.functions.js";
|
|
7
|
+
import { ENGINE_MISSING_TEXT, proposalText } from "../../lib/carrier-choice.js";
|
|
8
|
+
import { friendlyError } from "../../lib/errors.js";
|
|
9
|
+
/** Alleen voor beheerders, alleen lezen: landen en automatisch opgeslagen vervoerders. Wijzigen pas na akkoord. */
|
|
10
|
+
export function CarrierAdminCard() {
|
|
11
|
+
const { isAdmin } = useCustomerDefaults();
|
|
12
|
+
if (isAdmin !== true)
|
|
13
|
+
return null;
|
|
14
|
+
return _jsx(Inner, {});
|
|
15
|
+
}
|
|
16
|
+
function Inner() {
|
|
17
|
+
const [open, setOpen] = useState(false);
|
|
18
|
+
const countryFn = useServerFn(previewCountryFixes);
|
|
19
|
+
const reviewFn = useServerFn(reviewAutoCarrierLocations);
|
|
20
|
+
const countries = useQuery({ queryKey: ["admin-country-fixes"], queryFn: () => countryFn(), enabled: open });
|
|
21
|
+
const review = useQuery({ queryKey: ["admin-auto-carriers"], queryFn: () => reviewFn(), enabled: open });
|
|
22
|
+
return (_jsxs("div", { className: "text-xs text-muted-foreground", children: [_jsx("button", { type: "button", className: "underline", onClick: () => setOpen((v) => !v), children: "Details voor beheer: vervoerders en landen" }), open && (_jsxs("div", { className: "mt-2 space-y-3 rounded border p-3", children: [_jsx("p", { children: "Alleen een overzicht. Er wordt niets aangepast." }), _jsxs("div", { children: [_jsx("div", { className: "font-medium text-foreground", children: "Afleverlocaties met een land dat geen landcode is" }), countries.isLoading && _jsx("p", { children: "Ophalen\u2026" }), countries.error && _jsx("p", { className: "text-destructive", children: friendlyError(countries.error) }), countries.data && countries.data.rows.length === 0 && _jsx("p", { children: "Geen." }), countries.data?.rows.map((r) => (_jsxs("div", { children: [r.name ?? "Afleverlocatie", " (", r.id, "): \"", r.huidig, "\" \u2192 ", r.voorstel ?? "onbekend, niet omzetten"] }, r.id)))] }), _jsxs("div", { children: [_jsx("div", { className: "font-medium text-foreground", children: "Klanten met een land dat geen landcode is" }), countries.data && countries.data.customerRows.length === 0 && _jsx("p", { children: "Geen." }), countries.data?.customerRows.map((r) => (_jsxs("div", { children: [r.name ?? "Klant", " (", r.id, ") \u2013 ", r.veld, ": \"", r.huidig, "\" \u2192 ", r.voorstel ?? "onbekend, niet omzetten"] }, `${r.id}-${r.veld}`)))] }), _jsxs("div", { children: [_jsx("div", { className: "font-medium text-foreground", children: "Locaties met een opgeslagen vervoerder op \"Automatisch\"" }), review.isLoading && _jsx("p", { children: "Ophalen\u2026" }), review.error && _jsx("p", { className: "text-destructive", children: friendlyError(review.error) }), review.data && review.data.rows.length === 0 && _jsx("p", { children: "Geen." }), review.data?.rows.map((r) => (_jsxs("div", { children: [r.name ?? "Afleverlocatie", " (", r.id, "): nu ", r.huidig ?? "—", " \u00B7 voorstel", " ", r.voorstel?.status === "ok" ? proposalText(r.voorstel.proposal) : ENGINE_MISSING_TEXT] }, r.id)))] })] }))] }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { type LocationCarrierChoice, type ProposalResult } from "../../lib/carrier-choice.js";
|
|
2
|
+
export declare function useCarrierOptions(): {
|
|
3
|
+
ordered: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
4
|
+
data: {
|
|
5
|
+
carriers: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
6
|
+
usage: Record<string, number>;
|
|
7
|
+
};
|
|
8
|
+
error: Error;
|
|
9
|
+
isError: true;
|
|
10
|
+
isPending: false;
|
|
11
|
+
isLoading: false;
|
|
12
|
+
isLoadingError: false;
|
|
13
|
+
isRefetchError: true;
|
|
14
|
+
isSuccess: false;
|
|
15
|
+
isPlaceholderData: false;
|
|
16
|
+
status: "error";
|
|
17
|
+
dataUpdatedAt: number;
|
|
18
|
+
errorUpdatedAt: number;
|
|
19
|
+
failureCount: number;
|
|
20
|
+
failureReason: Error | null;
|
|
21
|
+
errorUpdateCount: number;
|
|
22
|
+
isFetched: boolean;
|
|
23
|
+
isFetchedAfterMount: boolean;
|
|
24
|
+
isFetching: boolean;
|
|
25
|
+
isInitialLoading: boolean;
|
|
26
|
+
isPaused: boolean;
|
|
27
|
+
isRefetching: boolean;
|
|
28
|
+
isStale: boolean;
|
|
29
|
+
isEnabled: boolean;
|
|
30
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
31
|
+
carriers: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
32
|
+
usage: Record<string, number>;
|
|
33
|
+
}, Error>>;
|
|
34
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
35
|
+
} | {
|
|
36
|
+
ordered: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
37
|
+
data: {
|
|
38
|
+
carriers: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
39
|
+
usage: Record<string, number>;
|
|
40
|
+
};
|
|
41
|
+
error: null;
|
|
42
|
+
isError: false;
|
|
43
|
+
isPending: false;
|
|
44
|
+
isLoading: false;
|
|
45
|
+
isLoadingError: false;
|
|
46
|
+
isRefetchError: false;
|
|
47
|
+
isSuccess: true;
|
|
48
|
+
isPlaceholderData: false;
|
|
49
|
+
status: "success";
|
|
50
|
+
dataUpdatedAt: number;
|
|
51
|
+
errorUpdatedAt: number;
|
|
52
|
+
failureCount: number;
|
|
53
|
+
failureReason: Error | null;
|
|
54
|
+
errorUpdateCount: number;
|
|
55
|
+
isFetched: boolean;
|
|
56
|
+
isFetchedAfterMount: boolean;
|
|
57
|
+
isFetching: boolean;
|
|
58
|
+
isInitialLoading: boolean;
|
|
59
|
+
isPaused: boolean;
|
|
60
|
+
isRefetching: boolean;
|
|
61
|
+
isStale: boolean;
|
|
62
|
+
isEnabled: boolean;
|
|
63
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
64
|
+
carriers: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
65
|
+
usage: Record<string, number>;
|
|
66
|
+
}, Error>>;
|
|
67
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
68
|
+
} | {
|
|
69
|
+
ordered: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
70
|
+
data: undefined;
|
|
71
|
+
error: Error;
|
|
72
|
+
isError: true;
|
|
73
|
+
isPending: false;
|
|
74
|
+
isLoading: false;
|
|
75
|
+
isLoadingError: true;
|
|
76
|
+
isRefetchError: false;
|
|
77
|
+
isSuccess: false;
|
|
78
|
+
isPlaceholderData: false;
|
|
79
|
+
status: "error";
|
|
80
|
+
dataUpdatedAt: number;
|
|
81
|
+
errorUpdatedAt: number;
|
|
82
|
+
failureCount: number;
|
|
83
|
+
failureReason: Error | null;
|
|
84
|
+
errorUpdateCount: number;
|
|
85
|
+
isFetched: boolean;
|
|
86
|
+
isFetchedAfterMount: boolean;
|
|
87
|
+
isFetching: boolean;
|
|
88
|
+
isInitialLoading: boolean;
|
|
89
|
+
isPaused: boolean;
|
|
90
|
+
isRefetching: boolean;
|
|
91
|
+
isStale: boolean;
|
|
92
|
+
isEnabled: boolean;
|
|
93
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
94
|
+
carriers: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
95
|
+
usage: Record<string, number>;
|
|
96
|
+
}, Error>>;
|
|
97
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
98
|
+
} | {
|
|
99
|
+
ordered: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
100
|
+
data: undefined;
|
|
101
|
+
error: null;
|
|
102
|
+
isError: false;
|
|
103
|
+
isPending: true;
|
|
104
|
+
isLoading: true;
|
|
105
|
+
isLoadingError: false;
|
|
106
|
+
isRefetchError: false;
|
|
107
|
+
isSuccess: false;
|
|
108
|
+
isPlaceholderData: false;
|
|
109
|
+
status: "pending";
|
|
110
|
+
dataUpdatedAt: number;
|
|
111
|
+
errorUpdatedAt: number;
|
|
112
|
+
failureCount: number;
|
|
113
|
+
failureReason: Error | null;
|
|
114
|
+
errorUpdateCount: number;
|
|
115
|
+
isFetched: boolean;
|
|
116
|
+
isFetchedAfterMount: boolean;
|
|
117
|
+
isFetching: boolean;
|
|
118
|
+
isInitialLoading: boolean;
|
|
119
|
+
isPaused: boolean;
|
|
120
|
+
isRefetching: boolean;
|
|
121
|
+
isStale: boolean;
|
|
122
|
+
isEnabled: boolean;
|
|
123
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
124
|
+
carriers: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
125
|
+
usage: Record<string, number>;
|
|
126
|
+
}, Error>>;
|
|
127
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
128
|
+
} | {
|
|
129
|
+
ordered: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
130
|
+
data: undefined;
|
|
131
|
+
error: null;
|
|
132
|
+
isError: false;
|
|
133
|
+
isPending: true;
|
|
134
|
+
isLoadingError: false;
|
|
135
|
+
isRefetchError: false;
|
|
136
|
+
isSuccess: false;
|
|
137
|
+
isPlaceholderData: false;
|
|
138
|
+
status: "pending";
|
|
139
|
+
dataUpdatedAt: number;
|
|
140
|
+
errorUpdatedAt: number;
|
|
141
|
+
failureCount: number;
|
|
142
|
+
failureReason: Error | null;
|
|
143
|
+
errorUpdateCount: number;
|
|
144
|
+
isFetched: boolean;
|
|
145
|
+
isFetchedAfterMount: boolean;
|
|
146
|
+
isFetching: boolean;
|
|
147
|
+
isLoading: boolean;
|
|
148
|
+
isInitialLoading: boolean;
|
|
149
|
+
isPaused: boolean;
|
|
150
|
+
isRefetching: boolean;
|
|
151
|
+
isStale: boolean;
|
|
152
|
+
isEnabled: boolean;
|
|
153
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
154
|
+
carriers: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
155
|
+
usage: Record<string, number>;
|
|
156
|
+
}, Error>>;
|
|
157
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
158
|
+
} | {
|
|
159
|
+
ordered: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
160
|
+
data: {
|
|
161
|
+
carriers: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
162
|
+
usage: Record<string, number>;
|
|
163
|
+
};
|
|
164
|
+
isError: false;
|
|
165
|
+
error: null;
|
|
166
|
+
isPending: false;
|
|
167
|
+
isLoading: false;
|
|
168
|
+
isLoadingError: false;
|
|
169
|
+
isRefetchError: false;
|
|
170
|
+
isSuccess: true;
|
|
171
|
+
isPlaceholderData: true;
|
|
172
|
+
status: "success";
|
|
173
|
+
dataUpdatedAt: number;
|
|
174
|
+
errorUpdatedAt: number;
|
|
175
|
+
failureCount: number;
|
|
176
|
+
failureReason: Error | null;
|
|
177
|
+
errorUpdateCount: number;
|
|
178
|
+
isFetched: boolean;
|
|
179
|
+
isFetchedAfterMount: boolean;
|
|
180
|
+
isFetching: boolean;
|
|
181
|
+
isInitialLoading: boolean;
|
|
182
|
+
isPaused: boolean;
|
|
183
|
+
isRefetching: boolean;
|
|
184
|
+
isStale: boolean;
|
|
185
|
+
isEnabled: boolean;
|
|
186
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<{
|
|
187
|
+
carriers: import("../../lib/carrier-choice.js").CarrierOption[];
|
|
188
|
+
usage: Record<string, number>;
|
|
189
|
+
}, Error>>;
|
|
190
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
191
|
+
};
|
|
192
|
+
export type ProposalItem = {
|
|
193
|
+
key: string;
|
|
194
|
+
location_id: string | null;
|
|
195
|
+
customer_id: string | null;
|
|
196
|
+
};
|
|
197
|
+
/** Live voorstel van de Logistieke Engine; wordt nooit opgeslagen. */
|
|
198
|
+
export declare function useCarrierProposals(items: ProposalItem[], enabled?: boolean): import("@tanstack/react-query").UseQueryResult<Record<string, ProposalResult>, Error>;
|
|
199
|
+
/** Eén regel: welke vervoerder het wordt en waarom, plus de waarschuwing van de Engine. */
|
|
200
|
+
export declare function ProposalLine({ result, loading, error, onRetry, compact, }: {
|
|
201
|
+
result: ProposalResult | undefined;
|
|
202
|
+
loading?: boolean;
|
|
203
|
+
error?: unknown;
|
|
204
|
+
onRetry?: () => void;
|
|
205
|
+
compact?: boolean;
|
|
206
|
+
}): import("react").JSX.Element;
|
|
207
|
+
/**
|
|
208
|
+
* Zoekbare keuzelijst. Variant "location": Automatisch / vervoerders / Klant haalt zelf op.
|
|
209
|
+
* Variant "customer": Geen standaardvervoerder / vervoerders.
|
|
210
|
+
*/
|
|
211
|
+
export declare function CarrierPicker(props: {
|
|
212
|
+
variant: "location";
|
|
213
|
+
value: LocationCarrierChoice;
|
|
214
|
+
onChange: (v: LocationCarrierChoice) => void;
|
|
215
|
+
autoLabel: string;
|
|
216
|
+
} | {
|
|
217
|
+
variant: "customer";
|
|
218
|
+
value: string | null;
|
|
219
|
+
onChange: (v: string | null) => void;
|
|
220
|
+
}): import("react").JSX.Element;
|
|
221
|
+
//# sourceMappingURL=CarrierPicker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CarrierPicker.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/CarrierPicker.tsx"],"names":[],"mappings":"AAOA,OAAO,EAIL,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAGlC,wBAAgB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQhC;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEnG,sEAAsE;AACtE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,OAAO,UAAO,yFAQxE;AAED,2FAA2F;AAC3F,wBAAgB,YAAY,CAAC,EAC3B,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,GACR,EAAE;IACD,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,+BAmCA;AAMD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EACD;IACE,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,qBAAqB,CAAC;IAC7B,QAAQ,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACtC,+BA+CN"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { useServerFn } from "@tanstack/react-start";
|
|
5
|
+
import { Button } from "@flowselections/core";
|
|
6
|
+
import { AlertTriangle, PackageCheck, Truck } from "lucide-react";
|
|
7
|
+
import { SearchableSelect } from "./SearchableSelect.js";
|
|
8
|
+
import { listCarrierOptions, resolveCarrierProposals } from "../../lib/carriers.functions.js";
|
|
9
|
+
import { ENGINE_MISSING_TEXT, orderCarrierOptions, proposalText, } from "../../lib/carrier-choice.js";
|
|
10
|
+
import { friendlyError } from "../../lib/errors.js";
|
|
11
|
+
export function useCarrierOptions() {
|
|
12
|
+
const fn = useServerFn(listCarrierOptions);
|
|
13
|
+
const q = useQuery({ queryKey: ["carrier-options"], queryFn: () => fn() });
|
|
14
|
+
const ordered = useMemo(() => orderCarrierOptions(q.data?.carriers ?? [], q.data?.usage ?? {}), [q.data]);
|
|
15
|
+
return { ...q, ordered };
|
|
16
|
+
}
|
|
17
|
+
/** Live voorstel van de Logistieke Engine; wordt nooit opgeslagen. */
|
|
18
|
+
export function useCarrierProposals(items, enabled = true) {
|
|
19
|
+
const fn = useServerFn(resolveCarrierProposals);
|
|
20
|
+
const key = items.map((i) => i.key).join(",");
|
|
21
|
+
return useQuery({
|
|
22
|
+
queryKey: ["carrier-proposals", key],
|
|
23
|
+
queryFn: () => fn({ data: { items } }).then((r) => r.proposals),
|
|
24
|
+
enabled: enabled && items.length > 0,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** Eén regel: welke vervoerder het wordt en waarom, plus de waarschuwing van de Engine. */
|
|
28
|
+
export function ProposalLine({ result, loading, error, onRetry, compact, }) {
|
|
29
|
+
if (error) {
|
|
30
|
+
return (_jsxs("span", { className: "inline-flex items-center gap-2 text-xs text-destructive", children: ["Voorstel ophalen mislukt: ", friendlyError(error), onRetry && (_jsx(Button, { variant: "link", size: "sm", className: "h-auto p-0", onClick: (e) => { e.stopPropagation(); onRetry(); }, children: "Opnieuw proberen" }))] }));
|
|
31
|
+
}
|
|
32
|
+
if (loading || !result)
|
|
33
|
+
return _jsx("span", { className: "text-xs text-muted-foreground", children: "Voorstel ophalen\u2026" });
|
|
34
|
+
if (result.status === "engine_missing") {
|
|
35
|
+
return _jsx("span", { className: "text-xs text-muted-foreground", children: ENGINE_MISSING_TEXT });
|
|
36
|
+
}
|
|
37
|
+
const p = result.proposal;
|
|
38
|
+
return (_jsxs("span", { className: compact ? "text-xs" : "text-sm", children: [_jsxs("span", { className: "inline-flex items-center gap-1", children: [p.carrier_kind === "self_pickup" ? (_jsx(PackageCheck, { className: "h-3.5 w-3.5 text-muted-foreground" })) : (_jsx(Truck, { className: "h-3.5 w-3.5 text-muted-foreground" })), proposalText(p)] }), p.waarschuwing && (_jsxs("span", { className: "ml-2 inline-flex items-center gap-1 text-warning-soft-foreground", children: [_jsx(AlertTriangle, { className: "h-3.5 w-3.5" }), " ", p.waarschuwing] }))] }));
|
|
39
|
+
}
|
|
40
|
+
const AUTO = "__auto__";
|
|
41
|
+
const SELF = "__self__";
|
|
42
|
+
const NONE = "__none__";
|
|
43
|
+
/**
|
|
44
|
+
* Zoekbare keuzelijst. Variant "location": Automatisch / vervoerders / Klant haalt zelf op.
|
|
45
|
+
* Variant "customer": Geen standaardvervoerder / vervoerders.
|
|
46
|
+
*/
|
|
47
|
+
export function CarrierPicker(props) {
|
|
48
|
+
const opts = useCarrierOptions();
|
|
49
|
+
if (opts.error) {
|
|
50
|
+
return (_jsxs("div", { className: "text-sm text-destructive flex items-center gap-2", children: ["Vervoerders ophalen mislukt: ", friendlyError(opts.error), _jsx(Button, { variant: "link", size: "sm", className: "h-auto p-0", onClick: () => opts.refetch(), children: "Opnieuw proberen" })] }));
|
|
51
|
+
}
|
|
52
|
+
const carrierOpts = opts.ordered.map((c) => ({
|
|
53
|
+
value: c.id,
|
|
54
|
+
label: c.is_default ? `${c.name} (favoriet)` : c.name,
|
|
55
|
+
search: c.name,
|
|
56
|
+
}));
|
|
57
|
+
if (props.variant === "customer") {
|
|
58
|
+
return (_jsx(SearchableSelect, { value: props.value ?? NONE, onValueChange: (v) => props.onChange(!v || v === NONE ? null : v), options: [{ value: NONE, label: "Geen standaardvervoerder" }, ...carrierOpts], placeholder: opts.isLoading ? "Vervoerders laden…" : "Kies een vervoerder" }));
|
|
59
|
+
}
|
|
60
|
+
const v = props.value;
|
|
61
|
+
const current = v.kind === "auto" ? AUTO : v.kind === "self_pickup" ? SELF : v.carrier_id;
|
|
62
|
+
return (_jsx(SearchableSelect, { value: current, onValueChange: (next) => {
|
|
63
|
+
if (!next || next === AUTO)
|
|
64
|
+
props.onChange({ kind: "auto" });
|
|
65
|
+
else if (next === SELF)
|
|
66
|
+
props.onChange({ kind: "self_pickup" });
|
|
67
|
+
else
|
|
68
|
+
props.onChange({ kind: "carrier", carrier_id: next });
|
|
69
|
+
}, options: [
|
|
70
|
+
{ value: AUTO, label: props.autoLabel, search: "automatisch" },
|
|
71
|
+
...carrierOpts,
|
|
72
|
+
{ value: SELF, label: "Klant haalt zelf op", search: "zelf ophalen eigen vervoer" },
|
|
73
|
+
], placeholder: opts.isLoading ? "Vervoerders laden…" : "Kies een vervoerder" }));
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomerCarrierCard.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/CustomerCarrierCard.tsx"],"names":[],"mappings":"AAQA,+FAA+F;AAC/F,wBAAgB,mBAAmB,CAAC,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,+BAqEzE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { useServerFn } from "@tanstack/react-start";
|
|
5
|
+
import { Button, Card, CardContent, Label, toast } from "@flowselections/core";
|
|
6
|
+
import { CarrierPicker, ProposalLine, useCarrierProposals } from "./CarrierPicker.js";
|
|
7
|
+
import { getCustomerDefaultCarrier, setCustomerDefaultCarrier } from "../../lib/carriers.functions.js";
|
|
8
|
+
import { friendlyError } from "../../lib/errors.js";
|
|
9
|
+
/** Welke vervoerder het wordt en waarom (Engine), plus de standaardvervoerder van de klant. */
|
|
10
|
+
export function CustomerCarrierCard({ customerId }) {
|
|
11
|
+
const qc = useQueryClient();
|
|
12
|
+
const getFn = useServerFn(getCustomerDefaultCarrier);
|
|
13
|
+
const setFn = useServerFn(setCustomerDefaultCarrier);
|
|
14
|
+
const cur = useQuery({
|
|
15
|
+
queryKey: ["customer-default-carrier", customerId],
|
|
16
|
+
queryFn: () => getFn({ data: { customer_id: customerId } }),
|
|
17
|
+
});
|
|
18
|
+
const proposal = useCarrierProposals([{ key: `klant:${customerId}`, location_id: null, customer_id: customerId }]);
|
|
19
|
+
const [value, setValue] = useState(null);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (cur.data)
|
|
22
|
+
setValue(cur.data.default_carrier_id);
|
|
23
|
+
}, [cur.data]);
|
|
24
|
+
const save = useMutation({
|
|
25
|
+
mutationFn: () => setFn({ data: { customer_id: customerId, carrier_id: value } }),
|
|
26
|
+
onSuccess: () => {
|
|
27
|
+
toast.success("Standaardvervoerder opgeslagen");
|
|
28
|
+
qc.invalidateQueries({ queryKey: ["customer-default-carrier", customerId] });
|
|
29
|
+
qc.invalidateQueries({ queryKey: ["carrier-proposals"] });
|
|
30
|
+
qc.invalidateQueries({ queryKey: ["carrier-options"] });
|
|
31
|
+
},
|
|
32
|
+
onError: (e) => toast.error(friendlyError(e, "Opslaan mislukt")),
|
|
33
|
+
});
|
|
34
|
+
const dirty = cur.data !== undefined && value !== cur.data.default_carrier_id;
|
|
35
|
+
return (_jsx(Card, { children: _jsxs(CardContent, { className: "pt-6 space-y-3", children: [_jsx("div", { className: "font-semibold", children: "Vervoerder" }), _jsxs("div", { children: [_jsx("div", { className: "text-xs text-muted-foreground mb-1", children: "Wordt nu" }), _jsx(ProposalLine, { result: proposal.data?.[`klant:${customerId}`], loading: proposal.isLoading, error: proposal.error, onRetry: () => proposal.refetch() })] }), _jsxs("div", { className: "space-y-1", children: [_jsx(Label, { children: "Standaardvervoerder van deze klant" }), cur.error ? (_jsxs("div", { className: "text-sm text-destructive flex items-center gap-2", children: [friendlyError(cur.error), _jsx(Button, { variant: "link", size: "sm", className: "h-auto p-0", onClick: () => cur.refetch(), children: "Opnieuw proberen" })] })) : (_jsx(CarrierPicker, { variant: "customer", value: value, onChange: setValue })), _jsx("p", { className: "text-xs text-muted-foreground", children: "Wordt gebruikt als bij de afleverlocatie niets is gekozen. Opslaan verstuurt geen mail." })] }), dirty && (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { variant: "outline", size: "sm", onClick: () => setValue(cur.data?.default_carrier_id ?? null), children: "Annuleren" }), _jsx(Button, { size: "sm", onClick: () => save.mutate(), disabled: save.isPending, children: save.isPending ? "Opslaan…" : "Opslaan" })] }))] }) }));
|
|
36
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeliveryLocationsTab.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/DeliveryLocationsTab.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DeliveryLocationsTab.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/DeliveryLocationsTab.tsx"],"names":[],"mappings":"AA6EA,wBAAgB,oBAAoB,CAAC,EACnC,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,WAAW,GACZ,EAAE;IACD,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,+BAkhBA"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { friendlyError } from "../../lib/errors.js";
|
|
3
3
|
import { useCustomerDefaults } from "./useCustomerDefaults.js";
|
|
4
|
-
import {
|
|
4
|
+
import { useMemo, useRef, useState } from "react";
|
|
5
5
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
6
6
|
import { useServerFn } from "@tanstack/react-start";
|
|
7
7
|
import { Button, Card, CardContent, Badge, toast, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@flowselections/core";
|
|
8
8
|
import { MapPin, Plus, Pencil, Trash2, Truck, Sparkles, PackageCheck, Download } from "lucide-react";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { listDeliveryLocations, upsertDeliveryLocation, deleteDeliveryLocation, importFloridayDeliveryLocations, setPrimaryDeliveryLocation, } from "../../lib/delivery-locations.functions.js";
|
|
10
|
+
import { CarrierPicker, ProposalLine, useCarrierOptions, useCarrierProposals } from "./CarrierPicker.js";
|
|
11
|
+
import { SearchableSelect } from "./SearchableSelect.js";
|
|
12
|
+
import { choiceFromLocation, locationCarrierFields, proposalText, ENGINE_MISSING_TEXT, } from "../../lib/carrier-choice.js";
|
|
13
|
+
import { findCountry } from "../../lib/eu-regions.js";
|
|
11
14
|
import { decodeDeep } from "../../lib/decode-html.js";
|
|
12
|
-
import { countryNameToFlag } from "../../lib/countries.js";
|
|
15
|
+
import { countryNameToFlag, COUNTRY_NAMES, countryNameFromIso, toIsoCountry } from "../../lib/countries.js";
|
|
13
16
|
const EMPTY = {
|
|
14
17
|
name: "", street: "", house_number: "", postal_code: "",
|
|
15
18
|
city: "", province: "", country: "",
|
|
@@ -34,7 +37,6 @@ export function DeliveryLocationsTab({ customerId, groupKey, externalProvider, e
|
|
|
34
37
|
};
|
|
35
38
|
const ownerKey = `${groupKey ?? ""}|${customerId ?? ""}|${externalProvider ?? ""}:${externalKey ?? ""}`;
|
|
36
39
|
const listFn = useServerFn(listDeliveryLocations);
|
|
37
|
-
const carriersFn = useServerFn(listCarriers);
|
|
38
40
|
const upsertFn = useServerFn(upsertDeliveryLocation);
|
|
39
41
|
const deleteFn = useServerFn(deleteDeliveryLocation);
|
|
40
42
|
const primaryFn = useServerFn(setPrimaryDeliveryLocation);
|
|
@@ -43,11 +45,8 @@ export function DeliveryLocationsTab({ customerId, groupKey, externalProvider, e
|
|
|
43
45
|
queryFn: () => listFn({ data: owner }).then(decodeDeep),
|
|
44
46
|
enabled: !!(customerId || groupKey || (externalProvider && externalKey)),
|
|
45
47
|
});
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
queryFn: () => carriersFn().then(decodeDeep),
|
|
49
|
-
});
|
|
50
|
-
const carriers = carriersResp?.carriers ?? [];
|
|
48
|
+
const carrierOpts = useCarrierOptions();
|
|
49
|
+
const carriers = carrierOpts.ordered;
|
|
51
50
|
const locations = (list?.locations ?? []).filter((loc) => loc.external_provider !== "floriday" || loc.raw?.isDeleted !== true);
|
|
52
51
|
const [open, setOpen] = useState(false);
|
|
53
52
|
const [form, setForm] = useState(EMPTY);
|
|
@@ -110,19 +109,25 @@ export function DeliveryLocationsTab({ customerId, groupKey, externalProvider, e
|
|
|
110
109
|
const showError = (field) => (submitted || touched[field]) && errors[field] ? errors[field] : undefined;
|
|
111
110
|
const markTouched = (field) => setTouched((t) => ({ ...t, [field]: true }));
|
|
112
111
|
const req = !form.self_pickup;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
112
|
+
// Live voorstel van de Logistieke Engine (nooit opgeslagen).
|
|
113
|
+
const proposals = useCarrierProposals(locations.map((l) => ({ key: l.id, location_id: l.id, customer_id: customerId ?? null })));
|
|
114
|
+
const formKey = form.id ?? `new:${customerId ?? ownerKey}`;
|
|
115
|
+
const formProposal = useCarrierProposals(open ? [{ key: formKey, location_id: form.id ?? null, customer_id: customerId ?? null }] : [], open);
|
|
116
|
+
const formProposalResult = formProposal.data ? formProposal.data[formKey] : undefined;
|
|
117
|
+
const autoLabel = formProposal.error
|
|
118
|
+
? "Automatisch (voorstel ophalen mislukt)"
|
|
119
|
+
: !formProposalResult
|
|
120
|
+
? "Automatisch (voorstel ophalen…)"
|
|
121
|
+
: formProposalResult.status === "engine_missing"
|
|
122
|
+
? `Automatisch (${ENGINE_MISSING_TEXT.toLowerCase()})`
|
|
123
|
+
: `Automatisch (voorstel: ${proposalText(formProposalResult.proposal)})`;
|
|
123
124
|
const carrierName = (id) => carriers.find((c) => c.id === id)?.name ?? "—";
|
|
124
125
|
const resetValidation = () => { setTouched({}); setSubmitted(false); };
|
|
125
|
-
const startNew = () => {
|
|
126
|
+
const startNew = () => {
|
|
127
|
+
setForm({ ...EMPTY, country: toIsoCountry(cd.defaults?.country ?? "") ?? "" });
|
|
128
|
+
resetValidation();
|
|
129
|
+
setOpen(true);
|
|
130
|
+
};
|
|
126
131
|
const startEdit = (loc) => {
|
|
127
132
|
resetValidation();
|
|
128
133
|
setForm({
|
|
@@ -133,7 +138,9 @@ export function DeliveryLocationsTab({ customerId, groupKey, externalProvider, e
|
|
|
133
138
|
postal_code: loc.postal_code ?? "",
|
|
134
139
|
city: loc.city ?? "",
|
|
135
140
|
province: loc.province ?? "",
|
|
136
|
-
|
|
141
|
+
// Oude namen ("Nederland") worden als ISO-code getoond; een onbekend land blijft staan,
|
|
142
|
+
// zodat opslaan het weigert in plaats van te raden.
|
|
143
|
+
country: toIsoCountry(loc.country) ?? (loc.country ?? ""),
|
|
137
144
|
carrier_id: loc.carrier_id,
|
|
138
145
|
carrier_assignment_source: (loc.carrier_assignment_source ?? "auto"),
|
|
139
146
|
is_primary: loc.is_primary,
|
|
@@ -180,36 +187,22 @@ export function DeliveryLocationsTab({ customerId, groupKey, externalProvider, e
|
|
|
180
187
|
}
|
|
181
188
|
saveMut.mutate();
|
|
182
189
|
};
|
|
183
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-sm text-muted-foreground", children: "Afleverlocaties staan volledig los van de boekhoudlocatie uit Twinfield en worden alleen gebruikt voor orderverwerking, planning, picking en levering. De vervoerder wordt
|
|
190
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("div", { className: "text-sm text-muted-foreground", children: "Afleverlocaties staan volledig los van de boekhoudlocatie uit Twinfield en worden alleen gebruikt voor orderverwerking, planning, picking en levering. De vervoerder wordt bepaald door de Logistieke Engine, tenzij je bij een locatie zelf een vervoerder kiest." }), _jsxs("div", { className: "flex gap-2", children: [_jsxs(Button, { size: "sm", variant: "outline", onClick: () => previewMut.mutate(), disabled: previewMut.isPending, children: [_jsx(Download, { className: "h-4 w-4 mr-2" }), previewMut.isPending ? "Laden…" : "Importeren uit Floriday"] }), _jsxs(Button, { size: "sm", onClick: startNew, children: [_jsx(Plus, { className: "h-4 w-4 mr-2" }), " Locatie toevoegen"] })] })] }), locations.length === 0 ? (_jsx(Card, { children: _jsx(CardContent, { className: "py-10 text-center text-sm text-muted-foreground", children: "Nog geen afleverlocaties." }) })) : (_jsx("div", { className: "grid gap-3 md:grid-cols-2", children: locations.map((loc) => {
|
|
184
191
|
const street = [loc.street, loc.house_number].filter(Boolean).join(" ") || loc.raw?.address?.addressLine || loc.address_line || "";
|
|
185
|
-
return (_jsx(Card, { children: _jsxs(CardContent, { className: "pt-5 space-y-3", children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "font-semibold flex items-center gap-2", children: [_jsx(MapPin, { className: "h-4 w-4 text-muted-foreground" }), loc.name || street || "Afleverlocatie"] }), _jsxs("div", { className: "text-sm text-muted-foreground mt-0.5", children: [loc.name ? street : "", loc.name && street && (loc.postal_code || loc.city) ? ", " : "", [loc.postal_code, loc.city].filter(Boolean).join(" "), loc.province ? ` · ${loc.province}` : "", loc.country ? (_jsxs("span", { className: "inline-flex items-center gap-1 ml-1", children: [_jsx("span", { className: "text-base", "aria-hidden": "true", children: countryNameToFlag(loc.country) ?? "🌐" }), _jsx("span", { children: loc.country })] })) : null] })] }), _jsxs("div", { className: "flex gap-1", children: [_jsx(Button, { variant: "ghost", size: "icon", onClick: () => startEdit(loc), children: _jsx(Pencil, { className: "h-4 w-4" }) }), _jsxs(AlertDialog, { children: [_jsx(AlertDialogTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "icon", children: _jsx(Trash2, { className: "h-4 w-4" }) }) }), _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: "Locatie verwijderen?" }), _jsx(AlertDialogDescription, { children: "Deze actie kan niet ongedaan worden gemaakt." })] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { children: "Annuleren" }), _jsx(AlertDialogAction, { onClick: () => delMut.mutate(loc.id), children: "Verwijderen" })] })] })] })] })] }), _jsxs("div", { className: "flex items-center gap-2 flex-wrap text-sm", children: [loc.self_pickup ? (_jsxs(_Fragment, { children: [_jsx(PackageCheck, { className: "h-4 w-4 text-muted-foreground" }), _jsx("span", { className: "font-medium", children: "
|
|
192
|
+
return (_jsx(Card, { children: _jsxs(CardContent, { className: "pt-5 space-y-3", children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "font-semibold flex items-center gap-2", children: [_jsx(MapPin, { className: "h-4 w-4 text-muted-foreground" }), loc.name || street || "Afleverlocatie"] }), _jsxs("div", { className: "text-sm text-muted-foreground mt-0.5", children: [loc.name ? street : "", loc.name && street && (loc.postal_code || loc.city) ? ", " : "", [loc.postal_code, loc.city].filter(Boolean).join(" "), loc.province ? ` · ${loc.province}` : "", loc.country ? (_jsxs("span", { className: "inline-flex items-center gap-1 ml-1", children: [_jsx("span", { className: "text-base", "aria-hidden": "true", children: countryNameToFlag(loc.country) ?? "🌐" }), _jsx("span", { children: toIsoCountry(loc.country) ? countryNameFromIso(toIsoCountry(loc.country)) : loc.country })] })) : null] })] }), _jsxs("div", { className: "flex gap-1", children: [_jsx(Button, { variant: "ghost", size: "icon", onClick: () => startEdit(loc), children: _jsx(Pencil, { className: "h-4 w-4" }) }), _jsxs(AlertDialog, { children: [_jsx(AlertDialogTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "icon", children: _jsx(Trash2, { className: "h-4 w-4" }) }) }), _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: "Locatie verwijderen?" }), _jsx(AlertDialogDescription, { children: "Deze actie kan niet ongedaan worden gemaakt." })] }), _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { children: "Annuleren" }), _jsx(AlertDialogAction, { onClick: () => delMut.mutate(loc.id), children: "Verwijderen" })] })] })] })] })] }), _jsxs("div", { className: "flex items-center gap-2 flex-wrap text-sm", children: [loc.self_pickup ? (_jsxs(_Fragment, { children: [_jsx(PackageCheck, { className: "h-4 w-4 text-muted-foreground" }), _jsx("span", { className: "font-medium", children: "Klant haalt zelf op" })] })) : loc.carrier_assignment_source === "manual" && loc.carrier_id ? (_jsxs(_Fragment, { children: [_jsx(Truck, { className: "h-4 w-4 text-muted-foreground" }), _jsx("span", { className: "font-medium", children: carrierName(loc.carrier_id) }), _jsx(Badge, { variant: "outline", children: "Gekozen bij deze locatie" })] })) : (_jsxs("span", { className: "inline-flex items-center gap-2 flex-wrap", children: [_jsxs(Badge, { variant: "secondary", className: "gap-1", children: [_jsx(Sparkles, { className: "h-3 w-3" }), "Automatisch"] }), _jsx(ProposalLine, { result: proposals.data?.[loc.id], loading: proposals.isLoading, error: proposals.error, onRetry: () => proposals.refetch() })] })), loc.external_provider === "floriday" && (_jsx(Badge, { variant: "outline", className: "text-success-soft-foreground border-success", children: "Floriday" })), loc.gln && _jsxs(Badge, { variant: "secondary", children: ["GLN ", loc.gln] }), loc.is_primary && _jsx(Badge, { children: "Vaste afleverlocatie" }), loc.external_provider === "floriday" && loc.raw?.isDefault === true && (_jsx(Badge, { variant: "outline", children: "Standaard in Floriday" })), !loc.is_primary && (_jsx(Button, { size: "sm", variant: "outline", className: "h-7", disabled: primaryMut.isPending, onClick: () => primaryMut.mutate(loc.id), title: loc.external_provider === "floriday"
|
|
186
193
|
? "Dit verandert niets in Floriday; de koper kiest daar zelf zijn standaard."
|
|
187
194
|
: undefined, children: "Maak vaste afleverlocatie" }))] })] }) }, loc.id));
|
|
188
|
-
}) })), _jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsxs(DialogContent, { className: "max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: form.id ? "Locatie bewerken" : "Nieuwe locatie" }), _jsx(DialogDescription, { children: "
|
|
195
|
+
}) })), _jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsxs(DialogContent, { className: "max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: form.id ? "Locatie bewerken" : "Nieuwe locatie" }), _jsx(DialogDescription, { children: "Kies \"Automatisch\" om de vervoerder steeds door de Logistieke Engine te laten bepalen." })] }), _jsxs("div", { className: "grid gap-4 md:grid-cols-2", children: [_jsxs("div", { className: "md:col-span-2", children: [_jsx(Label, { children: "Locatienaam (optioneel)" }), _jsx(Input, { value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) })] }), _jsxs("div", { className: "md:col-span-2 grid grid-cols-3 gap-3", children: [_jsxs("div", { className: "col-span-2", children: [_jsxs(Label, { children: ["Straat ", req && _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(Input, { ref: fieldRefs.street, value: form.street, onChange: (e) => setForm({ ...form, street: e.target.value }), onBlur: () => markTouched("street"), "aria-invalid": !!showError("street"), className: showError("street") ? "border-destructive" : undefined }), showError("street") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("street") })] }), _jsxs("div", { children: [_jsxs(Label, { children: ["Huisnummer ", req && _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(Input, { ref: fieldRefs.house_number, value: form.house_number, onChange: (e) => setForm({ ...form, house_number: e.target.value }), onBlur: () => markTouched("house_number"), "aria-invalid": !!showError("house_number"), className: showError("house_number") ? "border-destructive" : undefined }), showError("house_number") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("house_number") })] })] }), _jsxs("div", { children: [_jsxs(Label, { children: ["Postcode ", req && _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(Input, { ref: fieldRefs.postal_code, value: form.postal_code, onChange: (e) => setForm({ ...form, postal_code: e.target.value }), onBlur: () => {
|
|
189
196
|
markTouched("postal_code");
|
|
190
197
|
setForm((f) => ({ ...f, postal_code: normalizePostalCode(f.postal_code, f.country) }));
|
|
191
|
-
}, "aria-invalid": !!showError("postal_code"), className: showError("postal_code") ? "border-destructive" : undefined }), showError("postal_code") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("postal_code") })] }), _jsxs("div", { children: [_jsxs(Label, { children: ["Plaats ", req && _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(Input, { ref: fieldRefs.city, value: form.city, onChange: (e) => setForm({ ...form, city: e.target.value }), onBlur: () => markTouched("city"), "aria-invalid": !!showError("city"), className: showError("city") ? "border-destructive" : undefined }), showError("city") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("city") })] }), _jsxs("div", { ref: fieldRefs.country, tabIndex: -1, children: [_jsxs(Label, { children: ["Land ", req && _jsx("span", { className: "text-destructive", children: "*" })] }),
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const flag = countryNameToFlag(c.code);
|
|
197
|
-
return (_jsx(SelectItem, { value: c.name, children: _jsxs("span", { className: "inline-flex items-center gap-2", children: [flag ? _jsx("span", { className: "text-base", "aria-hidden": "true", children: flag }) : _jsx("span", { className: "w-4" }), _jsx("span", { children: c.name })] }) }, c.code));
|
|
198
|
-
}) })] }), showError("country") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("country") })] }), _jsxs("div", { ref: fieldRefs.province, tabIndex: -1, children: [_jsxs(Label, { children: ["Provincie ", req && _jsx("span", { className: "text-destructive", children: "*" })] }), (() => {
|
|
198
|
+
}, "aria-invalid": !!showError("postal_code"), className: showError("postal_code") ? "border-destructive" : undefined }), showError("postal_code") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("postal_code") })] }), _jsxs("div", { children: [_jsxs(Label, { children: ["Plaats ", req && _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(Input, { ref: fieldRefs.city, value: form.city, onChange: (e) => setForm({ ...form, city: e.target.value }), onBlur: () => markTouched("city"), "aria-invalid": !!showError("city"), className: showError("city") ? "border-destructive" : undefined }), showError("city") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("city") })] }), _jsxs("div", { ref: fieldRefs.country, tabIndex: -1, children: [_jsxs(Label, { children: ["Land ", req && _jsx("span", { className: "text-destructive", children: "*" })] }), _jsx(SearchableSelect, { value: form.country, onValueChange: (v) => { markTouched("country"); setForm({ ...form, country: v, province: "" }); }, options: Object.entries(COUNTRY_NAMES).map(([code, name]) => ({
|
|
199
|
+
value: code,
|
|
200
|
+
label: `${countryNameToFlag(code) ?? ""} ${name}`.trim(),
|
|
201
|
+
search: `${name} ${code}`,
|
|
202
|
+
})), placeholder: form.country && !COUNTRY_NAMES[form.country] ? `Onbekend land: ${form.country}` : "Kies een land", triggerClassName: `w-full ${showError("country") ? "border-destructive" : ""}` }), showError("country") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("country") })] }), _jsxs("div", { ref: fieldRefs.province, tabIndex: -1, children: [_jsxs(Label, { children: ["Provincie ", req && _jsx("span", { className: "text-destructive", children: "*" })] }), (() => {
|
|
199
203
|
const provinces = findCountry(form.country)?.provinces ?? [];
|
|
200
204
|
return provinces.length > 0 ? (_jsxs(Select, { value: form.province || "", onValueChange: (v) => { markTouched("province"); setForm({ ...form, province: v }); }, children: [_jsx(SelectTrigger, { className: showError("province") ? "border-destructive" : undefined, children: _jsx(SelectValue, { placeholder: "Kies een provincie" }) }), _jsx(SelectContent, { children: provinces.map((p) => (_jsx(SelectItem, { value: p, children: p }, p))) })] })) : (_jsx(Input, { value: form.province, onChange: (e) => setForm({ ...form, province: e.target.value }), onBlur: () => markTouched("province"), placeholder: "Kies eerst een land", disabled: !form.country, "aria-invalid": !!showError("province"), className: showError("province") ? "border-destructive" : undefined }));
|
|
201
|
-
})(), showError("province") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("province") })] }), _jsxs("div", { className: "md:col-span-2 space-y-2", children: [_jsx(Label, { children: "Vervoerder" }),
|
|
202
|
-
if (v === "__self__") {
|
|
203
|
-
setForm({ ...form, self_pickup: true, carrier_id: null, carrier_assignment_source: "manual" });
|
|
204
|
-
}
|
|
205
|
-
else if (v === "__none__") {
|
|
206
|
-
setForm({ ...form, self_pickup: false, carrier_id: null, carrier_assignment_source: "manual" });
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
setForm({ ...form, self_pickup: false, carrier_id: v, carrier_assignment_source: "manual" });
|
|
210
|
-
}
|
|
211
|
-
}, children: [_jsx(SelectTrigger, { children: _jsx(SelectValue, { placeholder: "Kies een vervoerder" }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "__self__", children: "Eigen vervoer (klant haalt zelf op)" }), _jsx(SelectItem, { value: "__none__", children: "\u2014 Geen vervoerder \u2014" }), carriers.map((c) => (_jsx(SelectItem, { value: c.id, children: c.name }, c.id)))] })] }), form.self_pickup ? (_jsx("div", { className: "text-xs text-muted-foreground", children: "De klant komt zelf de karren ophalen \u2014 er wordt geen vervoerder gekoppeld." })) : form.carrier_assignment_source === "manual" ? (_jsxs("div", { className: "flex items-center justify-between text-xs text-muted-foreground", children: [_jsx("span", { children: "Handmatig overschreven." }), _jsx(Button, { variant: "link", size: "sm", className: "h-auto p-0", onClick: () => setForm({ ...form, carrier_assignment_source: "auto" }), children: "Terug naar automatisch" })] })) : autoSuggested?.carrier_id ? (_jsxs("div", { className: "text-xs text-muted-foreground flex items-center gap-1", children: [_jsx(Sparkles, { className: "h-3 w-3" }), "Automatisch geselecteerd op basis van ", autoSuggested.matched_on === "city"
|
|
212
|
-
? "plaats" : autoSuggested.matched_on === "province" ? "provincie" : "land", "."] })) : (_jsx("div", { className: "text-xs text-warning-soft-foreground", children: "Geen vervoerder gevonden voor dit bedieningsgebied \u2014 selecteer er handmatig \u00E9\u00E9n." }))] }), _jsxs("label", { className: "md:col-span-2 flex items-start gap-2 text-sm", children: [_jsx("input", { type: "checkbox", className: "mt-1", checked: form.is_primary, onChange: (e) => setForm({ ...form, is_primary: e.target.checked }) }), _jsxs("span", { children: ["Vaste afleverlocatie", _jsx("span", { className: "block text-xs text-muted-foreground", children: "Wordt bij nieuwe orders vooraf gekozen. Een eventuele andere vaste locatie van deze klant vervalt." })] })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { variant: "outline", onClick: () => setOpen(false), children: "Annuleren" }), _jsx(Button, { onClick: handleSubmit, disabled: saveMut.isPending, children: form.id ? "Opslaan" : "Toevoegen" })] })] }) }), _jsx(Dialog, { open: importOpen, onOpenChange: setImportOpen, children: _jsxs(DialogContent, { className: "max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "Afleverlocaties importeren uit Floriday" }), _jsx(DialogDescription, { children: "Controleer de locaties voordat je importeert. Adres, plaats, land en GLN-code komen uit Floriday. De vervoerder wordt automatisch gekoppeld op basis van het bedieningsgebied." })] }), _jsx("div", { className: "max-h-[50vh] overflow-auto rounded-md border", children: _jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { className: "bg-muted/50 text-left", children: _jsxs("tr", { children: [_jsx("th", { className: "px-3 py-2 font-medium", children: "Locatie" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Klant" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Adres" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "GLN" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Actie" })] }) }), _jsxs("tbody", { children: [(importPreview?.items ?? []).map((it) => (_jsxs("tr", { className: "border-t", children: [_jsx("td", { className: "px-3 py-2", children: it.name }), _jsx("td", { className: "px-3 py-2", children: it.customer_name ?? "—" }), _jsx("td", { className: "px-3 py-2 text-muted-foreground", children: it.address || "—" }), _jsx("td", { className: "px-3 py-2 text-muted-foreground", children: it.gln ?? "—" }), _jsxs("td", { className: "px-3 py-2", children: [it.action === "create" && _jsx(Badge, { children: "Nieuw" }), it.action === "update" && _jsx(Badge, { variant: "secondary", children: "Bijwerken" }), it.action === "no_customer" && (_jsx(Badge, { variant: "outline", className: "text-warning-soft-foreground border-warning bg-warning-soft", children: "Geen klant gevonden" }))] })] }, it.floriday_id))), (importPreview?.items ?? []).length === 0 && (_jsx("tr", { children: _jsx("td", { colSpan: 5, className: "px-3 py-6 text-center text-muted-foreground", children: "Geen locaties gevonden in Floriday." }) }))] })] }) }), _jsxs("div", { className: "text-sm text-muted-foreground", children: [importPreview?.created ?? 0, " nieuw \u00B7 ", importPreview?.updated ?? 0, " bijwerken", (importPreview?.skipped ?? 0) > 0
|
|
205
|
+
})(), showError("province") && _jsx("p", { className: "mt-1 text-xs text-destructive", children: showError("province") })] }), _jsxs("div", { className: "md:col-span-2 space-y-2", children: [_jsx(Label, { children: "Vervoerder" }), _jsx(CarrierPicker, { variant: "location", value: choiceFromLocation(form), onChange: (choice) => setForm({ ...form, ...locationCarrierFields(choice) }), autoLabel: autoLabel }), formProposal.error && (_jsx(ProposalLine, { result: undefined, error: formProposal.error, onRetry: () => formProposal.refetch() })), form.self_pickup ? (_jsx("div", { className: "text-xs text-muted-foreground", children: "De klant komt zelf de karren ophalen. Er wordt geen vervoerder gekoppeld." })) : choiceFromLocation(form).kind === "auto" ? (_jsx("div", { className: "text-xs text-muted-foreground", children: "Er wordt geen vervoerder vastgelegd; het voorstel wordt steeds opnieuw bepaald." })) : null] }), _jsxs("label", { className: "md:col-span-2 flex items-start gap-2 text-sm", children: [_jsx("input", { type: "checkbox", className: "mt-1", checked: form.is_primary, onChange: (e) => setForm({ ...form, is_primary: e.target.checked }) }), _jsxs("span", { children: ["Vaste afleverlocatie", _jsx("span", { className: "block text-xs text-muted-foreground", children: "Wordt bij nieuwe orders vooraf gekozen. Een eventuele andere vaste locatie van deze klant vervalt." })] })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { variant: "outline", onClick: () => setOpen(false), children: "Annuleren" }), _jsx(Button, { onClick: handleSubmit, disabled: saveMut.isPending, children: form.id ? "Opslaan" : "Toevoegen" })] })] }) }), _jsx(Dialog, { open: importOpen, onOpenChange: setImportOpen, children: _jsxs(DialogContent, { className: "max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "Afleverlocaties importeren uit Floriday" }), _jsx(DialogDescription, { children: "Controleer de locaties voordat je importeert. Adres, plaats, land en GLN-code komen uit Floriday. Nieuwe locaties krijgen de vervoerder \"Automatisch\"; bestaande keuzes blijven staan." })] }), _jsx("div", { className: "max-h-[50vh] overflow-auto rounded-md border", children: _jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { className: "bg-muted/50 text-left", children: _jsxs("tr", { children: [_jsx("th", { className: "px-3 py-2 font-medium", children: "Locatie" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Klant" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Adres" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "GLN" }), _jsx("th", { className: "px-3 py-2 font-medium", children: "Actie" })] }) }), _jsxs("tbody", { children: [(importPreview?.items ?? []).map((it) => (_jsxs("tr", { className: "border-t", children: [_jsx("td", { className: "px-3 py-2", children: it.name }), _jsx("td", { className: "px-3 py-2", children: it.customer_name ?? "—" }), _jsx("td", { className: "px-3 py-2 text-muted-foreground", children: it.address || "—" }), _jsx("td", { className: "px-3 py-2 text-muted-foreground", children: it.gln ?? "—" }), _jsxs("td", { className: "px-3 py-2", children: [it.action === "create" && _jsx(Badge, { children: "Nieuw" }), it.action === "update" && _jsx(Badge, { variant: "secondary", children: "Bijwerken" }), it.action === "no_customer" && (_jsx(Badge, { variant: "outline", className: "text-warning-soft-foreground border-warning bg-warning-soft", children: "Geen klant gevonden" }))] })] }, it.floriday_id))), (importPreview?.items ?? []).length === 0 && (_jsx("tr", { children: _jsx("td", { colSpan: 5, className: "px-3 py-6 text-center text-muted-foreground", children: "Geen locaties gevonden in Floriday." }) }))] })] }) }), _jsxs("div", { className: "text-sm text-muted-foreground", children: [importPreview?.created ?? 0, " nieuw \u00B7 ", importPreview?.updated ?? 0, " bijwerken", (importPreview?.skipped ?? 0) > 0
|
|
213
206
|
? ` · ${importPreview?.skipped} overgeslagen omdat de Floriday-organisatie niet aan een klant gekoppeld is`
|
|
214
207
|
: ""] }), _jsxs(DialogFooter, { children: [_jsx(Button, { variant: "outline", onClick: () => setImportOpen(false), children: "Afbreken" }), _jsx(Button, { onClick: () => importMut.mutate(), disabled: importMut.isPending || ((importPreview?.created ?? 0) + (importPreview?.updated ?? 0)) === 0, children: importMut.isPending ? "Importeren…" : "Importeren" })] })] }) })] }));
|
|
215
208
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KlantDetail.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/KlantDetail.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"KlantDetail.d.ts","sourceRoot":"","sources":["../../../src/components/klanten/KlantDetail.tsx"],"names":[],"mappings":"AA8CA,wBAAgB,WAAW,CAAC,EAAE,EAAE,EAAE,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,+BA2XjD"}
|