order-management 0.0.78 → 0.0.79

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 (43) hide show
  1. package/.medusa/server/src/admin/index.js +620 -620
  2. package/.medusa/server/src/admin/index.mjs +621 -621
  3. package/.medusa/server/src/api/admin/orders/[order_id]/cancel-reason-mapping/route.js +1 -2
  4. package/.medusa/server/src/api/admin/orders/[order_id]/refund-context/route.js +1 -2
  5. package/.medusa/server/src/api/admin/payment-transactions/[id]/route.js +1 -2
  6. package/.medusa/server/src/api/admin/payment-transactions/route.js +1 -2
  7. package/.medusa/server/src/api/admin/refund-payment-mapping/[return_id]/mark-refunded/route.js +1 -2
  8. package/.medusa/server/src/api/admin/refund-payment-mapping/[return_id]/route.js +1 -2
  9. package/.medusa/server/src/api/admin/refunds/[id]/route.js +1 -2
  10. package/.medusa/server/src/api/admin/refunds/route.js +1 -2
  11. package/.medusa/server/src/api/admin/return/[id]/route.js +1 -2
  12. package/.medusa/server/src/api/admin/return/route.js +1 -2
  13. package/.medusa/server/src/api/admin/swaps/[id]/cancel/route.js +1 -2
  14. package/.medusa/server/src/api/store/guest-orders/[id]/cancel/route.js +1 -4
  15. package/.medusa/server/src/api/store/guest-orders/[id]/cancel-reason-mapping/route.js +1 -3
  16. package/.medusa/server/src/api/store/guest-orders/[id]/reorder/route.js +1 -13
  17. package/.medusa/server/src/api/store/guest-orders/[id]/returns/route.js +2 -3
  18. package/.medusa/server/src/api/store/guest-orders/[id]/route.js +1 -2
  19. package/.medusa/server/src/api/store/guest-orders/[id]/swaps/[swap_id]/cancel/route.js +1 -2
  20. package/.medusa/server/src/api/store/guest-orders/[id]/swaps/[swap_id]/route.js +1 -2
  21. package/.medusa/server/src/api/store/guest-orders/[id]/swaps/route.js +2 -5
  22. package/.medusa/server/src/api/store/guest-orders/route.js +1 -2
  23. package/.medusa/server/src/api/store/orders/[order_id]/cancel-reason-mapping/route.js +1 -2
  24. package/.medusa/server/src/api/store/orders/[order_id]/refund-payment-mappings/route.js +1 -2
  25. package/.medusa/server/src/api/store/orders/cancel/[order_id]/route.js +1 -19
  26. package/.medusa/server/src/api/store/otp/request/route.js +1 -7
  27. package/.medusa/server/src/api/store/otp/verify/route.js +1 -2
  28. package/.medusa/server/src/api/store/payment-details/[id]/make-default/route.js +1 -2
  29. package/.medusa/server/src/api/store/payment-details/[id]/route.js +1 -2
  30. package/.medusa/server/src/api/store/payment-details/route.js +1 -3
  31. package/.medusa/server/src/api/store/refund-payment-mapping/[return_id]/route.js +1 -3
  32. package/.medusa/server/src/api/store/returns/[id]/cancel/route.js +1 -2
  33. package/.medusa/server/src/api/store/returns/[id]/route.js +1 -2
  34. package/.medusa/server/src/api/store/returns/route.js +4 -8
  35. package/.medusa/server/src/api/store/swaps/[id]/cancel/route.js +1 -2
  36. package/.medusa/server/src/api/store/swaps/[id]/route.js +1 -2
  37. package/.medusa/server/src/api/store/swaps/route.js +2 -5
  38. package/.medusa/server/src/helpers/order-exchange-data.js +5 -20
  39. package/.medusa/server/src/subscribers/order-status-change.js +1 -3
  40. package/.medusa/server/src/subscribers/send-order-email.js +1 -4
  41. package/.medusa/server/src/utils/notification-handler.js +3 -13
  42. package/README.md +276 -0
  43. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
3
3
  import { useState, useEffect, useRef, useCallback, useMemo } from "react";
4
4
  import { Container, Text, Heading, Badge, Button, Label, Select, Textarea, Input } from "@medusajs/ui";
5
- import { CashSolid, PencilSquareSolid, Trash, Receipt, ArrowPath, CreditCard, ArrowLeft, CheckCircle } from "@medusajs/icons";
5
+ import { CashSolid, PencilSquareSolid, Trash, CreditCard, Receipt, ArrowPath, CheckCircle, ArrowLeft } from "@medusajs/icons";
6
6
  import { useNavigate, useParams } from "react-router-dom";
7
7
  function roundRectPath(ctx, x, y, w, h, r) {
8
8
  ctx.beginPath();
@@ -872,16 +872,216 @@ const getStatusBadgeClass$7 = (status) => {
872
872
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
873
873
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
874
874
  };
875
- const RefundsPage = () => {
875
+ const PaymentsPage = () => {
876
876
  const navigate = useNavigate();
877
877
  const [items, setItems] = useState([]);
878
+ const [statusFilter, setStatusFilter] = useState("all");
878
879
  const [orderIdSearch, setOrderIdSearch] = useState("");
879
880
  const debouncedOrderId = useDebounce$3(orderIdSearch, 300);
881
+ const [isLoading, setIsLoading] = useState(true);
882
+ const [isFetchingMore, setIsFetchingMore] = useState(false);
883
+ const [error, setError] = useState(null);
884
+ const [offset, setOffset] = useState(0);
885
+ const [count, setCount] = useState(0);
886
+ const limit = 50;
887
+ const loadTransactions = useCallback(
888
+ async (nextOffset, replace) => {
889
+ try {
890
+ if (replace) setIsLoading(true);
891
+ else setIsFetchingMore(true);
892
+ setError(null);
893
+ const params = new URLSearchParams();
894
+ params.set("limit", String(limit));
895
+ params.set("offset", String(nextOffset));
896
+ if (statusFilter !== "all") params.set("status", statusFilter);
897
+ if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
898
+ const response = await fetch(
899
+ `/admin/payment-transactions?${params.toString()}`,
900
+ { credentials: "include" }
901
+ );
902
+ if (!response.ok) {
903
+ const text = await response.text();
904
+ throw new Error(text || "Failed to load payment transactions");
905
+ }
906
+ const payload = await response.json();
907
+ const list = payload.transactions ?? [];
908
+ setCount(payload.count ?? 0);
909
+ setOffset(nextOffset + list.length);
910
+ setItems((prev) => replace ? list : [...prev, ...list]);
911
+ } catch (e) {
912
+ setError(e instanceof Error ? e.message : "Failed to load");
913
+ } finally {
914
+ setIsLoading(false);
915
+ setIsFetchingMore(false);
916
+ }
917
+ },
918
+ [statusFilter, debouncedOrderId]
919
+ );
920
+ useEffect(() => {
921
+ void loadTransactions(0, true);
922
+ }, [loadTransactions]);
923
+ const hasMore = useMemo(() => offset < count, [offset, count]);
924
+ const displayStatus = (t) => {
925
+ const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
926
+ return s2 !== "" ? s2 : "—";
927
+ };
928
+ const displayAmount = (t) => {
929
+ const code = (t.currency_code ?? "USD").toUpperCase();
930
+ return `${code} ${Number(t.amount)}`;
931
+ };
932
+ 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: [
933
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
934
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
935
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payments" }),
936
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
937
+ ] }),
938
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
939
+ ] }),
940
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
941
+ /* @__PURE__ */ jsx(
942
+ Input,
943
+ {
944
+ placeholder: "Search by Order ID",
945
+ value: orderIdSearch,
946
+ onChange: (e) => setOrderIdSearch(e.target.value),
947
+ className: "md:max-w-sm",
948
+ "aria-label": "Search by order ID"
949
+ }
950
+ ),
951
+ /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxs(
952
+ "select",
953
+ {
954
+ value: statusFilter,
955
+ onChange: (e) => setStatusFilter(e.target.value),
956
+ className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
957
+ "aria-label": "Filter by status",
958
+ children: [
959
+ /* @__PURE__ */ jsx("option", { value: "all", children: "All statuses" }),
960
+ /* @__PURE__ */ jsx("option", { value: "pending", children: "Pending" }),
961
+ /* @__PURE__ */ jsx("option", { value: "requires_more", children: "Requires more" }),
962
+ /* @__PURE__ */ jsx("option", { value: "error", children: "Error" }),
963
+ /* @__PURE__ */ jsx("option", { value: "canceled", children: "Canceled" }),
964
+ /* @__PURE__ */ jsx("option", { value: "authorized", children: "Authorized" }),
965
+ /* @__PURE__ */ jsx("option", { value: "captured", children: "Captured" })
966
+ ]
967
+ }
968
+ ) })
969
+ ] }),
970
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
971
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
972
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
973
+ ] }) : null,
974
+ isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
975
+ /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
976
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
977
+ ] }) : /* @__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: [
978
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
979
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
980
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
981
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
982
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
983
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
984
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
985
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
986
+ ] }) }),
987
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxs(
988
+ "tr",
989
+ {
990
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
991
+ onClick: () => navigate(`/payments/${t.payment_session_id}`),
992
+ children: [
993
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
994
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
995
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
996
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
997
+ Badge,
998
+ {
999
+ size: "2xsmall",
1000
+ className: `uppercase ${getStatusBadgeClass$7(displayStatus(t))}`,
1001
+ children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1002
+ }
1003
+ ) }),
1004
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1005
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1006
+ year: "numeric",
1007
+ month: "short",
1008
+ day: "numeric",
1009
+ hour: "numeric",
1010
+ minute: "2-digit",
1011
+ hour12: true
1012
+ }) }),
1013
+ /* @__PURE__ */ jsxs("td", { className: "px-4 py-4", children: [
1014
+ /* @__PURE__ */ jsx(
1015
+ Button,
1016
+ {
1017
+ variant: "transparent",
1018
+ size: "small",
1019
+ onClick: (e) => {
1020
+ e.stopPropagation();
1021
+ navigate(`/payments/${t.payment_session_id}`);
1022
+ },
1023
+ children: "View details"
1024
+ }
1025
+ ),
1026
+ t.order_id ? /* @__PURE__ */ jsx(
1027
+ Button,
1028
+ {
1029
+ variant: "transparent",
1030
+ size: "small",
1031
+ onClick: (e) => {
1032
+ e.stopPropagation();
1033
+ navigate(`/orders/${t.order_id}`);
1034
+ },
1035
+ children: "Order"
1036
+ }
1037
+ ) : null
1038
+ ] })
1039
+ ]
1040
+ },
1041
+ t.payment_session_id
1042
+ )) })
1043
+ ] }) }),
1044
+ hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
1045
+ Button,
1046
+ {
1047
+ variant: "secondary",
1048
+ isLoading: isFetchingMore,
1049
+ onClick: () => loadTransactions(offset, false),
1050
+ children: "Load more"
1051
+ }
1052
+ ) }) : null
1053
+ ] }) });
1054
+ };
1055
+ const config$7 = defineRouteConfig({
1056
+ label: "Payments",
1057
+ icon: CreditCard
1058
+ });
1059
+ const useDebounce$2 = (value, delay) => {
1060
+ const [debouncedValue, setDebouncedValue] = useState(value);
1061
+ useEffect(() => {
1062
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
1063
+ return () => clearTimeout(handler);
1064
+ }, [value, delay]);
1065
+ return debouncedValue;
1066
+ };
1067
+ const getStatusBadgeClass$6 = (status) => {
1068
+ const s2 = status.toLowerCase();
1069
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1070
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1071
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1072
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1073
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1074
+ };
1075
+ const RefundsPage = () => {
1076
+ const navigate = useNavigate();
1077
+ const [items, setItems] = useState([]);
1078
+ const [orderIdSearch, setOrderIdSearch] = useState("");
1079
+ const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
880
1080
  const [paymentStatusFilter, setPaymentStatusFilter] = useState("all");
881
1081
  const [providerSearch, setProviderSearch] = useState("");
882
- const debouncedProvider = useDebounce$3(providerSearch, 300);
1082
+ const debouncedProvider = useDebounce$2(providerSearch, 300);
883
1083
  const [currencySearch, setCurrencySearch] = useState("");
884
- const debouncedCurrency = useDebounce$3(currencySearch, 300);
1084
+ const debouncedCurrency = useDebounce$2(currencySearch, 300);
885
1085
  const [dateFrom, setDateFrom] = useState("");
886
1086
  const [dateTo, setDateTo] = useState("");
887
1087
  const [amountMin, setAmountMin] = useState("");
@@ -1093,7 +1293,7 @@ const RefundsPage = () => {
1093
1293
  Badge,
1094
1294
  {
1095
1295
  size: "2xsmall",
1096
- className: `uppercase ${getStatusBadgeClass$7(displayStatus(r))}`,
1296
+ className: `uppercase ${getStatusBadgeClass$6(displayStatus(r))}`,
1097
1297
  children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1098
1298
  }
1099
1299
  ) }),
