order-management 0.0.88 → 0.0.89

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, Receipt, ArrowPath, CreditCard, ArrowLeft, CheckCircle } from "@medusajs/icons";
5
+ import { CashSolid, PencilSquareSolid, Trash, CreditCard, Receipt, ArrowPath, CheckCircle, ArrowLeft } from "@medusajs/icons";
6
6
  import { useNavigate, useParams } from "react-router-dom";
7
7
  function roundRectPath(ctx, x, y, w, h, r) {
8
8
  ctx.beginPath();
@@ -872,16 +872,216 @@ const getStatusBadgeClass$7 = (status) => {
872
872
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
873
873
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
874
874
  };
875
- const RefundsPage = () => {
875
+ const PaymentsPage = () => {
876
876
  const navigate = useNavigate();
877
877
  const [items, setItems] = useState([]);
878
+ const [statusFilter, setStatusFilter] = useState("all");
878
879
  const [orderIdSearch, setOrderIdSearch] = useState("");
879
880
  const debouncedOrderId = useDebounce$3(orderIdSearch, 300);
881
+ const [isLoading, setIsLoading] = useState(true);
882
+ const [isFetchingMore, setIsFetchingMore] = useState(false);
883
+ const [error, setError] = useState(null);
884
+ const [offset, setOffset] = useState(0);
885
+ const [count, setCount] = useState(0);
886
+ const limit = 50;
887
+ const loadTransactions = useCallback(
888
+ async (nextOffset, replace) => {
889
+ try {
890
+ if (replace) setIsLoading(true);
891
+ else setIsFetchingMore(true);
892
+ setError(null);
893
+ const params = new URLSearchParams();
894
+ params.set("limit", String(limit));
895
+ params.set("offset", String(nextOffset));
896
+ if (statusFilter !== "all") params.set("status", statusFilter);
897
+ if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
898
+ const response = await fetch(
899
+ `/admin/payment-transactions?${params.toString()}`,
900
+ { credentials: "include" }
901
+ );
902
+ if (!response.ok) {
903
+ const text = await response.text();
904
+ throw new Error(text || "Failed to load payment transactions");
905
+ }
906
+ const payload = await response.json();
907
+ const list = payload.transactions ?? [];
908
+ setCount(payload.count ?? 0);
909
+ setOffset(nextOffset + list.length);
910
+ setItems((prev) => replace ? list : [...prev, ...list]);
911
+ } catch (e) {
912
+ setError(e instanceof Error ? e.message : "Failed to load");
913
+ } finally {
914
+ setIsLoading(false);
915
+ setIsFetchingMore(false);
916
+ }
917
+ },
918
+ [statusFilter, debouncedOrderId]
919
+ );
920
+ useEffect(() => {
921
+ void loadTransactions(0, true);
922
+ }, [loadTransactions]);
923
+ const hasMore = useMemo(() => offset < count, [offset, count]);
924
+ const displayStatus = (t) => {
925
+ const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
926
+ return s2 !== "" ? s2 : "—";
927
+ };
928
+ const displayAmount = (t) => {
929
+ const code = (t.currency_code ?? "USD").toUpperCase();
930
+ return `${code} ${Number(t.amount)}`;
931
+ };
932
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
933
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
934
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
935
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payments" }),
936
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
937
+ ] }),
938
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
939
+ ] }),
940
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
941
+ /* @__PURE__ */ jsx(
942
+ Input,
943
+ {
944
+ placeholder: "Search by Order ID",
945
+ value: orderIdSearch,
946
+ onChange: (e) => setOrderIdSearch(e.target.value),
947
+ className: "md:max-w-sm",
948
+ "aria-label": "Search by order ID"
949
+ }
950
+ ),
951
+ /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxs(
952
+ "select",
953
+ {
954
+ value: statusFilter,
955
+ onChange: (e) => setStatusFilter(e.target.value),
956
+ className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
957
+ "aria-label": "Filter by status",
958
+ children: [
959
+ /* @__PURE__ */ jsx("option", { value: "all", children: "All statuses" }),
960
+ /* @__PURE__ */ jsx("option", { value: "pending", children: "Pending" }),
961
+ /* @__PURE__ */ jsx("option", { value: "requires_more", children: "Requires more" }),
962
+ /* @__PURE__ */ jsx("option", { value: "error", children: "Error" }),
963
+ /* @__PURE__ */ jsx("option", { value: "canceled", children: "Canceled" }),
964
+ /* @__PURE__ */ jsx("option", { value: "authorized", children: "Authorized" }),
965
+ /* @__PURE__ */ jsx("option", { value: "captured", children: "Captured" })
966
+ ]
967
+ }
968
+ ) })
969
+ ] }),
970
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
971
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
972
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
973
+ ] }) : null,
974
+ isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
975
+ /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
976
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
977
+ ] }) : /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
978
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
979
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
980
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
981
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
982
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
983
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
984
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
985
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
986
+ ] }) }),
987
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxs(
988
+ "tr",
989
+ {
990
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
991
+ onClick: () => navigate(`/payments/${t.payment_session_id}`),
992
+ children: [
993
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
994
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
995
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
996
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
997
+ Badge,
998
+ {
999
+ size: "2xsmall",
1000
+ className: `uppercase ${getStatusBadgeClass$7(displayStatus(t))}`,
1001
+ children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1002
+ }
1003
+ ) }),
1004
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1005
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1006
+ year: "numeric",
1007
+ month: "short",
1008
+ day: "numeric",
1009
+ hour: "numeric",
1010
+ minute: "2-digit",
1011
+ hour12: true
1012
+ }) }),
1013
+ /* @__PURE__ */ jsxs("td", { className: "px-4 py-4", children: [
1014
+ /* @__PURE__ */ jsx(
1015
+ Button,
1016
+ {
1017
+ variant: "transparent",
1018
+ size: "small",
1019
+ onClick: (e) => {
1020
+ e.stopPropagation();
1021
+ navigate(`/payments/${t.payment_session_id}`);
1022
+ },
1023
+ children: "View details"
1024
+ }
1025
+ ),
1026
+ t.order_id ? /* @__PURE__ */ jsx(
1027
+ Button,
1028
+ {
1029
+ variant: "transparent",
1030
+ size: "small",
1031
+ onClick: (e) => {
1032
+ e.stopPropagation();
1033
+ navigate(`/orders/${t.order_id}`);
1034
+ },
1035
+ children: "Order"
1036
+ }
1037
+ ) : null
1038
+ ] })
1039
+ ]
1040
+ },
1041
+ t.payment_session_id
1042
+ )) })
1043
+ ] }) }),
1044
+ hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
1045
+ Button,
1046
+ {
1047
+ variant: "secondary",
1048
+ isLoading: isFetchingMore,
1049
+ onClick: () => loadTransactions(offset, false),
1050
+ children: "Load more"
1051
+ }
1052
+ ) }) : null
1053
+ ] }) });
1054
+ };
1055
+ const config$7 = defineRouteConfig({
1056
+ label: "Payments",
1057
+ icon: CreditCard
1058
+ });
1059
+ const useDebounce$2 = (value, delay) => {
1060
+ const [debouncedValue, setDebouncedValue] = useState(value);
1061
+ useEffect(() => {
1062
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
1063
+ return () => clearTimeout(handler);
1064
+ }, [value, delay]);
1065
+ return debouncedValue;
1066
+ };
1067
+ const getStatusBadgeClass$6 = (status) => {
1068
+ const s2 = status.toLowerCase();
1069
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1070
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1071
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1072
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1073
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1074
+ };
1075
+ const RefundsPage = () => {
1076
+ const navigate = useNavigate();
1077
+ const [items, setItems] = useState([]);
1078
+ const [orderIdSearch, setOrderIdSearch] = useState("");
1079
+ const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
880
1080
  const [paymentStatusFilter, setPaymentStatusFilter] = useState("all");
881
1081
  const [providerSearch, setProviderSearch] = useState("");
882
- const debouncedProvider = useDebounce$3(providerSearch, 300);
1082
+ const debouncedProvider = useDebounce$2(providerSearch, 300);
883
1083
  const [currencySearch, setCurrencySearch] = useState("");
884
- const debouncedCurrency = useDebounce$3(currencySearch, 300);
1084
+ const debouncedCurrency = useDebounce$2(currencySearch, 300);
885
1085
  const [dateFrom, setDateFrom] = useState("");
886
1086
  const [dateTo, setDateTo] = useState("");
887
1087
  const [amountMin, setAmountMin] = useState("");
@@ -1093,7 +1293,7 @@ const RefundsPage = () => {
1093
1293
  Badge,
1094
1294
  {
1095
1295
  size: "2xsmall",
1096
- className: `uppercase ${getStatusBadgeClass$7(displayStatus(r))}`,
1296
+ className: `uppercase ${getStatusBadgeClass$6(displayStatus(r))}`,
1097
1297
  children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1098
1298
  }
1099
1299
  ) }),
