order-management 0.0.25 → 0.0.26

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.
@@ -775,10 +775,6 @@ const SwapDetailPage = () => {
775
775
  const [error, setError] = react.useState(null);
776
776
  const [updateError, setUpdateError] = react.useState(null);
777
777
  const [updateSuccess, setUpdateSuccess] = react.useState(false);
778
- const [showShippingModal, setShowShippingModal] = react.useState(false);
779
- const [shippingOptions, setShippingOptions] = react.useState([]);
780
- const [selectedShippingOptionId, setSelectedShippingOptionId] = react.useState("");
781
- const [isLoadingShippingOptions, setIsLoadingShippingOptions] = react.useState(false);
782
778
  const availableStatuses = ["requested", "approved", "rejected"];
783
779
  react.useEffect(() => {
784
780
  if (!id) {
@@ -853,67 +849,32 @@ const SwapDetailPage = () => {
853
849
  if (!id) {
854
850
  return;
855
851
  }
856
- setShowShippingModal(true);
857
- setSelectedShippingOptionId("");
858
- setUpdateError(null);
859
- try {
860
- setIsLoadingShippingOptions(true);
861
- const response = await fetch(`/admin/swaps/${id}/shipping-options`, {
862
- credentials: "include"
863
- });
864
- if (!response.ok) {
865
- const message = await response.text();
866
- throw new Error(message || "Unable to fetch shipping options");
867
- }
868
- const payload = await response.json();
869
- setShippingOptions(payload.shipping_options || []);
870
- } catch (fetchError) {
871
- const message = fetchError instanceof Error ? fetchError.message : "Unable to fetch shipping options";
872
- setUpdateError(message);
873
- setShowShippingModal(false);
874
- } finally {
875
- setIsLoadingShippingOptions(false);
876
- }
877
- };
878
- const handleApproveConfirm = async () => {
879
- if (!id || !selectedShippingOptionId) {
880
- setUpdateError("Please select a shipping option");
852
+ if (!swap || !swap.order_id) {
853
+ setUpdateError("Swap must have an order_id to create exchange");
881
854
  return;
882
855
  }
883
856
  try {
884
857
  setIsApproving(true);
885
858
  setUpdateError(null);
886
859
  setUpdateSuccess(false);
887
- const response = await fetch(`/admin/swaps/${id}/approve`, {
860
+ const response = await fetch(`/admin/swaps/${id}/prepare-exchange`, {
888
861
  method: "POST",
889
862
  headers: {
890
863
  "Content-Type": "application/json"
891
864
  },
892
- credentials: "include",
893
- body: JSON.stringify({
894
- shipping_option_id: selectedShippingOptionId
895
- })
865
+ credentials: "include"
896
866
  });
897
867
  if (!response.ok) {
898
- const errorData = await response.json().catch(() => ({ message: "Unable to approve swap" }));
899
- throw new Error(errorData.message || errorData.error || "Unable to approve swap");
868
+ const errorData = await response.json().catch(() => ({ message: "Unable to prepare swap for exchange creation" }));
869
+ throw new Error(errorData.message || errorData.error || "Unable to prepare swap for exchange creation");
900
870
  }
901
871
  const payload = await response.json();
902
872
  setSwap(payload.swap);
903
873
  setUpdateSuccess(true);
904
- setShowShippingModal(false);
905
- setSelectedShippingOptionId("");
906
- setTimeout(() => setUpdateSuccess(false), 5e3);
907
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
908
- credentials: "include"
909
- });
910
- if (detailResponse.ok) {
911
- const detailPayload = await detailResponse.json();
912
- setSwap(detailPayload.swap);
913
- setOrder(detailPayload.order || null);
914
- }
874
+ setTimeout(() => setUpdateSuccess(false), 3e3);
875
+ window.location.href = `/app/orders/${swap.order_id}`;
915
876
  } catch (updateErr) {
916
- const message = updateErr instanceof Error ? updateErr.message : "Unable to approve swap";
877
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to prepare swap for exchange creation";
917
878
  setUpdateError(message);
918
879
  } finally {
919
880
  setIsApproving(false);
@@ -968,276 +929,226 @@ const SwapDetailPage = () => {
968
929
  ] }) }) });
969
930
  }
970
931
  const statusHistory = ((_a = swap.metadata) == null ? void 0 : _a.status_history) || [];