@@ -1147,11 +1347,11 @@ const RefundsPage = () => {
1147
1347
  ) }) : null
1148
1348
  ] }) });
1149
1349
  };
1150
- const config$7 = defineRouteConfig({
1350
+ const config$6 = defineRouteConfig({
1151
1351
  label: "Refunds",
1152
1352
  icon: Receipt
1153
1353
  });
1154
- const useDebounce$2 = (value, delay) => {
1354
+ const useDebounce$1 = (value, delay) => {
1155
1355
  const [debouncedValue, setDebouncedValue] = useState(value);
1156
1356
  useEffect(() => {
1157
1357
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1159,39 +1359,39 @@ const useDebounce$2 = (value, delay) => {
1159
1359
  }, [value, delay]);
1160
1360
  return debouncedValue;
1161
1361
  };
1162
- const getStatusBadgeClass$6 = (status) => {
1362
+ const getStatusBadgeClass$5 = (status) => {
1163
1363
  const statusLower = status.toLowerCase();
1164
1364
  if (statusLower === "requested") {
1165
1365
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1166
1366
  }
1167
- if (statusLower === "approved") {
1367
+ if (statusLower === "received") {
1168
1368
  return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1169
1369
  }
1170
- if (statusLower === "rejected") {
1370
+ if (statusLower === "requires_action") {
1171
1371
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
1172
1372
  }
1173
1373
  if (statusLower === "completed") {
1174
1374
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
1175
1375
  }
1176
- if (statusLower === "cancelled") {
1376
+ if (statusLower === "canceled") {
1177
1377
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1178
1378
  }
1179
1379
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1180
1380
  };
1181
- const SwapsPage = () => {
1381
+ const ReturnsPage = () => {
1182
1382
  const navigate = useNavigate();
1183
1383
  const [items, setItems] = useState([]);
1184
1384
  const [statusFilter, setStatusFilter] = useState("all");
1185
1385
  const [createdByFilter, setCreatedByFilter] = useState("all");
1186
1386
  const [searchQuery, setSearchQuery] = useState("");
1187
- const debouncedSearchQuery = useDebounce$2(searchQuery, 300);
1387
+ const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1188
1388
  const [isLoading, setIsLoading] = useState(true);
1189
1389
  const [isFetchingMore, setIsFetchingMore] = useState(false);
1190
1390
  const [error, setError] = useState(null);
1191
1391
  const [offset, setOffset] = useState(0);
1192
1392
  const [count, setCount] = useState(0);
1193
1393
  const limit = 50;
1194
- const loadSwaps = useCallback(
1394
+ const loadReturns = useCallback(
1195
1395
  async (nextOffset, replace = false) => {
1196
1396
  var _a;
1197
1397
  try {
@@ -1208,27 +1408,28 @@ const SwapsPage = () => {
1208
1408
  params.set("status", statusFilter);
1209
1409
  }
1210
1410
  if (debouncedSearchQuery.trim()) {
1211
- params.set("order_id", debouncedSearchQuery.trim());
1411
+ params.set("q", debouncedSearchQuery.trim());
1212
1412
  }
1213
1413
  if (createdByFilter !== "all") {
1214
1414
  params.set("created_by", createdByFilter);
1215
1415
  }
1416
+ params.set("order", "created_at");
1216
1417
  const response = await fetch(
1217
- `/admin/swaps?${params.toString()}`,
1418
+ `/admin/return?${params.toString()}`,
1218
1419
  { credentials: "include" }
1219
1420
  );
1220
1421
  if (!response.ok) {
1221
1422
  const message = await response.text();
1222
- throw new Error(message || "Unable to load swaps");
1423
+ throw new Error(message || "Unable to load return orders");
1223
1424
  }
1224
1425
  const payload = await response.json();
1225
1426
  setCount(payload.count ?? 0);
1226
- setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
1427
+ setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
1227
1428
  setItems(
1228
- (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
1429
+ (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
1229
1430
  );
1230
1431
  } catch (loadError) {
1231
- const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
1432
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
1232
1433
  setError(message);
1233
1434
  } finally {
1234
1435
  setIsLoading(false);
@@ -1238,8 +1439,8 @@ const SwapsPage = () => {
1238
1439
  [statusFilter, createdByFilter, debouncedSearchQuery]
1239
1440
  );
1240
1441
  useEffect(() => {
1241
- void loadSwaps(0, true);
1242
- }, [statusFilter, createdByFilter, debouncedSearchQuery, loadSwaps]);
1442
+ void loadReturns(0, true);
1443
+ }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
1243
1444
  const hasMore = useMemo(() => offset < count, [offset, count]);
1244
1445
  const availableStatuses = useMemo(() => {
1245
1446
  const statuses = /* @__PURE__ */ new Set();
@@ -1249,16 +1450,16 @@ const SwapsPage = () => {
1249
1450
  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: [
1250
1451
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1251
1452
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1252
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Exchanges" }),
1253
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer exchange requests" })
1453
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Orders" }),
1454
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
1254
1455
  ] }),
1255
- /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
1456
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
1256
1457
  ] }),
1257
1458
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1258
1459
  /* @__PURE__ */ jsx(
1259
1460
  Input,
1260
1461
  {
1261
- placeholder: "Search by swap ID or order ID",
1462
+ placeholder: "Search by return ID, order ID, or customer email",
1262
1463
  value: searchQuery,
1263
1464
  onChange: (event) => setSearchQuery(event.target.value),
1264
1465
  className: "md:max-w-sm"
@@ -1298,50 +1499,51 @@ const SwapsPage = () => {
1298
1499
  Button,
1299
1500
  {
1300
1501
  variant: "secondary",
1301
- onClick: () => loadSwaps(0, true),
1502
+ onClick: () => loadReturns(0, true),
1302
1503
  children: "Try again"
1303
1504
  }
1304
1505
  ) })
1305
1506
  ] }) : null,
1306
- 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: [
1307
- /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No exchanges yet" }),
1308
- /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Exchange requests created by customers will appear here." })
1507
+ 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: [
1508
+ /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1509
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1309
1510
  ] }) : /* @__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: [
1310
1511
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
1311
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Exchange ID" }),
1512
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
1312
1513
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1514
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1313
1515
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1314
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Difference Due" }),
1516
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
1315
1517
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1316
1518
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1317
1519
  ] }) }),
1318
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxs(
1520
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxs(
1319
1521
  "tr",
1320
1522
  {
1321
1523
  className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1322
- onClick: () => navigate(`/swaps/${swap.id}`),
1524
+ onClick: () => navigate(`/returns/${returnOrder.id}`),
1323
1525
  children: [
1324
- /* @__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 }) }) }),
1325
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: swap.order_id }),
1526
+ /* @__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 }) }) }),
1527
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1528
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1326
1529
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1327
1530
  Badge,
1328
1531
  {
1329
1532
  size: "2xsmall",
1330
- className: `uppercase ${getStatusBadgeClass$6(swap.status)}`,
1331
- children: swap.status.replace(/_/g, " ")
1533
+ className: `uppercase ${getStatusBadgeClass$5(returnOrder.status)}`,
1534
+ children: returnOrder.status.replace(/_/g, " ")
1332
1535
  }
1333
1536
  ) }),
1334
1537
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1335
- const amount = swap.difference_due;
1538
+ const amount = returnOrder.refund_amount;
1336
1539
  if (amount == null || amount === void 0) {
1337
1540
  return "—";
1338
1541
  }
1339
1542
  const displayAmount = Number(amount) / 100;
1340
- const currency = swap.currency_code || "$";
1341
- const sign = displayAmount >= 0 ? "+" : "";
1342
- return `${sign}${currency}${displayAmount.toFixed(2)}`;
1543
+ const currency = returnOrder.currency_code || "$";
1544
+ return `${currency}${displayAmount.toFixed(2)}`;
1343
1545
  })() }),
1344
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
1546
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1345
1547
  year: "numeric",
1346
1548
  month: "short",
1347
1549
  day: "numeric",
@@ -1356,14 +1558,14 @@ const SwapsPage = () => {
1356
1558
  size: "small",
1357
1559
  onClick: (e) => {
1358
1560
  e.stopPropagation();
1359
- navigate(`/app/orders/${swap.order_id}`);
1561
+ navigate(`/app/orders/${returnOrder.order_id}`);
1360
1562
  },
1361
1563
  children: "Go to order"
1362
1564
  }
1363
1565
  ) })
1364
1566
  ]
1365
1567
  },
1366
- swap.id
1568
+ returnOrder.id
1367
1569
  )) })
1368
1570
  ] }) }),
1369
1571
  hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
@@ -1371,17 +1573,17 @@ const SwapsPage = () => {
1371
1573
  {
1372
1574
  variant: "secondary",
1373
1575
  isLoading: isFetchingMore,
1374
- onClick: () => loadSwaps(offset, false),
1576
+ onClick: () => loadReturns(offset, false),
1375
1577
  children: "Load more"
1376
1578
  }
1377
1579
  ) }) : null
1378
1580
  ] }) });
1379
1581
  };
1380
- const config$6 = defineRouteConfig({
1381
- label: "Exchanges",
1582
+ const config$5 = defineRouteConfig({
1583
+ label: "Return Orders",
1382
1584
  icon: ArrowPath
1383
1585
  });
1384
- const useDebounce$1 = (value, delay) => {
1586
+ const useDebounce = (value, delay) => {
1385
1587
  const [debouncedValue, setDebouncedValue] = useState(value);
1386
1588
  useEffect(() => {
1387
1589
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1389,39 +1591,39 @@ const useDebounce$1 = (value, delay) => {
1389
1591
  }, [value, delay]);
1390
1592
  return debouncedValue;
1391
1593
  };
1392
- const getStatusBadgeClass$5 = (status) => {
1594
+ const getStatusBadgeClass$4 = (status) => {
1393
1595
  const statusLower = status.toLowerCase();
1394
1596
  if (statusLower === "requested") {
1395
1597
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1396
1598
  }
1397
- if (statusLower === "received") {
1599
+ if (statusLower === "approved") {
1398
1600
  return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1399
1601
  }
1400
- if (statusLower === "requires_action") {
1602
+ if (statusLower === "rejected") {
1401
1603
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
1402
1604
  }
1403
1605
  if (statusLower === "completed") {
1404
1606
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
1405
1607
  }
1406
- if (statusLower === "canceled") {
1608
+ if (statusLower === "cancelled") {
1407
1609
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1408
1610
  }
1409
1611
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1410
1612
  };
1411
- const ReturnsPage = () => {
1613
+ const SwapsPage = () => {
1412
1614
  const navigate = useNavigate();
1413
1615
  const [items, setItems] = useState([]);
1414
1616
  const [statusFilter, setStatusFilter] = useState("all");
1415
1617
  const [createdByFilter, setCreatedByFilter] = useState("all");
1416
1618
  const [searchQuery, setSearchQuery] = useState("");
1417
- const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1619
+ const debouncedSearchQuery = useDebounce(searchQuery, 300);
1418
1620
  const [isLoading, setIsLoading] = useState(true);
1419
1621
  const [isFetchingMore, setIsFetchingMore] = useState(false);
1420
1622
  const [error, setError] = useState(null);
1421
1623
  const [offset, setOffset] = useState(0);
1422
1624
  const [count, setCount] = useState(0);
1423
1625
  const limit = 50;
1424
- const loadReturns = useCallback(
1626
+ const loadSwaps = useCallback(
1425
1627
  async (nextOffset, replace = false) => {
1426
1628
  var _a;
1427
1629
  try {
@@ -1438,28 +1640,27 @@ const ReturnsPage = () => {
1438
1640
  params.set("status", statusFilter);
1439
1641
  }
1440
1642
  if (debouncedSearchQuery.trim()) {
1441
- params.set("q", debouncedSearchQuery.trim());
1643
+ params.set("order_id", debouncedSearchQuery.trim());
1442
1644
  }
1443
1645
  if (createdByFilter !== "all") {
1444
1646
  params.set("created_by", createdByFilter);
1445
1647
  }
1446
- params.set("order", "created_at");
1447
1648
  const response = await fetch(
1448
- `/admin/return?${params.toString()}`,
1649
+ `/admin/swaps?${params.toString()}`,
1449
1650
  { credentials: "include" }
1450
1651
  );
1451
1652
  if (!response.ok) {
1452
1653
  const message = await response.text();
1453
- throw new Error(message || "Unable to load return orders");
1654
+ throw new Error(message || "Unable to load swaps");
1454
1655
  }
1455
1656
  const payload = await response.json();
1456
1657
  setCount(payload.count ?? 0);
1457
- setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
1658
+ setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
1458
1659
  setItems(
1459
- (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
1660
+ (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
1460
1661
  );
1461
1662
  } catch (loadError) {
1462
- const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
1663
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
1463
1664
  setError(message);
1464
1665
  } finally {
1465
1666
  setIsLoading(false);
@@ -1469,8 +1670,8 @@ const ReturnsPage = () => {
1469
1670
  [statusFilter, createdByFilter, debouncedSearchQuery]
1470
1671
  );
1471
1672
  useEffect(() => {
1472
- void loadReturns(0, true);
1473
- }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
1673
+ void loadSwaps(0, true);
1674
+ }, [statusFilter, createdByFilter, debouncedSearchQuery, loadSwaps]);
1474
1675
  const hasMore = useMemo(() => offset < count, [offset, count]);
1475
1676
  const availableStatuses = useMemo(() => {
1476
1677
  const statuses = /* @__PURE__ */ new Set();
@@ -1480,16 +1681,16 @@ const ReturnsPage = () => {
1480
1681
  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: [
1481
1682
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1482
1683
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1483
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Orders" }),
1484
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
1684
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Exchanges" }),
1685
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer exchange requests" })
1485
1686
  ] }),
1486
- /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
1687
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
1487
1688
  ] }),
1488
1689
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1489
1690
  /* @__PURE__ */ jsx(
1490
1691
  Input,
1491
1692
  {
1492
- placeholder: "Search by return ID, order ID, or customer email",
1693
+ placeholder: "Search by swap ID or order ID",
1493
1694
  value: searchQuery,
1494
1695
  onChange: (event) => setSearchQuery(event.target.value),
1495
1696
  className: "md:max-w-sm"
@@ -1529,51 +1730,50 @@ const ReturnsPage = () => {
1529
1730
  Button,
1530
1731
  {
1531
1732
  variant: "secondary",
1532
- onClick: () => loadReturns(0, true),
1733
+ onClick: () => loadSwaps(0, true),
1533
1734
  children: "Try again"
1534
1735
  }
1535
1736
  ) })
1536
1737
  ] }) : null,
1537
- 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: [
1538
- /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1539
- /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1738
+ 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: [
1739
+ /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No exchanges yet" }),
1740
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Exchange requests created by customers will appear here." })
1540
1741
  ] }) : /* @__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: [
1541
1742
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
1542
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
1743
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Exchange ID" }),
1543
1744
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1544
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1545
1745
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1546
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
1746
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Difference Due" }),
1547
1747
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1548
1748
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1549
1749
  ] }) }),
1550
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxs(
1750
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxs(
1551
1751
  "tr",
1552
1752
  {
1553
1753
  className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1554
- onClick: () => navigate(`/returns/${returnOrder.id}`),
1754
+ onClick: () => navigate(`/swaps/${swap.id}`),
1555
1755
  children: [
1556
- /* @__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 }) }) }),
1557
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1558
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1756
+ /* @__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 }) }) }),
1757
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: swap.order_id }),
1559
1758
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1560
1759
  Badge,
1561
1760
  {
1562
1761
  size: "2xsmall",
1563
- className: `uppercase ${getStatusBadgeClass$5(returnOrder.status)}`,
1564
- children: returnOrder.status.replace(/_/g, " ")
1762
+ className: `uppercase ${getStatusBadgeClass$4(swap.status)}`,
1763
+ children: swap.status.replace(/_/g, " ")
1565
1764
  }
1566
1765
  ) }),
1567
1766
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1568
- const amount = returnOrder.refund_amount;
1767
+ const amount = swap.difference_due;
1569
1768
  if (amount == null || amount === void 0) {
1570
1769
  return "—";
1571
1770
  }
1572
1771
  const displayAmount = Number(amount) / 100;
1573
- const currency = returnOrder.currency_code || "$";
1574
- return `${currency}${displayAmount.toFixed(2)}`;
1772
+ const currency = swap.currency_code || "$";
1773
+ const sign = displayAmount >= 0 ? "+" : "";
1774
+ return `${sign}${currency}${displayAmount.toFixed(2)}`;
1575
1775
  })() }),
1576
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1776
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
1577
1777
  year: "numeric",
1578
1778
  month: "short",
1579
1779
  day: "numeric",
@@ -1588,14 +1788,14 @@ const ReturnsPage = () => {
1588
1788
  size: "small",
1589
1789
  onClick: (e) => {
1590
1790
  e.stopPropagation();
1591
- navigate(`/app/orders/${returnOrder.order_id}`);
1791
+ navigate(`/app/orders/${swap.order_id}`);
1592
1792
  },
1593
1793
  children: "Go to order"
1594
1794
  }
1595
1795
  ) })
1596
1796
  ]
1597
1797
  },
1598
- returnOrder.id
1798
+ swap.id
1599
1799
  )) })
1600
1800
  ] }) }),
1601
1801
  hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
@@ -1603,25 +1803,17 @@ const ReturnsPage = () => {
1603
1803
  {
1604
1804
  variant: "secondary",
1605
1805
  isLoading: isFetchingMore,
1606
- onClick: () => loadReturns(offset, false),
1806
+ onClick: () => loadSwaps(offset, false),
1607
1807
  children: "Load more"
1608
1808
  }
1609
1809
  ) }) : null
1610
1810
  ] }) });
1611
1811
  };
1612
- const config$5 = defineRouteConfig({
1613
- label: "Return Orders",
1812
+ const config$4 = defineRouteConfig({
1813
+ label: "Exchanges",
1614
1814
  icon: ArrowPath
1615
1815
  });
1616
- const useDebounce = (value, delay) => {
1617
- const [debouncedValue, setDebouncedValue] = useState(value);
1618
- useEffect(() => {
1619
- const handler = setTimeout(() => setDebouncedValue(value), delay);
1620
- return () => clearTimeout(handler);
1621
- }, [value, delay]);
1622
- return debouncedValue;
1623
- };
1624
- const getStatusBadgeClass$4 = (status) => {
1816
+ const getStatusBadgeClass$3 = (status) => {
1625
1817
  const s2 = status.toLowerCase();
1626
1818
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1627
1819
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1629,191 +1821,118 @@ const getStatusBadgeClass$4 = (status) => {
1629
1821
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1630
1822
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1631
1823
  };
1632
- const PaymentsPage = () => {
1824
+ const PaymentDetailPage = () => {
1825
+ var _a;
1633
1826
  const navigate = useNavigate();
1634
- const [items, setItems] = useState([]);
1635
- const [statusFilter, setStatusFilter] = useState("all");
1636
- const [orderIdSearch, setOrderIdSearch] = useState("");
1637
- const debouncedOrderId = useDebounce(orderIdSearch, 300);
1638
- const [isLoading, setIsLoading] = useState(true);
1639
- const [isFetchingMore, setIsFetchingMore] = useState(false);
1827
+ const params = useParams();
1828
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
1829
+ const [detail, setDetail] = useState(null);
1830
+ const [loading, setLoading] = useState(!!id);
1640
1831
  const [error, setError] = useState(null);
1641
- const [offset, setOffset] = useState(0);
1642
- const [count, setCount] = useState(0);
1643
- const limit = 50;
1644
- const loadTransactions = useCallback(
1645
- async (nextOffset, replace) => {
1646
- try {
1647
- if (replace) setIsLoading(true);
1648
- else setIsFetchingMore(true);
1649
- setError(null);
1650
- const params = new URLSearchParams();
1651
- params.set("limit", String(limit));
1652
- params.set("offset", String(nextOffset));
1653
- if (statusFilter !== "all") params.set("status", statusFilter);
1654
- if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
1655
- const response = await fetch(
1656
- `/admin/payment-transactions?${params.toString()}`,
1657
- { credentials: "include" }
1658
- );
1659
- if (!response.ok) {
1660
- const text = await response.text();
1661
- throw new Error(text || "Failed to load payment transactions");
1662
- }
1663
- const payload = await response.json();
1664
- const list = payload.transactions ?? [];
1665
- setCount(payload.count ?? 0);
1666
- setOffset(nextOffset + list.length);
1667
- setItems((prev) => replace ? list : [...prev, ...list]);
1668
- } catch (e) {
1669
- setError(e instanceof Error ? e.message : "Failed to load");
1670
- } finally {
1671
- setIsLoading(false);
1672
- setIsFetchingMore(false);
1673
- }
1674
- },
1675
- [statusFilter, debouncedOrderId]
1676
- );
1677
1832
  useEffect(() => {
1678
- void loadTransactions(0, true);
1679
- }, [loadTransactions]);
1680
- const hasMore = useMemo(() => offset < count, [offset, count]);
1681
- const displayStatus = (t) => {
1682
- const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
1683
- return s2 !== "" ? s2 : "—";
1684
- };
1685
- const displayAmount = (t) => {
1686
- const code = (t.currency_code ?? "USD").toUpperCase();
1687
- return `${code} ${Number(t.amount)}`;
1688
- };
1689
- 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: [
1690
- /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1691
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1692
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payments" }),
1693
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
1694
- ] }),
1695
- /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
1696
- ] }),
1697
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1698
- /* @__PURE__ */ jsx(
1699
- Input,
1700
- {
1701
- placeholder: "Search by Order ID",
1702
- value: orderIdSearch,
1703
- onChange: (e) => setOrderIdSearch(e.target.value),
1704
- className: "md:max-w-sm",
1705
- "aria-label": "Search by order ID"
1706
- }
1707
- ),
1708
- /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxs(
1709
- "select",
1710
- {
1711
- value: statusFilter,
1712
- onChange: (e) => setStatusFilter(e.target.value),
1713
- className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
1714
- "aria-label": "Filter by status",
1715
- children: [
1716
- /* @__PURE__ */ jsx("option", { value: "all", children: "All statuses" }),
1717
- /* @__PURE__ */ jsx("option", { value: "pending", children: "Pending" }),
1718
- /* @__PURE__ */ jsx("option", { value: "requires_more", children: "Requires more" }),
1719
- /* @__PURE__ */ jsx("option", { value: "error", children: "Error" }),
1720
- /* @__PURE__ */ jsx("option", { value: "canceled", children: "Canceled" }),
1721
- /* @__PURE__ */ jsx("option", { value: "authorized", children: "Authorized" }),
1722
- /* @__PURE__ */ jsx("option", { value: "captured", children: "Captured" })
1723
- ]
1724
- }
1725
- ) })
1726
- ] }),
1833
+ if (!id) {
1834
+ setLoading(false);
1835
+ return;
1836
+ }
1837
+ let cancelled = false;
1838
+ setLoading(true);
1839
+ setError(null);
1840
+ fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
1841
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
1842
+ return res.json();
1843
+ }).then((data) => {
1844
+ if (!cancelled) setDetail(data);
1845
+ }).catch((e) => {
1846
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
1847
+ }).finally(() => {
1848
+ if (!cancelled) setLoading(false);
1849
+ });
1850
+ return () => {
1851
+ cancelled = true;
1852
+ };
1853
+ }, [id]);
1854
+ const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
1855
+ const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
1856
+ const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
1857
+ const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
1858
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
1859
+ /* @__PURE__ */ jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1860
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
1861
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payment session" }),
1862
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
1863
+ ] }) }),
1727
1864
  error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1728
