order-management 0.0.84 → 0.0.85

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.
@@ -866,238 +866,6 @@ const useDebounce$3 = (value, delay) => {
866
866
  return debouncedValue;
867
867
  };
868
868
  const getStatusBadgeClass$7 = (status) => {
869
- const statusLower = status.toLowerCase();
870
- if (statusLower === "requested") {
871
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
872
- }
873
- if (statusLower === "received") {
874
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
875
- }
876
- if (statusLower === "requires_action") {
877
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
878
- }
879
- if (statusLower === "completed") {
880
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
881
- }
882
- if (statusLower === "canceled") {
883
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
884
- }
885
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
886
- };
887
- const ReturnsPage = () => {
888
- const navigate = reactRouterDom.useNavigate();
889
- const [items, setItems] = react.useState([]);
890
- const [statusFilter, setStatusFilter] = react.useState("all");
891
- const [createdByFilter, setCreatedByFilter] = react.useState("all");
892
- const [searchQuery, setSearchQuery] = react.useState("");
893
- const debouncedSearchQuery = useDebounce$3(searchQuery, 300);
894
- const [isLoading, setIsLoading] = react.useState(true);
895
- const [isFetchingMore, setIsFetchingMore] = react.useState(false);
896
- const [error, setError] = react.useState(null);
897
- const [offset, setOffset] = react.useState(0);
898
- const [count, setCount] = react.useState(0);
899
- const limit = 50;
900
- const loadReturns = react.useCallback(
901
- async (nextOffset, replace = false) => {
902
- var _a;
903
- try {
904
- if (replace) {
905
- setIsLoading(true);
906
- } else {
907
- setIsFetchingMore(true);
908
- }
909
- setError(null);
910
- const params = new URLSearchParams();
911
- params.set("limit", String(limit));
912
- params.set("offset", String(nextOffset));
913
- if (statusFilter !== "all") {
914
- params.set("status", statusFilter);
915
- }
916
- if (debouncedSearchQuery.trim()) {
917
- params.set("q", debouncedSearchQuery.trim());
918
- }
919
- if (createdByFilter !== "all") {
920
- params.set("created_by", createdByFilter);
921
- }
922
- params.set("order", "created_at");
923
- const response = await fetch(
924
- `/admin/return?${params.toString()}`,
925
- { credentials: "include" }
926
- );
927
- if (!response.ok) {
928
- const message = await response.text();
929
- throw new Error(message || "Unable to load return orders");
930
- }
931
- const payload = await response.json();
932
- setCount(payload.count ?? 0);
933
- setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
934
- setItems(
935
- (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
936
- );
937
- } catch (loadError) {
938
- const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
939
- setError(message);
940
- } finally {
941
- setIsLoading(false);
942
- setIsFetchingMore(false);
943
- }
944
- },
945
- [statusFilter, createdByFilter, debouncedSearchQuery]
946
- );
947
- react.useEffect(() => {
948
- void loadReturns(0, true);
949
- }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
950
- const hasMore = react.useMemo(() => offset < count, [offset, count]);
951
- const availableStatuses = react.useMemo(() => {
952
- const statuses = /* @__PURE__ */ new Set();
953
- items.forEach((item) => statuses.add(item.status));
954
- return Array.from(statuses).sort();
955
- }, [items]);
956
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
957
- /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
958
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
959
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Orders" }),
960
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
961
- ] }),
962
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
963
- ] }),
964
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
965
- /* @__PURE__ */ jsxRuntime.jsx(
966
- ui.Input,
967
- {
968
- placeholder: "Search by return ID, order ID, or customer email",
969
- value: searchQuery,
970
- onChange: (event) => setSearchQuery(event.target.value),
971
- className: "md:max-w-sm"
972
- }
973
- ),
974
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
975
- /* @__PURE__ */ jsxRuntime.jsxs(
976
- "select",
977
- {
978
- value: createdByFilter,
979
- onChange: (event) => setCreatedByFilter(event.target.value),
980
- 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",
981
- children: [
982
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All (Created by)" }),
983
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "customer", children: "Customer" }),
984
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "admin", children: "Admin" })
985
- ]
986
- }
987
- ),
988
- /* @__PURE__ */ jsxRuntime.jsxs(
989
- "select",
990
- {
991
- value: statusFilter,
992
- onChange: (event) => setStatusFilter(event.target.value),
993
- 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",
994
- children: [
995
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All Statuses" }),
996
- availableStatuses.map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
997
- ]
998
- }
999
- )
1000
- ] })
1001
- ] }),
1002
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1003
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1004
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1005
- ui.Button,
1006
- {
1007
- variant: "secondary",
1008
- onClick: () => loadReturns(0, true),
1009
- children: "Try again"
1010
- }
1011
- ) })
1012
- ] }) : null,
1013
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return orders..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1014
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1015
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1016
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
1017
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1018
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
1019
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1020
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1021
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1022
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
1023
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1024
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1025
- ] }) }),
1026
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxRuntime.jsxs(
1027
- "tr",
1028
- {
1029
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1030
- onClick: () => navigate(`/returns/${returnOrder.id}`),
1031
- children: [
1032
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: returnOrder.id }) }) }),
1033
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1034
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1035
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1036
- ui.Badge,
1037
- {
1038
- size: "2xsmall",
1039
- className: `uppercase ${getStatusBadgeClass$7(returnOrder.status)}`,
1040
- children: returnOrder.status.replace(/_/g, " ")
1041
- }
1042
- ) }),
1043
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1044
- const amount = returnOrder.refund_amount;
1045
- if (amount == null || amount === void 0) {
1046
- return "—";
1047
- }
1048
- const displayAmount = Number(amount) / 100;
1049
- const currency = returnOrder.currency_code || "$";
1050
- return `${currency}${displayAmount.toFixed(2)}`;
1051
- })() }),
1052
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1053
- year: "numeric",
1054
- month: "short",
1055
- day: "numeric",
1056
- hour: "numeric",
1057
- minute: "2-digit",
1058
- hour12: true
1059
- }) }),
1060
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1061
- ui.Button,
1062
- {
1063
- variant: "transparent",
1064
- size: "small",
1065
- onClick: (e) => {
1066
- e.stopPropagation();
1067
- navigate(`/app/orders/${returnOrder.order_id}`);
1068
- },
1069
- children: "Go to order"
1070
- }
1071
- ) })
1072
- ]
1073
- },
1074
- returnOrder.id
1075
- )) })
1076
- ] }) }),
1077
- hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1078
- ui.Button,
1079
- {
1080
- variant: "secondary",
1081
- isLoading: isFetchingMore,
1082
- onClick: () => loadReturns(offset, false),
1083
- children: "Load more"
1084
- }
1085
- ) }) : null
1086
- ] }) });
1087
- };
1088
- const config$7 = adminSdk.defineRouteConfig({
1089
- label: "Return Orders",
1090
- icon: icons.ArrowPath
1091
- });
1092
- const useDebounce$2 = (value, delay) => {
1093
- const [debouncedValue, setDebouncedValue] = react.useState(value);
1094
- react.useEffect(() => {
1095
- const handler = setTimeout(() => setDebouncedValue(value), delay);
1096
- return () => clearTimeout(handler);
1097
- }, [value, delay]);
1098
- return debouncedValue;
1099
- };
1100
- const getStatusBadgeClass$6 = (status) => {
1101
869
  const s2 = status.toLowerCase();
1102
870
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1103
871
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1110,7 +878,7 @@ const PaymentsPage = () => {
1110
878
  const [items, setItems] = react.useState([]);
1111
879
  const [statusFilter, setStatusFilter] = react.useState("all");
1112
880
  const [orderIdSearch, setOrderIdSearch] = react.useState("");
1113
- const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
881
+ const debouncedOrderId = useDebounce$3(orderIdSearch, 300);
1114
882
  const [isLoading, setIsLoading] = react.useState(true);
1115
883
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1116
884
  const [error, setError] = react.useState(null);
@@ -1230,7 +998,7 @@ const PaymentsPage = () => {
1230
998
  ui.Badge,
1231
999
  {
1232
1000
  size: "2xsmall",
1233
- className: `uppercase ${getStatusBadgeClass$6(displayStatus(t))}`,
1001
+ className: `uppercase ${getStatusBadgeClass$7(displayStatus(t))}`,
1234
1002
  children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
1235
1003
  }
1236
1004
  ) }),
