order-management 0.0.20 → 0.0.22

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