@@ -1147,11 +1347,11 @@ const RefundsPage = () => {
1147
1347
  ) }) : null
1148
1348
  ] }) });
1149
1349
  };
1150
- const config$7 = defineRouteConfig({
1350
+ const config$6 = defineRouteConfig({
1151
1351
  label: "Refunds",
1152
1352
  icon: Receipt
1153
1353
  });
1154
- const useDebounce$2 = (value, delay) => {
1354
+ const useDebounce$1 = (value, delay) => {
1155
1355
  const [debouncedValue, setDebouncedValue] = useState(value);
1156
1356
  useEffect(() => {
1157
1357
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1159,7 +1359,7 @@ const useDebounce$2 = (value, delay) => {
1159
1359
  }, [value, delay]);
1160
1360
  return debouncedValue;
1161
1361
  };
1162
- const getStatusBadgeClass$6 = (status) => {
1362
+ const getStatusBadgeClass$5 = (status) => {
1163
1363
  const statusLower = status.toLowerCase();
1164
1364
  if (statusLower === "requested") {
1165
1365
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -1184,7 +1384,7 @@ const ReturnsPage = () => {
1184
1384
  const [statusFilter, setStatusFilter] = useState("all");
1185
1385
  const [createdByFilter, setCreatedByFilter] = useState("all");
1186
1386
  const [searchQuery, setSearchQuery] = useState("");
1187
- const debouncedSearchQuery = useDebounce$2(searchQuery, 300);
1387
+ const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1188
1388
  const [isLoading, setIsLoading] = useState(true);
1189
1389
  const [isFetchingMore, setIsFetchingMore] = useState(false);
1190
1390
  const [error, setError] = useState(null);
@@ -1330,7 +1530,7 @@ const ReturnsPage = () => {
1330
1530
  Badge,
1331
1531
  {
1332
1532
  size: "2xsmall",
1333
- className: `uppercase ${getStatusBadgeClass$6(returnOrder.status)}`,
1533
+ className: `uppercase ${getStatusBadgeClass$5(returnOrder.status)}`,
1334
1534
  children: returnOrder.status.replace(/_/g, " ")
1335
1535
  }
1336
1536
  ) }),
@@ -1379,11 +1579,11 @@ const ReturnsPage = () => {
1379
1579
  ) }) : null
1380
1580
  ] }) });
1381
1581
  };
