order-management 0.0.21 → 0.0.23

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 (36) hide show
  1. package/.medusa/server/src/admin/index.js +513 -484
  2. package/.medusa/server/src/admin/index.mjs +513 -484
  3. package/.medusa/server/src/api/admin/swaps/[id]/approve/route.js +81 -31
  4. package/.medusa/server/src/api/admin/swaps/[id]/confirm-exchange/route.js +109 -0
  5. package/.medusa/server/src/api/admin/swaps/health/route.js +150 -0
  6. package/.medusa/server/src/api/admin/swaps/route.js +6 -12
  7. package/.medusa/server/src/api/admin/swaps/validators.js +9 -13
  8. package/.medusa/server/src/api/store/orders/[order_id]/swaps/route.js +47 -2
  9. package/.medusa/server/src/api/store/swaps/[id]/cancel/route.js +8 -1
  10. package/.medusa/server/src/api/store/swaps/[id]/route.js +15 -4
  11. package/.medusa/server/src/api/store/swaps/route.js +53 -10
  12. package/.medusa/server/src/helpers/swaps.js +1 -1
  13. package/.medusa/server/src/modules/swap/migrations/Migration20260123144734.js +29 -0
  14. package/.medusa/server/src/modules/swap/migrations/Migration20260123162423.js +48 -0
  15. package/.medusa/server/src/modules/swap/migrations/Migration20260126114640.js +48 -0
  16. package/.medusa/server/src/modules/swap/models/swap.js +7 -2
  17. package/.medusa/server/src/modules/swap/service.js +259 -32
  18. package/.medusa/server/src/subscribers/exchange-created.js +207 -0
  19. package/.medusa/server/src/workflows/steps/swap/create-medusa-exchange-step.js +166 -20
  20. package/.medusa/server/src/workflows/steps/swap/create-medusa-return-step.js +76 -8
  21. package/.medusa/server/src/workflows/steps/swap/create-swap-step.js +7 -12
  22. package/.medusa/server/src/workflows/steps/swap/index.js +6 -4
  23. package/.medusa/server/src/workflows/steps/swap/rollback-return-step.js +70 -0
  24. package/.medusa/server/src/workflows/steps/swap/sync-medusa-status-step.js +49 -3
  25. package/.medusa/server/src/workflows/steps/swap/update-swap-exchange-details-step.js +27 -0
  26. package/.medusa/server/src/workflows/steps/swap/validate-eligibility-step.js +9 -4
  27. package/.medusa/server/src/workflows/steps/swap/validate-order-step.js +24 -1
  28. package/.medusa/server/src/workflows/swaps/approve-swap-workflow.js +23 -5
  29. package/.medusa/server/src/workflows/swaps/confirm-exchange-workflow.js +51 -0
  30. package/.medusa/server/src/workflows/swaps/create-swap-workflow.js +3 -1
  31. package/.medusa/server/src/workflows/swaps/execute-swap-workflow.js +26 -4
  32. package/package.json +1 -1
  33. package/.medusa/server/src/api/admin/swaps/[id]/process-payment/route.js +0 -152
  34. package/.medusa/server/src/api/admin/swaps/[id]/status/route.js +0 -45
  35. package/.medusa/server/src/api/admin/swaps/[id]/sync/route.js +0 -148
  36. package/.medusa/server/src/workflows/steps/swap/handle-payment-difference-step.js +0 -102
