order-management 0.0.84 → 0.0.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { 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, ArrowPath, CreditCard, Receipt, CheckCircle, ArrowLeft } from "@medusajs/icons";
5
+ import { CashSolid, PencilSquareSolid, Trash, ArrowPath, CreditCard, Receipt, ArrowLeft, CheckCircle } 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();
@@ -865,6 +865,236 @@ const useDebounce$3 = (value, delay) => {
865
865
  return debouncedValue;
866
866
  };
867
867
  const getStatusBadgeClass$7 = (status) => {
868
+ const statusLower = status.toLowerCase();
869
+ if (statusLower === "requested") {
870
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
871
+ }
872
+ if (statusLower === "approved") {
873
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
874
+ }
875
+ if (statusLower === "rejected") {
876
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
877
+ }
878
+ if (statusLower === "completed") {
879
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
880
+ }
881
+ if (statusLower === "cancelled") {
882
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
883
+ }
884
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
885
+ };
886
+ const SwapsPage = () => {
887
+ const navigate = useNavigate();
888
+ const [items, setItems] = useState([]);
889
+ const [statusFilter, setStatusFilter] = useState("all");
890
+ const [createdByFilter, setCreatedByFilter] = useState("all");
891
+ const [searchQuery, setSearchQuery] = useState("");
892
+ const debouncedSearchQuery = useDebounce$3(searchQuery, 300);
893
+ const [isLoading, setIsLoading] = useState(true);
894
+ const [isFetchingMore, setIsFetchingMore] = useState(false);
895
+ const [error, setError] = useState(null);
896
+ const [offset, setOffset] = useState(0);
897
+ const [count, setCount] = useState(0);
898
+ const limit = 50;
899
+ const loadSwaps = useCallback(
900
+ async (nextOffset, replace = false) => {
901
+ var _a;
902
+ try {
903
+ if (replace) {
904
+ setIsLoading(true);
905
+ } else {
906
+ setIsFetchingMore(true);
907
+ }
908
+ setError(null);
909
+ const params = new URLSearchParams();
910
+ params.set("limit", String(limit));
911
+ params.set("offset", String(nextOffset));
912
+ if (statusFilter !== "all") {
913
+ params.set("status", statusFilter);
914
+ }
915
+ if (debouncedSearchQuery.trim()) {
916
+ params.set("order_id", debouncedSearchQuery.trim());
917
+ }
918
+ if (createdByFilter !== "all") {
919
+ params.set("created_by", createdByFilter);
920
+ }
921
+ const response = await fetch(
922
+ `/admin/swaps?${params.toString()}`,
923
+ { credentials: "include" }
924
+ );
925
+ if (!response.ok) {
926
+ const message = await response.text();
927
+ throw new Error(message || "Unable to load swaps");
928
+ }
929
+ const payload = await response.json();
930
+ setCount(payload.count ?? 0);
931
+ setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
932
+ setItems(
933
+ (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
934
+ );
935
+ } catch (loadError) {
936
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
937
+ setError(message);
938
+ } finally {
939
+ setIsLoading(false);
940
+ setIsFetchingMore(false);
941
+ }
942
+ },
943
+ [statusFilter, createdByFilter, debouncedSearchQuery]
944
+ );
945
+ useEffect(() => {
946
+ void loadSwaps(0, true);
947
+ }, [statusFilter, createdByFilter, debouncedSearchQuery, loadSwaps]);
948
+ const hasMore = useMemo(() => offset < count, [offset, count]);
949
+ const availableStatuses = useMemo(() => {
950
+ const statuses = /* @__PURE__ */ new Set();
951
+ items.forEach((item) => statuses.add(item.status));
952
+ return Array.from(statuses).sort();
953
+ }, [items]);
954
+ 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: [
955
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
956
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
957
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Exchanges" }),
958
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer exchange requests" })
959
+ ] }),
960
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
961
+ ] }),
962
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
963
+ /* @__PURE__ */ jsx(
964
+ Input,
965
+ {
966
+ placeholder: "Search by swap ID or order ID",
967
+ value: searchQuery,
968
+ onChange: (event) => setSearchQuery(event.target.value),
969
+ className: "md:max-w-sm"
970
+ }
971
+ ),
972
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-3", children: [
973
+ /* @__PURE__ */ jsxs(
974
+ "select",
975
+ {
976
+ value: createdByFilter,
977
+ onChange: (event) => setCreatedByFilter(event.target.value),
978
+ 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",
979
+ children: [
980
+ /* @__PURE__ */ jsx("option", { value: "all", children: "All (Created by)" }),
981
+ /* @__PURE__ */ jsx("option", { value: "customer", children: "Customer" }),
982
+ /* @__PURE__ */ jsx("option", { value: "admin", children: "Admin" })
983
+ ]
984
+ }
985
+ ),
986
+ /* @__PURE__ */ jsxs(
987
+ "select",
988
+ {
989
+ value: statusFilter,
990
+ onChange: (event) => setStatusFilter(event.target.value),
991
+ 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",
992
+ children: [
993
+ /* @__PURE__ */ jsx("option", { value: "all", children: "All Statuses" }),
994
+ availableStatuses.map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
995
+ ]
996
+ }
997
+ )
998
+ ] })
999
+ ] }),
1000
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1001
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1002
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(
1003
+ Button,
1004
+ {
1005
+ variant: "secondary",
1006
+ onClick: () => loadSwaps(0, true),
1007
+ children: "Try again"
1008
+ }
1009
+ ) })
1010
+ ] }) : null,
1011
+ 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: [
1012
+ /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No exchanges yet" }),
1013
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Exchange requests created by customers will appear here." })
1014
+ ] }) : /* @__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: [
1015
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
1016
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Exchange ID" }),
1017
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1018
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1019
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Difference Due" }),
1020
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1021
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1022
+ ] }) }),
1023
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxs(
1024
+ "tr",
1025
+ {
1026
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1027
+ onClick: () => navigate(`/swaps/${swap.id}`),
1028
+ children: [
1029
+ /* @__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 }) }) }),
1030
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: swap.order_id }),
1031
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1032
+ Badge,
1033
+ {
1034
+ size: "2xsmall",
1035
+ className: `uppercase ${getStatusBadgeClass$7(swap.status)}`,
1036
+ children: swap.status.replace(/_/g, " ")
1037
+ }
1038
+ ) }),
1039
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1040
+ const amount = swap.difference_due;
1041
+ if (amount == null || amount === void 0) {
1042
+ return "—";
1043
+ }
1044
+ const displayAmount = Number(amount) / 100;
1045
+ const currency = swap.currency_code || "$";
1046
+ const sign = displayAmount >= 0 ? "+" : "";
1047
+ return `${sign}${currency}${displayAmount.toFixed(2)}`;
1048
+ })() }),
1049
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
1050
+ year: "numeric",
1051
+ month: "short",
1052
+ day: "numeric",
1053
+ hour: "numeric",
1054
+ minute: "2-digit",
1055
+ hour12: true
1056
+ }) }),
1057
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1058
+ Button,
1059
+ {
1060
+ variant: "transparent",
1061
+ size: "small",
1062
+ onClick: (e) => {
1063
+ e.stopPropagation();
1064
+ navigate(`/app/orders/${swap.order_id}`);
1065
+ },
1066
+ children: "Go to order"
1067
+ }
1068
+ ) })
1069
+ ]
1070
+ },
1071
+ swap.id
1072
+ )) })
1073
+ ] }) }),
1074
+ hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
1075
+ Button,
1076
+ {
1077
+ variant: "secondary",
1078
+ isLoading: isFetchingMore,
1079
+ onClick: () => loadSwaps(offset, false),
1080
+ children: "Load more"
1081
+ }
1082
+ ) }) : null
1083
+ ] }) });
1084
+ };
1085
+ const config$7 = defineRouteConfig({
1086
+ label: "Exchanges",
1087
+ icon: ArrowPath
1088
+ });
1089
+ const useDebounce$2 = (value, delay) => {
1090
+ const [debouncedValue, setDebouncedValue] = useState(value);
1091
+ useEffect(() => {
1092
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
1093
+ return () => clearTimeout(handler);
1094
+ }, [value, delay]);
1095
+ return debouncedValue;
1096
+ };
1097
+ const getStatusBadgeClass$6 = (status) => {
868
1098
  const statusLower = status.toLowerCase();
869
1099
  if (statusLower === "requested") {
870
1100
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -889,7 +1119,7 @@ const ReturnsPage = () => {
889
1119
  const [statusFilter, setStatusFilter] = useState("all");
890
1120
  const [createdByFilter, setCreatedByFilter] = useState("all");
891
1121
  const [searchQuery, setSearchQuery] = useState("");
892
- const debouncedSearchQuery = useDebounce$3(searchQuery, 300);
1122
+ const debouncedSearchQuery = useDebounce$2(searchQuery, 300);
893
1123
  const [isLoading, setIsLoading] = useState(true);
894
1124
  const [isFetchingMore, setIsFetchingMore] = useState(false);
895
1125
  const [error, setError] = useState(null);
@@ -1035,7 +1265,7 @@ const ReturnsPage = () => {
1035
1265
  Badge,
1036
1266
  {
1037
1267
  size: "2xsmall",
1038
- className: `uppercase ${getStatusBadgeClass$7(returnOrder.status)}`,
1268
+ className: `uppercase ${getStatusBadgeClass$6(returnOrder.status)}`,
1039
1269
  children: returnOrder.status.replace(/_/g, " ")
1040
1270
  }
1041
1271
  ) }),
@@ -1084,11 +1314,11 @@ const ReturnsPage = () => {
1084
1314
  ) }) : null
1085
1315
  ] }) });
1086
1316
  };
1087
- const config$7 = defineRouteConfig({
1317
+ const config$6 = defineRouteConfig({
1088
1318
  label: "Return Orders",
1089
1319
  icon: ArrowPath
1090
1320
  });
1091
- const useDebounce$2 = (value, delay) => {
1321
+ const useDebounce$1 = (value, delay) => {
1092
1322
  const [debouncedValue, setDebouncedValue] = useState(value);
1093
1323
  useEffect(() => {
1094
1324
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1096,7 +1326,7 @@ const useDebounce$2 = (value, delay) => {
1096
1326
  }, [value, delay]);
1097
1327
  return debouncedValue;
1098
1328
  };
1099
- const getStatusBadgeClass$6 = (status) => {
1329
+ const getStatusBadgeClass$5 = (status) => {
1100
1330
  const s2 = status.toLowerCase();
1101
1331
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1102
1332
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1109,7 +1339,7 @@ const PaymentsPage = () => {
1109
1339
  const [items, setItems] = useState([]);
1110
1340
  const [statusFilter, setStatusFilter] = useState("all");
1111
1341
  const [orderIdSearch, setOrderIdSearch] = useState("");
1112
- const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
1342
+ const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1113
1343
  const [isLoading, setIsLoading] = useState(true);
1114
1344
  const [isFetchingMore, setIsFetchingMore] = useState(false);
1115
1345
  const [error, setError] = useState(null);
@@ -1229,7 +1459,7 @@ const PaymentsPage = () => {
1229
1459
  Badge,
1230
1460
  {
1231
1461
  size: "2xsmall",
1232
- className: `uppercase ${getStatusBadgeClass$6(displayStatus(t))}`,
1462
+ className: `uppercase ${getStatusBadgeClass$5(displayStatus(t))}`,
1233
1463
  children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1234
1464
  }
1235
1465
  ) }),
@@ -1284,11 +1514,11 @@ const PaymentsPage = () => {
1284
1514
  ) }) : null
1285
1515
  ] }) });
1286
1516
  };
1287
- const config$6 = defineRouteConfig({
1517
+ const config$5 = defineRouteConfig({
1288
1518
  label: "Payments",
1289
1519
  icon: CreditCard
1290
1520
  });
1291
- const useDebounce$1 = (value, delay) => {
1521
+ const useDebounce = (value, delay) => {
1292
1522
  const [debouncedValue, setDebouncedValue] = useState(value);
1293
1523
  useEffect(() => {
1294
1524
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1296,7 +1526,7 @@ const useDebounce$1 = (value, delay) => {
1296
1526
  }, [value, delay]);
1297
1527
  return debouncedValue;
1298
1528
  };
1299
- const getStatusBadgeClass$5 = (status) => {
1529
+ const getStatusBadgeClass$4 = (status) => {
1300
1530
  const s2 = status.toLowerCase();
1301
1531
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1302
1532
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1308,12 +1538,12 @@ const RefundsPage = () => {
1308
1538
  const navigate = useNavigate();
1309
1539
  const [items, setItems] = useState([]);
1310
1540
  const [orderIdSearch, setOrderIdSearch] = useState("");
1311
- const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1541
+ const debouncedOrderId = useDebounce(orderIdSearch, 300);
1312
1542
  const [paymentStatusFilter, setPaymentStatusFilter] = useState("all");
1313
1543
  const [providerSearch, setProviderSearch] = useState("");
1314
- const debouncedProvider = useDebounce$1(providerSearch, 300);
1544
+ const debouncedProvider = useDebounce(providerSearch, 300);
1315
1545
  const [currencySearch, setCurrencySearch] = useState("");
1316
- const debouncedCurrency = useDebounce$1(currencySearch, 300);
1546
+ const debouncedCurrency = useDebounce(currencySearch, 300);
1317
1547
  const [dateFrom, setDateFrom] = useState("");
1318
1548
  const [dateTo, setDateTo] = useState("");
1319
1549
  const [amountMin, setAmountMin] = useState("");
@@ -1525,7 +1755,7 @@ const RefundsPage = () => {
1525
1755
  Badge,
1526
1756
  {
1527
1757
  size: "2xsmall",
1528
- className: `uppercase ${getStatusBadgeClass$5(displayStatus(r))}`,
1758
+ className: `uppercase ${getStatusBadgeClass$4(displayStatus(r))}`,
1529
1759
  children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1530
1760
  }
1531
1761
  ) }),
@@ -1579,19 +1809,11 @@ const RefundsPage = () => {
1579
1809
  ) }) : null
1580
1810
  ] }) });
1581
1811
  };
1582
- const config$5 = defineRouteConfig({
1812
+ const config$4 = defineRouteConfig({
1583
1813
  label: "Refunds",
1584
1814
  icon: Receipt
1585
1815
  });
1586
- const useDebounce = (value, delay) => {
1587
- const [debouncedValue, setDebouncedValue] = useState(value);
1588
- useEffect(() => {
1589
- const handler = setTimeout(() => setDebouncedValue(value), delay);
1590
- return () => clearTimeout(handler);
1591
- }, [value, delay]);
1592
- return debouncedValue;
1593
- };
1594
- const getStatusBadgeClass$4 = (status) => {
1816
+ const getStatusBadgeClass$3 = (status) => {
1595
1817
  const statusLower = status.toLowerCase();
1596
1818
  if (statusLower === "requested") {
1597
1819
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -1605,324 +1827,106 @@ const getStatusBadgeClass$4 = (status) => {
1605
1827
  if (statusLower === "completed") {
1606
1828
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
1607
1829
  }
1608
- if (statusLower === "cancelled") {
1830
+ if (statusLower === "cancelled" || statusLower === "canceled") {
1609
1831
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1610
1832
  }
1611
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1612
- };
1613
- const SwapsPage = () => {
1614
- const navigate = useNavigate();
1615
- const [items, setItems] = useState([]);
1616
- const [statusFilter, setStatusFilter] = useState("all");
1617
- const [createdByFilter, setCreatedByFilter] = useState("all");
1618
- const [searchQuery, setSearchQuery] = useState("");
1619
- const debouncedSearchQuery = useDebounce(searchQuery, 300);
1620
- const [isLoading, setIsLoading] = useState(true);
1621
- const [isFetchingMore, setIsFetchingMore] = useState(false);
1622
- const [error, setError] = useState(null);
1623
- const [offset, setOffset] = useState(0);
1624
- const [count, setCount] = useState(0);
1625
- const limit = 50;
1626
- const loadSwaps = useCallback(
1627
- async (nextOffset, replace = false) => {
1628
- var _a;
1629
- try {
1630
- if (replace) {
1631
- setIsLoading(true);
1632
- } else {
1633
- setIsFetchingMore(true);
1634
- }
1635
- setError(null);
1636
- const params = new URLSearchParams();
1637
- params.set("limit", String(limit));
1638
- params.set("offset", String(nextOffset));
1639
- if (statusFilter !== "all") {
1640
- params.set("status", statusFilter);
1641
- }
1642
- if (debouncedSearchQuery.trim()) {
1643
- params.set("order_id", debouncedSearchQuery.trim());
1644
- }
1645
- if (createdByFilter !== "all") {
1646
- params.set("created_by", createdByFilter);
1647
- }
1648
- const response = await fetch(
1649
- `/admin/swaps?${params.toString()}`,
1650
- { credentials: "include" }
1651
- );
1652
- if (!response.ok) {
1653
- const message = await response.text();
1654
- throw new Error(message || "Unable to load swaps");
1655
- }
1656
- const payload = await response.json();
1657
- setCount(payload.count ?? 0);
1658
- setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
1659
- setItems(
1660
- (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
1661
- );
1662
- } catch (loadError) {
1663
- const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
1664
- setError(message);
1665
- } finally {
1666
- setIsLoading(false);
1667
- setIsFetchingMore(false);
1668
- }
1669
- },
1670
- [statusFilter, createdByFilter, debouncedSearchQuery]
1671
- );
1672
- useEffect(() => {
1673
- void loadSwaps(0, true);
1674
- }, [statusFilter, createdByFilter, debouncedSearchQuery, loadSwaps]);
1675
- const hasMore = useMemo(() => offset < count, [offset, count]);
1676
- const availableStatuses = useMemo(() => {
1677
- const statuses = /* @__PURE__ */ new Set();
1678
- items.forEach((item) => statuses.add(item.status));
1679
- return Array.from(statuses).sort();
1680
- }, [items]);
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: [
1682
- /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1683
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
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" })
1686
- ] }),
1687
- /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
1688
- ] }),
1689
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1690
- /* @__PURE__ */ jsx(
1691
- Input,
1692
- {
1693
- placeholder: "Search by swap ID or order ID",
1694
- value: searchQuery,
1695
- onChange: (event) => setSearchQuery(event.target.value),
1696
- className: "md:max-w-sm"
1697
- }
1698
- ),
1699
- /* @__PURE__ */ jsxs("div", { className: "flex gap-3", children: [
1700
- /* @__PURE__ */ jsxs(
1701
- "select",
1702
- {
1703
- value: createdByFilter,
1704
- onChange: (event) => setCreatedByFilter(event.target.value),
1705
- 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",
1706
- children: [
1707
- /* @__PURE__ */ jsx("option", { value: "all", children: "All (Created by)" }),
1708
- /* @__PURE__ */ jsx("option", { value: "customer", children: "Customer" }),
1709
- /* @__PURE__ */ jsx("option", { value: "admin", children: "Admin" })
1710
- ]
1711
- }
1712
- ),
1713
- /* @__PURE__ */ jsxs(
1714
- "select",
1715
- {
1716
- value: statusFilter,
1717
- onChange: (event) => setStatusFilter(event.target.value),
1718
- 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",
1719
- children: [
1720
- /* @__PURE__ */ jsx("option", { value: "all", children: "All Statuses" }),
1721
- availableStatuses.map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1722
- ]
1723
- }
1724
- )
1725
- ] })
1726
- ] }),
1727
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1728
- /* @__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(
1730
- Button,
1731
- {
1732
- variant: "secondary",
1733
- onClick: () => loadSwaps(0, true),
1734
- children: "Try again"
1735
- }
1736
- ) })
1737
- ] }) : null,
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." })
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: [
1742
- /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
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" }),
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" }),
1745
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
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" }),
1747
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1748
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1749
- ] }) }),
1750
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxs(
1751
- "tr",
1752
- {
1753
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1754
- onClick: () => navigate(`/swaps/${swap.id}`),
1755
- children: [
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 }),
1758
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1759
- Badge,
1760
- {
1761
- size: "2xsmall",
1762
- className: `uppercase ${getStatusBadgeClass$4(swap.status)}`,
1763
- children: swap.status.replace(/_/g, " ")
1764
- }
1765
- ) }),
1766
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1767
- const amount = swap.difference_due;
1768
- if (amount == null || amount === void 0) {
1769
- return "—";
1770
- }
1771
- const displayAmount = Number(amount) / 100;
1772
- const currency = swap.currency_code || "$";
1773
- const sign = displayAmount >= 0 ? "+" : "";
1774
- return `${sign}${currency}${displayAmount.toFixed(2)}`;
1775
- })() }),
1776
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
1777
- year: "numeric",
1778
- month: "short",
1779
- day: "numeric",
1780
- hour: "numeric",
1781
- minute: "2-digit",
1782
- hour12: true
1783
- }) }),
1784
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1785
- Button,
1786
- {
1787
- variant: "transparent",
1788
- size: "small",
1789
- onClick: (e) => {
1790
- e.stopPropagation();
1791
- navigate(`/app/orders/${swap.order_id}`);
1792
- },
1793
- children: "Go to order"
1794
- }
1795
- ) })
1796
- ]
1797
- },
1798
- swap.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: () => loadSwaps(offset, false),
1807
- children: "Load more"
1808
- }
1809
- ) }) : null
1810
- ] }) });
1811
- };
1812
- const config$4 = defineRouteConfig({
1813
- label: "Exchanges",
1814
- icon: ArrowPath
1815
- });
1816
- const getStatusBadgeClass$3 = (status) => {
1817
- const statusLower = status.toLowerCase();
1818
- if (statusLower === "requested") {
1833
+ if (statusLower === "pending") {
1819
1834
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1820
1835
  }
1821
- if (statusLower === "approved") {
1822
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1823
- }
1824
- if (statusLower === "rejected") {
1825
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
1826
- }
1827
- if (statusLower === "received") {
1828
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1829
- }
1830
- if (statusLower === "refunded") {
1831
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
1832
- }
1833
- if (statusLower === "completed") {
1834
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
1835
- }
1836
- if (statusLower === "cancelled") {
1837
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1838
- }
1839
1836
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1840
1837
  };
1841
- const ReturnDetailPage = () => {
1842
- var _a, _b;
1838
+ const SwapDetailPage = () => {
1839
+ var _a, _b, _c;
1843
1840
  const navigate = useNavigate();
1844
1841
  const { id } = useParams();
1845
- const [returnOrder, setReturnOrder] = useState(null);
1842
+ const [swap, setSwap] = useState(null);
1843
+ const [order, setOrder] = useState(null);
1846
1844
  const [isLoading, setIsLoading] = useState(true);
1847
- const [isRejecting, setIsRejecting] = useState(false);
1845
+ useState(false);
1846
+ const [isCancelling, setIsCancelling] = useState(false);
1848
1847
  const [error, setError] = useState(null);
1849
1848
  const [updateError, setUpdateError] = useState(null);
1850
1849
  const [updateSuccess, setUpdateSuccess] = useState(false);
1851
1850
  useEffect(() => {
1852
1851
  if (!id) {
1853
- navigate("/returns");
1852
+ navigate("/swaps");
1854
1853
  return;
1855
1854
  }
1856
- const loadReturn = async () => {
1855
+ const loadSwap = async () => {
1857
1856
  try {
1858
1857
  setIsLoading(true);
1859
1858
  setError(null);
1860
- const response = await fetch(`/admin/returns/${id}`, {
1859
+ const response = await fetch(`/admin/swaps/${id}`, {
1861
1860
  credentials: "include"
1862
1861
  });
1863
1862
  if (!response.ok) {
1864
1863
  const message = await response.text();
1865
- throw new Error(message || "Unable to load return order");
1864
+ throw new Error(message || "Unable to load swap");
1866
1865
  }
1867
1866
  const payload = await response.json();
1868
- setReturnOrder(payload.return);
1867
+ setSwap(payload.swap);
1868
+ setOrder(payload.order || null);
1869
1869
  } catch (loadError) {
1870
- const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
1870
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
1871
1871
  setError(message);
1872
1872
  } finally {
1873
1873
  setIsLoading(false);
1874
1874
  }
1875
1875
  };
1876
- void loadReturn();
1876
+ void loadSwap();
1877
1877
  }, [id, navigate]);
1878
- const handleReject = async () => {
1878
+ const handleCancelExchange = async () => {
1879
1879
  if (!id) {
1880
1880
  return;
1881
1881
  }
1882
1882
  try {
1883
- setIsRejecting(true);
1883
+ setIsCancelling(true);
1884
1884
  setUpdateError(null);
1885
1885
  setUpdateSuccess(false);
1886
- const response = await fetch(`/admin/returns/${id}/reject`, {
1886
+ const response = await fetch(`/admin/swaps/${id}/cancel`, {
1887
1887
  method: "POST",
1888
1888
  headers: {
1889
1889
  "Content-Type": "application/json"
1890
1890
  },
1891
- credentials: "include",
1892
- body: JSON.stringify({ reason: "Rejected by admin" })
1891
+ credentials: "include"
1893
1892
  });
1894
1893
  if (!response.ok) {
1895
1894
  const message = await response.text();
1896
- throw new Error(message || "Unable to reject return");
1895
+ throw new Error(message || "Unable to cancel exchange");
1897
1896
  }
1898
1897
  const payload = await response.json();
1899
- setReturnOrder(payload.return);
1898
+ setSwap(payload.swap);
1900
1899
  setUpdateSuccess(true);
1901
1900
  setTimeout(() => setUpdateSuccess(false), 3e3);
1902
- const detailResponse = await fetch(`/admin/returns/${id}`, {
1901
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
1903
1902
  credentials: "include"
1904
1903
  });
1905
1904
  if (detailResponse.ok) {
1906
1905
  const detailPayload = await detailResponse.json();
1907
- setReturnOrder(detailPayload.return);
1906
+ setSwap(detailPayload.swap);
1907
+ setOrder(detailPayload.order || null);
1908
1908
  }
1909
- } catch (updateErr) {
1910
- const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
1909
+ } catch (cancelErr) {
1910
+ const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
1911
1911
  setUpdateError(message);
1912
1912
  } finally {
1913
- setIsRejecting(false);
1913
+ setIsCancelling(false);
1914
1914
  }
1915
1915
  };
1916
+ const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
1917
+ const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
1918
+ ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
1919
+ );
1916
1920
  if (isLoading) {
1917
- 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..." }) }) }) });
1921
+ 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..." }) }) }) });
1918
1922
  }
1919
- if (error || !returnOrder) {
1923
+ if (error || !swap) {
1920
1924
  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: [
1921
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
1922
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
1925
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
1926
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
1923
1927
  ] }) }) });
1924
1928
  }
1925
- const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
1929
+ const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
1926
1930
  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: [
1927
1931
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
1928
1932
  /* @__PURE__ */ jsxs(
@@ -1930,7 +1934,7 @@ const ReturnDetailPage = () => {
1930
1934
  {
1931
1935
  variant: "transparent",
1932
1936
  size: "small",
1933
- onClick: () => navigate("/returns"),
1937
+ onClick: () => navigate("/swaps"),
1934
1938
  className: "w-fit",
1935
1939
  children: [
1936
1940
  /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
@@ -1940,81 +1944,67 @@ const ReturnDetailPage = () => {
1940
1944
  ),
1941
1945
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
1942
1946
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1943
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Order Details" }),
1944
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
1947
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Exchange Details" }),
1948
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
1945
1949
  ] }),
1946
1950
  /* @__PURE__ */ jsx(
1947
1951
  Badge,
1948
1952
  {
1949
1953
  size: "small",
1950
- className: `uppercase ${getStatusBadgeClass$3(returnOrder.status)}`,
1951
- children: returnOrder.status.replace(/_/g, " ")
1954
+ className: `uppercase ${getStatusBadgeClass$3(swap.status)}`,
1955
+ children: swap.status.replace(/_/g, " ")
1952
1956
  }
1953
1957
  )
1954
1958
  ] })
