@medusajs/draft-order 2.10.2-snapshot-20250829152522 → 2.10.2-snapshot-20250901132949

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.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9812,777 +9812,596 @@ const EmailForm = ({ order }) => {
9812
9812
  const schema$4 = objectType({
9813
9813
  email: stringType().email()
9814
9814
  });
9815
- const InlineTip = forwardRef(
9816
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9817
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9815
+ const CustomItems = () => {
9816
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9817
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9818
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9819
+ ] });
9820
+ };
9821
+ const CustomItemsForm = () => {
9822
+ const form = useForm({
9823
+ resolver: zodResolver(schema$3)
9824
+ });
9825
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9826
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9827
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9828
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9829
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9830
+ ] }) })
9831
+ ] }) });
9832
+ };
9833
+ const schema$3 = objectType({
9834
+ email: stringType().email()
9835
+ });
9836
+ const NumberInput = forwardRef(
9837
+ ({
9838
+ value,
9839
+ onChange,
9840
+ size = "base",
9841
+ min = 0,
9842
+ max = 100,
9843
+ step = 1,
9844
+ className,
9845
+ disabled,
9846
+ ...props
9847
+ }, ref) => {
9848
+ const handleChange = (event) => {
9849
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9850
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9851
+ onChange(newValue);
9852
+ }
9853
+ };
9854
+ const handleIncrement = () => {
9855
+ const newValue = value + step;
9856
+ if (max === void 0 || newValue <= max) {
9857
+ onChange(newValue);
9858
+ }
9859
+ };
9860
+ const handleDecrement = () => {
9861
+ const newValue = value - step;
9862
+ if (min === void 0 || newValue >= min) {
9863
+ onChange(newValue);
9864
+ }
9865
+ };
9818
9866
  return /* @__PURE__ */ jsxs(
9819
9867
  "div",
9820
9868
  {
9821
- ref,
9822
9869
  className: clx(
9823
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9870
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9871
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9872
+ {
9873
+ "h-7": size === "small",
9874
+ "h-8": size === "base"
9875
+ },
9824
9876
  className
9825
9877
  ),
9826
- ...props,
9827
9878
  children: [
9828
9879
  /* @__PURE__ */ jsx(
9829
- "div",
9880
+ "input",
9830
9881
  {
9831
- role: "presentation",
9832
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9833
- "bg-ui-tag-orange-icon": variant === "warning"
9834
- })
9882
+ ref,
9883
+ type: "number",
9884
+ value,
9885
+ onChange: handleChange,
9886
+ min,
9887
+ max,
9888
+ step,
9889
+ className: clx(
9890
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9891
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9892
+ "placeholder:text-ui-fg-muted"
9893
+ ),
9894
+ ...props
9835
9895
  }
9836
9896
  ),
9837
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9838
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9839
- labelValue,
9840
- ":"
9841
- ] }),
9842
- " ",
9843
- children
9844
- ] })
9897
+ /* @__PURE__ */ jsxs(
9898
+ "button",
9899
+ {
9900
+ className: clx(
9901
+ "flex items-center justify-center outline-none transition-fg",
9902
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9903
+ "focus:bg-ui-bg-field-component-hover",
9904
+ "hover:bg-ui-bg-field-component-hover",
9905
+ {
9906
+ "size-7": size === "small",
9907
+ "size-8": size === "base"
9908
+ }
9909
+ ),
9910
+ type: "button",
9911
+ onClick: handleDecrement,
9912
+ disabled: min !== void 0 && value <= min || disabled,
9913
+ children: [
9914
+ /* @__PURE__ */ jsx(Minus, {}),
9915
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9916
+ ]
9917
+ }
9918
+ ),
9919
+ /* @__PURE__ */ jsxs(
9920
+ "button",
9921
+ {
9922
+ className: clx(
9923
+ "flex items-center justify-center outline-none transition-fg",
9924
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9925
+ "focus:bg-ui-bg-field-hover",
9926
+ "hover:bg-ui-bg-field-hover",
9927
+ {
9928
+ "size-7": size === "small",
9929
+ "size-8": size === "base"
9930
+ }
9931
+ ),
9932
+ type: "button",
9933
+ onClick: handleIncrement,
9934
+ disabled: max !== void 0 && value >= max || disabled,
9935
+ children: [
9936
+ /* @__PURE__ */ jsx(Plus, {}),
9937
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9938
+ ]
9939
+ }
9940
+ )
9845
9941
  ]
9846
9942
  }
9847
9943
  );
9848
9944
  }
9849
9945
  );
9850
- InlineTip.displayName = "InlineTip";
9851
- const MetadataFieldSchema = objectType({
9852
- key: stringType(),
9853
- disabled: booleanType().optional(),
9854
- value: anyType()
9855
- });
9856
- const MetadataSchema = objectType({
9857
- metadata: arrayType(MetadataFieldSchema)
9858
- });
9859
- const Metadata = () => {
9946
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9947
+ const productVariantsQueryKeys = {
9948
+ list: (query2) => [
9949
+ PRODUCT_VARIANTS_QUERY_KEY,
9950
+ query2 ? query2 : void 0
9951
+ ]
9952
+ };
9953
+ const useProductVariants = (query2, options) => {
9954
+ const { data, ...rest } = useQuery({
9955
+ queryKey: productVariantsQueryKeys.list(query2),
9956
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9957
+ ...options
9958
+ });
9959
+ return { ...data, ...rest };
9960
+ };
9961
+ const useCancelOrderEdit = ({ preview }) => {
9962
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9963
+ const onCancel = useCallback(async () => {
9964
+ if (!preview) {
9965
+ return true;
9966
+ }
9967
+ let res = false;
9968
+ await cancelOrderEdit(void 0, {
9969
+ onError: (e) => {
9970
+ toast.error(e.message);
9971
+ },
9972
+ onSuccess: () => {
9973
+ res = true;
9974
+ }
9975
+ });
9976
+ return res;
9977
+ }, [preview, cancelOrderEdit]);
9978
+ return { onCancel };
9979
+ };
9980
+ let IS_REQUEST_RUNNING = false;
9981
+ const useInitiateOrderEdit = ({
9982
+ preview
9983
+ }) => {
9984
+ const navigate = useNavigate();
9985
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9986
+ useEffect(() => {
9987
+ async function run() {
9988
+ if (IS_REQUEST_RUNNING || !preview) {
9989
+ return;
9990
+ }
9991
+ if (preview.order_change) {
9992
+ return;
9993
+ }
9994
+ IS_REQUEST_RUNNING = true;
9995
+ await mutateAsync(void 0, {
9996
+ onError: (e) => {
9997
+ toast.error(e.message);
9998
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
9999
+ return;
10000
+ }
10001
+ });
10002
+ IS_REQUEST_RUNNING = false;
10003
+ }
10004
+ run();
10005
+ }, [preview, navigate, mutateAsync]);
10006
+ };
10007
+ function convertNumber(value) {
10008
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10009
+ }
10010
+ const STACKED_MODAL_ID = "items_stacked_modal";
10011
+ const Items = () => {
9860
10012
  const { id } = useParams();
9861
- const { order, isPending, isError, error } = useOrder(id, {
9862
- fields: "metadata"
10013
+ const {
10014
+ order: preview,
10015
+ isPending: isPreviewPending,
10016
+ isError: isPreviewError,
10017
+ error: previewError
10018
+ } = useOrderPreview(id, void 0, {
10019
+ placeholderData: keepPreviousData
9863
10020
  });
10021
+ useInitiateOrderEdit({ preview });
10022
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10023
+ id,
10024
+ {
10025
+ fields: "currency_code"
10026
+ },
10027
+ {
10028
+ enabled: !!id
10029
+ }
10030
+ );
10031
+ const { onCancel } = useCancelOrderEdit({ preview });
9864
10032
  if (isError) {
9865
10033
  throw error;
9866
10034
  }
9867
- const isReady = !isPending && !!order;
9868
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9869
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9870
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9871
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9872
- ] }),
9873
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9874
- ] });
10035
+ if (isPreviewError) {
10036
+ throw previewError;
10037
+ }
10038
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10039
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10040
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10041
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10042
+ ] }) });
9875
10043
  };
9876
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9877
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9878
- const MetadataForm = ({ orderId, metadata }) => {
10044
+ const ItemsForm = ({ preview, currencyCode }) => {
10045
+ var _a;
10046
+ const [isSubmitting, setIsSubmitting] = useState(false);
10047
+ const [modalContent, setModalContent] = useState(
10048
+ null
10049
+ );
9879
10050
  const { handleSuccess } = useRouteModal();
9880
- const hasUneditableRows = getHasUneditableRows(metadata);
9881
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10051
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10052
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10053
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10054
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10055
+ const matches = useMemo(() => {
10056
+ return matchSorter(preview.items, query2, {
10057
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10058
+ });
10059
+ }, [preview.items, query2]);
10060
+ const onSubmit = async () => {
10061
+ setIsSubmitting(true);
10062
+ let requestSucceeded = false;
10063
+ await requestOrderEdit(void 0, {
10064
+ onError: (e) => {
10065
+ toast.error(`Failed to request order edit: ${e.message}`);
10066
+ },
10067
+ onSuccess: () => {
10068
+ requestSucceeded = true;
10069
+ }
10070
+ });
10071
+ if (!requestSucceeded) {
10072
+ setIsSubmitting(false);
10073
+ return;
10074
+ }
10075
+ await confirmOrderEdit(void 0, {
10076
+ onError: (e) => {
10077
+ toast.error(`Failed to confirm order edit: ${e.message}`);
10078
+ },
10079
+ onSuccess: () => {
10080
+ handleSuccess();
10081
+ },
10082
+ onSettled: () => {
10083
+ setIsSubmitting(false);
10084
+ }
10085
+ });
10086
+ };
10087
+ const onKeyDown = useCallback(
10088
+ (e) => {
10089
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10090
+ if (modalContent || isSubmitting) {
10091
+ return;
10092
+ }
10093
+ onSubmit();
10094
+ }
10095
+ },
10096
+ [modalContent, isSubmitting, onSubmit]
10097
+ );
10098
+ useEffect(() => {
10099
+ document.addEventListener("keydown", onKeyDown);
10100
+ return () => {
10101
+ document.removeEventListener("keydown", onKeyDown);
10102
+ };
10103
+ }, [onKeyDown]);
10104
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10105
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10106
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10107
+ StackedFocusModal,
10108
+ {
10109
+ id: STACKED_MODAL_ID,
10110
+ onOpenChangeCallback: (open) => {
10111
+ if (!open) {
10112
+ setModalContent(null);
10113
+ }
10114
+ },
10115
+ children: [
10116
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10117
+ /* @__PURE__ */ jsxs("div", { children: [
10118
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10119
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
10120
+ ] }),
10121
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10122
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10123
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10124
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10125
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10126
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10127
+ ] }),
10128
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10129
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10130
+ Input,
10131
+ {
10132
+ type: "search",
10133
+ placeholder: "Search items",
10134
+ value: searchValue,
10135
+ onChange: (e) => onSearchValueChange(e.target.value)
10136
+ }
10137
+ ) }),
10138
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10139
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10140
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10141
+ /* @__PURE__ */ jsx(
10142
+ StackedModalTrigger$1,
10143
+ {
10144
+ type: "add-items",
10145
+ setModalContent
10146
+ }
10147
+ ),
10148
+ /* @__PURE__ */ jsx(
10149
+ StackedModalTrigger$1,
10150
+ {
10151
+ type: "add-custom-item",
10152
+ setModalContent
10153
+ }
10154
+ )
10155
+ ] })
10156
+ ] })
10157
+ ] })
10158
+ ] }),
10159
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10160
+ /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
10161
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10162
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10163
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10164
+ /* @__PURE__ */ jsx("div", {})
10165
+ ] }) }),
10166
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10167
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10168
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10169
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10170
+ Item,
10171
+ {
10172
+ item,
10173
+ preview,
10174
+ currencyCode
10175
+ },
10176
+ item.id
10177
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10178
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10179
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10180
+ 'No items found for "',
10181
+ query2,
10182
+ '".'
10183
+ ] })
10184
+ ] }) })
10185
+ ] })
10186
+ ] }),
10187
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10188
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10189
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10190
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10191
+ Text,
10192
+ {
10193
+ size: "small",
10194
+ leading: "compact",
10195
+ className: "text-ui-fg-subtle",
10196
+ children: [
10197
+ itemCount,
10198
+ " ",
10199
+ itemCount === 1 ? "item" : "items"
10200
+ ]
10201
+ }
10202
+ ) }),
10203
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10204
+ ] })
10205
+ ] }) }),
10206
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10207
+ CustomItemForm,
10208
+ {
10209
+ orderId: preview.id,
10210
+ currencyCode
10211
+ }
10212
+ ) : null)
10213
+ ]
10214
+ }
10215
+ ) }),
10216
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10217
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10218
+ /* @__PURE__ */ jsx(
10219
+ Button,
10220
+ {
10221
+ size: "small",
10222
+ type: "button",
10223
+ onClick: onSubmit,
10224
+ isLoading: isSubmitting,
10225
+ children: "Save"
10226
+ }
10227
+ )
10228
+ ] }) })
10229
+ ] });
10230
+ };
10231
+ const Item = ({ item, preview, currencyCode }) => {
10232
+ if (item.variant_id) {
10233
+ return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10234
+ }
10235
+ return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10236
+ };
10237
+ const VariantItem = ({ item, preview, currencyCode }) => {
10238
+ const [editing, setEditing] = useState(false);
9882
10239
  const form = useForm({
9883
10240
  defaultValues: {
9884
- metadata: getDefaultValues(metadata)
10241
+ quantity: item.quantity,
10242
+ unit_price: item.unit_price
9885
10243
  },
9886
- resolver: zodResolver(MetadataSchema)
10244
+ resolver: zodResolver(variantItemSchema)
9887
10245
  });
9888
- const handleSubmit = form.handleSubmit(async (data) => {
9889
- const parsedData = parseValues(data);
9890
- await mutateAsync(
10246
+ const actionId = useMemo(() => {
10247
+ var _a, _b;
10248
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10249
+ }, [item]);
10250
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10251
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10252
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10253
+ const onSubmit = form.handleSubmit(async (data) => {
10254
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10255
+ setEditing(false);
10256
+ return;
10257
+ }
10258
+ if (!actionId) {
10259
+ await updateOriginalItem(
10260
+ {
10261
+ item_id: item.id,
10262
+ quantity: data.quantity,
10263
+ unit_price: convertNumber(data.unit_price)
10264
+ },
10265
+ {
10266
+ onSuccess: () => {
10267
+ setEditing(false);
10268
+ },
10269
+ onError: (e) => {
10270
+ toast.error(e.message);
10271
+ }
10272
+ }
10273
+ );
10274
+ return;
10275
+ }
10276
+ await updateActionItem(
9891
10277
  {
9892
- metadata: parsedData
10278
+ action_id: actionId,
10279
+ quantity: data.quantity,
10280
+ unit_price: convertNumber(data.unit_price)
9893
10281
  },
9894
10282
  {
9895
10283
  onSuccess: () => {
9896
- toast.success("Metadata updated");
9897
- handleSuccess();
10284
+ setEditing(false);
9898
10285
  },
9899
- onError: (error) => {
9900
- toast.error(error.message);
10286
+ onError: (e) => {
10287
+ toast.error(e.message);
9901
10288
  }
9902
10289
  }
9903
10290
  );
9904
10291
  });
9905
- const { fields, insert, remove } = useFieldArray({
9906
- control: form.control,
9907
- name: "metadata"
9908
- });
9909
- function deleteRow(index) {
9910
- remove(index);
9911
- if (fields.length === 1) {
9912
- insert(0, {
9913
- key: "",
9914
- value: "",
9915
- disabled: false
9916
- });
9917
- }
9918
- }
9919
- function insertRow(index, position) {
9920
- insert(index + (position === "above" ? 0 : 1), {
9921
- key: "",
9922
- value: "",
9923
- disabled: false
9924
- });
9925
- }
9926
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9927
- KeyboundForm,
9928
- {
9929
- onSubmit: handleSubmit,
9930
- className: "flex flex-1 flex-col overflow-hidden",
9931
- children: [
9932
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9933
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9934
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9935
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9936
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9937
- ] }),
9938
- fields.map((field, index) => {
9939
- const isDisabled = field.disabled || false;
9940
- let placeholder = "-";
9941
- if (typeof field.value === "object") {
9942
- placeholder = "{ ... }";
9943
- }
9944
- if (Array.isArray(field.value)) {
9945
- placeholder = "[ ... ]";
9946
- }
9947
- return /* @__PURE__ */ jsx(
9948
- ConditionalTooltip,
9949
- {
9950
- showTooltip: isDisabled,
9951
- content: "This row is disabled because it contains non-primitive data.",
9952
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9953
- /* @__PURE__ */ jsxs(
9954
- "div",
9955
- {
9956
- className: clx("grid grid-cols-2 divide-x", {
9957
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9958
- }),
9959
- children: [
9960
- /* @__PURE__ */ jsx(
9961
- Form$2.Field,
9962
- {
9963
- control: form.control,
9964
- name: `metadata.${index}.key`,
9965
- render: ({ field: field2 }) => {
9966
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9967
- GridInput,
9968
- {
9969
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9970
- ...field2,
9971
- disabled: isDisabled,
9972
- placeholder: "Key"
9973
- }
9974
- ) }) });
9975
- }
9976
- }
9977
- ),
9978
- /* @__PURE__ */ jsx(
9979
- Form$2.Field,
9980
- {
9981
- control: form.control,
9982
- name: `metadata.${index}.value`,
9983
- render: ({ field: { value, ...field2 } }) => {
9984
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9985
- GridInput,
9986
- {
9987
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
9988
- ...field2,
9989
- value: isDisabled ? placeholder : value,
9990
- disabled: isDisabled,
9991
- placeholder: "Value"
9992
- }
9993
- ) }) });
9994
- }
9995
- }
9996
- )
9997
- ]
9998
- }
9999
- ),
10000
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10001
- /* @__PURE__ */ jsx(
10002
- DropdownMenu.Trigger,
10003
- {
10004
- className: clx(
10005
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10006
- {
10007
- hidden: isDisabled
10008
- }
10009
- ),
10010
- disabled: isDisabled,
10011
- asChild: true,
10012
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10013
- }
10014
- ),
10015
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10016
- /* @__PURE__ */ jsxs(
10017
- DropdownMenu.Item,
10018
- {
10019
- className: "gap-x-2",
10020
- onClick: () => insertRow(index, "above"),
10021
- children: [
10022
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10023
- "Insert row above"
10024
- ]
10025
- }
10026
- ),
10027
- /* @__PURE__ */ jsxs(
10028
- DropdownMenu.Item,
10029
- {
10030
- className: "gap-x-2",
10031
- onClick: () => insertRow(index, "below"),
10032
- children: [
10033
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10034
- "Insert row below"
10035
- ]
10036
- }
10037
- ),
10038
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10039
- /* @__PURE__ */ jsxs(
10040
- DropdownMenu.Item,
10041
- {
10042
- className: "gap-x-2",
10043
- onClick: () => deleteRow(index),
10044
- children: [
10045
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10046
- "Delete row"
10047
- ]
10048
- }
10049
- )
10050
- ] })
10051
- ] })
10052
- ] })
10053
- },
10054
- field.id
10055
- );
10056
- })
10057
- ] }),
10058
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10292
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10293
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
10294
+ /* @__PURE__ */ jsx(
10295
+ Thumbnail,
10296
+ {
10297
+ thumbnail: item.thumbnail,
10298
+ alt: item.product_title ?? void 0
10299
+ }
10300
+ ),
10301
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10302
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10303
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10304
+ /* @__PURE__ */ jsxs(
10305
+ Text,
10306
+ {
10307
+ size: "small",
10308
+ leading: "compact",
10309
+ className: "text-ui-fg-subtle",
10310
+ children: [
10311
+ "(",
10312
+ item.variant_title,
10313
+ ")"
10314
+ ]
10315
+ }
10316
+ )
10059
10317
  ] }),