1382
- const config$6 = defineRouteConfig({
1582
+ const config$5 = defineRouteConfig({
1383
1583
  label: "Return Orders",
1384
1584
  icon: ArrowPath
1385
1585
  });
1386
- const useDebounce$1 = (value, delay) => {
1586
+ const useDebounce = (value, delay) => {
1387
1587
  const [debouncedValue, setDebouncedValue] = useState(value);
1388
1588
  useEffect(() => {
1389
1589
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1391,247 +1591,47 @@ const useDebounce$1 = (value, delay) => {
1391
1591
  }, [value, delay]);
1392
1592
  return debouncedValue;
1393
1593
  };
1394
- const getStatusBadgeClass$5 = (status) => {
1395
- const s2 = status.toLowerCase();
1396
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1397
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1398
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1399
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1594
+ const getStatusBadgeClass$4 = (status) => {
1595
+ const statusLower = status.toLowerCase();
1596
+ if (statusLower === "requested") {
1597
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1598
+ }
1599
+ if (statusLower === "approved") {
1600
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1601
+ }
1602
+ if (statusLower === "rejected") {
1603
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
1604
+ }
1605
+ if (statusLower === "completed") {
1606
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
1607
+ }
1608
+ if (statusLower === "cancelled") {
1609
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1610
+ }
1400
1611
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1401
1612
  };
1402
- const PaymentsPage = () => {
1613
+ const SwapsPage = () => {
1403
1614
  const navigate = useNavigate();
1404
1615
  const [items, setItems] = useState([]);
1405
1616
  const [statusFilter, setStatusFilter] = useState("all");
1406
- const [orderIdSearch, setOrderIdSearch] = useState("");
1407
- const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1617
+ const [createdByFilter, setCreatedByFilter] = useState("all");
1618
+ const [searchQuery, setSearchQuery] = useState("");
1619
+ const debouncedSearchQuery = useDebounce(searchQuery, 300);
1408
1620
  const [isLoading, setIsLoading] = useState(true);
1409
1621
  const [isFetchingMore, setIsFetchingMore] = useState(false);
1410
1622
  const [error, setError] = useState(null);
1411
1623
  const [offset, setOffset] = useState(0);
1412
1624
  const [count, setCount] = useState(0);
1413
1625
  const limit = 50;
1414
- const loadTransactions = useCallback(
1415
- async (nextOffset, replace) => {
1626
+ const loadSwaps = useCallback(
1627
+ async (nextOffset, replace = false) => {
1628
+ var _a;
1416
1629
  try {
1417
- if (replace) setIsLoading(true);
1418
- else setIsFetchingMore(true);
1419
- setError(null);
1420
- const params = new URLSearchParams();
1421
- params.set("limit", String(limit));
1422
- params.set("offset", String(nextOffset));
1423
- if (statusFilter !== "all") params.set("status", statusFilter);
1424
- if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
1425
- const response = await fetch(
1426
- `/admin/payment-transactions?${params.toString()}`,
1427
- { credentials: "include" }
1428
- );
1429
- if (!response.ok) {
1430
- const text = await response.text();
1431
- throw new Error(text || "Failed to load payment transactions");
1432
- }
1433
- const payload = await response.json();
1434
- const list = payload.transactions ?? [];
1435
- setCount(payload.count ?? 0);
1436
- setOffset(nextOffset + list.length);
1437
- setItems((prev) => replace ? list : [...prev, ...list]);
1438
- } catch (e) {
1439
- setError(e instanceof Error ? e.message : "Failed to load");
1440
- } finally {
1441
- setIsLoading(false);
1442
- setIsFetchingMore(false);
1443
- }
1444
- },
1445
- [statusFilter, debouncedOrderId]
1446
- );
1447
- useEffect(() => {
1448
- void loadTransactions(0, true);
1449
- }, [loadTransactions]);
1450
- const hasMore = useMemo(() => offset < count, [offset, count]);
1451
- const displayStatus = (t) => {
1452
- const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
1453
- return s2 !== "" ? s2 : "—";
1454
- };
1455
- const displayAmount = (t) => {
1456
- const code = (t.currency_code ?? "USD").toUpperCase();
1457
- return `${code} ${Number(t.amount)}`;
1458
- };
1459
- 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: [
1460
- /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1461
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1462
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payments" }),
1463
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
1464
- ] }),
1465
- /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
1466
- ] }),
1467
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1468
- /* @__PURE__ */ jsx(
1469
- Input,
1470
- {
1471
- placeholder: "Search by Order ID",
1472
- value: orderIdSearch,
1473
- onChange: (e) => setOrderIdSearch(e.target.value),
1474
- className: "md:max-w-sm",
1475
- "aria-label": "Search by order ID"
1476
- }
1477
- ),
1478
- /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxs(
1479
- "select",
1480
- {
1481
- value: statusFilter,
1482
- onChange: (e) => setStatusFilter(e.target.value),
1483
- 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",
1484
- "aria-label": "Filter by status",
1485
- children: [
1486
- /* @__PURE__ */ jsx("option", { value: "all", children: "All statuses" }),
1487
- /* @__PURE__ */ jsx("option", { value: "pending", children: "Pending" }),
1488
- /* @__PURE__ */ jsx("option", { value: "requires_more", children: "Requires more" }),
1489
- /* @__PURE__ */ jsx("option", { value: "error", children: "Error" }),
1490
- /* @__PURE__ */ jsx("option", { value: "canceled", children: "Canceled" }),
1491
- /* @__PURE__ */ jsx("option", { value: "authorized", children: "Authorized" }),
1492
- /* @__PURE__ */ jsx("option", { value: "captured", children: "Captured" })
1493
- ]
1494
- }
1495
- ) })
1496
- ] }),
1497
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1498
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1499
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
1500
- ] }) : null,
1501
- isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1502
- /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
1503
- /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
1504
- ] }) : /* @__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: [
1505
- /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
1506
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1507
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1508
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1509
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1510
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
1511
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1512
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1513
- ] }) }),
1514
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxs(
1515
- "tr",
1516
- {
1517
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1518
- onClick: () => navigate(`/payments/${t.payment_session_id}`),
1519
- children: [
1520
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
1521
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
1522
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
1523
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1524
- Badge,
1525
- {
1526
- size: "2xsmall",
1527
- className: `uppercase ${getStatusBadgeClass$5(displayStatus(t))}`,
1528
- children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1529
- }
1530
- ) }),
1531
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
1532
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
1533
- year: "numeric",
1534
- month: "short",
1535
- day: "numeric",
1536
- hour: "numeric",
1537
- minute: "2-digit",
1538
- hour12: true
1539
- }) }),
1540
- /* @__PURE__ */ jsxs("td", { className: "px-4 py-4", children: [
1541
- /* @__PURE__ */ jsx(
1542
- Button,
1543
- {
1544
- variant: "transparent",
1545
- size: "small",
1546
- onClick: (e) => {
1547
- e.stopPropagation();
1548
- navigate(`/payments/${t.payment_session_id}`);
1549
- },
1550
- children: "View details"
1551
- }
1552
- ),
1553
- t.order_id ? /* @__PURE__ */ jsx(
1554
- Button,
1555
- {
1556
- variant: "transparent",
1557
- size: "small",
1558
- onClick: (e) => {
1559
- e.stopPropagation();
1560
- navigate(`/orders/${t.order_id}`);
1561
- },
1562
- children: "Order"
1563
- }
1564
- ) : null
1565
- ] })
1566
- ]
1567
- },
1568
- t.payment_session_id
1569
- )) })
1570
- ] }) }),
1571
- hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
1572
- Button,
1573
- {
1574
- variant: "secondary",
1575
- isLoading: isFetchingMore,
1576
- onClick: () => loadTransactions(offset, false),
1577
- children: "Load more"
1578
- }
1579
- ) }) : null
1580
- ] }) });
1581
- };
1582
- const config$5 = defineRouteConfig({
1583
- label: "Payments",
1584
- icon: CreditCard
1585
- });
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) => {
1595
- const statusLower = status.toLowerCase();
1596
- if (statusLower === "requested") {
1597
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1598
- }
1599
- if (statusLower === "approved") {
1600
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1601
- }
1602
- if (statusLower === "rejected") {
1603
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
1604
- }
1605
- if (statusLower === "completed") {
1606
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
1607
- }
1608
- if (statusLower === "cancelled") {
1609
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1610
- }
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
- }
1630
+ if (replace) {
1631
+ setIsLoading(true);
1632
+ } else {
1633
+ setIsFetchingMore(true);
1634
+ }
1635
1635
  setError(null);
1636
1636
  const params = new URLSearchParams();
1637
1637
  params.set("limit", String(limit));
@@ -1821,18 +1821,14 @@ const getStatusBadgeClass$3 = (status) => {
1821
1821
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1822
1822
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1823
1823
  };
1824
- const formatAmount = (value) => {
1825
- return String(value);
1826
- };
1827
- const RefundDetailPage = () => {
1828
- var _a, _b, _c;
1824
+ const PaymentDetailPage = () => {
1825
+ var _a;
1829
1826
  const navigate = useNavigate();
1830
1827
  const params = useParams();
1831
1828
  const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
1832
1829
  const [detail, setDetail] = useState(null);
1833
1830
  const [loading, setLoading] = useState(!!id);
1834
1831
  const [error, setError] = useState(null);
1835
- const [gatewayExpanded, setGatewayExpanded] = useState(false);
1836
1832
  useEffect(() => {
1837
1833
  if (!id) {
1838
1834
  setLoading(false);
@@ -1841,7 +1837,7 @@ const RefundDetailPage = () => {
1841
1837
  let cancelled = false;
1842
1838
  setLoading(true);
1843
1839
  setError(null);
1844
- fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
1840
+ fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
1845
1841
  if (!res.ok) throw new Error(res.statusText || "Failed to load");
1846
1842
  return res.json();
1847
1843
  }).then((data) => {
@@ -1855,40 +1851,163 @@ const RefundDetailPage = () => {
1855
1851
  cancelled = true;
1856
1852
  };
1857
1853
  }, [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;
1854
+ const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
1855
+ const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
1856
+ const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
1857
+ const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
1860
1858
  return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
1861
1859
  /* @__PURE__ */ jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
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 ?? "—" })
1860
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
1861
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Payment session" }),
1862
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
1865
1863
  ] }) }),
