order-management 0.0.87 → 0.0.88

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, Receipt, CreditCard, ArrowLeft, CheckCircle } from "@medusajs/icons";
5
+ import { CashSolid, PencilSquareSolid, Trash, Receipt, ArrowPath, CreditCard, 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,236 +865,6 @@ 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) => {
1098
868
  const s2 = status.toLowerCase();
1099
869
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1100
870
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1106,12 +876,12 @@ const RefundsPage = () => {
1106
876
  const navigate = useNavigate();
1107
877
  const [items, setItems] = useState([]);
1108
878
  const [orderIdSearch, setOrderIdSearch] = useState("");
1109
- const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
879
+ const debouncedOrderId = useDebounce$3(orderIdSearch, 300);
1110
880
  const [paymentStatusFilter, setPaymentStatusFilter] = useState("all");
1111
881
  const [providerSearch, setProviderSearch] = useState("");
1112
- const debouncedProvider = useDebounce$2(providerSearch, 300);
882
+ const debouncedProvider = useDebounce$3(providerSearch, 300);
1113
883
  const [currencySearch, setCurrencySearch] = useState("");
1114
- const debouncedCurrency = useDebounce$2(currencySearch, 300);
884
+ const debouncedCurrency = useDebounce$3(currencySearch, 300);
1115
885
  const [dateFrom, setDateFrom] = useState("");
1116
886
  const [dateTo, setDateTo] = useState("");
1117
887
  const [amountMin, setAmountMin] = useState("");
@@ -1323,7 +1093,7 @@ const RefundsPage = () => {
1323
1093
  Badge,
1324
1094
  {
1325
1095
  size: "2xsmall",
1326
- className: `uppercase ${getStatusBadgeClass$6(displayStatus(r))}`,
1096
+ className: `uppercase ${getStatusBadgeClass$7(displayStatus(r))}`,
1327
1097
  children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1328
1098
  }
1329
1099
  ) }),
@@ -1377,11 +1147,11 @@ const RefundsPage = () => {
1377
1147
  ) }) : null
1378
1148
  ] }) });
1379
1149
  };
1380
- const config$6 = defineRouteConfig({
1150
+ const config$7 = defineRouteConfig({
1381
1151
  label: "Refunds",
1382
1152
  icon: Receipt
1383
1153
  });
1384
- const useDebounce$1 = (value, delay) => {
1154
+ const useDebounce$2 = (value, delay) => {
1385
1155
  const [debouncedValue, setDebouncedValue] = useState(value);
1386
1156
  useEffect(() => {
1387
1157
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1389,7 +1159,7 @@ const useDebounce$1 = (value, delay) => {
1389
1159
  }, [value, delay]);
1390
1160
  return debouncedValue;
1391
1161
  };
1392
- const getStatusBadgeClass$5 = (status) => {
1162
+ const getStatusBadgeClass$6 = (status) => {
1393
1163
  const statusLower = status.toLowerCase();
1394
1164
  if (statusLower === "requested") {
1395
1165
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -1414,7 +1184,7 @@ const ReturnsPage = () => {
1414
1184
  const [statusFilter, setStatusFilter] = useState("all");
1415
1185
  const [createdByFilter, setCreatedByFilter] = useState("all");
1416
1186
  const [searchQuery, setSearchQuery] = useState("");
1417
- const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1187
+ const debouncedSearchQuery = useDebounce$2(searchQuery, 300);
1418
1188
  const [isLoading, setIsLoading] = useState(true);
1419
1189
  const [isFetchingMore, setIsFetchingMore] = useState(false);
1420
1190
  const [error, setError] = useState(null);
@@ -1560,7 +1330,7 @@ const ReturnsPage = () => {
1560
1330
  Badge,
1561
1331
  {
1562
1332
  size: "2xsmall",
1563
- className: `uppercase ${getStatusBadgeClass$5(returnOrder.status)}`,
1333
+ className: `uppercase ${getStatusBadgeClass$6(returnOrder.status)}`,
1564
1334
  children: returnOrder.status.replace(/_/g, " ")
1565
1335
  }
1566
1336
  ) }),
@@ -1609,11 +1379,11 @@ const ReturnsPage = () => {
1609
1379
  ) }) : null
1610
1380
  ] }) });
