@medusajs/draft-order 2.11.1-preview-20251023150219 → 2.11.1-preview-20251023180201

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.
@@ -9586,551 +9586,809 @@ const CustomItemsForm = () => {
9586
9586
  const schema$5 = objectType({
9587
9587
  email: stringType().email()
9588
9588
  });
9589
- const NumberInput = forwardRef(
9590
- ({
9591
- value,
9592
- onChange,
9593
- size = "base",
9594
- min = 0,
9595
- max = 100,
9596
- step = 1,
9597
- className,
9598
- disabled,
9599
- ...props
9600
- }, ref) => {
9601
- const handleChange = (event) => {
9602
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9603
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9604
- onChange(newValue);
9605
- }
9606
- };
9607
- const handleIncrement = () => {
9608
- const newValue = value + step;
9609
- if (max === void 0 || newValue <= max) {
9610
- onChange(newValue);
9611
- }
9612
- };
9613
- const handleDecrement = () => {
9614
- const newValue = value - step;
9615
- if (min === void 0 || newValue >= min) {
9616
- onChange(newValue);
9617
- }
9618
- };
9619
- return /* @__PURE__ */ jsxs(
9620
- "div",
9621
- {
9622
- className: clx(
9623
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9624
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9625
- {
9626
- "h-7": size === "small",
9627
- "h-8": size === "base"
9628
- },
9629
- className
9630
- ),
9631
- children: [
9632
- /* @__PURE__ */ jsx(
9633
- "input",
9634
- {
9635
- ref,
9636
- type: "number",
9637
- value,
9638
- onChange: handleChange,
9639
- min,
9640
- max,
9641
- step,
9642
- className: clx(
9643
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9644
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9645
- "placeholder:text-ui-fg-muted"
9646
- ),
9647
- ...props
9648
- }
9649
- ),
9650
- /* @__PURE__ */ jsxs(
9651
- "button",
9652
- {
9653
- className: clx(
9654
- "flex items-center justify-center outline-none transition-fg",
9655
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9656
- "focus:bg-ui-bg-field-component-hover",
9657
- "hover:bg-ui-bg-field-component-hover",
9658
- {
9659
- "size-7": size === "small",
9660
- "size-8": size === "base"
9661
- }
9662
- ),
9663
- type: "button",
9664
- onClick: handleDecrement,
9665
- disabled: min !== void 0 && value <= min || disabled,
9666
- children: [
9667
- /* @__PURE__ */ jsx(Minus, {}),
9668
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9669
- ]
9670
- }
9671
- ),
9672
- /* @__PURE__ */ jsxs(
9673
- "button",
9674
- {
9675
- className: clx(
9676
- "flex items-center justify-center outline-none transition-fg",
9677
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9678
- "focus:bg-ui-bg-field-hover",
9679
- "hover:bg-ui-bg-field-hover",
9680
- {
9681
- "size-7": size === "small",
9682
- "size-8": size === "base"
9683
- }
9684
- ),
9685
- type: "button",
9686
- onClick: handleIncrement,
9687
- disabled: max !== void 0 && value >= max || disabled,
9688
- children: [
9689
- /* @__PURE__ */ jsx(Plus, {}),
9690
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9691
- ]
9692
- }
9693
- )
9694
- ]
9695
- }
9696
- );
9589
+ const Email = () => {
9590
+ const { id } = useParams();
9591
+ const { order, isPending, isError, error } = useOrder(id, {
9592
+ fields: "+email"
9593
+ });
9594
+ if (isError) {
9595
+ throw error;
9697
9596
  }
9698
- );
9699
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9700
- const productVariantsQueryKeys = {
9701
- list: (query2) => [
9702
- PRODUCT_VARIANTS_QUERY_KEY,
9703
- query2 ? query2 : void 0
9704
- ]
9597
+ const isReady = !isPending && !!order;
9598
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9599
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9600
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9601
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9602
+ ] }),
9603
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9604
+ ] });
9705
9605
  };
9706
- const useProductVariants = (query2, options) => {
9707
- const { data, ...rest } = useQuery({
9708
- queryKey: productVariantsQueryKeys.list(query2),
9709
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9710
- ...options
9606
+ const EmailForm = ({ order }) => {
9607
+ const form = useForm({
9608
+ defaultValues: {
9609
+ email: order.email ?? ""
9610
+ },
9611
+ resolver: zodResolver(schema$4)
9711
9612
  });
9712
- return { ...data, ...rest };
9713
- };
9714
- const useCancelOrderEdit = ({ preview }) => {
9715
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9716
- const onCancel = useCallback(async () => {
9717
- if (!preview) {
9718
- return true;
9719
- }
9720
- let res = false;
9721
- await cancelOrderEdit(void 0, {
9722
- onError: (e) => {
9723
- toast.error(e.message);
9724
- },
9725
- onSuccess: () => {
9726
- res = true;
9727
- }
9728
- });
9729
- return res;
9730
- }, [preview, cancelOrderEdit]);
9731
- return { onCancel };
9732
- };
9733
- let IS_REQUEST_RUNNING = false;
9734
- const useInitiateOrderEdit = ({
9735
- preview
9736
- }) => {
9737
- const navigate = useNavigate();
9738
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9739
- useEffect(() => {
9740
- async function run() {
9741
- if (IS_REQUEST_RUNNING || !preview) {
9742
- return;
9743
- }
9744
- if (preview.order_change) {
9745
- return;
9746
- }
9747
- IS_REQUEST_RUNNING = true;
9748
- await mutateAsync(void 0, {
9749
- onError: (e) => {
9750
- toast.error(e.message);
9751
- navigate(`/draft-orders/${preview.id}`, { replace: true });
9752
- return;
9613
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9614
+ const { handleSuccess } = useRouteModal();
9615
+ const onSubmit = form.handleSubmit(async (data) => {
9616
+ await mutateAsync(
9617
+ { email: data.email },
9618
+ {
9619
+ onSuccess: () => {
9620
+ handleSuccess();
9621
+ },
9622
+ onError: (error) => {
9623
+ toast.error(error.message);
9753
9624
  }
9754
- });
9755
- IS_REQUEST_RUNNING = false;
9625
+ }
9626
+ );
9627
+ });
9628
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9629
+ KeyboundForm,
9630
+ {
9631
+ className: "flex flex-1 flex-col overflow-hidden",
9632
+ onSubmit,
9633
+ children: [
9634
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9635
+ Form$2.Field,
9636
+ {
9637
+ control: form.control,
9638
+ name: "email",
9639
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9640
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9641
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9642
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9643
+ ] })
9644
+ }
9645
+ ) }),
9646
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9647
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9648
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9649
+ ] }) })
9650
+ ]
9756
9651
  }
9757
- run();
9758
- }, [preview, navigate, mutateAsync]);
9652
+ ) });
9759
9653
  };
9760
- function convertNumber(value) {
9761
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
9762
- }
9763
- const STACKED_MODAL_ID = "items_stacked_modal";
9764
- const Items = () => {
9654
+ const schema$4 = objectType({
9655
+ email: stringType().email()
9656
+ });
9657
+ const BillingAddress = () => {
9765
9658
  const { id } = useParams();
9766
- const {
9767
- order: preview,
9768
- isPending: isPreviewPending,
9769
- isError: isPreviewError,
9770
- error: previewError
9771
- } = useOrderPreview(id, void 0, {
9772
- placeholderData: keepPreviousData
9659
+ const { order, isPending, isError, error } = useOrder(id, {
9660
+ fields: "+billing_address"
9773
9661
  });
9774
- useInitiateOrderEdit({ preview });
9775
- const { draft_order, isPending, isError, error } = useDraftOrder(
9776
- id,
9777
- {
9778
- fields: "currency_code"
9779
- },
9780
- {
9781
- enabled: !!id
9782
- }
9783
- );
9784
- const { onCancel } = useCancelOrderEdit({ preview });
9785
9662
  if (isError) {
9786
9663
  throw error;
9787
9664
  }
9788
- if (isPreviewError) {
9789
- throw previewError;
9790
- }
9791
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
9792
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
9793
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
9794
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
9795
- ] }) });
9796
- };
9797
- const ItemsForm = ({ preview, currencyCode }) => {
9798
- var _a;
9799
- const [isSubmitting, setIsSubmitting] = useState(false);
9800
- const [modalContent, setModalContent] = useState(
9801
- null
9802
- );
9803
- const { handleSuccess } = useRouteModal();
9804
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
9805
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
9806
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
9807
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
9808
- const matches = useMemo(() => {
9809
- return matchSorter(preview.items, query2, {
9810
- keys: ["product_title", "variant_title", "variant_sku", "title"]
9811
- });
9812
- }, [preview.items, query2]);
9813
- const onSubmit = async () => {
9814
- setIsSubmitting(true);
9815
- let requestSucceeded = false;
9816
- await requestOrderEdit(void 0, {
9817
- onError: (e) => {
9818
- toast.error(`Failed to request order edit: ${e.message}`);
9819
- },
9820
- onSuccess: () => {
9821
- requestSucceeded = true;
9822
- }
9823
- });
9824
- if (!requestSucceeded) {
9825
- setIsSubmitting(false);
9826
- return;
9827
- }
9828
- await confirmOrderEdit(void 0, {
9829
- onError: (e) => {
9830
- toast.error(`Failed to confirm order edit: ${e.message}`);
9831
- },
9832
- onSuccess: () => {
9833
- handleSuccess();
9834
- },
9835
- onSettled: () => {
9836
- setIsSubmitting(false);
9837
- }
9838
- });
9839
- };
9840
- const onKeyDown = useCallback(
9841
- (e) => {
9842
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
9843
- if (modalContent || isSubmitting) {
9844
- return;
9845
- }
9846
- onSubmit();
9847
- }
9848
- },
9849
- [modalContent, isSubmitting, onSubmit]
9850
- );
9851
- useEffect(() => {
9852
- document.addEventListener("keydown", onKeyDown);
9853
- return () => {
9854
- document.removeEventListener("keydown", onKeyDown);
9855
- };
9856
- }, [onKeyDown]);
9857
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
9858
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
9859
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
9860
- StackedFocusModal,
9861
- {
9862
- id: STACKED_MODAL_ID,
9863
- onOpenChangeCallback: (open) => {
9864
- if (!open) {
9865
- setModalContent(null);
9866
- }
9867
- },
9868
- children: [
9869
- /* @__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: [
9870
- /* @__PURE__ */ jsxs("div", { children: [
9871
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
9872
- /* @__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" }) })
9873
- ] }),
9874
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
9875
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
9876
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
9877
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
9878
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
9879
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
9880
- ] }),
9881
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
9882
- /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
9883
- Input,
9884
- {
9885
- type: "search",
9886
- placeholder: "Search items",
9887
- value: searchValue,
9888
- onChange: (e) => onSearchValueChange(e.target.value)
9889
- }
9890
- ) }),
9891
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
9892
- /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
9893
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
9894
- /* @__PURE__ */ jsx(
9895
- StackedModalTrigger$1,
9896
- {
9897
- type: "add-items",
9898
- setModalContent
9899
- }
9900
- ),
9901
- /* @__PURE__ */ jsx(
9902
- StackedModalTrigger$1,
9903
- {
9904
- type: "add-custom-item",
9905
- setModalContent
9906
- }
9907
- )
9908
- ] })
9909
- ] })
9910
- ] })
9911
- ] }),
9912
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
9913
- /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
9914
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
9915
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
9916
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
9917
- /* @__PURE__ */ jsx("div", {})
9918
- ] }) }),
9919
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
9920
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
9921
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
9922
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
9923
- Item,
9924
- {
9925
- item,
9926
- preview,
9927
- currencyCode
9928
- },
9929
- item.id
9930
- )) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
9931
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
9932
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
9933
- 'No items found for "',
9934
- query2,
9935
- '".'
9936
- ] })
9937
- ] }) })
9938
- ] })
9939
- ] }),
9940
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
9941
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
9942
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
9943
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
9944
- Text,
9945
- {
9946
- size: "small",
9947
- leading: "compact",
9948
- className: "text-ui-fg-subtle",
9949
- children: [
9950
- itemCount,
9951
- " ",
9952
- itemCount === 1 ? "item" : "items"
9953
- ]
9954
- }
9955
- ) }),
9956
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
9957
- ] })
9958
- ] }) }),
9959
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
9960
- CustomItemForm,
9961
- {
9962
- orderId: preview.id,
9963
- currencyCode
9964
- }
9965
- ) : null)
9966
- ]
9967
- }
9968
- ) }),
9969
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9970
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9971
- /* @__PURE__ */ jsx(
9972
- Button,
9973
- {
9974
- size: "small",
9975
- type: "button",
9976
- onClick: onSubmit,
9977
- isLoading: isSubmitting,
9978
- children: "Save"
9979
- }
9980
- )
9981
- ] }) })
9665
+ const isReady = !isPending && !!order;
9666
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9667
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9668
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9669
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9670
+ ] }),
9671
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9982
9672
  ] });