@@ -1285,11 +1053,11 @@ const PaymentsPage = () => {
1285
1053
  ) }) : null
1286
1054
  ] }) });
1287
1055
  };
1288
- const config$6 = adminSdk.defineRouteConfig({
1056
+ const config$7 = adminSdk.defineRouteConfig({
1289
1057
  label: "Payments",
1290
1058
  icon: icons.CreditCard
1291
1059
  });
1292
- const useDebounce$1 = (value, delay) => {
1060
+ const useDebounce$2 = (value, delay) => {
1293
1061
  const [debouncedValue, setDebouncedValue] = react.useState(value);
1294
1062
  react.useEffect(() => {
1295
1063
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1297,28 +1065,258 @@ const useDebounce$1 = (value, delay) => {
1297
1065
  }, [value, delay]);
1298
1066
  return debouncedValue;
1299
1067
  };
1300
- const getStatusBadgeClass$5 = (status) => {
1301
- const s2 = status.toLowerCase();
1302
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1303
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1304
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1305
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1306
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1307
- };
1308
- const RefundsPage = () => {
1309
- const navigate = reactRouterDom.useNavigate();
1310
- const [items, setItems] = react.useState([]);
1311
- const [orderIdSearch, setOrderIdSearch] = react.useState("");
1312
- const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1313
- const [paymentStatusFilter, setPaymentStatusFilter] = react.useState("all");
1314
- const [providerSearch, setProviderSearch] = react.useState("");
1315
- const debouncedProvider = useDebounce$1(providerSearch, 300);
1316
- const [currencySearch, setCurrencySearch] = react.useState("");
1317
- const debouncedCurrency = useDebounce$1(currencySearch, 300);
1318
- const [dateFrom, setDateFrom] = react.useState("");
1319
- const [dateTo, setDateTo] = react.useState("");
1320
- const [amountMin, setAmountMin] = react.useState("");
1321
- const [amountMax, setAmountMax] = react.useState("");
1068
+ const getStatusBadgeClass$6 = (status) => {
1069
+ const statusLower = status.toLowerCase();
1070
+ if (statusLower === "requested") {
1071
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1072
+ }
1073
+ if (statusLower === "approved") {
1074
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1075
+ }
1076
+ if (statusLower === "rejected") {
1077
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
1078
+ }
1079
+ if (statusLower === "completed") {
1080
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
1081
+ }
1082
+ if (statusLower === "cancelled") {
1083
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1084
+ }
1085
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1086
+ };
1087
+ const SwapsPage = () => {
1088
+ const navigate = reactRouterDom.useNavigate();
1089
+ const [items, setItems] = react.useState([]);
1090
+ const [statusFilter, setStatusFilter] = react.useState("all");
1091
+ const [createdByFilter, setCreatedByFilter] = react.useState("all");
1092
+ const [searchQuery, setSearchQuery] = react.useState("");
1093
+ const debouncedSearchQuery = useDebounce$2(searchQuery, 300);
1094
+ const [isLoading, setIsLoading] = react.useState(true);
1095
+ const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1096
+ const [error, setError] = react.useState(null);
1097
+ const [offset, setOffset] = react.useState(0);
1098
+ const [count, setCount] = react.useState(0);
1099
+ const limit = 50;
1100
+ const loadSwaps = react.useCallback(
1101
+ async (nextOffset, replace = false) => {
1102
+ var _a;
1103
+ try {
1104
+ if (replace) {
1105
+ setIsLoading(true);
1106
+ } else {
1107
+ setIsFetchingMore(true);
1108
+ }
1109
+ setError(null);
1110
+ const params = new URLSearchParams();
1111
+ params.set("limit", String(limit));
1112
+ params.set("offset", String(nextOffset));
1113
+ if (statusFilter !== "all") {
1114
+ params.set("status", statusFilter);
1115
+ }
1116
+ if (debouncedSearchQuery.trim()) {
1117
+ params.set("order_id", debouncedSearchQuery.trim());
1118
+ }
1119
+ if (createdByFilter !== "all") {
1120
+ params.set("created_by", createdByFilter);
1121
+ }
1122
+ const response = await fetch(
1123
+ `/admin/swaps?${params.toString()}`,
1124
+ { credentials: "include" }
1125
+ );
1126
+ if (!response.ok) {
1127
+ const message = await response.text();
1128
+ throw new Error(message || "Unable to load swaps");
1129
+ }
1130
+ const payload = await response.json();
1131
+ setCount(payload.count ?? 0);
1132
+ setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
1133
+ setItems(
1134
+ (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
1135
+ );
1136
+ } catch (loadError) {
1137
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
1138
+ setError(message);
1139
+ } finally {
1140
+ setIsLoading(false);
1141
+ setIsFetchingMore(false);
1142
+ }
1143
+ },
1144
+ [statusFilter, createdByFilter, debouncedSearchQuery]
1145
+ );
1146
+ react.useEffect(() => {
1147
+ void loadSwaps(0, true);
1148
+ }, [statusFilter, createdByFilter, debouncedSearchQuery, loadSwaps]);
1149
+ const hasMore = react.useMemo(() => offset < count, [offset, count]);
1150
+ const availableStatuses = react.useMemo(() => {
1151
+ const statuses = /* @__PURE__ */ new Set();
1152
+ items.forEach((item) => statuses.add(item.status));
1153
+ return Array.from(statuses).sort();
1154
+ }, [items]);
1155
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
1156
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1157
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1158
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchanges" }),
1159
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer exchange requests" })
1160
+ ] }),
1161
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
1162
+ ] }),
1163
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1164
+ /* @__PURE__ */ jsxRuntime.jsx(
1165
+ ui.Input,
1166
+ {
1167
+ placeholder: "Search by swap ID or order ID",
1168
+ value: searchQuery,
1169
+ onChange: (event) => setSearchQuery(event.target.value),
1170
+ className: "md:max-w-sm"
1171
+ }
1172
+ ),
1173
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
1174
+ /* @__PURE__ */ jsxRuntime.jsxs(
1175
+ "select",
1176
+ {
1177
+ value: createdByFilter,
1178
+ onChange: (event) => setCreatedByFilter(event.target.value),
1179
+ 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",
1180
+ children: [
1181
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All (Created by)" }),
1182
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "customer", children: "Customer" }),
1183
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "admin", children: "Admin" })
1184
+ ]
1185
+ }
1186
+ ),
1187
+ /* @__PURE__ */ jsxRuntime.jsxs(
1188
+ "select",
1189
+ {
1190
+ value: statusFilter,
1191
+ onChange: (event) => setStatusFilter(event.target.value),
1192
+ 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",
1193
+ children: [
1194
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All Statuses" }),
1195
+ availableStatuses.map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1196
+ ]
1197
+ }
1198
+ )
1199
+ ] })
1200
+ ] }),
1201
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1202
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1203
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1204
+ ui.Button,
1205
+ {
1206
+ variant: "secondary",
1207
+ onClick: () => loadSwaps(0, true),
1208
+ children: "Try again"
1209
+ }
1210
+ ) })
1211
+ ] }) : null,
1212
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swaps..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1213
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No exchanges yet" }),
1214
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Exchange requests created by customers will appear here." })
1215
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
1216
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1217
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Exchange ID" }),
1218
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1219
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1220
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Difference Due" }),
1221
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1222
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1223
+ ] }) }),
1224
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxRuntime.jsxs(
1225
+ "tr",
1226
+ {
1227
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1228
+ onClick: () => navigate(`/swaps/${swap.id}`),
1229
+ children: [
1230
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: swap.id }) }) }),
1231
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: swap.order_id }),
1232
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1233
+ ui.Badge,
1234
+ {
1235
+ size: "2xsmall",
1236
+ className: `uppercase ${getStatusBadgeClass$6(swap.status)}`,
1237
+ children: swap.status.replace(/_/g, " ")
1238
+ }
1239
+ ) }),
1240
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1241
+ const amount = swap.difference_due;
1242
+ if (amount == null || amount === void 0) {
1243
+ return "—";
1244
+ }
1245
+ const displayAmount = Number(amount) / 100;
1246
+ const currency = swap.currency_code || "$";
1247
+ const sign = displayAmount >= 0 ? "+" : "";
1248
+ return `${sign}${currency}${displayAmount.toFixed(2)}`;
1249
+ })() }),
1250
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
1251
+ year: "numeric",
1252
+ month: "short",
1253
+ day: "numeric",
1254
+ hour: "numeric",
1255
+ minute: "2-digit",
1256
+ hour12: true
1257
+ }) }),
1258
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1259
+ ui.Button,
1260
+ {
1261
+ variant: "transparent",
1262
+ size: "small",
1263
+ onClick: (e) => {
1264
+ e.stopPropagation();
1265
+ navigate(`/app/orders/${swap.order_id}`);
1266
+ },
1267
+ children: "Go to order"
1268
+ }
1269
+ ) })
1270
+ ]
1271
+ },
1272
+ swap.id
1273
+ )) })
1274
+ ] }) }),
1275
+ hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1276
+ ui.Button,
1277
+ {
1278
+ variant: "secondary",
1279
+ isLoading: isFetchingMore,
1280
+ onClick: () => loadSwaps(offset, false),
1281
+ children: "Load more"
1282
+ }
1283
+ ) }) : null
1284
+ ] }) });
1285
+ };
1286
+ const config$6 = adminSdk.defineRouteConfig({
1287
+ label: "Exchanges",
1288
+ icon: icons.ArrowPath
1289
+ });
1290
+ const useDebounce$1 = (value, delay) => {
1291
+ const [debouncedValue, setDebouncedValue] = react.useState(value);
1292
+ react.useEffect(() => {
1293
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
1294
+ return () => clearTimeout(handler);
1295
+ }, [value, delay]);
1296
+ return debouncedValue;
1297
+ };
1298
+ const getStatusBadgeClass$5 = (status) => {
1299
+ const s2 = status.toLowerCase();
1300
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1301
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1302
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1303
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1304
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1305
+ };
1306
+ const RefundsPage = () => {
1307
+ const navigate = reactRouterDom.useNavigate();
1308
+ const [items, setItems] = react.useState([]);
1309
+ const [orderIdSearch, setOrderIdSearch] = react.useState("");
1310
+ const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1311
+ const [paymentStatusFilter, setPaymentStatusFilter] = react.useState("all");
1312
+ const [providerSearch, setProviderSearch] = react.useState("");
1313
+ const debouncedProvider = useDebounce$1(providerSearch, 300);
1314
+ const [currencySearch, setCurrencySearch] = react.useState("");
1315
+ const debouncedCurrency = useDebounce$1(currencySearch, 300);
1316
+ const [dateFrom, setDateFrom] = react.useState("");
1317
+ const [dateTo, setDateTo] = react.useState("");
1318
+ const [amountMin, setAmountMin] = react.useState("");
1319
+ const [amountMax, setAmountMax] = react.useState("");
1322
1320
  const [isLoading, setIsLoading] = react.useState(true);
1323
1321
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1324
1322
  const [error, setError] = react.useState(null);
@@ -1597,21 +1595,21 @@ const getStatusBadgeClass$4 = (status) => {
1597
1595
  if (statusLower === "requested") {
1598
1596
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1599
1597
  }
1600
- if (statusLower === "approved") {
1598
+ if (statusLower === "received") {
1601
1599
  return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1602
1600
  }
1603
- if (statusLower === "rejected") {
1601
+ if (statusLower === "requires_action") {
1604
1602
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
1605
1603
  }
1606
1604
  if (statusLower === "completed") {
1607
1605
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
1608
1606
  }
1609
- if (statusLower === "cancelled") {
1607
+ if (statusLower === "canceled") {
1610
1608
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1611
1609
  }
1612
1610
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1613
1611
  };
1614
- const SwapsPage = () => {
1612
+ const ReturnsPage = () => {
1615
1613
  const navigate = reactRouterDom.useNavigate();
1616
1614
  const [items, setItems] = react.useState([]);
1617
1615
  const [statusFilter, setStatusFilter] = react.useState("all");
@@ -1624,7 +1622,7 @@ const SwapsPage = () => {
1624
1622
  const [offset, setOffset] = react.useState(0);
1625
1623
  const [count, setCount] = react.useState(0);
1626
1624
  const limit = 50;
1627
- const loadSwaps = react.useCallback(
1625
+ const loadReturns = react.useCallback(
1628
1626
  async (nextOffset, replace = false) => {
1629
1627
  var _a;
1630
1628
  try {
@@ -1641,27 +1639,28 @@ const SwapsPage = () => {
1641
1639
  params.set("status", statusFilter);
1642
1640
  }
1643
1641
  if (debouncedSearchQuery.trim()) {
1644
- params.set("order_id", debouncedSearchQuery.trim());
1642
+ params.set("q", debouncedSearchQuery.trim());
1645
1643
  }
1646
1644
  if (createdByFilter !== "all") {
1647
1645
  params.set("created_by", createdByFilter);
1648
1646
  }
1647
+ params.set("order", "created_at");
1649
1648
  const response = await fetch(
1650
- `/admin/swaps?${params.toString()}`,
1649
+ `/admin/return?${params.toString()}`,
1651
1650
  { credentials: "include" }
1652
1651
  );
1653
1652
  if (!response.ok) {
1654
1653
  const message = await response.text();
1655
- throw new Error(message || "Unable to load swaps");
1654
+ throw new Error(message || "Unable to load return orders");
1656
1655
  }
1657
1656
  const payload = await response.json();
1658
1657
  setCount(payload.count ?? 0);
1659
- setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
1658
+ setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
1660
1659
  setItems(
1661
- (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
1660
+ (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
1662
1661
  );
1663
1662
  } catch (loadError) {
1664
- const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
1663
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
1665
1664
  setError(message);
1666
1665
  } finally {
1667
1666
  setIsLoading(false);
@@ -1671,8 +1670,8 @@ const SwapsPage = () => {
1671
1670
  [statusFilter, createdByFilter, debouncedSearchQuery]
1672
1671
  );
1673
1672
  react.useEffect(() => {
1674
- void loadSwaps(0, true);
1675
- }, [statusFilter, createdByFilter, debouncedSearchQuery, loadSwaps]);
1673
+ void loadReturns(0, true);
1674
+ }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
1676
1675
  const hasMore = react.useMemo(() => offset < count, [offset, count]);
1677
1676
  const availableStatuses = react.useMemo(() => {
1678
1677
  const statuses = /* @__PURE__ */ new Set();
@@ -1682,16 +1681,16 @@ const SwapsPage = () => {
1682
1681
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
1683
1682
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1684
1683
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1685
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchanges" }),
1686
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer exchange requests" })
1684
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Orders" }),
1685
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
1687
1686
  ] }),
1688
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
1687
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
1689
1688
  ] }),
1690
1689
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1691
1690
  /* @__PURE__ */ jsxRuntime.jsx(
1692
1691
  ui.Input,
1693
1692
  {
1694
- placeholder: "Search by swap ID or order ID",
1693
+ placeholder: "Search by return ID, order ID, or customer email",
1695
1694
  value: searchQuery,
1696
1695
  onChange: (event) => setSearchQuery(event.target.value),
1697
1696
  className: "md:max-w-sm"
@@ -1731,50 +1730,51 @@ const SwapsPage = () => {
1731
1730
  ui.Button,
1732
1731
  {
1733
1732
  variant: "secondary",
1734
- onClick: () => loadSwaps(0, true),
1733
+ onClick: () => loadReturns(0, true),
1735
1734
  children: "Try again"
1736
1735
  }
1737
1736
  ) })
1738
1737
  ] }) : null,
1739
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swaps..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1740
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No exchanges yet" }),
1741
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Exchange requests created by customers will appear here." })
1738
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return orders..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1739
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1740
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1742
1741
  ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
1743
1742
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1744
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Exchange ID" }),
1743
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
1745
1744
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1745
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1746
1746
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1747
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Difference Due" }),
1747
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
1748
1748
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1749
1749
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1750
1750
  ] }) }),
1751
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxRuntime.jsxs(
1751
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxRuntime.jsxs(
1752
1752
  "tr",
1753
1753
  {
1754
1754
  className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1755
- onClick: () => navigate(`/swaps/${swap.id}`),
1755
+ onClick: () => navigate(`/returns/${returnOrder.id}`),
1756
1756
  children: [
1757
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: swap.id }) }) }),
1758
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: swap.order_id }),
1757
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: returnOrder.id }) }) }),
1758
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1759
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1759
1760
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1760
1761
  ui.Badge,