@@ -17,21 +17,21 @@ const getStatusBadgeClass$3 = (status) => {
17
17
  if (statusLower === "requested") {
18
18
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
19
19
  }
20
- if (statusLower === "received") {
20
+ if (statusLower === "approved") {
21
21
  return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
22
22
  }
23
- if (statusLower === "requires_action") {
23
+ if (statusLower === "rejected") {
24
24
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
25
25
  }
26
26
  if (statusLower === "completed") {
27
27
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
28
28
  }
29
- if (statusLower === "canceled") {
29
+ if (statusLower === "cancelled") {
30
30
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
31
31
  }
32
32
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
33
33
  };
34
- const ReturnsPage = () => {
34
+ const SwapsPage = () => {
35
35
  const navigate = useNavigate();
36
36
  const [items, setItems] = useState([]);
37
37
  const [statusFilter, setStatusFilter] = useState("all");
@@ -43,7 +43,7 @@ const ReturnsPage = () => {
43
43
  const [offset, setOffset] = useState(0);
44
44
  const [count, setCount] = useState(0);
45
45
  const limit = 50;
46
- const loadReturns = useCallback(
46
+ const loadSwaps = useCallback(
47
47
  async (nextOffset, replace = false) => {
48
48
  var _a;
49
49
  try {
@@ -60,25 +60,24 @@ const ReturnsPage = () => {
60
60
  params.set("status", statusFilter);
61
61
  }
62
62
  if (debouncedSearchQuery.trim()) {
63
- params.set("q", debouncedSearchQuery.trim());
63
+ params.set("order_id", debouncedSearchQuery.trim());
64
64
  }
65
- params.set("order", "created_at");
66
65
  const response = await fetch(
67
- `/admin/returns?${params.toString()}`,
66
+ `/admin/swaps?${params.toString()}`,
68
67
  { credentials: "include" }
69
68
  );
70
69
  if (!response.ok) {
71
70
  const message = await response.text();
72
- throw new Error(message || "Unable to load return orders");
71
+ throw new Error(message || "Unable to load swaps");
73
72
  }
74
73
  const payload = await response.json();
75
74
  setCount(payload.count ?? 0);
76
- setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
75
+ setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
77
76
  setItems(
78
- (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
77
+ (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
79
78
  );
80
79
  } catch (loadError) {
81
- const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
80
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
82
81
  setError(message);
83
82
  } finally {
84
83
  setIsLoading(false);
@@ -88,8 +87,8 @@ const ReturnsPage = () => {
88
87
  [statusFilter, debouncedSearchQuery]
89
88
  );
90
89
  useEffect(() => {
91
- void loadReturns(0, true);
92
- }, [statusFilter, debouncedSearchQuery, loadReturns]);
90
+ void loadSwaps(0, true);
91
+ }, [statusFilter, debouncedSearchQuery, loadSwaps]);
93
92
  const hasMore = useMemo(() => offset < count, [offset, count]);
94
93
  const availableStatuses = useMemo(() => {
95
94
  const statuses = /* @__PURE__ */ new Set();
@@ -99,16 +98,16 @@ const ReturnsPage = () => {
99
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: [
100
99
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
101
100
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
102
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Orders" }),
103
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
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" })
104
103
  ] }),
105
- /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
104
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
106
105
  ] }),
107
106
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
108
107
  /* @__PURE__ */ jsx(
109
108
  Input,
110
109
  {
111
- placeholder: "Search by return ID, order ID, or customer email",
110
+ placeholder: "Search by swap ID or order ID",
112
111
  value: searchQuery,
113
112
  onChange: (event) => setSearchQuery(event.target.value),
114
113
  className: "md:max-w-sm"
@@ -133,51 +132,50 @@ const ReturnsPage = () => {
133
132
  Button,
134
133
  {
135
134
  variant: "secondary",
136
- onClick: () => loadReturns(0, true),
135
+ onClick: () => loadSwaps(0, true),
137
136
  children: "Try again"
138
137
  }
139
138
  ) })
140
139
  ] }) : null,
141
- isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading return orders..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
142
- /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
143
- /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
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." })
144
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: [
145
144
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
146
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
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" }),
147
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" }),
148
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
149
147
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
150
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
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" }),
151
149
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
152
150
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
153
151
  ] }) }),
154
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxs(
152
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxs(
155
153
  "tr",
156
154
  {
157
155
  className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
158
- onClick: () => navigate(`/returns/${returnOrder.id}`),
156
+ onClick: () => navigate(`/swaps/${swap.id}`),
159
157
  children: [
160
- /* @__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: returnOrder.id }) }) }),
161
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
162
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
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 }),
163
160
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
164
161
  Badge,
165
162
  {
166
163
  size: "2xsmall",
167
- className: `uppercase ${getStatusBadgeClass$3(returnOrder.status)}`,
168
- children: returnOrder.status.replace(/_/g, " ")
164
+ className: `uppercase ${getStatusBadgeClass$3(swap.status)}`,
165
+ children: swap.status.replace(/_/g, " ")
169
166
  }
170
167
  ) }),
171
168
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
172
- const amount = returnOrder.refund_amount;
169
+ const amount = swap.difference_due;
173
170
  if (amount == null || amount === void 0) {
174
171
  return "—";
175
172
  }
176
173
  const displayAmount = Number(amount) / 100;
177
- const currency = returnOrder.currency_code || "$";
178
- return `${currency}${displayAmount.toFixed(2)}`;
174
+ const currency = swap.currency_code || "$";
175
+ const sign = displayAmount >= 0 ? "+" : "";
176
+ return `${sign}${currency}${displayAmount.toFixed(2)}`;
179
177
  })() }),
180
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
178
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
181
179
  year: "numeric",
182
180
  month: "short",
183
181
  day: "numeric",
@@ -192,14 +190,14 @@ const ReturnsPage = () => {
192
190
  size: "small",
193
191
  onClick: (e) => {
194
192
  e.stopPropagation();
195
- navigate(`/returns/${returnOrder.id}`);
193
+ navigate(`/swaps/${swap.id}`);
196
194
  },
197
195
  children: "View"
198
196
  }
199
197
  ) })
200
198
  ]
201
199
  },
202
- returnOrder.id
200
+ swap.id
203
201
  )) })
204
202
  ] }) }),
205
203
  hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
@@ -207,14 +205,14 @@ const ReturnsPage = () => {
207
205
  {
208
206
  variant: "secondary",
209
207
  isLoading: isFetchingMore,
210
- onClick: () => loadReturns(offset, false),
208
+ onClick: () => loadSwaps(offset, false),
211
209
  children: "Load more"
212
210
  }
213
211
  ) }) : null
214
212
  ] }) });
215
213
  };
216
214
  const config$3 = defineRouteConfig({
217
- label: "Return Orders",
215
+ label: "Swaps",
218
216
  icon: ArrowPath
219
217
  });
220
218
  const useDebounce = (value, delay) => {
@@ -230,21 +228,21 @@ const getStatusBadgeClass$2 = (status) => {
230
228
  if (statusLower === "requested") {
231
229
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
232
230
  }
233
- if (statusLower === "approved") {
231
+ if (statusLower === "received") {
234
232
  return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
235
233
  }
236
- if (statusLower === "rejected") {
234
+ if (statusLower === "requires_action") {
237
235
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
238
236
  }
239
237
  if (statusLower === "completed") {
240
238
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
241
239
  }
242
- if (statusLower === "cancelled") {
240
+ if (statusLower === "canceled") {
243
241
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
244
242
  }
245
243
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
246
244
  };
247
- const SwapsPage = () => {
245
+ const ReturnsPage = () => {
248
246
  const navigate = useNavigate();
249
247
  const [items, setItems] = useState([]);
250
248
  const [statusFilter, setStatusFilter] = useState("all");
@@ -256,7 +254,7 @@ const SwapsPage = () => {
256
254
  const [offset, setOffset] = useState(0);
257
255
  const [count, setCount] = useState(0);
258
256
  const limit = 50;
259
- const loadSwaps = useCallback(
257
+ const loadReturns = useCallback(
260
258
  async (nextOffset, replace = false) => {
261
259
  var _a;
262
260
  try {
@@ -273,24 +271,25 @@ const SwapsPage = () => {
273
271
  params.set("status", statusFilter);
274
272
  }
275
273
  if (debouncedSearchQuery.trim()) {
276
- params.set("order_id", debouncedSearchQuery.trim());
274
+ params.set("q", debouncedSearchQuery.trim());
277
275
  }
276
+ params.set("order", "created_at");
278
277
  const response = await fetch(
279
- `/admin/swaps?${params.toString()}`,
278
+ `/admin/returns?${params.toString()}`,
280
279
  { credentials: "include" }
281
280
  );
282
281
  if (!response.ok) {
283
282
  const message = await response.text();
284
- throw new Error(message || "Unable to load swaps");
283
+ throw new Error(message || "Unable to load return orders");
285
284
  }
286
285
  const payload = await response.json();
287
286
  setCount(payload.count ?? 0);
288
- setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
287
+ setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
289
288
  setItems(
290
- (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
289
+ (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
291
290
  );
292
291
  } catch (loadError) {
293
- const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
292
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
294
293
  setError(message);
295
294
  } finally {
296
295
  setIsLoading(false);
@@ -300,8 +299,8 @@ const SwapsPage = () => {
300
299
  [statusFilter, debouncedSearchQuery]
301
300
  );
302
301
  useEffect(() => {
303
- void loadSwaps(0, true);
304
- }, [statusFilter, debouncedSearchQuery, loadSwaps]);
302
+ void loadReturns(0, true);
303
+ }, [statusFilter, debouncedSearchQuery, loadReturns]);
305
304
  const hasMore = useMemo(() => offset < count, [offset, count]);
306
305
  const availableStatuses = useMemo(() => {
307
306
  const statuses = /* @__PURE__ */ new Set();
@@ -311,16 +310,16 @@ const SwapsPage = () => {
311
310
  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: [
312
311
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
313
312
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
314
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Swaps" }),
315
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer swap requests" })
313
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Orders" }),
314
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
316
315
  ] }),
317
- /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
316
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
318
317
  ] }),
319
318
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
320
319
  /* @__PURE__ */ jsx(
321
320
  Input,
322
321
  {
323
- placeholder: "Search by swap ID or order ID",
322
+ placeholder: "Search by return ID, order ID, or customer email",
324
323
  value: searchQuery,
325
324
  onChange: (event) => setSearchQuery(event.target.value),
326
325
  className: "md:max-w-sm"
@@ -345,50 +344,51 @@ const SwapsPage = () => {
345
344
  Button,
346
345
  {
347
346
  variant: "secondary",
348
- onClick: () => loadSwaps(0, true),
347
+ onClick: () => loadReturns(0, true),
349
348
  children: "Try again"
350
349
  }
351
350
  ) })
352
351
  ] }) : null,