9983
9673
  };
9984
- const Item = ({ item, preview, currencyCode }) => {
9985
- if (item.variant_id) {
9986
- return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
9987
- }
9988
- return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
9989
- };
9990
- const VariantItem = ({ item, preview, currencyCode }) => {
9991
- const [editing, setEditing] = useState(false);
9674
+ const BillingAddressForm = ({ order }) => {
9675
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9992
9676
  const form = useForm({
9993
9677
  defaultValues: {
9994
- quantity: item.quantity,
9995
- unit_price: item.unit_price
9678
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9679
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9680
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9681
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9682
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9683
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9684
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9685
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9686
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9687
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9996
9688
  },
9997
- resolver: zodResolver(variantItemSchema)
9689
+ resolver: zodResolver(schema$3)
9998
9690
  });
9999
- const actionId = useMemo(() => {
10000
- var _a, _b;
10001
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10002
- }, [item]);
10003
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10004
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10005
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
9691
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9692
+ const { handleSuccess } = useRouteModal();
10006
9693
  const onSubmit = form.handleSubmit(async (data) => {
10007
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10008
- setEditing(false);
10009
- return;
10010
- }
10011
- if (!actionId) {
10012
- await updateOriginalItem(
10013
- {
10014
- item_id: item.id,
10015
- quantity: data.quantity,
10016
- unit_price: convertNumber(data.unit_price)
9694
+ await mutateAsync(
9695
+ { billing_address: data },
9696
+ {
9697
+ onSuccess: () => {
9698
+ handleSuccess();
10017
9699
  },
10018
- {
10019
- onSuccess: () => {
10020
- setEditing(false);
10021
- },
10022
- onError: (e) => {
10023
- toast.error(e.message);
10024
- }
10025
- }
10026
- );
10027
- return;
10028
- }
10029
- await updateActionItem(
10030
- {
10031
- action_id: actionId,
10032
- quantity: data.quantity,
10033
- unit_price: convertNumber(data.unit_price)
10034
- },
10035
- {
10036
- onSuccess: () => {
10037
- setEditing(false);
10038
- },
10039
- onError: (e) => {
10040
- toast.error(e.message);
9700
+ onError: (error) => {
9701
+ toast.error(error.message);
10041
9702
  }
10042
9703
  }
10043
9704
  );
10044
9705
  });
10045
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10046
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10047
- /* @__PURE__ */ jsx(
10048
- Thumbnail,
10049
- {
10050
- thumbnail: item.thumbnail,
10051
- alt: item.product_title ?? void 0
10052
- }
10053
- ),
10054
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10055
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10056
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10057
- /* @__PURE__ */ jsxs(
10058
- Text,
9706
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9707
+ KeyboundForm,
9708
+ {
9709
+ className: "flex flex-1 flex-col overflow-hidden",
9710
+ onSubmit,
9711
+ children: [
9712
+ /* @__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: [
9713
+ /* @__PURE__ */ jsx(
9714
+ Form$2.Field,
10059
9715
  {
10060
- size: "small",
10061
- leading: "compact",
10062
- className: "text-ui-fg-subtle",
10063
- children: [
10064
- "(",
10065
- item.variant_title,
10066
- ")"
10067
- ]
9716
+ control: form.control,
9717
+ name: "country_code",
9718
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9720
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9721
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
+ ] })
10068
9723
  }
10069
- )
10070
- ] }),
10071
- /* @__PURE__ */ jsx(
10072
- Text,
10073
- {
10074
- size: "small",
10075
- leading: "compact",
10076
- className: "text-ui-fg-subtle",
10077
- children: item.variant_sku
10078
- }
10079
- )
10080
- ] })
10081
- ] }),
10082
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10083
- Form$2.Field,
10084
- {
10085
- control: form.control,
10086
- name: "quantity",
10087
- render: ({ field }) => {
10088
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10089
- }
10090
- }
10091
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10092
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10093
- Form$2.Field,
10094
- {
10095
- control: form.control,
10096
- name: "unit_price",
10097
- render: ({ field: { onChange, ...field } }) => {
10098
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10099
- CurrencyInput,
9724
+ ),
9725
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9726
+ /* @__PURE__ */ jsx(
9727
+ Form$2.Field,
9728
+ {
9729
+ control: form.control,
9730
+ name: "first_name",
9731
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9733
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
+ ] })
9736
+ }
9737
+ ),
9738
+ /* @__PURE__ */ jsx(
9739
+ Form$2.Field,
9740
+ {
9741
+ control: form.control,
9742
+ name: "last_name",
9743
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9745
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
+ ] })
9748
+ }
9749
+ )
9750
+ ] }),
9751
+ /* @__PURE__ */ jsx(
9752
+ Form$2.Field,
10100
9753
  {
10101
- ...field,
10102
- symbol: getNativeSymbol(currencyCode),
10103
- code: currencyCode,
10104
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
9754
+ control: form.control,
9755
+ name: "company",
9756
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9757
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9758
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9759
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9760
+ ] })
10105
9761
  }