10060
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10061
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10062
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10063
- ] }) })
10064
- ]
10065
- }
10066
- ) });
10067
- };
10068
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10069
- return /* @__PURE__ */ jsx(
10070
- "input",
10071
- {
10072
- ref,
10073
- ...props,
10074
- autoComplete: "off",
10075
- className: clx(
10076
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
10077
- className
10078
- )
10079
- }
10080
- );
10081
- });
10082
- GridInput.displayName = "MetadataForm.GridInput";
10083
- const PlaceholderInner = () => {
10084
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10085
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10086
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10087
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10088
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10089
- ] }) })
10090
- ] });
10091
- };
10092
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10093
- function getDefaultValues(metadata) {
10094
- if (!metadata || !Object.keys(metadata).length) {
10095
- return [
10318
+ /* @__PURE__ */ jsx(
10319
+ Text,
10320
+ {
10321
+ size: "small",
10322
+ leading: "compact",
10323
+ className: "text-ui-fg-subtle",
10324
+ children: item.variant_sku
10325
+ }
10326
+ )
10327
+ ] })
10328
+ ] }),
10329
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10330
+ Form$2.Field,
10096
10331
  {
10097
- key: "",
10098
- value: "",
10099
- disabled: false
10332
+ control: form.control,
10333
+ name: "quantity",
10334
+ render: ({ field }) => {
10335
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10336
+ }
10100
10337
  }
10101
- ];
10102
- }
10103
- return Object.entries(metadata).map(([key, value]) => {
10104
- if (!EDITABLE_TYPES.includes(typeof value)) {
10105
- return {
10106
- key,
10107
- value,
10108
- disabled: true
10109
- };
10110
- }
10111
- let stringValue = value;
10112
- if (typeof value !== "string") {
10113
- stringValue = JSON.stringify(value);
10114
- }
10115
- return {
10116
- key,
10117
- value: stringValue,
10118
- original_key: key
10119
- };
10120
- });
10121
- }
10122
- function parseValues(values) {
10123
- const metadata = values.metadata;
10124
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10125
- if (isEmpty) {
10126
- return null;
10127
- }
10128
- const update = {};
10129
- metadata.forEach((field) => {
10130
- let key = field.key;
10131
- let value = field.value;
10132
- const disabled = field.disabled;
10133
- if (!key || !value) {
10134
- return;
10135
- }
10136
- if (disabled) {
10137
- update[key] = value;
10138
- return;
10139
- }
10140
- key = key.trim();
10141
- value = value.trim();
10142
- if (value === "true") {
10143
- update[key] = true;
10144
- } else if (value === "false") {
10145
- update[key] = false;
10146
- } else {
10147
- const parsedNumber = parseFloat(value);
10148
- if (!isNaN(parsedNumber)) {
10149
- update[key] = parsedNumber;
10150
- } else {
10151
- update[key] = value;
10152
- }
10153
- }
10154
- });
10155
- return update;
10156
- }
10157
- function getHasUneditableRows(metadata) {
10158
- if (!metadata) {
10159
- return false;
10160
- }
10161
- return Object.values(metadata).some(
10162
- (value) => !EDITABLE_TYPES.includes(typeof value)
10163
- );
10164
- }
10165
- const NumberInput = forwardRef(
10166
- ({
10167
- value,
10168
- onChange,
10169
- size = "base",
10170
- min = 0,
10171
- max = 100,
10172
- step = 1,
10173
- className,
10174
- disabled,
10175
- ...props
10176
- }, ref) => {
10177
- const handleChange = (event) => {
10178
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10179
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10180
- onChange(newValue);
10181
- }
10182
- };
10183
- const handleIncrement = () => {
10184
- const newValue = value + step;
10185
- if (max === void 0 || newValue <= max) {
10186
- onChange(newValue);
10187
- }
10188
- };
10189
- const handleDecrement = () => {
10190
- const newValue = value - step;
10191
- if (min === void 0 || newValue >= min) {
10192
- onChange(newValue);
10193
- }
10194
- };
10195
- return /* @__PURE__ */ jsxs(
10196
- "div",
10338
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10339
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10340
+ Form$2.Field,
10197
10341
  {
10198
- className: clx(
10199
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10200
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10201
- {
10202
- "h-7": size === "small",
10203
- "h-8": size === "base"
10204
- },
10205
- className
10206
- ),
10207
- children: [
10208
- /* @__PURE__ */ jsx(
10209
- "input",
10210
- {
10211
- ref,
10212
- type: "number",
10213
- value,
10214
- onChange: handleChange,
10215
- min,
10216
- max,
10217
- step,
10218
- className: clx(
10219
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10220
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10221
- "placeholder:text-ui-fg-muted"
10222
- ),
10223
- ...props
10224
- }
10225
- ),
10226
- /* @__PURE__ */ jsxs(
10227
- "button",
10228
- {
10229
- className: clx(
10230
- "flex items-center justify-center outline-none transition-fg",
10231
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10232
- "focus:bg-ui-bg-field-component-hover",
10233
- "hover:bg-ui-bg-field-component-hover",
10234
- {
10235
- "size-7": size === "small",
10236
- "size-8": size === "base"
10237
- }
10238
- ),
10239
- type: "button",
10240
- onClick: handleDecrement,
10241
- disabled: min !== void 0 && value <= min || disabled,
10242
- children: [
10243
- /* @__PURE__ */ jsx(Minus, {}),
10244
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10245
- ]
10246
- }
10247
- ),
10248
- /* @__PURE__ */ jsxs(
10249
- "button",
10342
+ control: form.control,
10343
+ name: "unit_price",
10344
+ render: ({ field: { onChange, ...field } }) => {
10345
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10346
+ CurrencyInput,
10250
10347
  {
10251
- className: clx(
10252
- "flex items-center justify-center outline-none transition-fg",
10253
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10254
- "focus:bg-ui-bg-field-hover",
10255
- "hover:bg-ui-bg-field-hover",
10256
- {
10257
- "size-7": size === "small",
10258
- "size-8": size === "base"
10259
- }
10260
- ),
10261
- type: "button",
10262
- onClick: handleIncrement,
10263
- disabled: max !== void 0 && value >= max || disabled,
10264
- children: [
10265
- /* @__PURE__ */ jsx(Plus, {}),
10266
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10267
- ]
10348
+ ...field,
10349
+ symbol: getNativeSymbol(currencyCode),
10350
+ code: currencyCode,
10351
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10268
10352
  }
10269
- )
10270
- ]
10353
+ ) }) });
10354
+ }
10271
10355
  }
10272
- );
10273
- }
10274
- );
10275
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10276
- const productVariantsQueryKeys = {
10277
- list: (query2) => [
10278
- PRODUCT_VARIANTS_QUERY_KEY,
10279
- query2 ? query2 : void 0
10280
- ]
10281
- };
10282
- const useProductVariants = (query2, options) => {
10283
- const { data, ...rest } = useQuery({
10284
- queryKey: productVariantsQueryKeys.list(query2),
10285
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10286
- ...options
10287
- });
10288
- return { ...data, ...rest };
10289
- };
10290
- const useCancelOrderEdit = ({ preview }) => {
10291
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10292
- const onCancel = useCallback(async () => {
10293
- if (!preview) {
10294
- return true;
10295
- }
10296
- let res = false;
10297
- await cancelOrderEdit(void 0, {
10298
- onError: (e) => {
10299
- toast.error(e.message);
10300
- },
10301
- onSuccess: () => {
10302
- res = true;
10356
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10357
+ /* @__PURE__ */ jsx(
10358
+ IconButton,
10359
+ {
10360
+ type: "button",
10361
+ size: "small",
10362
+ onClick: editing ? onSubmit : () => {
10363
+ setEditing(true);
10364
+ },
10365
+ disabled: isPending,
10366
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10303
10367
  }
10304
- });
10305
- return res;
10306
- }, [preview, cancelOrderEdit]);
10307
- return { onCancel };
10368
+ )
10369
+ ] }) }) });
10308
10370
  };