1761
1762
  {
1762
1763
  size: "2xsmall",
1763
- className: `uppercase ${getStatusBadgeClass$4(swap.status)}`,
1764
- children: swap.status.replace(/_/g, " ")
1764
+ className: `uppercase ${getStatusBadgeClass$4(returnOrder.status)}`,
1765
+ children: returnOrder.status.replace(/_/g, " ")
1765
1766
  }
1766
1767
  ) }),
1767
1768
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1768
- const amount = swap.difference_due;
1769
+ const amount = returnOrder.refund_amount;
1769
1770
  if (amount == null || amount === void 0) {
1770
1771
  return "—";
1771
1772
  }
1772
1773
  const displayAmount = Number(amount) / 100;
1773
- const currency = swap.currency_code || "$";
1774
- const sign = displayAmount >= 0 ? "+" : "";
1775
- return `${sign}${currency}${displayAmount.toFixed(2)}`;
1774
+ const currency = returnOrder.currency_code || "$";
1775
+ return `${currency}${displayAmount.toFixed(2)}`;
1776
1776
  })() }),
1777
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
1777
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1778
1778
  year: "numeric",
1779
1779
  month: "short",
1780
1780
  day: "numeric",
@@ -1789,14 +1789,14 @@ const SwapsPage = () => {
1789
1789
  size: "small",
1790
1790
  onClick: (e) => {
1791
1791
  e.stopPropagation();
1792
- navigate(`/app/orders/${swap.order_id}`);
1792
+ navigate(`/app/orders/${returnOrder.order_id}`);
1793
1793
  },
1794
1794
  children: "Go to order"
1795
1795
  }