1865
  /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1729
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
1730
- ] }) : null,
1731
- isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1732
- /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
1733
- /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
1734
- ] }) : /* @__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: [
1735
- /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
1736
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1737
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1738
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1739
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1740
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
1741
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1742
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1866
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
1867
+ ] }) : loading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
1868
+ /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1869
+ /* @__PURE__ */ jsxs("div", { children: [
1870
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
1871
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsx(
1872
+ Button,
1873
+ {
1874
+ variant: "transparent",
1875
+ size: "small",
1876
+ onClick: () => navigate(`/orders/${detail.order_id}`),
1877
+ children: detail.order_id
1878
+ }
1879
+ ) : /* @__PURE__ */ jsx(Text, { children: "" }) })
1880
+ ] }),
1881
+ /* @__PURE__ */ jsxs("div", { children: [
1882
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
1883
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: displayAmount })
1884
+ ] }),
1885
+ /* @__PURE__ */ jsxs("div", { children: [
1886
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
1887
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.provider_id })
1888
+ ] }),
1889
+ /* @__PURE__ */ jsxs("div", { children: [
1890
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
1891
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
1892
+ Badge,
1893
+ {
1894
+ size: "2xsmall",
1895
+ className: `uppercase ${getStatusBadgeClass$3(displayStatus)}`,
1896
+ children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
1897
+ }
1898
+ ) })
1899
+ ] }),
1900
+ /* @__PURE__ */ jsxs("div", { children: [
1901
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
1902
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: sessionStatusRaw })
1903
+ ] }),
1904
+ /* @__PURE__ */ jsxs("div", { children: [
1905
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
1906
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: paymentStatusRaw })
1907
+ ] }),
1908
+ /* @__PURE__ */ jsxs("div", { children: [
1909
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
1910
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
1911
+ ] }),
1912
+ /* @__PURE__ */ jsxs("div", { children: [
1913
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
1914
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
1915
+ year: "numeric",
1916
+ month: "short",
1917
+ day: "numeric",
1918
+ hour: "numeric",
1919
+ minute: "2-digit",
1920
+ hour12: true
1921
+ }) })
1922
+ ] })
1743
1923
  ] }) }),