1955
1959
  ] }),
1956
- returnOrder.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
1960
+ canCancelExchange && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
1957
1961
  /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsx(
1958
1962
  Button,
1959
1963
  {
1960
1964
  variant: "danger",
1961
- onClick: handleReject,
1962
- disabled: isRejecting,
1963
- isLoading: isRejecting,
1964
- children: "Reject (Cancel) Return"
1965
+ onClick: handleCancelExchange,
1966
+ disabled: isCancelling,
1967
+ isLoading: isCancelling,
1968
+ children: "Cancel Exchange"
1965
1969
  }
1966
1970
  ) }),
1967
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
1968
- ] }),
1969
- /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1970
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
1971
- /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1972
- /* @__PURE__ */ jsxs("div", { children: [
1973
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
1974
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
1975
- ] }),
1976
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
1977
- Button,
1978
- {
1979
- variant: "secondary",
1980
- onClick: () => {
1981
- window.open(
1982
- `/app/orders/${returnOrder.order_id}`,
1983
- "_blank"
1984
- );
1985
- },
1986
- children: "View order"
1987
- }
1988
- ) })
1989
- ] })
1971
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
1990
1972
  ] }),
1991
1973
  /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
1992
1974
  /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1993
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
1975
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
1994
1976
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
1995
1977
  /* @__PURE__ */ jsxs("div", { children: [
1996
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
1997
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
1978
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
1979
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.id })
1998
1980
  ] }),