10106
- ) }) });
10107
- }
9762
+ ),
9763
+ /* @__PURE__ */ jsx(
9764
+ Form$2.Field,
9765
+ {
9766
+ control: form.control,
9767
+ name: "address_1",
9768
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9769
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9770
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9771
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9772
+ ] })
9773
+ }
9774
+ ),
9775
+ /* @__PURE__ */ jsx(
9776
+ Form$2.Field,
9777
+ {
9778
+ control: form.control,
9779
+ name: "address_2",
9780
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9781
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9782
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9783
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9784
+ ] })
9785
+ }
9786
+ ),
9787
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9788
+ /* @__PURE__ */ jsx(
9789
+ Form$2.Field,
9790
+ {
9791
+ control: form.control,
9792
+ name: "postal_code",
9793
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9794
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9795
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9796
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9797
+ ] })
9798
+ }
9799
+ ),
9800
+ /* @__PURE__ */ jsx(
9801
+ Form$2.Field,
9802
+ {
9803
+ control: form.control,
9804
+ name: "city",
9805
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9806
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9807
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9808
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9809
+ ] })
9810
+ }
9811
+ )
9812
+ ] }),
9813
+ /* @__PURE__ */ jsx(
9814
+ Form$2.Field,
9815
+ {
9816
+ control: form.control,
9817
+ name: "province",
9818
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9819
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9820
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9821
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9822
+ ] })
9823
+ }
9824
+ ),
9825
+ /* @__PURE__ */ jsx(
9826
+ Form$2.Field,
9827
+ {
9828
+ control: form.control,
9829
+ name: "phone",
9830
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9831
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9832
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9833
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9834
+ ] })
9835
+ }
9836
+ )
9837
+ ] }) }),
9838
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9839
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9840
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9841
+ ] }) })
9842
+ ]
9843
+ }
9844
+ ) });
9845
+ };
9846
+ const schema$3 = addressSchema;
9847
+ const NumberInput = forwardRef(
9848
+ ({
9849
+ value,
9850
+ onChange,
9851
+ size = "base",
9852
+ min = 0,
9853
+ max = 100,
9854
+ step = 1,
9855
+ className,
9856
+ disabled,
9857
+ ...props
9858
+ }, ref) => {
9859
+ const handleChange = (event) => {
9860
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9861
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9862
+ onChange(newValue);
10108
9863
  }
10109
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10110
- /* @__PURE__ */ jsx(
10111
- IconButton,
10112
- {
10113
- type: "button",
10114
- size: "small",
10115
- onClick: editing ? onSubmit : () => {
10116
- setEditing(true);
10117
- },
10118
- disabled: isPending,
10119
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
9864
+ };
9865
+ const handleIncrement = () => {
9866
+ const newValue = value + step;
9867
+ if (max === void 0 || newValue <= max) {
9868
+ onChange(newValue);
10120
9869
  }
10121
- )
10122
- ] }) }) });
10123
- };
10124
- const variantItemSchema = objectType({
10125
- quantity: numberType(),
10126
- unit_price: unionType([numberType(), stringType()])
10127
- });
10128
- const CustomItem = ({ item, preview, currencyCode }) => {
10129
- const [editing, setEditing] = useState(false);
10130
- const { quantity, unit_price, title } = item;
10131
- const form = useForm({
10132
- defaultValues: {
10133
- title,
9870
+ };
9871
+ const handleDecrement = () => {
9872
+ const newValue = value - step;
9873
+ if (min === void 0 || newValue >= min) {
9874
+ onChange(newValue);
9875
+ }
9876
+ };
9877
+ return /* @__PURE__ */ jsxs(
9878
+ "div",
9879
+ {
9880
+ className: clx(
9881
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9882
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9883
+ {
9884
+ "h-7": size === "small",
9885
+ "h-8": size === "base"
9886
+ },
9887
+ className
9888
+ ),
9889
+ children: [
9890
+ /* @__PURE__ */ jsx(
9891
+ "input",
9892
+ {
9893
+ ref,
9894
+ type: "number",
9895
+ value,
9896
+ onChange: handleChange,
9897
+ min,
9898
+ max,
9899
+ step,
9900
+ className: clx(
9901
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9902
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9903
+ "placeholder:text-ui-fg-muted"
9904
+ ),
9905
+ ...props
9906
+ }
9907
+ ),
9908
+ /* @__PURE__ */ jsxs(
9909
+ "button",
9910
+ {
9911
+ className: clx(
9912
+ "flex items-center justify-center outline-none transition-fg",
9913
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9914
+ "focus:bg-ui-bg-field-component-hover",
9915
+ "hover:bg-ui-bg-field-component-hover",
9916
+ {
9917
+ "size-7": size === "small",
9918
+ "size-8": size === "base"
9919
+ }
9920
+ ),
9921
+ type: "button",
9922
+ onClick: handleDecrement,
9923
+ disabled: min !== void 0 && value <= min || disabled,
9924
+ children: [
9925
+ /* @__PURE__ */ jsx(Minus, {}),
9926
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9927
+ ]
9928
+ }
9929
+ ),
9930
+ /* @__PURE__ */ jsxs(
9931
+ "button",
9932
+ {
9933
+ className: clx(
9934
+ "flex items-center justify-center outline-none transition-fg",
9935
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9936
+ "focus:bg-ui-bg-field-hover",
9937
+ "hover:bg-ui-bg-field-hover",
9938
+ {
9939
+ "size-7": size === "small",
9940
+ "size-8": size === "base"
9941
+ }
9942
+ ),
9943
+ type: "button",
9944
+ onClick: handleIncrement,
9945
+ disabled: max !== void 0 && value >= max || disabled,
9946
+ children: [
9947
+ /* @__PURE__ */ jsx(Plus, {}),
9948
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9949
+ ]
9950
+ }
9951
+ )
9952
+ ]
9953
+ }
9954
+ );
9955
+ }
9956
+ );
9957
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9958
+ const productVariantsQueryKeys = {
9959
+ list: (query2) => [
9960
+ PRODUCT_VARIANTS_QUERY_KEY,
9961
+ query2 ? query2 : void 0
9962
+ ]
9963
+ };
9964
+ const useProductVariants = (query2, options) => {
9965
+ const { data, ...rest } = useQuery({
9966
+ queryKey: productVariantsQueryKeys.list(query2),
9967
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9968
+ ...options
9969
+ });
9970
+ return { ...data, ...rest };
9971
+ };
9972
+ const useCancelOrderEdit = ({ preview }) => {
9973
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9974
+ const onCancel = useCallback(async () => {
9975
+ if (!preview) {
9976
+ return true;
9977
+ }
9978
+ let res = false;
9979
+ await cancelOrderEdit(void 0, {
9980
+ onError: (e) => {
9981
+ toast.error(e.message);
9982
+ },
9983
+ onSuccess: () => {
9984
+ res = true;
9985
+ }
9986
+ });
9987
+ return res;
9988
+ }, [preview, cancelOrderEdit]);
9989
+ return { onCancel };
9990
+ };
9991
+ let IS_REQUEST_RUNNING = false;
9992
+ const useInitiateOrderEdit = ({
9993
+ preview
9994
+ }) => {
9995
+ const navigate = useNavigate();
9996
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9997
+ useEffect(() => {
9998
+ async function run() {
9999
+ if (IS_REQUEST_RUNNING || !preview) {
10000
+ return;
10001
+ }
10002
+ if (preview.order_change) {
10003
+ return;
10004
+ }
10005
+ IS_REQUEST_RUNNING = true;
10006
+ await mutateAsync(void 0, {
10007
+ onError: (e) => {
10008
+ toast.error(e.message);
10009
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10010
+ return;
10011
+ }
10012
+ });
10013
+ IS_REQUEST_RUNNING = false;
10014
+ }
10015
+ run();
10016
+ }, [preview, navigate, mutateAsync]);
10017
+ };
10018
+ function convertNumber(value) {
10019
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10020
+ }
10021
+ const STACKED_MODAL_ID = "items_stacked_modal";
10022
+ const Items = () => {
10023
+ const { id } = useParams();
10024
+ const {
10025
+ order: preview,
10026
+ isPending: isPreviewPending,
10027
+ isError: isPreviewError,
10028
+ error: previewError
10029
+ } = useOrderPreview(id, void 0, {
10030
+ placeholderData: keepPreviousData
10031
+ });
10032
+ useInitiateOrderEdit({ preview });
10033
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10034
+ id,
10035
+ {
10036
+ fields: "currency_code"
10037
+ },
10038
+ {
10039
+ enabled: !!id
10040
+ }
10041
+ );
10042
+ const { onCancel } = useCancelOrderEdit({ preview });
10043
+ if (isError) {
10044
+ throw error;
10045
+ }
10046
+ if (isPreviewError) {
10047
+ throw previewError;
10048
+ }
10049
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10050
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10051
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10052
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10053
+ ] }) });
10054
+ };
10055
+ const ItemsForm = ({ preview, currencyCode }) => {
10056
+ var _a;
10057
+ const [isSubmitting, setIsSubmitting] = useState(false);
10058
+ const [modalContent, setModalContent] = useState(
10059
+ null
10060
+ );
10061
+ const { handleSuccess } = useRouteModal();
10062
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10063
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10064
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10065
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10066
+ const matches = useMemo(() => {
10067
+ return matchSorter(preview.items, query2, {
10068
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10069
+ });
10070
+ }, [preview.items, query2]);
10071
+ const onSubmit = async () => {
10072
+ setIsSubmitting(true);
10073
+ let requestSucceeded = false;
10074
+ await requestOrderEdit(void 0, {
10075
+ onError: (e) => {
10076
+ toast.error(`Failed to request order edit: ${e.message}`);
10077
+ },
10078
+ onSuccess: () => {
10079
+ requestSucceeded = true;
10080
+ }
10081
+ });
10082
+ if (!requestSucceeded) {
10083
+ setIsSubmitting(false);
10084
+ return;
10085
+ }
10086
+ await confirmOrderEdit(void 0, {
10087
+ onError: (e) => {
10088
+ toast.error(`Failed to confirm order edit: ${e.message}`);
10089
+ },
10090
+ onSuccess: () => {
10091
+ handleSuccess();
10092
+ },
10093
+ onSettled: () => {
10094
+ setIsSubmitting(false);
10095
+ }
10096
+ });
10097
+ };
10098
+ const onKeyDown = useCallback(
10099
+ (e) => {
10100
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10101
+ if (modalContent || isSubmitting) {
10102
+ return;
10103
+ }
10104
+ onSubmit();
10105
+ }
10106
+ },
10107
+ [modalContent, isSubmitting, onSubmit]
10108
+ );
10109
+ useEffect(() => {
10110
+ document.addEventListener("keydown", onKeyDown);
10111
+ return () => {
10112
+ document.removeEventListener("keydown", onKeyDown);
10113
+ };
10114
+ }, [onKeyDown]);
10115
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10116
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10117
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10118
+ StackedFocusModal,
10119
+ {
10120
+ id: STACKED_MODAL_ID,
10121
+ onOpenChangeCallback: (open) => {
10122
+ if (!open) {
10123
+ setModalContent(null);
10124
+ }
10125
+ },
10126
+ children: [
10127
+ /* @__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: [
10128
+ /* @__PURE__ */ jsxs("div", { children: [
10129
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10130
+ /* @__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" }) })
10131
+ ] }),
10132
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10133
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10134
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10135
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10136
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10137
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10138
+ ] }),
10139
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10140
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10141
+ Input,
10142
+ {
10143
+ type: "search",
10144
+ placeholder: "Search items",
10145
+ value: searchValue,
10146
+ onChange: (e) => onSearchValueChange(e.target.value)
10147
+ }
10148
+ ) }),
10149
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10150
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10151
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10152
+ /* @__PURE__ */ jsx(
10153
+ StackedModalTrigger$1,
10154
+ {
10155
+ type: "add-items",
10156
+ setModalContent
10157
+ }
10158
+ ),
10159
+ /* @__PURE__ */ jsx(
10160
+ StackedModalTrigger$1,
10161
+ {
10162
+ type: "add-custom-item",
10163
+ setModalContent
10164
+ }
10165
+ )
10166
+ ] })
10167
+ ] })
10168
+ ] })
10169
+ ] }),
10170
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10171
+ /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10172
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10173
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10174
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10175
+ /* @__PURE__ */ jsx("div", {})
10176
+ ] }) }),
10177
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10178
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10179
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10180
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10181
+ Item,
10182
+ {
10183
+ item,
10184
+ preview,
10185
+ currencyCode
10186
+ },
10187
+ item.id
10188
+ )) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10189
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10190
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10191
+ 'No items found for "',
10192
+ query2,
10193
+ '".'
10194
+ ] })
10195
+ ] }) })
10196
+ ] })
10197
+ ] }),
10198
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10199
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10200
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10201
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10202
+ Text,
10203
+ {
10204
+ size: "small",
10205
+ leading: "compact",
10206
+ className: "text-ui-fg-subtle",
10207
+ children: [
10208
+ itemCount,
10209
+ " ",
10210
+ itemCount === 1 ? "item" : "items"
10211
+ ]
10212
+ }
10213
+ ) }),
10214
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10215
+ ] })
10216
+ ] }) }),
10217
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10218
+ CustomItemForm,
10219
+ {
10220
+ orderId: preview.id,
10221
+ currencyCode
10222
+ }
10223
+ ) : null)
10224
+ ]
10225
+ }
10226
+ ) }),
10227
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10228
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10229
+ /* @__PURE__ */ jsx(
10230
+ Button,
10231
+ {
10232
+ size: "small",
10233
+ type: "button",
10234
+ onClick: onSubmit,
10235
+ isLoading: isSubmitting,
10236
+ children: "Save"
10237
+ }
10238
+ )
10239
+ ] }) })
10240
+ ] });
10241
+ };
10242
+ const Item = ({ item, preview, currencyCode }) => {
10243
+ if (item.variant_id) {
10244
+ return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10245
+ }
10246
+ return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10247
+ };
10248
+ const VariantItem = ({ item, preview, currencyCode }) => {
10249
+ const [editing, setEditing] = useState(false);
10250
+ const form = useForm({
10251
+ defaultValues: {
10252
+ quantity: item.quantity,
10253
+ unit_price: item.unit_price
10254
+ },
10255
+ resolver: zodResolver(variantItemSchema)
10256
+ });
10257
+ const actionId = useMemo(() => {
10258
+ var _a, _b;
10259
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10260
+ }, [item]);
10261
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10262
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10263
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10264
+ const onSubmit = form.handleSubmit(async (data) => {
10265
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10266
+ setEditing(false);
10267
+ return;
10268
+ }
10269
+ if (!actionId) {
10270
+ await updateOriginalItem(
10271
+ {
10272
+ item_id: item.id,
10273
+ quantity: data.quantity,
10274
+ unit_price: convertNumber(data.unit_price)
10275
+ },
10276
+ {
10277
+ onSuccess: () => {
10278
+ setEditing(false);
10279
+ },
10280
+ onError: (e) => {
10281
+ toast.error(e.message);
10282
+ }
10283
+ }
10284
+ );
10285
+ return;
10286
+ }
10287
+ await updateActionItem(
10288
+ {
10289
+ action_id: actionId,
10290
+ quantity: data.quantity,
10291
+ unit_price: convertNumber(data.unit_price)
10292
+ },
10293
+ {
10294
+ onSuccess: () => {
10295
+ setEditing(false);
10296
+ },
10297
+ onError: (e) => {
10298
+ toast.error(e.message);
10299
+ }
10300
+ }
10301
+ );
10302
+ });
10303
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10304
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10305
+ /* @__PURE__ */ jsx(
10306
+ Thumbnail,
10307
+ {
10308
+ thumbnail: item.thumbnail,
10309
+ alt: item.product_title ?? void 0
10310
+ }
10311
+ ),
10312
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10313
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10314
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10315
+ /* @__PURE__ */ jsxs(
10316
+ Text,
10317
+ {
10318
+ size: "small",
10319
+ leading: "compact",
10320
+ className: "text-ui-fg-subtle",
10321
+ children: [
10322
+ "(",
10323
+ item.variant_title,
10324
+ ")"
10325
+ ]
10326
+ }
10327
+ )
10328
+ ] }),
10329
+ /* @__PURE__ */ jsx(
10330
+ Text,
10331
+ {
10332
+ size: "small",
10333
+ leading: "compact",
10334
+ className: "text-ui-fg-subtle",
10335
+ children: item.variant_sku
10336
+ }
10337
+ )
10338
+ ] })
10339
+ ] }),
10340
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10341
+ Form$2.Field,
10342
+ {
10343
+ control: form.control,
10344
+ name: "quantity",
10345
+ render: ({ field }) => {
10346
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10347
+ }
10348
+ }
10349
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10350
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10351
+ Form$2.Field,
10352
+ {
10353
+ control: form.control,
10354
+ name: "unit_price",
10355
+ render: ({ field: { onChange, ...field } }) => {
10356
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10357
+ CurrencyInput,
10358
+ {
10359
+ ...field,
10360
+ symbol: getNativeSymbol(currencyCode),
10361
+ code: currencyCode,
10362
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10363
+ }
10364
+ ) }) });
10365
+ }
10366
+ }
10367
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10368
+ /* @__PURE__ */ jsx(
10369
+ IconButton,
10370
+ {
10371
+ type: "button",
10372
+ size: "small",
10373
+ onClick: editing ? onSubmit : () => {
10374
+ setEditing(true);
10375
+ },
10376
+ disabled: isPending,
10377
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10378
+ }
10379
+ )
10380
+ ] }) }) });
10381
+ };
10382
+ const variantItemSchema = objectType({
10383
+ quantity: numberType(),
10384
+ unit_price: unionType([numberType(), stringType()])
10385
+ });
10386
+ const CustomItem = ({ item, preview, currencyCode }) => {
10387
+ const [editing, setEditing] = useState(false);
10388
+ const { quantity, unit_price, title } = item;
10389
+ const form = useForm({
10390
+ defaultValues: {
10391
+ title,
10134
10392
  quantity,
10135
10393
  unit_price
10136
10394
  },
@@ -10783,710 +11041,465 @@ const MetadataForm = ({ orderId, metadata }) => {
10783
11041
  ]
10784
11042
  }
10785
11043
  ),
10786
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10787
- /* @__PURE__ */ jsxs(
10788
- DropdownMenu.Item,
10789
- {
10790
- className: "gap-x-2",
10791
- onClick: () => deleteRow(index),
10792
- children: [
10793
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10794
- "Delete row"
10795
- ]
10796
- }
10797
- )
10798
- ] })
10799
- ] })
10800
- ] })
10801
- },
10802
- field.id
10803
- );
10804
- })
10805
- ] }),
10806
- 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." })
10807
- ] }),
10808
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10809
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10810
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10811
- ] }) })
10812
- ]
10813
- }
10814
- ) });
10815
- };
10816
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10817
- return /* @__PURE__ */ jsx(
10818
- "input",
10819
- {
10820
- ref,
10821
- ...props,
10822
- autoComplete: "off",
10823
- className: clx(
10824
- "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",
10825
- className
10826
- )
10827
- }
10828
- );
10829
- });
10830
- GridInput.displayName = "MetadataForm.GridInput";
10831
- const PlaceholderInner = () => {
10832
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10833
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10834
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10835
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10836
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10837
- ] }) })
10838
- ] });
10839
- };
10840
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10841
- function getDefaultValues(metadata) {
10842
- if (!metadata || !Object.keys(metadata).length) {
10843
- return [
10844
- {
10845
- key: "",
10846
- value: "",
10847
- disabled: false
10848
- }
10849
- ];
10850
- }
10851
- return Object.entries(metadata).map(([key, value]) => {
10852
- if (!EDITABLE_TYPES.includes(typeof value)) {
10853
- return {
10854
- key,
10855
- value,
10856
- disabled: true
10857
- };
10858
- }
10859
- let stringValue = value;
10860
- if (typeof value !== "string") {
10861
- stringValue = JSON.stringify(value);
10862
- }
10863
- return {
10864
- key,
10865
- value: stringValue,
10866
- original_key: key
10867
- };
10868
- });
10869
- }
10870
- function parseValues(values) {
10871
- const metadata = values.metadata;
10872
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10873
- if (isEmpty) {
10874
- return null;
10875
- }
10876
- const update = {};
10877
- metadata.forEach((field) => {
10878
- let key = field.key;
10879
- let value = field.value;
10880
- const disabled = field.disabled;
10881
- if (!key || !value) {
10882
- return;
10883
- }
10884
- if (disabled) {
10885
- update[key] = value;
10886
- return;
10887
- }
10888
- key = key.trim();
10889
- value = value.trim();
10890
- if (value === "true") {
10891
- update[key] = true;
10892
- } else if (value === "false") {
10893
- update[key] = false;
10894
- } else {
10895
- const parsedNumber = parseFloat(value);
10896
- if (!isNaN(parsedNumber)) {
10897
- update[key] = parsedNumber;
10898
- } else {
10899
- update[key] = value;
10900
- }
10901
- }
10902
- });
10903
- return update;
10904
- }
10905
- function getHasUneditableRows(metadata) {
10906
- if (!metadata) {
10907
- return false;
10908
- }
10909
- return Object.values(metadata).some(
10910
- (value) => !EDITABLE_TYPES.includes(typeof value)
10911
- );
10912
- }
10913
- const PROMOTION_QUERY_KEY = "promotions";
10914
- const promotionsQueryKeys = {
10915
- list: (query2) => [
10916
- PROMOTION_QUERY_KEY,
10917
- query2 ? query2 : void 0
10918
- ],
10919
- detail: (id, query2) => [
10920
- PROMOTION_QUERY_KEY,
10921
- id,
10922
- query2 ? query2 : void 0
10923
- ]
10924
- };
10925
- const usePromotions = (query2, options) => {
10926
- const { data, ...rest } = useQuery({
10927
- queryKey: promotionsQueryKeys.list(query2),
10928
- queryFn: async () => sdk.admin.promotion.list(query2),
10929
- ...options
10930
- });
10931
- return { ...data, ...rest };
10932
- };
10933
- const Promotions = () => {
10934
- const { id } = useParams();
10935
- const {
10936
- order: preview,
10937
- isError: isPreviewError,
10938
- error: previewError
10939
- } = useOrderPreview(id, void 0);
10940
- useInitiateOrderEdit({ preview });
10941
- const { onCancel } = useCancelOrderEdit({ preview });
10942
- if (isPreviewError) {
10943
- throw previewError;
10944
- }
10945
- const isReady = !!preview;
10946
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10947
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10948
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10949
- ] });
10950
- };
10951
- const PromotionForm = ({ preview }) => {
10952
- const { items, shipping_methods } = preview;
10953
- const [isSubmitting, setIsSubmitting] = useState(false);
10954
- const [comboboxValue, setComboboxValue] = useState("");
10955
- const { handleSuccess } = useRouteModal();
10956
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10957
- const promoIds = getPromotionIds(items, shipping_methods);
10958
- const { promotions, isPending, isError, error } = usePromotions(
10959
- {
10960
- id: promoIds
10961
- },
10962
- {
10963
- enabled: !!promoIds.length
10964
- }
10965
- );
10966
- const comboboxData = useComboboxData({
10967
- queryKey: ["promotions", "combobox", promoIds],
10968
- queryFn: async (params) => {
10969
- return await sdk.admin.promotion.list({
10970
- ...params,
10971
- id: {
10972
- $nin: promoIds
10973
- }
10974
- });
10975
- },
10976
- getOptions: (data) => {
10977
- return data.promotions.map((promotion) => ({
10978
- label: promotion.code,
10979
- value: promotion.code
10980
- }));
10981
- }
10982
- });
10983
- const add = async (value) => {
10984
- if (!value) {
10985
- return;
10986
- }
10987
- addPromotions(
10988
- {
10989
- promo_codes: [value]
10990
- },
10991
- {
10992
- onError: (e) => {
10993
- toast.error(e.message);
10994
- comboboxData.onSearchValueChange("");
10995
- setComboboxValue("");
10996
- },
10997
- onSuccess: () => {
10998
- comboboxData.onSearchValueChange("");
10999
- setComboboxValue("");
11000
- }
11001
- }
11002
- );
11003
- };
11004
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11005
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11006
- const onSubmit = async () => {
11007
- setIsSubmitting(true);
11008
- let requestSucceeded = false;
11009
- await requestOrderEdit(void 0, {
11010
- onError: (e) => {
11011
- toast.error(e.message);
11012
- },
11013
- onSuccess: () => {
11014
- requestSucceeded = true;
11015
- }
11016
- });
11017
- if (!requestSucceeded) {
11018
- setIsSubmitting(false);
11019
- return;
11020
- }
11021
- await confirmOrderEdit(void 0, {
11022
- onError: (e) => {
11023
- toast.error(e.message);
11024
- },
11025
- onSuccess: () => {
11026
- handleSuccess();
11027
- },
11028
- onSettled: () => {
11029
- setIsSubmitting(false);
11030
- }
11031
- });
11032
- };
11033
- if (isError) {
11034
- throw error;
11035
- }
11036
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11037
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11038
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11039
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11040
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11041
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11044
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11045
+ /* @__PURE__ */ jsxs(
11046
+ DropdownMenu.Item,
11047
+ {
11048
+ className: "gap-x-2",
11049
+ onClick: () => deleteRow(index),
11050
+ children: [
11051
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11052
+ "Delete row"
11053
+ ]
11054
+ }
11055
+ )
11056
+ ] })
11057
+ ] })
11058
+ ] })
11059
+ },
11060
+ field.id
11061
+ );
11062
+ })
11063
+ ] }),
11064
+ 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." })
11042
11065
  ] }),
