order-management 0.0.16 → 0.0.18

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 (42) hide show
  1. package/.medusa/server/src/admin/index.js +638 -5
  2. package/.medusa/server/src/admin/index.mjs +638 -5
  3. package/.medusa/server/src/api/admin/swaps/[id]/approve/route.js +45 -0
  4. package/.medusa/server/src/api/admin/swaps/[id]/reject/route.js +43 -0
  5. package/.medusa/server/src/api/admin/swaps/[id]/route.js +70 -0
  6. package/.medusa/server/src/api/admin/swaps/[id]/status/route.js +45 -0
  7. package/.medusa/server/src/api/admin/swaps/route.js +51 -0
  8. package/.medusa/server/src/api/admin/swaps/validators.js +22 -0
  9. package/.medusa/server/src/api/store/guest-orders/[id]/invoice/route.js +19 -2
  10. package/.medusa/server/src/api/store/guest-orders/[id]/returns/route.js +19 -2
  11. package/.medusa/server/src/api/store/guest-orders/[id]/route.js +19 -2
  12. package/.medusa/server/src/api/store/guest-orders/route.js +19 -2
  13. package/.medusa/server/src/api/store/orders/[order_id]/swaps/route.js +107 -0
  14. package/.medusa/server/src/api/store/otp/request/route.js +12 -5
  15. package/.medusa/server/src/api/store/otp/verify/route.js +3 -2
  16. package/.medusa/server/src/api/store/swaps/[id]/cancel/route.js +64 -0
  17. package/.medusa/server/src/api/store/swaps/[id]/route.js +112 -0
  18. package/.medusa/server/src/api/store/swaps/route.js +117 -0
  19. package/.medusa/server/src/config.js +3 -24
  20. package/.medusa/server/src/helpers/index.js +18 -0
  21. package/.medusa/server/src/helpers/swaps.js +88 -0
  22. package/.medusa/server/src/modules/swap/index.js +13 -0
  23. package/.medusa/server/src/modules/swap/migrations/Migration20260121164326.js +49 -0
  24. package/.medusa/server/src/modules/swap/models/swap.js +21 -0
  25. package/.medusa/server/src/modules/swap/service.js +154 -0
  26. package/.medusa/server/src/services/otp-service.js +21 -4
  27. package/.medusa/server/src/subscribers/send-order-email.js +29 -7
  28. package/.medusa/server/src/workflows/index.js +8 -2
  29. package/.medusa/server/src/workflows/steps/swap/calculate-difference-step.js +56 -0
  30. package/.medusa/server/src/workflows/steps/swap/create-swap-step.js +29 -0
  31. package/.medusa/server/src/workflows/steps/swap/index.js +16 -0
  32. package/.medusa/server/src/workflows/steps/swap/retrieve-swap-step.js +26 -0
  33. package/.medusa/server/src/workflows/steps/swap/update-swap-status-step.js +25 -0
  34. package/.medusa/server/src/workflows/steps/swap/validate-order-step.js +47 -0
  35. package/.medusa/server/src/workflows/steps/swap/validate-swap-items-step.js +41 -0
  36. package/.medusa/server/src/workflows/swaps/approve-swap-workflow.js +38 -0
  37. package/.medusa/server/src/workflows/swaps/create-swap-workflow.js +46 -0
  38. package/.medusa/server/src/workflows/swaps/types.js +3 -0
  39. package/.medusa/server/src/workflows/swaps/update-swap-status-workflow.js +23 -0
  40. package/README.md +247 -5
  41. package/package.json +1 -1
  42. package/.medusa/server/src/utils/resolve-options.js +0 -57
@@ -4,6 +4,217 @@ import { defineRouteConfig } from "@medusajs/admin-sdk";
4
4
  import { Container, Heading, Text, Button, Input, Badge } from "@medusajs/ui";
5
5
  import { ArrowPath, ArrowLeft } from "@medusajs/icons";
6
6
  import { useNavigate, useParams } from "react-router-dom";
