order-management 0.0.49 → 0.0.50

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