1999
1981
  /* @__PURE__ */ jsxs("div", { children: [
2000
1982
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2001
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.status })
1983
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.status })
2002
1984
  ] }),
2003
- returnOrder.reason && /* @__PURE__ */ jsxs("div", { children: [
1985
+ /* @__PURE__ */ jsxs("div", { children: [
1986
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
1987
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
1988
+ ] }),
1989
+ swap.reason && /* @__PURE__ */ jsxs("div", { children: [
2004
1990
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2005
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.reason })
1991
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.reason })
2006
1992
  ] }),
2007
- returnOrder.note && /* @__PURE__ */ jsxs("div", { children: [
1993
+ swap.note && /* @__PURE__ */ jsxs("div", { children: [
2008
1994
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2009
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.note })
1995
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.note })
2010
1996
  ] }),
2011
1997
  /* @__PURE__ */ jsxs("div", { children: [
2012
1998
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2013
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
1999
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2014
2000
  ] }),
2015
2001
  /* @__PURE__ */ jsxs("div", { children: [
2016
2002
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2017
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2003
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2004
+ ] }),
2005
+ swap.exchange_id && /* @__PURE__ */ jsxs("div", { children: [
2006
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2007
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.exchange_id })
2018
2008
  ] })
2019
2009
  ] })
2020
2010
  ] }),