1744
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxs(
1745
- "tr",
1746
- {
1747
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1748
- onClick: () => navigate(`/payments/${t.payment_session_id}`),
1749
- children: [
1750
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
1751
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
1752
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
1753
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1754
- Badge,
1755
- {
1756
- size: "2xsmall",
1757
- className: `uppercase ${getStatusBadgeClass$4(displayStatus(t))}`,
1758
- children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1759
- }
1760
- ) }),
1761
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1762
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1763
- year: "numeric",
1764
- month: "short",
1765
- day: "numeric",
1766
- hour: "numeric",
1767
- minute: "2-digit",
1768
- hour12: true
1769
- }) }),
1770
- /* @__PURE__ */ jsxs("td", { className: "px-4 py-4", children: [
1771
- /* @__PURE__ */ jsx(
1772
- Button,
1773
- {
1774
- variant: "transparent",
1775
- size: "small",
1776
- onClick: (e) => {
1777
- e.stopPropagation();
1778
- navigate(`/payments/${t.payment_session_id}`);
1779
- },
1780
- children: "View details"
1781
- }
1782
- ),
1783
- t.order_id ? /* @__PURE__ */ jsx(
1784
- Button,
1785
- {
1786
- variant: "transparent",
1787
- size: "small",
1788
- onClick: (e) => {
1789
- e.stopPropagation();
1790
- navigate(`/orders/${t.order_id}`);
1791
- },
1792
- children: "Order"
1793
- }
1794
- ) : null
1795
- ] })
1796
- ]
1797
- },
1798
- t.payment_session_id
1799
- )) })
1800
- ] }) }),
1801
- hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
1802
- Button,
1803
- {
1804
- variant: "secondary",
1805
- isLoading: isFetchingMore,
1806
- onClick: () => loadTransactions(offset, false),
1807
- children: "Load more"
1808
- }
1809
- ) }) : null
1924
+ Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1925
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
1926
+ /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.data, null, 2) })
1927
+ ] }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
1928
+ ] }) : null
1810
1929
  ] }) });
