@burdenoff/microfe-movethewheels 2026.1101.3 → 2026.1102.1

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.
Files changed (29) hide show
  1. package/dist/components/CustomerDeliveryUpdatesFields.js +57 -0
  2. package/dist/components/CustomerNotificationSettingsCard.js +368 -0
  3. package/dist/components/UpcomingDemandPanel.js +75 -77
  4. package/dist/generated/tracking-quality-operations.d.ts +275 -0
  5. package/dist/generated/wspace-operations.d.ts +3 -0
  6. package/dist/hooks/useCustomers.js +9 -3
  7. package/dist/hooks/useDemandForecast.js +1 -1
  8. package/dist/movethewheels/components/CustomerDeliveryUpdatesFields.d.ts +12 -0
  9. package/dist/movethewheels/components/CustomerNotificationSettingsCard.d.ts +3 -0
  10. package/dist/movethewheels/hooks/useDemandForecast.d.ts +3 -0
  11. package/dist/movethewheels/types/index.d.ts +4 -0
  12. package/dist/movethewheels/utils/customerNotifications.d.ts +66 -0
  13. package/dist/node_modules/lucide-react/dist/esm/icons/bell-ring.js +22 -0
  14. package/dist/pages/CustomerDetailsPage.js +279 -231
  15. package/dist/pages/SettingsPage.js +242 -238
  16. package/dist/utils/customerNotifications.js +83 -0
  17. package/package.json +3 -2
  18. package/src/generated/tracking-quality-operations.ts +304 -0
  19. package/src/generated/wspace-operations.ts +6 -6
  20. package/src/movethewheels/components/CustomerDeliveryUpdatesFields.tsx +67 -0
  21. package/src/movethewheels/components/CustomerNotificationSettingsCard.tsx +465 -0
  22. package/src/movethewheels/components/UpcomingDemandPanel.tsx +71 -29
  23. package/src/movethewheels/hooks/useCustomers.ts +17 -0
  24. package/src/movethewheels/hooks/useDemandForecast.ts +7 -0
  25. package/src/movethewheels/pages/CustomerDetailsPage.tsx +39 -0
  26. package/src/movethewheels/pages/SettingsPage.tsx +221 -208
  27. package/src/movethewheels/types/index.ts +4 -0
  28. package/src/movethewheels/utils/customerNotifications.ts +209 -0
  29. package/src/operations/wspace/movethewheels/queries/forecast.graphql +3 -0