10309
- let IS_REQUEST_RUNNING = false;
10310
- const useInitiateOrderEdit = ({
10311
- preview
10312
- }) => {
10313
- const navigate = useNavigate();
10314
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10371
+ const variantItemSchema = objectType({
10372
+ quantity: numberType(),
10373
+ unit_price: unionType([numberType(), stringType()])
10374
+ });
10375
+ const CustomItem = ({ item, preview, currencyCode }) => {
10376
+ const [editing, setEditing] = useState(false);
10377
+ const { quantity, unit_price, title } = item;
10378
+ const form = useForm({
10379
+ defaultValues: {
10380
+ title,
10381
+ quantity,
10382
+ unit_price
10383
+ },
10384
+ resolver: zodResolver(customItemSchema)
10385
+ });
10315
10386
  useEffect(() => {
10316
- async function run() {
10317
- if (IS_REQUEST_RUNNING || !preview) {
10318
- return;
10319
- }
10320
- if (preview.order_change) {
10321
- return;
10322
- }
10323
- IS_REQUEST_RUNNING = true;
10324
- await mutateAsync(void 0, {
10325
- onError: (e) => {
10326
- toast.error(e.message);
10327
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10328
- return;
10329
- }
10330
- });
10331
- IS_REQUEST_RUNNING = false;
10332
- }
10333
- run();
10334
- }, [preview, navigate, mutateAsync]);
10335
- };
10336
- function convertNumber(value) {
10337
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10338
- }
10339
- const STACKED_MODAL_ID = "items_stacked_modal";
10340
- const Items = () => {
10341
- const { id } = useParams();
10342
- const {
10343
- order: preview,
10344
- isPending: isPreviewPending,
10345
- isError: isPreviewError,
10346
- error: previewError
10347
- } = useOrderPreview(id, void 0, {
10348
- placeholderData: keepPreviousData
10349
- });
10350
- useInitiateOrderEdit({ preview });
10351
- const { draft_order, isPending, isError, error } = useDraftOrder(
10352
- id,
10353
- {
10354
- fields: "currency_code"
10355
- },
10356
- {
10357
- enabled: !!id
10358
- }
10359
- );
10360
- const { onCancel } = useCancelOrderEdit({ preview });
10361
- if (isError) {
10362
- throw error;
10363
- }
10364
- if (isPreviewError) {
10365
- throw previewError;
10366
- }
10367
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10368
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10369
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10370
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10371
- ] }) });
10372
- };
10373
- const ItemsForm = ({ preview, currencyCode }) => {
10374
- var _a;
10375
- const [isSubmitting, setIsSubmitting] = useState(false);
10376
- const [modalContent, setModalContent] = useState(
10377
- null
10378
- );
10379
- const { handleSuccess } = useRouteModal();
10380
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10381
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10382
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10383
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10384
- const matches = useMemo(() => {
10385
- return matchSorter(preview.items, query2, {
10386
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10387
- });
10388
- }, [preview.items, query2]);
10389
- const onSubmit = async () => {
10390
- setIsSubmitting(true);
10391
- let requestSucceeded = false;
10392
- await requestOrderEdit(void 0, {
10393
- onError: (e) => {
10394
- toast.error(`Failed to request order edit: ${e.message}`);
10395
- },
10396
- onSuccess: () => {
10397
- requestSucceeded = true;
10398
- }
10399
- });
10400
- if (!requestSucceeded) {
10401
- setIsSubmitting(false);
10402
- return;
10403
- }
10404
- await confirmOrderEdit(void 0, {
10405
- onError: (e) => {
10406
- toast.error(`Failed to confirm order edit: ${e.message}`);
10407
- },
10408
- onSuccess: () => {
10409
- handleSuccess();
10410
- },
10411
- onSettled: () => {
10412
- setIsSubmitting(false);
10413
- }
10414
- });
10415
- };
10416
- const onKeyDown = useCallback(
10417
- (e) => {
10418
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10419
- if (modalContent || isSubmitting) {
10420
- return;
10421
- }
10422
- onSubmit();
10423
- }
10424
- },
10425
- [modalContent, isSubmitting, onSubmit]
10426
- );
10427
- useEffect(() => {
10428
- document.addEventListener("keydown", onKeyDown);
10429
- return () => {
10430
- document.removeEventListener("keydown", onKeyDown);
10431
- };
10432
- }, [onKeyDown]);
10433
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10434
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10435
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10436
- StackedFocusModal,
10437
- {
10438
- id: STACKED_MODAL_ID,
10439
- onOpenChangeCallback: (open) => {
10440
- if (!open) {
10441
- setModalContent(null);
10442
- }
10443
- },
10444
- children: [
10445
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10446
- /* @__PURE__ */ jsxs("div", { children: [
10447
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10448
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
10449
- ] }),
10450
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10451
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10452
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10453
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10454
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10455
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10456
- ] }),
10457
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10458
- /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10459
- Input,
10460
- {
10461
- type: "search",
10462
- placeholder: "Search items",
10463
- value: searchValue,
10464
- onChange: (e) => onSearchValueChange(e.target.value)
10465
- }
10466
- ) }),
10467
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10468
- /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10469
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10470
- /* @__PURE__ */ jsx(
10471
- StackedModalTrigger$1,
10472
- {
10473
- type: "add-items",
10474
- setModalContent
10475
- }
10476
- ),
10477
- /* @__PURE__ */ jsx(
10478
- StackedModalTrigger$1,
10479
- {
10480
- type: "add-custom-item",
10481
- setModalContent
10482
- }
10483
- )
10484
- ] })
10485
- ] })
10486
- ] })
10487
- ] }),
10488
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10489
- /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
10490
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10491
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10492
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10493
- /* @__PURE__ */ jsx("div", {})
10494
- ] }) }),
10495
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10496
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10497
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10498
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10499
- Item,
10500
- {
10501
- item,
10502
- preview,
10503
- currencyCode
10504
- },
10505
- item.id
10506
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10507
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10508
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10509
- 'No items found for "',
10510
- query2,
10511
- '".'
10512
- ] })
10513
- ] }) })
10514
- ] })
10515
- ] }),
10516
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10517
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10518
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10519
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10520
- Text,
10521
- {
10522
- size: "small",
10523
- leading: "compact",
10524
- className: "text-ui-fg-subtle",
10525
- children: [
10526
- itemCount,
10527
- " ",
10528
- itemCount === 1 ? "item" : "items"
10529
- ]
10530
- }
10531
- ) }),
10532
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10533
- ] })
10534
- ] }) }),
10535
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10536
- CustomItemForm,
10537
- {
10538
- orderId: preview.id,
10539
- currencyCode
10540
- }
10541
- ) : null)
10542
- ]
10543
- }
10544
- ) }),
10545
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10546
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10547
- /* @__PURE__ */ jsx(
10548
- Button,
10549
- {
10550
- size: "small",
10551
- type: "button",
10552
- onClick: onSubmit,
10553
- isLoading: isSubmitting,
10554
- children: "Save"
10555
- }
10556
- )
10557
- ] }) })
10558
- ] });
10559
- };
10560
- const Item = ({ item, preview, currencyCode }) => {
10561
- if (item.variant_id) {
10562
- return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10563
- }
10564
- return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10565
- };
10566
- const VariantItem = ({ item, preview, currencyCode }) => {
10567
- const [editing, setEditing] = useState(false);
10568
- const form = useForm({
10569
- defaultValues: {
10570
- quantity: item.quantity,
10571
- unit_price: item.unit_price
10572
- },
10573
- resolver: zodResolver(variantItemSchema)
10574
- });
10575
- const actionId = useMemo(() => {
10576
- var _a, _b;
10577
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10578
- }, [item]);
10579
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10580
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10581
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10582
- const onSubmit = form.handleSubmit(async (data) => {
10583
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10584
- setEditing(false);
10585
- return;
10387
+ form.reset({
10388
+ title,
10389
+ quantity,
10390
+ unit_price
10391
+ });
10392
+ }, [form, title, quantity, unit_price]);
10393
+ const actionId = useMemo(() => {
10394
+ var _a, _b;
10395
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10396
+ }, [item]);
10397
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10398
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10399
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10400
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10401
+ const onSubmit = form.handleSubmit(async (data) => {
10402
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10403
+ setEditing(false);
10404
+ return;
10586
10405
  }
10587
10406
  if (!actionId) {
10588
10407
  await updateOriginalItem(
@@ -10600,165 +10419,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10600
10419
  }
10601
10420
  }
10602
10421
  );
10603
- return;
10604
- }
10605
- await updateActionItem(
10606
- {
10607
- action_id: actionId,
10608
- quantity: data.quantity,
10609
- unit_price: convertNumber(data.unit_price)
10610
- },
10611
- {
10612
- onSuccess: () => {
10613
- setEditing(false);
10614
- },
10615
- onError: (e) => {
10616
- toast.error(e.message);
10617
- }
10618
- }
10619
- );
10620
- });
10621
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10622
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
10623
- /* @__PURE__ */ jsx(
10624
- Thumbnail,
10625
- {
10626
- thumbnail: item.thumbnail,
10627
- alt: item.product_title ?? void 0
10628
- }
10629
- ),
10630
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10631
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10632
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10633
- /* @__PURE__ */ jsxs(
10634
- Text,
10635
- {
10636
- size: "small",
10637
- leading: "compact",
10638
- className: "text-ui-fg-subtle",
10639
- children: [
10640
- "(",
10641
- item.variant_title,
10642
- ")"
10643
- ]
10644
- }
10645
- )
10646
- ] }),
10647
- /* @__PURE__ */ jsx(
10648
- Text,
10649
- {
10650
- size: "small",
10651
- leading: "compact",
10652
- className: "text-ui-fg-subtle",
10653
- children: item.variant_sku
10654
- }
10655
- )
10656
- ] })
10657
- ] }),
10658
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10659
- Form$2.Field,
10660
- {
10661
- control: form.control,
10662
- name: "quantity",
10663
- render: ({ field }) => {
10664
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10665
- }
10666
- }
10667
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10668
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10669
- Form$2.Field,
10670
- {
10671
- control: form.control,
10672
- name: "unit_price",
10673
- render: ({ field: { onChange, ...field } }) => {
10674
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10675
- CurrencyInput,
10676
- {
10677
- ...field,
10678
- symbol: getNativeSymbol(currencyCode),
10679
- code: currencyCode,
10680
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10681
- }
10682
- ) }) });
10683
- }
10684
- }
10685
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10686
- /* @__PURE__ */ jsx(
10687
- IconButton,
10688
- {
10689
- type: "button",
10690
- size: "small",
10691
- onClick: editing ? onSubmit : () => {
10692
- setEditing(true);
10693
- },
10694
- disabled: isPending,
10695
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10696
- }
10697
- )
10698
- ] }) }) });
10699
- };
10700
- const variantItemSchema = objectType({
10701
- quantity: numberType(),
10702
- unit_price: unionType([numberType(), stringType()])
10703
- });
10704
- const CustomItem = ({ item, preview, currencyCode }) => {
10705
- const [editing, setEditing] = useState(false);
10706
- const { quantity, unit_price, title } = item;
10707
- const form = useForm({
10708
- defaultValues: {
10709
- title,
10710
- quantity,
10711
- unit_price
10712
- },
10713
- resolver: zodResolver(customItemSchema)
10714
- });
10715
- useEffect(() => {
10716
- form.reset({
10717
- title,
10718
- quantity,
10719
- unit_price
10720
- });
10721
- }, [form, title, quantity, unit_price]);
10722
- const actionId = useMemo(() => {
10723
- var _a, _b;
10724
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10725
- }, [item]);
10726
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10727
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10728
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10729
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10730
- const onSubmit = form.handleSubmit(async (data) => {
10731
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10732
- setEditing(false);
10733
- return;
10734
- }
10735
- if (!actionId) {
10736
- await updateOriginalItem(
10737
- {
10738
- item_id: item.id,
10739
- quantity: data.quantity,
10740
- unit_price: convertNumber(data.unit_price)
10741
- },
10742
- {
10743
- onSuccess: () => {
10744
- setEditing(false);
10745
- },
10746
- onError: (e) => {
10747
- toast.error(e.message);
10748
- }
10749
- }
10750
- );
10751
- return;
10752
- }
10753
- if (data.quantity === 0) {
10754
- await removeActionItem(actionId, {
10755
- onSuccess: () => {
10756
- setEditing(false);
10757
- },
10758
- onError: (e) => {
10759
- toast.error(e.message);
10760
- }
10761
- });
10422
+ return;
10423
+ }
10424
+ if (data.quantity === 0) {
10425
+ await removeActionItem(actionId, {
10426
+ onSuccess: () => {
10427
+ setEditing(false);
10428
+ },
10429
+ onError: (e) => {
10430
+ toast.error(e.message);
10431
+ }
10432
+ });
10762
10433
  return;
10763
10434
  }
10764
10435
  await updateActionItem(
@@ -11136,1131 +10807,781 @@ const customItemSchema = objectType({
11136
10807
  quantity: numberType(),
11137
10808
  unit_price: unionType([numberType(), stringType()])
11138
10809
  });
11139
- const CustomItems = () => {
10810
+ const InlineTip = forwardRef(
10811
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10812
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10813
+ return /* @__PURE__ */ jsxs(
10814
+ "div",
10815
+ {
10816
+ ref,
10817
+ className: clx(
10818
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10819
+ className
10820
+ ),
10821
+ ...props,
10822
+ children: [
10823
+ /* @__PURE__ */ jsx(
10824
+ "div",
10825
+ {
10826
+ role: "presentation",
10827
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10828
+ "bg-ui-tag-orange-icon": variant === "warning"
10829
+ })
10830
+ }
10831
+ ),
10832
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10833
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10834
+ labelValue,
10835
+ ":"
10836
+ ] }),
10837
+ " ",
10838
+ children
10839
+ ] })
10840
+ ]
10841
+ }
10842
+ );
10843
+ }
10844
+ );
10845
+ InlineTip.displayName = "InlineTip";
10846
+ const MetadataFieldSchema = objectType({
10847
+ key: stringType(),
10848
+ disabled: booleanType().optional(),
10849
+ value: anyType()
10850
+ });
10851
+ const MetadataSchema = objectType({
10852
+ metadata: arrayType(MetadataFieldSchema)
10853
+ });
10854
+ const Metadata = () => {
10855
+ const { id } = useParams();
10856
+ const { order, isPending, isError, error } = useOrder(id, {
10857
+ fields: "metadata"
10858
+ });
10859
+ if (isError) {
10860
+ throw error;
10861
+ }
10862
+ const isReady = !isPending && !!order;
11140
10863
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11141
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
11142
- /* @__PURE__ */ jsx(CustomItemsForm, {})
10864
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10865
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10866
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10867
+ ] }),
10868
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11143
10869
  ] });
11144
10870
  };
11145
- const CustomItemsForm = () => {
10871
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10872
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10873
+ const MetadataForm = ({ orderId, metadata }) => {
10874
+ const { handleSuccess } = useRouteModal();
10875
+ const hasUneditableRows = getHasUneditableRows(metadata);
10876
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11146
10877
  const form = useForm({
11147
- resolver: zodResolver(schema$3)
10878
+ defaultValues: {
10879
+ metadata: getDefaultValues(metadata)
10880
+ },
10881
+ resolver: zodResolver(MetadataSchema)
11148
10882
  });
11149
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11150
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
11151
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11152
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11153
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
11154
- ] }) })
11155
- ] }) });
11156
- };
11157
- const schema$3 = objectType({
11158
- email: stringType().email()
11159
- });
11160
- const PROMOTION_QUERY_KEY = "promotions";
11161
- const promotionsQueryKeys = {
11162
- list: (query2) => [
11163
- PROMOTION_QUERY_KEY,
11164
- query2 ? query2 : void 0
11165
- ],
11166
- detail: (id, query2) => [
11167
- PROMOTION_QUERY_KEY,
11168
- id,
11169
- query2 ? query2 : void 0
11170
- ]
11171
- };
11172
- const usePromotions = (query2, options) => {
11173
- const { data, ...rest } = useQuery({
11174
- queryKey: promotionsQueryKeys.list(query2),
11175
- queryFn: async () => sdk.admin.promotion.list(query2),
11176
- ...options
11177
- });
11178
- return { ...data, ...rest };
11179
- };
11180
- const Promotions = () => {
11181
- const { id } = useParams();
11182
- const {
11183
- order: preview,
11184
- isError: isPreviewError,
11185
- error: previewError
11186
- } = useOrderPreview(id, void 0);
11187
- useInitiateOrderEdit({ preview });
11188
- const { onCancel } = useCancelOrderEdit({ preview });
11189
- if (isPreviewError) {
11190
- throw previewError;
11191
- }
11192
- const isReady = !!preview;
11193
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11194
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11195
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11196
- ] });
11197
- };
11198
- const PromotionForm = ({ preview }) => {
11199
- const { items, shipping_methods } = preview;
11200
- const [isSubmitting, setIsSubmitting] = useState(false);
11201
- const [comboboxValue, setComboboxValue] = useState("");
11202
- const { handleSuccess } = useRouteModal();
11203
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11204
- const promoCodes = getPromotionCodes(items, shipping_methods);
11205
- const { promotions, isPending, isError, error } = usePromotions(
11206
- {
11207
- code: promoCodes
11208
- },
11209
- {
11210
- enabled: !!promoCodes.length
11211
- }
11212
- );
11213
- const comboboxData = useComboboxData({
11214
- queryKey: ["promotions", "combobox", promoCodes],
11215
- queryFn: async (params) => {
11216
- return await sdk.admin.promotion.list({
11217
- ...params,
11218
- code: {
11219
- $nin: promoCodes
11220
- }
11221
- });
11222
- },
11223
- getOptions: (data) => {
11224
- return data.promotions.map((promotion) => ({
11225
- label: promotion.code,
11226
- value: promotion.code
11227
- }));
11228
- }
11229
- });
11230
- const add = async (value) => {
11231
- if (!value) {
11232
- return;
11233
- }
11234
- addPromotions(
10883
+ const handleSubmit = form.handleSubmit(async (data) => {
10884
+ const parsedData = parseValues(data);
10885
+ await mutateAsync(
11235
10886
  {
11236
- promo_codes: [value]
10887
+ metadata: parsedData
11237
10888
  },
11238
10889
  {
11239
- onError: (e) => {
11240
- toast.error(e.message);
11241
- comboboxData.onSearchValueChange("");
11242
- setComboboxValue("");
11243
- },
11244
10890
  onSuccess: () => {
11245
- comboboxData.onSearchValueChange("");
11246
- setComboboxValue("");
10891
+ toast.success("Metadata updated");
10892
+ handleSuccess();
10893
+ },
10894
+ onError: (error) => {
10895
+ toast.error(error.message);
11247
10896
  }
11248
10897
  }
11249
10898
  );
11250
- };
11251
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11252
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11253
- const onSubmit = async () => {
11254
- setIsSubmitting(true);
11255
- let requestSucceeded = false;
11256
- await requestOrderEdit(void 0, {
11257
- onError: (e) => {
11258
- toast.error(e.message);
11259
- },
11260
- onSuccess: () => {
11261
- requestSucceeded = true;
11262
- }
11263
- });
11264
- if (!requestSucceeded) {
11265
- setIsSubmitting(false);
11266
- return;
10899
+ });
10900
+ const { fields, insert, remove } = useFieldArray({
10901
+ control: form.control,
10902
+ name: "metadata"
10903
+ });
10904
+ function deleteRow(index) {
10905
+ remove(index);
10906
+ if (fields.length === 1) {
10907
+ insert(0, {
10908
+ key: "",
10909
+ value: "",
10910
+ disabled: false
10911
+ });
11267
10912
  }
11268
- await confirmOrderEdit(void 0, {
11269
- onError: (e) => {
11270
- toast.error(e.message);
11271
- },
11272
- onSuccess: () => {
11273
- handleSuccess();
11274
- },
11275
- onSettled: () => {
11276
- setIsSubmitting(false);
11277
- }
10913
+ }
10914
+ function insertRow(index, position) {
10915
+ insert(index + (position === "above" ? 0 : 1), {
10916
+ key: "",
10917
+ value: "",
10918
+ disabled: false
11278
10919
  });
11279
- };
11280
- if (isError) {
11281
- throw error;
11282
10920
  }
11283
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11284
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11285
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11286
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11287
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11288
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11289
- ] }),
11290
- /* @__PURE__ */ jsx(
11291
- Combobox,
11292
- {
11293
- id: "promotion-combobox",
11294
- "aria-describedby": "promotion-combobox-hint",
11295
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11296
- fetchNextPage: comboboxData.fetchNextPage,
11297
- options: comboboxData.options,
11298
- onSearchValueChange: comboboxData.onSearchValueChange,
11299
- searchValue: comboboxData.searchValue,
11300
- disabled: comboboxData.disabled || isAddingPromotions,
11301
- onChange: add,
11302
- value: comboboxValue
11303
- }
11304
- )
11305
- ] }),
11306
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11307
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11308
- PromotionItem,
11309
- {
11310
- promotion,
11311
- orderId: preview.id,
11312
- isLoading: isPending
11313
- },
11314
- promotion.id
11315
- )) })
11316
- ] }) }),
11317
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11318
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11319
- /* @__PURE__ */ jsx(
11320
- Button,
11321
- {
11322
- size: "small",
11323
- type: "submit",
11324
- isLoading: isSubmitting || isAddingPromotions,
11325
- children: "Save"
11326
- }
11327
- )
11328
- ] }) })
11329
- ] });
11330
- };
11331
- const PromotionItem = ({
11332
- promotion,
11333
- orderId,
11334
- isLoading
11335
- }) => {
11336
- var _a;
11337
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11338
- const onRemove = async () => {
11339
- removePromotions(
11340
- {
11341
- promo_codes: [promotion.code]
11342
- },
11343
- {
11344
- onError: (e) => {
11345
- toast.error(e.message);
11346
- }
11347
- }
11348
- );
11349
- };
11350
- const displayValue = getDisplayValue(promotion);
11351
- return /* @__PURE__ */ jsxs(
11352
- "div",
10921
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10922
+ KeyboundForm,
11353
10923
  {
11354
- className: clx(
11355
- "px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
11356
- {
11357
- "animate-pulse": isLoading
11358
- }
11359
- ),
10924
+ onSubmit: handleSubmit,
10925
+ className: "flex flex-1 flex-col overflow-hidden",
11360
10926
  children: [
11361
- /* @__PURE__ */ jsxs("div", { children: [
11362
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11363
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
11364
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11365
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11366
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
10927
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10928
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10929
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10930
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10931
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11367
10932
  ] }),
11368
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11369
- ] })
11370
- ] }),
11371
- /* @__PURE__ */ jsx(
11372
- IconButton,
11373
- {
11374
- size: "small",
11375
- type: "button",
11376
- variant: "transparent",
11377
- onClick: onRemove,
11378
- isLoading: isPending || isLoading,
11379
- children: /* @__PURE__ */ jsx(XMark, {})
11380
- }
11381
- )
11382
- ]
11383
- },
11384
- promotion.id
11385
- );
11386
- };
11387
- function getDisplayValue(promotion) {
11388
- var _a, _b, _c, _d;
11389
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11390
- if (!value) {
11391
- return null;
11392
- }
11393
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11394
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11395
- if (!currency) {
11396
- return null;
11397
- }
11398
- return getLocaleAmount(value, currency);
11399
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11400
- return formatPercentage(value);
11401
- }
11402
- return null;
11403
- }
11404
- const formatter = new Intl.NumberFormat([], {
11405
- style: "percent",
11406
- minimumFractionDigits: 2
10933
+ fields.map((field, index) => {
10934
+ const isDisabled = field.disabled || false;
10935
+ let placeholder = "-";
10936
+ if (typeof field.value === "object") {
10937
+ placeholder = "{ ... }";
10938
+ }
10939
+ if (Array.isArray(field.value)) {
10940
+ placeholder = "[ ... ]";
10941
+ }
10942
+ return /* @__PURE__ */ jsx(
10943
+ ConditionalTooltip,
10944
+ {
10945
+ showTooltip: isDisabled,
10946
+ content: "This row is disabled because it contains non-primitive data.",
10947
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10948
+ /* @__PURE__ */ jsxs(
10949
+ "div",
10950
+ {
10951
+ className: clx("grid grid-cols-2 divide-x", {
10952
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10953
+ }),
10954
+ children: [
10955
+ /* @__PURE__ */ jsx(
10956
+ Form$2.Field,
10957
+ {
10958
+ control: form.control,
10959
+ name: `metadata.${index}.key`,
10960
+ render: ({ field: field2 }) => {
10961
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10962
+ GridInput,
10963
+ {
10964
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10965
+ ...field2,
10966
+ disabled: isDisabled,
10967
+ placeholder: "Key"
10968
+ }
10969
+ ) }) });
10970
+ }
10971
+ }
10972
+ ),
10973
+ /* @__PURE__ */ jsx(
10974
+ Form$2.Field,
10975
+ {
10976
+ control: form.control,
10977
+ name: `metadata.${index}.value`,
10978
+ render: ({ field: { value, ...field2 } }) => {
10979
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10980
+ GridInput,
10981
+ {
10982
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10983
+ ...field2,
10984
+ value: isDisabled ? placeholder : value,
10985
+ disabled: isDisabled,
10986
+ placeholder: "Value"
10987
+ }
10988
+ ) }) });
10989
+ }
10990
+ }
10991
+ )
10992
+ ]
10993
+ }
10994
+ ),
10995
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10996
+ /* @__PURE__ */ jsx(
10997
+ DropdownMenu.Trigger,
10998
+ {
10999
+ className: clx(
11000
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11001
+ {
11002
+ hidden: isDisabled
11003
+ }
11004
+ ),
11005
+ disabled: isDisabled,
11006
+ asChild: true,
11007
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11008
+ }
11009
+ ),
11010
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11011
+ /* @__PURE__ */ jsxs(
11012
+ DropdownMenu.Item,
11013
+ {
11014
+ className: "gap-x-2",
11015
+ onClick: () => insertRow(index, "above"),
11016
+ children: [
11017
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11018
+ "Insert row above"
11019
+ ]
11020
+ }
11021
+ ),
11022
+ /* @__PURE__ */ jsxs(
11023
+ DropdownMenu.Item,
11024
+ {
11025
+ className: "gap-x-2",
11026
+ onClick: () => insertRow(index, "below"),
11027
+ children: [
11028
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11029
+ "Insert row below"
11030
+ ]
11031
+ }
11032
+ ),
11033
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11034
+ /* @__PURE__ */ jsxs(
11035
+ DropdownMenu.Item,
11036
+ {
11037
+ className: "gap-x-2",
11038
+ onClick: () => deleteRow(index),
11039
+ children: [
11040
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11041
+ "Delete row"
11042
+ ]
11043
+ }
11044
+ )
11045
+ ] })
11046
+ ] })
11047
+ ] })
11048
+ },
11049
+ field.id
11050
+ );
11051
+ })
11052
+ ] }),
11053
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11054
+ ] }),
11055
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11056
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11057
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11058
+ ] }) })
11059
+ ]
11060
+ }
11061
+ ) });
11062
+ };
11063
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11064
+ return /* @__PURE__ */ jsx(
11065
+ "input",
11066
+ {
11067
+ ref,
11068
+ ...props,
11069
+ autoComplete: "off",
11070
+ className: clx(
11071
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11072
+ className
11073
+ )
11074
+ }
11075
+ );
11407
11076
  });