353
- 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: [
354
- /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No swaps yet" }),
355
- /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Swap requests created by customers will appear here." })
352
+ isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading return orders..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
353
+ /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
354
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
356
355
  ] }) : /* @__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: [
357
356
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
358
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Swap ID" }),
357
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
359
358
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
359
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
360
360
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
361
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Difference Due" }),
361
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
362
362
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
363
363
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
364
364
  ] }) }),
365
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxs(
365
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxs(
366
366
  "tr",
367
367
  {
368
368
  className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
369
- onClick: () => navigate(`/swaps/${swap.id}`),
369
+ onClick: () => navigate(`/returns/${returnOrder.id}`),
370
370
  children: [
371
- /* @__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 }) }) }),
372
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: swap.order_id }),
371
+ /* @__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: returnOrder.id }) }) }),
372
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
373
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
373
374
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
374
375
  Badge,
375
376
  {
376
377
  size: "2xsmall",
377
- className: `uppercase ${getStatusBadgeClass$2(swap.status)}`,
378
- children: swap.status.replace(/_/g, " ")
378
+ className: `uppercase ${getStatusBadgeClass$2(returnOrder.status)}`,
379
+ children: returnOrder.status.replace(/_/g, " ")
379
380
  }
380
381
  ) }),
381
382
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
382
- const amount = swap.difference_due;
383
+ const amount = returnOrder.refund_amount;
383
384
  if (amount == null || amount === void 0) {
384
385
  return "—";
385
386
  }
386
387
  const displayAmount = Number(amount) / 100;
387
- const currency = swap.currency_code || "$";
388
- const sign = displayAmount >= 0 ? "+" : "";
389
- return `${sign}${currency}${displayAmount.toFixed(2)}`;
388
+ const currency = returnOrder.currency_code || "$";
389
+ return `${currency}${displayAmount.toFixed(2)}`;
390
390
  })() }),
391
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
391
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
392
392
  year: "numeric",
393
393
  month: "short",
394
394
  day: "numeric",
@@ -403,14 +403,14 @@ const SwapsPage = () => {
403
403
  size: "small",
404
404
  onClick: (e) => {
405
405
  e.stopPropagation();
406
- navigate(`/swaps/${swap.id}`);
406
+ navigate(`/returns/${returnOrder.id}`);
407
407
  },
408
408
  children: "View"
409
409
  }
410
410
  ) })
411
411
  ]
412
412
  },
413
- swap.id
413
+ returnOrder.id
414
414
  )) })
415
415
  ] }) }),
416
416
  hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
@@ -418,14 +418,14 @@ const SwapsPage = () => {
418
418
  {
419
419
  variant: "secondary",
420
420
  isLoading: isFetchingMore,
421
- onClick: () => loadSwaps(offset, false),
421
+ onClick: () => loadReturns(offset, false),
422
422
  children: "Load more"
423
423
  }
424
424
  ) }) : null
425
425
  ] }) });
426
426
  };
427
427
  const config$2 = defineRouteConfig({
428
- label: "Swaps",
428
+ label: "Return Orders",
429
429
  icon: ArrowPath
430
430
  });
431
431
  const getStatusBadgeClass$1 = (status) => {
@@ -433,65 +433,63 @@ const getStatusBadgeClass$1 = (status) => {
433
433
  if (statusLower === "requested") {
434
434
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
435
435
  }
436
- if (statusLower === "received") {
436
+ if (statusLower === "approved") {
437
437
  return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
438
438
  }
439
- if (statusLower === "requires_action") {
439
+ if (statusLower === "rejected") {
440
440
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
441
441
  }
442
442
  if (statusLower === "completed") {
443
443
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
444
444
  }
445
- if (statusLower === "canceled") {
445
+ if (statusLower === "cancelled") {
446
446
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
447
447
  }
448
448
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
449
449
  };
450
- const ReturnDetailPage = () => {
451
- var _a, _b, _c;
450
+ const SwapDetailPage = () => {
451
+ var _a, _b;
452
452
  const navigate = useNavigate();
453
453
  const { id } = useParams();
454
- const [returnOrder, setReturnOrder] = useState(null);
454
+ const [swap, setSwap] = useState(null);
455
+ const [order, setOrder] = useState(null);
455
456
  const [selectedStatus, setSelectedStatus] = useState("");
456
457
  const [isLoading, setIsLoading] = useState(true);
457
458
  const [isUpdating, setIsUpdating] = useState(false);
459
+ const [isApproving, setIsApproving] = useState(false);
460
+ const [isRejecting, setIsRejecting] = useState(false);
458
461
  const [error, setError] = useState(null);
459
462
  const [updateError, setUpdateError] = useState(null);
460
463
  const [updateSuccess, setUpdateSuccess] = useState(false);
461
- const availableStatuses = [
462
- "requested",
463
- "received",
464
- "requires_action",
465
- "completed",
466
- "canceled"
467
- ];
464
+ const availableStatuses = ["requested", "approved", "rejected"];
468
465
  useEffect(() => {
469
466
  if (!id) {
470
- navigate("/returns");
467
+ navigate("/swaps");
471
468
  return;
472
469
  }
473
- const loadReturn = async () => {
470
+ const loadSwap = async () => {
474
471
  try {
475
472
  setIsLoading(true);
476
473
  setError(null);
477
- const response = await fetch(`/admin/returns/${id}`, {
474
+ const response = await fetch(`/admin/swaps/${id}`, {
478
475
  credentials: "include"
479
476
  });
480
477
  if (!response.ok) {
481
478
  const message = await response.text();
482
- throw new Error(message || "Unable to load return order");
479
+ throw new Error(message || "Unable to load swap");
483
480
  }
484
481
  const payload = await response.json();
485
- setReturnOrder(payload.return);
482
+ setSwap(payload.swap);
483
+ setOrder(payload.order || null);
486
484
  setSelectedStatus("");
487
485
  } catch (loadError) {
488
- const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
486
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
489
487
  setError(message);
490
488
  } finally {
491
489
  setIsLoading(false);
492
490
  }
493
491
  };
494
- void loadReturn();
492
+ void loadSwap();
495
493
  }, [id, navigate]);
496
494
  const handleStatusUpdate = async () => {
497
495
  if (!id || !selectedStatus) {
@@ -501,7 +499,7 @@ const ReturnDetailPage = () => {
501
499
  setIsUpdating(true);
502
500
  setUpdateError(null);
503
501
  setUpdateSuccess(false);
504
- const response = await fetch(`/admin/returns/${id}/status`, {
502
+ const response = await fetch(`/admin/swaps/${id}/status`, {
505
503
  method: "POST",
506
504
  headers: {
507
505
  "Content-Type": "application/json"
@@ -514,16 +512,17 @@ const ReturnDetailPage = () => {
514
512
  throw new Error(message || "Unable to update status");
515
513
  }
516
514
  const payload = await response.json();
517
- setReturnOrder(payload.return);
515
+ setSwap(payload.swap);
518
516
  setSelectedStatus("");
519
517
  setUpdateSuccess(true);
520
518
  setTimeout(() => setUpdateSuccess(false), 3e3);
521
- const detailResponse = await fetch(`/admin/returns/${id}`, {
519
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
522
520
  credentials: "include"
523
521
  });
524
522
  if (detailResponse.ok) {
525
523
  const detailPayload = await detailResponse.json();
526
- setReturnOrder(detailPayload.return);
524
+ setSwap(detailPayload.swap);
525
+ setOrder(detailPayload.order || null);
527
526
  }
528
527
  } catch (updateErr) {
529
528
  const message = updateErr instanceof Error ? updateErr.message : "Unable to update status";
@@ -532,65 +531,167 @@ const ReturnDetailPage = () => {
532
531
  setIsUpdating(false);
533
532
  }
534
533
  };
535
- if (isLoading) {
536
- 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 return order..." }) }) }) });
537
- }
538
- if (error || !returnOrder) {
539
- 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: [
540
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
541
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
542
- ] }) }) });
543
- }
544
- const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
545
- 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: [
546
- /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
547
- /* @__PURE__ */ jsxs(
548
- Button,
549
- {
550
- variant: "transparent",
551
- size: "small",
552
- onClick: () => navigate("/returns"),
553
- className: "w-fit",
554
- children: [
555
- /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
556
- "Back to list"
557
- ]
558
- }
559
- ),
560
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
561
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
562
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Order Details" }),
563
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
564
- ] }),
565
- /* @__PURE__ */ jsx(
566
- Badge,
567
- {
568
- size: "small",
569
- className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
570
- children: returnOrder.status.replace("_", " ")
571
- }
572
- )
573
- ] })
574
- ] }),
575
- /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
576
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Update Status" }),
577
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-end", children: [
578
- /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
579
- /* @__PURE__ */ jsx("label", { className: "mb-2 block text-sm font-medium text-ui-fg-base", children: "New Status" }),
580
- /* @__PURE__ */ jsxs(
581
- "select",
582
- {
583
- value: selectedStatus,
584
- onChange: (event) => setSelectedStatus(event.target.value),
585
- 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",
586
- children: [
587
- /* @__PURE__ */ jsx("option", { value: "", children: "Select new status" }),
588
- availableStatuses.filter((status) => status !== returnOrder.status).map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace("_", " ").toUpperCase() }, status))
589
- ]
590
- }
591
- )
592
- ] }),
593
- /* @__PURE__ */ jsx(
534
+ const handleApprove = async () => {
535
+ if (!id) {
536
+ return;
537
+ }
538
+ try {
539
+ setIsApproving(true);
540
+ setUpdateError(null);
541
+ setUpdateSuccess(false);
542
+ const response = await fetch(`/admin/swaps/${id}/approve`, {
543
+ method: "POST",
544
+ headers: {
545
+ "Content-Type": "application/json"
546
+ },
547
+ credentials: "include"
548
+ });
549
+ if (!response.ok) {
550
+ const message = await response.text();
551
+ throw new Error(message || "Unable to approve swap");
552
+ }
553
+ const payload = await response.json();
554
+ setSwap(payload.swap);
555
+ setUpdateSuccess(true);
556
+ setTimeout(() => setUpdateSuccess(false), 5e3);
557
+ if (payload.show_exchange_form && payload.order_id) {
558
+ window.open(`/app/orders/${payload.order_id}/exchanges?swap_id=${id}`, "_blank");
559
+ }
560
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
561
+ credentials: "include"
562
+ });
563
+ if (detailResponse.ok) {
564
+ const detailPayload = await detailResponse.json();
565
+ setSwap(detailPayload.swap);
566
+ setOrder(detailPayload.order || null);
567
+ }
568
+ } catch (updateErr) {
569
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to approve swap";
570
+ setUpdateError(message);
571
+ } finally {
572
+ setIsApproving(false);
573
+ }
574
+ };
575
+ const handleReject = async () => {
576
+ if (!id) {
577
+ return;
578
+ }
579
+ try {
580
+ setIsRejecting(true);
581
+ setUpdateError(null);
582
+ setUpdateSuccess(false);
583
+ const response = await fetch(`/admin/swaps/${id}/reject`, {
584
+ method: "POST",
585
+ headers: {
586
+ "Content-Type": "application/json"
587
+ },
588
+ credentials: "include",
589
+ body: JSON.stringify({ reason: "Rejected by admin" })
590
+ });
591
+ if (!response.ok) {
592
+ const message = await response.text();
593
+ throw new Error(message || "Unable to reject swap");
594
+ }
595
+ const payload = await response.json();
596
+ setSwap(payload.swap);
597
+ setUpdateSuccess(true);
598
+ setTimeout(() => setUpdateSuccess(false), 3e3);
599
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
600
+ credentials: "include"
601
+ });
602
+ if (detailResponse.ok) {
603
+ const detailPayload = await response.json();
604
+ setSwap(detailPayload.swap);
605
+ setOrder(detailPayload.order || null);
606
+ }
607
+ } catch (updateErr) {
608
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to reject swap";
609
+ setUpdateError(message);
610
+ } finally {
611
+ setIsRejecting(false);
612
+ }
613
+ };
614
+ if (isLoading) {
615
+ 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..." }) }) }) });
616
+ }
617
+ if (error || !swap) {
618
+ 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: [
619
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
620
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
621
+ ] }) }) });
622
+ }
623
+ const statusHistory = ((_a = swap.metadata) == null ? void 0 : _a.status_history) || [];
624
+ 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: [
625
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
626
+ /* @__PURE__ */ jsxs(
627
+ Button,
628
+ {
629
+ variant: "transparent",
630
+ size: "small",
631
+ onClick: () => navigate("/swaps"),
632
+ className: "w-fit",
633
+ children: [
634
+ /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
635
+ "Back to list"
636
+ ]
637
+ }
638
+ ),
639
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
640
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
641
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Swap Details" }),
642
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
643
+ ] }),
644
+ /* @__PURE__ */ jsx(
645
+ Badge,
646
+ {
647
+ size: "small",
648
+ className: `uppercase ${getStatusBadgeClass$1(swap.status)}`,
649
+ children: swap.status.replace(/_/g, " ")
650
+ }
651
+ )
652
+ ] })
653
+ ] }),
654
+ swap.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "flex gap-3", children: [
655
+ /* @__PURE__ */ jsx(
656
+ Button,
657
+ {
658
+ variant: "primary",
659
+ onClick: handleApprove,
660
+ disabled: isApproving || isRejecting,
661
+ isLoading: isApproving,
662
+ children: "Approve Swap"
663
+ }
664
+ ),
665
+ /* @__PURE__ */ jsx(
666
+ Button,
667
+ {
668
+ variant: "secondary",
669
+ onClick: handleReject,
670
+ disabled: isApproving || isRejecting,
671
+ isLoading: isRejecting,
672
+ children: "Reject Swap"
673
+ }
674
+ )
675
+ ] }),
676
+ swap.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
677
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Update Status" }),
678
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-end", children: [
679
+ /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
680
+ /* @__PURE__ */ jsx("label", { className: "mb-2 block text-sm font-medium text-ui-fg-base", children: "New Status" }),
681
+ /* @__PURE__ */ jsxs(
682
+ "select",
683
+ {
684
+ value: selectedStatus,
685
+ onChange: (event) => setSelectedStatus(event.target.value),
686
+ 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",
687
+ children: [
688
+ /* @__PURE__ */ jsx("option", { value: "", children: "Select new status" }),
689
+ availableStatuses.filter((status) => status !== swap.status).map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
690
+ ]
691
+ }
692
+ )
693
+ ] }),
694
+ /* @__PURE__ */ jsx(
594
695
  Button,
595
696
  {
596
697
  variant: "primary",
@@ -604,37 +705,73 @@ const ReturnDetailPage = () => {
604
705
  updateError && /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-error", children: updateError }),
605
706
  updateSuccess && /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-success", children: "Status updated successfully" })
606
707
  ] }),