@@ -2044,31 +2034,31 @@ const ReturnDetailPage = () => {
2044
2034
  )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2045
2035
  ] })
2046
2036
  ] }),
2047
- returnOrder.order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2037
+ order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2048
2038
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2049
2039
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2050
2040
  /* @__PURE__ */ jsxs("div", { children: [
2051
2041
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2052
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.id })
2042
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.id })
2053
2043
  ] }),
2054
2044
  /* @__PURE__ */ jsxs("div", { children: [
2055
2045
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2056
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2046
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.status || "—" })
2057
2047
  ] }),
2058
2048
  /* @__PURE__ */ jsxs("div", { children: [
2059
2049
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2060
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2050
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2061
2051
  ] }),
2062
- returnOrder.order.total && /* @__PURE__ */ jsxs("div", { children: [
2052
+ order.total && /* @__PURE__ */ jsxs("div", { children: [
2063
2053
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2064
2054
  /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
2065
- returnOrder.order.currency_code || "$",
2066
- (Number(returnOrder.order.total) / 100).toFixed(2)
2055
+ order.currency_code || "$",
2056
+ (Number(order.total) / 100).toFixed(2)
2067
2057
  ] })
2068
2058
  ] })
2069
2059
  ] })
2070
2060
  ] }),
2071
- 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: [
2061
+ 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: [
2072
2062
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2073
2063
  /* @__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: [
2074
2064
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
@@ -2076,139 +2066,309 @@ const ReturnDetailPage = () => {
2076
2066
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2077
2067
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2078
2068
  ] }) }),
2079
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2069
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2080
2070
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2081
2071
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2082
2072
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2083
2073
  ] }, item.id || index)) })
2084
2074
  ] }) })
2085
2075
  ] }),
2086
- 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 }) }),
2087
- 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" }) })
2076
+ 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: [
2077
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2078
+ /* @__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: [
2079
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
2080
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2081
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2082
+ ] }) }),
2083
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2084
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2085
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2086
+ ] }, item.variant_id || index)) })
2087
+ ] }) })
2088
+ ] })
2088
2089
  ] }) });
2089
2090
  };
2090
2091
  const config$3 = defineRouteConfig({
2091
- label: "Return Order Details",
2092
- icon: CheckCircle
2092
+ label: "Swap Details",
2093
+ icon: ArrowPath
2093
2094
  });
2094
2095
  const getStatusBadgeClass$2 = (status) => {
2095
- const s2 = status.toLowerCase();
2096
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2097
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2098
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2099
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2096
+ const statusLower = status.toLowerCase();
2097
+ if (statusLower === "requested") {
2098
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2099
+ }
2100
+ if (statusLower === "approved") {
2101
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2102
+ }
2103
+ if (statusLower === "rejected") {
2104
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
2105
+ }
2106
+ if (statusLower === "received") {
2107
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2108
+ }
2109
+ if (statusLower === "refunded") {
2110
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2111
+ }
2112
+ if (statusLower === "completed") {
2113
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2114
+ }
2115
+ if (statusLower === "cancelled") {
2116
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2117
+ }
2100
2118
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2101
2119
  };
2102
- const PaymentDetailPage = () => {
2103
- var _a;
2120
+ const ReturnDetailPage = () => {
2121
+ var _a, _b;
2104
2122
  const navigate = useNavigate();
2105
- const params = useParams();
2106
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2107
- const [detail, setDetail] = useState(null);
2108
- const [loading, setLoading] = useState(!!id);
2123
+ const { id } = useParams();
2124
+ const [returnOrder, setReturnOrder] = useState(null);
2125
+ const [isLoading, setIsLoading] = useState(true);
2126
+ const [isRejecting, setIsRejecting] = useState(false);
2109
2127
  const [error, setError] = useState(null);
2128
+ const [updateError, setUpdateError] = useState(null);
2129
+ const [updateSuccess, setUpdateSuccess] = useState(false);
2110
2130
  useEffect(() => {
2111
2131
  if (!id) {
2112
- setLoading(false);
2132
+ navigate("/returns");
2113
2133
  return;
2114
2134
  }
2115
- let cancelled = false;
2116
- setLoading(true);
2117
- setError(null);
2118
- fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2119
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2120
- return res.json();
2121
- }).then((data) => {
2122
- if (!cancelled) setDetail(data);
2123
- }).catch((e) => {
2124
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2125
- }).finally(() => {
2126
- if (!cancelled) setLoading(false);
2127
- });
2128
- return () => {
2129
- cancelled = true;
2135
+ const loadReturn = async () => {
2136
+ try {
2137
+ setIsLoading(true);
2138
+ setError(null);
2139
+ const response = await fetch(`/admin/returns/${id}`, {
2140
+ credentials: "include"
2141
+ });
2142
+ if (!response.ok) {
2143
+ const message = await response.text();
2144
+ throw new Error(message || "Unable to load return order");
2145
+ }
2146
+ const payload = await response.json();
2147
+ setReturnOrder(payload.return);
2148
+ } catch (loadError) {
2149
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2150
+ setError(message);
2151
+ } finally {
2152
+ setIsLoading(false);
2153
+ }
2130
2154
  };
2131
- }, [id]);
2132
- const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
2133
- const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
2134
- const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
2135
- const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
2136
- 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: [
2137
- /* @__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: [
2138
- /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
2139
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payment session" }),
2140
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
2141
- ] }) }),
2142
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2143
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2144
- /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
2145
- ] }) : 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: [
2146
- /* @__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: [
2147
- /* @__PURE__ */ jsxs("div", { children: [
2148
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
2149
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsx(
2150
- Button,
2151
- {
2152
- variant: "transparent",
2153
- size: "small",
2154
- onClick: () => navigate(`/orders/${detail.order_id}`),
2155
- children: detail.order_id
2156
- }
2157
- ) : /* @__PURE__ */ jsx(Text, { children: "—" }) })
2158
- ] }),
2159
- /* @__PURE__ */ jsxs("div", { children: [
2160
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2161
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: displayAmount })
2162
- ] }),
2163
- /* @__PURE__ */ jsxs("div", { children: [
2164
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2165
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.provider_id })
2166
- ] }),
2167
- /* @__PURE__ */ jsxs("div", { children: [
2168
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2169
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2170
- Badge,
2171
- {
2172
- size: "2xsmall",
2173
- className: `uppercase ${getStatusBadgeClass$2(displayStatus)}`,
2174
- children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2175
- }
2176
- ) })
2155
+ void loadReturn();
2156
+ }, [id, navigate]);
2157
+ const handleReject = async () => {
2158
+ if (!id) {
2159
+ return;
2160
+ }
2161
+ try {
2162
+ setIsRejecting(true);
2163
+ setUpdateError(null);
2164
+ setUpdateSuccess(false);
2165
+ const response = await fetch(`/admin/returns/${id}/reject`, {
2166
+ method: "POST",
2167
+ headers: {
2168
+ "Content-Type": "application/json"
2169
+ },
2170
+ credentials: "include",
2171
+ body: JSON.stringify({ reason: "Rejected by admin" })
2172
+ });
2173
+ if (!response.ok) {
2174
+ const message = await response.text();
2175
+ throw new Error(message || "Unable to reject return");
2176
+ }
2177
+ const payload = await response.json();
2178
+ setReturnOrder(payload.return);
2179
+ setUpdateSuccess(true);
2180
+ setTimeout(() => setUpdateSuccess(false), 3e3);
2181
+ const detailResponse = await fetch(`/admin/returns/${id}`, {
2182
+ credentials: "include"
2183
+ });
2184
+ if (detailResponse.ok) {
2185
+ const detailPayload = await detailResponse.json();
2186
+ setReturnOrder(detailPayload.return);
2187
+ }
2188
+ } catch (updateErr) {
2189
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2190
+ setUpdateError(message);
2191
+ } finally {
2192
+ setIsRejecting(false);
2193
+ }
2194
+ };
2195
+ if (isLoading) {
2196
+ 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..." }) }) }) });
2197
+ }
2198
+ if (error || !returnOrder) {
2199
+ 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: [
2200
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
2201
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2202
+ ] }) }) });
2203
+ }
2204
+ const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2205
+ 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: [
2206
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
2207
+ /* @__PURE__ */ jsxs(
2208
+ Button,
2209
+ {
2210
+ variant: "transparent",
2211
+ size: "small",
2212
+ onClick: () => navigate("/returns"),
2213
+ className: "w-fit",
2214
+ children: [
2215
+ /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
2216
+ "Back to list"
2217
+ ]
2218
+ }
2219
+ ),
2220
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2221
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2222
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Order Details" }),
2223
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2177
2224
  ] }),