11043
- /* @__PURE__ */ jsx(
11044
- Combobox,
11045
- {
11046
- id: "promotion-combobox",
11047
- "aria-describedby": "promotion-combobox-hint",
11048
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11049
- fetchNextPage: comboboxData.fetchNextPage,
11050
- options: comboboxData.options,
11051
- onSearchValueChange: comboboxData.onSearchValueChange,
11052
- searchValue: comboboxData.searchValue,
11053
- disabled: comboboxData.disabled || isAddingPromotions,
11054
- onChange: add,
11055
- value: comboboxValue
11056
- }
11057
- )
11058
- ] }),
11059
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11060
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11061
- PromotionItem,
11062
- {
11063
- promotion,
11064
- orderId: preview.id,
11065
- isLoading: isPending
11066
- },
11067
- promotion.id
11068
- )) })
11069
- ] }) }),
11070
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11071
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11072
- /* @__PURE__ */ jsx(
11073
- Button,
11074
- {
11075
- size: "small",
11076
- type: "submit",
11077
- isLoading: isSubmitting || isAddingPromotions,
11078
- children: "Save"
11079
- }
11066
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11067
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11068
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11069
+ ] }) })
11070
+ ]
11071
+ }
11072
+ ) });
11073
+ };
11074
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11075
+ return /* @__PURE__ */ jsx(
11076
+ "input",
11077
+ {
11078
+ ref,
11079
+ ...props,
11080
+ autoComplete: "off",
11081
+ className: clx(
11082
+ "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",
11083
+ className
11080
11084
  )
11085
+ }
11086
+ );
11087
+ });
11088
+ GridInput.displayName = "MetadataForm.GridInput";
11089
+ const PlaceholderInner = () => {
11090
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11091
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11092
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11093
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11094
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11081
11095
  ] }) })