708
+ swap.status === "approved" && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
709
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
710
+ swap.exchange_id ? /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
711
+ /* @__PURE__ */ jsxs("div", { children: [
712
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
713
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.exchange_id })
714
+ ] }),
715
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
716
+ Button,
717
+ {
718
+ variant: "secondary",
719
+ onClick: () => {
720
+ window.open(`/app/orders/${swap.order_id}/exchanges/${swap.exchange_id}`, "_blank");
721
+ },
722
+ children: "View Exchange"
723
+ }
724
+ ) })
725
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
726
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Swap approved. Please create the exchange using Medusa's exchange creation form." }),
727
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
728
+ Button,
729
+ {
730
+ variant: "primary",
731
+ onClick: () => {
732
+ window.open(`/app/orders/${swap.order_id}/exchanges`, "_blank");
733
+ },
734
+ children: "Create Exchange"
735
+ }
736
+ ) }),
737
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "The exchange will be automatically linked to this swap once created." })
738
+ ] })
739
+ ] }),
607
740
  /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
608
741
  /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
609
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
742
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Swap Information" }),
610
743
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
611
744
  /* @__PURE__ */ jsxs("div", { children: [
612
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
613
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
745
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Swap ID" }),
746
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.id })
614
747
  ] }),
615
748
  /* @__PURE__ */ jsxs("div", { children: [
616
749
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
617
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.status })
750
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.status })
618
751
  ] }),