11408
- const formatPercentage = (value, isPercentageValue = false) => {
11409
- let val = value || 0;
11410
- if (!isPercentageValue) {
11411
- val = val / 100;
11412
- }
11413
- return formatter.format(val);
11077
+ GridInput.displayName = "MetadataForm.GridInput";
11078
+ const PlaceholderInner = () => {
11079
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11080
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11081
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11082
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11083
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11084
+ ] }) })
11085
+ ] });
11414
11086
  };
11415
- function getPromotionCodes(items, shippingMethods) {
11416
- const codes = /* @__PURE__ */ new Set();
11417
- for (const item of items) {
11418
- if (item.adjustments) {
11419
- for (const adjustment of item.adjustments) {
11420
- if (adjustment.code) {
11421
- codes.add(adjustment.code);
11422
- }
11087
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11088
+ function getDefaultValues(metadata) {
11089
+ if (!metadata || !Object.keys(metadata).length) {
11090
+ return [
11091
+ {
11092
+ key: "",
11093
+ value: "",
11094
+ disabled: false
11423
11095
  }
11096
+ ];
11097
+ }
11098
+ return Object.entries(metadata).map(([key, value]) => {
11099
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11100
+ return {
11101
+ key,
11102
+ value,
11103
+ disabled: true
11104
+ };
11105
+ }
11106
+ let stringValue = value;
11107
+ if (typeof value !== "string") {
11108
+ stringValue = JSON.stringify(value);
11424
11109
  }
11110
+ return {
11111
+ key,
11112
+ value: stringValue,
11113
+ original_key: key
11114
+ };
11115
+ });
11116
+ }
11117
+ function parseValues(values) {
11118
+ const metadata = values.metadata;
11119
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11120
+ if (isEmpty) {
11121
+ return null;
11425
11122
  }
11426
- for (const shippingMethod of shippingMethods) {
11427
- if (shippingMethod.adjustments) {
11428
- for (const adjustment of shippingMethod.adjustments) {
11429
- if (adjustment.code) {
11430
- codes.add(adjustment.code);
11431
- }
11123
+ const update = {};
11124
+ metadata.forEach((field) => {
11125
+ let key = field.key;
11126
+ let value = field.value;
11127
+ const disabled = field.disabled;
11128
+ if (!key || !value) {
11129
+ return;
11130
+ }
11131
+ if (disabled) {
11132
+ update[key] = value;
11133
+ return;
11134
+ }
11135
+ key = key.trim();
11136
+ value = value.trim();
11137
+ if (value === "true") {
11138
+ update[key] = true;
11139
+ } else if (value === "false") {
11140
+ update[key] = false;
11141
+ } else {
11142
+ const parsedNumber = parseFloat(value);
11143
+ if (!isNaN(parsedNumber)) {
11144
+ update[key] = parsedNumber;
11145
+ } else {
11146
+ update[key] = value;
11432
11147
  }
11433
11148
  }
11149
+ });
11150
+ return update;
11151
+ }
11152
+ function getHasUneditableRows(metadata) {
11153
+ if (!metadata) {
11154
+ return false;
11434
11155
  }
11435
- return Array.from(codes);
11156
+ return Object.values(metadata).some(
11157
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11158
+ );
11436
11159
  }
11437
- const SalesChannel = () => {
11438
- const { id } = useParams();
11439
- const { draft_order, isPending, isError, error } = useDraftOrder(
11160
+ const PROMOTION_QUERY_KEY = "promotions";
11161
+ const promotionsQueryKeys = {
11162
+ list: (query2) => [
11163
+ PROMOTION_QUERY_KEY,
11164
+ query2 ? query2 : void 0
11165
+ ],
11166
+ detail: (id, query2) => [
11167
+ PROMOTION_QUERY_KEY,
11440
11168
  id,
11441
- {
11442
- fields: "+sales_channel_id"
11443
- },
11444
- {
11445
- enabled: !!id
11446
- }
11447
- );
11448
- if (isError) {
11449
- throw error;
11169
+ query2 ? query2 : void 0
11170
+ ]
11171
+ };
11172
+ const usePromotions = (query2, options) => {
11173
+ const { data, ...rest } = useQuery({
11174
+ queryKey: promotionsQueryKeys.list(query2),
11175
+ queryFn: async () => sdk.admin.promotion.list(query2),
11176
+ ...options
11177
+ });
11178
+ return { ...data, ...rest };
11179
+ };
11180
+ const Promotions = () => {
11181
+ const { id } = useParams();
11182
+ const {
11183
+ order: preview,
11184
+ isError: isPreviewError,
11185
+ error: previewError
11186
+ } = useOrderPreview(id, void 0);
11187
+ useInitiateOrderEdit({ preview });
11188
+ const { onCancel } = useCancelOrderEdit({ preview });
11189
+ if (isPreviewError) {
11190
+ throw previewError;
11450
11191
  }
11451
- const ISrEADY = !!draft_order && !isPending;
11452
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11453
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11454
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11455
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11456
- ] }),
11457
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11192
+ const isReady = !!preview;
11193
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11194
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11195
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11458
11196
  ] });
11459
11197
  };
11460
- const SalesChannelForm = ({ order }) => {
11461
- const form = useForm({
11462
- defaultValues: {
11463
- sales_channel_id: order.sales_channel_id || ""
11464
- },
11465
- resolver: zodResolver(schema$2)
11466
- });
11467
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11198
+ const PromotionForm = ({ preview }) => {
11199
+ const { items, shipping_methods } = preview;
11200
+ const [isSubmitting, setIsSubmitting] = useState(false);
11201
+ const [comboboxValue, setComboboxValue] = useState("");
11468
11202
  const { handleSuccess } = useRouteModal();
11469
- const onSubmit = form.handleSubmit(async (data) => {
11470
- await mutateAsync(
11471
- {
11472
- sales_channel_id: data.sales_channel_id
11473
- },
11474
- {
11475
- onSuccess: () => {
11476
- toast.success("Sales channel updated");
11477
- handleSuccess();
11478
- },
11479
- onError: (error) => {
11480
- toast.error(error.message);
11481
- }
11482
- }
11483
- );
11484
- });
11485
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11486
- KeyboundForm,
11203
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11204
+ const promoCodes = getPromotionCodes(items, shipping_methods);
11205
+ const { promotions, isPending, isError, error } = usePromotions(
11487
11206
  {
11488
- className: "flex flex-1 flex-col overflow-hidden",
11489
- onSubmit,
11490
- children: [
11491
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11492
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11493
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11494
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11495
- ] }) })
11496
- ]
11207
+ code: promoCodes
11208
+ },
11209
+ {
11210
+ enabled: !!promoCodes.length
11497
11211
  }
11498
- ) });
11499
- };
11500
- const SalesChannelField = ({ control, order }) => {
11501
- const salesChannels = useComboboxData({
11212
+ );
11213
+ const comboboxData = useComboboxData({
11214
+ queryKey: ["promotions", "combobox", promoCodes],
11502
11215
  queryFn: async (params) => {
11503
- return await sdk.admin.salesChannel.list(params);
11216
+ return await sdk.admin.promotion.list({
11217
+ ...params,
11218
+ code: {
11219
+ $nin: promoCodes
11220
+ }
11221
+ });
11504
11222
  },
11505
- queryKey: ["sales-channels"],
11506
11223
  getOptions: (data) => {
11507
- return data.sales_channels.map((salesChannel) => ({
11508
- label: salesChannel.name,
11509
- value: salesChannel.id
11224
+ return data.promotions.map((promotion) => ({
11225
+ label: promotion.code,
11226
+ value: promotion.code
11510
11227
  }));
11511
- },
11512
- defaultValue: order.sales_channel_id || void 0
11513
- });
11514
- return /* @__PURE__ */ jsx(
11515
- Form$2.Field,
11516
- {
11517
- control,
11518
- name: "sales_channel_id",
11519
- render: ({ field }) => {
11520
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11521
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11522
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11523
- Combobox,
11524
- {
11525
- options: salesChannels.options,
11526
- fetchNextPage: salesChannels.fetchNextPage,
11527
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11528
- searchValue: salesChannels.searchValue,
11529
- onSearchValueChange: salesChannels.onSearchValueChange,
11530
- placeholder: "Select sales channel",
11531
- ...field
11532
- }
11533
- ) }),
11534
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11535
- ] });
11536
- }
11537
11228
  }