@@ -0,0 +1,57 @@
1
+ import { Checkbox as e, Label as t } from "./ui.js";
2
+ import { jsx as n, jsxs as r } from "react/jsx-runtime";
3
+ //#region src/movethewheels/components/CustomerDeliveryUpdatesFields.tsx
4
+ function i({ idPrefix: i, value: a, onChange: o, disabled: s }) {
5
+ return /* @__PURE__ */ r("fieldset", {
6
+ className: "space-y-3",
7
+ disabled: s,
8
+ "data-testid": `${i}-delivery-updates`,
9
+ children: [
10
+ /* @__PURE__ */ n("legend", {
11
+ className: "text-sm font-medium text-text-primary",
12
+ children: "Delivery updates"
13
+ }),
14
+ /* @__PURE__ */ r("div", {
15
+ className: "flex items-start gap-2",
16
+ children: [/* @__PURE__ */ n(e, {
17
+ id: `${i}-notify-email`,
18
+ checked: a.notifyByEmail,
19
+ disabled: s,
20
+ onCheckedChange: (e) => o({
21
+ ...a,
22
+ notifyByEmail: e === !0
23
+ })
24
+ }), /* @__PURE__ */ n(t, {
25
+ htmlFor: `${i}-notify-email`,
26
+ className: "text-sm font-normal leading-snug",
27
+ children: "Email this customer about their shipments"
28
+ })]
29
+ }),
30
+ /* @__PURE__ */ r("div", {
31
+ className: "flex items-start gap-2",
32
+ children: [/* @__PURE__ */ n(e, {
33
+ id: `${i}-notify-sms`,
34
+ checked: a.notifyBySms,
35
+ disabled: s,
36
+ onCheckedChange: (e) => o({
37
+ ...a,
38
+ notifyBySms: e === !0
39
+ })
40
+ }), /* @__PURE__ */ n(t, {
41
+ htmlFor: `${i}-notify-sms`,
42
+ className: "text-sm font-normal leading-snug",
43
+ children: "Text this customer about their shipments (only with their consent; the phone number needs its country code, e.g. +91…)"
44
+ })]
45
+ }),
46
+ /* @__PURE__ */ n("p", {
47
+ className: "text-xs text-text-secondary",
48
+ children: "Sent only while customer delivery notifications are on in Settings."
49
+ })
50
+ ]
51
+ });
52
+ }
53
+ function a(e) {
54
+ return e.notifyByEmail && e.notifyBySms ? "Email and SMS" : e.notifyByEmail ? "Email" : e.notifyBySms ? "SMS" : "Off";
55
+ }
56
+ //#endregion
57
+ export { i as CustomerDeliveryUpdatesFields, a as deliveryUpdatesSummary };
@@ -0,0 +1,368 @@
1
+ import { BellRing as e } from "../node_modules/lucide-react/dist/esm/icons/bell-ring.js";
2
+ import { LoaderCircle as t } from "../node_modules/lucide-react/dist/esm/icons/loader-circle.js";
3
+ import { RefreshCw as n } from "../node_modules/lucide-react/dist/esm/icons/refresh-cw.js";
4
+ import { RotateCcw as ee } from "../node_modules/lucide-react/dist/esm/icons/rotate-ccw.js";
5
+ import { Save as te } from "../node_modules/lucide-react/dist/esm/icons/save.js";
6
+ import { useMoveTheWheels as ne } from "../providers/MoveTheWheelsProvider.js";
7
+ import { executeGraphQL as r } from "../utils/graphqlClient.js";
8
+ import { formatDateTime as i } from "../utils/formatters.js";
9
+ import { Badge as a, Button as o, Card as re, CardContent as ie, CardDescription as ae, CardHeader as oe, CardTitle as se, Checkbox as s, Label as c, Skeleton as l, Switch as ce } from "./ui.js";
10
+ import { FormError as u } from "./FormError.js";
11
+ import { Notice as le, useNotice as ue } from "./Notice.js";
12
+ import { CUSTOMER_NOTIFICATION_EVENTS as d, MTW_CUSTOMER_NOTIFICATIONS_QUERY as de, MTW_CUSTOMER_NOTIFICATION_PREVIEWS_QUERY as fe, MTW_CUSTOMER_NOTIFICATION_SETTINGS_QUERY as pe, STATUS_LABELS as me, UPDATE_MTW_CUSTOMER_NOTIFICATION_SETTINGS_MUTATION as he, changedNotificationSettings as ge, defaultNotificationSettings as _e, eventLabel as ve, notificationDraftError as ye, toggleEvent as be } from "../utils/customerNotifications.js";
13
+ import { useCallback as xe, useEffect as f, useMemo as p, useRef as Se, useState as m } from "react";
14
+ import { jsx as h, jsxs as g } from "react/jsx-runtime";
15
+ //#region src/movethewheels/components/CustomerNotificationSettingsCard.tsx
16
+ var Ce = 10, _ = (e) => ({
17
+ enabled: e.enabled,
18
+ emailEnabled: e.emailEnabled,
19
+ smsEnabled: e.smsEnabled,
20
+ events: [...e.events]
21
+ }), we = {
22
+ SENT: "default",
23
+ PENDING: "secondary",
24
+ SKIPPED: "outline",
25
+ FAILED: "destructive"
26
+ };
27
+ function v({ readOnly: v }) {
28
+ let { apiGatewayUrl: y, authToken: b, workspaceToken: x, workspaceId: S, tenantId: C, currentUser: w } = ne(), T = p(() => ({
29
+ apiGatewayUrl: y,
30
+ authToken: b,
31
+ workspaceToken: x,
32
+ workspaceId: S,
33
+ tenantId: C,
34
+ actorId: w?.id
35
+ }), [
36
+ y,
37
+ b,
38
+ x,
39
+ S,
40
+ C,
41
+ w?.id
42
+ ]), [E, D] = m(() => _e(S ?? "")), [O, k] = m(() => _(E)), [A, j] = m(!1), [M, N] = m(null), [P, F] = m(!1), [Te, I] = m(null), { message: Ee, notify: De } = ue(), [L, Oe] = m([]), [R, ke] = m(0), [z, B] = m(null), [V, H] = m(!0), [U, Ae] = m([]), [W, je] = m("BOOKED"), [Me, Ne] = m(0), G = Se(0);
43
+ f(() => {
44
+ if (!T.workspaceId) return;
45
+ let e = !1;
46
+ return j(!1), r(T, pe).then((t) => {
47
+ e || (D(t.mtwCustomerNotificationSettings), k(_(t.mtwCustomerNotificationSettings)), N(null), j(!0));
48
+ }).catch((t) => {
49
+ e || N(t instanceof Error ? t.message : "Could not load the settings");
50
+ }), r(T, fe).then((t) => {
51
+ e || Ae(t.mtwCustomerNotificationPreviews);
52
+ }).catch(() => {}), () => {
53
+ e = !0;
54
+ };
55
+ }, [T, Me]);
56
+ let K = xe(async () => {
57
+ if (!T.workspaceId) {
58
+ H(!1);
59
+ return;
60
+ }
61
+ let e = ++G.current;
62
+ H(!0);
63
+ try {
64
+ let t = await r(T, de, { pagination: {
65
+ limit: Ce,
66
+ offset: 0
67
+ } });
68
+ if (e !== G.current) return;
69
+ Oe(t.mtwCustomerNotifications.items), ke(t.mtwCustomerNotifications.total), B(null);
70
+ } catch (t) {
71
+ if (e !== G.current) return;
72
+ B(t instanceof Error ? t.message : "Could not load notifications");
73
+ } finally {
74
+ e === G.current && H(!1);
75
+ }
76
+ }, [T]);
77
+ f(() => (K(), () => {
78
+ G.current += 1;
79
+ }), [K]);
80
+ let q = p(() => ge(E, O), [E, O]), J = ye(O), Y = Object.keys(q).length > 0, X = A && !v && !P && Y && !J, Z = v || P || !A, Q = (e) => {
81
+ I(null), k((t) => ({
82
+ ...t,
83
+ ...e
84
+ }));
85
+ }, Pe = async (e) => {
86
+ if (e.preventDefault(), X) {
87
+ F(!0), I(null);
88
+ try {
89
+ let e = (await r(T, he, { input: q }, "SINGLE_ATTEMPT")).updateMtwCustomerNotificationSettings;
90
+ D(e), k(_(e)), De(e.enabled ? "Customer notifications are on. Customers hear about shipment changes from now on." : "Customer notifications are off.");
91
+ } catch (e) {
92
+ I(e instanceof Error ? e.message : "Could not save the settings");
93
+ } finally {
94
+ F(!1);
95
+ }
96
+ }
97
+ }, $ = U.find((e) => e.event === W);
98
+ return /* @__PURE__ */ g(re, {
99
+ "data-testid": "mtw-customer-notifications",
100
+ children: [/* @__PURE__ */ g(oe, { children: [/* @__PURE__ */ g("div", {
101
+ className: "flex flex-wrap items-center justify-between gap-3",
102
+ children: [/* @__PURE__ */ g(se, {
103
+ className: "flex items-center gap-2 text-base",
104
+ children: [/* @__PURE__ */ h(e, { size: 18 }), " Customer delivery notifications"]
105
+ }), A && /* @__PURE__ */ h(a, {
106
+ variant: E.enabled ? "default" : "outline",
107
+ children: E.enabled ? "On" : "Off"
108
+ })]
109
+ }), /* @__PURE__ */ h(ae, { children: "Email or text your customers when their shipment is booked, picked up, out for delivery, delivered, running late or could not be delivered. Each customer can opt out on their customer record; SMS goes only to customers who agreed to texts." })] }), /* @__PURE__ */ g(ie, {
110
+ className: "space-y-6",
111
+ children: [
112
+ M && /* @__PURE__ */ g("div", {
113
+ className: "space-y-3",
114
+ children: [/* @__PURE__ */ h(u, { message: `Could not load the customer notification settings (${M}). They cannot be changed until they load.` }), /* @__PURE__ */ g(o, {
115
+ type: "button",
116
+ variant: "outline",
117
+ size: "sm",
118
+ onClick: () => {
119
+ N(null), Ne((e) => e + 1);
120
+ },
121
+ children: [/* @__PURE__ */ h(n, {
122
+ size: 14,
123
+ className: "mr-2"
124
+ }), " Try again"]
125
+ })]
126
+ }),
127
+ /* @__PURE__ */ h(le, { message: Ee }),
128
+ A ? /* @__PURE__ */ g("form", {
129
+ className: "space-y-6",
130
+ onSubmit: (e) => void Pe(e),
131
+ "aria-label": "Customer notification settings",
132
+ children: [
133
+ v && /* @__PURE__ */ h("p", {
134
+ className: "rounded-lg border border-border-default bg-surface-secondary px-4 py-3 text-sm text-text-secondary",
135
+ children: "You can view these settings. Ask a workspace admin or the Logistics Director to change them."
136
+ }),
137
+ /* @__PURE__ */ g("div", {
138
+ className: "flex items-start justify-between gap-4 rounded-lg border border-border-default px-4 py-3",
139
+ children: [/* @__PURE__ */ g("div", {
140
+ className: "min-w-0",
141
+ children: [/* @__PURE__ */ h(c, {
142
+ htmlFor: "mtw-customer-notify-enabled",
143
+ className: "text-sm font-medium",
144
+ children: "Notify customers about their shipments"
145
+ }), /* @__PURE__ */ g("p", {
146
+ className: "text-xs text-text-secondary",
147
+ children: ["Only changes made after you switch this on notify; customers are never mailed about shipments that already happened.", E.enabledAt && E.enabled ? ` On since ${i(E.enabledAt)}.` : ""]
148
+ })]
149
+ }), /* @__PURE__ */ h(ce, {
150
+ id: "mtw-customer-notify-enabled",
151
+ checked: O.enabled,
152
+ disabled: Z,
153
+ onCheckedChange: (e) => Q({ enabled: e })
154
+ })]
155
+ }),
156
+ /* @__PURE__ */ g("fieldset", {
157
+ className: "space-y-3",
158
+ disabled: Z,
159
+ children: [
160
+ /* @__PURE__ */ h("legend", {
161
+ className: "text-sm font-semibold text-text-primary",
162
+ children: "Channels"
163
+ }),
164
+ /* @__PURE__ */ g("div", {
165
+ className: "flex flex-wrap gap-6",
166
+ children: [/* @__PURE__ */ g("div", {
167
+ className: "flex items-center gap-2",
168
+ children: [/* @__PURE__ */ h(s, {
169
+ id: "mtw-customer-notify-email",
170
+ checked: O.emailEnabled,
171
+ disabled: Z,
172
+ onCheckedChange: (e) => Q({ emailEnabled: e === !0 })
173
+ }), /* @__PURE__ */ h(c, {
174
+ htmlFor: "mtw-customer-notify-email",
175
+ className: "text-sm font-normal",
176
+ children: "Email"
177
+ })]
178
+ }), /* @__PURE__ */ g("div", {
179
+ className: "flex items-center gap-2",
180
+ children: [/* @__PURE__ */ h(s, {
181
+ id: "mtw-customer-notify-sms",
182
+ checked: O.smsEnabled,
183
+ disabled: Z,
184
+ onCheckedChange: (e) => Q({ smsEnabled: e === !0 })
185
+ }), /* @__PURE__ */ h(c, {
186
+ htmlFor: "mtw-customer-notify-sms",
187
+ className: "text-sm font-normal",
188
+ children: "SMS (phone numbers with a country code, e.g. +91…)"
189
+ })]
190
+ })]
191
+ }),
192
+ /* @__PURE__ */ h("p", {
193
+ className: "text-xs text-text-secondary",
194
+ children: "Texts are sent through the SMS channel configured for your organization. Without one, SMS sends are recorded as failed in the recent notifications below."
195
+ })
196
+ ]
197
+ }),
198
+ /* @__PURE__ */ g("fieldset", {
199
+ className: "space-y-3",
200
+ disabled: Z,
201
+ children: [/* @__PURE__ */ h("legend", {
202
+ className: "text-sm font-semibold text-text-primary",
203
+ children: "Events"
204
+ }), /* @__PURE__ */ h("div", {
205
+ className: "grid grid-cols-1 gap-3 md:grid-cols-2",
206
+ children: d.map((e) => {
207
+ let t = `mtw-customer-notify-event-${e.value}`;
208
+ return /* @__PURE__ */ g("div", {
209
+ className: "flex items-start gap-2",
210
+ children: [/* @__PURE__ */ h(s, {
211
+ id: t,
212
+ checked: O.events.includes(e.value),
213
+ disabled: Z,
214
+ onCheckedChange: (t) => Q({ events: be(O.events, e.value, t === !0) })
215
+ }), /* @__PURE__ */ g(c, {
216
+ htmlFor: t,
217
+ className: "text-sm font-normal leading-snug",
218
+ children: [/* @__PURE__ */ h("span", {
219
+ className: "block font-medium text-text-primary",
220
+ children: e.label
221
+ }), /* @__PURE__ */ h("span", {
222
+ className: "block text-xs text-text-secondary",
223
+ children: e.description
224
+ })]
225
+ })]
226
+ }, e.value);
227
+ })
228
+ })]
229
+ }),
230
+ J && /* @__PURE__ */ h("p", {
231
+ className: "text-xs text-status-error-text",
232
+ children: J
233
+ }),
234
+ /* @__PURE__ */ h(u, { message: Te }),
235
+ /* @__PURE__ */ g("div", {
236
+ className: "flex flex-wrap items-center justify-end gap-3",
237
+ children: [/* @__PURE__ */ g(o, {
238
+ type: "button",
239
+ variant: "outline",
240
+ disabled: !Y || P,
241
+ onClick: () => {
242
+ I(null), k(_(E));
243
+ },
244
+ children: [/* @__PURE__ */ h(ee, {
245
+ size: 16,
246
+ className: "mr-2"
247
+ }), " Discard changes"]
248
+ }), /* @__PURE__ */ g(o, {
249
+ type: "submit",
250
+ disabled: !X,
251
+ children: [P ? /* @__PURE__ */ h(t, {
252
+ size: 16,
253
+ className: "mr-2 animate-spin"
254
+ }) : /* @__PURE__ */ h(te, {
255
+ size: 16,
256
+ className: "mr-2"
257
+ }), "Save notification settings"]
258
+ })]
259
+ })
260
+ ]
261
+ }) : M ? null : /* @__PURE__ */ g("div", {
262
+ className: "space-y-3",
263
+ "aria-busy": "true",
264
+ children: [/* @__PURE__ */ h(l, { className: "h-8 w-full" }), /* @__PURE__ */ h(l, { className: "h-24 w-full" })]
265
+ }),
266
+ U.length > 0 && /* @__PURE__ */ g("div", {
267
+ className: "space-y-3 border-t border-border-default pt-4",
268
+ children: [/* @__PURE__ */ g("div", {
269
+ className: "flex flex-wrap items-center gap-2",
270
+ children: [/* @__PURE__ */ h("span", {
271
+ className: "text-sm font-semibold text-text-primary",
272
+ children: "Preview"
273
+ }), d.map((e) => /* @__PURE__ */ h(o, {
274
+ type: "button",
275
+ size: "sm",
276
+ variant: W === e.value ? "default" : "outline",
277
+ onClick: () => je(e.value),
278
+ children: e.label
279
+ }, e.value))]
280
+ }), $ && /* @__PURE__ */ g("div", {
281
+ className: "space-y-2 rounded-lg bg-surface-secondary px-4 py-3 text-sm",
282
+ "data-testid": "mtw-customer-notify-preview",
283
+ children: [
284
+ /* @__PURE__ */ h("p", {
285
+ className: "font-medium text-text-primary",
286
+ children: $.subject
287
+ }),
288
+ /* @__PURE__ */ h("p", {
289
+ className: "whitespace-pre-line text-text-secondary",
290
+ children: $.emailText
291
+ }),
292
+ /* @__PURE__ */ g("p", {
293
+ className: "text-xs text-text-tertiary",
294
+ children: ["SMS: ", $.smsText]
295
+ })
296
+ ]
297
+ })]
298
+ }),
299
+ /* @__PURE__ */ g("div", {
300
+ className: "space-y-3 border-t border-border-default pt-4",
301
+ children: [
302
+ /* @__PURE__ */ g("div", {
303
+ className: "flex flex-wrap items-center justify-between gap-2",
304
+ children: [/* @__PURE__ */ g("span", {
305
+ className: "text-sm font-semibold text-text-primary",
306
+ children: ["Recent notifications", R > 0 ? ` (${R})` : ""]
307
+ }), /* @__PURE__ */ g(o, {
308
+ type: "button",
309
+ size: "sm",
310
+ variant: "outline",
311
+ disabled: V,
312
+ onClick: () => void K(),
313
+ children: [/* @__PURE__ */ h(n, {
314
+ size: 14,
315
+ className: "mr-2"
316
+ }), " Refresh"]
317
+ })]
318
+ }),
319
+ z && /* @__PURE__ */ h(u, { message: z }),
320
+ !z && L.length === 0 && !V && /* @__PURE__ */ h("p", {
321
+ className: "text-sm text-text-secondary",
322
+ children: "No customer notifications yet. They appear here as shipments change."
323
+ }),
324
+ L.length > 0 && /* @__PURE__ */ h("ul", {
325
+ className: "divide-y divide-border-default",
326
+ "data-testid": "mtw-customer-notify-recent",
327
+ children: L.map((e) => /* @__PURE__ */ g("li", {
328
+ className: "flex flex-wrap items-start justify-between gap-2 py-2",
329
+ children: [/* @__PURE__ */ g("div", {
330
+ className: "min-w-0",
331
+ children: [
332
+ /* @__PURE__ */ g("p", {
333
+ className: "text-sm font-medium text-text-primary",
334
+ children: [
335
+ ve(e.event),
336
+ " · ",
337
+ e.shipmentNumber ?? e.shipmentId
338
+ ]
339
+ }),
340
+ /* @__PURE__ */ g("p", {
341
+ className: "text-xs text-text-secondary",
342
+ children: [
343
+ e.channel === "EMAIL" ? "Email" : "SMS",
344
+ e.recipient ? ` to ${e.recipient}` : "",
345
+ " ·",
346
+ " ",
347
+ i(e.sentAt ?? e.createdAt)
348
+ ]
349
+ }),
350
+ e.lastError && e.status !== "SENT" && /* @__PURE__ */ h("p", {
351
+ className: "text-xs text-text-tertiary",
352
+ children: e.lastError
353
+ })
354
+ ]
355
+ }), /* @__PURE__ */ h(a, {
356
+ variant: we[e.status],
357
+ children: me[e.status]
358
+ })]
359
+ }, e.id))
360
+ })
361
+ ]
362
+ })
363
+ ]
364
+ })]
365
+ });
366
+ }
367
+ //#endregion
368
+ export { v as CustomerNotificationSettingsCard };