619
752
  /* @__PURE__ */ jsxs("div", { children: [
620
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Refund Amount" }),
621
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.refund_amount ? `${((_b = returnOrder.order) == null ? void 0 : _b.currency_code) || "$"}${Number(returnOrder.refund_amount).toFixed(2)}` : "—" })
753
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
754
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
622
755
  ] }),
623
- returnOrder.reason && /* @__PURE__ */ jsxs("div", { children: [
756
+ swap.reason && /* @__PURE__ */ jsxs("div", { children: [
624
757
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
625
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.reason })
758
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.reason })
626
759
  ] }),
627
- returnOrder.note && /* @__PURE__ */ jsxs("div", { children: [
760
+ swap.note && /* @__PURE__ */ jsxs("div", { children: [
628
761
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
629
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.note })
762
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.note })
630
763
  ] }),
631
764
  /* @__PURE__ */ jsxs("div", { children: [
632
765
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
633
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
766
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
634
767
  ] }),
635
768
  /* @__PURE__ */ jsxs("div", { children: [
636
769
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
637
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
770
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
771
+ ] }),
772
+ swap.exchange_id && /* @__PURE__ */ jsxs("div", { children: [
773
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
774
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.exchange_id })
638
775
  ] })
639
776
  ] })
640
777
  ] }),
@@ -645,23 +782,18 @@ const ReturnDetailPage = () => {
645
782
  {
646
783
  className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
647
784
  children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
648
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
649
- /* @__PURE__ */ jsx(
650
- Badge,
651
- {
652
- size: "2xsmall",
653
- className: `uppercase ${getStatusBadgeClass$1(entry.to)}`,
654
- children: entry.to.replace("_", " ")
655
- }
656
- ),
657
- entry.from && /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
658
- "from ",
659
- entry.from.replace("_", " ")
660
- ] })
661
- ] }),
785
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx(
786
+ Badge,
787
+ {
788
+ size: "2xsmall",
789
+ className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
790
+ children: entry.status.replace(/_/g, " ")
791
+ }
792
+ ) }),
662
793
  /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
663
- new Date(entry.changed_at).toLocaleString(),
664
- entry.changed_by && ` by ${entry.changed_by}`
794
+ new Date(entry.timestamp).toLocaleString(),
795
+ entry.admin_id && ` by ${entry.admin_id}`,
796
+ entry.reason && ` - ${entry.reason}`
665
797
  ] })
666
798
  ] })
667
799
  },
@@ -669,76 +801,62 @@ const ReturnDetailPage = () => {
669
801
  )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
670
802
  ] })
671
803
  ] }),
672
- returnOrder.order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
804
+ order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
673
805
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
674
- /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
675
- /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
676
- /* @__PURE__ */ jsxs("div", { children: [
677
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
678
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.id })
679
- ] }),
680
- /* @__PURE__ */ jsxs("div", { children: [
681
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
682
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.status || "—" })
683
- ] }),
684
- /* @__PURE__ */ jsxs("div", { children: [
685
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
686
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_c = returnOrder.order.customer) == null ? void 0 : _c.email) || returnOrder.order.email || "—" })
687
- ] }),
688
- /* @__PURE__ */ jsxs("div", { children: [
689
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
690
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.total ? `${returnOrder.order.currency_code || "$"}${Number(returnOrder.order.total).toFixed(2)}` : "—" })
691
- ] })
806
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
807
+ /* @__PURE__ */ jsxs("div", { children: [
808
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
809
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.id })
692
810
  ] }),
693
- /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
694
- /* @__PURE__ */ jsxs("div", { children: [
695
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Subtotal" }),
696
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.subtotal ? `${returnOrder.order.currency_code || "$"}${Number(returnOrder.order.subtotal).toFixed(2)}` : "—" })
697
- ] }),
698
- /* @__PURE__ */ jsxs("div", { children: [
699
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Tax Total" }),
700
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.tax_total ? `${returnOrder.order.currency_code || "$"}${Number(returnOrder.order.tax_total).toFixed(2)}` : "—" })
701
- ] }),
702
- /* @__PURE__ */ jsxs("div", { children: [
703
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Shipping Total" }),
704
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.shipping_total ? `${returnOrder.order.currency_code || "$"}${Number(returnOrder.order.shipping_total).toFixed(2)}` : "—" })
705
- ] }),
706
- /* @__PURE__ */ jsxs("div", { children: [
707
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Created" }),
708
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.created_at ? new Date(returnOrder.order.created_at).toLocaleString() : "—" })
811
+ /* @__PURE__ */ jsxs("div", { children: [
812
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
813
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.status || "" })
814
+ ] }),
815
+ /* @__PURE__ */ jsxs("div", { children: [
816
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
817
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = order.customer) == null ? void 0 : _b.email) || order.email || "—" })
818
+ ] }),
819
+ order.total && /* @__PURE__ */ jsxs("div", { children: [
820
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
821
+ /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
822
+ order.currency_code || "$",
823
+ (Number(order.total) / 100).toFixed(2)
709
824
  ] })
710
825
  ] })
711
826
  ] })
712
827
  ] }),
713
- returnOrder.items && returnOrder.items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
828
+ 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: [
714
829
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
715
830
  /* @__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: [
716
831
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
717
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item" }),
718
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
832
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
833
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
834
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
719
835
  ] }) }),
720
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.items.map((item) => {
721
- var _a2, _b2;
722
- return /* @__PURE__ */ jsxs("tr", { children: [
723
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: ((_a2 = item.item) == null ? void 0 : _a2.title) || ((_b2 = item.item) == null ? void 0 : _b2.id) || item.id }),
724
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
725
- ] }, item.id);
726
- }) })
836
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
837
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
838
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
839
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
840
+ ] }, item.id || index)) })
727
841
  ] }) })
728
842
  ] }),