1611
1381
  };
1612
- const config$5 = defineRouteConfig({
1382
+ const config$6 = defineRouteConfig({
1613
1383
  label: "Return Orders",
1614
1384
  icon: ArrowPath
1615
1385
  });
1616
- const useDebounce = (value, delay) => {
1386
+ const useDebounce$1 = (value, delay) => {
1617
1387
  const [debouncedValue, setDebouncedValue] = useState(value);
1618
1388
  useEffect(() => {
1619
1389
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1621,7 +1391,7 @@ const useDebounce = (value, delay) => {
1621
1391
  }, [value, delay]);
1622
1392
  return debouncedValue;
1623
1393
  };
1624
- const getStatusBadgeClass$4 = (status) => {
1394
+ const getStatusBadgeClass$5 = (status) => {
1625
1395
  const s2 = status.toLowerCase();
1626
1396
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1627
1397
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1634,7 +1404,7 @@ const PaymentsPage = () => {
1634
1404
  const [items, setItems] = useState([]);
1635
1405
  const [statusFilter, setStatusFilter] = useState("all");
1636
1406
  const [orderIdSearch, setOrderIdSearch] = useState("");
1637
- const debouncedOrderId = useDebounce(orderIdSearch, 300);
1407
+ const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1638
1408
  const [isLoading, setIsLoading] = useState(true);
1639
1409
  const [isFetchingMore, setIsFetchingMore] = useState(false);
1640
1410
  const [error, setError] = useState(null);
@@ -1754,7 +1524,7 @@ const PaymentsPage = () => {
1754
1524
  Badge,
1755
1525
  {
1756
1526
  size: "2xsmall",
1757
- className: `uppercase ${getStatusBadgeClass$4(displayStatus(t))}`,
1527
+ className: `uppercase ${getStatusBadgeClass$5(displayStatus(t))}`,
1758
1528
  children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1759
1529
  }
1760
1530
  ) }),
@@ -1809,11 +1579,19 @@ const PaymentsPage = () => {
1809
1579
  ) }) : null
1810
1580
  ] }) });
1811
1581
  };