971
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full p-6", children: [
972
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
973
- /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
974
- /* @__PURE__ */ jsxRuntime.jsxs(
975
- ui.Button,
932
+ 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: [
933
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
934
+ /* @__PURE__ */ jsxRuntime.jsxs(
935
+ ui.Button,
936
+ {
937
+ variant: "transparent",
938
+ size: "small",
939
+ onClick: () => navigate("/swaps"),
940
+ className: "w-fit",
941
+ children: [
942
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
943
+ "Back to list"
944
+ ]
945
+ }
946
+ ),
947
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
948
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
949
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Swap Details" }),
950
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
951
+ ] }),
952
+ /* @__PURE__ */ jsxRuntime.jsx(
953
+ ui.Badge,
976
954
  {
977
- variant: "transparent",
978
955
  size: "small",
979
- onClick: () => navigate("/swaps"),
980
- className: "w-fit",
981
- children: [
982
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
983
- "Back to list"
984
- ]
956
+ className: `uppercase ${getStatusBadgeClass(swap.status)}`,
957
+ children: swap.status.replace(/_/g, " ")
985
958
  }
986
- ),
987
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
988
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
989
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Swap Details" }),
990
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
991
- ] }),
992
- /* @__PURE__ */ jsxRuntime.jsx(
993
- ui.Badge,
959
+ )
960
+ ] })
961
+ ] }),
962
+ swap.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
963
+ /* @__PURE__ */ jsxRuntime.jsx(
964
+ ui.Button,
965
+ {
966
+ variant: "primary",
967
+ onClick: handleApproveClick,
968
+ disabled: isApproving || isRejecting,
969
+ isLoading: isApproving,
970
+ children: "Approve Swap"
971
+ }
972
+ ),
973
+ /* @__PURE__ */ jsxRuntime.jsx(
974
+ ui.Button,
975
+ {
976
+ variant: "secondary",
977
+ onClick: handleReject,
978
+ disabled: isApproving || isRejecting,
979
+ isLoading: isRejecting,
980
+ children: "Reject Swap"
981
+ }
982
+ )
983
+ ] }),
984
+ swap.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
985
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Update Status" }),
986
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-end", children: [
987
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1", children: [
988
+ /* @__PURE__ */ jsxRuntime.jsx("label", { className: "mb-2 block text-sm font-medium text-ui-fg-base", children: "New Status" }),
989
+ /* @__PURE__ */ jsxRuntime.jsxs(
990
+ "select",
994
991
  {
995
- size: "small",
996
- className: `uppercase ${getStatusBadgeClass(swap.status)}`,
997
- children: swap.status.replace(/_/g, " ")
992
+ value: selectedStatus,
993
+ onChange: (event) => setSelectedStatus(event.target.value),
994
+ className: "h-9 w-full 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",
995
+ children: [
996
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: "Select new status" }),
997
+ availableStatuses.filter((status) => status !== swap.status).map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
998
+ ]
998
999
  }
999
1000
  )
1000
- ] })
1001
- ] }),
1002
- swap.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
1001
+ ] }),
1003
1002
  /* @__PURE__ */ jsxRuntime.jsx(
1004
1003
  ui.Button,
1005
1004
  {
1006
1005
  variant: "primary",
1007
- onClick: handleApproveClick,
1008
- disabled: isApproving || isRejecting,
1009
- isLoading: isApproving,
1010
- children: "Approve Swap"
1006
+ onClick: handleStatusUpdate,
1007
+ disabled: !selectedStatus || isUpdating,
1008
+ isLoading: isUpdating,
1009
+ children: "Update Status"
1011
1010
  }
1012
- ),
1013
- /* @__PURE__ */ jsxRuntime.jsx(
1011
+ )
1012
+ ] }),
1013
+ updateError && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-error", children: updateError }),
1014
+ updateSuccess && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-success", children: "Status updated successfully" })
1015
+ ] }),
1016
+ swap.status === "approved" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1017
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
1018
+ swap.exchange_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1019
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1020
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
1021
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
1022
+ ] }),
1023
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
1014
1024
  ui.Button,
1015
1025
  {
1016
1026
  variant: "secondary",
1017
- onClick: handleReject,
1018
- disabled: isApproving || isRejecting,
1019
- isLoading: isRejecting,
1020
- children: "Reject Swap"
1027
+ onClick: () => {
1028
+ window.open(`/app/orders/${swap.order_id}/exchanges/${swap.exchange_id}`, "_blank");
1029
+ },
1030
+ children: "View Exchange"
1021
1031
  }