729
- returnOrder.metadata && Object.keys(returnOrder.metadata).filter(
730
- (key) => key !== "status_history"
731
- ).length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
732
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Metadata" }),
733
- /* @__PURE__ */ jsx("div", { className: "space-y-2", children: Object.entries(returnOrder.metadata).filter(([key]) => key !== "status_history").map(([key, value]) => /* @__PURE__ */ jsxs("div", { className: "flex justify-between", children: [
734
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: key }),
735
- /* @__PURE__ */ jsx(Text, { size: "small", className: "font-medium", children: typeof value === "string" ? value : JSON.stringify(value) })
736
- ] }, key)) })
843
+ 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: [
844
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
845
+ /* @__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: [
846
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
847
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
848
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
849
+ ] }) }),
850
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
851
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
852
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
853
+ ] }, item.variant_id || index)) })
854
+ ] }) })
737
855
  ] })
738
856
  ] }) });
739
857
  };
740
858
  const config$1 = defineRouteConfig({
741
- label: "Return Order Details",
859
+ label: "Swap Details",
742
860
  icon: ArrowPath
743
861
  });
744
862
  const getStatusBadgeClass = (status) => {
@@ -746,201 +864,115 @@ const getStatusBadgeClass = (status) => {
746
864
  if (statusLower === "requested") {
747
865
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
748
866
  }
749
- if (statusLower === "approved") {
867
+ if (statusLower === "received") {
750
868
  return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
751
869
  }
752
- if (statusLower === "rejected") {
870
+ if (statusLower === "requires_action") {
753
871
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
754
872
  }
755
873
  if (statusLower === "completed") {
756
874
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
757
875
  }
758
- if (statusLower === "cancelled") {
876
+ if (statusLower === "canceled") {
759
877
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
760
878
  }
761
879
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
762
880
  };
763
- const SwapDetailPage = () => {
764
- var _a, _b;
881
+ const ReturnDetailPage = () => {
882
+ var _a, _b, _c;
765
883
  const navigate = useNavigate();
766
884
  const { id } = useParams();
767
- const [swap, setSwap] = useState(null);
768
- const [order, setOrder] = useState(null);
885
+ const [returnOrder, setReturnOrder] = useState(null);
769
886
  const [selectedStatus, setSelectedStatus] = useState("");
770
887
  const [isLoading, setIsLoading] = useState(true);
771
888
  const [isUpdating, setIsUpdating] = useState(false);
772
- const [isApproving, setIsApproving] = useState(false);
773
- const [isRejecting, setIsRejecting] = useState(false);
774
889
  const [error, setError] = useState(null);
775
890
  const [updateError, setUpdateError] = useState(null);
776
891
  const [updateSuccess, setUpdateSuccess] = useState(false);
777
892
  const availableStatuses = [
778
893
  "requested",
779
- "approved",
780
- "rejected",
781
- "return_started",
782
- "return_shipped",
783
- "return_received",
784
- "new_items_shipped",
894
+ "received",
895
+ "requires_action",
785
896
  "completed",
786
- "cancelled"
897
+ "canceled"
787
898
  ];
788
- useEffect(() => {
789
- if (!id) {
790
- navigate("/swaps");
791
- return;
792
- }
793
- const loadSwap = async () => {
794
- try {
795
- setIsLoading(true);
796
- setError(null);
797
- const response = await fetch(`/admin/swaps/${id}`, {
798
- credentials: "include"
799
- });
800
- if (!response.ok) {
801
- const message = await response.text();
802
- throw new Error(message || "Unable to load swap");
803
- }
804
- const payload = await response.json();
805
- setSwap(payload.swap);
806
- setOrder(payload.order || null);
807
- setSelectedStatus("");
808
- } catch (loadError) {
809
- const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
810
- setError(message);
811
- } finally {
812
- setIsLoading(false);
813
- }
814
- };
815
- void loadSwap();
816
- }, [id, navigate]);
817
- const handleStatusUpdate = async () => {
818
- if (!id || !selectedStatus) {
819
- return;
820
- }
821
- try {
822
- setIsUpdating(true);
823
- setUpdateError(null);
824
- setUpdateSuccess(false);
825
- const response = await fetch(`/admin/swaps/${id}/status`, {
826
- method: "POST",
827
- headers: {
828
- "Content-Type": "application/json"
829
- },
830
- credentials: "include",
831
- body: JSON.stringify({ status: selectedStatus })
832
- });
833
- if (!response.ok) {
834
- const message = await response.text();
835
- throw new Error(message || "Unable to update status");
836
- }
837
- const payload = await response.json();
838
- setSwap(payload.swap);
839
- setSelectedStatus("");
840
- setUpdateSuccess(true);
841
- setTimeout(() => setUpdateSuccess(false), 3e3);
842
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
843
- credentials: "include"
844
- });
845
- if (detailResponse.ok) {
846
- const detailPayload = await detailResponse.json();
847
- setSwap(detailPayload.swap);
848
- setOrder(detailPayload.order || null);
849
- }
850
- } catch (updateErr) {
851
- const message = updateErr instanceof Error ? updateErr.message : "Unable to update status";
852
- setUpdateError(message);
853
- } finally {
854
- setIsUpdating(false);
855
- }
856
- };
857
- const handleApprove = async () => {
858
- if (!id) {
859
- return;
860
- }
861
- try {
862
- setIsApproving(true);
863
- setUpdateError(null);
864
- setUpdateSuccess(false);
865
- const response = await fetch(`/admin/swaps/${id}/approve`, {
866
- method: "POST",
867
- headers: {
868
- "Content-Type": "application/json"
869
- },
870
- credentials: "include"
871
- });
872
- if (!response.ok) {
873
- const message = await response.text();
874
- throw new Error(message || "Unable to approve swap");
875
- }
876
- const payload = await response.json();
877
- setSwap(payload.swap);
878
- setUpdateSuccess(true);
879
- setTimeout(() => setUpdateSuccess(false), 3e3);
880
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
881
- credentials: "include"
882
- });
883
- if (detailResponse.ok) {
884
- const detailPayload = await response.json();
885
- setSwap(detailPayload.swap);
886
- setOrder(detailPayload.order || null);
887
- }
888
- } catch (updateErr) {
889
- const message = updateErr instanceof Error ? updateErr.message : "Unable to approve swap";
890
- setUpdateError(message);
891
- } finally {
892
- setIsApproving(false);
893
- }
894
- };
895
- const handleReject = async () => {
899
+ useEffect(() => {
896
900
  if (!id) {
901
+ navigate("/returns");
902
+ return;
903
+ }
904
+ const loadReturn = async () => {
905
+ try {
906
+ setIsLoading(true);
907
+ setError(null);
908
+ const response = await fetch(`/admin/returns/${id}`, {
909
+ credentials: "include"
910
+ });
911
+ if (!response.ok) {
912
+ const message = await response.text();
913
+ throw new Error(message || "Unable to load return order");
914
+ }
915
+ const payload = await response.json();
916
+ setReturnOrder(payload.return);
917
+ setSelectedStatus("");
918
+ } catch (loadError) {
919
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
920
+ setError(message);
921
+ } finally {
922
+ setIsLoading(false);
923
+ }
924
+ };
925
+ void loadReturn();
926
+ }, [id, navigate]);
927
+ const handleStatusUpdate = async () => {
928
+ if (!id || !selectedStatus) {
897
929
  return;
898
930
  }
899
931
  try {
900
- setIsRejecting(true);
932
+ setIsUpdating(true);
901
933
  setUpdateError(null);
902
934
  setUpdateSuccess(false);
903
- const response = await fetch(`/admin/swaps/${id}/reject`, {
935
+ const response = await fetch(`/admin/returns/${id}/status`, {
904
936
  method: "POST",
905
937
  headers: {
906
938
  "Content-Type": "application/json"
907
939
  },
908
940
  credentials: "include",
909
- body: JSON.stringify({ reason: "Rejected by admin" })
941
+ body: JSON.stringify({ status: selectedStatus })
910
942
  });
911
943
  if (!response.ok) {
912
944
  const message = await response.text();
913
- throw new Error(message || "Unable to reject swap");
945
+ throw new Error(message || "Unable to update status");
914
946
  }
915
947
  const payload = await response.json();
916
- setSwap(payload.swap);
948
+ setReturnOrder(payload.return);
949
+ setSelectedStatus("");
917
950
  setUpdateSuccess(true);
918
951
  setTimeout(() => setUpdateSuccess(false), 3e3);
919
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
952
+ const detailResponse = await fetch(`/admin/returns/${id}`, {
920
953
  credentials: "include"
921
954
  });
922
955
  if (detailResponse.ok) {
923
- const detailPayload = await response.json();
924
- setSwap(detailPayload.swap);
925
- setOrder(detailPayload.order || null);
956
+ const detailPayload = await detailResponse.json();
957
+ setReturnOrder(detailPayload.return);
926
958
  }
927
959
  } catch (updateErr) {
928
- const message = updateErr instanceof Error ? updateErr.message : "Unable to reject swap";
960
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to update status";
929
961
  setUpdateError(message);
930
962
  } finally {
931
- setIsRejecting(false);
963
+ setIsUpdating(false);
932
964
  }
933
965
  };
934
966
  if (isLoading) {
935
- 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..." }) }) }) });
967
+ 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 return order..." }) }) }) });
936
968
  }
937
- if (error || !swap) {
969
+ if (error || !returnOrder) {
938
970
  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: [
939
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
940
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
971
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
972
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
941
973
  ] }) }) });
942
974
  }
943
- const statusHistory = ((_a = swap.metadata) == null ? void 0 : _a.status_history) || [];
975
+ const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
944
976
  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: [
945
977
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
946
978
  /* @__PURE__ */ jsxs(
@@ -948,7 +980,7 @@ const SwapDetailPage = () => {
948
980
  {
949
981
  variant: "transparent",
950
982
  size: "small",
951
- onClick: () => navigate("/swaps"),
983
+ onClick: () => navigate("/returns"),
952
984
  className: "w-fit",
953
985
  children: [
954
986
  /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
@@ -958,41 +990,19 @@ const SwapDetailPage = () => {
958
990
  ),
959
991
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
960
992
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
961
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Swap Details" }),
962
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
993
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Order Details" }),
994
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
963
995
  ] }),
964
996
  /* @__PURE__ */ jsx(
965
997
  Badge,
966
998
  {
967
999
  size: "small",
968
- className: `uppercase ${getStatusBadgeClass(swap.status)}`,
969
- children: swap.status.replace(/_/g, " ")
1000
+ className: `uppercase ${getStatusBadgeClass(returnOrder.status)}`,
1001
+ children: returnOrder.status.replace("_", " ")
970
1002
  }
971
1003
  )
972
1004
  ] })