11082
11096
  ] });
11083
11097
  };
11084
- const PromotionItem = ({
11085
- promotion,
11086
- orderId,
11087
- isLoading
11088
- }) => {
11089
- var _a;
11090
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11091
- const onRemove = async () => {
11092
- removePromotions(
11093
- {
11094
- promo_codes: [promotion.code]
11095
- },
11098
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11099
+ function getDefaultValues(metadata) {
11100
+ if (!metadata || !Object.keys(metadata).length) {
11101
+ return [
11096
11102
  {
11097
- onError: (e) => {
11098
- toast.error(e.message);
11099
- }
11103
+ key: "",
11104
+ value: "",
11105
+ disabled: false
11100
11106
  }
11101
- );
11102
- };
11103
- const displayValue = getDisplayValue(promotion);
11104
- return /* @__PURE__ */ jsxs(
11105
- "div",
11106
- {
11107
- className: clx(
11108
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11109
- {
11110
- "animate-pulse": isLoading
11111
- }
11112
- ),
11113
- children: [
11114
- /* @__PURE__ */ jsxs("div", { children: [
11115
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11116
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11117
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11118
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11119
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11120
- ] }),
11121
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11122
- ] })
11123
- ] }),
11124
- /* @__PURE__ */ jsx(
11125
- IconButton,
11126
- {
11127
- size: "small",
11128
- type: "button",
11129
- variant: "transparent",
11130
- onClick: onRemove,
11131
- isLoading: isPending || isLoading,
11132
- children: /* @__PURE__ */ jsx(XMark, {})
11133
- }
11134
- )
11135
- ]
11136
- },
11137
- promotion.id
11138
- );
11139
- };
11140
- function getDisplayValue(promotion) {
11141
- var _a, _b, _c, _d;
11142
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11143
- if (!value) {
11144
- return null;
11107
+ ];
11145
11108
  }
11146
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11147
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11148
- if (!currency) {
11149
- return null;
11109
+ return Object.entries(metadata).map(([key, value]) => {
11110
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11111
+ return {
11112
+ key,
11113
+ value,
11114
+ disabled: true
11115
+ };
11150
11116
  }
11151
- return getLocaleAmount(value, currency);
11152
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11153
- return formatPercentage(value);
11154
- }
11155
- return null;
11117
+ let stringValue = value;
11118
+ if (typeof value !== "string") {
11119
+ stringValue = JSON.stringify(value);
11120
+ }
11121
+ return {
11122
+ key,
11123
+ value: stringValue,
11124
+ original_key: key
11125
+ };
11126
+ });
11156
11127
  }
11157
- const formatter = new Intl.NumberFormat([], {
11158
- style: "percent",
11159
- minimumFractionDigits: 2
11160
- });
11161
- const formatPercentage = (value, isPercentageValue = false) => {
11162
- let val = value || 0;
11163
- if (!isPercentageValue) {
11164
- val = val / 100;
11128
+ function parseValues(values) {
11129
+ const metadata = values.metadata;
11130
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11131
+ if (isEmpty) {
11132
+ return null;
11165
11133
  }
11166
- return formatter.format(val);
11167
- };
11168
- function getPromotionIds(items, shippingMethods) {
11169
- const promotionIds = /* @__PURE__ */ new Set();
11170
- for (const item of items) {
11171
- if (item.adjustments) {
11172
- for (const adjustment of item.adjustments) {
11173
- if (adjustment.promotion_id) {
11174
- promotionIds.add(adjustment.promotion_id);
11175
- }
11176
- }
11134
+ const update = {};
11135
+ metadata.forEach((field) => {
11136
+ let key = field.key;
11137
+ let value = field.value;
11138
+ const disabled = field.disabled;
11139
+ if (!key || !value) {
11140
+ return;
11177
11141
  }
11178
- }
11179
- for (const shippingMethod of shippingMethods) {
11180
- if (shippingMethod.adjustments) {
11181
- for (const adjustment of shippingMethod.adjustments) {
11182
- if (adjustment.promotion_id) {
11183
- promotionIds.add(adjustment.promotion_id);
11184
- }
11142
+ if (disabled) {
11143
+ update[key] = value;
11144
+ return;
11145
+ }
11146
+ key = key.trim();
11147
+ value = value.trim();
11148
+ if (value === "true") {
11149
+ update[key] = true;
11150
+ } else if (value === "false") {
11151
+ update[key] = false;
11152
+ } else {
11153
+ const parsedNumber = parseFloat(value);
11154
+ if (!isNaN(parsedNumber)) {
11155
+ update[key] = parsedNumber;
11156
+ } else {
11157
+ update[key] = value;
11185
11158
  }
11186
11159
  }
11160
+ });
11161
+ return update;
11162
+ }
11163
+ function getHasUneditableRows(metadata) {
11164
+ if (!metadata) {
11165
+ return false;
11187
11166
  }
11188
- return Array.from(promotionIds);
11167
+ return Object.values(metadata).some(
11168
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11169
+ );
11189
11170
  }
11190
- const SalesChannel = () => {
11171
+ const PROMOTION_QUERY_KEY = "promotions";
11172
+ const promotionsQueryKeys = {
11173
+ list: (query2) => [
11174
+ PROMOTION_QUERY_KEY,
11175
+ query2 ? query2 : void 0
11176
+ ],
11177
+ detail: (id, query2) => [
11178
+ PROMOTION_QUERY_KEY,
11179
+ id,
11180
+ query2 ? query2 : void 0
11181
+ ]
11182
+ };
11183
+ const usePromotions = (query2, options) => {
11184
+ const { data, ...rest } = useQuery({
11185
+ queryKey: promotionsQueryKeys.list(query2),
11186
+ queryFn: async () => sdk.admin.promotion.list(query2),
11187
+ ...options
11188
+ });
11189
+ return { ...data, ...rest };
11190
+ };
11191
+ const Promotions = () => {
11191
11192
  const { id } = useParams();
11192
- const { draft_order, isPending, isError, error } = useDraftOrder(
11193
- id,
11193
+ const {
11194
+ order: preview,
11195
+ isError: isPreviewError,
11196
+ error: previewError
11197
+ } = useOrderPreview(id, void 0);
11198
+ useInitiateOrderEdit({ preview });
11199
+ const { onCancel } = useCancelOrderEdit({ preview });
11200
+ if (isPreviewError) {
11201
+ throw previewError;
11202
+ }
11203
+ const isReady = !!preview;
11204
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11205
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11206
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11207
+ ] });
11208
+ };
11209
+ const PromotionForm = ({ preview }) => {
11210
+ const { items, shipping_methods } = preview;
11211
+ const [isSubmitting, setIsSubmitting] = useState(false);
11212
+ const [comboboxValue, setComboboxValue] = useState("");
11213
+ const { handleSuccess } = useRouteModal();
11214
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11215
+ const promoIds = getPromotionIds(items, shipping_methods);
11216
+ const { promotions, isPending, isError, error } = usePromotions(
11194
11217
  {
11195
- fields: "+sales_channel_id"
11218
+ id: promoIds
11196
11219
  },
11197
11220
  {
11198
- enabled: !!id
11221
+ enabled: !!promoIds.length
11199
11222
  }
11200
11223
  );
11201
- if (isError) {
11202
- throw error;
11203
- }
11204
- const ISrEADY = !!draft_order && !isPending;
11205
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11206
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11207
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11208
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11209
- ] }),
11210
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11211
- ] });
11212
- };
11213
- const SalesChannelForm = ({ order }) => {
11214
- const form = useForm({
11215
- defaultValues: {
11216
- sales_channel_id: order.sales_channel_id || ""
11224
+ const comboboxData = useComboboxData({
11225
+ queryKey: ["promotions", "combobox", promoIds],
11226
+ queryFn: async (params) => {
11227
+ return await sdk.admin.promotion.list({
11228
+ ...params,
11229
+ id: {
11230
+ $nin: promoIds
11231
+ }
11232
+ });
11217
11233
  },
11218
- resolver: zodResolver(schema$4)
11234
+ getOptions: (data) => {
11235
+ return data.promotions.map((promotion) => ({
11236
+ label: promotion.code,
11237
+ value: promotion.code
11238
+ }));
11239
+ }
11219
11240
  });
11220
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11221
- const { handleSuccess } = useRouteModal();
11222
- const onSubmit = form.handleSubmit(async (data) => {
11223
- await mutateAsync(
11241
+ const add = async (value) => {
11242
+ if (!value) {
11243
+ return;
11244
+ }
11245
+ addPromotions(
11224
11246
  {
11225
- sales_channel_id: data.sales_channel_id
11247
+ promo_codes: [value]
11226
11248
  },
11227
11249
  {
11228
- onSuccess: () => {
11229
- toast.success("Sales channel updated");
11230
- handleSuccess();
11250
+ onError: (e) => {
11251
+ toast.error(e.message);
11252
+ comboboxData.onSearchValueChange("");
11253
+ setComboboxValue("");
11231
11254
  },
11232
- onError: (error) => {
11233
- toast.error(error.message);
11255
+ onSuccess: () => {
11256
+ comboboxData.onSearchValueChange("");
11257
+ setComboboxValue("");
11234
11258
  }
11235
11259
  }
11236
11260
  );
11237
- });
11238
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11239
- KeyboundForm,
11240
- {
11241
- className: "flex flex-1 flex-col overflow-hidden",
11242
- onSubmit,
11243
- children: [
11244
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11245
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11246
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11247
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11248
- ] }) })
11249
- ]
11250
- }
11251
- ) });
11252
- };
11253
- const SalesChannelField = ({ control, order }) => {
11254
- const salesChannels = useComboboxData({
11255
- queryFn: async (params) => {
11256
- return await sdk.admin.salesChannel.list(params);
11257
- },
11258
- queryKey: ["sales-channels"],
11259
- getOptions: (data) => {
11260
- return data.sales_channels.map((salesChannel) => ({
11261
- label: salesChannel.name,
11262
- value: salesChannel.id
11263
- }));
11264
- },
11265
- defaultValue: order.sales_channel_id || void 0
11266
- });
11267
- return /* @__PURE__ */ jsx(
11268
- Form$2.Field,
11269
- {
11270
- control,
11271
- name: "sales_channel_id",
11272
- render: ({ field }) => {
11273
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11274
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11275
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11276
- Combobox,
11277
- {
11278
- options: salesChannels.options,
11279
- fetchNextPage: salesChannels.fetchNextPage,
11280
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11281
- searchValue: salesChannels.searchValue,
11282
- onSearchValueChange: salesChannels.onSearchValueChange,
11283
- placeholder: "Select sales channel",
11284
- ...field
11285
- }
11286
- ) }),
11287
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11288
- ] });
11261
+ };
11262
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11263
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11264
+ const onSubmit = async () => {
11265
+ setIsSubmitting(true);
11266
+ let requestSucceeded = false;
11267
+ await requestOrderEdit(void 0, {
11268
+ onError: (e) => {
11269
+ toast.error(e.message);
11270
+ },
11271
+ onSuccess: () => {
11272
+ requestSucceeded = true;
11289
11273
  }
11274
+ });
11275
+ if (!requestSucceeded) {
11276
+ setIsSubmitting(false);
11277
+ return;
11290
11278
  }
11291
- );
11292
- };
11293
- const schema$4 = objectType({
11294
- sales_channel_id: stringType().min(1)
11295
- });
11296
- const ShippingAddress = () => {
11297
- const { id } = useParams();
11298
- const { order, isPending, isError, error } = useOrder(id, {
11299
- fields: "+shipping_address"
11300
- });
11279
+ await confirmOrderEdit(void 0, {
11280
+ onError: (e) => {
11281
+ toast.error(e.message);
11282
+ },
11283
+ onSuccess: () => {
11284
+ handleSuccess();
11285
+ },
11286
+ onSettled: () => {
11287
+ setIsSubmitting(false);
11288
+ }
11289
+ });
11290
+ };
11301
11291
  if (isError) {
11302
11292
  throw error;
11303
11293
  }