1796
1796
  ) })
1797
1797
  ]
1798
1798
  },
1799
- swap.id
1799
+ returnOrder.id
1800
1800
  )) })
1801
1801
  ] }) }),
1802
1802
  hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1804,17 +1804,136 @@ const SwapsPage = () => {
1804
1804
  {
1805
1805
  variant: "secondary",
1806
1806
  isLoading: isFetchingMore,
1807
- onClick: () => loadSwaps(offset, false),
1807
+ onClick: () => loadReturns(offset, false),
1808
1808
  children: "Load more"
1809
1809
  }
1810
1810
  ) }) : null
1811
1811
  ] }) });
1812
1812
  };
1813
1813
  const config$4 = adminSdk.defineRouteConfig({
1814
- label: "Exchanges",
1814
+ label: "Return Orders",
1815
1815
  icon: icons.ArrowPath
1816
1816
  });
1817
1817
  const getStatusBadgeClass$3 = (status) => {
1818
+ const s2 = status.toLowerCase();
1819
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1820
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1821
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1822
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1823
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1824
+ };
1825
+ const PaymentDetailPage = () => {
1826
+ var _a;
1827
+ const navigate = reactRouterDom.useNavigate();
1828
+ const params = reactRouterDom.useParams();
1829
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
1830
+ const [detail, setDetail] = react.useState(null);
1831
+ const [loading, setLoading] = react.useState(!!id);
1832
+ const [error, setError] = react.useState(null);
1833
+ react.useEffect(() => {
1834
+ if (!id) {
1835
+ setLoading(false);
1836
+ return;
1837
+ }
1838
+ let cancelled = false;
1839
+ setLoading(true);
1840
+ setError(null);
1841
+ fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
1842
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
1843
+ return res.json();
1844
+ }).then((data) => {
1845
+ if (!cancelled) setDetail(data);
1846
+ }).catch((e) => {
1847
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
1848
+ }).finally(() => {
1849
+ if (!cancelled) setLoading(false);
1850
+ });
1851
+ return () => {
1852
+ cancelled = true;
1853
+ };
1854
+ }, [id]);
1855
+ const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
1856
+ const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
1857
+ const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
1858
+ const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
1859
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
1860
+ /* @__PURE__ */ jsxRuntime.jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1861
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
1862
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payment session" }),
1863
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
1864
+ ] }) }),
1865
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1866
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1867
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
1868
+ ] }) : loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
1869
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1870
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1871
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
1872
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1873
+ ui.Button,
1874
+ {
1875
+ variant: "transparent",
1876
+ size: "small",
1877
+ onClick: () => navigate(`/orders/${detail.order_id}`),
1878
+ children: detail.order_id
1879
+ }
1880
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "—" }) })
1881
+ ] }),
1882
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1883
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
1884
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: displayAmount })
1885
+ ] }),
1886
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1887
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
1888
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.provider_id })
1889
+ ] }),
1890
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1891
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
1892
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
1893
+ ui.Badge,
1894
+ {
1895
+ size: "2xsmall",
1896
+ className: `uppercase ${getStatusBadgeClass$3(displayStatus)}`,
1897
+ children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
1898
+ }
1899
+ ) })
1900
+ ] }),
1901
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1902
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
1903
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: sessionStatusRaw })
1904
+ ] }),
1905
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1906
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
1907
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: paymentStatusRaw })
1908
+ ] }),
1909
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1910
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
1911
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
1912
+ ] }),
1913
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1914
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
1915
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
1916
+ year: "numeric",
1917
+ month: "short",
1918
+ day: "numeric",
1919
+ hour: "numeric",
1920
+ minute: "2-digit",
1921
+ hour12: true
1922
+ }) })
1923
+ ] })
1924
+ ] }) }),
1925
+ Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1926
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
1927
+ /* @__PURE__ */ jsxRuntime.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) })
1928
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
1929
+ ] }) : null
1930
+ ] }) });
1931
+ };
1932
+ const config$3 = adminSdk.defineRouteConfig({
1933
+ label: "Payment details",
1934
+ icon: icons.CreditCard
1935
+ });
1936
+ const getStatusBadgeClass$2 = (status) => {
1818
1937
  const statusLower = status.toLowerCase();
1819
1938
  if (statusLower === "requested") {
1820
1939
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -1825,105 +1944,109 @@ const getStatusBadgeClass$3 = (status) => {
1825
1944
  if (statusLower === "rejected") {
1826
1945
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
1827
1946
  }
1828
- if (statusLower === "received") {
1829
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1830
- }
1831
- if (statusLower === "refunded") {
1832
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
1833
- }
1834
1947
  if (statusLower === "completed") {
1835
1948
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
1836
1949
  }
1837
- if (statusLower === "cancelled") {
1950
+ if (statusLower === "cancelled" || statusLower === "canceled") {
1838
1951
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1839
1952
  }
1953
+ if (statusLower === "pending") {
1954
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1955
+ }
1840
1956
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1841
1957
  };
1842
- const ReturnDetailPage = () => {
1843
- var _a, _b;
1958
+ const SwapDetailPage = () => {
1959
+ var _a, _b, _c;
1844
1960
  const navigate = reactRouterDom.useNavigate();
1845
1961
  const { id } = reactRouterDom.useParams();
1846
- const [returnOrder, setReturnOrder] = react.useState(null);
1962
+ const [swap, setSwap] = react.useState(null);
1963
+ const [order, setOrder] = react.useState(null);
1847
1964
  const [isLoading, setIsLoading] = react.useState(true);
1848
- const [isRejecting, setIsRejecting] = react.useState(false);
1965
+ react.useState(false);
1966
+ const [isCancelling, setIsCancelling] = react.useState(false);
1849
1967
  const [error, setError] = react.useState(null);
1850
1968
  const [updateError, setUpdateError] = react.useState(null);
1851
1969
  const [updateSuccess, setUpdateSuccess] = react.useState(false);
1852
1970
  react.useEffect(() => {
1853
1971
  if (!id) {
1854
- navigate("/returns");
1972
+ navigate("/swaps");
1855
1973
  return;
1856
1974
  }
1857
- const loadReturn = async () => {
1975
+ const loadSwap = async () => {
1858
1976
  try {
1859
1977
  setIsLoading(true);
1860
1978
  setError(null);
1861
- const response = await fetch(`/admin/returns/${id}`, {
1979
+ const response = await fetch(`/admin/swaps/${id}`, {
1862
1980
  credentials: "include"
1863
1981
  });
1864
1982
  if (!response.ok) {
1865
1983
  const message = await response.text();
1866
- throw new Error(message || "Unable to load return order");
1984
+ throw new Error(message || "Unable to load swap");
1867
1985
  }
1868
1986
  const payload = await response.json();
1869
- setReturnOrder(payload.return);
1987
+ setSwap(payload.swap);
1988
+ setOrder(payload.order || null);
1870
1989
  } catch (loadError) {
1871
- const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
1990
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
1872
1991
  setError(message);
1873
1992
  } finally {
1874
1993
  setIsLoading(false);
1875
1994
  }
1876
1995
  };
1877
- void loadReturn();
1996
+ void loadSwap();
1878
1997
  }, [id, navigate]);
1879
- const handleReject = async () => {
1998
+ const handleCancelExchange = async () => {
1880
1999
  if (!id) {
1881
2000
  return;
1882
2001
  }
1883
2002
  try {
1884
- setIsRejecting(true);
2003
+ setIsCancelling(true);
1885
2004
  setUpdateError(null);
1886
2005
  setUpdateSuccess(false);
1887
- const response = await fetch(`/admin/returns/${id}/reject`, {
2006
+ const response = await fetch(`/admin/swaps/${id}/cancel`, {
1888
2007
  method: "POST",
1889
2008
  headers: {
1890
2009
  "Content-Type": "application/json"
1891
2010
  },
1892
- credentials: "include",
1893
- body: JSON.stringify({ reason: "Rejected by admin" })
2011
+ credentials: "include"
1894
2012
  });
1895
2013
  if (!response.ok) {
1896
2014
  const message = await response.text();
1897
- throw new Error(message || "Unable to reject return");
2015
+ throw new Error(message || "Unable to cancel exchange");
1898
2016
  }
1899
2017
  const payload = await response.json();
1900
- setReturnOrder(payload.return);
2018
+ setSwap(payload.swap);
1901
2019
  setUpdateSuccess(true);
1902
2020
  setTimeout(() => setUpdateSuccess(false), 3e3);
1903
- const detailResponse = await fetch(`/admin/returns/${id}`, {
2021
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
1904
2022
  credentials: "include"
1905
2023
  });
1906
2024
  if (detailResponse.ok) {
1907
2025
  const detailPayload = await detailResponse.json();
1908
- setReturnOrder(detailPayload.return);
2026
+ setSwap(detailPayload.swap);
2027
+ setOrder(detailPayload.order || null);
1909
2028
  }
1910
- } catch (updateErr) {
1911
- const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2029
+ } catch (cancelErr) {
2030
+ const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
1912
2031
  setUpdateError(message);
1913
2032
  } finally {
1914
- setIsRejecting(false);
2033
+ setIsCancelling(false);
1915
2034
  }
1916
2035
  };
2036
+ const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
2037
+ const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
2038
+ ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
2039
+ );
1917
2040
  if (isLoading) {
1918
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return order..." }) }) }) });
2041
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swap..." }) }) }) });
1919
2042
  }
1920
- if (error || !returnOrder) {
2043
+ if (error || !swap) {
1921
2044
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1922
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
1923
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2045
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
2046
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
1924
2047
  ] }) }) });
1925
2048
  }
1926
- const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2049
+ const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
1927
2050
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
1928
2051
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
1929
2052
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1931,7 +2054,7 @@ const ReturnDetailPage = () => {
1931
2054
  {
1932
2055
  variant: "transparent",
1933
2056
  size: "small",
1934
- onClick: () => navigate("/returns"),
2057
+ onClick: () => navigate("/swaps"),
1935
2058
  className: "w-fit",
1936
2059
  children: [
1937
2060
  /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
@@ -1941,81 +2064,67 @@ const ReturnDetailPage = () => {
1941
2064
  ),
1942
2065
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
1943
2066
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1944
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Order Details" }),
1945
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2067
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchange Details" }),
2068
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
1946
2069
  ] }),
1947
2070
  /* @__PURE__ */ jsxRuntime.jsx(
1948
2071
  ui.Badge,
1949
2072
  {
1950
2073
  size: "small",
1951
- className: `uppercase ${getStatusBadgeClass$3(returnOrder.status)}`,
1952
- children: returnOrder.status.replace(/_/g, " ")
2074
+ className: `uppercase ${getStatusBadgeClass$2(swap.status)}`,
2075
+ children: swap.status.replace(/_/g, " ")
1953
2076
  }
1954
2077
  )
1955
2078
  ] })
1956
2079
  ] }),