11538
- );
11539
- };
11540
- const schema$2 = objectType({
11541
- sales_channel_id: stringType().min(1)
11542
- });
11543
- const ShippingAddress = () => {
11544
- const { id } = useParams();
11545
- const { order, isPending, isError, error } = useOrder(id, {
11546
- fields: "+shipping_address"
11547
- });
11548
- if (isError) {
11549
- throw error;
11550
- }
11551
- const isReady = !isPending && !!order;
11552
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11553
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11554
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11555
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11556
- ] }),
11557
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11558
- ] });
11559
- };
11560
- const ShippingAddressForm = ({ order }) => {
11561
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11562
- const form = useForm({
11563
- defaultValues: {
11564
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11565
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11566
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11567
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11568
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11569
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11570
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11571
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11572
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11573
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11574
- },
11575
- resolver: zodResolver(schema$1)
11576
11229
  });
11577
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11578
- const { handleSuccess } = useRouteModal();
11579
- const onSubmit = form.handleSubmit(async (data) => {
11580
- await mutateAsync(
11230
+ const add = async (value) => {
11231
+ if (!value) {
11232
+ return;
11233
+ }
11234
+ addPromotions(
11581
11235
  {
11582
- shipping_address: {
11583
- first_name: data.first_name,
11584
- last_name: data.last_name,
11585
- company: data.company,
11586
- address_1: data.address_1,
11587
- address_2: data.address_2,
11588
- city: data.city,
11589
- province: data.province,
11590
- country_code: data.country_code,
11591
- postal_code: data.postal_code,
11592
- phone: data.phone
11593
- }
11236
+ promo_codes: [value]
11594
11237
  },
11595
11238
  {
11596
- onSuccess: () => {
11597
- handleSuccess();
11239
+ onError: (e) => {
11240
+ toast.error(e.message);
11241
+ comboboxData.onSearchValueChange("");
11242
+ setComboboxValue("");
11598
11243
  },
11599
- onError: (error) => {
11600
- toast.error(error.message);
11244
+ onSuccess: () => {
11245
+ comboboxData.onSearchValueChange("");
11246
+ setComboboxValue("");
11601
11247
  }
11602
11248
  }
11603
11249
  );
11604
- });
11605
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11606
- KeyboundForm,
11607
- {
11608
- className: "flex flex-1 flex-col overflow-hidden",
11609
- onSubmit,
11610
- children: [
11611
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11612
- /* @__PURE__ */ jsx(
11613
- Form$2.Field,
11614
- {
11615
- control: form.control,
11616
- name: "country_code",
11617
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11618
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11619
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11620
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11621
- ] })
11622
- }
11623
- ),
11624
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11625
- /* @__PURE__ */ jsx(
11626
- Form$2.Field,
11627
- {
11628
- control: form.control,
11629
- name: "first_name",
11630
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11631
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11632
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11633
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11634
- ] })
11635
- }
11636
- ),
11637
- /* @__PURE__ */ jsx(
11638
- Form$2.Field,
11639
- {
11640
- control: form.control,
11641
- name: "last_name",
11642
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11643
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11644
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11645
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11646
- ] })
11647
- }
11648
- )
11649
- ] }),
11650
- /* @__PURE__ */ jsx(
11651
- Form$2.Field,
11652
- {
11653
- control: form.control,
11654
- name: "company",
11655
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11656
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11657
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11658
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11659
- ] })
11660
- }
11661
- ),
11662
- /* @__PURE__ */ jsx(
11663
- Form$2.Field,
11664
- {
11665
- control: form.control,
11666
- name: "address_1",
11667
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11668
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11669
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11670
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11671
- ] })
11672
- }
11673
- ),
11674
- /* @__PURE__ */ jsx(
11675
- Form$2.Field,
11676
- {
11677
- control: form.control,
11678
- name: "address_2",
11679
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11680
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11681
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11682
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11683
- ] })
11684
- }
11685
- ),
11686
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11687
- /* @__PURE__ */ jsx(
11688
- Form$2.Field,
11689
- {
11690
- control: form.control,
11691
- name: "postal_code",
11692
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11693
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11694
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11695
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11696
- ] })
11697
- }
11698
- ),
11699
- /* @__PURE__ */ jsx(
11700
- Form$2.Field,
11701
- {
11702
- control: form.control,
11703
- name: "city",
11704
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11705
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11706
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11707
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11708
- ] })
11709
- }
11710
- )
11711
- ] }),
11712
- /* @__PURE__ */ jsx(
11713
- Form$2.Field,
11714
- {
11715
- control: form.control,
11716
- name: "province",
11717
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11718
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11719
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11720
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11721
- ] })
11722
- }
11723
- ),
11724
- /* @__PURE__ */ jsx(
11725
- Form$2.Field,
11726
- {
11727
- control: form.control,
11728
- name: "phone",
11729
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11730
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11731
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11732
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11733
- ] })
11734
- }
11735
- )
11736
- ] }) }),
11737
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11738
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11739
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11740
- ] }) })
11741
- ]
11250
+ };
11251
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11252
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11253
+ const onSubmit = async () => {
11254
+ setIsSubmitting(true);
11255
+ let requestSucceeded = false;
11256
+ await requestOrderEdit(void 0, {
11257
+ onError: (e) => {
11258
+ toast.error(e.message);
11259
+ },
11260
+ onSuccess: () => {
11261
+ requestSucceeded = true;
11262
+ }
11263
+ });
11264
+ if (!requestSucceeded) {
11265
+ setIsSubmitting(false);
11266
+ return;
11742
11267
  }
11743
- ) });
11744
- };
11745
- const schema$1 = addressSchema;
11746
- const TransferOwnership = () => {
11747
- const { id } = useParams();
11748
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11749
- fields: "id,customer_id,customer.*"
11750
- });
11268
+ await confirmOrderEdit(void 0, {
11269
+ onError: (e) => {
11270
+ toast.error(e.message);
11271
+ },
11272
+ onSuccess: () => {
11273
+ handleSuccess();
11274
+ },
11275
+ onSettled: () => {
11276
+ setIsSubmitting(false);
11277
+ }
11278
+ });
11279
+ };
11751
11280
  if (isError) {
11752
11281
  throw error;
11753
11282
  }
11754
- const isReady = !isPending && !!draft_order;
11755
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11756
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11757
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11758
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11759
- ] }),
11760
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11283
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11284
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11285
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11286
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11287
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11288
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11289
+ ] }),
11290
+ /* @__PURE__ */ jsx(
11291
+ Combobox,
11292
+ {
11293
+ id: "promotion-combobox",
11294
+ "aria-describedby": "promotion-combobox-hint",
11295
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11296
+ fetchNextPage: comboboxData.fetchNextPage,
11297
+ options: comboboxData.options,
11298
+ onSearchValueChange: comboboxData.onSearchValueChange,
11299
+ searchValue: comboboxData.searchValue,
11300
+ disabled: comboboxData.disabled || isAddingPromotions,
11301
+ onChange: add,
11302
+ value: comboboxValue
11303
+ }
11304
+ )
11305
+ ] }),
11306
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11307
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11308
+ PromotionItem,
11309
+ {
11310
+ promotion,
11311
+ orderId: preview.id,
11312
+ isLoading: isPending
11313
+ },
11314
+ promotion.id
11315
+ )) })
11316
+ ] }) }),
11317
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11318
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11319
+ /* @__PURE__ */ jsx(
11320
+ Button,
11321
+ {
11322
+ size: "small",
11323
+ type: "submit",
11324
+ isLoading: isSubmitting || isAddingPromotions,
11325
+ children: "Save"
11326
+ }
11327
+ )
11328
+ ] }) })
11761
11329
  ] });
11762
11330
  };
11763
- const TransferOwnershipForm = ({ order }) => {
11764
- var _a, _b;
11765
- const form = useForm({
11766
- defaultValues: {
11767
- customer_id: order.customer_id || ""
11768
- },
11769
- resolver: zodResolver(schema)
11770
- });
11771
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11772
- const { handleSuccess } = useRouteModal();
11773
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11774
- const currentCustomer = order.customer ? {
11775
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11776
- value: order.customer.id
11777
- } : null;
11778
- const onSubmit = form.handleSubmit(async (data) => {
11779
- await mutateAsync(
11780
- { customer_id: data.customer_id },
11331
+ const PromotionItem = ({
11332
+ promotion,
11333
+ orderId,
11334
+ isLoading
11335
+ }) => {
11336
+ var _a;
11337
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11338
+ const onRemove = async () => {
11339
+ removePromotions(
11781
11340
  {
11782
- onSuccess: () => {
11783
- toast.success("Customer updated");
11784
- handleSuccess();
11785
- },
11786
- onError: (error) => {
11787
- toast.error(error.message);
11341
+ promo_codes: [promotion.code]
11342
+ },
11343
+ {
11344
+ onError: (e) => {
11345
+ toast.error(e.message);
11788
11346
  }
11789
11347
  }
11790
11348
  );
11791
- });
11792
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11793
- KeyboundForm,
11349
+ };
11350
+ const displayValue = getDisplayValue(promotion);
11351
+ return /* @__PURE__ */ jsxs(
11352
+ "div",
11794
11353
  {
11795
- className: "flex flex-1 flex-col overflow-hidden",
11796
- onSubmit,
11354
+ className: clx(
11355
+ "px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
11356
+ {
11357
+ "animate-pulse": isLoading
11358
+ }
11359
+ ),
11797
11360
  children: [
11798
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11799
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11800
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11801
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11802
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11803
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11361
+ /* @__PURE__ */ jsxs("div", { children: [
11362
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11363
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
11364
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11365
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11366
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11804
11367
  ] }),
11805
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11806
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11807
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11808
- ] })
11809
- ] }),
11810
- /* @__PURE__ */ jsx(
11811
- CustomerField,
11812
- {
11813
- control: form.control,
11814
- currentCustomerId: order.customer_id
11815
- }
11816
- )
11368
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11369
+ ] })
11817
11370
  ] }),
11818
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11819
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11820
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11821
- ] }) })
11371
+ /* @__PURE__ */ jsx(
11372
+ IconButton,
11373
+ {
11374
+ size: "small",
11375
+ type: "button",
11376
+ variant: "transparent",
11377
+ onClick: onRemove,
11378
+ isLoading: isPending || isLoading,
11379
+ children: /* @__PURE__ */ jsx(XMark, {})
11380
+ }
11381
+ )
11382
+ ]
11383
+ },
11384
+ promotion.id
11385
+ );
11386
+ };
11387
+ function getDisplayValue(promotion) {
11388
+ var _a, _b, _c, _d;
11389
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11390
+ if (!value) {
11391
+ return null;
11392
+ }
11393
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11394
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11395
+ if (!currency) {
11396
+ return null;
11397
+ }
11398
+ return getLocaleAmount(value, currency);
11399
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11400
+ return formatPercentage(value);
11401
+ }
11402
+ return null;
11403
+ }
11404
+ const formatter = new Intl.NumberFormat([], {
11405
+ style: "percent",
11406
+ minimumFractionDigits: 2
11407
+ });
11408
+ const formatPercentage = (value, isPercentageValue = false) => {
11409
+ let val = value || 0;
11410
+ if (!isPercentageValue) {
11411
+ val = val / 100;
11412
+ }
11413
+ return formatter.format(val);
11414
+ };
11415
+ function getPromotionCodes(items, shippingMethods) {
11416
+ const codes = /* @__PURE__ */ new Set();
11417
+ for (const item of items) {
11418
+ if (item.adjustments) {
11419
+ for (const adjustment of item.adjustments) {
11420
+ if (adjustment.code) {
11421
+ codes.add(adjustment.code);
11422
+ }
11423
+ }
11424
+ }
11425
+ }
11426
+ for (const shippingMethod of shippingMethods) {
11427
+ if (shippingMethod.adjustments) {
11428
+ for (const adjustment of shippingMethod.adjustments) {
11429
+ if (adjustment.code) {
11430
+ codes.add(adjustment.code);
11431
+ }
11432
+ }
11433
+ }
11434
+ }
11435
+ return Array.from(codes);
11436
+ }
11437
+ const SalesChannel = () => {
11438
+ const { id } = useParams();
11439
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11440
+ id,
11441
+ {
11442
+ fields: "+sales_channel_id"
11443
+ },
11444
+ {
11445
+ enabled: !!id
11446
+ }
11447
+ );
11448
+ if (isError) {
11449
+ throw error;
11450
+ }
11451
+ const ISrEADY = !!draft_order && !isPending;
11452
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11453
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11454
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11455
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11456
+ ] }),
11457
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11458
+ ] });
11459
+ };
11460
+ const SalesChannelForm = ({ order }) => {
11461
+ const form = useForm({
11462
+ defaultValues: {
11463
+ sales_channel_id: order.sales_channel_id || ""
11464
+ },
11465
+ resolver: zodResolver(schema$2)
11466
+ });
11467
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11468
+ const { handleSuccess } = useRouteModal();
11469
+ const onSubmit = form.handleSubmit(async (data) => {
11470
+ await mutateAsync(
11471
+ {
11472
+ sales_channel_id: data.sales_channel_id
11473
+ },
11474
+ {
11475
+ onSuccess: () => {
11476
+ toast.success("Sales channel updated");
11477
+ handleSuccess();
11478
+ },
11479
+ onError: (error) => {
11480
+ toast.error(error.message);
11481
+ }
11482
+ }
11483
+ );
11484
+ });
11485
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11486
+ KeyboundForm,
11487
+ {
11488
+ className: "flex flex-1 flex-col overflow-hidden",
11489
+ onSubmit,
11490
+ children: [
11491
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11492
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11493
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11494
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11495
+ ] }) })
11822
11496
  ]
11823
11497
  }
11824
11498
  ) });
11825
11499
  };
11826
- const CustomerField = ({ control, currentCustomerId }) => {
11827
- const customers = useComboboxData({
11500
+ const SalesChannelField = ({ control, order }) => {
11501
+ const salesChannels = useComboboxData({
11828
11502
  queryFn: async (params) => {
11829
- return await sdk.admin.customer.list({
11830
- ...params,
11831
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11832
- });
11503
+ return await sdk.admin.salesChannel.list(params);
11833
11504
  },
11834
- queryKey: ["customers"],
11505
+ queryKey: ["sales-channels"],
11835
11506
  getOptions: (data) => {
11836
- return data.customers.map((customer) => {
11837
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11838
- return {
11839
- label: name ? `${name} (${customer.email})` : customer.email,
11840
- value: customer.id
11841
- };
11842
- });
11843
- }
11507
+ return data.sales_channels.map((salesChannel) => ({
11508
+ label: salesChannel.name,
11509
+ value: salesChannel.id
11510
+ }));
11511
+ },
11512
+ defaultValue: order.sales_channel_id || void 0
11844
11513
  });
11845
11514
  return /* @__PURE__ */ jsx(
11846
11515
  Form$2.Field,
11847
11516
  {
11848
- name: "customer_id",
11849
11517
  control,
11850
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11851
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11852
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11853
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11854
- ] }),
11855
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11856
- Combobox,
11857
- {
11858
- options: customers.options,
11859
- fetchNextPage: customers.fetchNextPage,
11860
- isFetchingNextPage: customers.isFetchingNextPage,
11861
- searchValue: customers.searchValue,
11862
- onSearchValueChange: customers.onSearchValueChange,
11863
- placeholder: "Select customer",
11864
- ...field
11865
- }
11866
- ) }),
11867
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11868
- ] })
11518
+ name: "sales_channel_id",
11519
+ render: ({ field }) => {
11520
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11521
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11522
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11523
+ Combobox,
11524
+ {
11525
+ options: salesChannels.options,
11526
+ fetchNextPage: salesChannels.fetchNextPage,
11527
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11528
+ searchValue: salesChannels.searchValue,
11529
+ onSearchValueChange: salesChannels.onSearchValueChange,
11530
+ placeholder: "Select sales channel",
11531
+ ...field
11532
+ }
11533
+ ) }),
11534
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11535
+ ] });
11536
+ }
11869
11537
  }
11870
11538
  );
11871
11539
  };
