@lodashventure/medusa-booking-for-pickup 1.4.1 → 1.4.2

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,15 +1,346 @@
1
1
  "use strict";
2
2
  const jsxRuntime = require("react/jsx-runtime");
3
+ const react = require("react");
4
+ const lucideReact = require("lucide-react");
3
5
  const adminSdk = require("@medusajs/admin-sdk");
4
- const icons = require("@medusajs/icons");
5
6
  const ui = require("@medusajs/ui");
6
- const react = require("react");
7
+ const icons = require("@medusajs/icons");
7
8
  const reactRouterDom = require("react-router-dom");
8
- const reactQuery = require("@tanstack/react-query");
9
9
  const Medusa = require("@medusajs/js-sdk");
10
- const lucideReact = require("lucide-react");
11
10
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
12
11
  const Medusa__default = /* @__PURE__ */ _interopDefault(Medusa);
12
+ const CustomerPickupHistoryWidget = ({ data }) => {
13
+ const [pickupHistory, setPickupHistory] = react.useState([]);
14
+ const [loading, setLoading] = react.useState(true);
15
+ const [error, setError] = react.useState(null);
16
+ const customer = data;
17
+ react.useEffect(() => {
18
+ fetchPickupHistory();
19
+ }, [customer.id]);
20
+ const fetchPickupHistory = async () => {
21
+ setLoading(true);
22
+ setError(null);
23
+ try {
24
+ const response = await fetch(
25
+ `/admin/customers/${customer.id}/pickup-history`,
26
+ {
27
+ credentials: "include"
28
+ }
29
+ );
30
+ if (!response.ok) {
31
+ throw new Error("Failed to fetch pickup history");
32
+ }
33
+ const data2 = await response.json();
34
+ setPickupHistory(data2.pickup_history || []);
35
+ } catch (err) {
36
+ console.error("Error fetching pickup history:", err);
37
+ setError(err.message);
38
+ } finally {
39
+ setLoading(false);
40
+ }
41
+ };
42
+ const formatDate = (dateString) => {
43
+ const date = new Date(dateString);
44
+ return new Intl.DateTimeFormat("th-TH", {
45
+ year: "numeric",
46
+ month: "short",
47
+ day: "numeric",
48
+ hour: "2-digit",
49
+ minute: "2-digit"
50
+ }).format(date);
51
+ };
52
+ const formatCurrency = (amount, currency) => {
53
+ return new Intl.NumberFormat("th-TH", {
54
+ style: "currency",
55
+ currency: currency.toUpperCase()
56
+ }).format(amount / 100);
57
+ };
58
+ const getStatusBadge = (status) => {
59
+ const statusColors = {
60
+ completed: "green",
61
+ pending: "orange",
62
+ canceled: "red",
63
+ processing: "blue"
64
+ };
65
+ const statusLabels = {
66
+ completed: "เสร็จสิ้น",
67
+ pending: "รอดำเนินการ",
68
+ canceled: "ยกเลิก",
69
+ processing: "กำลังดำเนินการ"
70
+ };
71
+ return /* @__PURE__ */ jsxRuntime.jsx(Badge, { color: statusColors[status] || "grey", size: "small", children: statusLabels[status] || status });
72
+ };
73
+ if (loading) {
74
+ return /* @__PURE__ */ jsxRuntime.jsxs(Container, { className: "divide-y p-0", children: [
75
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
76
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { className: "text-ui-fg-subtle" }),
77
+ /* @__PURE__ */ jsxRuntime.jsx(Heading, { level: "h2", children: "ประวัติการจองรับสินค้า" })
78
+ ] }) }),
79
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(Text, { className: "text-ui-fg-subtle", children: "กำลังโหลด..." }) })
80
+ ] });
81
+ }
82
+ if (error) {
83
+ return /* @__PURE__ */ jsxRuntime.jsxs(Container, { className: "divide-y p-0", children: [
84
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
85
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { className: "text-ui-fg-subtle" }),
86
+ /* @__PURE__ */ jsxRuntime.jsx(Heading, { level: "h2", children: "ประวัติการจองรับสินค้า" })
87
+ ] }) }),
88
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(Text, { className: "text-red-500", children: error }) })
89
+ ] });
90
+ }
91
+ return /* @__PURE__ */ jsxRuntime.jsxs(Container, { className: "divide-y p-0", children: [
92
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
93
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
94
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { className: "text-ui-fg-subtle" }),
95
+ /* @__PURE__ */ jsxRuntime.jsx(Heading, { level: "h2", children: "ประวัติการจองรับสินค้า" }),
96
+ pickupHistory.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(Badge, { size: "small", children: pickupHistory.length })
97
+ ] }),
98
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { size: "small", variant: "transparent", onClick: fetchPickupHistory, children: "รีเฟรช" })
99
+ ] }),
100
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: pickupHistory.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center py-8 text-center", children: [
101
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Package, { className: "text-ui-fg-muted mb-4", size: 48 }),
102
+ /* @__PURE__ */ jsxRuntime.jsx(Text, { className: "text-ui-fg-subtle", children: "ยังไม่มีประวัติการจองรับสินค้า" })
103
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-4", children: pickupHistory.map((pickup) => {
104
+ var _a;
105
+ return /* @__PURE__ */ jsxRuntime.jsxs(
106
+ "div",
107
+ {
108
+ className: "rounded-lg border p-4 hover:bg-ui-bg-subtle transition-colors",
109
+ children: [
110
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between mb-3", children: [
111
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
112
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ShoppingBag, { className: "text-ui-fg-subtle", size: 20 }),
113
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: pickup.order ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
114
+ /* @__PURE__ */ jsxRuntime.jsxs(Text, { weight: "plus", size: "small", children: [
115
+ "คำสั่งซื้อ #",
116
+ pickup.order.display_id
117
+ ] }),
118
+ /* @__PURE__ */ jsxRuntime.jsxs(Text, { size: "xsmall", className: "text-ui-fg-subtle", children: [
119
+ ((_a = pickup.order.items) == null ? void 0 : _a.length) || 0,
120
+ " รายการ"
121
+ ] })
122
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(Text, { weight: "plus", size: "small", children: [
123
+ "คำสั่งซื้อ ",
124
+ pickup.order_id
125
+ ] }) })
126
+ ] }),
127
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-end gap-1", children: [
128
+ pickup.order && getStatusBadge(pickup.order.status),
129
+ pickup.order && /* @__PURE__ */ jsxRuntime.jsx(Text, { weight: "plus", size: "small", children: formatCurrency(
130
+ pickup.order.total,
131
+ pickup.order.currency_code
132
+ ) })
133
+ ] })
134
+ ] }),
135
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-4 text-sm", children: [
136
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 text-ui-fg-subtle", children: [
137
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { size: 16 }),
138
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
139
+ "วันที่รับ: ",
140
+ formatDate(pickup.pickup_datetime)
141
+ ] })
142
+ ] }),
143
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 text-ui-fg-subtle", children: [
144
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { size: 16 }),
145
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
146
+ "จองเมื่อ: ",
147
+ formatDate(pickup.created_at)
148
+ ] })
149
+ ] })
150
+ ] }),
151
+ pickup.order && pickup.order.shipping_methods && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-2 pt-2 border-t", children: /* @__PURE__ */ jsxRuntime.jsx(Text, { size: "xsmall", className: "text-ui-fg-subtle", children: pickup.order.shipping_methods.map((sm) => sm.name).join(", ") }) })
152
+ ]
153
+ },
154
+ pickup.id
155
+ );
156
+ }) }) })
157
+ ] });
158
+ };
159
+ defineWidgetConfig({
160
+ zone: "customer.details.after"
161
+ });
162
+ const OrderPickupBookingWidget = ({ data }) => {
163
+ var _a, _b;
164
+ const [pickupBooking, setPickupBooking] = react.useState(null);
165
+ const [loading, setLoading] = react.useState(true);
166
+ const [error, setError] = react.useState(null);
167
+ const order = data;
168
+ react.useEffect(() => {
169
+ fetchPickupBooking();
170
+ }, [order.id]);
171
+ const fetchPickupBooking = async () => {
172
+ setLoading(true);
173
+ setError(null);
174
+ try {
175
+ const response = await fetch(`/admin/orders/${order.id}/pickup-booking`, {
176
+ credentials: "include"
177
+ });
178
+ if (!response.ok) {
179
+ if (response.status === 404) {
180
+ setPickupBooking(null);
181
+ setLoading(false);
182
+ return;
183
+ }
184
+ throw new Error("Failed to fetch pickup booking");
185
+ }
186
+ const data2 = await response.json();
187
+ setPickupBooking(data2.pickup_booking);
188
+ } catch (err) {
189
+ console.error("Error fetching pickup booking:", err);
190
+ setError(err.message);
191
+ } finally {
192
+ setLoading(false);
193
+ }
194
+ };
195
+ const formatDate = (dateString) => {
196
+ const date = new Date(dateString);
197
+ return new Intl.DateTimeFormat("th-TH", {
198
+ year: "numeric",
199
+ month: "long",
200
+ day: "numeric"
201
+ }).format(date);
202
+ };
203
+ const formatTime = (dateString) => {
204
+ const date = new Date(dateString);
205
+ return new Intl.DateTimeFormat("th-TH", {
206
+ hour: "2-digit",
207
+ minute: "2-digit",
208
+ hour12: false
209
+ }).format(date);
210
+ };
211
+ const formatDateTime = (dateString) => {
212
+ const date = new Date(dateString);
213
+ return new Intl.DateTimeFormat("th-TH", {
214
+ year: "numeric",
215
+ month: "short",
216
+ day: "numeric",
217
+ hour: "2-digit",
218
+ minute: "2-digit"
219
+ }).format(date);
220
+ };
221
+ const getPickupStatus = () => {
222
+ const now = /* @__PURE__ */ new Date();
223
+ const pickupDate = pickupBooking ? new Date(pickupBooking.pickup_datetime) : null;
224
+ if (!pickupDate) return { label: "N/A", color: "grey" };
225
+ if (order.status === "completed" || order.status === "delivered") {
226
+ return { label: "รับสินค้าแล้ว", color: "green" };
227
+ }
228
+ if (order.status === "canceled") {
229
+ return { label: "ยกเลิก", color: "red" };
230
+ }
231
+ if (now > pickupDate) {
232
+ return { label: "เลยกำหนดรับ", color: "orange" };
233
+ }
234
+ return { label: "รอรับสินค้า", color: "blue" };
235
+ };
236
+ if (loading) {
237
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
238
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
239
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { className: "text-ui-fg-subtle" }),
240
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "การจองรับสินค้า" })
241
+ ] }) }),
242
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "กำลังโหลด..." }) })
243
+ ] });
244
+ }
245
+ if (error) {
246
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
247
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
248
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { className: "text-ui-fg-subtle" }),
249
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "การจองรับสินค้า" })
250
+ ] }) }),
251
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-red-500", children: error }) })
252
+ ] });
253
+ }
254
+ if (!pickupBooking) {
255
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
256
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
257
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { className: "text-ui-fg-subtle" }),
258
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "การจองรับสินค้า" })
259
+ ] }) }),
260
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center py-8 text-center", children: [
261
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MapPin, { className: "text-ui-fg-muted mb-4", size: 48 }),
262
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "คำสั่งซื้อนี้ไม่ได้จองรับสินค้าที่สาขา" }),
263
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-muted mt-2", children: "คำสั่งซื้อนี้อาจเป็นการจัดส่งแบบปกติ" })
264
+ ] }) })
265
+ ] });
266
+ }
267
+ const status = getPickupStatus();
268
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
269
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
270
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
271
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { className: "text-ui-fg-subtle" }),
272
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "การจองรับสินค้าที่สาขา" }),
273
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: status.color, size: "small", children: status.label })
274
+ ] }),
275
+ /* @__PURE__ */ jsxRuntime.jsx(
276
+ ui.Button,
277
+ {
278
+ size: "small",
279
+ variant: "transparent",
280
+ onClick: () => {
281
+ fetchPickupBooking();
282
+ ui.toast.success("รีเฟรชข้อมูลแล้ว");
283
+ },
284
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RefreshCw, { size: 16 })
285
+ }
286
+ )
287
+ ] }),
288
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
289
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
290
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
291
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-ui-fg-subtle", children: [
292
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Calendar, { size: 16 }),
293
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", weight: "plus", children: "วันที่รับสินค้า" })
294
+ ] }),
295
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", children: formatDate(pickupBooking.pickup_datetime) })
296
+ ] }),
297
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
298
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-ui-fg-subtle", children: [
299
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { size: 16 }),
300
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", weight: "plus", children: "เวลารับสินค้า" })
301
+ ] }),
302
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", children: formatTime(pickupBooking.pickup_datetime) })
303
+ ] })
304
+ ] }),
305
+ pickupBooking.shipping_option && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border p-4 bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-2 mb-2", children: [
306
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MapPin, { className: "text-ui-fg-muted mt-1", size: 16 }),
307
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1", children: [
308
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", size: "small", className: "mb-1", children: pickupBooking.shipping_option.name }),
309
+ ((_b = (_a = pickupBooking.shipping_option.service_zone) == null ? void 0 : _a.fulfillment_set) == null ? void 0 : _b.location) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
310
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: pickupBooking.shipping_option.service_zone.fulfillment_set.location.name }),
311
+ pickupBooking.shipping_option.service_zone.fulfillment_set.location.address && /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "xsmall", className: "text-ui-fg-muted mt-1", children: [
312
+ pickupBooking.shipping_option.service_zone.fulfillment_set.location.address.address_1,
313
+ pickupBooking.shipping_option.service_zone.fulfillment_set.location.address.address_2 && `, ${pickupBooking.shipping_option.service_zone.fulfillment_set.location.address.address_2}`,
314
+ /* @__PURE__ */ jsxRuntime.jsx("br", {}),
315
+ pickupBooking.shipping_option.service_zone.fulfillment_set.location.address.city,
316
+ " ",
317
+ pickupBooking.shipping_option.service_zone.fulfillment_set.location.address.province,
318
+ " ",
319
+ pickupBooking.shipping_option.service_zone.fulfillment_set.location.address.postal_code
320
+ ] })
321
+ ] })
322
+ ] })
323
+ ] }) }),
324
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-4 border-t", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
325
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
326
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-subtle", children: "จองเมื่อ" }),
327
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: formatDateTime(pickupBooking.created_at) })
328
+ ] }),
329
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
330
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", className: "text-ui-fg-subtle", children: "อัปเดตล่าสุด" }),
331
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", children: formatDateTime(pickupBooking.updated_at) })
332
+ ] })
333
+ ] }) }),
334
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-4 border-t", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "xsmall", className: "text-ui-fg-muted", children: [
335
+ "Booking ID: ",
336
+ pickupBooking.id
337
+ ] }) })
338
+ ] }) })
339
+ ] });
340
+ };
341
+ adminSdk.defineWidgetConfig({
342
+ zone: "order.details.after"
343
+ });
13
344
  const sdk = new Medusa__default.default({
14
345
  baseUrl: "/",
15
346
  debug: false,
@@ -17,25 +348,54 @@ const sdk = new Medusa__default.default({
17
348
  type: "session"
18
349
  }
19
350
  });
20
- const usePickupShippingOptions = (options) => {
21
- return reactQuery.useQuery({
22
- ...options,
23
- queryKey: ["pickup-shipping-options"],
24
- queryFn: async () => {
25
- const options2 = await sdk.admin.shippingOption.list({
26
- fields: "*.*"
351
+ const usePickupShippingOptions = () => {
352
+ const [data, setData] = react.useState(
353
+ null
354
+ );
355
+ const [isLoading, setIsLoading] = react.useState(true);
356
+ const [error, setError] = react.useState(null);
357
+ const fetchOptions = async () => {
358
+ setIsLoading(true);
359
+ setError(null);
360
+ try {
361
+ const options = await sdk.admin.shippingOption.list({
362
+ fields: [
363
+ "id",
364
+ "name",
365
+ "shipping_profile.*",
366
+ "service_zone.*",
367
+ "service_zone.fulfillment_set.*"
368
+ ].join(",")
27
369
  });
28
- const filteredOptions = options2.shipping_options.filter(
29
- (option) => option.service_zone.fulfillment_set.type === "pickup"
370
+ const filteredOptions = (options.shipping_options ?? []).filter(
371
+ (option) => {
372
+ var _a, _b;
373
+ return ((_b = (_a = option == null ? void 0 : option.service_zone) == null ? void 0 : _a.fulfillment_set) == null ? void 0 : _b.type) === "pickup";
374
+ }
30
375
  );
31
- return {
376
+ setData({
32
377
  shipping_options: filteredOptions,
33
378
  count: filteredOptions.length,
34
- limit: options2.limit,
35
- offset: options2.offset
36
- };
379
+ limit: options.limit,
380
+ offset: options.offset
381
+ });
382
+ } catch (err) {
383
+ setError(
384
+ err instanceof Error ? err : new Error("Failed to fetch pickup shipping options")
385
+ );
386
+ } finally {
387
+ setIsLoading(false);
37
388
  }
38
- });
389
+ };
390
+ react.useEffect(() => {
391
+ fetchOptions();
392
+ }, []);
393
+ return {
394
+ data,
395
+ isLoading,
396
+ error,
397
+ refetch: fetchOptions
398
+ };
39
399
  };
40
400
  const columnHelper = ui.createDataTableColumnHelper();
41
401
  const columns = [
@@ -1238,23 +1598,43 @@ axios$3.exports.default = axios$2;
1238
1598
  var axiosExports = axios$3.exports;
1239
1599
  var axios = axiosExports;
1240
1600
  const axios$1 = /* @__PURE__ */ getDefaultExportFromCjs(axios);
1241
- const usePickupAvailable = (id, options) => {
1242
- return reactQuery.useQuery({
1243
- ...options,
1244
- queryKey: ["pickup-shipping-option", id],
1245
- queryFn: async () => {
1246
- if (!id) {
1247
- throw new Error("id is required");
1248
- }
1601
+ const usePickupAvailable = (id) => {
1602
+ const [data, setData] = react.useState(null);
1603
+ const [isLoading, setIsLoading] = react.useState(true);
1604
+ const [error, setError] = react.useState(null);
1605
+ const fetchPickupAvailable = async () => {
1606
+ if (!id) {
1607
+ setError(new Error("id is required"));
1608
+ setIsLoading(false);
1609
+ return;
1610
+ }
1611
+ setIsLoading(true);
1612
+ setError(null);
1613
+ try {
1249
1614
  const option = await sdk.admin.shippingOption.retrieve(id, {
1250
1615
  fields: "*.*,pickup_availabilities.*"
1251
1616
  });
1252
1617
  if (option.shipping_option.service_zone.fulfillment_set.type !== "pickup") {
1253
1618
  throw new Error("shipping option is not pickup");
1254
1619
  }
1255
- return option;
1620
+ setData(option);
1621
+ } catch (err) {
1622
+ setError(
1623
+ err instanceof Error ? err : new Error("Failed to fetch pickup availability")
1624
+ );
1625
+ } finally {
1626
+ setIsLoading(false);
1256
1627
  }
1257
- });
1628
+ };
1629
+ react.useEffect(() => {
1630
+ fetchPickupAvailable();
1631
+ }, [id]);
1632
+ return {
1633
+ data,
1634
+ isLoading,
1635
+ error,
1636
+ refetch: fetchPickupAvailable
1637
+ };
1258
1638
  };
1259
1639
  const stringToMinutes = (time, defaultValue) => {
1260
1640
  if (!time) return defaultValue;
@@ -1611,7 +1991,16 @@ function ShippingOptionDetails() {
1611
1991
  /* @__PURE__ */ jsxRuntime.jsx(TimeTable, { schedule })
1612
1992
  ] });
1613
1993
  }
1614
- const widgetModule = { widgets: [] };
1994
+ const widgetModule = { widgets: [
1995
+ {
1996
+ Component: CustomerPickupHistoryWidget,
1997
+ zone: ["customer.details.after"]
1998
+ },
1999
+ {
2000
+ Component: OrderPickupBookingWidget,
2001
+ zone: ["order.details.after"]
2002
+ }
2003
+ ] };
1615
2004
  const routeModule = {
1616
2005
  routes: [
1617
2006
  {
@@ -1638,11 +2027,13 @@ const formModule = { customFields: {} };
1638
2027
  const displayModule = {
1639
2028
  displays: {}
1640
2029
  };
2030
+ const i18nModule = { resources: {} };
1641
2031
  const plugin = {
1642
2032
  widgetModule,
1643
2033
  routeModule,
1644
2034
  menuItemModule,
1645
2035
  formModule,
1646
- displayModule
2036
+ displayModule,
2037
+ i18nModule
1647
2038
  };
1648
2039
  module.exports = plugin;