1812
- const config$4 = defineRouteConfig({
1582
+ const config$5 = defineRouteConfig({
1813
1583
  label: "Payments",
1814
1584
  icon: CreditCard
1815
1585
  });
1816
- const getStatusBadgeClass$3 = (status) => {
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) => {
1817
1595
  const statusLower = status.toLowerCase();
1818
1596
  if (statusLower === "requested") {
1819
1597
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -1827,11 +1605,425 @@ const getStatusBadgeClass$3 = (status) => {
1827
1605
  if (statusLower === "completed") {
1828
1606
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
1829
1607
  }
1830
- if (statusLower === "cancelled" || statusLower === "canceled") {
1608
+ if (statusLower === "cancelled") {
1831
1609
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1832
1610
  }
1833
- if (statusLower === "pending") {
1834
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
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 s2 = status.toLowerCase();
1818
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1819
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1820
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1821
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1822
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1823
+ };
1824
+ const formatAmount = (value) => {
1825
+ return String(value);
1826
+ };
1827
+ const RefundDetailPage = () => {
1828
+ var _a, _b, _c;
1829
+ const navigate = useNavigate();
1830
+ const params = useParams();
1831
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
1832
+ const [detail, setDetail] = useState(null);
1833
+ const [loading, setLoading] = useState(!!id);
1834
+ const [error, setError] = useState(null);
1835
+ const [gatewayExpanded, setGatewayExpanded] = useState(false);
1836
+ useEffect(() => {
1837
+ if (!id) {
1838
+ setLoading(false);
1839
+ return;
1840
+ }
1841
+ let cancelled = false;
1842
+ setLoading(true);
1843
+ setError(null);
1844
+ fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
1845
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
1846
+ return res.json();
1847
+ }).then((data) => {
1848
+ if (!cancelled) setDetail(data);
1849
+ }).catch((e) => {
1850
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
1851
+ }).finally(() => {
1852
+ if (!cancelled) setLoading(false);
1853
+ });
1854
+ return () => {
1855
+ cancelled = true;
1856
+ };
1857
+ }, [id]);
1858
+ const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
1859
+ 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;
1860
+ 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: [
1861
+ /* @__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: [
1862
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
1863
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Refund details" }),
1864
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
1865
+ ] }) }),
1866
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1867
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1868
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
1869
+ ] }) : 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: [
1870
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1871
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
1872
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1873
+ /* @__PURE__ */ jsxs("div", { children: [
1874
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
1875
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
1876
+ ] }),
1877
+ /* @__PURE__ */ jsxs("div", { children: [
1878
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
1879
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
1880
+ ] }),
1881
+ /* @__PURE__ */ jsxs("div", { children: [
1882
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
1883
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
1884
+ ] }),
1885
+ /* @__PURE__ */ jsxs("div", { children: [
1886
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
1887
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
1888
+ year: "numeric",
1889
+ month: "short",
1890
+ day: "numeric",
1891
+ hour: "numeric",
1892
+ minute: "2-digit",
1893
+ hour12: true
1894
+ }) })
1895
+ ] }),
1896
+ detail.refund.created_by ? /* @__PURE__ */ jsxs("div", { children: [
1897
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
1898
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
1899
+ ] }) : null
1900
+ ] })
1901
+ ] }),
1902
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1903
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
1904
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1905
+ /* @__PURE__ */ jsxs("div", { children: [
1906
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
1907
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
1908
+ ] }),
1909
+ /* @__PURE__ */ jsxs("div", { children: [
1910
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
1911
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
1912
+ ] }),
1913
+ /* @__PURE__ */ jsxs("div", { children: [
1914
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
1915
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
1916
+ ] }),
1917
+ /* @__PURE__ */ jsxs("div", { children: [
1918
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
1919
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
1920
+ ] }),
1921
+ /* @__PURE__ */ jsxs("div", { children: [
1922
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
1923
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
1924
+ Badge,
1925
+ {
1926
+ size: "2xsmall",
1927
+ className: `uppercase ${getStatusBadgeClass$3(paymentStatus)}`,
1928
+ children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
1929
+ }
1930
+ ) })
1931
+ ] }),
1932
+ detail.computed ? /* @__PURE__ */ jsxs(Fragment, { children: [
1933
+ /* @__PURE__ */ jsxs("div", { children: [
1934
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
1935
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
1936
+ ] }),
1937
+ /* @__PURE__ */ jsxs("div", { children: [
1938
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
1939
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
1940
+ ] }),
1941
+ /* @__PURE__ */ jsxs("div", { children: [
1942
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
1943
+ /* @__PURE__ */ jsxs(Text, { className: "mt-1 block", children: [
1944
+ detail.computed.refund_percentage.toFixed(1),
1945
+ "%"
1946
+ ] })
1947
+ ] })
1948
+ ] }) : null
1949
+ ] })
1950
+ ] }),
1951
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1952
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
1953
+ detail.order ? /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1954
+ /* @__PURE__ */ jsxs("div", { children: [
1955
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
1956
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
1957
+ Button,
1958
+ {
1959
+ variant: "transparent",
1960
+ size: "small",
1961
+ onClick: () => navigate(`/orders/${detail.order.order_id}`),
1962
+ children: detail.order.order_number ?? detail.order.order_id
1963
+ }
1964
+ ) })
1965
+ ] }),
1966
+ detail.order.total != null ? /* @__PURE__ */ jsxs("div", { children: [
1967
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
1968
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
1969
+ ] }) : null,
1970
+ detail.order.customer_id ? /* @__PURE__ */ jsxs("div", { children: [
1971
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
1972
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
1973
+ ] }) : null,
1974
+ detail.order.region ? /* @__PURE__ */ jsxs("div", { children: [
1975
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
1976
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.region })
1977
+ ] }) : null,
1978
+ detail.order.fulfillment_status ? /* @__PURE__ */ jsxs("div", { children: [
1979
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
1980
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
1981
+ ] }) : null
1982
+ ] }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
1983
+ ] }),
1984
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1985
+ /* @__PURE__ */ jsxs(
1986
+ "button",
1987
+ {
1988
+ type: "button",
1989
+ className: "flex w-full items-center justify-between text-left",
1990
+ onClick: () => setGatewayExpanded((prev) => !prev),
1991
+ "aria-expanded": gatewayExpanded,
1992
+ "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
1993
+ children: [
1994
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
1995
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
1996
+ ]
1997
+ }
1998
+ ),
1999
+ 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." }) })
2000
+ ] })
2001
+ ] }) : null
2002
+ ] }) });
2003
+ };
2004
+ const config$3 = defineRouteConfig({
2005
+ label: "Refund details",
2006
+ icon: Receipt
2007
+ });
2008
+ const getStatusBadgeClass$2 = (status) => {
2009
+ const statusLower = status.toLowerCase();
2010
+ if (statusLower === "requested") {
2011
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2012
+ }
2013
+ if (statusLower === "approved") {
2014
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2015
+ }
2016
+ if (statusLower === "rejected") {
2017
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
2018
+ }
2019
+ if (statusLower === "completed") {
2020
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2021
+ }
2022
+ if (statusLower === "cancelled" || statusLower === "canceled") {
2023
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2024
+ }
2025
+ if (statusLower === "pending") {
2026
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1835
2027
  }
1836
2028
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1837
2029
  };