11872
- const Illustration = () => {
11873
- return /* @__PURE__ */ jsxs(
11874
- "svg",
11875
- {
11876
- width: "280",
11877
- height: "180",
11878
- viewBox: "0 0 280 180",
11879
- fill: "none",
11880
- xmlns: "http://www.w3.org/2000/svg",
11881
- children: [
11882
- /* @__PURE__ */ jsx(
11883
- "rect",
11884
- {
11885
- x: "0.00428286",
11886
- y: "-0.742904",
11887
- width: "33.5",
11888
- height: "65.5",
11889
- rx: "6.75",
11890
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11891
- fill: "#D4D4D8",
11892
- stroke: "#52525B",
11893
- strokeWidth: "1.5"
11894
- }
11895
- ),
11896
- /* @__PURE__ */ jsx(
11897
- "rect",
11898
- {
11899
- x: "0.00428286",
11900
- y: "-0.742904",
11901
- width: "33.5",
11902
- height: "65.5",
11903
- rx: "6.75",
11904
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11905
- fill: "white",
11906
- stroke: "#52525B",
11907
- strokeWidth: "1.5"
11908
- }
11909
- ),
11910
- /* @__PURE__ */ jsx(
11911
- "path",
11912
- {
11913
- d: "M180.579 107.142L179.126 107.959",
11914
- stroke: "#52525B",
11915
- strokeWidth: "1.5",
11916
- strokeLinecap: "round",
11917
- strokeLinejoin: "round"
11918
- }
11919
- ),
11920
- /* @__PURE__ */ jsx(
11921
- "path",
11922
- {
11923
- opacity: "0.88",
11924
- d: "M182.305 109.546L180.257 109.534",
11925
- stroke: "#52525B",
11926
- strokeWidth: "1.5",
11927
- strokeLinecap: "round",
11928
- strokeLinejoin: "round"
11929
- }
11930
- ),
11931
- /* @__PURE__ */ jsx(
11932
- "path",
11933
- {
11934
- opacity: "0.75",
11935
- d: "M180.551 111.93L179.108 111.096",
11936
- stroke: "#52525B",
11937
- strokeWidth: "1.5",
11938
- strokeLinecap: "round",
11939
- strokeLinejoin: "round"
11940
- }
11941
- ),
11942
- /* @__PURE__ */ jsx(
11943
- "path",
11944
- {
11945
- opacity: "0.63",
11946
- d: "M176.347 112.897L176.354 111.73",
11947
- stroke: "#52525B",
11948
- strokeWidth: "1.5",
11949
- strokeLinecap: "round",
11950
- strokeLinejoin: "round"
11951
- }
11952
- ),
11953
- /* @__PURE__ */ jsx(
11954
- "path",
11955
- {
11956
- opacity: "0.5",
11957
- d: "M172.153 111.881L173.606 111.064",
11958
- stroke: "#52525B",
11959
- strokeWidth: "1.5",
11960
- strokeLinecap: "round",
11961
- strokeLinejoin: "round"
11962
- }
11963
- ),
11964
- /* @__PURE__ */ jsx(
11965
- "path",
11966
- {
11967
- opacity: "0.38",
11968
- d: "M170.428 109.478L172.476 109.489",
11969
- stroke: "#52525B",
11970
- strokeWidth: "1.5",
11971
- strokeLinecap: "round",
11972
- strokeLinejoin: "round"
11973
- }
11974
- ),
11975
- /* @__PURE__ */ jsx(
11976
- "path",
11977
- {
11978
- opacity: "0.25",
11979
- d: "M172.181 107.094L173.624 107.928",
11980
- stroke: "#52525B",
11981
- strokeWidth: "1.5",
11982
- strokeLinecap: "round",
11983
- strokeLinejoin: "round"
11984
- }
11985
- ),
11986
- /* @__PURE__ */ jsx(
11987
- "path",
11988
- {
11989
- opacity: "0.13",
11990
- d: "M176.386 106.126L176.379 107.294",
11991
- stroke: "#52525B",
11992
- strokeWidth: "1.5",
11993
- strokeLinecap: "round",
11994
- strokeLinejoin: "round"
11995
- }
11996
- ),
11997
- /* @__PURE__ */ jsx(
11998
- "rect",
11999
- {
12000
- width: "12",
12001
- height: "3",
12002
- rx: "1.5",
12003
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12004
- fill: "#D4D4D8"
12005
- }
12006
- ),
12007
- /* @__PURE__ */ jsx(
12008
- "rect",
12009
- {
12010
- x: "0.00428286",
12011
- y: "-0.742904",
12012
- width: "33.5",
12013
- height: "65.5",
12014
- rx: "6.75",
12015
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12016
- fill: "#D4D4D8",
12017
- stroke: "#52525B",
12018
- strokeWidth: "1.5"
12019
- }
12020
- ),
12021
- /* @__PURE__ */ jsx(
12022
- "rect",
12023
- {
12024
- x: "0.00428286",
12025
- y: "-0.742904",
12026
- width: "33.5",
12027
- height: "65.5",
12028
- rx: "6.75",
12029
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12030
- fill: "white",
12031
- stroke: "#52525B",
12032
- strokeWidth: "1.5"
12033
- }
12034
- ),
12035
- /* @__PURE__ */ jsx(
12036
- "rect",
12037
- {
12038
- width: "12",
12039
- height: "3",
12040
- rx: "1.5",
12041
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12042
- fill: "#D4D4D8"
12043
- }
12044
- ),
12045
- /* @__PURE__ */ jsx(
12046
- "rect",
12047
- {
12048
- width: "17",
12049
- height: "3",
12050
- rx: "1.5",
12051
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12052
- fill: "#D4D4D8"
12053
- }
12054
- ),
12055
- /* @__PURE__ */ jsx(
12056
- "rect",
12057
- {
12058
- width: "12",
12059
- height: "3",
12060
- rx: "1.5",
12061
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12062
- fill: "#D4D4D8"
12063
- }
12064
- ),
12065
- /* @__PURE__ */ jsx(
12066
- "path",
12067
- {
12068
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12069
- fill: "#A1A1AA"
12070
- }
12071
- ),
12072
- /* @__PURE__ */ jsx(
12073
- "rect",
12074
- {
12075
- width: "17",
12076
- height: "3",
12077
- rx: "1.5",
12078
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12079
- fill: "#A1A1AA"
12080
- }
12081
- ),
12082
- /* @__PURE__ */ jsx(
12083
- "rect",
12084
- {
12085
- width: "12",
12086
- height: "3",
12087
- rx: "1.5",
12088
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12089
- fill: "#A1A1AA"
12090
- }
12091
- ),
12092
- /* @__PURE__ */ jsx(
12093
- "path",
12094
- {
12095
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12096
- fill: "#52525B"
12097
- }
12098
- ),
12099
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12100
- "path",
12101
- {
12102
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12103
- stroke: "#A1A1AA",
12104
- strokeWidth: "1.5",
12105
- strokeLinecap: "round",
12106
- strokeLinejoin: "round"
12107
- }
12108
- ) }),
12109
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12110
- "path",
12111
- {
12112
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12113
- stroke: "#A1A1AA",
12114
- strokeWidth: "1.5",
12115
- strokeLinecap: "round",
12116
- strokeLinejoin: "round"
12117
- }
12118
- ) }),
12119
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12120
- "path",
12121
- {
12122
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12123
- stroke: "#A1A1AA",
12124
- strokeWidth: "1.5",
12125
- strokeLinecap: "round",
12126
- strokeLinejoin: "round"
12127
- }
12128
- ) }),
12129
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12130
- "path",
12131
- {
12132
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12133
- stroke: "#A1A1AA",
12134
- strokeWidth: "1.5",
12135
- strokeLinecap: "round",
12136
- strokeLinejoin: "round"
12137
- }
12138
- ) }),
12139
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12140
- "path",
12141
- {
12142
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12143
- stroke: "#A1A1AA",
12144
- strokeWidth: "1.5",
12145
- strokeLinecap: "round",
12146
- strokeLinejoin: "round"
12147
- }
12148
- ) }),
12149
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12150
- "path",
12151
- {
12152
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12153
- stroke: "#A1A1AA",
12154
- strokeWidth: "1.5",
12155
- strokeLinecap: "round",
12156
- strokeLinejoin: "round"
12157
- }
12158
- ) }),
12159
- /* @__PURE__ */ jsxs("defs", { children: [
12160
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12161
- "rect",
12162
- {
12163
- width: "12",
12164
- height: "12",
12165
- fill: "white",
12166
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12167
- }
12168
- ) }),
12169
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12170
- "rect",
12171
- {
12172
- width: "12",
12173
- height: "12",
12174
- fill: "white",
12175
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12176
- }
12177
- ) }),
12178
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12179
- "rect",
12180
- {
12181
- width: "12",
12182
- height: "12",
12183
- fill: "white",
12184
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12185
- }
12186
- ) }),
12187
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12188
- "rect",
12189
- {
12190
- width: "12",
12191
- height: "12",
12192
- fill: "white",
12193
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12194
- }
12195
- ) }),
12196
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12197
- "rect",
12198
- {
12199
- width: "12",
12200
- height: "12",
12201
- fill: "white",
12202
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12203
- }
12204
- ) }),
12205
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12206
- "rect",
12207
- {
12208
- width: "12",
12209
- height: "12",
12210
- fill: "white",
12211
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12212
- }
12213
- ) })
12214
- ] })
12215
- ]
12216
- }
12217
- );
12218
- };
12219
- const schema = objectType({
12220
- customer_id: stringType().min(1)
12221
- });
12222
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12223
- const Shipping = () => {
12224
- var _a;
12225
- const { id } = useParams();
12226
- const { order, isPending, isError, error } = useOrder(id, {
12227
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12228
- });
12229
- const {
12230
- order: preview,
12231
- isPending: isPreviewPending,
12232
- isError: isPreviewError,
12233
- error: previewError
12234
- } = useOrderPreview(id);
12235
- useInitiateOrderEdit({ preview });
12236
- const { onCancel } = useCancelOrderEdit({ preview });
12237
- if (isError) {
12238
- throw error;
12239
- }
12240
- if (isPreviewError) {
12241
- throw previewError;
12242
- }
12243
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12244
- const isReady = preview && !isPreviewPending && order && !isPending;
12245
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12246
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12247
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12248
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12249
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12250
- ] }) }) }),
12251
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12252
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
12253
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12254
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12255
- ] }) });
12256
- };
12257
- const ShippingForm = ({ preview, order }) => {
12258
- var _a;
12259
- const { setIsOpen } = useStackedModal();
12260
- const [isSubmitting, setIsSubmitting] = useState(false);
12261
- const [data, setData] = useState(null);
12262
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12263
- const { shipping_options } = useShippingOptions(
11540
+ const schema$2 = objectType({
11541
+ sales_channel_id: stringType().min(1)
11542
+ });
11543
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11544
+ const Shipping = () => {
11545
+ var _a;
11546
+ const { id } = useParams();
11547
+ const { order, isPending, isError, error } = useOrder(id, {
11548
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11549
+ });
11550
+ const {
11551
+ order: preview,
11552
+ isPending: isPreviewPending,
11553
+ isError: isPreviewError,
11554
+ error: previewError
11555
+ } = useOrderPreview(id);
11556
+ useInitiateOrderEdit({ preview });
11557
+ const { onCancel } = useCancelOrderEdit({ preview });
11558
+ if (isError) {
11559
+ throw error;
11560
+ }
11561
+ if (isPreviewError) {
11562
+ throw previewError;
11563
+ }
11564
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11565
+ const isReady = preview && !isPreviewPending && order && !isPending;
11566
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11567
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11568
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11569
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11570
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11571
+ ] }) }) }),
11572
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11573
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11574
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11575
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11576
+ ] }) });
11577
+ };
11578
+ const ShippingForm = ({ preview, order }) => {
11579
+ var _a;
11580
+ const { setIsOpen } = useStackedModal();
11581
+ const [isSubmitting, setIsSubmitting] = useState(false);
11582
+ const [data, setData] = useState(null);
11583
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11584
+ const { shipping_options } = useShippingOptions(
12264
11585
  {
12265
11586
  id: appliedShippingOptionIds,
12266
11587
  fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
@@ -12616,416 +11937,1095 @@ const ShippingForm = ({ preview, order }) => {
12616
11937
  if (!open) {
12617
11938
  setData(null);
12618
11939
  }
12619
- return open;
12620
- },
12621
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
12622
- }
12623
- )
12624
- ] }),
12625
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12626
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12627
- /* @__PURE__ */ jsx(
12628
- Button,
11940
+ return open;
11941
+ },
11942
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11943
+ }
11944
+ )
11945
+ ] }),
11946
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11947
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11948
+ /* @__PURE__ */ jsx(
11949
+ Button,
11950
+ {
11951
+ size: "small",
11952
+ type: "button",
11953
+ isLoading: isSubmitting,
11954
+ onClick: onSubmit,
11955
+ children: "Save"
11956
+ }
11957
+ )
11958
+ ] }) })
11959
+ ] });
11960
+ };
11961
+ const StackedModalTrigger = ({
11962
+ shippingProfileId,
11963
+ shippingOption,
11964
+ shippingMethod,
11965
+ setData,
11966
+ children
11967
+ }) => {
11968
+ const { setIsOpen, getIsOpen } = useStackedModal();
11969
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11970
+ const onToggle = () => {
11971
+ if (isOpen) {
11972
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11973
+ setData(null);
11974
+ } else {
11975
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11976
+ setData({
11977
+ shippingProfileId,
11978
+ shippingOption,
11979
+ shippingMethod
11980
+ });
11981
+ }
11982
+ };
11983
+ return /* @__PURE__ */ jsx(
11984
+ Button,
11985
+ {
11986
+ size: "small",
11987
+ variant: "secondary",
11988
+ onClick: onToggle,
11989
+ className: "text-ui-fg-primary shrink-0",
11990
+ children
11991
+ }
11992
+ );
11993
+ };
11994
+ const ShippingProfileForm = ({
11995
+ data,
11996
+ order,
11997
+ preview
11998
+ }) => {
11999
+ var _a, _b, _c, _d, _e, _f;
12000
+ const { setIsOpen } = useStackedModal();
12001
+ const form = useForm({
12002
+ resolver: zodResolver(shippingMethodSchema),
12003
+ defaultValues: {
12004
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12005
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12006
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12007
+ }
12008
+ });
12009
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12010
+ const {
12011
+ mutateAsync: updateShippingMethod,
12012
+ isPending: isUpdatingShippingMethod
12013
+ } = useDraftOrderUpdateShippingMethod(order.id);
12014
+ const onSubmit = form.handleSubmit(async (values) => {
12015
+ if (isEqual(values, form.formState.defaultValues)) {
12016
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12017
+ return;
12018
+ }
12019
+ if (data.shippingMethod) {
12020
+ await updateShippingMethod(
12021
+ {
12022
+ method_id: data.shippingMethod.id,
12023
+ shipping_option_id: values.shipping_option_id,
12024
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12025
+ },
12026
+ {
12027
+ onError: (e) => {
12028
+ toast.error(e.message);
12029
+ },
12030
+ onSuccess: () => {
12031
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12032
+ }
12033
+ }
12034
+ );
12035
+ return;
12036
+ }
12037
+ await addShippingMethod(
12038
+ {
12039
+ shipping_option_id: values.shipping_option_id,
12040
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12041
+ },
12042
+ {
12043
+ onError: (e) => {
12044
+ toast.error(e.message);
12045
+ },
12046
+ onSuccess: () => {
12047
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12048
+ }
12049
+ }
12050
+ );
12051
+ });
12052
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12053
+ KeyboundForm,
12054
+ {
12055
+ className: "flex h-full flex-col overflow-hidden",
12056
+ onSubmit,
12057
+ children: [
12058
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12059
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12060
+ /* @__PURE__ */ jsxs("div", { children: [
12061
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12062
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12063
+ ] }),
12064
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12065
+ /* @__PURE__ */ jsx(
12066
+ LocationField,
12067
+ {
12068
+ control: form.control,
12069
+ setValue: form.setValue
12070
+ }
12071
+ ),
12072
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12073
+ /* @__PURE__ */ jsx(
12074
+ ShippingOptionField,
12075
+ {
12076
+ shippingProfileId: data.shippingProfileId,
12077
+ preview,
12078
+ control: form.control
12079
+ }
12080
+ ),
12081
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12082
+ /* @__PURE__ */ jsx(
12083
+ CustomAmountField,
12084
+ {
12085
+ control: form.control,
12086
+ currencyCode: order.currency_code
12087
+ }
12088
+ ),
12089
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12090
+ /* @__PURE__ */ jsx(
12091
+ ItemsPreview,
12092
+ {
12093
+ order,
12094
+ shippingProfileId: data.shippingProfileId
12095
+ }
12096
+ )
12097
+ ] }) }) }),
12098
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12099
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12100
+ /* @__PURE__ */ jsx(
12101
+ Button,
12102
+ {
12103
+ size: "small",
12104
+ type: "submit",
12105
+ isLoading: isPending || isUpdatingShippingMethod,
12106
+ children: data.shippingMethod ? "Update" : "Add"
12107
+ }
12108
+ )
12109
+ ] }) })
12110
+ ]
12111
+ }
12112
+ ) }) });
12113
+ };
12114
+ const shippingMethodSchema = objectType({
12115
+ location_id: stringType(),
12116
+ shipping_option_id: stringType(),
12117
+ custom_amount: unionType([numberType(), stringType()]).optional()
12118
+ });
12119
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12120
+ const matches = order.items.filter(
12121
+ (item) => {
12122
+ var _a, _b, _c;
12123
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12124
+ }
12125
+ );
12126
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12127
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12128
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12129
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12130
+ ] }) }),
12131
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12132
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12133
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12134
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12135
+ ] }),
12136
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12137
+ "div",
12629
12138
  {
12630
- size: "small",
12631
- type: "button",
12632
- isLoading: isSubmitting,
12633
- onClick: onSubmit,
12634
- children: "Save"
12635
- }
12636
- )
12637
- ] }) })
12139
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12140
+ children: [
12141
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12142
+ /* @__PURE__ */ jsx(
12143
+ Thumbnail,
12144
+ {
12145
+ thumbnail: item.thumbnail,
12146
+ alt: item.product_title ?? void 0
12147
+ }
12148
+ ),
12149
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12150
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12151
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12152
+ /* @__PURE__ */ jsxs(
12153
+ Text,
12154
+ {
12155
+ size: "small",
12156
+ leading: "compact",
12157
+ className: "text-ui-fg-subtle",
12158
+ children: [
12159
+ "(",
12160
+ item.variant_title,
12161
+ ")"
12162
+ ]
12163
+ }
12164
+ )
12165
+ ] }),
12166
+ /* @__PURE__ */ jsx(
12167
+ Text,
12168
+ {
12169
+ size: "small",
12170
+ leading: "compact",
12171
+ className: "text-ui-fg-subtle",
12172
+ children: item.variant_sku
12173
+ }
12174
+ )
12175
+ ] })
12176
+ ] }),
12177
+ /* @__PURE__ */ jsxs(
12178
+ Text,
12179
+ {
12180
+ size: "small",
12181
+ leading: "compact",
12182
+ className: "text-ui-fg-subtle",
12183
+ children: [
12184
+ item.quantity,
12185
+ "x"
12186
+ ]
12187
+ }
12188
+ )
12189
+ ]
12190
+ },
12191
+ item.id
12192
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12193
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12194
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12195
+ 'No items found for "',
12196
+ query,
12197
+ '".'
12198
+ ] })
12199
+ ] }) })
12200
+ ] })
12638
12201
  ] });
12639
12202
  };