1866
1864
  error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1867
1865
  /* @__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" })
1866
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
1869
1867
  ] }) : loading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
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",
1868
+ /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1869
+ /* @__PURE__ */ jsxs("div", { children: [
1870
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
1871
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsx(
1872
+ Button,
1873
+ {
1874
+ variant: "transparent",
1875
+ size: "small",
1876
+ onClick: () => navigate(`/orders/${detail.order_id}`),
1877
+ children: detail.order_id
1878
+ }
1879
+ ) : /* @__PURE__ */ jsx(Text, { children: "—" }) })
1880
+ ] }),
1881
+ /* @__PURE__ */ jsxs("div", { children: [
1882
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
1883
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: displayAmount })
1884
+ ] }),
1885
+ /* @__PURE__ */ jsxs("div", { children: [
1886
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
1887
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.provider_id })
1888
+ ] }),
1889
+ /* @__PURE__ */ jsxs("div", { children: [
1890
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
1891
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
1892
+ Badge,
1893
+ {
1894
+ size: "2xsmall",
1895
+ className: `uppercase ${getStatusBadgeClass$3(displayStatus)}`,
1896
+ children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
1897
+ }
1898
+ ) })
1899
+ ] }),
1900
+ /* @__PURE__ */ jsxs("div", { children: [
1901
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
1902
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: sessionStatusRaw })
1903
+ ] }),
1904
+ /* @__PURE__ */ jsxs("div", { children: [
1905
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
1906
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: paymentStatusRaw })
1907
+ ] }),
1908
+ /* @__PURE__ */ jsxs("div", { children: [
1909
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
1910
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
1911
+ ] }),
1912
+ /* @__PURE__ */ jsxs("div", { children: [
1913
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
1914
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
1915
+ year: "numeric",
1916
+ month: "short",
1917
+ day: "numeric",
1918
+ hour: "numeric",
1919
+ minute: "2-digit",
1920
+ hour12: true
1921
+ }) })
1922
+ ] })
1923
+ ] }) }),
1924
+ Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1925
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
1926
+ /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.data, null, 2) })
1927
+ ] }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
1928
+ ] }) : null
1929
+ ] }) });
1930
+ };
1931
+ const config$3 = defineRouteConfig({
1932
+ label: "Payment details",
1933
+ icon: CreditCard
1934
+ });
1935
+ const getStatusBadgeClass$2 = (status) => {
1936
+ const s2 = status.toLowerCase();
1937
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1938
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1939
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1940
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1941
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1942
+ };
1943
+ const formatAmount = (value) => {
1944
+ return String(value);
1945
+ };
1946
+ const RefundDetailPage = () => {
1947
+ var _a, _b, _c;
1948
+ const navigate = useNavigate();
1949
+ const params = useParams();
1950
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
1951
+ const [detail, setDetail] = useState(null);
1952
+ const [loading, setLoading] = useState(!!id);
1953
+ const [error, setError] = useState(null);
1954
+ const [gatewayExpanded, setGatewayExpanded] = useState(false);
1955
+ useEffect(() => {
1956
+ if (!id) {
1957
+ setLoading(false);
1958
+ return;
1959
+ }
1960
+ let cancelled = false;
1961
+ setLoading(true);
1962
+ setError(null);
1963
+ fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
1964
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
1965
+ return res.json();
1966
+ }).then((data) => {
1967
+ if (!cancelled) setDetail(data);
1968
+ }).catch((e) => {
1969
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
1970
+ }).finally(() => {
1971
+ if (!cancelled) setLoading(false);
1972
+ });
1973
+ return () => {
1974
+ cancelled = true;
1975
+ };
1976
+ }, [id]);
1977
+ const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
1978
+ 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;
1979
+ 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: [
1980
+ /* @__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: [
1981
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
1982
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Refund details" }),
1983
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
1984
+ ] }) }),
1985
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1986
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1987
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
1988
+ ] }) : 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: [
1989
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1990
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
1991
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1992
+ /* @__PURE__ */ jsxs("div", { children: [
1993
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
1994
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
1995
+ ] }),
1996
+ /* @__PURE__ */ jsxs("div", { children: [
1997
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
1998
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
1999
+ ] }),
2000
+ /* @__PURE__ */ jsxs("div", { children: [
2001
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2002
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2003
+ ] }),
2004
+ /* @__PURE__ */ jsxs("div", { children: [
2005
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2006
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2007
+ year: "numeric",
2008
+ month: "short",
2009
+ day: "numeric",
2010
+ hour: "numeric",
1892
2011
  minute: "2-digit",
1893
2012
  hour12: true
1894
2013
  }) })
@@ -1924,7 +2043,7 @@ const RefundDetailPage = () => {
1924
2043
  Badge,
1925
2044
  {
1926
2045
  size: "2xsmall",
1927
- className: `uppercase ${getStatusBadgeClass$3(paymentStatus)}`,
2046
+ className: `uppercase ${getStatusBadgeClass$2(paymentStatus)}`,
1928
2047
  children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
1929
2048
  }
1930
2049
  ) })
@@ -2001,11 +2120,11 @@ const RefundDetailPage = () => {
2001
2120
  ] }) : null
2002
2121
  ] }) });
2003
2122
  };