2225
+ /* @__PURE__ */ jsx(
2226
+ Badge,
2227
+ {
2228
+ size: "small",
2229
+ className: `uppercase ${getStatusBadgeClass$2(returnOrder.status)}`,
2230
+ children: returnOrder.status.replace(/_/g, " ")
2231
+ }
2232
+ )
2233
+ ] })
2234
+ ] }),
2235
+ returnOrder.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2236
+ /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsx(
2237
+ Button,
2238
+ {
2239
+ variant: "danger",
2240
+ onClick: handleReject,
2241
+ disabled: isRejecting,
2242
+ isLoading: isRejecting,
2243
+ children: "Reject (Cancel) Return"
2244
+ }
2245
+ ) }),
2246
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
2247
+ ] }),
2248
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2249
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
2250
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2178
2251
  /* @__PURE__ */ jsxs("div", { children: [
2179
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
2180
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: sessionStatusRaw })
2252
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2253
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2181
2254
  ] }),
2255
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
2256
+ Button,
2257
+ {
2258
+ variant: "secondary",
2259
+ onClick: () => {
2260
+ window.open(
2261
+ `/app/orders/${returnOrder.order_id}`,
2262
+ "_blank"
2263
+ );
2264
+ },
2265
+ children: "View order"
2266
+ }
2267
+ ) })
2268
+ ] })
2269
+ ] }),
2270
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2271
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2272
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2273
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2274
+ /* @__PURE__ */ jsxs("div", { children: [
2275
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2276
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2277
+ ] }),
2278
+ /* @__PURE__ */ jsxs("div", { children: [
2279
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2280
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.status })
2281
+ ] }),
2282
+ returnOrder.reason && /* @__PURE__ */ jsxs("div", { children: [
2283
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2284
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.reason })
2285
+ ] }),
2286
+ returnOrder.note && /* @__PURE__ */ jsxs("div", { children: [
2287
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2288
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.note })
2289
+ ] }),
2290
+ /* @__PURE__ */ jsxs("div", { children: [
2291
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2292
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2293
+ ] }),
2294
+ /* @__PURE__ */ jsxs("div", { children: [
2295
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2296
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2297
+ ] })
2298
+ ] })
2299
+ ] }),
2300
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2301
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Status History" }),
2302
+ statusHistory.length > 0 ? /* @__PURE__ */ jsx("div", { className: "space-y-2", children: statusHistory.map((entry, index) => /* @__PURE__ */ jsx(
2303
+ "div",
2304
+ {
2305
+ className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
2306
+ children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2307
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx(
2308
+ Badge,
2309
+ {
2310
+ size: "2xsmall",
2311
+ className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2312
+ children: entry.status.replace(/_/g, " ")
2313
+ }
2314
+ ) }),
2315
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
2316
+ new Date(entry.timestamp).toLocaleString(),
2317
+ entry.admin_id && ` by ${entry.admin_id}`,
2318
+ entry.reason && ` - ${entry.reason}`
2319
+ ] })
2320
+ ] })
2321
+ },
2322
+ index
2323
+ )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2324
+ ] })
2325
+ ] }),
2326
+ returnOrder.order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2327
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2328
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2182
2329
  /* @__PURE__ */ jsxs("div", { children: [
2183
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
2184
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: paymentStatusRaw })
2330
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2331
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.id })
2185
2332
  ] }),
2186
2333
  /* @__PURE__ */ jsxs("div", { children: [
2187
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
2188
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
2334
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2335
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2189
2336
  ] }),