1811
1930
  };
1812
- const config$4 = defineRouteConfig({
1813
- label: "Payments",
1931
+ const config$3 = defineRouteConfig({
1932
+ label: "Payment details",
1814
1933
  icon: CreditCard
1815
1934
  });
1816
- const getStatusBadgeClass$3 = (status) => {
1935
+ const getStatusBadgeClass$2 = (status) => {
1817
1936
  const s2 = status.toLowerCase();
1818
1937
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1819
1938
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1924,7 +2043,7 @@ const RefundDetailPage = () => {
1924
2043
  Badge,
1925
2044
  {
1926
2045
  size: "2xsmall",
1927
- className: `uppercase ${getStatusBadgeClass$3(paymentStatus)}`,
2046
+ className: `uppercase ${getStatusBadgeClass$2(paymentStatus)}`,
1928
2047
  children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
1929
2048
  }
1930
2049
  ) })
@@ -2001,11 +2120,11 @@ const RefundDetailPage = () => {
2001
2120
  ] }) : null
2002
2121
  ] }) });
2003
2122
  };
2004
- const config$3 = defineRouteConfig({
2123
+ const config$2 = defineRouteConfig({
2005
2124
  label: "Refund details",
2006
2125
  icon: Receipt
2007
2126
  });
2008
- const getStatusBadgeClass$2 = (status) => {
2127
+ const getStatusBadgeClass$1 = (status) => {
2009
2128
  const statusLower = status.toLowerCase();
2010
2129
  if (statusLower === "requested") {
2011
2130
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2016,109 +2135,105 @@ const getStatusBadgeClass$2 = (status) => {
2016
2135
  if (statusLower === "rejected") {
2017
2136
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
2018
2137
  }
2138
+ if (statusLower === "received") {
2139
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2140
+ }
2141
+ if (statusLower === "refunded") {
2142
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2143
+ }
2019
2144
  if (statusLower === "completed") {
2020
2145
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
2021
2146
  }
2022
- if (statusLower === "cancelled" || statusLower === "canceled") {
2147
+ if (statusLower === "cancelled") {
2023
2148
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2024
2149
  }
2025
- if (statusLower === "pending") {
2026
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2027
- }
2028
2150
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2029
2151
  };
2030
- const SwapDetailPage = () => {
2031
- var _a, _b, _c;
2152
+ const ReturnDetailPage = () => {
2153
+ var _a, _b;
2032
2154
  const navigate = useNavigate();
2033
2155
  const { id } = useParams();
2034
- const [swap, setSwap] = useState(null);
2035
- const [order, setOrder] = useState(null);
2156
+ const [returnOrder, setReturnOrder] = useState(null);
2036
2157
  const [isLoading, setIsLoading] = useState(true);
2037
- useState(false);
2038
- const [isCancelling, setIsCancelling] = useState(false);
2158
+ const [isRejecting, setIsRejecting] = useState(false);
2039
2159
  const [error, setError] = useState(null);
2040
2160
  const [updateError, setUpdateError] = useState(null);
2041
2161
  const [updateSuccess, setUpdateSuccess] = useState(false);
2042
2162
  useEffect(() => {
2043
2163
  if (!id) {
2044
- navigate("/swaps");
2164
+ navigate("/returns");
2045
2165
  return;
2046
2166
  }
2047
- const loadSwap = async () => {
2167
+ const loadReturn = async () => {
2048
2168
  try {
2049
2169
  setIsLoading(true);
2050
2170
  setError(null);
2051
- const response = await fetch(`/admin/swaps/${id}`, {
2171
+ const response = await fetch(`/admin/returns/${id}`, {
2052
2172
  credentials: "include"
2053
2173
  });
2054
2174
  if (!response.ok) {
2055
2175
  const message = await response.text();
2056
- throw new Error(message || "Unable to load swap");
2176
+ throw new Error(message || "Unable to load return order");
2057
2177
  }
2058
2178
  const payload = await response.json();
2059
- setSwap(payload.swap);
2060
- setOrder(payload.order || null);
2179
+ setReturnOrder(payload.return);
2061
2180
  } catch (loadError) {
2062
- const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
2181
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2063
2182
  setError(message);
2064
2183
  } finally {
2065
2184
  setIsLoading(false);
2066
2185
  }
2067
2186
  };
2068
- void loadSwap();
2187
+ void loadReturn();
2069
2188
  }, [id, navigate]);
2070
- const handleCancelExchange = async () => {
2189
+ const handleReject = async () => {
2071
2190
  if (!id) {
2072
2191
  return;
2073
2192
  }
2074
2193
  try {
2075
- setIsCancelling(true);
2194
+ setIsRejecting(true);
2076
2195
  setUpdateError(null);
2077
2196
  setUpdateSuccess(false);
2078
- const response = await fetch(`/admin/swaps/${id}/cancel`, {
2197
+ const response = await fetch(`/admin/returns/${id}/reject`, {
2079
2198
  method: "POST",
2080
2199
  headers: {
2081
2200
  "Content-Type": "application/json"
2082
2201
  },
2083
- credentials: "include"
2202
+ credentials: "include",
2203
+ body: JSON.stringify({ reason: "Rejected by admin" })
2084
2204
  });
2085
2205
  if (!response.ok) {
2086
2206
  const message = await response.text();
2087
- throw new Error(message || "Unable to cancel exchange");
2207
+ throw new Error(message || "Unable to reject return");
2088
2208
  }
2089
2209
  const payload = await response.json();
2090
- setSwap(payload.swap);
2210
+ setReturnOrder(payload.return);
2091
2211
  setUpdateSuccess(true);
2092
2212
  setTimeout(() => setUpdateSuccess(false), 3e3);
2093
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
2213
+ const detailResponse = await fetch(`/admin/returns/${id}`, {
2094
2214
  credentials: "include"
2095
2215
  });
2096
2216
  if (detailResponse.ok) {
2097
2217
  const detailPayload = await detailResponse.json();
2098
- setSwap(detailPayload.swap);
2099
- setOrder(detailPayload.order || null);
2218
+ setReturnOrder(detailPayload.return);
2100
2219
  }
2101
- } catch (cancelErr) {
2102
- const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
2220
+ } catch (updateErr) {
2221
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2103
2222
  setUpdateError(message);
2104
2223
  } finally {
2105
- setIsCancelling(false);
2224
+ setIsRejecting(false);
2106
2225
  }
2107
2226
  };
2108
- const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
2109
- const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
2110
- ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
2111
- );
2112
2227
  if (isLoading) {
2113
- 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..." }) }) }) });
2228
+ 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..." }) }) }) });
2114
2229
  }
2115
- if (error || !swap) {
2230
+ if (error || !returnOrder) {
2116
2231
  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: [
2117
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
2118
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
2232
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
2233
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2119
2234
  ] }) }) });
2120
2235
  }
2121
- const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
2236
+ const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2122
2237
  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: [
2123
2238
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
2124
2239
  /* @__PURE__ */ jsxs(
@@ -2126,7 +2241,7 @@ const SwapDetailPage = () => {
2126
2241
  {
2127
2242
  variant: "transparent",
2128
2243
  size: "small",
2129
- onClick: () => navigate("/swaps"),
2244
+ onClick: () => navigate("/returns"),
2130
2245
  className: "w-fit",
2131
2246
  children: [
2132
2247
  /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
@@ -2136,67 +2251,81 @@ const SwapDetailPage = () => {
2136
2251
  ),
2137
2252
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2138
2253
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2139
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Exchange Details" }),
2140
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
2254
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Order Details" }),
2255
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2141
2256
  ] }),
2142
2257
  /* @__PURE__ */ jsx(
2143
2258
  Badge,
2144
2259
  {
2145
2260
  size: "small",
2146
- className: `uppercase ${getStatusBadgeClass$2(swap.status)}`,
2147
- children: swap.status.replace(/_/g, " ")
2261
+ className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
2262
+ children: returnOrder.status.replace(/_/g, " ")
2148
2263
  }
2149
2264
  )
2150
2265
  ] })
2151
2266
  ] }),
2152
- canCancelExchange && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2267
+ returnOrder.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2153
2268
  /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsx(
2154
2269
  Button,
2155
2270
  {
2156
2271
  variant: "danger",
2157
- onClick: handleCancelExchange,
2158
- disabled: isCancelling,
2159
- isLoading: isCancelling,
2160
- children: "Cancel Exchange"
2272
+ onClick: handleReject,
2273
+ disabled: isRejecting,
2274
+ isLoading: isRejecting,
2275
+ children: "Reject (Cancel) Return"
2161
2276
  }
2162
2277
  ) }),
2163
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
2278
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
2164
2279
  ] }),