1022
- )
1023
- ] }),
1024
- swap.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1025
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Update Status" }),
1026
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-end", children: [
1027
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1", children: [
1028
- /* @__PURE__ */ jsxRuntime.jsx("label", { className: "mb-2 block text-sm font-medium text-ui-fg-base", children: "New Status" }),
1029
- /* @__PURE__ */ jsxRuntime.jsxs(
1030
- "select",
1031
- {
1032
- value: selectedStatus,
1033
- onChange: (event) => setSelectedStatus(event.target.value),
1034
- className: "h-9 w-full 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",
1035
- children: [
1036
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: "Select new status" }),
1037
- availableStatuses.filter((status) => status !== swap.status).map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1038
- ]
1039
- }
1040
- )
1032
+ ) })
1033
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange is being created. Please refresh the page to see the exchange details." }) })
1034
+ ] }),
1035
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
1036
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1037
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Swap Information" }),
1038
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1039
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1040
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Swap ID" }),
1041
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
1041
1042
  ] }),
1042
- /* @__PURE__ */ jsxRuntime.jsx(
1043
- ui.Button,
1044
- {
1045
- variant: "primary",
1046
- onClick: handleStatusUpdate,
1047
- disabled: !selectedStatus || isUpdating,
1048
- isLoading: isUpdating,
1049
- children: "Update Status"
1050
- }
1051
- )
1052
- ] }),
1053
- updateError && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-error", children: updateError }),
1054
- updateSuccess && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-success", children: "Status updated successfully" })
1055
- ] }),
1056
- swap.status === "approved" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1057
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
1058
- swap.exchange_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1059
1043
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1060
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
1061
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
1044
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
1045
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
1062
1046
  ] }),
1063
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
1064
- ui.Button,
1065
- {
1066
- variant: "secondary",
1067
- onClick: () => {
1068
- window.open(`/app/orders/${swap.order_id}/exchanges/${swap.exchange_id}`, "_blank");
1069
- },
1070
- children: "View Exchange"
1071
- }
1072
- ) })
1073
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange is being created. Please refresh the page to see the exchange details." }) })
1074
- ] }),
1075
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
1076
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1077
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Swap Information" }),
1078
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1079
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1080
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Swap ID" }),
1081
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
1082
- ] }),
1083
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1084
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
1085
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
1086
- ] }),
1087
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1088
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
1089
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
1090
- ] }),
1091
- swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1092
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
1093
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
1094
- ] }),
1095
- swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1096
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
1097
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
1098
- ] }),
1099
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1100
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
1101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
1102
- ] }),
1103
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1104
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
1105
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
1106
- ] }),
1107
- swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1108
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
1109
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
1110
- ] })
1111
- ] })
1112
- ] }),
1113
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1114
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Status History" }),
1115
- statusHistory.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: statusHistory.map((entry, index) => /* @__PURE__ */ jsxRuntime.jsx(
1116
- "div",
1117
- {
1118
- className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
1119
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1120
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsxRuntime.jsx(
1121
- ui.Badge,
1122
- {
1123
- size: "2xsmall",
1124
- className: `uppercase ${getStatusBadgeClass(entry.status)}`,
1125
- children: entry.status.replace(/_/g, " ")
1126
- }
1127
- ) }),
1128
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
1129
- new Date(entry.timestamp).toLocaleString(),
1130
- entry.admin_id && ` by ${entry.admin_id}`,
1131
- entry.reason && ` - ${entry.reason}`
1132
- ] })
1133
- ] })
1134
- },
1135
- index
1136
- )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
1137
- ] })
1138
- ] }),
1139
- order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1140
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
1141
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1142
1047
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1143
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
1144
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
1048
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
1049
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
1050
+ ] }),
1051
+ swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1052
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
1053
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
1054
+ ] }),
1055
+ swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1056
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
1057
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
1145
1058
  ] }),
1146
1059
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1147
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
1148
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
1060
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
1061
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
1149
1062
  ] }),
1150
1063
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1151
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
1152
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = order.customer) == null ? void 0 : _b.email) || order.email || "—" })
1064
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
1065
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
1153
1066
  ] }),
1154
- order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1155
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
1156
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
1157
- order.currency_code || "$",
1158
- (Number(order.total) / 100).toFixed(2)
1159
- ] })
1067
+ swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1068
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
1069
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
1160
1070
  ] })
1161
1071
  ] })
1162
1072
  ] }),