2190
2337
  /* @__PURE__ */ jsxs("div", { children: [
2191
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
2192
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2193
- year: "numeric",
2194
- month: "short",
2195
- day: "numeric",
2196
- hour: "numeric",
2197
- minute: "2-digit",
2198
- hour12: true
2199
- }) })
2338
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2339
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2340
+ ] }),
2341
+ returnOrder.order.total && /* @__PURE__ */ jsxs("div", { children: [
2342
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2343
+ /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
2344
+ returnOrder.order.currency_code || "$",
2345
+ (Number(returnOrder.order.total) / 100).toFixed(2)
2346
+ ] })
2200
2347
  ] })
2201
- ] }) }),
2202
- Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2203
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2204
- /* @__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) })
2205
- ] }) : /* @__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." }) })
2206
- ] }) : null
2348
+ ] })
2349
+ ] }),
2350
+ 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: [
2351
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2352
+ /* @__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: [
2353
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
2354
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
2355
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2356
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2357
+ ] }) }),
2358
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2359
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2360
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2361
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2362
+ ] }, item.id || index)) })
2363
+ ] }) })
2364
+ ] }),
2365
+ 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 }) }),
2366
+ 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" }) })
2207
2367
  ] }) });
2208
2368
  };
2209
2369
  const config$2 = defineRouteConfig({
2210
- label: "Payment details",
2211
- icon: CreditCard
2370
+ label: "Return Order Details",
2371
+ icon: CheckCircle
2212
2372
  });
2213
2373
  const getStatusBadgeClass$1 = (status) => {
2214
2374
  const s2 = status.toLowerCase();
@@ -2218,18 +2378,14 @@ const getStatusBadgeClass$1 = (status) => {
2218
2378
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2219
2379
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2220
2380
  };
2221
- const formatAmount = (value) => {
2222
- return String(value);
2223
- };
2224
- const RefundDetailPage = () => {
2225
- var _a, _b, _c;
2381
+ const PaymentDetailPage = () => {
2382
+ var _a;
2226
2383
  const navigate = useNavigate();
2227
2384
  const params = useParams();
2228
2385
  const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2229
2386
  const [detail, setDetail] = useState(null);
2230
2387
  const [loading, setLoading] = useState(!!id);
2231
2388
  const [error, setError] = useState(null);
2232
- const [gatewayExpanded, setGatewayExpanded] = useState(false);
2233
2389
  useEffect(() => {
2234
2390
  if (!id) {
2235
2391
  setLoading(false);
@@ -2238,7 +2394,7 @@ const RefundDetailPage = () => {
2238
2394
  let cancelled = false;
2239
2395
  setLoading(true);
2240
2396
  setError(null);
2241
- fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
2397
+ fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2242
2398
  if (!res.ok) throw new Error(res.statusText || "Failed to load");
2243
2399
  return res.json();
2244
2400
  }).then((data) => {
@@ -2252,434 +2408,278 @@ const RefundDetailPage = () => {
2252
2408
  cancelled = true;
2253
2409
  };
2254
2410
  }, [id]);
2255
- const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
2256
- const hasGatewayData = ((_c = detail == null ? void 0 : detail.payment) == null ? void 0 : _c.payment_data) && typeof detail.payment.payment_data === "object" && Object.keys(detail.payment.payment_data).length > 0;
2411
+ const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
2412
+ const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
2413
+ const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
2414
+ const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
2257
2415
  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: [
2258
2416
  /* @__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: [
2259
- /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
2260
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Refund details" }),
2261
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
2417
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
2418
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payment session" }),
2419
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
2262
2420
  ] }) }),
2263
2421
  error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2264
2422
  /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2265
- /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
2423
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
2266
2424
  ] }) : 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: [
2267
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2268
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
2269
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2270
- /* @__PURE__ */ jsxs("div", { children: [
2271
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
2272
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
2273
- ] }),
2274
- /* @__PURE__ */ jsxs("div", { children: [
2275
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2276
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
2277
- ] }),
2278
- /* @__PURE__ */ jsxs("div", { children: [
2279
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2280
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2281
- ] }),
2282
- /* @__PURE__ */ jsxs("div", { children: [
2283
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2284
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2285
- year: "numeric",
2286
- month: "short",
2287
- day: "numeric",
2288
- hour: "numeric",
2289
- minute: "2-digit",
2290
- hour12: true
2291
- }) })
2292
- ] }),
2293
- detail.refund.created_by ? /* @__PURE__ */ jsxs("div", { children: [
2294
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
2295
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
2296
- ] }) : null
2297
- ] })
2298
- ] }),
2299
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2300
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
2301
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2302
- /* @__PURE__ */ jsxs("div", { children: [
2303
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
2304
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
2305
- ] }),
2306
- /* @__PURE__ */ jsxs("div", { children: [
2307
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
2308
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2309
- ] }),
2310
- /* @__PURE__ */ jsxs("div", { children: [
2311
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
2312
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2313
- ] }),
2314
- /* @__PURE__ */ jsxs("div", { children: [
2315
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2316
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
2317
- ] }),
2318
- /* @__PURE__ */ jsxs("div", { children: [
2319
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2320
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2321
- Badge,
2322
- {
2323
- size: "2xsmall",
2324
- className: `uppercase ${getStatusBadgeClass$1(paymentStatus)}`,
2325
- children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2326
- }
2327
- ) })
2328
- ] }),
2329
- detail.computed ? /* @__PURE__ */ jsxs(Fragment, { children: [
2330
- /* @__PURE__ */ jsxs("div", { children: [
2331
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
2332
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
2333
- ] }),
2334
- /* @__PURE__ */ jsxs("div", { children: [
2335
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
2336
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
2337
- ] }),
2338
- /* @__PURE__ */ jsxs("div", { children: [
2339
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
2340
- /* @__PURE__ */ jsxs(Text, { className: "mt-1 block", children: [
2341
- detail.computed.refund_percentage.toFixed(1),
2342
- "%"
2343
- ] })
2344
- ] })
2345
- ] }) : null
2425
+ /* @__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: [
2426
+ /* @__PURE__ */ jsxs("div", { children: [
2427
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
2428
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsx(
2429
+ Button,
2430
+ {
2431
+ variant: "transparent",
2432
+ size: "small",
2433
+ onClick: () => navigate(`/orders/${detail.order_id}`),
2434
+ children: detail.order_id
2435
+ }
2436
+ ) : /* @__PURE__ */ jsx(Text, { children: "—" }) })
2437
+ ] }),
2438
+ /* @__PURE__ */ jsxs("div", { children: [
2439
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2440
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: displayAmount })
2441
+ ] }),
2442
+ /* @__PURE__ */ jsxs("div", { children: [
2443
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2444
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.provider_id })
2445
+ ] }),
2446
+ /* @__PURE__ */ jsxs("div", { children: [
2447
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2448
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2449
+ Badge,
2450
+ {
2451
+ size: "2xsmall",
2452
+ className: `uppercase ${getStatusBadgeClass$1(displayStatus)}`,
2453
+ children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2454
+ }
2455
+ ) })
2456
+ ] }),
2457
+ /* @__PURE__ */ jsxs("div", { children: [
2458
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
2459
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: sessionStatusRaw })
2460
+ ] }),
2461
+ /* @__PURE__ */ jsxs("div", { children: [
2462
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
2463
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: paymentStatusRaw })
2464
+ ] }),
2465
+ /* @__PURE__ */ jsxs("div", { children: [
2466
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
2467
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
2468
+ ] }),
2469
+ /* @__PURE__ */ jsxs("div", { children: [
2470
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
2471
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2472
+ year: "numeric",
2473
+ month: "short",
2474
+ day: "numeric",
2475
+ hour: "numeric",
2476
+ minute: "2-digit",
2477
+ hour12: true
2478
+ }) })
2346
2479
  ] })