7
+ const useDebounce$1 = (value, delay) => {
8
+ const [debouncedValue, setDebouncedValue] = useState(value);
9
+ useEffect(() => {
10
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
11
+ return () => clearTimeout(handler);
12
+ }, [value, delay]);
13
+ return debouncedValue;
14
+ };
15
+ const getStatusBadgeClass$3 = (status) => {
16
+ const statusLower = status.toLowerCase();
17
+ if (statusLower === "requested") {
18
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
19
+ }
20
+ if (statusLower === "approved") {
21
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
22
+ }
23
+ if (statusLower === "rejected") {
24
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
25
+ }
26
+ if (statusLower === "completed") {
27
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
28
+ }
29
+ if (statusLower === "cancelled") {
30
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
31
+ }
32
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
33
+ };
34
+ const SwapsPage = () => {
35
+ const navigate = useNavigate();
36
+ const [items, setItems] = useState([]);
37
+ const [statusFilter, setStatusFilter] = useState("all");
38
+ const [searchQuery, setSearchQuery] = useState("");
39
+ const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
40
+ const [isLoading, setIsLoading] = useState(true);
41
+ const [isFetchingMore, setIsFetchingMore] = useState(false);
42
+ const [error, setError] = useState(null);
43
+ const [offset, setOffset] = useState(0);
44
+ const [count, setCount] = useState(0);
45
+ const limit = 50;
46
+ const loadSwaps = useCallback(
47
+ async (nextOffset, replace = false) => {
48
+ var _a;
49
+ try {
50
+ if (replace) {
51
+ setIsLoading(true);
52
+ } else {
53
+ setIsFetchingMore(true);
54
+ }
55
+ setError(null);
56
+ const params = new URLSearchParams();
57
+ params.set("limit", String(limit));
58
+ params.set("offset", String(nextOffset));
59
+ if (statusFilter !== "all") {
60
+ params.set("status", statusFilter);
61
+ }
62
+ if (debouncedSearchQuery.trim()) {
63
+ params.set("order_id", debouncedSearchQuery.trim());
64
+ }
65
+ const response = await fetch(
66
+ `/admin/swaps?${params.toString()}`,
67
+ { credentials: "include" }
68
+ );
69
+ if (!response.ok) {
70
+ const message = await response.text();
71
+ throw new Error(message || "Unable to load swaps");
72
+ }
73
+ const payload = await response.json();
74
+ setCount(payload.count ?? 0);
75
+ setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
76
+ setItems(
77
+ (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
78
+ );
79
+ } catch (loadError) {
80
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
81
+ setError(message);
82
+ } finally {
83
+ setIsLoading(false);
84
+ setIsFetchingMore(false);
85
+ }
86
+ },
87
+ [statusFilter, debouncedSearchQuery]
88
+ );
89
+ useEffect(() => {
90
+ void loadSwaps(0, true);
91
+ }, [statusFilter, debouncedSearchQuery, loadSwaps]);
92
+ const hasMore = useMemo(() => offset < count, [offset, count]);
93
+ const availableStatuses = useMemo(() => {
94
+ const statuses = /* @__PURE__ */ new Set();
95
+ items.forEach((item) => statuses.add(item.status));
96
+ return Array.from(statuses).sort();
97
+ }, [items]);
98
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
99
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
100
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
101
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Swaps" }),
102
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer swap requests" })
103
+ ] }),
104
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
105
+ ] }),
106
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
107
+ /* @__PURE__ */ jsx(
108
+ Input,
109
+ {
110
+ placeholder: "Search by swap ID or order ID",
111
+ value: searchQuery,
112
+ onChange: (event) => setSearchQuery(event.target.value),
113
+ className: "md:max-w-sm"
114
+ }
115
+ ),
116
+ /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxs(
117
+ "select",
118
+ {
119
+ value: statusFilter,
120
+ onChange: (event) => setStatusFilter(event.target.value),
121
+ className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
122
+ children: [
123
+ /* @__PURE__ */ jsx("option", { value: "all", children: "All Statuses" }),
124
+ availableStatuses.map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
125
+ ]
126
+ }
127
+ ) })
128
+ ] }),
129
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
130
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
131
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(
132
+ Button,
133
+ {
134
+ variant: "secondary",
135
+ onClick: () => loadSwaps(0, true),
136
+ children: "Try again"
137
+ }
138
+ ) })
139
+ ] }) : null,
140
+ isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading swaps..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
141
+ /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No swaps yet" }),
142
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Swap requests created by customers will appear here." })
143
+ ] }) : /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
144
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
145
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Swap ID" }),
146
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
147
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
148
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Difference Due" }),
149
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
150
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
151
+ ] }) }),
152
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxs(
153
+ "tr",
154
+ {
155
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
156
+ onClick: () => navigate(`/swaps/${swap.id}`),
157
+ children: [
158
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsx("span", { children: swap.id }) }) }),
159
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: swap.order_id }),
160
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
161
+ Badge,
162
+ {
163
+ size: "2xsmall",
164
+ className: `uppercase ${getStatusBadgeClass$3(swap.status)}`,
165
+ children: swap.status.replace(/_/g, " ")
166
+ }
167
+ ) }),
168
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
169
+ const amount = swap.difference_due;
170
+ if (amount == null || amount === void 0) {
171
+ return "—";
172
+ }
173
+ const displayAmount = Number(amount) / 100;
174
+ const currency = swap.currency_code || "$";
175
+ const sign = displayAmount >= 0 ? "+" : "";
176
+ return `${sign}${currency}${displayAmount.toFixed(2)}`;
177
+ })() }),
178
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
179
+ year: "numeric",
180
+ month: "short",
181
+ day: "numeric",
182
+ hour: "numeric",
183
+ minute: "2-digit",
184
+ hour12: true
185
+ }) }),
186
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
187
+ Button,
188
+ {
189
+ variant: "transparent",
190
+ size: "small",
191
+ onClick: (e) => {
192
+ e.stopPropagation();
193
+ navigate(`/swaps/${swap.id}`);
194
+ },
195
+ children: "View"
196
+ }
197
+ ) })
198
+ ]
199
+ },
200
+ swap.id
201
+ )) })
202
+ ] }) }),
203
+ hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
204
+ Button,
205
+ {
206
+ variant: "secondary",
207
+ isLoading: isFetchingMore,
208
+ onClick: () => loadSwaps(offset, false),
209
+ children: "Load more"
210
+ }
211
+ ) }) : null
212
+ ] }) });
213
+ };
214
+ const config$3 = defineRouteConfig({
215
+ label: "Swaps",
216
+ icon: ArrowPath
217
+ });
7
218
  const useDebounce = (value, delay) => {
8
219
  const [debouncedValue, setDebouncedValue] = useState(value);
9
220
  useEffect(() => {
@@ -12,7 +223,7 @@ const useDebounce = (value, delay) => {
12
223
  }, [value, delay]);
13
224
  return debouncedValue;
14
225
  };
15
- const getStatusBadgeClass$1 = (status) => {
226
+ const getStatusBadgeClass$2 = (status) => {
16
227
  const statusLower = status.toLowerCase();
17
228
  if (statusLower === "requested") {
18
229
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -164,7 +375,7 @@ const ReturnsPage = () => {
164
375
  Badge,
165
376
  {
166
377
  size: "2xsmall",
167
- className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
378
+ className: `uppercase ${getStatusBadgeClass$2(returnOrder.status)}`,
168
379
  children: returnOrder.status.replace(/_/g, " ")
169
380
  }
170
381
  ) }),
@@ -213,10 +424,412 @@ const ReturnsPage = () => {
213
424
  ) }) : null