12640
- const StackedModalTrigger = ({
12203
+ const LocationField = ({ control, setValue }) => {
12204
+ const locations = useComboboxData({
12205
+ queryKey: ["locations"],
12206
+ queryFn: async (params) => {
12207
+ return await sdk.admin.stockLocation.list(params);
12208
+ },
12209
+ getOptions: (data) => {
12210
+ return data.stock_locations.map((location) => ({
12211
+ label: location.name,
12212
+ value: location.id
12213
+ }));
12214
+ }
12215
+ });
12216
+ return /* @__PURE__ */ jsx(
12217
+ Form$2.Field,
12218
+ {
12219
+ control,
12220
+ name: "location_id",
12221
+ render: ({ field: { onChange, ...field } }) => {
12222
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12223
+ /* @__PURE__ */ jsxs("div", { children: [
12224
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12225
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12226
+ ] }),
12227
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12228
+ Combobox,
12229
+ {
12230
+ options: locations.options,
12231
+ fetchNextPage: locations.fetchNextPage,
12232
+ isFetchingNextPage: locations.isFetchingNextPage,
12233
+ searchValue: locations.searchValue,
12234
+ onSearchValueChange: locations.onSearchValueChange,
12235
+ placeholder: "Select location",
12236
+ onChange: (value) => {
12237
+ setValue("shipping_option_id", "", {
12238
+ shouldDirty: true,
12239
+ shouldTouch: true
12240
+ });
12241
+ onChange(value);
12242
+ },
12243
+ ...field
12244
+ }
12245
+ ) })
12246
+ ] }) });
12247
+ }
12248
+ }
12249
+ );
12250
+ };
12251
+ const ShippingOptionField = ({
12641
12252
  shippingProfileId,
12642
- shippingOption,
12643
- shippingMethod,
12644
- setData,
12645
- children
12253
+ preview,
12254
+ control
12646
12255
  }) => {
12647
- const { setIsOpen, getIsOpen } = useStackedModal();
12648
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12649
- const onToggle = () => {
12650
- if (isOpen) {
12651
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12652
- setData(null);
12653
- } else {
12654
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12655
- setData({
12656
- shippingProfileId,
12657
- shippingOption,
12658
- shippingMethod
12256
+ var _a;
12257
+ const locationId = useWatch({ control, name: "location_id" });
12258
+ const shippingOptions = useComboboxData({
12259
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12260
+ queryFn: async (params) => {
12261
+ return await sdk.admin.shippingOption.list({
12262
+ ...params,
12263
+ stock_location_id: locationId,
12264
+ shipping_profile_id: shippingProfileId
12659
12265
  });
12266
+ },
12267
+ getOptions: (data) => {
12268
+ return data.shipping_options.map((option) => {
12269
+ var _a2;
12270
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12271
+ (r) => r.attribute === "is_return" && r.value === "true"
12272
+ )) {
12273
+ return void 0;
12274
+ }
12275
+ return {
12276
+ label: option.name,
12277
+ value: option.id
12278
+ };
12279
+ }).filter(Boolean);
12280
+ },
12281
+ enabled: !!locationId && !!shippingProfileId,
12282
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12283
+ });
12284
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12285
+ return /* @__PURE__ */ jsx(
12286
+ Form$2.Field,
12287
+ {
12288
+ control,
12289
+ name: "shipping_option_id",
12290
+ render: ({ field }) => {
12291
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12292
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12293
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12294
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12295
+ ] }),
12296
+ /* @__PURE__ */ jsx(
12297
+ ConditionalTooltip,
12298
+ {
12299
+ content: tooltipContent,
12300
+ showTooltip: !locationId || !shippingProfileId,
12301
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12302
+ Combobox,
12303
+ {
12304
+ options: shippingOptions.options,
12305
+ fetchNextPage: shippingOptions.fetchNextPage,
12306
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12307
+ searchValue: shippingOptions.searchValue,
12308
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12309
+ placeholder: "Select shipping option",
12310
+ ...field,
12311
+ disabled: !locationId || !shippingProfileId
12312
+ }
12313
+ ) }) })
12314
+ }
12315
+ )
12316
+ ] }) });
12317
+ }
12660
12318
  }
12661
- };
12319
+ );
12320
+ };
12321
+ const CustomAmountField = ({
12322
+ control,
12323
+ currencyCode
12324
+ }) => {
12662
12325
  return /* @__PURE__ */ jsx(
12663
- Button,
12326
+ Form$2.Field,
12664
12327
  {
12665
- size: "small",
12666
- variant: "secondary",
12667
- onClick: onToggle,
12668
- className: "text-ui-fg-primary shrink-0",
12669
- children
12328
+ control,
12329
+ name: "custom_amount",
12330
+ render: ({ field: { onChange, ...field } }) => {
12331
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12332
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12333
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12334
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12335
+ ] }),
12336
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12337
+ CurrencyInput,
12338
+ {
12339
+ ...field,
12340
+ onValueChange: (value) => onChange(value),
12341
+ symbol: getNativeSymbol(currencyCode),
12342
+ code: currencyCode
12343
+ }
12344
+ ) })
12345
+ ] });
12346
+ }
12670
12347
  }
12671
12348
  );
12672
12349
  };
12673
- const ShippingProfileForm = ({
12674
- data,
12675
- order,
12676
- preview
12677
- }) => {
12678
- var _a, _b, _c, _d, _e, _f;
12679
- const { setIsOpen } = useStackedModal();
12350
+ const TransferOwnership = () => {
12351
+ const { id } = useParams();
12352
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12353
+ fields: "id,customer_id,customer.*"
12354
+ });
12355
+ if (isError) {
12356
+ throw error;
12357
+ }
12358
+ const isReady = !isPending && !!draft_order;
12359
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12360
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12361
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12362
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12363
+ ] }),
12364
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12365
+ ] });
12366
+ };
12367
+ const TransferOwnershipForm = ({ order }) => {
12368
+ var _a, _b;
12680
12369
  const form = useForm({
12681
- resolver: zodResolver(shippingMethodSchema),
12682
12370
  defaultValues: {
12683
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12684
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12685
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12371
+ customer_id: order.customer_id || ""
12372
+ },
12373
+ resolver: zodResolver(schema$1)
12374
+ });
12375
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12376
+ const { handleSuccess } = useRouteModal();
12377
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12378
+ const currentCustomer = order.customer ? {
12379
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12380
+ value: order.customer.id
12381
+ } : null;
12382
+ const onSubmit = form.handleSubmit(async (data) => {
12383
+ await mutateAsync(
12384
+ { customer_id: data.customer_id },
12385
+ {
12386
+ onSuccess: () => {
12387
+ toast.success("Customer updated");
12388
+ handleSuccess();
12389
+ },
12390
+ onError: (error) => {
12391
+ toast.error(error.message);
12392
+ }
12393
+ }
12394
+ );
12395
+ });
12396
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12397
+ KeyboundForm,
12398
+ {
12399
+ className: "flex flex-1 flex-col overflow-hidden",
12400
+ onSubmit,
12401
+ children: [
12402
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12403
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12404
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12405
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12406
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12407
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12408
+ ] }),
12409
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12410
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12411
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12412
+ ] })
12413
+ ] }),
12414
+ /* @__PURE__ */ jsx(
12415
+ CustomerField,
12416
+ {
12417
+ control: form.control,
12418
+ currentCustomerId: order.customer_id
12419
+ }
12420
+ )
12421
+ ] }),
12422
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12423
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12424
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12425
+ ] }) })
12426
+ ]
12427
+ }
12428
+ ) });
12429
+ };
12430
+ const CustomerField = ({ control, currentCustomerId }) => {
12431
+ const customers = useComboboxData({
12432
+ queryFn: async (params) => {
12433
+ return await sdk.admin.customer.list({
12434
+ ...params,
12435
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12436
+ });
12437
+ },
12438
+ queryKey: ["customers"],
12439
+ getOptions: (data) => {
12440
+ return data.customers.map((customer) => {
12441
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12442
+ return {
12443
+ label: name ? `${name} (${customer.email})` : customer.email,
12444
+ value: customer.id
12445
+ };
12446
+ });
12686
12447
  }
12687
12448
  });
12688
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12689
- const {
12690
- mutateAsync: updateShippingMethod,
12691
- isPending: isUpdatingShippingMethod
12692
- } = useDraftOrderUpdateShippingMethod(order.id);
12693
- const onSubmit = form.handleSubmit(async (values) => {
12694
- if (isEqual(values, form.formState.defaultValues)) {
12695
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12696
- return;
12449
+ return /* @__PURE__ */ jsx(
12450
+ Form$2.Field,
12451
+ {
12452
+ name: "customer_id",
12453
+ control,
12454
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12455
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12456
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12457
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12458
+ ] }),
12459
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12460
+ Combobox,
12461
+ {
12462
+ options: customers.options,
12463
+ fetchNextPage: customers.fetchNextPage,
12464
+ isFetchingNextPage: customers.isFetchingNextPage,
12465
+ searchValue: customers.searchValue,
12466
+ onSearchValueChange: customers.onSearchValueChange,
12467
+ placeholder: "Select customer",
12468
+ ...field
12469
+ }
12470
+ ) }),
12471
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12472
+ ] })
12697
12473
  }
12698
- if (data.shippingMethod) {
12699
- await updateShippingMethod(
12700
- {
12701
- method_id: data.shippingMethod.id,
12702
- shipping_option_id: values.shipping_option_id,
12703
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12704
- },
12705
- {
12706
- onError: (e) => {
12707
- toast.error(e.message);
12708
- },
12709
- onSuccess: () => {
12710
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12474
+ );
12475
+ };
12476
+ const Illustration = () => {
12477
+ return /* @__PURE__ */ jsxs(
12478
+ "svg",
12479
+ {
12480
+ width: "280",
12481
+ height: "180",
12482
+ viewBox: "0 0 280 180",
12483
+ fill: "none",
12484
+ xmlns: "http://www.w3.org/2000/svg",
12485
+ children: [
12486
+ /* @__PURE__ */ jsx(
12487
+ "rect",
12488
+ {
12489
+ x: "0.00428286",
12490
+ y: "-0.742904",
12491
+ width: "33.5",
12492
+ height: "65.5",
12493
+ rx: "6.75",
12494
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12495
+ fill: "#D4D4D8",
12496
+ stroke: "#52525B",
12497
+ strokeWidth: "1.5"
12498
+ }
12499
+ ),
12500
+ /* @__PURE__ */ jsx(
12501
+ "rect",
12502
+ {
12503
+ x: "0.00428286",
12504
+ y: "-0.742904",
12505
+ width: "33.5",
12506
+ height: "65.5",
12507
+ rx: "6.75",
12508
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12509
+ fill: "white",
12510
+ stroke: "#52525B",
12511
+ strokeWidth: "1.5"
12512
+ }
12513
+ ),
12514
+ /* @__PURE__ */ jsx(
12515
+ "path",
12516
+ {
12517
+ d: "M180.579 107.142L179.126 107.959",
12518
+ stroke: "#52525B",
12519
+ strokeWidth: "1.5",
12520
+ strokeLinecap: "round",
12521
+ strokeLinejoin: "round"
12522
+ }
12523
+ ),
12524
+ /* @__PURE__ */ jsx(
12525
+ "path",
12526
+ {
12527
+ opacity: "0.88",
12528
+ d: "M182.305 109.546L180.257 109.534",
12529
+ stroke: "#52525B",
12530
+ strokeWidth: "1.5",
12531
+ strokeLinecap: "round",
12532
+ strokeLinejoin: "round"
12711
12533
  }
12712
- }
12713
- );
12714
- return;
12715
- }
12716
- await addShippingMethod(
12717
- {
12718
- shipping_option_id: values.shipping_option_id,
12719
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12720
- },
12721
- {
12722
- onError: (e) => {
12723
- toast.error(e.message);
12724
- },
12725
- onSuccess: () => {
12726
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12727
- }
12728
- }
12729
- );
12730
- });
12731
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12732
- KeyboundForm,
12733
- {
12734
- className: "flex h-full flex-col overflow-hidden",
12735
- onSubmit,
12736
- children: [
12737
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12738
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12739
- /* @__PURE__ */ jsxs("div", { children: [
12740
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12741
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12742
- ] }),
12743
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12744
- /* @__PURE__ */ jsx(
12745
- LocationField,
12534
+ ),
12535
+ /* @__PURE__ */ jsx(
12536
+ "path",
12537
+ {
12538
+ opacity: "0.75",
12539
+ d: "M180.551 111.93L179.108 111.096",
12540
+ stroke: "#52525B",
12541
+ strokeWidth: "1.5",
12542
+ strokeLinecap: "round",
12543
+ strokeLinejoin: "round"
12544
+ }
12545
+ ),
12546
+ /* @__PURE__ */ jsx(
12547
+ "path",
12548
+ {
12549
+ opacity: "0.63",
12550
+ d: "M176.347 112.897L176.354 111.73",
12551
+ stroke: "#52525B",
12552
+ strokeWidth: "1.5",
12553
+ strokeLinecap: "round",
12554
+ strokeLinejoin: "round"
12555
+ }
12556
+ ),
12557
+ /* @__PURE__ */ jsx(
12558
+ "path",
12559
+ {
12560
+ opacity: "0.5",
12561
+ d: "M172.153 111.881L173.606 111.064",
12562
+ stroke: "#52525B",
12563
+ strokeWidth: "1.5",
12564
+ strokeLinecap: "round",
12565
+ strokeLinejoin: "round"
12566
+ }
12567
+ ),
12568
+ /* @__PURE__ */ jsx(
12569
+ "path",
12570
+ {
12571
+ opacity: "0.38",
12572
+ d: "M170.428 109.478L172.476 109.489",
12573
+ stroke: "#52525B",
12574
+ strokeWidth: "1.5",
12575
+ strokeLinecap: "round",
12576
+ strokeLinejoin: "round"
12577
+ }
12578
+ ),
12579
+ /* @__PURE__ */ jsx(
12580
+ "path",
12581
+ {
12582
+ opacity: "0.25",
12583
+ d: "M172.181 107.094L173.624 107.928",
12584
+ stroke: "#52525B",
12585
+ strokeWidth: "1.5",
12586
+ strokeLinecap: "round",
12587
+ strokeLinejoin: "round"
12588
+ }
12589
+ ),
12590
+ /* @__PURE__ */ jsx(
12591
+ "path",
12592
+ {
12593
+ opacity: "0.13",
12594
+ d: "M176.386 106.126L176.379 107.294",
12595
+ stroke: "#52525B",
12596
+ strokeWidth: "1.5",
12597
+ strokeLinecap: "round",
12598
+ strokeLinejoin: "round"
12599
+ }
12600
+ ),
12601
+ /* @__PURE__ */ jsx(
12602
+ "rect",
12603
+ {
12604
+ width: "12",
12605
+ height: "3",
12606
+ rx: "1.5",
12607
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12608
+ fill: "#D4D4D8"
12609
+ }
12610
+ ),
12611
+ /* @__PURE__ */ jsx(
12612
+ "rect",
12613
+ {
12614
+ x: "0.00428286",
12615
+ y: "-0.742904",
12616
+ width: "33.5",
12617
+ height: "65.5",
12618
+ rx: "6.75",
12619
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12620
+ fill: "#D4D4D8",
12621
+ stroke: "#52525B",
12622
+ strokeWidth: "1.5"
12623
+ }
12624
+ ),
12625
+ /* @__PURE__ */ jsx(
12626
+ "rect",
12627
+ {
12628
+ x: "0.00428286",
12629
+ y: "-0.742904",
12630
+ width: "33.5",
12631
+ height: "65.5",
12632
+ rx: "6.75",
12633
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12634
+ fill: "white",
12635
+ stroke: "#52525B",
12636
+ strokeWidth: "1.5"
12637
+ }
12638
+ ),
12639
+ /* @__PURE__ */ jsx(
12640
+ "rect",
12641
+ {
12642
+ width: "12",
12643
+ height: "3",
12644
+ rx: "1.5",
12645
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12646
+ fill: "#D4D4D8"
12647
+ }
12648
+ ),
12649
+ /* @__PURE__ */ jsx(
12650
+ "rect",
12651
+ {
12652
+ width: "17",
12653
+ height: "3",
12654
+ rx: "1.5",
12655
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12656
+ fill: "#D4D4D8"
12657
+ }
12658
+ ),
12659
+ /* @__PURE__ */ jsx(
12660
+ "rect",
12661
+ {
12662
+ width: "12",
12663
+ height: "3",
12664
+ rx: "1.5",
12665
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12666
+ fill: "#D4D4D8"
12667
+ }
12668
+ ),
12669
+ /* @__PURE__ */ jsx(
12670
+ "path",
12671
+ {
12672
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12673
+ fill: "#A1A1AA"
12674
+ }
12675
+ ),
12676
+ /* @__PURE__ */ jsx(
12677
+ "rect",
12678
+ {
12679
+ width: "17",
12680
+ height: "3",
12681
+ rx: "1.5",
12682
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12683
+ fill: "#A1A1AA"
12684
+ }
12685
+ ),
12686
+ /* @__PURE__ */ jsx(
12687
+ "rect",
12688
+ {
12689
+ width: "12",
12690
+ height: "3",
12691
+ rx: "1.5",
12692
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12693
+ fill: "#A1A1AA"
12694
+ }
12695
+ ),
12696
+ /* @__PURE__ */ jsx(
12697
+ "path",
12698
+ {
12699
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12700
+ fill: "#52525B"
12701
+ }
12702
+ ),
12703
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12704
+ "path",
12705
+ {
12706
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12707
+ stroke: "#A1A1AA",
12708
+ strokeWidth: "1.5",
12709
+ strokeLinecap: "round",
12710
+ strokeLinejoin: "round"
12711
+ }
12712
+ ) }),
12713
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12714
+ "path",
12715
+ {
12716
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12717
+ stroke: "#A1A1AA",
12718
+ strokeWidth: "1.5",
12719
+ strokeLinecap: "round",
12720
+ strokeLinejoin: "round"
12721
+ }
12722
+ ) }),
12723
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12724
+ "path",
12725
+ {
12726
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12727
+ stroke: "#A1A1AA",
12728
+ strokeWidth: "1.5",
12729
+ strokeLinecap: "round",
12730
+ strokeLinejoin: "round"
12731
+ }
12732
+ ) }),
12733
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12734
+ "path",
12735
+ {
12736
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12737
+ stroke: "#A1A1AA",
12738
+ strokeWidth: "1.5",
12739
+ strokeLinecap: "round",
12740
+ strokeLinejoin: "round"
12741
+ }
12742
+ ) }),
12743
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12744
+ "path",
12745
+ {
12746
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12747
+ stroke: "#A1A1AA",
12748
+ strokeWidth: "1.5",
12749
+ strokeLinecap: "round",
12750
+ strokeLinejoin: "round"
12751
+ }
12752
+ ) }),
12753
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12754
+ "path",
12755
+ {
12756
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12757
+ stroke: "#A1A1AA",
12758
+ strokeWidth: "1.5",
12759
+ strokeLinecap: "round",
12760
+ strokeLinejoin: "round"
12761
+ }
12762
+ ) }),
12763
+ /* @__PURE__ */ jsxs("defs", { children: [
12764
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12765
+ "rect",
12746
12766
  {
12747
- control: form.control,
12748
- setValue: form.setValue
12767
+ width: "12",
12768
+ height: "12",
12769
+ fill: "white",
12770
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12749
12771
  }
12750
- ),
12751
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12752
- /* @__PURE__ */ jsx(
12753
- ShippingOptionField,
12772
+ ) }),
12773
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12774
+ "rect",
12754
12775
  {
12755
- shippingProfileId: data.shippingProfileId,
12756
- preview,
12757
- control: form.control
12776
+ width: "12",
12777
+ height: "12",
12778
+ fill: "white",
12779
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12758
12780
  }