11304
- const isReady = !isPending && !!order;
11305
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11306
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11307
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11308
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11309
- ] }),
11310
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11311
- ] });
11312
- };
11313
- const ShippingAddressForm = ({ order }) => {
11314
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11315
- const form = useForm({
11316
- defaultValues: {
11317
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11318
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11319
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11320
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11321
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11322
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11323
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11324
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11325
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11326
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11327
- },
11328
- resolver: zodResolver(schema$3)
11329
- });
11330
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11331
- const { handleSuccess } = useRouteModal();
11332
- const onSubmit = form.handleSubmit(async (data) => {
11333
- await mutateAsync(
11334
- {
11335
- shipping_address: {
11336
- first_name: data.first_name,
11337
- last_name: data.last_name,
11338
- company: data.company,
11339
- address_1: data.address_1,
11340
- address_2: data.address_2,
11341
- city: data.city,
11342
- province: data.province,
11343
- country_code: data.country_code,
11344
- postal_code: data.postal_code,
11345
- phone: data.phone
11294
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11295
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11296
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11297
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11298
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11299
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11300
+ ] }),
11301
+ /* @__PURE__ */ jsx(
11302
+ Combobox,
11303
+ {
11304
+ id: "promotion-combobox",
11305
+ "aria-describedby": "promotion-combobox-hint",
11306
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11307
+ fetchNextPage: comboboxData.fetchNextPage,
11308
+ options: comboboxData.options,
11309
+ onSearchValueChange: comboboxData.onSearchValueChange,
11310
+ searchValue: comboboxData.searchValue,
11311
+ disabled: comboboxData.disabled || isAddingPromotions,
11312
+ onChange: add,
11313
+ value: comboboxValue
11314
+ }
11315
+ )
11316
+ ] }),
11317
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11318
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11319
+ PromotionItem,
11320
+ {
11321
+ promotion,
11322
+ orderId: preview.id,
11323
+ isLoading: isPending
11324
+ },
11325
+ promotion.id
11326
+ )) })
11327
+ ] }) }),
11328
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11329
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11330
+ /* @__PURE__ */ jsx(
11331
+ Button,
11332
+ {
11333
+ size: "small",
11334
+ type: "submit",
11335
+ isLoading: isSubmitting || isAddingPromotions,
11336
+ children: "Save"
11346
11337
  }
11338
+ )
11339
+ ] }) })
11340
+ ] });
11341
+ };
11342
+ const PromotionItem = ({
11343
+ promotion,
11344
+ orderId,
11345
+ isLoading
11346
+ }) => {
11347
+ var _a;
11348
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11349
+ const onRemove = async () => {
11350
+ removePromotions(
11351
+ {
11352
+ promo_codes: [promotion.code]
11347
11353
  },
11348
11354
  {
11349
- onSuccess: () => {
11350
- handleSuccess();
11351
- },
11352
- onError: (error) => {
11353
- toast.error(error.message);
11355
+ onError: (e) => {
11356
+ toast.error(e.message);
11354
11357
  }
11355
11358
  }
11356
11359
  );
11357
- });
11358
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11359
- KeyboundForm,
11360
+ };
11361
+ const displayValue = getDisplayValue(promotion);
11362
+ return /* @__PURE__ */ jsxs(
11363
+ "div",
11360
11364
  {
11361
- className: "flex flex-1 flex-col overflow-hidden",
11362
- onSubmit,
11365
+ className: clx(
11366
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11367
+ {
11368
+ "animate-pulse": isLoading
11369
+ }
11370
+ ),
11363
11371
  children: [
11364
- /* @__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: [
11365
- /* @__PURE__ */ jsx(
11366
- Form$2.Field,
11367
- {
11368
- control: form.control,
11369
- name: "country_code",
11370
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11371
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11372
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11373
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11374
- ] })
11375
- }
11376
- ),
11377
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11378
- /* @__PURE__ */ jsx(
11379
- Form$2.Field,
11380
- {
11381
- control: form.control,
11382
- name: "first_name",
11383
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11384
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11385
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11386
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11387
- ] })
11388
- }
11389
- ),
11390
- /* @__PURE__ */ jsx(
11391
- Form$2.Field,
11392
- {
11393
- control: form.control,
11394
- name: "last_name",
11395
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11396
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11397
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11398
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11399
- ] })
11400
- }
11401
- )
11402
- ] }),
11403
- /* @__PURE__ */ jsx(
11404
- Form$2.Field,
11405
- {
11406
- control: form.control,
11407
- name: "company",
11408
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11409
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11410
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11411
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11412
- ] })
11413
- }
11414
- ),
11415
- /* @__PURE__ */ jsx(
11416
- Form$2.Field,
11417
- {
11418
- control: form.control,
11419
- name: "address_1",
11420
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11421
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11422
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11423
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11424
- ] })
11425
- }
11426
- ),
11427
- /* @__PURE__ */ jsx(
11428
- Form$2.Field,
11429
- {
11430
- control: form.control,
11431
- name: "address_2",
11432
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11433
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11434
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11435
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11436
- ] })
11437
- }
11438
- ),
11439
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11440
- /* @__PURE__ */ jsx(
11441
- Form$2.Field,
11442
- {
11443
- control: form.control,
11444
- name: "postal_code",
11445
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11446
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11447
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11448
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11449
- ] })
11450
- }
11451
- ),
11452
- /* @__PURE__ */ jsx(
11453
- Form$2.Field,
11454
- {
11455
- control: form.control,
11456
- name: "city",
11457
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11458
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11459
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11460
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11461
- ] })
11462
- }
11463
- )
11464
- ] }),
11465
- /* @__PURE__ */ jsx(
11466
- Form$2.Field,
11467
- {
11468
- control: form.control,
11469
- name: "province",
11470
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11471
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11472
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11473
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11474
- ] })
11475
- }
11476
- ),
11477
- /* @__PURE__ */ jsx(
11478
- Form$2.Field,
11479
- {
11480
- control: form.control,
11481
- name: "phone",
11482
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11483
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11484
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11485
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11486
- ] })
11487
- }
11488
- )
11489
- ] }) }),
11372
+ /* @__PURE__ */ jsxs("div", { children: [
11373
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11374
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11375
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11376
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11377
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11378
+ ] }),
11379
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11380
+ ] })
11381
+ ] }),
11382
+ /* @__PURE__ */ jsx(
11383
+ IconButton,
11384
+ {
11385
+ size: "small",
11386
+ type: "button",
11387
+ variant: "transparent",
11388
+ onClick: onRemove,
11389
+ isLoading: isPending || isLoading,
11390
+ children: /* @__PURE__ */ jsx(XMark, {})
11391
+ }
11392
+ )
11393
+ ]
11394
+ },
11395
+ promotion.id
11396
+ );
11397
+ };
11398
+ function getDisplayValue(promotion) {
11399
+ var _a, _b, _c, _d;
11400
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11401
+ if (!value) {
11402
+ return null;
11403
+ }
11404
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11405
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11406
+ if (!currency) {
11407
+ return null;
11408
+ }
11409
+ return getLocaleAmount(value, currency);
11410
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11411
+ return formatPercentage(value);
11412
+ }
11413
+ return null;
11414
+ }
11415
+ const formatter = new Intl.NumberFormat([], {
11416
+ style: "percent",
11417
+ minimumFractionDigits: 2
11418
+ });
11419
+ const formatPercentage = (value, isPercentageValue = false) => {
11420
+ let val = value || 0;
11421
+ if (!isPercentageValue) {
11422
+ val = val / 100;
11423
+ }
11424
+ return formatter.format(val);
11425
+ };
11426
+ function getPromotionIds(items, shippingMethods) {
11427
+ const promotionIds = /* @__PURE__ */ new Set();
11428
+ for (const item of items) {
11429
+ if (item.adjustments) {
11430
+ for (const adjustment of item.adjustments) {
11431
+ if (adjustment.promotion_id) {
11432
+ promotionIds.add(adjustment.promotion_id);
11433
+ }
11434
+ }
11435
+ }
11436
+ }
11437
+ for (const shippingMethod of shippingMethods) {
11438
+ if (shippingMethod.adjustments) {
11439
+ for (const adjustment of shippingMethod.adjustments) {
11440
+ if (adjustment.promotion_id) {
11441
+ promotionIds.add(adjustment.promotion_id);
11442
+ }
11443
+ }
11444
+ }
11445
+ }
11446
+ return Array.from(promotionIds);
11447
+ }
11448
+ const SalesChannel = () => {
11449
+ const { id } = useParams();
11450
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11451
+ id,
11452
+ {
11453
+ fields: "+sales_channel_id"
11454
+ },
11455
+ {
11456
+ enabled: !!id
11457
+ }
11458
+ );
11459
+ if (isError) {
11460
+ throw error;
11461
+ }
11462
+ const ISrEADY = !!draft_order && !isPending;
11463
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11464
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11465
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11466
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11467
+ ] }),
11468
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11469
+ ] });
11470
+ };
11471
+ const SalesChannelForm = ({ order }) => {
11472
+ const form = useForm({
11473
+ defaultValues: {
11474
+ sales_channel_id: order.sales_channel_id || ""
11475
+ },
11476
+ resolver: zodResolver(schema$2)
11477
+ });
11478
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11479
+ const { handleSuccess } = useRouteModal();
11480
+ const onSubmit = form.handleSubmit(async (data) => {
11481
+ await mutateAsync(
11482
+ {
11483
+ sales_channel_id: data.sales_channel_id
11484
+ },
11485
+ {
11486
+ onSuccess: () => {
11487
+ toast.success("Sales channel updated");
11488
+ handleSuccess();
11489
+ },
11490
+ onError: (error) => {
11491
+ toast.error(error.message);
11492
+ }
11493
+ }
11494
+ );
11495
+ });
11496
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11497
+ KeyboundForm,
11498
+ {
11499
+ className: "flex flex-1 flex-col overflow-hidden",
11500
+ onSubmit,
11501
+ children: [
11502
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11490
11503
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11491
11504
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11492
11505
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11495,7 +11508,49 @@ const ShippingAddressForm = ({ order }) => {
11495
11508
  }
11496
11509
  ) });