214
425
  ] }) });
215
426
  };
216
- const config$1 = defineRouteConfig({
427
+ const config$2 = defineRouteConfig({
217
428
  label: "Return Orders",
218
429
  icon: ArrowPath
219
430
  });
431
+ const getStatusBadgeClass$1 = (status) => {
432
+ const statusLower = status.toLowerCase();
433
+ if (statusLower === "requested") {
434
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
435
+ }
436
+ if (statusLower === "approved") {
437
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
438
+ }
439
+ if (statusLower === "rejected") {
440
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
441
+ }
442
+ if (statusLower === "completed") {
443
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
444
+ }
445
+ if (statusLower === "cancelled") {
446
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
447
+ }
448
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
449
+ };
450
+ const SwapDetailPage = () => {
451
+ var _a, _b;
452
+ const navigate = useNavigate();
453
+ const { id } = useParams();
454
+ const [swap, setSwap] = useState(null);
455
+ const [order, setOrder] = useState(null);
456
+ const [selectedStatus, setSelectedStatus] = useState("");
457
+ const [isLoading, setIsLoading] = useState(true);
458
+ const [isUpdating, setIsUpdating] = useState(false);
459
+ const [isApproving, setIsApproving] = useState(false);
460
+ const [isRejecting, setIsRejecting] = useState(false);
461
+ const [error, setError] = useState(null);
462
+ const [updateError, setUpdateError] = useState(null);
463
+ const [updateSuccess, setUpdateSuccess] = useState(false);
464
+ const availableStatuses = [
465
+ "requested",
466
+ "approved",
467
+ "rejected",
468
+ "return_started",
469
+ "return_shipped",
470
+ "return_received",
471
+ "new_items_shipped",
472
+ "completed",
473
+ "cancelled"
474
+ ];
475
+ useEffect(() => {
476
+ if (!id) {
477
+ navigate("/swaps");
478
+ return;
479
+ }
480
+ const loadSwap = async () => {
481
+ try {
482
+ setIsLoading(true);
483
+ setError(null);
484
+ const response = await fetch(`/admin/swaps/${id}`, {
485
+ credentials: "include"
486
+ });
487
+ if (!response.ok) {
488
+ const message = await response.text();
489
+ throw new Error(message || "Unable to load swap");
490
+ }
491
+ const payload = await response.json();
492
+ setSwap(payload.swap);
493
+ setOrder(payload.order || null);
494
+ setSelectedStatus("");
495
+ } catch (loadError) {
496
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
497
+ setError(message);
498
+ } finally {
499
+ setIsLoading(false);
500
+ }
501
+ };
502
+ void loadSwap();
503
+ }, [id, navigate]);
504
+ const handleStatusUpdate = async () => {
505
+ if (!id || !selectedStatus) {
506
+ return;
507
+ }
508
+ try {
509
+ setIsUpdating(true);
510
+ setUpdateError(null);
511
+ setUpdateSuccess(false);
512
+ const response = await fetch(`/admin/swaps/${id}/status`, {
513
+ method: "POST",
514
+ headers: {
515
+ "Content-Type": "application/json"
516
+ },
517
+ credentials: "include",
518
+ body: JSON.stringify({ status: selectedStatus })
519
+ });
520
+ if (!response.ok) {
521
+ const message = await response.text();
522
+ throw new Error(message || "Unable to update status");
523
+ }
524
+ const payload = await response.json();
525
+ setSwap(payload.swap);
526
+ setSelectedStatus("");
527
+ setUpdateSuccess(true);
528
+ setTimeout(() => setUpdateSuccess(false), 3e3);
529
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
530
+ credentials: "include"
531
+ });
532
+ if (detailResponse.ok) {
533
+ const detailPayload = await detailResponse.json();
534
+ setSwap(detailPayload.swap);
535
+ setOrder(detailPayload.order || null);
536
+ }
537
+ } catch (updateErr) {
538
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to update status";
539
+ setUpdateError(message);
540
+ } finally {
541
+ setIsUpdating(false);
542
+ }
543
+ };
544
+ const handleApprove = async () => {
545
+ if (!id) {
546
+ return;
547
+ }
548
+ try {
549
+ setIsApproving(true);
550
+ setUpdateError(null);
551
+ setUpdateSuccess(false);
552
+ const response = await fetch(`/admin/swaps/${id}/approve`, {
553
+ method: "POST",
554
+ headers: {
555
+ "Content-Type": "application/json"
556
+ },
557
+ credentials: "include"
558
+ });
559
+ if (!response.ok) {
560
+ const message = await response.text();
561
+ throw new Error(message || "Unable to approve swap");
562
+ }
563
+ const payload = await response.json();
564
+ setSwap(payload.swap);
565
+ setUpdateSuccess(true);
566
+ setTimeout(() => setUpdateSuccess(false), 3e3);
567
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
568
+ credentials: "include"
569
+ });
570
+ if (detailResponse.ok) {
571
+ const detailPayload = await response.json();
572
+ setSwap(detailPayload.swap);
573
+ setOrder(detailPayload.order || null);
574
+ }
575
+ } catch (updateErr) {
576
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to approve swap";
577
+ setUpdateError(message);
578
+ } finally {
579
+ setIsApproving(false);
580
+ }
581
+ };
582
+ const handleReject = async () => {
583
+ if (!id) {
584
+ return;
585
+ }
586
+ try {
587
+ setIsRejecting(true);
588
+ setUpdateError(null);
589
+ setUpdateSuccess(false);
590
+ const response = await fetch(`/admin/swaps/${id}/reject`, {
591
+ method: "POST",
592
+ headers: {
593
+ "Content-Type": "application/json"
594
+ },
595
+ credentials: "include",
596
+ body: JSON.stringify({ reason: "Rejected by admin" })
597
+ });
598
+ if (!response.ok) {
599
+ const message = await response.text();
600
+ throw new Error(message || "Unable to reject swap");
601
+ }
602
+ const payload = await response.json();
603
+ setSwap(payload.swap);
604
+ setUpdateSuccess(true);
605
+ setTimeout(() => setUpdateSuccess(false), 3e3);
606
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
607
+ credentials: "include"
608
+ });
609
+ if (detailResponse.ok) {
610
+ const detailPayload = await response.json();
611
+ setSwap(detailPayload.swap);
612
+ setOrder(detailPayload.order || null);
613
+ }
614
+ } catch (updateErr) {
615
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to reject swap";
616
+ setUpdateError(message);
617
+ } finally {
618
+ setIsRejecting(false);
619
+ }
620
+ };
621
+ if (isLoading) {
622
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsx(Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading swap..." }) }) }) });
623
+ }
624
+ if (error || !swap) {
625
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsx(Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
626
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
627
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
628
+ ] }) }) });
629
+ }
630
+ const statusHistory = ((_a = swap.metadata) == null ? void 0 : _a.status_history) || [];
631
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
632
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
633
+ /* @__PURE__ */ jsxs(
634
+ Button,
635
+ {
636
+ variant: "transparent",
637
+ size: "small",
638
+ onClick: () => navigate("/swaps"),
639
+ className: "w-fit",
640
+ children: [
641
+ /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
642
+ "Back to list"
643
+ ]
644
+ }
645
+ ),
646
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
647
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
648
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Swap Details" }),
649
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
650
+ ] }),
651
+ /* @__PURE__ */ jsx(
652
+ Badge,
653
+ {
654
+ size: "small",
655
+ className: `uppercase ${getStatusBadgeClass$1(swap.status)}`,
656
+ children: swap.status.replace(/_/g, " ")
657
+ }
658
+ )
659
+ ] })
660
+ ] }),
661
+ swap.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "flex gap-3", children: [
662
+ /* @__PURE__ */ jsx(
663
+ Button,
664
+ {
665
+ variant: "primary",
666
+ onClick: handleApprove,
667
+ disabled: isApproving || isRejecting,
668
+ isLoading: isApproving,
669
+ children: "Approve Swap"
670
+ }
671
+ ),
672
+ /* @__PURE__ */ jsx(
673
+ Button,
674
+ {
675
+ variant: "secondary",
676
+ onClick: handleReject,
677
+ disabled: isApproving || isRejecting,
678
+ isLoading: isRejecting,
679
+ children: "Reject Swap"
680
+ }
681
+ )
682
+ ] }),
683
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
684
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Update Status" }),
685
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-end", children: [
686
+ /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
687
+ /* @__PURE__ */ jsx("label", { className: "mb-2 block text-sm font-medium text-ui-fg-base", children: "New Status" }),
688
+ /* @__PURE__ */ jsxs(
689
+ "select",
690
+ {
691
+ value: selectedStatus,
692
+ onChange: (event) => setSelectedStatus(event.target.value),
693
+ className: "h-9 w-full rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive",
694
+ children: [
695
+ /* @__PURE__ */ jsx("option", { value: "", children: "Select new status" }),
696
+ availableStatuses.filter((status) => status !== swap.status).map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
697
+ ]
698
+ }
699
+ )
700
+ ] }),
701
+ /* @__PURE__ */ jsx(
702
+ Button,
703
+ {
704
+ variant: "primary",
705
+ onClick: handleStatusUpdate,
706
+ disabled: !selectedStatus || isUpdating,
707
+ isLoading: isUpdating,
708
+ children: "Update Status"
709
+ }
710
+ )
711
+ ] }),
712
+ updateError && /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-error", children: updateError }),
713
+ updateSuccess && /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-success", children: "Status updated successfully" })
714
+ ] }),
715
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
716
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
717
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Swap Information" }),
718
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
719
+ /* @__PURE__ */ jsxs("div", { children: [
720
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Swap ID" }),
721
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.id })
722
+ ] }),
723
+ /* @__PURE__ */ jsxs("div", { children: [
724
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
725
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.status })
726
+ ] }),
727
+ /* @__PURE__ */ jsxs("div", { children: [
728
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
729
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
730
+ ] }),
731
+ swap.reason && /* @__PURE__ */ jsxs("div", { children: [
732
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
733
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.reason })
734
+ ] }),
735
+ swap.note && /* @__PURE__ */ jsxs("div", { children: [
736
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
737
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.note })
738
+ ] }),
739
+ /* @__PURE__ */ jsxs("div", { children: [
740
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
741
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
742
+ ] }),
743
+ /* @__PURE__ */ jsxs("div", { children: [
744
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
745
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
746
+ ] })
747
+ ] })
748
+ ] }),
749
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
750
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Status History" }),
751
+ statusHistory.length > 0 ? /* @__PURE__ */ jsx("div", { className: "space-y-2", children: statusHistory.map((entry, index) => /* @__PURE__ */ jsx(
752
+ "div",
753
+ {
754
+ className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
755
+ children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
756
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx(
757
+ Badge,
758
+ {
759
+ size: "2xsmall",
760
+ className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
761
+ children: entry.status.replace(/_/g, " ")
762
+ }
763
+ ) }),
764
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
765
+ new Date(entry.timestamp).toLocaleString(),
766
+ entry.admin_id && ` by ${entry.admin_id}`,
767
+ entry.reason && ` - ${entry.reason}`
768
+ ] })
769
+ ] })
770
+ },
771
+ index
772
+ )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
773
+ ] })
774
+ ] }),
775
+ order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
776
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
777
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
778
+ /* @__PURE__ */ jsxs("div", { children: [
779
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
780
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.id })
781
+ ] }),
782
+ /* @__PURE__ */ jsxs("div", { children: [
783
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
784
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.status || "—" })
785
+ ] }),
786
+ /* @__PURE__ */ jsxs("div", { children: [
787
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
788
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = order.customer) == null ? void 0 : _b.email) || order.email || "—" })
789
+ ] }),
790
+ order.total && /* @__PURE__ */ jsxs("div", { children: [
791
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
792
+ /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
793
+ order.currency_code || "$",
794
+ (Number(order.total) / 100).toFixed(2)
795
+ ] })
796
+ ] })
797
+ ] })
798
+ ] }),
799
+ swap.return_items && swap.return_items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
800
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
801
+ /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
802
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
803
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
804
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
805
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
806
+ ] }) }),
807
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
808
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
809
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
810
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
811
+ ] }, item.id || index)) })
812
+ ] }) })
813
+ ] }),
814
+ swap.new_items && swap.new_items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
815
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
816
+ /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
817
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
818
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
819
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
820
+ ] }) }),
821
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
822
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
823
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
824
+ ] }, item.variant_id || index)) })
825
+ ] }) })
826
+ ] })
827
+ ] }) });
828
+ };
829
+ const config$1 = defineRouteConfig({
830
+ label: "Swap Details",
831
+ icon: ArrowPath
832
+ });
220
833
  const getStatusBadgeClass = (status) => {
221
834
  const statusLower = status.toLowerCase();
222
835
  if (statusLower === "requested") {
@@ -534,10 +1147,18 @@ const i18nTranslations0 = {};
534
1147
  const widgetModule = { widgets: [] };
535
1148
  const routeModule = {
536
1149
  routes: [
1150
+ {
1151
+ Component: SwapsPage,
1152
+ path: "/swaps"
1153
+ },
537
1154
  {
538
1155
  Component: ReturnsPage,
539
1156
  path: "/returns"
540
1157
  },
1158
+ {
1159
+ Component: SwapDetailPage,
1160
+ path: "/swaps/:id"
1161
+ },
541
1162
  {
542
1163
  Component: ReturnDetailPage,
543
1164
  path: "/returns/:id"
@@ -547,16 +1168,28 @@ const routeModule = {
547
1168
  const menuItemModule = {
548
1169
  menuItems: [
549
1170
  {
550
- label: config$1.label,
551
- icon: config$1.icon,
1171
+ label: config$2.label,
1172
+ icon: config$2.icon,
552
1173
  path: "/returns",
553
1174
  nested: void 0
554
1175
  },
1176
+ {
1177
+ label: config$3.label,
1178
+ icon: config$3.icon,
1179
+ path: "/swaps",
1180
+ nested: void 0
1181
+ },
555
1182
  {
556
1183
  label: config.label,
557
1184
  icon: config.icon,
558
1185
  path: "/returns/:id",
559
1186
  nested: void 0
1187
+ },
1188
+ {
1189
+ label: config$1.label,
1190
+ icon: config$1.icon,
1191
+ path: "/swaps/:id",
1192
+ nested: void 0
560
1193
  }
561
1194
  ]
562
1195
  };