2165
- /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2166
- /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2167
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
2168
- /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2169
- /* @__PURE__ */ jsxs("div", { children: [
2170
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2171
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.id })
2172
- ] }),
2173
- /* @__PURE__ */ jsxs("div", { children: [
2174
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2175
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.status })
2176
- ] }),
2177
- /* @__PURE__ */ jsxs("div", { children: [
2178
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
2179
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
2280
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2281
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
2282
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2283
+ /* @__PURE__ */ jsxs("div", { children: [
2284
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2285
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2286
+ ] }),
2287
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
2288
+ Button,
2289
+ {
2290
+ variant: "secondary",
2291
+ onClick: () => {
2292
+ window.open(
2293
+ `/app/orders/${returnOrder.order_id}`,
2294
+ "_blank"
2295
+ );
2296
+ },
2297
+ children: "View order"
2298
+ }
2299
+ ) })
2300
+ ] })
2301
+ ] }),
2302
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2303
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2304
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2305
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2306
+ /* @__PURE__ */ jsxs("div", { children: [
2307
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2308
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2180
2309
  ] }),
2181
- swap.reason && /* @__PURE__ */ jsxs("div", { children: [
2310
+ /* @__PURE__ */ jsxs("div", { children: [
2311
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2312
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.status })
2313
+ ] }),
2314
+ returnOrder.reason && /* @__PURE__ */ jsxs("div", { children: [
2182
2315
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2183
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.reason })
2316
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.reason })
2184
2317
  ] }),
2185
- swap.note && /* @__PURE__ */ jsxs("div", { children: [
2318
+ returnOrder.note && /* @__PURE__ */ jsxs("div", { children: [
2186
2319
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2187
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.note })
2320
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.note })
2188
2321
  ] }),
2189
2322
  /* @__PURE__ */ jsxs("div", { children: [
2190
2323
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2191
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2324
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2192
2325
  ] }),
2193
2326
  /* @__PURE__ */ jsxs("div", { children: [
2194
2327
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2195
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2196
- ] }),
2197
- swap.exchange_id && /* @__PURE__ */ jsxs("div", { children: [
2198
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2199
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.exchange_id })
2328
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2200
2329
  ] })
2201
2330
  ] })
2202
2331
  ] }),
@@ -2211,7 +2340,7 @@ const SwapDetailPage = () => {
2211
2340
  Badge,
2212
2341
  {
2213
2342
  size: "2xsmall",
2214
- className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2343
+ className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
2215
2344
  children: entry.status.replace(/_/g, " ")
2216
2345
  }
2217
2346
  ) }),
@@ -2226,31 +2355,31 @@ const SwapDetailPage = () => {
2226
2355
  )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2227
2356
  ] })
2228
2357
  ] }),
2229
- order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2358
+ returnOrder.order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2230
2359
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2231
2360
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2232
2361
  /* @__PURE__ */ jsxs("div", { children: [
2233
2362
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2234
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.id })
2363
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.id })
2235
2364
  ] }),
2236
2365
  /* @__PURE__ */ jsxs("div", { children: [
2237
2366
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2238
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.status || "—" })
2367
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2239
2368
  ] }),
2240
2369
  /* @__PURE__ */ jsxs("div", { children: [
2241
2370
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2242
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2371
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2243
2372
  ] }),
2244
- order.total && /* @__PURE__ */ jsxs("div", { children: [
2373
+ returnOrder.order.total && /* @__PURE__ */ jsxs("div", { children: [
2245
2374
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2246
2375
  /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
2247
- order.currency_code || "$",
2248
- (Number(order.total) / 100).toFixed(2)
2376
+ returnOrder.order.currency_code || "$",
2377
+ (Number(returnOrder.order.total) / 100).toFixed(2)
2249
2378
  ] })
2250
2379
  ] })
2251
2380
  ] })
2252
2381
  ] }),