2347
- ] }),
2348
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2349
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
2350
- detail.order ? /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2351
- /* @__PURE__ */ jsxs("div", { children: [
2352
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
2353
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2354
- Button,
2355
- {
2356
- variant: "transparent",
2357
- size: "small",
2358
- onClick: () => navigate(`/orders/${detail.order.order_id}`),
2359
- children: detail.order.order_number ?? detail.order.order_id
2360
- }
2361
- ) })
2362
- ] }),
2363
- detail.order.total != null ? /* @__PURE__ */ jsxs("div", { children: [
2364
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
2365
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
2366
- ] }) : null,
2367
- detail.order.customer_id ? /* @__PURE__ */ jsxs("div", { children: [
2368
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
2369
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
2370
- ] }) : null,
2371
- detail.order.region ? /* @__PURE__ */ jsxs("div", { children: [
2372
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
2373
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.region })
2374
- ] }) : null,
2375
- detail.order.fulfillment_status ? /* @__PURE__ */ jsxs("div", { children: [
2376
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
2377
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
2378
- ] }) : null
2379
- ] }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
2380
- ] }),
2381
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2382
- /* @__PURE__ */ jsxs(
2383
- "button",
2384
- {
2385
- type: "button",
2386
- className: "flex w-full items-center justify-between text-left",
2387
- onClick: () => setGatewayExpanded((prev) => !prev),
2388
- "aria-expanded": gatewayExpanded,
2389
- "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
2390
- children: [
2391
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
2392
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
2393
- ]
2394
- }
2395
- ),
2396
- gatewayExpanded && /* @__PURE__ */ jsx("div", { className: "mt-4", children: hasGatewayData ? /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.payment.payment_data, null, 2) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No gateway payload for this payment." }) })
2397
- ] })
2480
+ ] }) }),
2481
+ Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2482
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2483
+ /* @__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) })
2484
+ ] }) : /* @__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." }) })
2398
2485
  ] }) : null
2399
2486
  ] }) });
2400
2487
  };
2401
2488
  const config$1 = defineRouteConfig({
2402
- label: "Refund details",
2403
- icon: Receipt
2489
+ label: "Payment details",
2490
+ icon: CreditCard
2404
2491
  });
2405
2492
  const getStatusBadgeClass = (status) => {
2406
- const statusLower = status.toLowerCase();
2407
- if (statusLower === "requested") {
2408
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2409
- }
2410
- if (statusLower === "approved") {
2411
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2412
- }
2413
- if (statusLower === "rejected") {
2414
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
2415
- }
2416
- if (statusLower === "completed") {
2417
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
2418
- }
2419
- if (statusLower === "cancelled" || statusLower === "canceled") {
2420
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2421
- }
2422
- if (statusLower === "pending") {
2423
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2424
- }
2493
+ const s2 = status.toLowerCase();
2494
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2495
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2496
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2497
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2425
2498
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2426
2499
  };
2427
- const SwapDetailPage = () => {
2500
+ const formatAmount = (value) => {
2501
+ return String(value);
2502
+ };
2503
+ const RefundDetailPage = () => {
2428
2504
  var _a, _b, _c;
2429
2505
  const navigate = useNavigate();
2430
- const { id } = useParams();
2431
- const [swap, setSwap] = useState(null);
2432
- const [order, setOrder] = useState(null);
2433
- const [isLoading, setIsLoading] = useState(true);
2434
- useState(false);
2435
- const [isCancelling, setIsCancelling] = useState(false);
2506
+ const params = useParams();
2507
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2508
+ const [detail, setDetail] = useState(null);
2509
+ const [loading, setLoading] = useState(!!id);
2436
2510
  const [error, setError] = useState(null);
2437
- const [updateError, setUpdateError] = useState(null);
2438
- const [updateSuccess, setUpdateSuccess] = useState(false);
2511
+ const [gatewayExpanded, setGatewayExpanded] = useState(false);
2439
2512
  useEffect(() => {
2440
2513
  if (!id) {
2441
- navigate("/swaps");
2514
+ setLoading(false);
2442
2515
  return;
2443
2516
  }
2444
- const loadSwap = async () => {
2445
- try {
2446
- setIsLoading(true);
2447
- setError(null);
2448
- const response = await fetch(`/admin/swaps/${id}`, {
2449
- credentials: "include"
2450
- });
2451
- if (!response.ok) {
2452
- const message = await response.text();
2453
- throw new Error(message || "Unable to load swap");
2454
- }
2455
- const payload = await response.json();
2456
- setSwap(payload.swap);
2457
- setOrder(payload.order || null);
2458
- } catch (loadError) {
2459
- const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
2460
- setError(message);
2461
- } finally {
2462
- setIsLoading(false);
2463
- }
2517
+ let cancelled = false;
2518
+ setLoading(true);
2519
+ setError(null);
2520
+ fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
2521
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
2522
+ return res.json();
2523
+ }).then((data) => {
2524
+ if (!cancelled) setDetail(data);
2525
+ }).catch((e) => {
2526
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2527
+ }).finally(() => {
2528
+ if (!cancelled) setLoading(false);
2529
+ });
2530
+ return () => {
2531
+ cancelled = true;
2464
2532
  };
2465
- void loadSwap();
2466
- }, [id, navigate]);
2467
- const handleCancelExchange = async () => {
2468
- if (!id) {
2469
- return;
2470
- }
2471
- try {
2472
- setIsCancelling(true);
2473
- setUpdateError(null);
2474
- setUpdateSuccess(false);
2475
- const response = await fetch(`/admin/swaps/${id}/cancel`, {
2476
- method: "POST",
2477
- headers: {
2478
- "Content-Type": "application/json"
2479
- },
2480
- credentials: "include"
2481
- });
2482
- if (!response.ok) {
2483
- const message = await response.text();
2484
- throw new Error(message || "Unable to cancel exchange");
2485
- }
2486
- const payload = await response.json();
2487
- setSwap(payload.swap);
2488
- setUpdateSuccess(true);
2489
- setTimeout(() => setUpdateSuccess(false), 3e3);
2490
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
2491
- credentials: "include"
2492
- });
2493
- if (detailResponse.ok) {
2494
- const detailPayload = await detailResponse.json();
2495
- setSwap(detailPayload.swap);
2496
- setOrder(detailPayload.order || null);
2497
- }
2498
- } catch (cancelErr) {
2499
- const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
2500
- setUpdateError(message);
2501
- } finally {
2502
- setIsCancelling(false);
2503
- }
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
- );
2509
- if (isLoading) {
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..." }) }) }) });
2511
- }
2512
- if (error || !swap) {
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: [
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" }) })
2516
- ] }) }) });
2517
- }
2518
- const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
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: [
2520
- /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
2521
- /* @__PURE__ */ jsxs(
2522
- Button,
2523
- {
2524
- variant: "transparent",
2525
- size: "small",
2526
- onClick: () => navigate("/swaps"),
2527
- className: "w-fit",
2528
- children: [
2529
- /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
2530
- "Back to list"
2531
- ]
2532
- }
2533
- ),
2534
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2535
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2536
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Exchange Details" }),
2537
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
2538
- ] }),
2539
- /* @__PURE__ */ jsx(
2540
- Badge,
2541
- {
2542
- size: "small",
2543
- className: `uppercase ${getStatusBadgeClass(swap.status)}`,
2544
- children: swap.status.replace(/_/g, " ")
2545
- }
2546
- )
2547
- ] })
2548
- ] }),
2549
- canCancelExchange && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2550
- /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsx(
2551
- Button,
2552
- {
2553
- variant: "danger",
2554
- onClick: handleCancelExchange,
2555
- disabled: isCancelling,
2556
- isLoading: isCancelling,
2557
- children: "Cancel Exchange"
2558
- }
2559
- ) }),
2560
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
2561
- ] }),
2562
- /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2563
- /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2564
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
2565
- /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2533
+ }, [id]);
2534
+ const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
2535
+ const hasGatewayData = ((_c = detail == null ? void 0 : detail.payment) == null ? void 0 : _c.payment_data) && typeof detail.payment.payment_data === "object" && Object.keys(detail.payment.payment_data).length > 0;
2536
+ 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: [
2537
+ /* @__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: [
2538
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
2539
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Refund details" }),
2540
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
2541
+ ] }) }),
2542
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2543
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2544
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
2545
+ ] }) : 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: [
2546
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2547
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
2548
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2566
2549
  /* @__PURE__ */ jsxs("div", { children: [
2567
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2568
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.id })
2550
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
2551
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
2569
2552
  ] }),
2570
2553
  /* @__PURE__ */ jsxs("div", { children: [
2571
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2572
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.status })
2554
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2555
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
2573
2556
  ] }),
2574
2557
  /* @__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)}` : "—" })
2558
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2559
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2577
2560
  ] }),
2578
- swap.reason && /* @__PURE__ */ jsxs("div", { children: [
2579
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2580
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.reason })
2561
+ /* @__PURE__ */ jsxs("div", { children: [
2562
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2563
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2564
+ year: "numeric",
2565
+ month: "short",
2566
+ day: "numeric",
2567
+ hour: "numeric",
2568
+ minute: "2-digit",
2569
+ hour12: true
2570
+ }) })
2581
2571
  ] }),
2582
- swap.note && /* @__PURE__ */ jsxs("div", { children: [
2583
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2584
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.note })
2572
+ detail.refund.created_by ? /* @__PURE__ */ jsxs("div", { children: [
2573
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
2574
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
2575
+ ] }) : null
2576
+ ] })
2577
+ ] }),
2578
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2579
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
2580
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2581
+ /* @__PURE__ */ jsxs("div", { children: [
2582
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
2583
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
2585
2584
  ] }),