973
1005
  ] }),
974
- swap.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "flex gap-3", children: [
975
- /* @__PURE__ */ jsx(
976
- Button,
977
- {
978
- variant: "primary",
979
- onClick: handleApprove,
980
- disabled: isApproving || isRejecting,
981
- isLoading: isApproving,
982
- children: "Approve Swap"
983
- }
984
- ),
985
- /* @__PURE__ */ jsx(
986
- Button,
987
- {
988
- variant: "secondary",
989
- onClick: handleReject,
990
- disabled: isApproving || isRejecting,
991
- isLoading: isRejecting,
992
- children: "Reject Swap"
993
- }
994
- )
995
- ] }),
996
1006
  /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
997
1007
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Update Status" }),
998
1008
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-end", children: [
@@ -1006,7 +1016,7 @@ const SwapDetailPage = () => {
1006
1016
  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",
1007
1017
  children: [
1008
1018
  /* @__PURE__ */ jsx("option", { value: "", children: "Select new status" }),
1009
- availableStatuses.filter((status) => status !== swap.status).map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1019
+ availableStatuses.filter((status) => status !== returnOrder.status).map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace("_", " ").toUpperCase() }, status))
1010
1020
  ]
1011
1021
  }
1012
1022
  )
@@ -1027,35 +1037,35 @@ const SwapDetailPage = () => {
1027
1037
  ] }),
1028
1038
  /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
1029
1039
  /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1030
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Swap Information" }),
1040
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
1031
1041
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1032
1042
  /* @__PURE__ */ jsxs("div", { children: [
1033
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Swap ID" }),
1034
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.id })
1043
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
1044
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
1035
1045
  ] }),
1036
1046
  /* @__PURE__ */ jsxs("div", { children: [
1037
1047
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
1038
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.status })
1048
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.status })
1039
1049
  ] }),
1040
1050
  /* @__PURE__ */ jsxs("div", { children: [
1041
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
1042
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
1051
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Refund Amount" }),
1052
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.refund_amount ? `${((_b = returnOrder.order) == null ? void 0 : _b.currency_code) || "$"}${Number(returnOrder.refund_amount).toFixed(2)}` : "—" })
1043
1053
  ] }),
1044
- swap.reason && /* @__PURE__ */ jsxs("div", { children: [
1054
+ returnOrder.reason && /* @__PURE__ */ jsxs("div", { children: [
1045
1055
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
1046
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.reason })
1056
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.reason })
1047
1057
  ] }),
1048
- swap.note && /* @__PURE__ */ jsxs("div", { children: [
1058
+ returnOrder.note && /* @__PURE__ */ jsxs("div", { children: [
1049
1059
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
1050
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.note })
1060
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.note })
1051
1061
  ] }),
1052
1062
  /* @__PURE__ */ jsxs("div", { children: [
1053
1063
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
1054
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
1064
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
1055
1065
  ] }),
1056
1066
  /* @__PURE__ */ jsxs("div", { children: [
1057
1067
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
1058
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
1068
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
1059
1069
  ] })
1060
1070
  ] })
1061
1071
  ] }),
@@ -1066,18 +1076,23 @@ const SwapDetailPage = () => {
1066
1076
  {
1067
1077
  className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
1068
1078
  children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1069
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx(
1070
- Badge,
1071
- {
1072
- size: "2xsmall",
1073
- className: `uppercase ${getStatusBadgeClass(entry.status)}`,
1074
- children: entry.status.replace(/_/g, " ")
1075
- }
1076
- ) }),
1079
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1080
+ /* @__PURE__ */ jsx(
1081
+ Badge,
1082
+ {
1083
+ size: "2xsmall",
1084
+ className: `uppercase ${getStatusBadgeClass(entry.to)}`,
1085
+ children: entry.to.replace("_", " ")
1086
+ }
1087
+ ),
1088
+ entry.from && /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
1089
+ "from ",
1090
+ entry.from.replace("_", " ")
1091
+ ] })
1092
+ ] }),
1077
1093
  /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