1957
- returnOrder.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
2080
+ canCancelExchange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
1958
2081
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
1959
2082
  ui.Button,
1960
2083
  {
1961
2084
  variant: "danger",
1962
- onClick: handleReject,
1963
- disabled: isRejecting,
1964
- isLoading: isRejecting,
1965
- children: "Reject (Cancel) Return"
2085
+ onClick: handleCancelExchange,
2086
+ disabled: isCancelling,
2087
+ isLoading: isCancelling,
2088
+ children: "Cancel Exchange"
1966
2089
  }
1967
2090
  ) }),
1968
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
1969
- ] }),
1970
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1971
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
1972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1973
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1974
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
1975
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
1976
- ] }),
1977
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
1978
- ui.Button,
1979
- {
1980
- variant: "secondary",
1981
- onClick: () => {
1982
- window.open(
1983
- `/app/orders/${returnOrder.order_id}`,
1984
- "_blank"
1985
- );
1986
- },
1987
- children: "View order"
1988
- }
1989
- ) })
1990
- ] })
2091
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
1991
2092
  ] }),
1992
2093
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
1993
2094
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1994
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2095
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
1995
2096
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1996
2097
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1997
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
1998
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2098
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2099
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
1999
2100
  ] }),
2000
2101
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2001
2102
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2002
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.status })
2103
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
2003
2104
  ] }),
2004
- returnOrder.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2105
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2106
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
2107
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
2108
+ ] }),
2109
+ swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2005
2110
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2006
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.reason })
2111
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
2007
2112
  ] }),
2008
- returnOrder.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2113
+ swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2009
2114
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2010
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.note })
2115
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
2011
2116
  ] }),
2012
2117
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2013
2118
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2014
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2119
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2015
2120
  ] }),
2016
2121
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2017
2122
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2018
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2123
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2124
+ ] }),
2125
+ swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2126
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2127
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
2019
2128
  ] })
2020
2129
  ] })
2021
2130
  ] }),
@@ -2030,7 +2139,7 @@ const ReturnDetailPage = () => {
2030
2139
  ui.Badge,
2031
2140
  {
2032
2141
  size: "2xsmall",
2033
- className: `uppercase ${getStatusBadgeClass$3(entry.status)}`,
2142
+ className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2034
2143
  children: entry.status.replace(/_/g, " ")
2035
2144
  }
2036
2145
  ) }),
@@ -2045,31 +2154,31 @@ const ReturnDetailPage = () => {
2045
2154
  )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2046
2155
  ] })
2047
2156
  ] }),
2048
- returnOrder.order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2157
+ order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2049
2158
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2050
2159
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2051
2160
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2052
2161
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2053
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.id })
2162
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
2054
2163
  ] }),
2055
2164
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2056
2165
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2057
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2166
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
2058
2167
  ] }),
2059
2168
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2060
2169
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2061
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2170
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2062
2171
  ] }),
2063
- returnOrder.order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2172
+ order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2064
2173
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2065
2174
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
2066
- returnOrder.order.currency_code || "$",
2067
- (Number(returnOrder.order.total) / 100).toFixed(2)
2175
+ order.currency_code || "$",
2176
+ (Number(order.total) / 100).toFixed(2)
2068
2177
  ] })
2069
2178
  ] })
2070
2179
  ] })
2071
2180
  ] }),