2586
2585
  /* @__PURE__ */ jsxs("div", { children: [
2587
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2588
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2586
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
2587
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2589
2588
  ] }),
2590
2589
  /* @__PURE__ */ jsxs("div", { children: [
2591
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2592
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2590
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
2591
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2593
2592
  ] }),
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 })
2597
- ] })
2598
- ] })
2599
- ] }),
2600
- /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2601
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Status History" }),
2602
- statusHistory.length > 0 ? /* @__PURE__ */ jsx("div", { className: "space-y-2", children: statusHistory.map((entry, index) => /* @__PURE__ */ jsx(
2603
- "div",
2604
- {
2605
- className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
2606
- children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2607
- /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx(
2608
- Badge,
2609
- {
2610
- size: "2xsmall",
2611
- className: `uppercase ${getStatusBadgeClass(entry.status)}`,
2612
- children: entry.status.replace(/_/g, " ")
2613
- }
2614
- ) }),
2615
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
2616
- new Date(entry.timestamp).toLocaleString(),
2617
- entry.admin_id && ` by ${entry.admin_id}`,
2618
- entry.reason && ` - ${entry.reason}`
2593
+ /* @__PURE__ */ jsxs("div", { children: [
2594
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2595
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
2596
+ ] }),
2597
+ /* @__PURE__ */ jsxs("div", { children: [
2598
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2599
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2600
+ Badge,
2601
+ {
2602
+ size: "2xsmall",
2603
+ className: `uppercase ${getStatusBadgeClass(paymentStatus)}`,
2604
+ children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2605
+ }
2606
+ ) })
2607
+ ] }),
2608
+ detail.computed ? /* @__PURE__ */ jsxs(Fragment, { children: [
2609
+ /* @__PURE__ */ jsxs("div", { children: [
2610
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
2611
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
2612
+ ] }),
2613
+ /* @__PURE__ */ jsxs("div", { children: [
2614
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
2615
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
2616
+ ] }),
2617
+ /* @__PURE__ */ jsxs("div", { children: [
2618
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
2619
+ /* @__PURE__ */ jsxs(Text, { className: "mt-1 block", children: [
2620
+ detail.computed.refund_percentage.toFixed(1),
2621
+ "%"
2619
2622
  ] })
2620
2623
  ] })
2621
- },
2622
- index
2623
- )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2624
- ] })
2625
- ] }),
2626
- order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2627
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2628
- /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2629
- /* @__PURE__ */ jsxs("div", { children: [
2630
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2631
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.id })
2632
- ] }),
2633
- /* @__PURE__ */ jsxs("div", { children: [
2634
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2635
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.status || "—" })
2636
- ] }),
2637
- /* @__PURE__ */ jsxs("div", { children: [
2638
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2639
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2640
- ] }),
2641
- order.total && /* @__PURE__ */ jsxs("div", { children: [
2642
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2643
- /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
2644
- order.currency_code || "$",
2645
- (Number(order.total) / 100).toFixed(2)
2646
- ] })
2624
+ ] }) : null
2647
2625
  ] })
2626
+ ] }),
2627
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2628
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
2629
+ detail.order ? /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2630
+ /* @__PURE__ */ jsxs("div", { children: [
2631
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
2632
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2633
+ Button,
2634
+ {
2635
+ variant: "transparent",
2636
+ size: "small",
2637
+ onClick: () => navigate(`/orders/${detail.order.order_id}`),
2638
+ children: detail.order.order_number ?? detail.order.order_id
2639
+ }
2640
+ ) })
2641
+ ] }),
2642
+ detail.order.total != null ? /* @__PURE__ */ jsxs("div", { children: [
2643
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
2644
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
2645
+ ] }) : null,
2646
+ detail.order.customer_id ? /* @__PURE__ */ jsxs("div", { children: [
2647
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
2648
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
2649
+ ] }) : null,
2650
+ detail.order.region ? /* @__PURE__ */ jsxs("div", { children: [
2651
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
2652
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.region })
2653
+ ] }) : null,
2654
+ detail.order.fulfillment_status ? /* @__PURE__ */ jsxs("div", { children: [
2655
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
2656
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
2657
+ ] }) : null
2658
+ ] }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
2659
+ ] }),
2660
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2661
+ /* @__PURE__ */ jsxs(
2662
+ "button",
2663
+ {
2664
+ type: "button",
2665
+ className: "flex w-full items-center justify-between text-left",
2666
+ onClick: () => setGatewayExpanded((prev) => !prev),
2667
+ "aria-expanded": gatewayExpanded,
2668
+ "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
2669
+ children: [
2670
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
2671
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
2672
+ ]
2673
+ }
2674
+ ),
2675
+ gatewayExpanded && /* @__PURE__ */ jsx("div", { className: "mt-4", children: hasGatewayData ? /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.payment.payment_data, null, 2) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No gateway payload for this payment." }) })
2648
2676
  ] })
2649
- ] }),
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: [
2651
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
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: [
2653
- /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
2654
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
2655
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2656
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2657
- ] }) }),
2658
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2659
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2660
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2661
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2662
- ] }, item.id || index)) })
2663
- ] }) })
2664
- ] }),
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
- ] })
2677
+ ] }) : null
2678
2678
  ] }) });
2679
2679
  };
2680
2680
  const config = defineRouteConfig({
2681
- label: "Swap Details",
2682
- icon: ArrowPath
2681
+ label: "Refund details",
2682
+ icon: Receipt
2683
2683
  });
2684
2684
  const i18nTranslations0 = {};
2685
2685
  const widgetModule = { widgets: [
@@ -2694,6 +2694,10 @@ const widgetModule = { widgets: [
2694
2694
  ] };
2695
2695
  const routeModule = {
2696
2696
  routes: [
2697
+ {
2698
+ Component: SwapsPage,
2699
+ path: "/swaps"
2700
+ },
2697
2701
  {
2698
2702
  Component: ReturnsPage,
2699
2703
  path: "/returns"
@@ -2707,8 +2711,8 @@ const routeModule = {
2707
2711
  path: "/refunds"
2708
2712
  },
2709
2713
  {
2710
- Component: SwapsPage,
2711
- path: "/swaps"
2714
+ Component: SwapDetailPage,
2715
+ path: "/swaps/:id"
2712
2716
  },
2713
2717
  {
2714
2718
  Component: ReturnDetailPage,
@@ -2721,10 +2725,6 @@ const routeModule = {
2721
2725
  {
2722
2726
  Component: RefundDetailPage,
2723
2727
  path: "/refunds/:id"
2724
- },
2725
- {
2726
- Component: SwapDetailPage,
2727
- path: "/swaps/:id"
2728
2728
  }
2729
2729
  ]
2730
2730
  };
@@ -2733,49 +2733,49 @@ const menuItemModule = {
2733
2733
  {
2734
2734
  label: config$4.label,
2735
2735
  icon: config$4.icon,
2736
- path: "/swaps",
2736
+ path: "/refunds",
2737
2737
  nested: void 0
2738
2738
  },
2739
2739
  {
2740
2740
  label: config$5.label,
2741
2741
  icon: config$5.icon,
2742
- path: "/refunds",
2742
+ path: "/payments",
2743
2743
  nested: void 0
2744
2744
  },
2745
2745
  {
2746
2746
  label: config$7.label,
2747
2747
  icon: config$7.icon,
2748
- path: "/returns",
2748
+ path: "/swaps",
2749
2749
  nested: void 0
2750
2750
  },
2751
2751
  {
2752
2752
  label: config$6.label,
2753
2753
  icon: config$6.icon,
2754
- path: "/payments",
2754
+ path: "/returns",
2755
2755
  nested: void 0
2756
2756
  },
2757
2757
  {
2758
2758
  label: config.label,
2759
2759
  icon: config.icon,
2760
- path: "/swaps/:id",
2760
+ path: "/refunds/:id",
2761
2761
  nested: void 0
2762
2762
  },
2763
2763
  {
2764
2764
  label: config$1.label,
2765
2765
  icon: config$1.icon,
2766
- path: "/refunds/:id",
2766
+ path: "/payments/:id",
2767
2767
  nested: void 0
2768
2768
  },
2769
2769
  {
2770
- label: config$3.label,
2771
- icon: config$3.icon,
2770
+ label: config$2.label,
2771
+ icon: config$2.icon,
2772
2772
  path: "/returns/:id",
2773
2773
  nested: void 0
2774
2774
  },
2775
2775
  {
2776
- label: config$2.label,
2777
- icon: config$2.icon,
2778
- path: "/payments/:id",
2776
+ label: config$3.label,
2777
+ icon: config$3.icon,
2778
+ path: "/swaps/:id",
2779
2779
  nested: void 0
2780
2780
  }
2781
2781
  ]