@@ -1951,7 +2143,7 @@ const SwapDetailPage = () => {
1951
2143
  Badge,
1952
2144
  {
1953
2145
  size: "small",
1954
- className: `uppercase ${getStatusBadgeClass$3(swap.status)}`,
2146
+ className: `uppercase ${getStatusBadgeClass$2(swap.status)}`,
1955
2147
  children: swap.status.replace(/_/g, " ")
1956
2148
  }
1957
2149
  )
@@ -2019,7 +2211,7 @@ const SwapDetailPage = () => {
2019
2211
  Badge,
2020
2212
  {
2021
2213
  size: "2xsmall",
2022
- className: `uppercase ${getStatusBadgeClass$3(entry.status)}`,
2214
+ className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2023
2215
  children: entry.status.replace(/_/g, " ")
2024
2216
  }
2025
2217
  ) }),
@@ -2088,11 +2280,11 @@ const SwapDetailPage = () => {
2088
2280
  ] })
2089
2281
  ] }) });
2090
2282
  };
2091
- const config$3 = defineRouteConfig({
2283
+ const config$2 = defineRouteConfig({
2092
2284
  label: "Swap Details",
2093
2285
  icon: ArrowPath
2094
2286
  });
2095
- const getStatusBadgeClass$2 = (status) => {
2287
+ const getStatusBadgeClass$1 = (status) => {
2096
2288
  const s2 = status.toLowerCase();
2097
2289
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2098
2290
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -2100,18 +2292,14 @@ const getStatusBadgeClass$2 = (status) => {
2100
2292
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2101
2293
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2102
2294
  };
2103
- const formatAmount = (value) => {
2104
- return String(value);
2105
- };
2106
- const RefundDetailPage = () => {
2107
- var _a, _b, _c;
2295
+ const PaymentDetailPage = () => {
2296
+ var _a;
2108
2297
  const navigate = useNavigate();
2109
2298
  const params = useParams();
2110
2299
  const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2111
2300
  const [detail, setDetail] = useState(null);
2112
2301
  const [loading, setLoading] = useState(!!id);
2113
2302
  const [error, setError] = useState(null);
2114
- const [gatewayExpanded, setGatewayExpanded] = useState(false);
2115
2303
  useEffect(() => {
2116
2304
  if (!id) {
2117
2305
  setLoading(false);
@@ -2120,7 +2308,7 @@ const RefundDetailPage = () => {
2120
2308
  let cancelled = false;
2121
2309
  setLoading(true);
2122
2310
  setError(null);
2123
- fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
2311
+ fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2124
2312
  if (!res.ok) throw new Error(res.statusText || "Failed to load");
2125
2313
  return res.json();
2126
2314
  }).then((data) => {
@@ -2134,157 +2322,88 @@ const RefundDetailPage = () => {
2134
2322
  cancelled = true;
2135
2323
  };
2136
2324
  }, [id]);
2137
- const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
2138
- 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;
2325
+ const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
2326
+ const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
2327
+ const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
2328
+ const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
2139
2329
  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: [
2140
2330
  /* @__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: [
2141
- /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
2142
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Refund details" }),
2143
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
2331
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
2332
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payment session" }),
2333
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
2144
2334
  ] }) }),
2145
2335
  error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2146
2336
  /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2147
- /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
2337
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
2148
2338
  ] }) : 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: [
2149
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2150
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
2151
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2152
- /* @__PURE__ */ jsxs("div", { children: [
2153
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
2154
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
2155
- ] }),
2156
- /* @__PURE__ */ jsxs("div", { children: [
2157
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2158
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
2159
- ] }),
2160
- /* @__PURE__ */ jsxs("div", { children: [
2161
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2162
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2163
- ] }),
2164
- /* @__PURE__ */ jsxs("div", { children: [
2165
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2166
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2167
- year: "numeric",
2168
- month: "short",
2169
- day: "numeric",
2170
- hour: "numeric",
2171
- minute: "2-digit",
2172
- hour12: true
2173
- }) })
2174
- ] }),
2175
- detail.refund.created_by ? /* @__PURE__ */ jsxs("div", { children: [
2176
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
2177
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
2178
- ] }) : null
2179
- ] })
2180
- ] }),
2181
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2182
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
2183
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2184
- /* @__PURE__ */ jsxs("div", { children: [
2185
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
2186
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
2187
- ] }),
2188
- /* @__PURE__ */ jsxs("div", { children: [
2189
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
2190
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2191
- ] }),
2192
- /* @__PURE__ */ jsxs("div", { children: [
2193
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
2194
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2195
- ] }),
2196
- /* @__PURE__ */ jsxs("div", { children: [
2197
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2198
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
2199
- ] }),
2200
- /* @__PURE__ */ jsxs("div", { children: [
2201
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2202
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2203
- Badge,
2204
- {
2205
- size: "2xsmall",
2206
- className: `uppercase ${getStatusBadgeClass$2(paymentStatus)}`,
2207
- children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2208
- }
2209
- ) })
2210
- ] }),
2211
- detail.computed ? /* @__PURE__ */ jsxs(Fragment, { children: [
2212
- /* @__PURE__ */ jsxs("div", { children: [
2213
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
2214
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
2215
- ] }),
2216
- /* @__PURE__ */ jsxs("div", { children: [
2217
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
2218
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
2219
- ] }),
2220
- /* @__PURE__ */ jsxs("div", { children: [
2221
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
2222
- /* @__PURE__ */ jsxs(Text, { className: "mt-1 block", children: [
2223
- detail.computed.refund_percentage.toFixed(1),
2224
- "%"
2225
- ] })
2226
- ] })
2227
- ] }) : null
2339
+ /* @__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: [
2340
+ /* @__PURE__ */ jsxs("div", { children: [
2341
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
2342
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsx(
2343
+ Button,
2344
+ {
2345
+ variant: "transparent",
2346
+ size: "small",
2347
+ onClick: () => navigate(`/orders/${detail.order_id}`),
2348
+ children: detail.order_id
2349
+ }
2350
+ ) : /* @__PURE__ */ jsx(Text, { children: "—" }) })
2351
+ ] }),
2352
+ /* @__PURE__ */ jsxs("div", { children: [
2353
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2354
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: displayAmount })
2355
+ ] }),
2356
+ /* @__PURE__ */ jsxs("div", { children: [
2357
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2358
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.provider_id })
2359
+ ] }),
2360
+ /* @__PURE__ */ jsxs("div", { children: [
2361
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2362
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2363
+ Badge,
2364
+ {
2365
+ size: "2xsmall",
2366
+ className: `uppercase ${getStatusBadgeClass$1(displayStatus)}`,
2367
+ children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2368
+ }
2369
+ ) })
2370
+ ] }),
2371
+ /* @__PURE__ */ jsxs("div", { children: [
2372
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
2373
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: sessionStatusRaw })
2374
+ ] }),
2375
+ /* @__PURE__ */ jsxs("div", { children: [
2376
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
2377
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: paymentStatusRaw })
2378
+ ] }),
2379
+ /* @__PURE__ */ jsxs("div", { children: [
2380
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
2381
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
2382
+ ] }),
2383
+ /* @__PURE__ */ jsxs("div", { children: [
2384
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
2385
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2386
+ year: "numeric",
2387
+ month: "short",
2388
+ day: "numeric",
2389
+ hour: "numeric",
2390
+ minute: "2-digit",
2391
+ hour12: true
2392
+ }) })
2228
2393
  ] })