2004
- const config$3 = defineRouteConfig({
2123
+ const config$2 = defineRouteConfig({
2005
2124
  label: "Refund details",
2006
2125
  icon: Receipt
2007
2126
  });
2008
- const getStatusBadgeClass$2 = (status) => {
2127
+ const getStatusBadgeClass$1 = (status) => {
2009
2128
  const statusLower = status.toLowerCase();
2010
2129
  if (statusLower === "requested") {
2011
2130
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2016,109 +2135,105 @@ const getStatusBadgeClass$2 = (status) => {
2016
2135
  if (statusLower === "rejected") {
2017
2136
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
2018
2137
  }
2138
+ if (statusLower === "received") {
2139
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2140
+ }
2141
+ if (statusLower === "refunded") {
2142
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2143
+ }
2019
2144
  if (statusLower === "completed") {
2020
2145
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
2021
2146
  }
2022
- if (statusLower === "cancelled" || statusLower === "canceled") {
2147
+ if (statusLower === "cancelled") {
2023
2148
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2024
2149
  }
2025
- if (statusLower === "pending") {
2026
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2027
- }
2028
2150
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2029
2151
  };
2030
- const SwapDetailPage = () => {
2031
- var _a, _b, _c;
2152
+ const ReturnDetailPage = () => {
2153
+ var _a, _b;
2032
2154
  const navigate = useNavigate();
2033
2155
  const { id } = useParams();
2034
- const [swap, setSwap] = useState(null);
2035
- const [order, setOrder] = useState(null);
2156
+ const [returnOrder, setReturnOrder] = useState(null);
2036
2157
  const [isLoading, setIsLoading] = useState(true);
2037
- useState(false);
2038
- const [isCancelling, setIsCancelling] = useState(false);
2158
+ const [isRejecting, setIsRejecting] = useState(false);
2039
2159
  const [error, setError] = useState(null);
2040
2160
  const [updateError, setUpdateError] = useState(null);
2041
2161
  const [updateSuccess, setUpdateSuccess] = useState(false);
2042
2162
  useEffect(() => {
2043
2163
  if (!id) {
2044
- navigate("/swaps");
2164
+ navigate("/returns");
2045
2165
  return;
2046
2166
  }
2047
- const loadSwap = async () => {
2167
+ const loadReturn = async () => {
2048
2168
  try {
2049
2169
  setIsLoading(true);
2050
2170
  setError(null);
2051
- const response = await fetch(`/admin/swaps/${id}`, {
2171
+ const response = await fetch(`/admin/returns/${id}`, {
2052
2172
  credentials: "include"
2053
2173
  });
2054
2174
  if (!response.ok) {
2055
2175
  const message = await response.text();
2056
- throw new Error(message || "Unable to load swap");
2176
+ throw new Error(message || "Unable to load return order");
2057
2177
  }
2058
2178
  const payload = await response.json();
2059
- setSwap(payload.swap);
2060
- setOrder(payload.order || null);
2179
+ setReturnOrder(payload.return);
2061
2180
  } catch (loadError) {
2062
- const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
2181
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2063
2182
  setError(message);
2064
2183
  } finally {
2065
2184
  setIsLoading(false);
2066
2185
  }
2067
2186
  };
2068
- void loadSwap();
2187
+ void loadReturn();
2069
2188
  }, [id, navigate]);
2070
- const handleCancelExchange = async () => {
2189
+ const handleReject = async () => {
2071
2190
  if (!id) {
2072
2191
  return;
2073
2192
  }
2074
2193
  try {
2075
- setIsCancelling(true);
2194
+ setIsRejecting(true);
2076
2195
  setUpdateError(null);
2077
2196
  setUpdateSuccess(false);
2078
- const response = await fetch(`/admin/swaps/${id}/cancel`, {
2197
+ const response = await fetch(`/admin/returns/${id}/reject`, {
2079
2198
  method: "POST",
2080
2199
  headers: {
2081
2200
  "Content-Type": "application/json"
2082
2201
  },
2083
- credentials: "include"
2202
+ credentials: "include",
2203
+ body: JSON.stringify({ reason: "Rejected by admin" })
2084
2204
  });
2085
2205
  if (!response.ok) {
2086
2206
  const message = await response.text();
2087
- throw new Error(message || "Unable to cancel exchange");
2207
+ throw new Error(message || "Unable to reject return");
2088
2208
  }
2089
2209
  const payload = await response.json();
2090
- setSwap(payload.swap);
2210
+ setReturnOrder(payload.return);
2091
2211
  setUpdateSuccess(true);
2092
2212
  setTimeout(() => setUpdateSuccess(false), 3e3);
2093
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
2213
+ const detailResponse = await fetch(`/admin/returns/${id}`, {
2094
2214
  credentials: "include"
2095
2215
  });
2096
2216
  if (detailResponse.ok) {
2097
2217
  const detailPayload = await detailResponse.json();
2098
- setSwap(detailPayload.swap);
2099
- setOrder(detailPayload.order || null);
2218
+ setReturnOrder(detailPayload.return);
2100
2219
  }
2101
- } catch (cancelErr) {
2102
- const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
2220
+ } catch (updateErr) {
2221
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2103
2222
  setUpdateError(message);
2104
2223
  } finally {
2105
- setIsCancelling(false);
2224
+ setIsRejecting(false);
2106
2225
  }
2107
2226
  };
2108
- const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
2109
- const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
2110
- ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
2111
- );
2112
2227
  if (isLoading) {
2113
- return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsx(Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading swap..." }) }) }) });
2228
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsx(Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading return order..." }) }) }) });
2114
2229
  }
2115
- if (error || !swap) {
2230
+ if (error || !returnOrder) {
2116
2231
  return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsx(Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2117
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
2118
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
2232
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
2233
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2119
2234
  ] }) }) });
2120
2235
  }
2121
- const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
2236
+ const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2122
2237
  return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
2123
2238
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
2124
2239
  /* @__PURE__ */ jsxs(
@@ -2126,7 +2241,7 @@ const SwapDetailPage = () => {
2126
2241
  {
2127
2242
  variant: "transparent",
2128
2243
  size: "small",
2129
- onClick: () => navigate("/swaps"),
2244
+ onClick: () => navigate("/returns"),
2130
2245
  className: "w-fit",
2131
2246
  children: [
2132
2247
  /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
@@ -2136,67 +2251,81 @@ const SwapDetailPage = () => {
2136
2251
  ),
2137
2252
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2138
2253
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2139
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Exchange Details" }),
2140
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
2254
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Order Details" }),
2255
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2141
2256
  ] }),
2142
2257
  /* @__PURE__ */ jsx(
2143
2258
  Badge,
2144
2259
  {
2145
2260
  size: "small",
2146
- className: `uppercase ${getStatusBadgeClass$2(swap.status)}`,
2147
- children: swap.status.replace(/_/g, " ")
2261
+ className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
2262
+ children: returnOrder.status.replace(/_/g, " ")
2148
2263
  }
2149
2264
  )
2150
2265
  ] })
2151
2266
  ] }),
2152
- canCancelExchange && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2267
+ returnOrder.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2153
2268
  /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsx(
2154
2269
  Button,
2155
2270
  {
2156
2271
  variant: "danger",
2157
- onClick: handleCancelExchange,
2158
- disabled: isCancelling,
2159
- isLoading: isCancelling,
2160
- children: "Cancel Exchange"
2272
+ onClick: handleReject,
2273
+ disabled: isRejecting,
2274
+ isLoading: isRejecting,
2275
+ children: "Reject (Cancel) Return"
2161
2276
  }
2162
2277
  ) }),
2163
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
2278
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
2279
+ ] }),
2280
+ /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2281
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
2282
+ /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2283
+ /* @__PURE__ */ jsxs("div", { children: [
2284
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2285
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2286
+ ] }),
2287
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
2288
+ Button,
2289
+ {
2290
+ variant: "secondary",
2291
+ onClick: () => {
2292
+ window.open(
2293
+ `/app/orders/${returnOrder.order_id}`,
2294
+ "_blank"
2295
+ );
2296
+ },
2297
+ children: "View order"
2298
+ }
2299
+ ) })
2300
+ ] })
2164
2301
  ] }),
2165
2302
  /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2166