2253
- 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: [
2382
+ 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: [
2254
2383
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2255
2384
  /* @__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: [
2256
2385
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
@@ -2258,33 +2387,22 @@ const SwapDetailPage = () => {
2258
2387
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2259
2388
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2260
2389
  ] }) }),
2261
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2390
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2262
2391
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2263
2392
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2264
2393
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2265
2394
  ] }, item.id || index)) })
2266
2395
  ] }) })
2267
2396
  ] }),
2268
- 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: [
2269
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2270
- /* @__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: [
2271
- /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
2272
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2273
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2274
- ] }) }),
2275
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2276
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2277
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2278
- ] }, item.variant_id || index)) })
2279
- ] }) })
2280
- ] })
2397
+ 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 }) }),
2398
+ 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" }) })
2281
2399
  ] }) });
2282
2400
  };
2283
- const config$2 = defineRouteConfig({
2284
- label: "Swap Details",
2285
- icon: ArrowPath
2401
+ const config$1 = defineRouteConfig({
2402
+ label: "Return Order Details",
2403
+ icon: CheckCircle
2286
2404
  });
2287
- const getStatusBadgeClass$1 = (status) => {
2405
+ const getStatusBadgeClass = (status) => {
2288
2406
  const statusLower = status.toLowerCase();
2289
2407
  if (statusLower === "requested") {
2290
2408
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2295,105 +2413,109 @@ const getStatusBadgeClass$1 = (status) => {
2295
2413
  if (statusLower === "rejected") {
2296
2414
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
2297
2415
  }
2298
- if (statusLower === "received") {
2299
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2300
- }
2301
- if (statusLower === "refunded") {
2302
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
2303
- }
2304
2416
  if (statusLower === "completed") {
2305
2417
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
2306
2418
  }
2307
- if (statusLower === "cancelled") {
2419
+ if (statusLower === "cancelled" || statusLower === "canceled") {
2308
2420
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2309
2421
  }
2422
+ if (statusLower === "pending") {
2423
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2424
+ }
2310
2425
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2311
2426
  };
2312
- const ReturnDetailPage = () => {
2313
- var _a, _b;
2427
+ const SwapDetailPage = () => {
2428
+ var _a, _b, _c;
2314
2429
  const navigate = useNavigate();
2315
2430
  const { id } = useParams();
2316
- const [returnOrder, setReturnOrder] = useState(null);
2431
+ const [swap, setSwap] = useState(null);
2432
+ const [order, setOrder] = useState(null);
2317
2433
  const [isLoading, setIsLoading] = useState(true);
2318
- const [isRejecting, setIsRejecting] = useState(false);
2434
+ useState(false);
2435
+ const [isCancelling, setIsCancelling] = useState(false);
2319
2436
  const [error, setError] = useState(null);
2320
2437
  const [updateError, setUpdateError] = useState(null);
2321
2438
  const [updateSuccess, setUpdateSuccess] = useState(false);
2322
2439
  useEffect(() => {
2323
2440
  if (!id) {
2324
- navigate("/returns");
2441
+ navigate("/swaps");
2325
2442
  return;
2326
2443
  }
2327
- const loadReturn = async () => {
2444
+ const loadSwap = async () => {
2328
2445
  try {
2329
2446
  setIsLoading(true);
2330
2447
  setError(null);
2331
- const response = await fetch(`/admin/returns/${id}`, {
2448
+ const response = await fetch(`/admin/swaps/${id}`, {
2332
2449
  credentials: "include"
2333
2450
  });
2334
2451
  if (!response.ok) {
2335
2452
  const message = await response.text();
2336
- throw new Error(message || "Unable to load return order");
2453
+ throw new Error(message || "Unable to load swap");
2337
2454
  }
2338
2455
  const payload = await response.json();
2339
- setReturnOrder(payload.return);
2456
+ setSwap(payload.swap);
2457
+ setOrder(payload.order || null);
2340
2458
  } catch (loadError) {
2341
- const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2459
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
2342
2460
  setError(message);
2343
2461
  } finally {
2344
2462
  setIsLoading(false);
2345
2463
  }
2346
2464
  };
2347
- void loadReturn();
2465
+ void loadSwap();
2348
2466
  }, [id, navigate]);
2349
- const handleReject = async () => {
2467
+ const handleCancelExchange = async () => {
2350
2468
  if (!id) {
2351
2469
  return;
2352
2470
  }
2353
2471
  try {
2354
- setIsRejecting(true);
2472
+ setIsCancelling(true);
2355
2473
  setUpdateError(null);
2356
2474
  setUpdateSuccess(false);
2357
- const response = await fetch(`/admin/returns/${id}/reject`, {
2475
+ const response = await fetch(`/admin/swaps/${id}/cancel`, {
2358
2476
  method: "POST",
2359
2477
  headers: {
2360
2478
  "Content-Type": "application/json"
2361
2479
  },
2362
- credentials: "include",
2363
- body: JSON.stringify({ reason: "Rejected by admin" })
2480
+ credentials: "include"
2364
2481
  });
2365
2482
  if (!response.ok) {
2366
2483
  const message = await response.text();
2367
- throw new Error(message || "Unable to reject return");
2484
+ throw new Error(message || "Unable to cancel exchange");
2368
2485
  }
2369
2486
  const payload = await response.json();
2370
- setReturnOrder(payload.return);
2487
+ setSwap(payload.swap);
2371
2488
  setUpdateSuccess(true);
2372
2489
  setTimeout(() => setUpdateSuccess(false), 3e3);
2373
- const detailResponse = await fetch(`/admin/returns/${id}`, {
2490
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
2374
2491
  credentials: "include"
2375
2492
  });
2376
2493
  if (detailResponse.ok) {
2377
2494
  const detailPayload = await detailResponse.json();
2378
- setReturnOrder(detailPayload.return);
2495
+ setSwap(detailPayload.swap);
2496
+ setOrder(detailPayload.order || null);
2379
2497
  }
2380
- } catch (updateErr) {
2381
- const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2498
+ } catch (cancelErr) {
2499
+ const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
2382
2500
  setUpdateError(message);
2383
2501
  } finally {
2384
- setIsRejecting(false);
2502
+ setIsCancelling(false);
2385
2503
  }
2386
2504
  };
2505
+ const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
2506
+ const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
2507
+ ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
2508
+ );
2387
2509
  if (isLoading) {
2388
- 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..." }) }) }) });
2510
+ 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..." }) }) }) });
2389
2511
  }
2390
- if (error || !returnOrder) {
2512
+ if (error || !swap) {
2391
2513
  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: [
2392
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
2393
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2514
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
2515
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
2394
2516
  ] }) }) });
2395
2517
  }
2396
- const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2518
+ const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
2397
2519
  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: [
2398
2520
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
2399
2521
  /* @__PURE__ */ jsxs(
@@ -2401,7 +2523,7 @@ const ReturnDetailPage = () => {
2401
2523
  {
2402
2524
  variant: "transparent",
2403
2525
  size: "small",
2404
- onClick: () => navigate("/returns"),
2526
+ onClick: () => navigate("/swaps"),
2405
2527
  className: "w-fit",
2406
2528
  children: [
2407
2529
  /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
@@ -2411,81 +2533,67 @@ const ReturnDetailPage = () => {
2411
2533
  ),
2412
2534
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2413
2535
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2414
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Order Details" }),
2415
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2536
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Exchange Details" }),
2537
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
2416
2538
  ] }),
2417
2539
  /* @__PURE__ */ jsx(
2418
2540
  Badge,
2419
2541
  {
2420
2542
  size: "small",
2421
- className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
2422
- children: returnOrder.status.replace(/_/g, " ")
2543
+ className: `uppercase ${getStatusBadgeClass(swap.status)}`,
2544
+ children: swap.status.replace(/_/g, " ")
2423
2545
  }
2424
2546
  )
2425
2547
  ] })
2426
2548
  ] }),
2427
- returnOrder.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2549
+ canCancelExchange && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2428
2550
  /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsx(
2429
2551
  Button,
2430
2552
  {
2431
2553
  variant: "danger",
2432
- onClick: handleReject,
2433
- disabled: isRejecting,
2434
- isLoading: isRejecting,
2435
- children: "Reject (Cancel) Return"
2554
+ onClick: handleCancelExchange,
2555
+ disabled: isCancelling,
2556
+ isLoading: isCancelling,
2557
+ children: "Cancel Exchange"
2436
2558
  }
2437
2559
  ) }),
2438
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
2439
- ] }),
2440
- /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2441
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
2442
- /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2443
- /* @__PURE__ */ jsxs("div", { children: [
2444
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2445
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2446
- ] }),
2447
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
2448
- Button,
2449
- {
2450
- variant: "secondary",
2451
- onClick: () => {
2452
- window.open(
2453
- `/app/orders/${returnOrder.order_id}`,
2454
- "_blank"
2455
- );
2456
- },
2457
- children: "View order"
2458
- }
2459
- ) })
2460
- ] })
2560
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
2461
2561
  ] }),
2462
2562
  /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2463
2563
  /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2464
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2564
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
2465
2565
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2466
2566
  /* @__PURE__ */ jsxs("div", { children: [
2467
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2468
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2567
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2568
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.id })
2469
2569
  ] }),
2470
2570
  /* @__PURE__ */ jsxs("div", { children: [
2471
2571
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2472
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.status })
2572
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.status })
2473
2573
  ] }),
2474
- returnOrder.reason && /* @__PURE__ */ jsxs("div", { children: [
2574
+ /* @__PURE__ */ jsxs("div", { children: [
2575
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
2576
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
2577
+ ] }),
2578
+ swap.reason && /* @__PURE__ */ jsxs("div", { children: [
2475
2579
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2476
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.reason })
2580
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.reason })
2477
2581
  ] }),
2478
- returnOrder.note && /* @__PURE__ */ jsxs("div", { children: [
2582
+ swap.note && /* @__PURE__ */ jsxs("div", { children: [
2479
2583
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2480
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.note })
2584
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.note })
2481
2585
  ] }),
2482
2586
  /* @__PURE__ */ jsxs("div", { children: [
2483
2587
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2484
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2588
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2485
2589
  ] }),
2486
2590
  /* @__PURE__ */ jsxs("div", { children: [
2487
2591
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2488
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2592
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2593
+ ] }),
2594
+ swap.exchange_id && /* @__PURE__ */ jsxs("div", { children: [
2595
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2596
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.exchange_id })
2489
2597
  ] })
2490
2598
  ] })
2491
2599
  ] }),
@@ -2500,7 +2608,7 @@ const ReturnDetailPage = () => {
2500
2608
  Badge,
2501
2609
  {
2502
2610
  size: "2xsmall",
2503
- className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
2611
+ className: `uppercase ${getStatusBadgeClass(entry.status)}`,
2504
2612
  children: entry.status.replace(/_/g, " ")
2505
2613
  }
2506
2614
  ) }),
@@ -2515,31 +2623,31 @@ const ReturnDetailPage = () => {
2515
2623
  )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2516
2624
  ] })
2517
2625
  ] }),
2518
- returnOrder.order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2626
+ order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2519
2627
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2520
2628
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2521
2629
  /* @__PURE__ */ jsxs("div", { children: [
2522
2630
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2523
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.id })
2631
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.id })
2524
2632
  ] }),