2229
- ] }),
2230
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2231
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
2232
- detail.order ? /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2233
- /* @__PURE__ */ jsxs("div", { children: [
2234
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
2235
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2236
- Button,
2237
- {
2238
- variant: "transparent",
2239
- size: "small",
2240
- onClick: () => navigate(`/orders/${detail.order.order_id}`),
2241
- children: detail.order.order_number ?? detail.order.order_id
2242
- }
2243
- ) })
2244
- ] }),
2245
- detail.order.total != null ? /* @__PURE__ */ jsxs("div", { children: [
2246
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
2247
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
2248
- ] }) : null,
2249
- detail.order.customer_id ? /* @__PURE__ */ jsxs("div", { children: [
2250
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
2251
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
2252
- ] }) : null,
2253
- detail.order.region ? /* @__PURE__ */ jsxs("div", { children: [
2254
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
2255
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.region })
2256
- ] }) : null,
2257
- detail.order.fulfillment_status ? /* @__PURE__ */ jsxs("div", { children: [
2258
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
2259
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
2260
- ] }) : null
2261
- ] }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
2262
- ] }),
2263
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2264
- /* @__PURE__ */ jsxs(
2265
- "button",
2266
- {
2267
- type: "button",
2268
- className: "flex w-full items-center justify-between text-left",
2269
- onClick: () => setGatewayExpanded((prev) => !prev),
2270
- "aria-expanded": gatewayExpanded,
2271
- "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
2272
- children: [
2273
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
2274
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
2275
- ]
2276
- }
2277
- ),
2278
- 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." }) })
2279
- ] })
2394
+ ] }) }),
2395
+ Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2396
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2397
+ /* @__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) })
2398
+ ] }) : /* @__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." }) })
2280
2399
  ] }) : null
2281
2400
  ] }) });
2282
2401
  };
2283
- const config$2 = defineRouteConfig({
2284
- label: "Refund details",
2285
- icon: Receipt
2402
+ const config$1 = defineRouteConfig({
2403
+ label: "Payment details",
2404
+ icon: CreditCard
2286
2405
  });
2287
- const getStatusBadgeClass$1 = (status) => {
2406
+ const getStatusBadgeClass = (status) => {
2288
2407
  const statusLower = status.toLowerCase();
2289
2408
  if (statusLower === "requested") {
2290
2409
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2418,7 +2537,7 @@ const ReturnDetailPage = () => {
2418
2537
  Badge,
2419
2538
  {
2420
2539
  size: "small",
2421
- className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
2540
+ className: `uppercase ${getStatusBadgeClass(returnOrder.status)}`,
2422
2541
  children: returnOrder.status.replace(/_/g, " ")
2423
2542
  }
2424
2543
  )
@@ -2500,7 +2619,7 @@ const ReturnDetailPage = () => {
2500
2619
  Badge,
2501
2620
  {
2502
2621
  size: "2xsmall",
2503
- className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
2622
+ className: `uppercase ${getStatusBadgeClass(entry.status)}`,
2504
2623
  children: entry.status.replace(/_/g, " ")
2505
2624
  }
2506
2625
  ) }),
@@ -2558,129 +2677,10 @@ const ReturnDetailPage = () => {
2558
2677
  updateSuccess && /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2559
2678
  ] }) });
2560
2679
  };
2561
- const config$1 = defineRouteConfig({
2680
+ const config = defineRouteConfig({
2562
2681
  label: "Return Order Details",
2563
2682
  icon: CheckCircle
2564
2683
  });
2565
- const getStatusBadgeClass = (status) => {
2566
- const s2 = status.toLowerCase();
2567
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2568
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2569
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2570
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2571
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2572
- };
2573
- const PaymentDetailPage = () => {
2574
- var _a;
2575
- const navigate = useNavigate();
2576
- const params = useParams();
2577
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2578
- const [detail, setDetail] = useState(null);
2579
- const [loading, setLoading] = useState(!!id);
2580
- const [error, setError] = useState(null);
2581
- useEffect(() => {
2582
- if (!id) {
2583
- setLoading(false);
2584
- return;
2585
- }
2586
- let cancelled = false;
2587
- setLoading(true);
2588
- setError(null);
2589
- fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2590
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2591
- return res.json();
2592
- }).then((data) => {
2593
- if (!cancelled) setDetail(data);
2594
- }).catch((e) => {
2595
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2596
- }).finally(() => {
2597
- if (!cancelled) setLoading(false);
2598
- });
2599
- return () => {
2600
- cancelled = true;
2601
- };
2602
- }, [id]);
2603
- const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
2604
- const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
2605
- const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
2606
- const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
2607
- return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
2608
- /* @__PURE__ */ jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2609
- /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
2610
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payment session" }),
2611
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
2612
- ] }) }),
2613
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2614
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2615
- /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
2616
- ] }) : loading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
2617
- /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2618
- /* @__PURE__ */ jsxs("div", { children: [
2619
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
2620
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsx(
2621
- Button,
2622
- {
2623
- variant: "transparent",
2624
- size: "small",
2625
- onClick: () => navigate(`/orders/${detail.order_id}`),
2626
- children: detail.order_id
2627
- }
2628
- ) : /* @__PURE__ */ jsx(Text, { children: "—" }) })
2629
- ] }),
2630
- /* @__PURE__ */ jsxs("div", { children: [
2631
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2632
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: displayAmount })
2633
- ] }),
2634
- /* @__PURE__ */ jsxs("div", { children: [
2635
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2636
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.provider_id })
2637
- ] }),
2638
- /* @__PURE__ */ jsxs("div", { children: [
2639
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2640
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2641
- Badge,
2642
- {
2643
- size: "2xsmall",
2644
- className: `uppercase ${getStatusBadgeClass(displayStatus)}`,
2645
- children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2646
- }
2647
- ) })
2648
- ] }),
2649
- /* @__PURE__ */ jsxs("div", { children: [
2650
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
2651
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: sessionStatusRaw })
2652
- ] }),
2653
- /* @__PURE__ */ jsxs("div", { children: [
2654
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
2655
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: paymentStatusRaw })
2656
- ] }),
2657
- /* @__PURE__ */ jsxs("div", { children: [
2658
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
2659
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
2660
- ] }),
2661
- /* @__PURE__ */ jsxs("div", { children: [
2662
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
2663
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2664
- year: "numeric",
2665
- month: "short",
2666
- day: "numeric",
2667
- hour: "numeric",
2668
- minute: "2-digit",
2669
- hour12: true
2670
- }) })
2671
- ] })
2672
- ] }) }),
2673
- Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2674
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2675
- /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.data, null, 2) })
2676
- ] }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
2677
- ] }) : null
2678
- ] }) });
2679
- };
2680
- const config = defineRouteConfig({
2681
- label: "Payment details",
2682
- icon: CreditCard
2683
- });
2684
2684
  const i18nTranslations0 = {};