2303
  /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2167
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
2304
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2168
2305
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2169
2306
  /* @__PURE__ */ jsxs("div", { children: [
2170
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2171
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.id })
2307
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2308
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2172
2309
  ] }),
2173
2310
  /* @__PURE__ */ jsxs("div", { children: [
2174
2311
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2175
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.status })
2176
- ] }),
2177
- /* @__PURE__ */ jsxs("div", { children: [
2178
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
2179
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
2312
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.status })
2180
2313
  ] }),
2181
- swap.reason && /* @__PURE__ */ jsxs("div", { children: [
2314
+ returnOrder.reason && /* @__PURE__ */ jsxs("div", { children: [
2182
2315
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2183
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.reason })
2316
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.reason })
2184
2317
  ] }),
2185
- swap.note && /* @__PURE__ */ jsxs("div", { children: [
2318
+ returnOrder.note && /* @__PURE__ */ jsxs("div", { children: [
2186
2319
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2187
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.note })
2320
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.note })
2188
2321
  ] }),
2189
2322
  /* @__PURE__ */ jsxs("div", { children: [
2190
2323
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2191
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2324
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2192
2325
  ] }),
2193
2326
  /* @__PURE__ */ jsxs("div", { children: [
2194
2327
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2195
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2196
- ] }),
2197
- swap.exchange_id && /* @__PURE__ */ jsxs("div", { children: [
2198
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2199
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.exchange_id })
2328
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2200
2329
  ] })
2201
2330
  ] })
2202
2331
  ] }),
@@ -2211,7 +2340,7 @@ const SwapDetailPage = () => {
2211
2340
  Badge,
2212
2341
  {
2213
2342
  size: "2xsmall",
2214
- className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2343
+ className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
2215
2344
  children: entry.status.replace(/_/g, " ")
2216
2345
  }
2217
2346
  ) }),
@@ -2226,182 +2355,52 @@ const SwapDetailPage = () => {
2226
2355
  )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2227
2356
  ] })
2228
2357
  ] }),
2229
- order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2358
+ returnOrder.order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2230
2359
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2231
2360
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2232
2361
  /* @__PURE__ */ jsxs("div", { children: [
2233
2362
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2234
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.id })
2363
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.id })
2235
2364
  ] }),
2236
2365
  /* @__PURE__ */ jsxs("div", { children: [
2237
2366
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2238
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.status || "—" })
2367
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2239
2368
  ] }),
2240
2369
  /* @__PURE__ */ jsxs("div", { children: [
2241
2370
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2242
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2371
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2243
2372
  ] }),
2244
- order.total && /* @__PURE__ */ jsxs("div", { children: [
2373
+ returnOrder.order.total && /* @__PURE__ */ jsxs("div", { children: [
2245
2374
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2246
2375
  /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
2247
- order.currency_code || "$",
2248
- (Number(order.total) / 100).toFixed(2)
2376
+ returnOrder.order.currency_code || "$",
2377
+ (Number(returnOrder.order.total) / 100).toFixed(2)
2249
2378
  ] })
2250
2379
  ] })
2251
2380
  ] })
2252
2381
  ] }),
2253
- swap.return_items && swap.return_items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2382
+ returnOrder.return_items && returnOrder.return_items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2254
2383
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2255
2384
  /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2256