1078
- new Date(entry.timestamp).toLocaleString(),
1079
- entry.admin_id && ` by ${entry.admin_id}`,
1080
- entry.reason && ` - ${entry.reason}`
1094
+ new Date(entry.changed_at).toLocaleString(),
1095
+ entry.changed_by && ` by ${entry.changed_by}`
1081
1096
  ] })
1082
1097
  ] })
1083
1098
  },
@@ -1085,83 +1100,97 @@ const SwapDetailPage = () => {
1085
1100
  )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
1086
1101
  ] })
1087
1102
  ] }),
1088
- order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1103
+ returnOrder.order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1089
1104
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
1090
- /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1091
- /* @__PURE__ */ jsxs("div", { children: [
1092
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
1093
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.id })
1094
- ] }),
1095
- /* @__PURE__ */ jsxs("div", { children: [
1096
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
1097
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.status || "—" })
1098
- ] }),
1099
- /* @__PURE__ */ jsxs("div", { children: [
1100
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
1101
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = order.customer) == null ? void 0 : _b.email) || order.email || "" })
1105
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
1106
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1107
+ /* @__PURE__ */ jsxs("div", { children: [
1108
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
1109
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.id })
1110
+ ] }),
1111
+ /* @__PURE__ */ jsxs("div", { children: [
1112
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
1113
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.status || "—" })
1114
+ ] }),
1115
+ /* @__PURE__ */ jsxs("div", { children: [
1116
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
1117
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_c = returnOrder.order.customer) == null ? void 0 : _c.email) || returnOrder.order.email || "—" })
1118
+ ] }),
1119
+ /* @__PURE__ */ jsxs("div", { children: [
1120
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
1121
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.total ? `${returnOrder.order.currency_code || "$"}${Number(returnOrder.order.total).toFixed(2)}` : "—" })
1122
+ ] })
1102
1123
  ] }),
1103
- order.total && /* @__PURE__ */ jsxs("div", { children: [
1104
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
1105
- /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
1106
- order.currency_code || "$",
1107
- (Number(order.total) / 100).toFixed(2)
1124
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1125
+ /* @__PURE__ */ jsxs("div", { children: [
1126
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Subtotal" }),
1127
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.subtotal ? `${returnOrder.order.currency_code || "$"}${Number(returnOrder.order.subtotal).toFixed(2)}` : "—" })
1128
+ ] }),
1129
+ /* @__PURE__ */ jsxs("div", { children: [
1130
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Tax Total" }),
1131
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.tax_total ? `${returnOrder.order.currency_code || "$"}${Number(returnOrder.order.tax_total).toFixed(2)}` : "—" })
1132
+ ] }),
1133
+ /* @__PURE__ */ jsxs("div", { children: [
1134
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Shipping Total" }),
1135
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.shipping_total ? `${returnOrder.order.currency_code || "$"}${Number(returnOrder.order.shipping_total).toFixed(2)}` : "—" })
1136
+ ] }),
1137
+ /* @__PURE__ */ jsxs("div", { children: [
1138
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Created" }),
1139
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.created_at ? new Date(returnOrder.order.created_at).toLocaleString() : "—" })
1108
1140
  ] })
1109
1141
  ] })
1110
1142
  ] })
1111
1143
  ] }),
1112
- 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: [
1144
+ returnOrder.items && returnOrder.items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1113
1145
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
1114
1146
  /* @__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: [
1115
1147
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
1116
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
1117
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
1118
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
1119
- ] }) }),
1120
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
1121
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
1122
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
1123
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
1124
- ] }, item.id || index)) })
1125
- ] }) })
1126
- ] }),
1127
- 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: [
1128
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
1129
- /* @__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: [
1130
- /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
1131
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
1148
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item" }),
1132
1149
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
1133
1150
  ] }) }),
1134
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
1135
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
1136
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
1137
- ] }, item.variant_id || index)) })
1151
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.items.map((item) => {
1152
+ var _a2, _b2;
1153
+ return /* @__PURE__ */ jsxs("tr", { children: [
1154
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: ((_a2 = item.item) == null ? void 0 : _a2.title) || ((_b2 = item.item) == null ? void 0 : _b2.id) || item.id }),
1155
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
1156
+ ] }, item.id);
1157
+ }) })
1138
1158
  ] }) })
1159
+ ] }),
1160
+ returnOrder.metadata && Object.keys(returnOrder.metadata).filter(
1161
+ (key) => key !== "status_history"
1162
+ ).length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1163
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Metadata" }),
1164
+ /* @__PURE__ */ jsx("div", { className: "space-y-2", children: Object.entries(returnOrder.metadata).filter(([key]) => key !== "status_history").map(([key, value]) => /* @__PURE__ */ jsxs("div", { className: "flex justify-between", children: [
1165
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: key }),
1166
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "font-medium", children: typeof value === "string" ? value : JSON.stringify(value) })
1167
+ ] }, key)) })
1139
1168
  ] })
1140
1169
  ] }) });
1141
1170
  };
1142
1171
  const config = defineRouteConfig({
1143
- label: "Swap Details",
1172
+ label: "Return Order Details",
1144
1173
  icon: ArrowPath
1145
1174
  });
1146
1175
  const i18nTranslations0 = {};
1147
1176
  const widgetModule = { widgets: [] };
1148
1177
  const routeModule = {
1149
1178
  routes: [
1150
- {
1151
- Component: ReturnsPage,
1152
- path: "/returns"
1153
- },
1154
1179
  {
1155
1180
  Component: SwapsPage,
1156
1181
  path: "/swaps"
1157
1182
  },
1158
1183
  {
1159
- Component: ReturnDetailPage,
1160
- path: "/returns/:id"
1184
+ Component: ReturnsPage,
1185
+ path: "/returns"
1161
1186
  },
1162
1187
  {
1163
1188
  Component: SwapDetailPage,
1164
1189
  path: "/swaps/:id"
1190
+ },
1191
+ {
1192
+ Component: ReturnDetailPage,
1193
+ path: "/returns/:id"
1165
1194
  }
1166
1195
  ]
1167
1196
  };
@@ -1170,25 +1199,25 @@ const menuItemModule = {
1170
1199
  {
1171
1200
  label: config$2.label,
1172
1201
  icon: config$2.icon,
1173
- path: "/swaps",
1202
+ path: "/returns",
1174
1203
  nested: void 0
1175
1204
  },
1176
1205
  {
1177
1206
  label: config$3.label,
1178
1207
  icon: config$3.icon,
1179
- path: "/returns",
1208
+ path: "/swaps",
1180
1209
  nested: void 0
1181
1210
  },
1182
1211
  {
1183
1212
  label: config.label,
1184
1213
  icon: config.icon,
1185
- path: "/swaps/:id",
1214
+ path: "/returns/:id",
1186
1215
  nested: void 0
1187
1216
  },
1188
1217
  {
1189
1218
  label: config$1.label,
1190
1219
  icon: config$1.icon,
1191
- path: "/returns/:id",
1220
+ path: "/swaps/:id",
1192
1221
  nested: void 0
1193
1222
  }
1194
1223
  ]