2072
- returnOrder.return_items && returnOrder.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2181
+ swap.return_items && swap.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2073
2182
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2074
2183
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2075
2184
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
@@ -2077,141 +2186,311 @@ const ReturnDetailPage = () => {
2077
2186
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2078
2187
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2079
2188
  ] }) }),
2080
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2189
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2081
2190
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2082
2191
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2083
2192
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2084
2193
  ] }, item.id || index)) })
2085
2194
  ] }) })
2086
2195
  ] }),
2087
- updateError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-error bg-ui-bg-error-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", children: updateError }) }),
2088
- updateSuccess && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2196
+ swap.new_items && swap.new_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2197
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2198
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2199
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2200
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2201
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2202
+ ] }) }),
2203
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2204
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2205
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2206
+ ] }, item.variant_id || index)) })
2207
+ ] }) })
2208
+ ] })
2089
2209
  ] }) });
2090
2210
  };
2091
- const config$3 = adminSdk.defineRouteConfig({
2092
- label: "Return Order Details",
2093
- icon: icons.CheckCircle
2211
+ const config$2 = adminSdk.defineRouteConfig({
2212
+ label: "Swap Details",
2213
+ icon: icons.ArrowPath
2094
2214
  });
2095
- const getStatusBadgeClass$2 = (status) => {
2096
- const s2 = status.toLowerCase();
2097
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2098
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2099
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2100
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2215
+ const getStatusBadgeClass$1 = (status) => {
2216
+ const statusLower = status.toLowerCase();
2217
+ if (statusLower === "requested") {
2218
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2219
+ }
2220
+ if (statusLower === "approved") {
2221
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2222
+ }
2223
+ if (statusLower === "rejected") {
2224
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
2225
+ }
2226
+ if (statusLower === "received") {
2227
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2228
+ }
2229
+ if (statusLower === "refunded") {
2230
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2231
+ }
2232
+ if (statusLower === "completed") {
2233
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2234
+ }
2235
+ if (statusLower === "cancelled") {
2236
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2237
+ }
2101
2238
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2102
2239
  };
2103
- const PaymentDetailPage = () => {
2104
- var _a;
2240
+ const ReturnDetailPage = () => {
2241
+ var _a, _b;
2105
2242
  const navigate = reactRouterDom.useNavigate();
2106
- const params = reactRouterDom.useParams();
2107
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2108
- const [detail, setDetail] = react.useState(null);
2109
- const [loading, setLoading] = react.useState(!!id);
2243
+ const { id } = reactRouterDom.useParams();
2244
+ const [returnOrder, setReturnOrder] = react.useState(null);
2245
+ const [isLoading, setIsLoading] = react.useState(true);
2246
+ const [isRejecting, setIsRejecting] = react.useState(false);
2110
2247
  const [error, setError] = react.useState(null);
2248
+ const [updateError, setUpdateError] = react.useState(null);
2249
+ const [updateSuccess, setUpdateSuccess] = react.useState(false);
2111
2250
  react.useEffect(() => {
2112
2251
  if (!id) {
2113
- setLoading(false);
2252
+ navigate("/returns");
2114
2253
  return;
2115
2254
  }
2116
- let cancelled = false;
2117
- setLoading(true);
2118
- setError(null);
2119
- fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
2120
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2121
- return res.json();
2122
- }).then((data) => {
2123
- if (!cancelled) setDetail(data);
2124
- }).catch((e) => {
2125
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2126
- }).finally(() => {
2127
- if (!cancelled) setLoading(false);
2128
- });
2129
- return () => {
2130
- cancelled = true;
2255
+ const loadReturn = async () => {
2256
+ try {
2257
+ setIsLoading(true);
2258
+ setError(null);
2259
+ const response = await fetch(`/admin/returns/${id}`, {
2260
+ credentials: "include"
2261
+ });
2262
+ if (!response.ok) {
2263
+ const message = await response.text();
2264
+ throw new Error(message || "Unable to load return order");
2265
+ }
2266
+ const payload = await response.json();
2267
+ setReturnOrder(payload.return);
2268
+ } catch (loadError) {
2269
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2270
+ setError(message);
2271
+ } finally {
2272
+ setIsLoading(false);
2273
+ }
2131
2274
  };
2132
- }, [id]);
2133
- const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
2134
- const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
2135
- const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
2136
- const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
2137
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
2138
- /* @__PURE__ */ jsxRuntime.jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2139
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
2140
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payment session" }),
2141
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
2142
- ] }) }),
2143
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2144
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2145
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
2146
- ] }) : loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
2147
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2148
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2149
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order ID" }),
2150
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: detail.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
2151
- ui.Button,
2152
- {
2153
- variant: "transparent",
2154
- size: "small",
2155
- onClick: () => navigate(`/orders/${detail.order_id}`),
2156
- children: detail.order_id
2157
- }
2158
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "—" }) })
2159
- ] }),
2160
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2161
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2162
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: displayAmount })
2163
- ] }),
2164
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2165
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2166
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.provider_id })
2167
- ] }),
2168
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2169
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2170
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2171
- ui.Badge,
2172
- {
2173
- size: "2xsmall",
2174
- className: `uppercase ${getStatusBadgeClass$2(displayStatus)}`,
2175
- children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
2176
- }
2177
- ) })
2178
- ] }),
2179
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2180
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Session status (DB)" }),
2181
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: sessionStatusRaw })
2182
- ] }),
2183
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2184
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment status (DB)" }),
2185
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: paymentStatusRaw })
2186
- ] }),
2187
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2188
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Finalized" }),
2189
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment_id != null ? "Yes" : "No" })
2190
- ] }),
2191
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2192
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
2193
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2194
- year: "numeric",
2195
- month: "short",
2196
- day: "numeric",
2197
- hour: "numeric",
2198
- minute: "2-digit",
2199
- hour12: true
2200
- }) })
2275
+ void loadReturn();
2276
+ }, [id, navigate]);
2277
+ const handleReject = async () => {
2278
+ if (!id) {
2279
+ return;
2280
+ }
2281
+ try {
2282
+ setIsRejecting(true);
2283
+ setUpdateError(null);
2284
+ setUpdateSuccess(false);
2285
+ const response = await fetch(`/admin/returns/${id}/reject`, {
2286
+ method: "POST",
2287
+ headers: {
2288
+ "Content-Type": "application/json"
2289
+ },
2290
+ credentials: "include",
2291
+ body: JSON.stringify({ reason: "Rejected by admin" })
2292
+ });
2293
+ if (!response.ok) {
2294
+ const message = await response.text();
2295
+ throw new Error(message || "Unable to reject return");
2296
+ }
2297
+ const payload = await response.json();
2298
+ setReturnOrder(payload.return);
2299
+ setUpdateSuccess(true);
2300
+ setTimeout(() => setUpdateSuccess(false), 3e3);
2301
+ const detailResponse = await fetch(`/admin/returns/${id}`, {
2302
+ credentials: "include"
2303
+ });
2304
+ if (detailResponse.ok) {
2305
+ const detailPayload = await detailResponse.json();
2306
+ setReturnOrder(detailPayload.return);
2307
+ }
2308
+ } catch (updateErr) {
2309
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2310
+ setUpdateError(message);
2311
+ } finally {
2312
+ setIsRejecting(false);
2313
+ }
2314
+ };
2315
+ if (isLoading) {
2316
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return order..." }) }) }) });
2317
+ }
2318
+ if (error || !returnOrder) {
2319
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2320
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
2321
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2322
+ ] }) }) });
2323
+ }
2324
+ const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2325
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
2326
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
2327
+ /* @__PURE__ */ jsxRuntime.jsxs(
2328
+ ui.Button,
2329
+ {
2330
+ variant: "transparent",
2331
+ size: "small",
2332
+ onClick: () => navigate("/returns"),
2333
+ className: "w-fit",
2334
+ children: [
2335
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
2336
+ "Back to list"
2337
+ ]
2338
+ }
2339
+ ),
2340
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2341
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2342
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Order Details" }),
2343
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2344
+ ] }),
2345
+ /* @__PURE__ */ jsxRuntime.jsx(
2346
+ ui.Badge,
2347
+ {
2348
+ size: "small",
2349
+ className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
2350
+ children: returnOrder.status.replace(/_/g, " ")
2351
+ }
2352
+ )
2353
+ ] })
2354
+ ] }),
2355
+ returnOrder.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
2356
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
2357
+ ui.Button,
2358
+ {
2359
+ variant: "danger",
2360
+ onClick: handleReject,
2361
+ disabled: isRejecting,
2362
+ isLoading: isRejecting,
2363
+ children: "Reject (Cancel) Return"
2364
+ }
2365
+ ) }),
2366
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
2367
+ ] }),
2368
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2369
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
2370
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2371
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2372
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2373
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2374
+ ] }),
2375
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
2376
+ ui.Button,
2377
+ {
2378
+ variant: "secondary",
2379
+ onClick: () => {
2380
+ window.open(
2381
+ `/app/orders/${returnOrder.order_id}`,
2382
+ "_blank"
2383
+ );
2384
+ },
2385
+ children: "View order"
2386
+ }
2387
+ ) })
2388
+ ] })
2389
+ ] }),
2390
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2391
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2392
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2393
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2394
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2395
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2396
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2397
+ ] }),
2398
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2399
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2400
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.status })
2401
+ ] }),
2402
+ returnOrder.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2403
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2404
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.reason })
2405
+ ] }),
2406
+ returnOrder.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2407
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2408
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.note })
2409
+ ] }),
2410
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2411
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2412
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2413
+ ] }),
2414
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2415
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2416
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2417
+ ] })
2201
2418
  ] })