2385
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
2257
2386
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
2258
2387
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2259
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2260
- ] }) }),
2261
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2262
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2263
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2264
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2265
- ] }, item.id || index)) })
2266
- ] }) })
2267
- ] }),
2268
- swap.new_items && swap.new_items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2269
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2270
- /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2271
- /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
2272
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2273
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2274
- ] }) }),
2275
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2276
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2277
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2278
- ] }, item.variant_id || index)) })
2279
- ] }) })
2280
- ] })
2281
- ] }) });
2282
- };
2283
- const config$2 = defineRouteConfig({
2284
- label: "Swap Details",
2285
- icon: ArrowPath
2286
- });
2287
- const getStatusBadgeClass$1 = (status) => {
2288
- const s2 = status.toLowerCase();
2289
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2290
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2291
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2292
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2293
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2294
- };
2295
- const PaymentDetailPage = () => {
2296
- var _a;
2297
- const navigate = useNavigate();
2298
- const params = useParams();
2299
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2300
- const [detail, setDetail] = useState(null);
2301
- const [loading, setLoading] = useState(!!id);
2302
- const [error, setError] = useState(null);
2303
- useEffect(() => {
2304
- if (!id) {
2305
- setLoading(false);
2306
- return;
2307
- }
2308
- let cancelled = false;
2309
- setLoading(true);
2310
- setError(null);
2311
- fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2312
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2313
- return res.json();
2314
- }).then((data) => {
2315
- if (!cancelled) setDetail(data);
2316
- }).catch((e) => {
2317
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2318
- }).finally(() => {
2319
- if (!cancelled) setLoading(false);
2320
- });
2321
- return () => {
2322
- cancelled = true;
2323
- };
2324
- }, [id]);
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)}` : "";
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: [
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: [
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 ?? "—" })
2334
- ] }) }),
2335
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2336
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2337
- /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
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: [
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
- }) })
2393
- ] })
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." }) })
2399
- ] }) : null
2388
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2389
+ ] }) }),
2390
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2391
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2392
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2393
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2394
+ ] }, item.id || index)) })
2395
+ ] }) })
2396
+ ] }),
2397
+ updateError && /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-ui-border-error bg-ui-bg-error-subtle p-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error", children: updateError }) }),
2398
+ updateSuccess && /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2400
2399
  ] }) });
2401
2400
  };
2402
2401
  const config$1 = defineRouteConfig({
2403
- label: "Payment details",
2404
- icon: CreditCard
2402
+ label: "Return Order Details",
2403
+ icon: CheckCircle
2405
2404
  });
2406
2405
  const getStatusBadgeClass = (status) => {
2407
2406
  const statusLower = status.toLowerCase();
@@ -2414,105 +2413,109 @@ const getStatusBadgeClass = (status) => {
2414
2413
  if (statusLower === "rejected") {
2415
2414
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
2416
2415
  }
2417
- if (statusLower === "received") {
2418
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2419
- }
2420
- if (statusLower === "refunded") {
2421
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
2422
- }
2423
2416
  if (statusLower === "completed") {
2424
2417
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
2425
2418
  }
2426
- if (statusLower === "cancelled") {
2419
+ if (statusLower === "cancelled" || statusLower === "canceled") {
2427
2420
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2428
2421
  }
2422
+ if (statusLower === "pending") {
2423
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2424
+ }
2429
2425
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2430
2426
  };
2431
- const ReturnDetailPage = () => {
2432
- var _a, _b;
2427
+ const SwapDetailPage = () => {
2428
+ var _a, _b, _c;
2433
2429
  const navigate = useNavigate();
2434
2430
  const { id } = useParams();
2435
- const [returnOrder, setReturnOrder] = useState(null);
2431
+ const [swap, setSwap] = useState(null);
2432
+ const [order, setOrder] = useState(null);
2436
2433
  const [isLoading, setIsLoading] = useState(true);
2437
- const [isRejecting, setIsRejecting] = useState(false);
2434
+ useState(false);
2435
+ const [isCancelling, setIsCancelling] = useState(false);
2438
2436
  const [error, setError] = useState(null);
2439
2437
  const [updateError, setUpdateError] = useState(null);
2440
2438
  const [updateSuccess, setUpdateSuccess] = useState(false);
2441
2439
  useEffect(() => {
2442
2440
  if (!id) {
2443
- navigate("/returns");
2441
+ navigate("/swaps");
2444
2442
  return;
2445
2443
  }
2446
- const loadReturn = async () => {
2444
+ const loadSwap = async () => {
2447
2445
  try {
2448
2446
  setIsLoading(true);
2449
2447
  setError(null);
2450
- const response = await fetch(`/admin/returns/${id}`, {
2448
+ const response = await fetch(`/admin/swaps/${id}`, {
2451
2449
  credentials: "include"
2452
2450
  });
2453
2451
  if (!response.ok) {
2454
2452
  const message = await response.text();
2455
- throw new Error(message || "Unable to load return order");
2453
+ throw new Error(message || "Unable to load swap");
2456
2454
  }
2457
2455
  const payload = await response.json();
2458
- setReturnOrder(payload.return);
2456
+ setSwap(payload.swap);
2457
+ setOrder(payload.order || null);
2459
2458
  } catch (loadError) {
2460
- const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2459
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
2461
2460
  setError(message);
2462
2461
  } finally {
2463
2462
  setIsLoading(false);
2464
2463
  }
2465
2464
  };
2466
- void loadReturn();
2465
+ void loadSwap();
2467
2466
  }, [id, navigate]);
2468
- const handleReject = async () => {
2467
+ const handleCancelExchange = async () => {
2469
2468
  if (!id) {
2470
2469
  return;
2471
2470
  }
2472
2471
  try {
2473
- setIsRejecting(true);
2472
+ setIsCancelling(true);
2474
2473
  setUpdateError(null);
2475
2474
  setUpdateSuccess(false);
2476
- const response = await fetch(`/admin/returns/${id}/reject`, {
2475
+ const response = await fetch(`/admin/swaps/${id}/cancel`, {
2477
2476
  method: "POST",
2478
2477
  headers: {
2479
2478
  "Content-Type": "application/json"
2480
2479
  },
2481
- credentials: "include",
2482
- body: JSON.stringify({ reason: "Rejected by admin" })
2480
+ credentials: "include"
2483
2481
  });
2484
2482
  if (!response.ok) {
2485
2483
  const message = await response.text();
2486
- throw new Error(message || "Unable to reject return");
2484
+ throw new Error(message || "Unable to cancel exchange");
2487
2485
  }
2488
2486
  const payload = await response.json();
2489
- setReturnOrder(payload.return);
2487
+ setSwap(payload.swap);
2490
2488
  setUpdateSuccess(true);
2491
2489
  setTimeout(() => setUpdateSuccess(false), 3e3);
2492
- const detailResponse = await fetch(`/admin/returns/${id}`, {
2490
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
2493
2491
  credentials: "include"
2494
2492
  });
2495
2493
  if (detailResponse.ok) {
2496
2494
  const detailPayload = await detailResponse.json();
2497
- setReturnOrder(detailPayload.return);
2495
+ setSwap(detailPayload.swap);
2496
+ setOrder(detailPayload.order || null);
2498
2497
  }
2499
- } catch (updateErr) {
2500
- const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2498
+ } catch (cancelErr) {
2499
+ const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
2501
2500
  setUpdateError(message);
2502
2501
  } finally {
2503
- setIsRejecting(false);
2502
+ setIsCancelling(false);
2504
2503
  }
2505
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
+ );
2506
2509
  if (isLoading) {
2507
- return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsx(Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading return order..." }) }) }) });
2510
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsx(Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading swap..." }) }) }) });
2508
2511
  }
2509
- if (error || !returnOrder) {
2512
+ if (error || !swap) {
2510
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: [
2511
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
2512
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2514
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
2515
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
2513
2516
  ] }) }) });
2514
2517
  }
2515
- const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2518
+ const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
2516
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: [
2517
2520
  /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3", children: [
2518
2521
  /* @__PURE__ */ jsxs(
@@ -2520,7 +2523,7 @@ const ReturnDetailPage = () => {
2520
2523
  {
2521
2524
  variant: "transparent",
2522
2525
  size: "small",
2523
- onClick: () => navigate("/returns"),
2526
+ onClick: () => navigate("/swaps"),
2524
2527
  className: "w-fit",
2525
2528
  children: [
2526
2529
  /* @__PURE__ */ jsx(ArrowLeft, { className: "mr-2" }),
@@ -2530,81 +2533,67 @@ const ReturnDetailPage = () => {
2530
2533
  ),
2531
2534
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2532
2535
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2533
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Order Details" }),
2534
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2536
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Exchange Details" }),
2537
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
2535
2538
  ] }),
2536
2539
  /* @__PURE__ */ jsx(
2537
2540
  Badge,
2538
2541
  {
2539
2542
  size: "small",
2540
- className: `uppercase ${getStatusBadgeClass(returnOrder.status)}`,
2541
- children: returnOrder.status.replace(/_/g, " ")
2543
+ className: `uppercase ${getStatusBadgeClass(swap.status)}`,
2544
+ children: swap.status.replace(/_/g, " ")
2542
2545
  }
2543
2546
  )
2544
2547
  ] })
2545
2548
  ] }),
2546
- returnOrder.status === "requested" && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2549
+ canCancelExchange && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2547
2550
  /* @__PURE__ */ jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsx(
2548
2551
  Button,
2549
2552
  {
2550
2553
  variant: "danger",
2551
- onClick: handleReject,
2552
- disabled: isRejecting,
2553
- isLoading: isRejecting,
2554
- children: "Reject (Cancel) Return"
2554
+ onClick: handleCancelExchange,
2555
+ disabled: isCancelling,
2556
+ isLoading: isCancelling,
2557
+ children: "Cancel Exchange"
2555
2558
  }
2556
2559
  ) }),
2557
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
2558
- ] }),
2559
- /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2560
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
2561
- /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2562
- /* @__PURE__ */ jsxs("div", { children: [
2563
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2564
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2565
- ] }),
2566
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
2567
- Button,
2568
- {
2569
- variant: "secondary",
2570
- onClick: () => {
2571
- window.open(
2572
- `/app/orders/${returnOrder.order_id}`,
2573
- "_blank"
2574
- );
2575
- },
2576
- children: "View order"
2577
- }
2578
- ) })
2579
- ] })
2560
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
2580
2561
  ] }),
2581
2562
  /* @__PURE__ */ jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2582
2563
  /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2583
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2564
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
2584
2565
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2585
2566
  /* @__PURE__ */ jsxs("div", { children: [
2586
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2587
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.id })
2567
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2568
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.id })
2588
2569
  ] }),
2589
2570
  /* @__PURE__ */ jsxs("div", { children: [
2590
2571
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2591
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.status })
2572
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.status })
2592
2573
  ] }),
2593
- returnOrder.reason && /* @__PURE__ */ jsxs("div", { children: [
2574
+ /* @__PURE__ */ jsxs("div", { children: [
2575
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
2576
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
2577
+ ] }),
2578
+ swap.reason && /* @__PURE__ */ jsxs("div", { children: [
2594
2579
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2595
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.reason })
2580
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.reason })
2596
2581
  ] }),
2597
- returnOrder.note && /* @__PURE__ */ jsxs("div", { children: [
2582
+ swap.note && /* @__PURE__ */ jsxs("div", { children: [
2598
2583
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2599
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.note })
2584
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.note })
2600
2585
  ] }),
2601
2586
  /* @__PURE__ */ jsxs("div", { children: [
2602
2587
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2603
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2588
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2604
2589
  ] }),
2605
2590
  /* @__PURE__ */ jsxs("div", { children: [
2606
2591
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2607
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2592
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2593
+ ] }),
2594
+ swap.exchange_id && /* @__PURE__ */ jsxs("div", { children: [
2595
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2596
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: swap.exchange_id })
2608
2597
  ] })
2609
2598
  ] })
2610
2599
  ] }),
@@ -2634,31 +2623,31 @@ const ReturnDetailPage = () => {
2634
2623
  )) }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2635
2624
  ] })
2636
2625
  ] }),
2637
- returnOrder.order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2626
+ order && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2638
2627
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2639
2628
  /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
2640
2629
  /* @__PURE__ */ jsxs("div", { children: [
2641
2630
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2642
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.id })
2631
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.id })
2643
2632
  ] }),
2644
2633
  /* @__PURE__ */ jsxs("div", { children: [
2645
2634
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2646
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2635
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: order.status || "—" })
2647
2636
  ] }),
2648
2637
  /* @__PURE__ */ jsxs("div", { children: [
2649
2638
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2650
- /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2639
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2651
2640
  ] }),
2652
- returnOrder.order.total && /* @__PURE__ */ jsxs("div", { children: [
2641
+ order.total && /* @__PURE__ */ jsxs("div", { children: [
2653
2642
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2654
2643
  /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
2655
- returnOrder.order.currency_code || "$",
2656
- (Number(returnOrder.order.total) / 100).toFixed(2)
2644
+ order.currency_code || "$",
2645
+ (Number(order.total) / 100).toFixed(2)
2657
2646
  ] })
2658
2647
  ] })
2659
2648
  ] })
2660
2649
  ] }),
2661
- returnOrder.return_items && returnOrder.return_items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2650
+ swap.return_items && swap.return_items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2662
2651
  /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2663
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: [
2664
2653
  /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
@@ -2666,20 +2655,31 @@ const ReturnDetailPage = () => {
2666
2655
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2667
2656
  /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2668
2657
  ] }) }),
2669
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2658
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2670
2659
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2671
2660
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2672
2661
  /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2673
2662
  ] }, item.id || index)) })
2674
2663
  ] }) })
2675
2664
  ] }),
2676
- 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 }) }),
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" }) })
2665
+ swap.new_items && swap.new_items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2666
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2667
+ /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2668
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
2669
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2670
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2671
+ ] }) }),
2672
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxs("tr", { children: [
2673
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2674
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2675
+ ] }, item.variant_id || index)) })
2676
+ ] }) })
2677
+ ] })
2678
2678
  ] }) });
2679
2679
  };
2680
2680
  const config = defineRouteConfig({
2681
- label: "Return Order Details",
2682
- icon: CheckCircle
2681
+ label: "Swap Details",
2682
+ icon: ArrowPath
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: PaymentsPage,
2699
+ path: "/payments"
2700
+ },
2697
2701
  {
2698
2702
  Component: RefundsPage,
2699
2703
  path: "/refunds"
@@ -2702,50 +2706,46 @@ const routeModule = {
2702
2706
  Component: ReturnsPage,
2703
2707
  path: "/returns"
2704
2708
  },
2705
- {
2706
- Component: PaymentsPage,
2707
- path: "/payments"
2708
- },
2709
2709
  {
2710
2710
  Component: SwapsPage,
2711
2711
  path: "/swaps"
2712
2712
  },
2713
- {
2714
- Component: RefundDetailPage,
2715
- path: "/refunds/:id"
2716
- },
2717
- {
2718
- Component: SwapDetailPage,
2719
- path: "/swaps/:id"
2720
- },
2721
2713
  {
2722
2714
  Component: PaymentDetailPage,
2723
2715
  path: "/payments/:id"
2724
2716
  },
2717
+ {
2718
+ Component: RefundDetailPage,
2719
+ path: "/refunds/:id"
2720
+ },
2725
2721
  {
2726
2722
  Component: ReturnDetailPage,
2727
2723
  path: "/returns/:id"
2724
+ },
2725
+ {
2726
+ Component: SwapDetailPage,
2727
+ path: "/swaps/:id"
2728
2728
  }
2729
2729
  ]
2730
2730
  };
2731
2731
  const menuItemModule = {
2732
2732
  menuItems: [
2733
2733
  {
2734
- label: config$5.label,
2735
- icon: config$5.icon,
2734
+ label: config$7.label,
2735
+ icon: config$7.icon,
2736
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: "/returns",
2742
+ path: "/refunds",
2743
2743
  nested: void 0
2744
2744
  },
2745
2745
  {
2746
- label: config$7.label,
2747
- icon: config$7.icon,
2748
- path: "/refunds",
2746
+ label: config$5.label,
2747
+ icon: config$5.icon,
2748
+ path: "/returns",
2749
2749
  nested: void 0
2750
2750
  },
2751
2751
  {
@@ -2755,27 +2755,27 @@ const menuItemModule = {
2755
2755
  nested: void 0
2756
2756
  },
2757
2757
  {
2758
- label: config.label,
2759
- icon: config.icon,
2760
- path: "/returns/:id",
2761
- nested: void 0
2762
- },
2763
- {
2764
- label: config$1.label,
2765
- icon: config$1.icon,
2758
+ label: config$3.label,
2759
+ icon: config$3.icon,
2766
2760
  path: "/payments/:id",
2767
2761
  nested: void 0
2768
2762
  },
2769
2763
  {
2770
2764
  label: config$2.label,
2771
2765
  icon: config$2.icon,
2772
- path: "/swaps/:id",
2766
+ path: "/refunds/:id",
2773
2767
  nested: void 0
2774
2768
  },
2775
2769
  {
2776
- label: config$3.label,
2777
- icon: config$3.icon,
2778
- path: "/refunds/:id",
2770
+ label: config$1.label,
2771
+ icon: config$1.icon,
2772
+ path: "/returns/:id",
2773
+ nested: void 0
2774
+ },
2775
+ {
2776
+ label: config.label,
2777
+ icon: config.icon,
2778
+ path: "/swaps/:id",
2779
2779
  nested: void 0
2780
2780
  }
2781
2781
  ]