2525
2633
  /* @__PURE__ */ jsxs("div", { children: [
2526
2634
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2527
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2635
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.status || "—" })
2528
2636
  ] }),
2529
2637
  /* @__PURE__ */ jsxs("div", { children: [
2530
2638
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2531
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2639
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2532
2640
  ] }),
2533
- returnOrder.order.total && /* @__PURE__ */ jsxs("div", { children: [
2641
+ order.total && /* @__PURE__ */ jsxs("div", { children: [
2534
2642
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2535
2643
  /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
2536
- returnOrder.order.currency_code || "$",
2537
- (Number(returnOrder.order.total) / 100).toFixed(2)
2644
+ order.currency_code || "$",
2645
+ (Number(order.total) / 100).toFixed(2)
2538
2646
  ] })
2539
2647
  ] })
2540
2648
  ] })
2541
2649
  ] }),
2542
- 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: [
2650
+ 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: [
2543
2651
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2544
2652
  /* @__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: [
2545
2653
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
@@ -2547,139 +2655,31 @@ const ReturnDetailPage = () => {
2547
2655
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2548
2656
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2549
2657
  ] }) }),
2550
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2658
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2551
2659
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2552
2660
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2553
2661
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2554
2662
  ] }, item.id || index)) })
2555
2663
  ] }) })
2556
2664
  ] }),
2557
- 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 }) }),
2558
- 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" }) })
2559
- ] }) });
2560
- };
2561
- const config$1 = defineRouteConfig({
2562
- label: "Return Order Details",
2563
- icon: CheckCircle
2564
- });
2565
- const getStatusBadgeClass = (status) => {
2566
- const s2 = status.toLowerCase();
2567
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2568
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2569
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2570
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2571
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2572
- };
2573
- const PaymentDetailPage = () => {
2574
- var _a;
2575
- const navigate = useNavigate();
2576
- const params = useParams();
2577
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2578
- const [detail, setDetail] = useState(null);
2579
- const [loading, setLoading] = useState(!!id);
2580
- const [error, setError] = useState(null);
2581
- useEffect(() => {
2582
- if (!id) {
2583
- setLoading(false);
2584
- return;
2585
- }
2586
- let cancelled = false;
2587
- setLoading(true);
2588
- setError(null);
2589
- fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2590
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2591
- return res.json();
2592
- }).then((data) => {
2593
- if (!cancelled) setDetail(data);
2594
- }).catch((e) => {
2595
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2596
- }).finally(() => {
2597
- if (!cancelled) setLoading(false);
2598
- });
2599
- return () => {
2600
- cancelled = true;
2601
- };
2602
- }, [id]);
2603
- const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
2604
- const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
2605
- const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
2606
- const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
2607
- return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
2608
- /* @__PURE__ */ jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2609
- /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
2610
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payment session" }),
2611
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
2612
- ] }) }),
2613
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2614
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2615
- /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
2616
- ] }) : loading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
2617
- /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2618
- /* @__PURE__ */ jsxs("div", { children: [
2619
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
2620
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsx(
2621
- Button,
2622
- {
2623
- variant: "transparent",
2624
- size: "small",
2625
- onClick: () => navigate(`/orders/${detail.order_id}`),
2626
- children: detail.order_id
2627
- }
2628
- ) : /* @__PURE__ */ jsx(Text, { children: "—" }) })
2629
- ] }),
2630
- /* @__PURE__ */ jsxs("div", { children: [
2631
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2632
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: displayAmount })
2633
- ] }),
2634
- /* @__PURE__ */ jsxs("div", { children: [
2635
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2636
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.provider_id })
2637
- ] }),
2638
- /* @__PURE__ */ jsxs("div", { children: [
2639
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2640
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2641
- Badge,
2642
- {
2643
- size: "2xsmall",
2644
- className: `uppercase ${getStatusBadgeClass(displayStatus)}`,
2645
- children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2646
- }
2647
- ) })
2648
- ] }),
2649
- /* @__PURE__ */ jsxs("div", { children: [
2650
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
2651
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: sessionStatusRaw })
2652
- ] }),
2653
- /* @__PURE__ */ jsxs("div", { children: [
2654
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
2655
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: paymentStatusRaw })
2656
- ] }),
2657
- /* @__PURE__ */ jsxs("div", { children: [
2658
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
2659
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
2660
- ] }),
2661
- /* @__PURE__ */ jsxs("div", { children: [
2662
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
2663
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2664
- year: "numeric",
2665
- month: "short",
2666
- day: "numeric",
2667
- hour: "numeric",
2668
- minute: "2-digit",
2669
- hour12: true
2670
- }) })
2671
- ] })
2672
- ] }) }),
2673
- Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2674
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2675
- /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.data, null, 2) })
2676
- ] }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
2677
- ] }) : null
2665
+ 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: [
2666
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2667
+ /* @__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: [
2668
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
2669
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2670
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2671
+ ] }) }),
2672
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2673
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2674
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2675
+ ] }, item.variant_id || index)) })
2676
+ ] }) })
2677
+ ] })
2678
2678
  ] }) });
2679
2679
  };
2680
2680
  const config = defineRouteConfig({
2681
- label: "Payment details",
2682
- icon: CreditCard
2681
+ label: "Swap Details",
2682
+ icon: ArrowPath
2683
2683
  });
2684
2684
  const i18nTranslations0 = {};
2685
2685
  const widgetModule = { widgets: [
@@ -2695,47 +2695,41 @@ const widgetModule = { widgets: [
2695
2695
  const routeModule = {
2696
2696
  routes: [
2697
2697
  {
2698
- Component: RefundsPage,
2699
- path: "/refunds"
2698
+ Component: PaymentsPage,
2699
+ path: "/payments"
2700
2700
  },
2701
2701
  {
2702
- Component: SwapsPage,
2703
- path: "/swaps"
2702
+ Component: RefundsPage,
2703
+ path: "/refunds"
2704
2704
  },
2705
2705
  {
2706
2706
  Component: ReturnsPage,
2707
2707
  path: "/returns"
2708
2708
  },
2709
2709
  {
2710
- Component: PaymentsPage,
2711
- path: "/payments"
2710
+ Component: SwapsPage,
2711
+ path: "/swaps"
2712
2712
  },
2713
2713
  {
2714
- Component: RefundDetailPage,
2715
- path: "/refunds/:id"
2714
+ Component: PaymentDetailPage,
2715
+ path: "/payments/:id"
2716
2716
  },
2717
2717
  {
2718
- Component: SwapDetailPage,
2719
- path: "/swaps/:id"
2718
+ Component: RefundDetailPage,
2719
+ path: "/refunds/:id"
2720
2720
  },
2721
2721
  {
2722
2722
  Component: ReturnDetailPage,
2723
2723
  path: "/returns/:id"
2724
2724
  },
2725
2725
  {
2726
- Component: PaymentDetailPage,
2727
- path: "/payments/:id"
2726
+ Component: SwapDetailPage,
2727
+ path: "/swaps/:id"
2728
2728
  }
2729
2729
  ]
2730
2730
  };
2731
2731
  const menuItemModule = {
2732
2732
  menuItems: [
2733
- {
2734
- label: config$4.label,
2735
- icon: config$4.icon,
2736
- path: "/payments",
2737
- nested: void 0
2738
- },
2739
2733
  {
2740
2734
  label: config$5.label,
2741
2735
  icon: config$5.icon,
@@ -2743,21 +2737,21 @@ const menuItemModule = {
2743
2737
  nested: void 0
2744
2738
  },
2745
2739
  {
2746
- label: config$7.label,
2747
- icon: config$7.icon,
2748
- path: "/refunds",
2740
+ label: config$4.label,
2741
+ icon: config$4.icon,
2742
+ path: "/swaps",
2749
2743
  nested: void 0
2750
2744
  },
2751
2745
  {
2752
2746
  label: config$6.label,
2753
2747
  icon: config$6.icon,
2754
- path: "/swaps",
2748
+ path: "/refunds",
2755
2749
  nested: void 0
2756
2750
  },
2757
2751
  {
2758
- label: config.label,
2759
- icon: config.icon,
2760
- path: "/payments/:id",
2752
+ label: config$7.label,
2753
+ icon: config$7.icon,
2754
+ path: "/payments",
2761
2755
  nested: void 0
2762
2756
  },
2763
2757
  {
@@ -2767,15 +2761,21 @@ const menuItemModule = {
2767
2761
  nested: void 0
2768
2762
  },
2769
2763
  {
2770
- label: config$3.label,
2771
- icon: config$3.icon,
2772
- path: "/refunds/:id",
2764
+ label: config.label,
2765
+ icon: config.icon,
2766
+ path: "/swaps/:id",
2773
2767
  nested: void 0
2774
2768
  },
2775
2769
  {
2776
2770
  label: config$2.label,
2777
2771
  icon: config$2.icon,
2778
- path: "/swaps/:id",
2772
+ path: "/refunds/:id",
2773
+ nested: void 0
2774
+ },
2775
+ {
2776
+ label: config$3.label,
2777
+ icon: config$3.icon,
2778
+ path: "/payments/:id",
2779
2779
  nested: void 0
2780
2780
  }
2781
2781
  ]