11497
11510
  };
11498
- const schema$3 = addressSchema;
11511
+ const SalesChannelField = ({ control, order }) => {
11512
+ const salesChannels = useComboboxData({
11513
+ queryFn: async (params) => {
11514
+ return await sdk.admin.salesChannel.list(params);
11515
+ },
11516
+ queryKey: ["sales-channels"],
11517
+ getOptions: (data) => {
11518
+ return data.sales_channels.map((salesChannel) => ({
11519
+ label: salesChannel.name,
11520
+ value: salesChannel.id
11521
+ }));
11522
+ },
11523
+ defaultValue: order.sales_channel_id || void 0
11524
+ });
11525
+ return /* @__PURE__ */ jsx(
11526
+ Form$2.Field,
11527
+ {
11528
+ control,
11529
+ name: "sales_channel_id",
11530
+ render: ({ field }) => {
11531
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11532
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11533
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11534
+ Combobox,
11535
+ {
11536
+ options: salesChannels.options,
11537
+ fetchNextPage: salesChannels.fetchNextPage,
11538
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11539
+ searchValue: salesChannels.searchValue,
11540
+ onSearchValueChange: salesChannels.onSearchValueChange,
11541
+ placeholder: "Select sales channel",
11542
+ ...field
11543
+ }
11544
+ ) }),
11545
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11546
+ ] });
11547
+ }
11548
+ }
11549
+ );
11550
+ };
11551
+ const schema$2 = objectType({
11552
+ sales_channel_id: stringType().min(1)
11553
+ });
11499
11554
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11500
11555
  const Shipping = () => {
11501
11556
  var _a;
@@ -12250,59 +12305,262 @@ const ShippingOptionField = ({
12250
12305
  /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12251
12306
  ] }),
12252
12307
  /* @__PURE__ */ jsx(
12253
- ConditionalTooltip,
12308
+ ConditionalTooltip,
12309
+ {
12310
+ content: tooltipContent,
12311
+ showTooltip: !locationId || !shippingProfileId,
12312
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12313
+ Combobox,
12314
+ {
12315
+ options: shippingOptions.options,
12316
+ fetchNextPage: shippingOptions.fetchNextPage,
12317
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12318
+ searchValue: shippingOptions.searchValue,
12319
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12320
+ placeholder: "Select shipping option",
12321
+ ...field,
12322
+ disabled: !locationId || !shippingProfileId
12323
+ }
12324
+ ) }) })
12325
+ }
12326
+ )
12327
+ ] }) });
12328
+ }
12329
+ }
12330
+ );
12331
+ };
12332
+ const CustomAmountField = ({
12333
+ control,
12334
+ currencyCode
12335
+ }) => {
12336
+ return /* @__PURE__ */ jsx(
12337
+ Form$2.Field,
12338
+ {
12339
+ control,
12340
+ name: "custom_amount",
12341
+ render: ({ field: { onChange, ...field } }) => {
12342
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12343
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12345
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12346
+ ] }),
12347
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12348
+ CurrencyInput,
12349
+ {
12350
+ ...field,
12351
+ onValueChange: (value) => onChange(value),
12352
+ symbol: getNativeSymbol(currencyCode),
12353
+ code: currencyCode
12354
+ }
12355
+ ) })
12356
+ ] });
12357
+ }
12358
+ }
12359
+ );
12360
+ };
12361
+ const ShippingAddress = () => {
12362
+ const { id } = useParams();
12363
+ const { order, isPending, isError, error } = useOrder(id, {
12364
+ fields: "+shipping_address"
12365
+ });
12366
+ if (isError) {
12367
+ throw error;
12368
+ }
12369
+ const isReady = !isPending && !!order;
12370
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12371
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12372
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12373
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12374
+ ] }),
12375
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12376
+ ] });
12377
+ };
12378
+ const ShippingAddressForm = ({ order }) => {
12379
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12380
+ const form = useForm({
12381
+ defaultValues: {
12382
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12383
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12384
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12385
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12386
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12387
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12388
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12389
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12390
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12391
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12392
+ },
12393
+ resolver: zodResolver(schema$1)
12394
+ });
12395
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12396
+ const { handleSuccess } = useRouteModal();
12397
+ const onSubmit = form.handleSubmit(async (data) => {
12398
+ await mutateAsync(
12399
+ {
12400
+ shipping_address: {
12401
+ first_name: data.first_name,
12402
+ last_name: data.last_name,
12403
+ company: data.company,
12404
+ address_1: data.address_1,
12405
+ address_2: data.address_2,
12406
+ city: data.city,
12407
+ province: data.province,
12408
+ country_code: data.country_code,
12409
+ postal_code: data.postal_code,
12410
+ phone: data.phone
12411
+ }
12412
+ },
12413
+ {
12414
+ onSuccess: () => {
12415
+ handleSuccess();
12416
+ },
12417
+ onError: (error) => {
12418
+ toast.error(error.message);
12419
+ }
12420
+ }
12421
+ );
12422
+ });
12423
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12424
+ KeyboundForm,
12425
+ {
12426
+ className: "flex flex-1 flex-col overflow-hidden",
12427
+ onSubmit,
12428
+ children: [
12429
+ /* @__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: [
12430
+ /* @__PURE__ */ jsx(
12431
+ Form$2.Field,
12432
+ {
12433
+ control: form.control,
12434
+ name: "country_code",
12435
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12436
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12437
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12438
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12439
+ ] })
12440
+ }
12441
+ ),
12442
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12443
+ /* @__PURE__ */ jsx(
12444
+ Form$2.Field,
12445
+ {
12446
+ control: form.control,
12447
+ name: "first_name",
12448
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12449
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12450
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12451
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12452
+ ] })
12453
+ }
12454
+ ),
12455
+ /* @__PURE__ */ jsx(
12456
+ Form$2.Field,
12457
+ {
12458
+ control: form.control,
12459
+ name: "last_name",
12460
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12461
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12462
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12463
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12464
+ ] })
12465
+ }
12466
+ )
12467
+ ] }),
12468
+ /* @__PURE__ */ jsx(
12469
+ Form$2.Field,
12254
12470
  {
12255
- content: tooltipContent,
12256
- showTooltip: !locationId || !shippingProfileId,
12257
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12258
- Combobox,
12259
- {
12260
- options: shippingOptions.options,
12261
- fetchNextPage: shippingOptions.fetchNextPage,
12262
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12263
- searchValue: shippingOptions.searchValue,
12264
- onSearchValueChange: shippingOptions.onSearchValueChange,
12265
- placeholder: "Select shipping option",
12266
- ...field,
12267
- disabled: !locationId || !shippingProfileId
12268
- }
12269
- ) }) })
12471
+ control: form.control,
12472
+ name: "company",
12473
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12474
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12475
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12476
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12477
+ ] })
12270
12478
  }
12271
- )
12272
- ] }) });
12273
- }
12274
- }
12275
- );
12276
- };
12277
- const CustomAmountField = ({
12278
- control,
12279
- currencyCode
12280
- }) => {
12281
- return /* @__PURE__ */ jsx(
12282
- Form$2.Field,
12283
- {
12284
- control,
12285
- name: "custom_amount",
12286
- render: ({ field: { onChange, ...field } }) => {
12287
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12288
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12289
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12290
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12479
+ ),
12480
+ /* @__PURE__ */ jsx(
12481
+ Form$2.Field,
12482
+ {
12483
+ control: form.control,
12484
+ name: "address_1",
12485
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12486
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12487
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12488
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12489
+ ] })
12490
+ }
12491
+ ),
12492
+ /* @__PURE__ */ jsx(
12493
+ Form$2.Field,
12494
+ {
12495
+ control: form.control,
12496
+ name: "address_2",
12497
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12498
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12499
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12500
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12501
+ ] })
12502
+ }
12503
+ ),
12504
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12505
+ /* @__PURE__ */ jsx(
12506
+ Form$2.Field,
12507
+ {
12508
+ control: form.control,
12509
+ name: "postal_code",
12510
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12511
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12512
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12513
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12514
+ ] })
12515
+ }
12516
+ ),
12517
+ /* @__PURE__ */ jsx(
12518
+ Form$2.Field,
12519
+ {
12520
+ control: form.control,
12521
+ name: "city",
12522
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12523
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12524
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12525
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12526
+ ] })
12527
+ }
12528
+ )
12291
12529
  ] }),
12292
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12293
- CurrencyInput,
12530
+ /* @__PURE__ */ jsx(
12531
+ Form$2.Field,
12294
12532
  {
12295
- ...field,
12296
- onValueChange: (value) => onChange(value),
12297
- symbol: getNativeSymbol(currencyCode),
12298
- code: currencyCode
12533
+ control: form.control,
12534
+ name: "province",
12535
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12536
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12537
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12538
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12539
+ ] })
12299
12540
  }
12300
- ) })
12301
- ] });
12302
- }
12541
+ ),
12542
+ /* @__PURE__ */ jsx(
12543
+ Form$2.Field,
12544
+ {
12545
+ control: form.control,
12546
+ name: "phone",
12547
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12548
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12549
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12550
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12551
+ ] })
12552
+ }
12553
+ )
12554
+ ] }) }),
12555
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12556
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12557
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12558
+ ] }) })
12559
+ ]
12303
12560
  }