2202
- ] }) }),
2203
- Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2204
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2205
- /* @__PURE__ */ jsxRuntime.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) })
2206
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
2207
- ] }) : null
2419
+ ] }),
2420
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2421
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Status History" }),
2422
+ statusHistory.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: statusHistory.map((entry, index) => /* @__PURE__ */ jsxRuntime.jsx(
2423
+ "div",
2424
+ {
2425
+ className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
2426
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2427
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsxRuntime.jsx(
2428
+ ui.Badge,
2429
+ {
2430
+ size: "2xsmall",
2431
+ className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
2432
+ children: entry.status.replace(/_/g, " ")
2433
+ }
2434
+ ) }),
2435
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
2436
+ new Date(entry.timestamp).toLocaleString(),
2437
+ entry.admin_id && ` by ${entry.admin_id}`,
2438
+ entry.reason && ` - ${entry.reason}`
2439
+ ] })
2440
+ ] })
2441
+ },
2442
+ index
2443
+ )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2444
+ ] })
2445
+ ] }),
2446
+ returnOrder.order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2447
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2448
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2449
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2450
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2451
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.id })
2452
+ ] }),
2453
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2454
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2455
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2456
+ ] }),
2457
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2458
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2459
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2460
+ ] }),
2461
+ returnOrder.order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2462
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2463
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
2464
+ returnOrder.order.currency_code || "$",
2465
+ (Number(returnOrder.order.total) / 100).toFixed(2)
2466
+ ] })
2467
+ ] })
2468
+ ] })
2469
+ ] }),
2470
+ returnOrder.return_items && returnOrder.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2471
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2472
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2473
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2474
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
2475
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2476
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2477
+ ] }) }),
2478
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2479
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2480
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2481
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2482
+ ] }, item.id || index)) })
2483
+ ] }) })
2484
+ ] }),
2485
+ updateError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-error bg-ui-bg-error-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", children: updateError }) }),
2486
+ updateSuccess && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2208
2487
  ] }) });
2209
2488
  };
2210
- const config$2 = adminSdk.defineRouteConfig({
2211
- label: "Payment details",
2212
- icon: icons.CreditCard
2489
+ const config$1 = adminSdk.defineRouteConfig({
2490
+ label: "Return Order Details",
2491
+ icon: icons.CheckCircle
2213
2492
  });
2214
- const getStatusBadgeClass$1 = (status) => {
2493
+ const getStatusBadgeClass = (status) => {
2215
2494
  const s2 = status.toLowerCase();
2216
2495
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2217
2496
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -2322,7 +2601,7 @@ const RefundDetailPage = () => {
2322
2601
  ui.Badge,
2323
2602
  {
2324
2603
  size: "2xsmall",
2325
- className: `uppercase ${getStatusBadgeClass$1(paymentStatus)}`,
2604
+ className: `uppercase ${getStatusBadgeClass(paymentStatus)}`,
2326
2605
  children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2327
2606
  }
2328
2607
  ) })
@@ -2399,333 +2678,54 @@ const RefundDetailPage = () => {
2399
2678
  ] }) : null
2400
2679
  ] }) });
2401
2680
  };