12759
- ),
12760
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12761
- /* @__PURE__ */ jsx(
12762
- CustomAmountField,
12781
+ ) }),
12782
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12783
+ "rect",
12763
12784
  {
12764
- control: form.control,
12765
- currencyCode: order.currency_code
12785
+ width: "12",
12786
+ height: "12",
12787
+ fill: "white",
12788
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12766
12789
  }
12767
- ),
12768
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12769
- /* @__PURE__ */ jsx(
12770
- ItemsPreview,
12790
+ ) }),
12791
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12792
+ "rect",
12771
12793
  {
12772
- order,
12773
- shippingProfileId: data.shippingProfileId
12794
+ width: "12",
12795
+ height: "12",
12796
+ fill: "white",
12797
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12774
12798
  }
12775
- )
12776
- ] }) }) }),
12777
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12778
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12779
- /* @__PURE__ */ jsx(
12780
- Button,
12799
+ ) }),
12800
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12801
+ "rect",
12781
12802
  {
12782
- size: "small",
12783
- type: "submit",
12784
- isLoading: isPending || isUpdatingShippingMethod,
12785
- children: data.shippingMethod ? "Update" : "Add"
12803
+ width: "12",
12804
+ height: "12",
12805
+ fill: "white",
12806
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12786
12807
  }
12787
- )
12788
- ] }) })
12789
- ]
12790
- }
12791
- ) }) });
12792
- };
12793
- const shippingMethodSchema = objectType({
12794
- location_id: stringType(),
12795
- shipping_option_id: stringType(),
12796
- custom_amount: unionType([numberType(), stringType()]).optional()
12797
- });
12798
- const ItemsPreview = ({ order, shippingProfileId }) => {
12799
- const matches = order.items.filter(
12800
- (item) => {
12801
- var _a, _b, _c;
12802
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12803
- }
12804
- );
12805
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12806
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12807
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12808
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12809
- ] }) }),
12810
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12811
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12812
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12813
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12814
- ] }),
12815
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12816
- "div",
12817
- {
12818
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12819
- children: [
12820
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12821
- /* @__PURE__ */ jsx(
12822
- Thumbnail,
12823
- {
12824
- thumbnail: item.thumbnail,
12825
- alt: item.product_title ?? void 0
12826
- }
12827
- ),
12828
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12829
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12830
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12831
- /* @__PURE__ */ jsxs(
12832
- Text,
12833
- {
12834
- size: "small",
12835
- leading: "compact",
12836
- className: "text-ui-fg-subtle",
12837
- children: [
12838
- "(",
12839
- item.variant_title,
12840
- ")"
12841
- ]
12842
- }
12843
- )
12844
- ] }),
12845
- /* @__PURE__ */ jsx(
12846
- Text,
12847
- {
12848
- size: "small",
12849
- leading: "compact",
12850
- className: "text-ui-fg-subtle",
12851
- children: item.variant_sku
12852
- }
12853
- )
12854
- ] })
12855
- ] }),
12856
- /* @__PURE__ */ jsxs(
12857
- Text,
12858
- {
12859
- size: "small",
12860
- leading: "compact",
12861
- className: "text-ui-fg-subtle",
12862
- children: [
12863
- item.quantity,
12864
- "x"
12865
- ]
12866
- }
12867
- )
12868
- ]
12869
- },
12870
- item.id
12871
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12872
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12873
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12874
- 'No items found for "',
12875
- query,
12876
- '".'
12877
- ] })
12878
- ] }) })
12879
- ] })
12880
- ] });
12881
- };
12882
- const LocationField = ({ control, setValue }) => {
12883
- const locations = useComboboxData({
12884
- queryKey: ["locations"],
12885
- queryFn: async (params) => {
12886
- return await sdk.admin.stockLocation.list(params);
12887
- },
12888
- getOptions: (data) => {
12889
- return data.stock_locations.map((location) => ({
12890
- label: location.name,
12891
- value: location.id
12892
- }));
12893
- }
12894
- });
12895
- return /* @__PURE__ */ jsx(
12896
- Form$2.Field,
12897
- {
12898
- control,
12899
- name: "location_id",
12900
- render: ({ field: { onChange, ...field } }) => {
12901
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12902
- /* @__PURE__ */ jsxs("div", { children: [
12903
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12904
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12905
- ] }),
12906
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12907
- Combobox,
12808
+ ) }),
12809
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12810
+ "rect",
12908
12811
  {
12909
- options: locations.options,
12910
- fetchNextPage: locations.fetchNextPage,
12911
- isFetchingNextPage: locations.isFetchingNextPage,
12912
- searchValue: locations.searchValue,
12913
- onSearchValueChange: locations.onSearchValueChange,
12914
- placeholder: "Select location",
12915
- onChange: (value) => {
12916
- setValue("shipping_option_id", "", {
12917
- shouldDirty: true,
12918
- shouldTouch: true
12919
- });
12920
- onChange(value);
12921
- },
12922
- ...field
12812
+ width: "12",
12813
+ height: "12",
12814
+ fill: "white",
12815
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12923
12816
  }
12924
12817
  ) })
12925
- ] }) });
12926
- }
12818
+ ] })
12819
+ ]
12927
12820
  }
12928
12821
  );
12929
12822
  };
12930
- const ShippingOptionField = ({
12931
- shippingProfileId,
12932
- preview,
12933
- control
12934
- }) => {
12935
- var _a;
12936
- const locationId = useWatch({ control, name: "location_id" });
12937
- const shippingOptions = useComboboxData({
12938
- queryKey: ["shipping_options", locationId, shippingProfileId],
12939
- queryFn: async (params) => {
12940
- return await sdk.admin.shippingOption.list({
12941
- ...params,
12942
- stock_location_id: locationId,
12943
- shipping_profile_id: shippingProfileId
12944
- });
12823
+ const schema$1 = objectType({
12824
+ customer_id: stringType().min(1)
12825
+ });
12826
+ const ShippingAddress = () => {
12827
+ const { id } = useParams();
12828
+ const { order, isPending, isError, error } = useOrder(id, {
12829
+ fields: "+shipping_address"
12830
+ });
12831
+ if (isError) {
12832
+ throw error;
12833
+ }
12834
+ const isReady = !isPending && !!order;
12835
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12836
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12837
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12838
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12839
+ ] }),
12840
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12841
+ ] });
12842
+ };
12843
+ const ShippingAddressForm = ({ order }) => {
12844
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12845
+ const form = useForm({
12846
+ defaultValues: {
12847
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12848
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12849
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12850
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12851
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12852
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12853
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12854
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12855
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12856
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12945
12857
  },
12946
- getOptions: (data) => {
12947
- return data.shipping_options.map((option) => {
12948
- var _a2;
12949
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12950
- (r) => r.attribute === "is_return" && r.value === "true"
12951
- )) {
12952
- return void 0;
12858
+ resolver: zodResolver(schema)
12859
+ });
12860
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12861
+ const { handleSuccess } = useRouteModal();
12862
+ const onSubmit = form.handleSubmit(async (data) => {
12863
+ await mutateAsync(
12864
+ {
12865
+ shipping_address: {
12866
+ first_name: data.first_name,
12867
+ last_name: data.last_name,
12868
+ company: data.company,
12869
+ address_1: data.address_1,
12870
+ address_2: data.address_2,
12871
+ city: data.city,
12872
+ province: data.province,
12873
+ country_code: data.country_code,
12874
+ postal_code: data.postal_code,
12875
+ phone: data.phone
12953
12876
  }
12954
- return {
12955
- label: option.name,
12956
- value: option.id
12957
- };
12958
- }).filter(Boolean);
12959
- },
12960
- enabled: !!locationId && !!shippingProfileId,
12961
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12877
+ },
12878
+ {
12879
+ onSuccess: () => {
12880
+ handleSuccess();
12881
+ },
12882
+ onError: (error) => {
12883
+ toast.error(error.message);
12884
+ }
12885
+ }
12886
+ );
12962
12887
  });
12963
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12964
- return /* @__PURE__ */ jsx(
12965
- Form$2.Field,
12888
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12889
+ KeyboundForm,
12966
12890
  {
12967
- control,
12968
- name: "shipping_option_id",
12969
- render: ({ field }) => {
12970
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12971
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12972
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12973
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12891
+ className: "flex flex-1 flex-col overflow-hidden",
12892
+ onSubmit,
12893
+ children: [
12894
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12895
+ /* @__PURE__ */ jsx(
12896
+ Form$2.Field,
12897
+ {
12898
+ control: form.control,
12899
+ name: "country_code",
12900
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12901
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12902
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12903
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12904
+ ] })
12905
+ }
12906
+ ),
12907
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12908
+ /* @__PURE__ */ jsx(
12909
+ Form$2.Field,
12910
+ {
12911
+ control: form.control,
12912
+ name: "first_name",
12913
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12915
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12916
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
+ ] })
12918
+ }
12919
+ ),
12920
+ /* @__PURE__ */ jsx(
12921
+ Form$2.Field,
12922
+ {
12923
+ control: form.control,
12924
+ name: "last_name",
12925
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12926
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12927
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12928
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12929
+ ] })
12930
+ }
12931
+ )
12974
12932
  ] }),
12975
12933
  /* @__PURE__ */ jsx(
12976
- ConditionalTooltip,
12934
+ Form$2.Field,
12977
12935
  {
12978
- content: tooltipContent,
12979
- showTooltip: !locationId || !shippingProfileId,
12980
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12981
- Combobox,
12982
- {
12983
- options: shippingOptions.options,
12984
- fetchNextPage: shippingOptions.fetchNextPage,
12985
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12986
- searchValue: shippingOptions.searchValue,
12987
- onSearchValueChange: shippingOptions.onSearchValueChange,
12988
- placeholder: "Select shipping option",
12989
- ...field,
12990
- disabled: !locationId || !shippingProfileId
12991
- }
12992
- ) }) })
12936
+ control: form.control,
12937
+ name: "company",
12938
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12940
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
+ ] })
12993
12943
  }
12994
- )
12995
- ] }) });
12996
- }
12997
- }
12998
- );
12999
- };
13000
- const CustomAmountField = ({
13001
- control,
13002
- currencyCode
13003
- }) => {
13004
- return /* @__PURE__ */ jsx(
13005
- Form$2.Field,
13006
- {
13007
- control,
13008
- name: "custom_amount",
13009
- render: ({ field: { onChange, ...field } }) => {
13010
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13011
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
13012
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13013
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12944
+ ),
12945
+ /* @__PURE__ */ jsx(
12946
+ Form$2.Field,
12947
+ {
12948
+ control: form.control,
12949
+ name: "address_1",
12950
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12951
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12952
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12953
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12954
+ ] })
12955
+ }
12956
+ ),
12957
+ /* @__PURE__ */ jsx(
12958
+ Form$2.Field,
12959
+ {
12960
+ control: form.control,
12961
+ name: "address_2",
12962
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12963
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12964
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12965
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12966
+ ] })
12967
+ }
12968
+ ),
12969
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12970
+ /* @__PURE__ */ jsx(
12971
+ Form$2.Field,
12972
+ {
12973
+ control: form.control,
12974
+ name: "postal_code",
12975
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12977
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
+ ] })
12980
+ }
12981
+ ),
12982
+ /* @__PURE__ */ jsx(
12983
+ Form$2.Field,
12984
+ {
12985
+ control: form.control,
12986
+ name: "city",
12987
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12988
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12989
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12990
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12991
+ ] })
12992
+ }
12993
+ )
13014
12994
  ] }),
13015
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13016
- CurrencyInput,
12995
+ /* @__PURE__ */ jsx(
12996
+ Form$2.Field,
13017
12997
  {
13018
- ...field,
13019
- onValueChange: (value) => onChange(value),
13020
- symbol: getNativeSymbol(currencyCode),
13021
- code: currencyCode
12998
+ control: form.control,
12999
+ name: "province",
13000
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13002
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
+ ] })
13022
13005
  }
13023
- ) })
13024
- ] });
13025
- }
13006
+ ),
13007
+ /* @__PURE__ */ jsx(
13008
+ Form$2.Field,
13009
+ {
13010
+ control: form.control,
13011
+ name: "phone",
13012
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13013
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13014
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13015
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13016
+ ] })
13017
+ }
13018
+ )
13019
+ ] }) }),
13020
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13021
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13022
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13023
+ ] }) })
13024
+ ]
13026
13025
  }
13027
- );
13026
+ ) });
13028
13027
  };
13028
+ const schema = addressSchema;
13029
13029
  const widgetModule = { widgets: [] };
13030
13030
  const routeModule = {
13031
13031
  routes: [
@@ -13055,16 +13055,16 @@ const routeModule = {
13055
13055
  path: "/draft-orders/:id/email"
13056
13056
  },
13057
13057
  {
13058
- Component: Metadata,
13059
- path: "/draft-orders/:id/metadata"
13058
+ Component: CustomItems,
13059
+ path: "/draft-orders/:id/custom-items"
13060
13060
  },
13061
13061
  {
13062
13062
  Component: Items,
13063
13063
  path: "/draft-orders/:id/items"
13064
13064
  },
13065
13065
  {
13066
- Component: CustomItems,
13067
- path: "/draft-orders/:id/custom-items"
13066
+ Component: Metadata,
13067
+ path: "/draft-orders/:id/metadata"
13068
13068
  },
13069
13069
  {
13070
13070
  Component: Promotions,
@@ -13075,16 +13075,16 @@ const routeModule = {
13075
13075
  path: "/draft-orders/:id/sales-channel"
13076
13076
  },
13077
13077
  {
13078
- Component: ShippingAddress,
13079
- path: "/draft-orders/:id/shipping-address"
13078
+ Component: Shipping,
13079
+ path: "/draft-orders/:id/shipping"
13080
13080
  },
13081
13081
  {
13082
13082
  Component: TransferOwnership,
13083
13083
  path: "/draft-orders/:id/transfer-ownership"
13084
13084
  },
13085
13085
  {
13086
- Component: Shipping,
13087
- path: "/draft-orders/:id/shipping"
13086
+ Component: ShippingAddress,
13087
+ path: "/draft-orders/:id/shipping-address"
13088
13088
  }
13089
13089
  ]
13090
13090
  }