12304
- );
12561
+ ) });
12305
12562
  };
12563
+ const schema$1 = addressSchema;
12306
12564
  const TransferOwnership = () => {
12307
12565
  const { id } = useParams();
12308
12566
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12326,7 +12584,7 @@ const TransferOwnershipForm = ({ order }) => {
12326
12584
  defaultValues: {
12327
12585
  customer_id: order.customer_id || ""
12328
12586
  },
12329
- resolver: zodResolver(schema$2)
12587
+ resolver: zodResolver(schema)
12330
12588
  });
12331
12589
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12332
12590
  const { handleSuccess } = useRouteModal();
@@ -12713,330 +12971,72 @@ const Illustration = () => {
12713
12971
  stroke: "#A1A1AA",
12714
12972
  strokeWidth: "1.5",
12715
12973
  strokeLinecap: "round",
12716
- strokeLinejoin: "round"
12717
- }
12718
- ) }),
12719
- /* @__PURE__ */ jsxs("defs", { children: [
12720
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12721
- "rect",
12722
- {
12723
- width: "12",
12724
- height: "12",
12725
- fill: "white",
12726
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12727
- }
12728
- ) }),
12729
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12730
- "rect",
12731
- {
12732
- width: "12",
12733
- height: "12",
12734
- fill: "white",
12735
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12736
- }
12737
- ) }),
12738
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12739
- "rect",
12740
- {
12741
- width: "12",
12742
- height: "12",
12743
- fill: "white",
12744
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12745
- }
12746
- ) }),
12747
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12748
- "rect",
12749
- {
12750
- width: "12",
12751
- height: "12",
12752
- fill: "white",
12753
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12754
- }
12755
- ) }),
12756
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12757
- "rect",
12758
- {
12759
- width: "12",
12760
- height: "12",
12761
- fill: "white",
12762
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12763
- }
12764
- ) }),
12765
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12766
- "rect",
12767
- {
12768
- width: "12",
12769
- height: "12",
12770
- fill: "white",
12771
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12772
- }
12773
- ) })
12774
- ] })
12775
- ]
12776
- }
12777
- );
12778
- };
12779
- const schema$2 = objectType({
12780
- customer_id: stringType().min(1)
12781
- });
12782
- const Email = () => {
12783
- const { id } = useParams();
12784
- const { order, isPending, isError, error } = useOrder(id, {
12785
- fields: "+email"
12786
- });
12787
- if (isError) {
12788
- throw error;
12789
- }
12790
- const isReady = !isPending && !!order;
12791
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12792
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12793
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12794
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12795
- ] }),
12796
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12797
- ] });
12798
- };
12799
- const EmailForm = ({ order }) => {
12800
- const form = useForm({
12801
- defaultValues: {
12802
- email: order.email ?? ""
12803
- },
12804
- resolver: zodResolver(schema$1)
12805
- });
12806
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12807
- const { handleSuccess } = useRouteModal();
12808
- const onSubmit = form.handleSubmit(async (data) => {
12809
- await mutateAsync(
12810
- { email: data.email },
12811
- {
12812
- onSuccess: () => {
12813
- handleSuccess();
12814
- },
12815
- onError: (error) => {
12816
- toast.error(error.message);
12817
- }
12818
- }
12819
- );
12820
- });
12821
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12822
- KeyboundForm,
12823
- {
12824
- className: "flex flex-1 flex-col overflow-hidden",
12825
- onSubmit,
12826
- children: [
12827
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
12828
- Form$2.Field,
12829
- {
12830
- control: form.control,
12831
- name: "email",
12832
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12833
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
12834
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12835
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12836
- ] })
12974
+ strokeLinejoin: "round"
12837
12975
  }
12838
12976
  ) }),
12839
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12840
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12841
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12842
- ] }) })
12843
- ]
12844
- }
12845
- ) });
12846
- };
12847
- const schema$1 = objectType({
12848
- email: stringType().email()
12849
- });
12850
- const BillingAddress = () => {
12851
- const { id } = useParams();
12852
- const { order, isPending, isError, error } = useOrder(id, {
12853
- fields: "+billing_address"
12854
- });
12855
- if (isError) {
12856
- throw error;
12857
- }
12858
- const isReady = !isPending && !!order;
12859
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12860
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12861
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12862
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12863
- ] }),
12864
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12865
- ] });
12866
- };
12867
- const BillingAddressForm = ({ order }) => {
12868
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12869
- const form = useForm({
12870
- defaultValues: {
12871
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12872
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12873
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12874
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12875
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12876
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12877
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12878
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12879
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12880
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12881
- },
12882
- resolver: zodResolver(schema)
12883
- });
12884
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12885
- const { handleSuccess } = useRouteModal();
12886
- const onSubmit = form.handleSubmit(async (data) => {
12887
- await mutateAsync(
12888
- { billing_address: data },
12889
- {
12890
- onSuccess: () => {
12891
- handleSuccess();
12892
- },
12893
- onError: (error) => {
12894
- toast.error(error.message);
12895
- }
12896
- }
12897
- );
12898
- });
12899
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12900
- KeyboundForm,
12901
- {
12902
- className: "flex flex-1 flex-col overflow-hidden",
12903
- onSubmit,
12904
- children: [
12905
- /* @__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: [
12906
- /* @__PURE__ */ jsx(
12907
- Form$2.Field,
12977
+ /* @__PURE__ */ jsxs("defs", { children: [
12978
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12979
+ "rect",
12908
12980
  {
12909
- control: form.control,
12910
- name: "country_code",
12911
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12912
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12913
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12914
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12915
- ] })
12981
+ width: "12",
12982
+ height: "12",
12983
+ fill: "white",
12984
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12916
12985
  }
12917
- ),
12918
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12919
- /* @__PURE__ */ jsx(
12920
- Form$2.Field,
12921
- {
12922
- control: form.control,
12923
- name: "first_name",
12924
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12925
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12926
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12927
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12928
- ] })
12929
- }
12930
- ),
12931
- /* @__PURE__ */ jsx(
12932
- Form$2.Field,
12933
- {
12934
- control: form.control,
12935
- name: "last_name",
12936
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12937
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12938
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12939
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12940
- ] })
12941
- }
12942
- )
12943
- ] }),
12944
- /* @__PURE__ */ jsx(
12945
- Form$2.Field,
12986
+ ) }),
12987
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12988
+ "rect",
12946
12989
  {
12947
- control: form.control,
12948
- name: "company",
12949
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12950
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12951
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12952
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12953
- ] })
12990
+ width: "12",
12991
+ height: "12",
12992
+ fill: "white",
12993
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12954
12994
  }
12955
- ),
12956
- /* @__PURE__ */ jsx(
12957
- Form$2.Field,
12995
+ ) }),
12996
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12997
+ "rect",
12958
12998
  {
12959
- control: form.control,
12960
- name: "address_1",
12961
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12962
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12963
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12964
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12965
- ] })
12999
+ width: "12",
13000
+ height: "12",
13001
+ fill: "white",
13002
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12966
13003
  }
12967
- ),
12968
- /* @__PURE__ */ jsx(
12969
- Form$2.Field,
13004
+ ) }),
13005
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13006
+ "rect",
12970
13007
  {
12971
- control: form.control,
12972
- name: "address_2",
12973
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12974
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12975
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12976
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12977
- ] })
13008
+ width: "12",
13009
+ height: "12",
13010
+ fill: "white",
13011
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12978
13012
  }
12979
- ),
12980
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12981
- /* @__PURE__ */ jsx(
12982
- Form$2.Field,
12983
- {
12984
- control: form.control,
12985
- name: "postal_code",
12986
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12987
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12988
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12989
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12990
- ] })
12991
- }
12992
- ),
12993
- /* @__PURE__ */ jsx(
12994
- Form$2.Field,
12995
- {
12996
- control: form.control,
12997
- name: "city",
12998
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12999
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13000
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13001
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13002
- ] })
13003
- }
13004
- )
13005
- ] }),
13006
- /* @__PURE__ */ jsx(
13007
- Form$2.Field,
13013
+ ) }),
13014
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13015
+ "rect",
13008
13016
  {
13009
- control: form.control,
13010
- name: "province",
13011
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13012
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13013
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13014
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13015
- ] })
13017
+ width: "12",
13018
+ height: "12",
13019
+ fill: "white",
13020
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13016
13021
  }
13017
- ),
13018
- /* @__PURE__ */ jsx(
13019
- Form$2.Field,
13022
+ ) }),
13023
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13024
+ "rect",
13020
13025
  {
13021
- control: form.control,
13022
- name: "phone",
13023
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13024
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13025
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13026
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13027
- ] })
13026
+ width: "12",
13027
+ height: "12",
13028
+ fill: "white",
13029
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13028
13030
  }
13029
- )
13030
- ] }) }),
13031
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13032
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13033
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13034
- ] }) })
13031
+ ) })
13032
+ ] })
13035
13033
  ]
13036
13034
  }
13037
- ) });
13035
+ );
13038
13036
  };
13039
- const schema = addressSchema;
13037
+ const schema = objectType({
13038
+ customer_id: stringType().min(1)
13039
+ });
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13061,6 +13061,14 @@ const routeModule = {
13061
13061
  Component: CustomItems,
13062
13062
  path: "/draft-orders/:id/custom-items"
13063
13063
  },
13064
+ {
13065
+ Component: Email,
13066
+ path: "/draft-orders/:id/email"
13067
+ },
13068
+ {
13069
+ Component: BillingAddress,
13070
+ path: "/draft-orders/:id/billing-address"
13071
+ },
13064
13072
  {
13065
13073
  Component: Items,
13066
13074
  path: "/draft-orders/:id/items"
@@ -13077,25 +13085,17 @@ const routeModule = {
13077
13085
  Component: SalesChannel,
13078
13086
  path: "/draft-orders/:id/sales-channel"
13079
13087
  },
13080
- {
13081
- Component: ShippingAddress,
13082
- path: "/draft-orders/:id/shipping-address"
13083
- },
13084
13088
  {
13085
13089
  Component: Shipping,
13086
13090
  path: "/draft-orders/:id/shipping"
13087
13091
  },
13088
13092
  {
13089
- Component: TransferOwnership,
13090
- path: "/draft-orders/:id/transfer-ownership"
13091
- },
13092
- {
13093
- Component: Email,
13094
- path: "/draft-orders/:id/email"
13093
+ Component: ShippingAddress,
13094
+ path: "/draft-orders/:id/shipping-address"
13095
13095
  },
13096
13096
  {
13097
- Component: BillingAddress,
13098
- path: "/draft-orders/:id/billing-address"
13097
+ Component: TransferOwnership,
13098
+ path: "/draft-orders/:id/transfer-ownership"
13099
13099
  }
13100
13100
  ]
13101
13101
  }