2402
- const config$1 = adminSdk.defineRouteConfig({
2681
+ const config = adminSdk.defineRouteConfig({
2403
2682
  label: "Refund details",
2404
2683
  icon: icons.Receipt
2405
2684
  });
2406
- const getStatusBadgeClass = (status) => {
2407
- const statusLower = status.toLowerCase();
2408
- if (statusLower === "requested") {
2409
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2410
- }
2411
- if (statusLower === "approved") {
2412
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2413
- }
2414
- if (statusLower === "rejected") {
2415
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
2416
- }
2417
- if (statusLower === "completed") {
2418
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
2419
- }
2420
- if (statusLower === "cancelled" || statusLower === "canceled") {
2421
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2422
- }
2423
- if (statusLower === "pending") {
2424
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2425
- }
2426
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2427
- };
2428
- const SwapDetailPage = () => {
2429
- var _a, _b, _c;
2430
- const navigate = reactRouterDom.useNavigate();
2431
- const { id } = reactRouterDom.useParams();
2432
- const [swap, setSwap] = react.useState(null);
2433
- const [order, setOrder] = react.useState(null);
2434
- const [isLoading, setIsLoading] = react.useState(true);
2435
- react.useState(false);
2436
- const [isCancelling, setIsCancelling] = react.useState(false);
2437
- const [error, setError] = react.useState(null);
2438
- const [updateError, setUpdateError] = react.useState(null);
2439
- const [updateSuccess, setUpdateSuccess] = react.useState(false);
2440
- react.useEffect(() => {
2441
- if (!id) {
2442
- navigate("/swaps");
2443
- return;
2444
- }
2445
- const loadSwap = async () => {
2446
- try {
2447
- setIsLoading(true);
2448
- setError(null);
2449
- const response = await fetch(`/admin/swaps/${id}`, {
2450
- credentials: "include"
2451
- });
2452
- if (!response.ok) {
2453
- const message = await response.text();
2454
- throw new Error(message || "Unable to load swap");
2455
- }
2456
- const payload = await response.json();
2457
- setSwap(payload.swap);
2458
- setOrder(payload.order || null);
2459
- } catch (loadError) {
2460
- const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
2461
- setError(message);
2462
- } finally {
2463
- setIsLoading(false);
2464
- }
2465
- };
2466
- void loadSwap();
2467
- }, [id, navigate]);
2468
- const handleCancelExchange = async () => {
2469
- if (!id) {
2470
- return;
2471
- }
2472
- try {
2473
- setIsCancelling(true);
2474
- setUpdateError(null);
2475
- setUpdateSuccess(false);
2476
- const response = await fetch(`/admin/swaps/${id}/cancel`, {
2477
- method: "POST",
2478
- headers: {
2479
- "Content-Type": "application/json"
2480
- },
2481
- credentials: "include"
2482
- });
2483
- if (!response.ok) {
2484
- const message = await response.text();
2485
- throw new Error(message || "Unable to cancel exchange");
2486
- }
2487
- const payload = await response.json();
2488
- setSwap(payload.swap);
2489
- setUpdateSuccess(true);
2490
- setTimeout(() => setUpdateSuccess(false), 3e3);
2491
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
2492
- credentials: "include"
2493
- });
2494
- if (detailResponse.ok) {
2495
- const detailPayload = await detailResponse.json();
2496
- setSwap(detailPayload.swap);
2497
- setOrder(detailPayload.order || null);
2498
- }
2499
- } catch (cancelErr) {
2500
- const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
2501
- setUpdateError(message);
2502
- } finally {
2503
- setIsCancelling(false);
2504
- }
2505
- };
2506
- const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
2507
- const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
2508
- ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
2509
- );
2510
- if (isLoading) {
2511
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swap..." }) }) }) });
2512
- }
2513
- if (error || !swap) {
2514
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2515
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
2516
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
2517
- ] }) }) });
2518
- }
2519
- const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
2520
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
2521
- /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
2522
- /* @__PURE__ */ jsxRuntime.jsxs(
2523
- ui.Button,
2524
- {
2525
- variant: "transparent",
2526
- size: "small",
2527
- onClick: () => navigate("/swaps"),
2528
- className: "w-fit",
2529
- children: [
2530
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
2531
- "Back to list"
2532
- ]
2533
- }
2534
- ),
2535
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2536
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2537
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchange Details" }),
2538
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
2539
- ] }),
2540
- /* @__PURE__ */ jsxRuntime.jsx(
2541
- ui.Badge,
2542
- {
2543
- size: "small",
2544
- className: `uppercase ${getStatusBadgeClass(swap.status)}`,
2545
- children: swap.status.replace(/_/g, " ")
2546
- }
2547
- )
2548
- ] })
2549
- ] }),
2550
- canCancelExchange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
2551
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
2552
- ui.Button,
2553
- {
2554
- variant: "danger",
2555
- onClick: handleCancelExchange,
2556
- disabled: isCancelling,
2557
- isLoading: isCancelling,
2558
- children: "Cancel Exchange"
2559
- }
2560
- ) }),
2561
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
2562
- ] }),
2563
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2564
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2565
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
2566
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2567
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2568
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2569
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
2570
- ] }),
2571
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2572
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2573
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
2574
- ] }),
2575
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2576
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
2577
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
2578
- ] }),
2579
- swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2580
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2581
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
2582
- ] }),
2583
- swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2584
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2585
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
2586
- ] }),
2587
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2588
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2589
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2590
- ] }),
2591
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2592
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2593
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2594
- ] }),
2595
- swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2596
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2597
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
2598
- ] })
2599
- ] })
2600
- ] }),
2601
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2602
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Status History" }),
2603
- statusHistory.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: statusHistory.map((entry, index) => /* @__PURE__ */ jsxRuntime.jsx(
2604
- "div",
2605
- {
2606
- className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
2607
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2608
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsxRuntime.jsx(
2609
- ui.Badge,
2610
- {
2611
- size: "2xsmall",
2612
- className: `uppercase ${getStatusBadgeClass(entry.status)}`,
2613
- children: entry.status.replace(/_/g, " ")
2614
- }
2615
- ) }),
2616
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
2617
- new Date(entry.timestamp).toLocaleString(),
2618
- entry.admin_id && ` by ${entry.admin_id}`,
2619
- entry.reason && ` - ${entry.reason}`
2620
- ] })
2621
- ] })
2622
- },
2623
- index
2624
- )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2625
- ] })
2626
- ] }),
2627
- order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2628
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2629
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2630
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2631
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2632
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
2633
- ] }),
2634
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2635
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2636
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
2637
- ] }),
2638
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2639
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2640
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2641
- ] }),
2642
- order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2643
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2644
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
2645
- order.currency_code || "$",
2646
- (Number(order.total) / 100).toFixed(2)
2647
- ] })
2648
- ] })
2649
- ] })
2650
- ] }),
2651
- swap.return_items && swap.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2652
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2653
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2654
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2655
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
2656
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2657
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2658
- ] }) }),
2659
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2660
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2661
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2662
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2663
- ] }, item.id || index)) })
2664
- ] }) })
2665
- ] }),
2666
- swap.new_items && swap.new_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2667
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2668
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2669
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2670
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2671
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2672
- ] }) }),
2673
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2674
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2675
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2676
- ] }, item.variant_id || index)) })
2677
- ] }) })
2678
- ] })
2679
- ] }) });
2680
- };
2681
- const config = adminSdk.defineRouteConfig({
2682
- label: "Swap Details",
2683
- icon: icons.ArrowPath
2684
- });
2685
- const i18nTranslations0 = {};
2686
- const widgetModule = { widgets: [
2687
- {
2688
- Component: OrderGiftItemsWidget,
2689
- zone: ["order.details.side.after"]
2690
- },
2691
- {
2692
- Component: OrderRefundContextWidget,
2693
- zone: ["order.details.after"]
2685
+ const i18nTranslations0 = {};
2686
+ const widgetModule = { widgets: [
2687
+ {
2688
+ Component: OrderGiftItemsWidget,
2689
+ zone: ["order.details.side.after"]
2690
+ },
2691
+ {
2692
+ Component: OrderRefundContextWidget,
2693
+ zone: ["order.details.after"]
2694
2694
  }
2695
2695
  ] };
2696
2696
  const routeModule = {
2697
2697
  routes: [
2698
- {
2699
- Component: ReturnsPage,
2700
- path: "/returns"
2701
- },
2702
2698
  {
2703
2699
  Component: PaymentsPage,
2704
2700
  path: "/payments"
2705
2701
  },
2706
- {
2707
- Component: RefundsPage,
2708
- path: "/refunds"
2709
- },
2710
2702
  {
2711
2703
  Component: SwapsPage,
2712
2704
  path: "/swaps"
2713
2705
  },
2714
2706
  {
2715
- Component: ReturnDetailPage,
2716
- path: "/returns/:id"
2707
+ Component: RefundsPage,
2708
+ path: "/refunds"
2717
2709
  },
2718
2710
  {
2719
- Component: PaymentDetailPage,
2720
- path: "/payments/:id"
2711
+ Component: ReturnsPage,
2712
+ path: "/returns"
2721
2713
  },
2722
2714
  {
2723
- Component: RefundDetailPage,
2724
- path: "/refunds/:id"
2715
+ Component: PaymentDetailPage,
2716
+ path: "/payments/:id"
2725
2717
  },
2726
2718
  {
2727
2719
  Component: SwapDetailPage,
2728
2720
  path: "/swaps/:id"
2721
+ },
2722
+ {
2723
+ Component: ReturnDetailPage,
2724
+ path: "/returns/:id"
2725
+ },
2726
+ {
2727
+ Component: RefundDetailPage,
2728
+ path: "/refunds/:id"
2729
2729
  }
2730
2730
  ]
2731
2731
  };
@@ -2734,7 +2734,7 @@ const menuItemModule = {
2734
2734
  {
2735
2735
  label: config$4.label,
2736
2736
  icon: config$4.icon,
2737
- path: "/swaps",
2737
+ path: "/returns",
2738
2738
  nested: void 0
2739
2739
  },
2740
2740
  {
@@ -2746,37 +2746,37 @@ const menuItemModule = {
2746
2746
  {
2747
2747
  label: config$7.label,
2748
2748
  icon: config$7.icon,
2749
- path: "/returns",
2749
+ path: "/payments",
2750
2750
  nested: void 0
2751
2751
  },
2752
2752
  {
2753
2753
  label: config$6.label,
2754
2754
  icon: config$6.icon,
2755
- path: "/payments",
2755
+ path: "/swaps",
2756
2756
  nested: void 0
2757
2757
  },
2758
2758
  {
2759
- label: config.label,
2760
- icon: config.icon,
2761
- path: "/swaps/:id",
2759
+ label: config$1.label,
2760
+ icon: config$1.icon,
2761
+ path: "/returns/:id",
2762
2762
  nested: void 0
2763
2763
  },
2764
2764
  {
2765
- label: config$1.label,
2766
- icon: config$1.icon,
2765
+ label: config.label,
2766
+ icon: config.icon,
2767
2767
  path: "/refunds/:id",
2768
2768
  nested: void 0
2769
2769
  },
2770
2770
  {
2771
2771
  label: config$3.label,
2772
2772
  icon: config$3.icon,
2773
- path: "/returns/:id",
2773
+ path: "/payments/:id",
2774
2774
  nested: void 0
2775
2775
  },
2776
2776
  {
2777
2777
  label: config$2.label,
2778
2778
  icon: config$2.icon,
2779
- path: "/payments/:id",
2779
+ path: "/swaps/:id",
2780
2780
  nested: void 0
2781
2781
  }
2782
2782
  ]