2685
2685
  const widgetModule = { widgets: [
2686
2686
  {
@@ -2694,10 +2694,6 @@ const widgetModule = { widgets: [
2694
2694
  ] };
2695
2695
  const routeModule = {
2696
2696
  routes: [
2697
- {
2698
- Component: SwapsPage,
2699
- path: "/swaps"
2700
- },
2701
2697
  {
2702
2698
  Component: RefundsPage,
2703
2699
  path: "/refunds"
@@ -2711,20 +2707,24 @@ const routeModule = {
2711
2707
  path: "/payments"
2712
2708
  },
2713
2709
  {
2714
- Component: SwapDetailPage,
2715
- path: "/swaps/:id"
2710
+ Component: SwapsPage,
2711
+ path: "/swaps"
2716
2712
  },
2717
2713
  {
2718
2714
  Component: RefundDetailPage,
2719
2715
  path: "/refunds/:id"
2720
2716
  },
2721
2717
  {
2722
- Component: ReturnDetailPage,
2723
- path: "/returns/:id"
2718
+ Component: SwapDetailPage,
2719
+ path: "/swaps/:id"
2724
2720
  },
2725
2721
  {
2726
2722
  Component: PaymentDetailPage,
2727
2723
  path: "/payments/:id"
2724
+ },
2725
+ {
2726
+ Component: ReturnDetailPage,
2727
+ path: "/returns/:id"
2728
2728
  }
2729
2729
  ]
2730
2730
  };
@@ -2733,49 +2733,49 @@ const menuItemModule = {
2733
2733
  {
2734
2734
  label: config$5.label,
2735
2735
  icon: config$5.icon,
2736
- path: "/returns",
2736
+ path: "/payments",
2737
2737
  nested: void 0
2738
2738
  },
2739
2739
  {
2740
2740
  label: config$6.label,
2741
2741
  icon: config$6.icon,
2742
- path: "/refunds",
2742
+ path: "/returns",
2743
2743
  nested: void 0
2744
2744
  },
2745
2745
  {
2746
- label: config$4.label,
2747
- icon: config$4.icon,
2748
- path: "/payments",
2746
+ label: config$7.label,
2747
+ icon: config$7.icon,
2748
+ path: "/refunds",
2749
2749
  nested: void 0
2750
2750
  },
2751
2751
  {
2752
- label: config$7.label,
2753
- icon: config$7.icon,
2752
+ label: config$4.label,
2753
+ icon: config$4.icon,
2754
2754
  path: "/swaps",
2755
2755
  nested: void 0
2756
2756
  },
2757
2757
  {
2758
- label: config$1.label,
2759
- icon: config$1.icon,
2758
+ label: config.label,
2759
+ icon: config.icon,
2760
2760
  path: "/returns/:id",
2761
2761
  nested: void 0
2762
2762
  },
2763
2763
  {
2764
- label: config.label,
2765
- icon: config.icon,
2764
+ label: config$1.label,
2765
+ icon: config$1.icon,
2766
2766
  path: "/payments/:id",
2767
2767
  nested: void 0
2768
2768
  },
2769
2769
  {
2770
2770
  label: config$2.label,
2771
2771
  icon: config$2.icon,
2772
- path: "/refunds/:id",
2772
+ path: "/swaps/:id",
2773
2773
  nested: void 0
2774
2774
  },
2775
2775
  {
2776
2776
  label: config$3.label,
2777
2777
  icon: config$3.icon,
2778
- path: "/swaps/:id",
2778
+ path: "/refunds/:id",
2779
2779
  nested: void 0
2780
2780
  }
2781
2781
  ]