1163
- 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: [
1164
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
1165
- /* @__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: [
1166
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1167
- /* @__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" }),
1168
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
1169
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
1170
- ] }) }),
1171
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1172
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
1173
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
1174
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
1175
- ] }, item.id || index)) })
1176
- ] }) })
1177
- ] }),
1178
- 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: [
1179
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
1180
- /* @__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: [
1181
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1182
- /* @__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" }),
1183
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
1184
- ] }) }),
1185
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1186
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
1187
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
1188
- ] }, item.variant_id || index)) })
1189
- ] }) })
1073
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1074
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Status History" }),
1075
+ statusHistory.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: statusHistory.map((entry, index) => /* @__PURE__ */ jsxRuntime.jsx(
1076
+ "div",
1077
+ {
1078
+ className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
1079
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1080
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsxRuntime.jsx(
1081
+ ui.Badge,
1082
+ {
1083
+ size: "2xsmall",
1084
+ className: `uppercase ${getStatusBadgeClass(entry.status)}`,
1085
+ children: entry.status.replace(/_/g, " ")
1086
+ }
1087
+ ) }),
1088
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
1089
+ new Date(entry.timestamp).toLocaleString(),
1090
+ entry.admin_id && ` by ${entry.admin_id}`,
1091
+ entry.reason && ` - ${entry.reason}`
1092
+ ] })
1093
+ ] })
1094
+ },
1095
+ index
1096
+ )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
1190
1097
  ] })
1191
1098
  ] }),
1192
- showShippingModal && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative w-full max-w-md rounded-lg border border-ui-border-base bg-ui-bg-base p-6 shadow-lg", children: [
1193
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
1194
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg", children: "Select Shipping Option" }),
1195
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Please select a shipping option for the exchange. This is required to create the exchange." })
1196
- ] }),
1197
- isLoadingShippingOptions ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-8 text-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading shipping options..." }) }) : shippingOptions.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-8 text-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", children: "No shipping options available for this order's region." }) }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-6", children: [
1198
- /* @__PURE__ */ jsxRuntime.jsx("label", { className: "mb-2 block text-sm font-medium text-ui-fg-base", children: "Shipping Option" }),
1199
- /* @__PURE__ */ jsxRuntime.jsxs(
1200
- ui.Select,
1201
- {
1202
- value: selectedShippingOptionId,
1203
- onValueChange: setSelectedShippingOptionId,
1204
- children: [
1205
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Select a shipping option" }) }),
1206
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: shippingOptions.map((option) => /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: option.id, children: option.name }, option.id)) })
1207
- ]
1208
- }
1209
- )
1210
- ] }),
1211
- updateError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-error", children: updateError }) }),
1212
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
1213
- /* @__PURE__ */ jsxRuntime.jsx(
1214
- ui.Button,
1215
- {
1216
- variant: "secondary",
1217
- onClick: () => {
1218
- setShowShippingModal(false);
1219
- setSelectedShippingOptionId("");
1220
- setUpdateError(null);
1221
- },
1222
- disabled: isApproving,
1223
- className: "flex-1",
1224
- children: "Cancel"
1225
- }
1226
- ),
1227
- /* @__PURE__ */ jsxRuntime.jsx(
1228
- ui.Button,
1229
- {
1230
- variant: "primary",
1231
- onClick: handleApproveConfirm,
1232
- disabled: !selectedShippingOptionId || isApproving || isLoadingShippingOptions,
1233
- isLoading: isApproving,
1234
- className: "flex-1",
1235
- children: "Confirm & Approve"
1236
- }
1237
- )
1099
+ order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
1101
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1102
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1103
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
1104
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
1105
+ ] }),
1106
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1107
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
1108
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
1109
+ ] }),
1110
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1111
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
1112
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = order.customer) == null ? void 0 : _b.email) || order.email || "—" })
1113
+ ] }),
1114
+ order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1115
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
1116
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
1117
+ order.currency_code || "$",
1118
+ (Number(order.total) / 100).toFixed(2)
1119
+ ] })
1120
+ ] })
1238
1121
  ] })
1239
- ] }) })
1240
- ] });
1122
+ ] }),
1123
+ 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: [
1124
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
1125
+ /* @__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: [
1126
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1127
+ /* @__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" }),
1128
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
1129
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
1130
+ ] }) }),
1131
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1132
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
1133
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
1134
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
1135
+ ] }, item.id || index)) })
1136
+ ] }) })
1137
+ ] }),
1138
+ 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: [
1139
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
1140
+ /* @__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: [
1141
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1142
+ /* @__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" }),
1143
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
1144
+ ] }) }),
1145
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1146
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
1147
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
1148
+ ] }, item.variant_id || index)) })
1149
+ ] }) })
1150
+ ] })
1151
+ ] }) });
1241
1152
  };
1242
1153
  const config = adminSdk.defineRouteConfig({
1243
1154
  label: "Swap Details",