@medusajs/draft-order 2.10.4-preview-20251005180152 → 2.10.4-preview-20251005210149

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.
@@ -9573,6 +9573,196 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
+ const BillingAddress = () => {
9577
+ const { id } = reactRouterDom.useParams();
9578
+ const { order, isPending, isError, error } = useOrder(id, {
9579
+ fields: "+billing_address"
9580
+ });
9581
+ if (isError) {
9582
+ throw error;
9583
+ }
9584
+ const isReady = !isPending && !!order;
9585
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9589
+ ] }),
9590
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9591
+ ] });
9592
+ };
9593
+ const BillingAddressForm = ({ order }) => {
9594
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9595
+ const form = reactHookForm.useForm({
9596
+ defaultValues: {
9597
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9598
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9599
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9600
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9601
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9602
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9603
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9604
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9605
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9607
+ },
9608
+ resolver: zod.zodResolver(schema$5)
9609
+ });
9610
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
+ const { handleSuccess } = useRouteModal();
9612
+ const onSubmit = form.handleSubmit(async (data) => {
9613
+ await mutateAsync(
9614
+ { billing_address: data },
9615
+ {
9616
+ onSuccess: () => {
9617
+ handleSuccess();
9618
+ },
9619
+ onError: (error) => {
9620
+ ui.toast.error(error.message);
9621
+ }
9622
+ }
9623
+ );
9624
+ });
9625
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9626
+ KeyboundForm,
9627
+ {
9628
+ className: "flex flex-1 flex-col overflow-hidden",
9629
+ onSubmit,
9630
+ children: [
9631
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9632
+ /* @__PURE__ */ jsxRuntime.jsx(
9633
+ Form$2.Field,
9634
+ {
9635
+ control: form.control,
9636
+ name: "country_code",
9637
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9639
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9640
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9641
+ ] })
9642
+ }
9643
+ ),
9644
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9645
+ /* @__PURE__ */ jsxRuntime.jsx(
9646
+ Form$2.Field,
9647
+ {
9648
+ control: form.control,
9649
+ name: "first_name",
9650
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9652
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9653
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9654
+ ] })
9655
+ }
9656
+ ),
9657
+ /* @__PURE__ */ jsxRuntime.jsx(
9658
+ Form$2.Field,
9659
+ {
9660
+ control: form.control,
9661
+ name: "last_name",
9662
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9664
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9665
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9666
+ ] })
9667
+ }
9668
+ )
9669
+ ] }),
9670
+ /* @__PURE__ */ jsxRuntime.jsx(
9671
+ Form$2.Field,
9672
+ {
9673
+ control: form.control,
9674
+ name: "company",
9675
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9677
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9678
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9679
+ ] })
9680
+ }
9681
+ ),
9682
+ /* @__PURE__ */ jsxRuntime.jsx(
9683
+ Form$2.Field,
9684
+ {
9685
+ control: form.control,
9686
+ name: "address_1",
9687
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9689
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9690
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9691
+ ] })
9692
+ }
9693
+ ),
9694
+ /* @__PURE__ */ jsxRuntime.jsx(
9695
+ Form$2.Field,
9696
+ {
9697
+ control: form.control,
9698
+ name: "address_2",
9699
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9702
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9703
+ ] })
9704
+ }
9705
+ ),
9706
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9707
+ /* @__PURE__ */ jsxRuntime.jsx(
9708
+ Form$2.Field,
9709
+ {
9710
+ control: form.control,
9711
+ name: "postal_code",
9712
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9714
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9715
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9716
+ ] })
9717
+ }
9718
+ ),
9719
+ /* @__PURE__ */ jsxRuntime.jsx(
9720
+ Form$2.Field,
9721
+ {
9722
+ control: form.control,
9723
+ name: "city",
9724
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9727
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
+ ] })
9729
+ }
9730
+ )
9731
+ ] }),
9732
+ /* @__PURE__ */ jsxRuntime.jsx(
9733
+ Form$2.Field,
9734
+ {
9735
+ control: form.control,
9736
+ name: "province",
9737
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
+ ] })
9742
+ }
9743
+ ),
9744
+ /* @__PURE__ */ jsxRuntime.jsx(
9745
+ Form$2.Field,
9746
+ {
9747
+ control: form.control,
9748
+ name: "phone",
9749
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
+ ] })
9754
+ }
9755
+ )
9756
+ ] }) }),
9757
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9760
+ ] }) })
9761
+ ]
9762
+ }
9763
+ ) });
9764
+ };
9765
+ const schema$5 = addressSchema;
9576
9766
  const CustomItems = () => {
9577
9767
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
9768
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9581,7 +9771,7 @@ const CustomItems = () => {
9581
9771
  };
9582
9772
  const CustomItemsForm = () => {
9583
9773
  const form = reactHookForm.useForm({
9584
- resolver: zod.zodResolver(schema$5)
9774
+ resolver: zod.zodResolver(schema$4)
9585
9775
  });
9586
9776
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
9777
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9591,7 +9781,7 @@ const CustomItemsForm = () => {
9591
9781
  ] }) })
9592
9782
  ] }) });
9593
9783
  };
9594
- const schema$5 = objectType({
9784
+ const schema$4 = objectType({
9595
9785
  email: stringType().email()
9596
9786
  });
9597
9787
  const Email = () => {
@@ -9616,7 +9806,7 @@ const EmailForm = ({ order }) => {
9616
9806
  defaultValues: {
9617
9807
  email: order.email ?? ""
9618
9808
  },
9619
- resolver: zod.zodResolver(schema$4)
9809
+ resolver: zod.zodResolver(schema$3)
9620
9810
  });
9621
9811
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9622
9812
  const { handleSuccess } = useRouteModal();
@@ -9659,7 +9849,7 @@ const EmailForm = ({ order }) => {
9659
9849
  }
9660
9850
  ) });
9661
9851
  };
9662
- const schema$4 = objectType({
9852
+ const schema$3 = objectType({
9663
9853
  email: stringType().email()
9664
9854
  });
9665
9855
  const NumberInput = React.forwardRef(
@@ -10636,283 +10826,6 @@ const customItemSchema = objectType({
10636
10826
  quantity: numberType(),
10637
10827
  unit_price: unionType([numberType(), stringType()])
10638
10828
  });
10639
- const PROMOTION_QUERY_KEY = "promotions";
10640
- const promotionsQueryKeys = {
10641
- list: (query2) => [
10642
- PROMOTION_QUERY_KEY,
10643
- query2 ? query2 : void 0
10644
- ],
10645
- detail: (id, query2) => [
10646
- PROMOTION_QUERY_KEY,
10647
- id,
10648
- query2 ? query2 : void 0
10649
- ]
10650
- };
10651
- const usePromotions = (query2, options) => {
10652
- const { data, ...rest } = reactQuery.useQuery({
10653
- queryKey: promotionsQueryKeys.list(query2),
10654
- queryFn: async () => sdk.admin.promotion.list(query2),
10655
- ...options
10656
- });
10657
- return { ...data, ...rest };
10658
- };
10659
- const Promotions = () => {
10660
- const { id } = reactRouterDom.useParams();
10661
- const {
10662
- order: preview,
10663
- isError: isPreviewError,
10664
- error: previewError
10665
- } = useOrderPreview(id, void 0);
10666
- useInitiateOrderEdit({ preview });
10667
- const { onCancel } = useCancelOrderEdit({ preview });
10668
- if (isPreviewError) {
10669
- throw previewError;
10670
- }
10671
- const isReady = !!preview;
10672
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10673
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10674
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10675
- ] });
10676
- };
10677
- const PromotionForm = ({ preview }) => {
10678
- const { items, shipping_methods } = preview;
10679
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10680
- const [comboboxValue, setComboboxValue] = React.useState("");
10681
- const { handleSuccess } = useRouteModal();
10682
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10683
- const promoIds = getPromotionIds(items, shipping_methods);
10684
- const { promotions, isPending, isError, error } = usePromotions(
10685
- {
10686
- id: promoIds
10687
- },
10688
- {
10689
- enabled: !!promoIds.length
10690
- }
10691
- );
10692
- const comboboxData = useComboboxData({
10693
- queryKey: ["promotions", "combobox", promoIds],
10694
- queryFn: async (params) => {
10695
- return await sdk.admin.promotion.list({
10696
- ...params,
10697
- id: {
10698
- $nin: promoIds
10699
- }
10700
- });
10701
- },
10702
- getOptions: (data) => {
10703
- return data.promotions.map((promotion) => ({
10704
- label: promotion.code,
10705
- value: promotion.code
10706
- }));
10707
- }
10708
- });
10709
- const add = async (value) => {
10710
- if (!value) {
10711
- return;
10712
- }
10713
- addPromotions(
10714
- {
10715
- promo_codes: [value]
10716
- },
10717
- {
10718
- onError: (e) => {
10719
- ui.toast.error(e.message);
10720
- comboboxData.onSearchValueChange("");
10721
- setComboboxValue("");
10722
- },
10723
- onSuccess: () => {
10724
- comboboxData.onSearchValueChange("");
10725
- setComboboxValue("");
10726
- }
10727
- }
10728
- );
10729
- };
10730
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10731
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10732
- const onSubmit = async () => {
10733
- setIsSubmitting(true);
10734
- let requestSucceeded = false;
10735
- await requestOrderEdit(void 0, {
10736
- onError: (e) => {
10737
- ui.toast.error(e.message);
10738
- },
10739
- onSuccess: () => {
10740
- requestSucceeded = true;
10741
- }
10742
- });
10743
- if (!requestSucceeded) {
10744
- setIsSubmitting(false);
10745
- return;
10746
- }
10747
- await confirmOrderEdit(void 0, {
10748
- onError: (e) => {
10749
- ui.toast.error(e.message);
10750
- },
10751
- onSuccess: () => {
10752
- handleSuccess();
10753
- },
10754
- onSettled: () => {
10755
- setIsSubmitting(false);
10756
- }
10757
- });
10758
- };
10759
- if (isError) {
10760
- throw error;
10761
- }
10762
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10763
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10764
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10765
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10766
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10767
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10768
- ] }),
10769
- /* @__PURE__ */ jsxRuntime.jsx(
10770
- Combobox,
10771
- {
10772
- id: "promotion-combobox",
10773
- "aria-describedby": "promotion-combobox-hint",
10774
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10775
- fetchNextPage: comboboxData.fetchNextPage,
10776
- options: comboboxData.options,
10777
- onSearchValueChange: comboboxData.onSearchValueChange,
10778
- searchValue: comboboxData.searchValue,
10779
- disabled: comboboxData.disabled || isAddingPromotions,
10780
- onChange: add,
10781
- value: comboboxValue
10782
- }
10783
- )
10784
- ] }),
10785
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10786
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10787
- PromotionItem,
10788
- {
10789
- promotion,
10790
- orderId: preview.id,
10791
- isLoading: isPending
10792
- },
10793
- promotion.id
10794
- )) })
10795
- ] }) }),
10796
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10797
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10798
- /* @__PURE__ */ jsxRuntime.jsx(
10799
- ui.Button,
10800
- {
10801
- size: "small",
10802
- type: "submit",
10803
- isLoading: isSubmitting || isAddingPromotions,
10804
- children: "Save"
10805
- }
10806
- )
10807
- ] }) })
10808
- ] });
10809
- };
10810
- const PromotionItem = ({
10811
- promotion,
10812
- orderId,
10813
- isLoading
10814
- }) => {
10815
- var _a;
10816
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10817
- const onRemove = async () => {
10818
- removePromotions(
10819
- {
10820
- promo_codes: [promotion.code]
10821
- },
10822
- {
10823
- onError: (e) => {
10824
- ui.toast.error(e.message);
10825
- }
10826
- }
10827
- );
10828
- };
10829
- const displayValue = getDisplayValue(promotion);
10830
- return /* @__PURE__ */ jsxRuntime.jsxs(
10831
- "div",
10832
- {
10833
- className: ui.clx(
10834
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
10835
- {
10836
- "animate-pulse": isLoading
10837
- }
10838
- ),
10839
- children: [
10840
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10841
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10842
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
10843
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
10844
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
10845
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
10846
- ] }),
10847
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10848
- ] })
10849
- ] }),
10850
- /* @__PURE__ */ jsxRuntime.jsx(
10851
- ui.IconButton,
10852
- {
10853
- size: "small",
10854
- type: "button",
10855
- variant: "transparent",
10856
- onClick: onRemove,
10857
- isLoading: isPending || isLoading,
10858
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
10859
- }
10860
- )
10861
- ]
10862
- },
10863
- promotion.id
10864
- );
10865
- };
10866
- function getDisplayValue(promotion) {
10867
- var _a, _b, _c, _d;
10868
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10869
- if (!value) {
10870
- return null;
10871
- }
10872
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10873
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10874
- if (!currency) {
10875
- return null;
10876
- }
10877
- return getLocaleAmount(value, currency);
10878
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10879
- return formatPercentage(value);
10880
- }
10881
- return null;
10882
- }
10883
- const formatter = new Intl.NumberFormat([], {
10884
- style: "percent",
10885
- minimumFractionDigits: 2
10886
- });
10887
- const formatPercentage = (value, isPercentageValue = false) => {
10888
- let val = value || 0;
10889
- if (!isPercentageValue) {
10890
- val = val / 100;
10891
- }
10892
- return formatter.format(val);
10893
- };
10894
- function getPromotionIds(items, shippingMethods) {
10895
- const promotionIds = /* @__PURE__ */ new Set();
10896
- for (const item of items) {
10897
- if (item.adjustments) {
10898
- for (const adjustment of item.adjustments) {
10899
- if (adjustment.promotion_id) {
10900
- promotionIds.add(adjustment.promotion_id);
10901
- }
10902
- }
10903
- }
10904
- }
10905
- for (const shippingMethod of shippingMethods) {
10906
- if (shippingMethod.adjustments) {
10907
- for (const adjustment of shippingMethod.adjustments) {
10908
- if (adjustment.promotion_id) {
10909
- promotionIds.add(adjustment.promotion_id);
10910
- }
10911
- }
10912
- }
10913
- }
10914
- return Array.from(promotionIds);
10915
- }
10916
10829
  const InlineTip = React.forwardRef(
10917
10830
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10918
10831
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11263,183 +11176,105 @@ function getHasUneditableRows(metadata) {
11263
11176
  (value) => !EDITABLE_TYPES.includes(typeof value)
11264
11177
  );
11265
11178
  }
11266
- const SalesChannel = () => {
11267
- const { id } = reactRouterDom.useParams();
11268
- const { draft_order, isPending, isError, error } = useDraftOrder(
11179
+ const PROMOTION_QUERY_KEY = "promotions";
11180
+ const promotionsQueryKeys = {
11181
+ list: (query2) => [
11182
+ PROMOTION_QUERY_KEY,
11183
+ query2 ? query2 : void 0
11184
+ ],
11185
+ detail: (id, query2) => [
11186
+ PROMOTION_QUERY_KEY,
11269
11187
  id,
11270
- {
11271
- fields: "+sales_channel_id"
11272
- },
11273
- {
11274
- enabled: !!id
11275
- }
11276
- );
11277
- if (isError) {
11278
- throw error;
11279
- }
11280
- const ISrEADY = !!draft_order && !isPending;
11281
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11282
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11283
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11284
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11285
- ] }),
11286
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11287
- ] });
11188
+ query2 ? query2 : void 0
11189
+ ]
11288
11190
  };
11289
- const SalesChannelForm = ({ order }) => {
11290
- const form = reactHookForm.useForm({
11291
- defaultValues: {
11292
- sales_channel_id: order.sales_channel_id || ""
11293
- },
11294
- resolver: zod.zodResolver(schema$3)
11295
- });
11296
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11297
- const { handleSuccess } = useRouteModal();
11298
- const onSubmit = form.handleSubmit(async (data) => {
11299
- await mutateAsync(
11300
- {
11301
- sales_channel_id: data.sales_channel_id
11302
- },
11303
- {
11304
- onSuccess: () => {
11305
- ui.toast.success("Sales channel updated");
11306
- handleSuccess();
11307
- },
11308
- onError: (error) => {
11309
- ui.toast.error(error.message);
11310
- }
11311
- }
11312
- );
11313
- });
11314
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11315
- KeyboundForm,
11316
- {
11317
- className: "flex flex-1 flex-col overflow-hidden",
11318
- onSubmit,
11319
- children: [
11320
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11321
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11322
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11323
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11324
- ] }) })
11325
- ]
11326
- }
11327
- ) });
11328
- };
11329
- const SalesChannelField = ({ control, order }) => {
11330
- const salesChannels = useComboboxData({
11331
- queryFn: async (params) => {
11332
- return await sdk.admin.salesChannel.list(params);
11333
- },
11334
- queryKey: ["sales-channels"],
11335
- getOptions: (data) => {
11336
- return data.sales_channels.map((salesChannel) => ({
11337
- label: salesChannel.name,
11338
- value: salesChannel.id
11339
- }));
11340
- },
11341
- defaultValue: order.sales_channel_id || void 0
11191
+ const usePromotions = (query2, options) => {
11192
+ const { data, ...rest } = reactQuery.useQuery({
11193
+ queryKey: promotionsQueryKeys.list(query2),
11194
+ queryFn: async () => sdk.admin.promotion.list(query2),
11195
+ ...options
11342
11196
  });
11343
- return /* @__PURE__ */ jsxRuntime.jsx(
11344
- Form$2.Field,
11345
- {
11346
- control,
11347
- name: "sales_channel_id",
11348
- render: ({ field }) => {
11349
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11352
- Combobox,
11353
- {
11354
- options: salesChannels.options,
11355
- fetchNextPage: salesChannels.fetchNextPage,
11356
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11357
- searchValue: salesChannels.searchValue,
11358
- onSearchValueChange: salesChannels.onSearchValueChange,
11359
- placeholder: "Select sales channel",
11360
- ...field
11361
- }
11362
- ) }),
11363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11364
- ] });
11365
- }
11366
- }
11367
- );
11197
+ return { ...data, ...rest };
11368
11198
  };
11369
- const schema$3 = objectType({
11370
- sales_channel_id: stringType().min(1)
11371
- });
11372
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11373
- const Shipping = () => {
11374
- var _a;
11199
+ const Promotions = () => {
11375
11200
  const { id } = reactRouterDom.useParams();
11376
- const { order, isPending, isError, error } = useOrder(id, {
11377
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11378
- });
11379
11201
  const {
11380
11202
  order: preview,
11381
- isPending: isPreviewPending,
11382
11203
  isError: isPreviewError,
11383
11204
  error: previewError
11384
- } = useOrderPreview(id);
11205
+ } = useOrderPreview(id, void 0);
11385
11206
  useInitiateOrderEdit({ preview });
11386
11207
  const { onCancel } = useCancelOrderEdit({ preview });
11387
- if (isError) {
11388
- throw error;
11389
- }
11390
11208
  if (isPreviewError) {
11391
11209
  throw previewError;
11392
11210
  }
11393
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11394
- const isReady = preview && !isPreviewPending && order && !isPending;
11395
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11396
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11397
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11398
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11399
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11400
- ] }) }) }),
11401
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11402
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11403
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11404
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11405
- ] }) });
11211
+ const isReady = !!preview;
11212
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11213
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11214
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11215
+ ] });
11406
11216
  };
11407
- const ShippingForm = ({ preview, order }) => {
11408
- var _a;
11409
- const { setIsOpen } = useStackedModal();
11217
+ const PromotionForm = ({ preview }) => {
11218
+ const { items, shipping_methods } = preview;
11410
11219
  const [isSubmitting, setIsSubmitting] = React.useState(false);
11411
- const [data, setData] = React.useState(null);
11412
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11413
- const { shipping_options } = useShippingOptions(
11220
+ const [comboboxValue, setComboboxValue] = React.useState("");
11221
+ const { handleSuccess } = useRouteModal();
11222
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11223
+ const promoIds = getPromotionIds(items, shipping_methods);
11224
+ const { promotions, isPending, isError, error } = usePromotions(
11414
11225
  {
11415
- id: appliedShippingOptionIds,
11416
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11226
+ id: promoIds
11417
11227
  },
11418
11228
  {
11419
- enabled: appliedShippingOptionIds.length > 0
11229
+ enabled: !!promoIds.length
11420
11230
  }
11421
11231
  );
11422
- const uniqueShippingProfiles = React.useMemo(() => {
11423
- const profiles = /* @__PURE__ */ new Map();
11424
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11425
- profiles.set(profile.id, profile);
11426
- });
11427
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11428
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11429
- });
11430
- return Array.from(profiles.values());
11431
- }, [order.items, shipping_options]);
11432
- const { handleSuccess } = useRouteModal();
11232
+ const comboboxData = useComboboxData({
11233
+ queryKey: ["promotions", "combobox", promoIds],
11234
+ queryFn: async (params) => {
11235
+ return await sdk.admin.promotion.list({
11236
+ ...params,
11237
+ id: {
11238
+ $nin: promoIds
11239
+ }
11240
+ });
11241
+ },
11242
+ getOptions: (data) => {
11243
+ return data.promotions.map((promotion) => ({
11244
+ label: promotion.code,
11245
+ value: promotion.code
11246
+ }));
11247
+ }
11248
+ });
11249
+ const add = async (value) => {
11250
+ if (!value) {
11251
+ return;
11252
+ }
11253
+ addPromotions(
11254
+ {
11255
+ promo_codes: [value]
11256
+ },
11257
+ {
11258
+ onError: (e) => {
11259
+ ui.toast.error(e.message);
11260
+ comboboxData.onSearchValueChange("");
11261
+ setComboboxValue("");
11262
+ },
11263
+ onSuccess: () => {
11264
+ comboboxData.onSearchValueChange("");
11265
+ setComboboxValue("");
11266
+ }
11267
+ }
11268
+ );
11269
+ };
11433
11270
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11434
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11435
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11436
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11271
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11437
11272
  const onSubmit = async () => {
11438
11273
  setIsSubmitting(true);
11439
11274
  let requestSucceeded = false;
11440
11275
  await requestOrderEdit(void 0, {
11441
11276
  onError: (e) => {
11442
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11277
+ ui.toast.error(e.message);
11443
11278
  },
11444
11279
  onSuccess: () => {
11445
11280
  requestSucceeded = true;
@@ -11451,7 +11286,7 @@ const ShippingForm = ({ preview, order }) => {
11451
11286
  }
11452
11287
  await confirmOrderEdit(void 0, {
11453
11288
  onError: (e) => {
11454
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11289
+ ui.toast.error(e.message);
11455
11290
  },
11456
11291
  onSuccess: () => {
11457
11292
  handleSuccess();
@@ -11461,924 +11296,1076 @@ const ShippingForm = ({ preview, order }) => {
11461
11296
  }
11462
11297
  });
11463
11298
  };
11464
- const onKeydown = React.useCallback(
11465
- (e) => {
11466
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11467
- if (data || isSubmitting) {
11468
- return;
11469
- }
11470
- onSubmit();
11471
- }
11472
- },
11473
- [data, isSubmitting, onSubmit]
11474
- );
11475
- React.useEffect(() => {
11476
- document.addEventListener("keydown", onKeydown);
11477
- return () => {
11478
- document.removeEventListener("keydown", onKeydown);
11479
- };
11480
- }, [onKeydown]);
11481
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11482
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11483
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11484
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11485
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11486
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11487
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11299
+ if (isError) {
11300
+ throw error;
11301
+ }
11302
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11304
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11305
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11306
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11307
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11488
11308
  ] }),
11489
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11490
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11491
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11492
- /* @__PURE__ */ jsxRuntime.jsx(
11493
- ui.Text,
11494
- {
11495
- size: "xsmall",
11496
- weight: "plus",
11497
- className: "text-ui-fg-muted",
11498
- children: "Shipping profile"
11499
- }
11500
- ),
11501
- /* @__PURE__ */ jsxRuntime.jsx(
11502
- ui.Text,
11503
- {
11504
- size: "xsmall",
11505
- weight: "plus",
11506
- className: "text-ui-fg-muted",
11507
- children: "Action"
11508
- }
11509
- )
11510
- ] }),
11511
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11512
- var _a2, _b, _c, _d, _e, _f, _g;
11513
- const items = getItemsWithShippingProfile(
11514
- profile.id,
11515
- order.items
11516
- );
11517
- const hasItems = items.length > 0;
11518
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11519
- (option) => option.shipping_profile_id === profile.id
11520
- );
11521
- const shippingMethod = preview.shipping_methods.find(
11522
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11523
- );
11524
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11525
- (action) => action.action === "SHIPPING_ADD"
11526
- );
11527
- return /* @__PURE__ */ jsxRuntime.jsxs(
11528
- radixUi.Accordion.Item,
11529
- {
11530
- value: profile.id,
11531
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11532
- children: [
11533
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11534
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11535
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11536
- ui.IconButton,
11537
- {
11538
- size: "2xsmall",
11539
- variant: "transparent",
11540
- className: "group/trigger",
11541
- disabled: !hasItems,
11542
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11543
- }
11544
- ) }),
11545
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11546
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11547
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11548
- /* @__PURE__ */ jsxRuntime.jsx(
11549
- ui.Text,
11550
- {
11551
- size: "small",
11552
- weight: "plus",
11553
- leading: "compact",
11554
- children: profile.name
11555
- }
11556
- ),
11557
- /* @__PURE__ */ jsxRuntime.jsxs(
11558
- ui.Text,
11559
- {
11560
- size: "small",
11561
- leading: "compact",
11562
- className: "text-ui-fg-subtle",
11563
- children: [
11564
- items.length,
11565
- " ",
11566
- pluralize(items.length, "items", "item")
11567
- ]
11568
- }
11569
- )
11570
- ] })
11571
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11572
- /* @__PURE__ */ jsxRuntime.jsx(
11573
- ui.Tooltip,
11574
- {
11575
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11576
- var _a3, _b2, _c2;
11577
- return /* @__PURE__ */ jsxRuntime.jsx(
11578
- "li",
11579
- {
11580
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11581
- },
11582
- item.id
11583
- );
11584
- }) }),
11585
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11586
- ui.Badge,
11587
- {
11588
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11589
- size: "xsmall",
11590
- children: [
11591
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11592
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11593
- items.reduce(
11594
- (acc, item) => acc + item.quantity,
11595
- 0
11596
- ),
11597
- "x",
11598
- " ",
11599
- pluralize(items.length, "items", "item")
11600
- ] })
11601
- ]
11602
- }
11603
- )
11604
- }
11605
- ),
11606
- /* @__PURE__ */ jsxRuntime.jsx(
11607
- ui.Tooltip,
11608
- {
11609
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11610
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11611
- ui.Badge,
11612
- {
11613
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11614
- size: "xsmall",
11615
- children: [
11616
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11617
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11618
- ]
11619
- }
11620
- )
11621
- }
11622
- ),
11623
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11624
- ui.Badge,
11625
- {
11626
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11627
- size: "xsmall",
11628
- children: [
11629
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11630
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11631
- ]
11632
- }
11633
- ) })
11634
- ] })
11635
- ] }),
11636
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11637
- ActionMenu,
11638
- {
11639
- groups: [
11640
- {
11641
- actions: [
11642
- hasItems ? {
11643
- label: "Edit shipping option",
11644
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11645
- onClick: () => {
11646
- setIsOpen(
11647
- STACKED_FOCUS_MODAL_ID,
11648
- true
11649
- );
11650
- setData({
11651
- shippingProfileId: profile.id,
11652
- shippingOption,
11653
- shippingMethod
11654
- });
11655
- }
11656
- } : void 0,
11657
- {
11658
- label: "Remove shipping option",
11659
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11660
- onClick: () => {
11661
- if (shippingMethod) {
11662
- if (addShippingMethodAction) {
11663
- removeActionShippingMethod(
11664
- addShippingMethodAction.id
11665
- );
11666
- } else {
11667
- removeShippingMethod(
11668
- shippingMethod.id
11669
- );
11670
- }
11671
- }
11672
- }
11673
- }
11674
- ].filter(Boolean)
11675
- }
11676
- ]
11677
- }
11678
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11679
- StackedModalTrigger,
11680
- {
11681
- shippingProfileId: profile.id,
11682
- shippingOption,
11683
- shippingMethod,
11684
- setData,
11685
- children: "Add shipping option"
11686
- }
11687
- )
11688
- ] }),
11689
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11690
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11691
- items.map((item, idx) => {
11692
- var _a3, _b2, _c2, _d2, _e2;
11693
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11694
- /* @__PURE__ */ jsxRuntime.jsxs(
11695
- "div",
11696
- {
11697
- className: "px-3 flex items-center gap-x-3",
11698
- children: [
11699
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11700
- ui.Divider,
11701
- {
11702
- variant: "dashed",
11703
- orientation: "vertical"
11704
- }
11705
- ) }),
11706
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11707
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11708
- ui.Text,
11709
- {
11710
- size: "small",
11711
- leading: "compact",
11712
- className: "text-ui-fg-subtle",
11713
- children: [
11714
- item.quantity,
11715
- "x"
11716
- ]
11717
- }
11718
- ) }),
11719
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11720
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11721
- /* @__PURE__ */ jsxRuntime.jsxs(
11722
- ui.Text,
11723
- {
11724
- size: "small",
11725
- leading: "compact",
11726
- weight: "plus",
11727
- children: [
11728
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11729
- " (",
11730
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11731
- ")"
11732
- ]
11733
- }
11734
- ),
11735
- /* @__PURE__ */ jsxRuntime.jsx(
11736
- ui.Text,
11737
- {
11738
- size: "small",
11739
- leading: "compact",
11740
- className: "text-ui-fg-subtle",
11741
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11742
- }
11743
- )
11744
- ] })
11745
- ] })
11746
- ]
11747
- },
11748
- item.id
11749
- ),
11750
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11751
- ] }, item.id);
11752
- })
11753
- ] })
11754
- ]
11755
- },
11756
- profile.id
11757
- );
11758
- }) })
11759
- ] }) })
11760
- ] }) }),
11761
- /* @__PURE__ */ jsxRuntime.jsx(
11762
- StackedFocusModal,
11309
+ /* @__PURE__ */ jsxRuntime.jsx(
11310
+ Combobox,
11311
+ {
11312
+ id: "promotion-combobox",
11313
+ "aria-describedby": "promotion-combobox-hint",
11314
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11315
+ fetchNextPage: comboboxData.fetchNextPage,
11316
+ options: comboboxData.options,
11317
+ onSearchValueChange: comboboxData.onSearchValueChange,
11318
+ searchValue: comboboxData.searchValue,
11319
+ disabled: comboboxData.disabled || isAddingPromotions,
11320
+ onChange: add,
11321
+ value: comboboxValue
11322
+ }
11323
+ )
11324
+ ] }),
11325
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11326
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11327
+ PromotionItem,
11763
11328
  {
11764
- id: STACKED_FOCUS_MODAL_ID,
11765
- onOpenChangeCallback: (open) => {
11766
- if (!open) {
11767
- setData(null);
11768
- }
11769
- return open;
11770
- },
11771
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11772
- }
11773
- )
11774
- ] }),
11775
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11776
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11329
+ promotion,
11330
+ orderId: preview.id,
11331
+ isLoading: isPending
11332
+ },
11333
+ promotion.id
11334
+ )) })
11335
+ ] }) }),
11336
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11337
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11777
11338
  /* @__PURE__ */ jsxRuntime.jsx(
11778
11339
  ui.Button,
11779
11340
  {
11780
11341
  size: "small",
11781
- type: "button",
11782
- isLoading: isSubmitting,
11783
- onClick: onSubmit,
11342
+ type: "submit",
11343
+ isLoading: isSubmitting || isAddingPromotions,
11784
11344
  children: "Save"
11785
11345
  }
11786
11346
  )
11787
11347
  ] }) })
11788
11348
  ] });
11789
11349
  };
11790
- const StackedModalTrigger = ({
11791
- shippingProfileId,
11792
- shippingOption,
11793
- shippingMethod,
11794
- setData,
11795
- children
11350
+ const PromotionItem = ({
11351
+ promotion,
11352
+ orderId,
11353
+ isLoading
11796
11354
  }) => {
11797
- const { setIsOpen, getIsOpen } = useStackedModal();
11798
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11799
- const onToggle = () => {
11800
- if (isOpen) {
11801
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11802
- setData(null);
11803
- } else {
11804
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11805
- setData({
11806
- shippingProfileId,
11807
- shippingOption,
11808
- shippingMethod
11809
- });
11810
- }
11355
+ var _a;
11356
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11357
+ const onRemove = async () => {
11358
+ removePromotions(
11359
+ {
11360
+ promo_codes: [promotion.code]
11361
+ },
11362
+ {
11363
+ onError: (e) => {
11364
+ ui.toast.error(e.message);
11365
+ }
11366
+ }
11367
+ );
11811
11368
  };
11812
- return /* @__PURE__ */ jsxRuntime.jsx(
11813
- ui.Button,
11369
+ const displayValue = getDisplayValue(promotion);
11370
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11371
+ "div",
11814
11372
  {
11815
- size: "small",
11816
- variant: "secondary",
11817
- onClick: onToggle,
11818
- className: "text-ui-fg-primary shrink-0",
11819
- children
11820
- }
11373
+ className: ui.clx(
11374
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11375
+ {
11376
+ "animate-pulse": isLoading
11377
+ }
11378
+ ),
11379
+ children: [
11380
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11381
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11382
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11383
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11384
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11385
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11386
+ ] }),
11387
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11388
+ ] })
11389
+ ] }),
11390
+ /* @__PURE__ */ jsxRuntime.jsx(
11391
+ ui.IconButton,
11392
+ {
11393
+ size: "small",
11394
+ type: "button",
11395
+ variant: "transparent",
11396
+ onClick: onRemove,
11397
+ isLoading: isPending || isLoading,
11398
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11399
+ }
11400
+ )
11401
+ ]
11402
+ },
11403
+ promotion.id
11821
11404
  );
11822
11405
  };
11823
- const ShippingProfileForm = ({
11824
- data,
11825
- order,
11826
- preview
11827
- }) => {
11828
- var _a, _b, _c, _d, _e, _f;
11829
- const { setIsOpen } = useStackedModal();
11830
- const form = reactHookForm.useForm({
11831
- resolver: zod.zodResolver(shippingMethodSchema),
11832
- defaultValues: {
11833
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
11834
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11835
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11406
+ function getDisplayValue(promotion) {
11407
+ var _a, _b, _c, _d;
11408
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11409
+ if (!value) {
11410
+ return null;
11411
+ }
11412
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11413
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11414
+ if (!currency) {
11415
+ return null;
11836
11416
  }
11837
- });
11838
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11839
- const {
11840
- mutateAsync: updateShippingMethod,
11841
- isPending: isUpdatingShippingMethod
11842
- } = useDraftOrderUpdateShippingMethod(order.id);
11843
- const onSubmit = form.handleSubmit(async (values) => {
11844
- if (lodash.isEqual(values, form.formState.defaultValues)) {
11845
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11846
- return;
11417
+ return getLocaleAmount(value, currency);
11418
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11419
+ return formatPercentage(value);
11420
+ }
11421
+ return null;
11422
+ }
11423
+ const formatter = new Intl.NumberFormat([], {
11424
+ style: "percent",
11425
+ minimumFractionDigits: 2
11426
+ });
11427
+ const formatPercentage = (value, isPercentageValue = false) => {
11428
+ let val = value || 0;
11429
+ if (!isPercentageValue) {
11430
+ val = val / 100;
11431
+ }
11432
+ return formatter.format(val);
11433
+ };
11434
+ function getPromotionIds(items, shippingMethods) {
11435
+ const promotionIds = /* @__PURE__ */ new Set();
11436
+ for (const item of items) {
11437
+ if (item.adjustments) {
11438
+ for (const adjustment of item.adjustments) {
11439
+ if (adjustment.promotion_id) {
11440
+ promotionIds.add(adjustment.promotion_id);
11441
+ }
11442
+ }
11847
11443
  }
11848
- if (data.shippingMethod) {
11849
- await updateShippingMethod(
11850
- {
11851
- method_id: data.shippingMethod.id,
11852
- shipping_option_id: values.shipping_option_id,
11853
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11854
- },
11855
- {
11856
- onError: (e) => {
11857
- ui.toast.error(e.message);
11858
- },
11859
- onSuccess: () => {
11860
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11861
- }
11444
+ }
11445
+ for (const shippingMethod of shippingMethods) {
11446
+ if (shippingMethod.adjustments) {
11447
+ for (const adjustment of shippingMethod.adjustments) {
11448
+ if (adjustment.promotion_id) {
11449
+ promotionIds.add(adjustment.promotion_id);
11862
11450
  }
11863
- );
11864
- return;
11451
+ }
11865
11452
  }
11866
- await addShippingMethod(
11453
+ }
11454
+ return Array.from(promotionIds);
11455
+ }
11456
+ const SalesChannel = () => {
11457
+ const { id } = reactRouterDom.useParams();
11458
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11459
+ id,
11460
+ {
11461
+ fields: "+sales_channel_id"
11462
+ },
11463
+ {
11464
+ enabled: !!id
11465
+ }
11466
+ );
11467
+ if (isError) {
11468
+ throw error;
11469
+ }
11470
+ const ISrEADY = !!draft_order && !isPending;
11471
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11473
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11474
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11475
+ ] }),
11476
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11477
+ ] });
11478
+ };
11479
+ const SalesChannelForm = ({ order }) => {
11480
+ const form = reactHookForm.useForm({
11481
+ defaultValues: {
11482
+ sales_channel_id: order.sales_channel_id || ""
11483
+ },
11484
+ resolver: zod.zodResolver(schema$2)
11485
+ });
11486
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11487
+ const { handleSuccess } = useRouteModal();
11488
+ const onSubmit = form.handleSubmit(async (data) => {
11489
+ await mutateAsync(
11867
11490
  {
11868
- shipping_option_id: values.shipping_option_id,
11869
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11491
+ sales_channel_id: data.sales_channel_id
11870
11492
  },
11871
11493
  {
11872
- onError: (e) => {
11873
- ui.toast.error(e.message);
11874
- },
11875
11494
  onSuccess: () => {
11876
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11495
+ ui.toast.success("Sales channel updated");
11496
+ handleSuccess();
11497
+ },
11498
+ onError: (error) => {
11499
+ ui.toast.error(error.message);
11877
11500
  }
11878
11501
  }
11879
11502
  );
11880
11503
  });
11881
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11882
- KeyboundForm,
11504
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11505
+ KeyboundForm,
11506
+ {
11507
+ className: "flex flex-1 flex-col overflow-hidden",
11508
+ onSubmit,
11509
+ children: [
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11512
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11513
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11514
+ ] }) })
11515
+ ]
11516
+ }
11517
+ ) });
11518
+ };
11519
+ const SalesChannelField = ({ control, order }) => {
11520
+ const salesChannels = useComboboxData({
11521
+ queryFn: async (params) => {
11522
+ return await sdk.admin.salesChannel.list(params);
11523
+ },
11524
+ queryKey: ["sales-channels"],
11525
+ getOptions: (data) => {
11526
+ return data.sales_channels.map((salesChannel) => ({
11527
+ label: salesChannel.name,
11528
+ value: salesChannel.id
11529
+ }));
11530
+ },
11531
+ defaultValue: order.sales_channel_id || void 0
11532
+ });
11533
+ return /* @__PURE__ */ jsxRuntime.jsx(
11534
+ Form$2.Field,
11883
11535
  {
11884
- className: "flex h-full flex-col overflow-hidden",
11885
- onSubmit,
11886
- children: [
11887
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11888
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11889
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11890
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11891
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11892
- ] }),
11893
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11894
- /* @__PURE__ */ jsxRuntime.jsx(
11895
- LocationField,
11896
- {
11897
- control: form.control,
11898
- setValue: form.setValue
11899
- }
11900
- ),
11901
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11902
- /* @__PURE__ */ jsxRuntime.jsx(
11903
- ShippingOptionField,
11904
- {
11905
- shippingProfileId: data.shippingProfileId,
11906
- preview,
11907
- control: form.control
11908
- }
11909
- ),
11910
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11911
- /* @__PURE__ */ jsxRuntime.jsx(
11912
- CustomAmountField,
11913
- {
11914
- control: form.control,
11915
- currencyCode: order.currency_code
11916
- }
11917
- ),
11918
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11919
- /* @__PURE__ */ jsxRuntime.jsx(
11920
- ItemsPreview,
11921
- {
11922
- order,
11923
- shippingProfileId: data.shippingProfileId
11924
- }
11925
- )
11926
- ] }) }) }),
11927
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11928
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11929
- /* @__PURE__ */ jsxRuntime.jsx(
11930
- ui.Button,
11536
+ control,
11537
+ name: "sales_channel_id",
11538
+ render: ({ field }) => {
11539
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11541
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11542
+ Combobox,
11931
11543
  {
11932
- size: "small",
11933
- type: "submit",
11934
- isLoading: isPending || isUpdatingShippingMethod,
11935
- children: data.shippingMethod ? "Update" : "Add"
11544
+ options: salesChannels.options,
11545
+ fetchNextPage: salesChannels.fetchNextPage,
11546
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11547
+ searchValue: salesChannels.searchValue,
11548
+ onSearchValueChange: salesChannels.onSearchValueChange,
11549
+ placeholder: "Select sales channel",
11550
+ ...field
11936
11551
  }
11937
- )
11938
- ] }) })
11939
- ]
11552
+ ) }),
11553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11554
+ ] });
11555
+ }
11940
11556
  }
11941
- ) }) });
11557
+ );
11942
11558
  };
11943
- const shippingMethodSchema = objectType({
11944
- location_id: stringType(),
11945
- shipping_option_id: stringType(),
11946
- custom_amount: unionType([numberType(), stringType()]).optional()
11559
+ const schema$2 = objectType({
11560
+ sales_channel_id: stringType().min(1)
11947
11561
  });
11948
- const ItemsPreview = ({ order, shippingProfileId }) => {
11949
- const matches = order.items.filter(
11950
- (item) => {
11951
- var _a, _b, _c;
11952
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11562
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11563
+ const Shipping = () => {
11564
+ var _a;
11565
+ const { id } = reactRouterDom.useParams();
11566
+ const { order, isPending, isError, error } = useOrder(id, {
11567
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11568
+ });
11569
+ const {
11570
+ order: preview,
11571
+ isPending: isPreviewPending,
11572
+ isError: isPreviewError,
11573
+ error: previewError
11574
+ } = useOrderPreview(id);
11575
+ useInitiateOrderEdit({ preview });
11576
+ const { onCancel } = useCancelOrderEdit({ preview });
11577
+ if (isError) {
11578
+ throw error;
11579
+ }
11580
+ if (isPreviewError) {
11581
+ throw previewError;
11582
+ }
11583
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11584
+ const isReady = preview && !isPreviewPending && order && !isPending;
11585
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11590
+ ] }) }) }),
11591
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11592
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11593
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11594
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11595
+ ] }) });
11596
+ };
11597
+ const ShippingForm = ({ preview, order }) => {
11598
+ var _a;
11599
+ const { setIsOpen } = useStackedModal();
11600
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11601
+ const [data, setData] = React.useState(null);
11602
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11603
+ const { shipping_options } = useShippingOptions(
11604
+ {
11605
+ id: appliedShippingOptionIds,
11606
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11607
+ },
11608
+ {
11609
+ enabled: appliedShippingOptionIds.length > 0
11953
11610
  }
11954
11611
  );
11955
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11956
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11957
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11958
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11959
- ] }) }),
11960
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11961
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11962
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11963
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
11964
- ] }),
11965
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
11966
- "div",
11967
- {
11968
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11969
- children: [
11970
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11971
- /* @__PURE__ */ jsxRuntime.jsx(
11972
- Thumbnail,
11973
- {
11974
- thumbnail: item.thumbnail,
11975
- alt: item.product_title ?? void 0
11976
- }
11977
- ),
11978
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11979
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11980
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11981
- /* @__PURE__ */ jsxRuntime.jsxs(
11982
- ui.Text,
11983
- {
11984
- size: "small",
11985
- leading: "compact",
11986
- className: "text-ui-fg-subtle",
11987
- children: [
11988
- "(",
11989
- item.variant_title,
11990
- ")"
11991
- ]
11992
- }
11993
- )
11994
- ] }),
11995
- /* @__PURE__ */ jsxRuntime.jsx(
11996
- ui.Text,
11997
- {
11998
- size: "small",
11999
- leading: "compact",
12000
- className: "text-ui-fg-subtle",
12001
- children: item.variant_sku
12002
- }
12003
- )
12004
- ] })
12005
- ] }),
12006
- /* @__PURE__ */ jsxRuntime.jsxs(
11612
+ const uniqueShippingProfiles = React.useMemo(() => {
11613
+ const profiles = /* @__PURE__ */ new Map();
11614
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11615
+ profiles.set(profile.id, profile);
11616
+ });
11617
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11618
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11619
+ });
11620
+ return Array.from(profiles.values());
11621
+ }, [order.items, shipping_options]);
11622
+ const { handleSuccess } = useRouteModal();
11623
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11624
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11625
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11626
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11627
+ const onSubmit = async () => {
11628
+ setIsSubmitting(true);
11629
+ let requestSucceeded = false;
11630
+ await requestOrderEdit(void 0, {
11631
+ onError: (e) => {
11632
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11633
+ },
11634
+ onSuccess: () => {
11635
+ requestSucceeded = true;
11636
+ }
11637
+ });
11638
+ if (!requestSucceeded) {
11639
+ setIsSubmitting(false);
11640
+ return;
11641
+ }
11642
+ await confirmOrderEdit(void 0, {
11643
+ onError: (e) => {
11644
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11645
+ },
11646
+ onSuccess: () => {
11647
+ handleSuccess();
11648
+ },
11649
+ onSettled: () => {
11650
+ setIsSubmitting(false);
11651
+ }
11652
+ });
11653
+ };
11654
+ const onKeydown = React.useCallback(
11655
+ (e) => {
11656
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11657
+ if (data || isSubmitting) {
11658
+ return;
11659
+ }
11660
+ onSubmit();
11661
+ }
11662
+ },
11663
+ [data, isSubmitting, onSubmit]
11664
+ );
11665
+ React.useEffect(() => {
11666
+ document.addEventListener("keydown", onKeydown);
11667
+ return () => {
11668
+ document.removeEventListener("keydown", onKeydown);
11669
+ };
11670
+ }, [onKeydown]);
11671
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11672
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11673
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11674
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11675
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11676
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11677
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11678
+ ] }),
11679
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11680
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11681
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11682
+ /* @__PURE__ */ jsxRuntime.jsx(
12007
11683
  ui.Text,
12008
11684
  {
12009
- size: "small",
12010
- leading: "compact",
12011
- className: "text-ui-fg-subtle",
11685
+ size: "xsmall",
11686
+ weight: "plus",
11687
+ className: "text-ui-fg-muted",
11688
+ children: "Shipping profile"
11689
+ }
11690
+ ),
11691
+ /* @__PURE__ */ jsxRuntime.jsx(
11692
+ ui.Text,
11693
+ {
11694
+ size: "xsmall",
11695
+ weight: "plus",
11696
+ className: "text-ui-fg-muted",
11697
+ children: "Action"
11698
+ }
11699
+ )
11700
+ ] }),
11701
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11702
+ var _a2, _b, _c, _d, _e, _f, _g;
11703
+ const items = getItemsWithShippingProfile(
11704
+ profile.id,
11705
+ order.items
11706
+ );
11707
+ const hasItems = items.length > 0;
11708
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11709
+ (option) => option.shipping_profile_id === profile.id
11710
+ );
11711
+ const shippingMethod = preview.shipping_methods.find(
11712
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11713
+ );
11714
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11715
+ (action) => action.action === "SHIPPING_ADD"
11716
+ );
11717
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11718
+ radixUi.Accordion.Item,
11719
+ {
11720
+ value: profile.id,
11721
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12012
11722
  children: [
12013
- item.quantity,
12014
- "x"
11723
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11724
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11725
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11726
+ ui.IconButton,
11727
+ {
11728
+ size: "2xsmall",
11729
+ variant: "transparent",
11730
+ className: "group/trigger",
11731
+ disabled: !hasItems,
11732
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11733
+ }
11734
+ ) }),
11735
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11736
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11737
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11738
+ /* @__PURE__ */ jsxRuntime.jsx(
11739
+ ui.Text,
11740
+ {
11741
+ size: "small",
11742
+ weight: "plus",
11743
+ leading: "compact",
11744
+ children: profile.name
11745
+ }
11746
+ ),
11747
+ /* @__PURE__ */ jsxRuntime.jsxs(
11748
+ ui.Text,
11749
+ {
11750
+ size: "small",
11751
+ leading: "compact",
11752
+ className: "text-ui-fg-subtle",
11753
+ children: [
11754
+ items.length,
11755
+ " ",
11756
+ pluralize(items.length, "items", "item")
11757
+ ]
11758
+ }
11759
+ )
11760
+ ] })
11761
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11762
+ /* @__PURE__ */ jsxRuntime.jsx(
11763
+ ui.Tooltip,
11764
+ {
11765
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11766
+ var _a3, _b2, _c2;
11767
+ return /* @__PURE__ */ jsxRuntime.jsx(
11768
+ "li",
11769
+ {
11770
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11771
+ },
11772
+ item.id
11773
+ );
11774
+ }) }),
11775
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11776
+ ui.Badge,
11777
+ {
11778
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11779
+ size: "xsmall",
11780
+ children: [
11781
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11782
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11783
+ items.reduce(
11784
+ (acc, item) => acc + item.quantity,
11785
+ 0
11786
+ ),
11787
+ "x",
11788
+ " ",
11789
+ pluralize(items.length, "items", "item")
11790
+ ] })
11791
+ ]
11792
+ }
11793
+ )
11794
+ }
11795
+ ),
11796
+ /* @__PURE__ */ jsxRuntime.jsx(
11797
+ ui.Tooltip,
11798
+ {
11799
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11800
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11801
+ ui.Badge,
11802
+ {
11803
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11804
+ size: "xsmall",
11805
+ children: [
11806
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11807
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11808
+ ]
11809
+ }
11810
+ )
11811
+ }
11812
+ ),
11813
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11814
+ ui.Badge,
11815
+ {
11816
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11817
+ size: "xsmall",
11818
+ children: [
11819
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11820
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11821
+ ]
11822
+ }
11823
+ ) })
11824
+ ] })
11825
+ ] }),
11826
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11827
+ ActionMenu,
11828
+ {
11829
+ groups: [
11830
+ {
11831
+ actions: [
11832
+ hasItems ? {
11833
+ label: "Edit shipping option",
11834
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11835
+ onClick: () => {
11836
+ setIsOpen(
11837
+ STACKED_FOCUS_MODAL_ID,
11838
+ true
11839
+ );
11840
+ setData({
11841
+ shippingProfileId: profile.id,
11842
+ shippingOption,
11843
+ shippingMethod
11844
+ });
11845
+ }
11846
+ } : void 0,
11847
+ {
11848
+ label: "Remove shipping option",
11849
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11850
+ onClick: () => {
11851
+ if (shippingMethod) {
11852
+ if (addShippingMethodAction) {
11853
+ removeActionShippingMethod(
11854
+ addShippingMethodAction.id
11855
+ );
11856
+ } else {
11857
+ removeShippingMethod(
11858
+ shippingMethod.id
11859
+ );
11860
+ }
11861
+ }
11862
+ }
11863
+ }
11864
+ ].filter(Boolean)
11865
+ }
11866
+ ]
11867
+ }
11868
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
11869
+ StackedModalTrigger,
11870
+ {
11871
+ shippingProfileId: profile.id,
11872
+ shippingOption,
11873
+ shippingMethod,
11874
+ setData,
11875
+ children: "Add shipping option"
11876
+ }
11877
+ )
11878
+ ] }),
11879
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11880
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11881
+ items.map((item, idx) => {
11882
+ var _a3, _b2, _c2, _d2, _e2;
11883
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11884
+ /* @__PURE__ */ jsxRuntime.jsxs(
11885
+ "div",
11886
+ {
11887
+ className: "px-3 flex items-center gap-x-3",
11888
+ children: [
11889
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11890
+ ui.Divider,
11891
+ {
11892
+ variant: "dashed",
11893
+ orientation: "vertical"
11894
+ }
11895
+ ) }),
11896
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11897
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11898
+ ui.Text,
11899
+ {
11900
+ size: "small",
11901
+ leading: "compact",
11902
+ className: "text-ui-fg-subtle",
11903
+ children: [
11904
+ item.quantity,
11905
+ "x"
11906
+ ]
11907
+ }
11908
+ ) }),
11909
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11910
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11911
+ /* @__PURE__ */ jsxRuntime.jsxs(
11912
+ ui.Text,
11913
+ {
11914
+ size: "small",
11915
+ leading: "compact",
11916
+ weight: "plus",
11917
+ children: [
11918
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11919
+ " (",
11920
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
11921
+ ")"
11922
+ ]
11923
+ }
11924
+ ),
11925
+ /* @__PURE__ */ jsxRuntime.jsx(
11926
+ ui.Text,
11927
+ {
11928
+ size: "small",
11929
+ leading: "compact",
11930
+ className: "text-ui-fg-subtle",
11931
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11932
+ }
11933
+ )
11934
+ ] })
11935
+ ] })
11936
+ ]
11937
+ },
11938
+ item.id
11939
+ ),
11940
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11941
+ ] }, item.id);
11942
+ })
11943
+ ] })
12015
11944
  ]
12016
- }
12017
- )
12018
- ]
12019
- },
12020
- item.id
12021
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12022
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12023
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12024
- 'No items found for "',
12025
- query,
12026
- '".'
12027
- ] })
12028
- ] }) })
12029
- ] })
12030
- ] });
12031
- };
12032
- const LocationField = ({ control, setValue }) => {
12033
- const locations = useComboboxData({
12034
- queryKey: ["locations"],
12035
- queryFn: async (params) => {
12036
- return await sdk.admin.stockLocation.list(params);
12037
- },
12038
- getOptions: (data) => {
12039
- return data.stock_locations.map((location) => ({
12040
- label: location.name,
12041
- value: location.id
12042
- }));
12043
- }
12044
- });
12045
- return /* @__PURE__ */ jsxRuntime.jsx(
12046
- Form$2.Field,
12047
- {
12048
- control,
12049
- name: "location_id",
12050
- render: ({ field: { onChange, ...field } }) => {
12051
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12052
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12053
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12054
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12055
- ] }),
12056
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12057
- Combobox,
12058
- {
12059
- options: locations.options,
12060
- fetchNextPage: locations.fetchNextPage,
12061
- isFetchingNextPage: locations.isFetchingNextPage,
12062
- searchValue: locations.searchValue,
12063
- onSearchValueChange: locations.onSearchValueChange,
12064
- placeholder: "Select location",
12065
- onChange: (value) => {
12066
- setValue("shipping_option_id", "", {
12067
- shouldDirty: true,
12068
- shouldTouch: true
12069
- });
12070
- onChange(value);
12071
11945
  },
12072
- ...field
11946
+ profile.id
11947
+ );
11948
+ }) })
11949
+ ] }) })
11950
+ ] }) }),
11951
+ /* @__PURE__ */ jsxRuntime.jsx(
11952
+ StackedFocusModal,
11953
+ {
11954
+ id: STACKED_FOCUS_MODAL_ID,
11955
+ onOpenChangeCallback: (open) => {
11956
+ if (!open) {
11957
+ setData(null);
12073
11958
  }
12074
- ) })
12075
- ] }) });
12076
- }
12077
- }
12078
- );
11959
+ return open;
11960
+ },
11961
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11962
+ }
11963
+ )
11964
+ ] }),
11965
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11966
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11967
+ /* @__PURE__ */ jsxRuntime.jsx(
11968
+ ui.Button,
11969
+ {
11970
+ size: "small",
11971
+ type: "button",
11972
+ isLoading: isSubmitting,
11973
+ onClick: onSubmit,
11974
+ children: "Save"
11975
+ }
11976
+ )
11977
+ ] }) })
11978
+ ] });
12079
11979
  };
12080
- const ShippingOptionField = ({
11980
+ const StackedModalTrigger = ({
12081
11981
  shippingProfileId,
12082
- preview,
12083
- control
11982
+ shippingOption,
11983
+ shippingMethod,
11984
+ setData,
11985
+ children
12084
11986
  }) => {
12085
- var _a;
12086
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12087
- const shippingOptions = useComboboxData({
12088
- queryKey: ["shipping_options", locationId, shippingProfileId],
12089
- queryFn: async (params) => {
12090
- return await sdk.admin.shippingOption.list({
12091
- ...params,
12092
- stock_location_id: locationId,
12093
- shipping_profile_id: shippingProfileId
11987
+ const { setIsOpen, getIsOpen } = useStackedModal();
11988
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11989
+ const onToggle = () => {
11990
+ if (isOpen) {
11991
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11992
+ setData(null);
11993
+ } else {
11994
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11995
+ setData({
11996
+ shippingProfileId,
11997
+ shippingOption,
11998
+ shippingMethod
12094
11999
  });
12095
- },
12096
- getOptions: (data) => {
12097
- return data.shipping_options.map((option) => {
12098
- var _a2;
12099
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12100
- (r) => r.attribute === "is_return" && r.value === "true"
12101
- )) {
12102
- return void 0;
12103
- }
12104
- return {
12105
- label: option.name,
12106
- value: option.id
12107
- };
12108
- }).filter(Boolean);
12109
- },
12110
- enabled: !!locationId && !!shippingProfileId,
12111
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12112
- });
12113
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12114
- return /* @__PURE__ */ jsxRuntime.jsx(
12115
- Form$2.Field,
12116
- {
12117
- control,
12118
- name: "shipping_option_id",
12119
- render: ({ field }) => {
12120
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12121
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12122
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12123
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12124
- ] }),
12125
- /* @__PURE__ */ jsxRuntime.jsx(
12126
- ConditionalTooltip,
12127
- {
12128
- content: tooltipContent,
12129
- showTooltip: !locationId || !shippingProfileId,
12130
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12131
- Combobox,
12132
- {
12133
- options: shippingOptions.options,
12134
- fetchNextPage: shippingOptions.fetchNextPage,
12135
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12136
- searchValue: shippingOptions.searchValue,
12137
- onSearchValueChange: shippingOptions.onSearchValueChange,
12138
- placeholder: "Select shipping option",
12139
- ...field,
12140
- disabled: !locationId || !shippingProfileId
12141
- }
12142
- ) }) })
12143
- }
12144
- )
12145
- ] }) });
12146
- }
12147
12000
  }
12148
- );
12149
- };
12150
- const CustomAmountField = ({
12151
- control,
12152
- currencyCode
12153
- }) => {
12001
+ };
12154
12002
  return /* @__PURE__ */ jsxRuntime.jsx(
12155
- Form$2.Field,
12003
+ ui.Button,
12156
12004
  {
12157
- control,
12158
- name: "custom_amount",
12159
- render: ({ field: { onChange, ...field } }) => {
12160
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12161
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12162
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12163
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12164
- ] }),
12165
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12166
- ui.CurrencyInput,
12167
- {
12168
- ...field,
12169
- onValueChange: (value) => onChange(value),
12170
- symbol: getNativeSymbol(currencyCode),
12171
- code: currencyCode
12172
- }
12173
- ) })
12174
- ] });
12175
- }
12005
+ size: "small",
12006
+ variant: "secondary",
12007
+ onClick: onToggle,
12008
+ className: "text-ui-fg-primary shrink-0",
12009
+ children
12176
12010
  }
12177
12011
  );
12178
12012
  };
12179
- const ShippingAddress = () => {
12180
- const { id } = reactRouterDom.useParams();
12181
- const { order, isPending, isError, error } = useOrder(id, {
12182
- fields: "+shipping_address"
12183
- });
12184
- if (isError) {
12185
- throw error;
12186
- }
12187
- const isReady = !isPending && !!order;
12188
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12189
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12190
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12191
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12192
- ] }),
12193
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12194
- ] });
12195
- };
12196
- const ShippingAddressForm = ({ order }) => {
12197
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12013
+ const ShippingProfileForm = ({
12014
+ data,
12015
+ order,
12016
+ preview
12017
+ }) => {
12018
+ var _a, _b, _c, _d, _e, _f;
12019
+ const { setIsOpen } = useStackedModal();
12198
12020
  const form = reactHookForm.useForm({
12021
+ resolver: zod.zodResolver(shippingMethodSchema),
12199
12022
  defaultValues: {
12200
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12201
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12202
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12203
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12204
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12205
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12206
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12207
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12208
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12209
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12210
- },
12211
- resolver: zod.zodResolver(schema$2)
12023
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12024
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12025
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12026
+ }
12212
12027
  });
12213
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12214
- const { handleSuccess } = useRouteModal();
12215
- const onSubmit = form.handleSubmit(async (data) => {
12216
- await mutateAsync(
12217
- {
12218
- shipping_address: {
12219
- first_name: data.first_name,
12220
- last_name: data.last_name,
12221
- company: data.company,
12222
- address_1: data.address_1,
12223
- address_2: data.address_2,
12224
- city: data.city,
12225
- province: data.province,
12226
- country_code: data.country_code,
12227
- postal_code: data.postal_code,
12228
- phone: data.phone
12028
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12029
+ const {
12030
+ mutateAsync: updateShippingMethod,
12031
+ isPending: isUpdatingShippingMethod
12032
+ } = useDraftOrderUpdateShippingMethod(order.id);
12033
+ const onSubmit = form.handleSubmit(async (values) => {
12034
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12035
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12036
+ return;
12037
+ }
12038
+ if (data.shippingMethod) {
12039
+ await updateShippingMethod(
12040
+ {
12041
+ method_id: data.shippingMethod.id,
12042
+ shipping_option_id: values.shipping_option_id,
12043
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12044
+ },
12045
+ {
12046
+ onError: (e) => {
12047
+ ui.toast.error(e.message);
12048
+ },
12049
+ onSuccess: () => {
12050
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12051
+ }
12229
12052
  }
12053
+ );
12054
+ return;
12055
+ }
12056
+ await addShippingMethod(
12057
+ {
12058
+ shipping_option_id: values.shipping_option_id,
12059
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12230
12060
  },
12231
12061
  {
12232
- onSuccess: () => {
12233
- handleSuccess();
12062
+ onError: (e) => {
12063
+ ui.toast.error(e.message);
12234
12064
  },
12235
- onError: (error) => {
12236
- ui.toast.error(error.message);
12065
+ onSuccess: () => {
12066
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12237
12067
  }
12238
12068
  }
12239
12069
  );
12240
12070
  });
12241
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12071
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12242
12072
  KeyboundForm,
12243
12073
  {
12244
- className: "flex flex-1 flex-col overflow-hidden",
12074
+ className: "flex h-full flex-col overflow-hidden",
12245
12075
  onSubmit,
12246
12076
  children: [
12247
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12077
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12078
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12079
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12080
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12081
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12082
+ ] }),
12083
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12248
12084
  /* @__PURE__ */ jsxRuntime.jsx(
12249
- Form$2.Field,
12085
+ LocationField,
12250
12086
  {
12251
12087
  control: form.control,
12252
- name: "country_code",
12253
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12254
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12255
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12256
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12257
- ] })
12088
+ setValue: form.setValue
12258
12089
  }
12259
12090
  ),
12260
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12261
- /* @__PURE__ */ jsxRuntime.jsx(
12262
- Form$2.Field,
12263
- {
12264
- control: form.control,
12265
- name: "first_name",
12266
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12267
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12268
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12269
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12270
- ] })
12271
- }
12272
- ),
12273
- /* @__PURE__ */ jsxRuntime.jsx(
12274
- Form$2.Field,
12275
- {
12276
- control: form.control,
12277
- name: "last_name",
12278
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12279
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12280
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12281
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12282
- ] })
12283
- }
12284
- )
12285
- ] }),
12091
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12286
12092
  /* @__PURE__ */ jsxRuntime.jsx(
12287
- Form$2.Field,
12093
+ ShippingOptionField,
12288
12094
  {
12289
- control: form.control,
12290
- name: "company",
12291
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12292
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12293
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12294
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12295
- ] })
12095
+ shippingProfileId: data.shippingProfileId,
12096
+ preview,
12097
+ control: form.control
12296
12098
  }
12297
12099
  ),
12100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12298
12101
  /* @__PURE__ */ jsxRuntime.jsx(
12299
- Form$2.Field,
12102
+ CustomAmountField,
12300
12103
  {
12301
12104
  control: form.control,
12302
- name: "address_1",
12303
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12304
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12305
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12306
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12307
- ] })
12105
+ currencyCode: order.currency_code
12308
12106
  }
12309
12107
  ),
12108
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12310
12109
  /* @__PURE__ */ jsxRuntime.jsx(
12311
- Form$2.Field,
12110
+ ItemsPreview,
12312
12111
  {
12313
- control: form.control,
12314
- name: "address_2",
12315
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12316
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12317
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12318
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12319
- ] })
12112
+ order,
12113
+ shippingProfileId: data.shippingProfileId
12320
12114
  }
12321
- ),
12322
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12323
- /* @__PURE__ */ jsxRuntime.jsx(
12324
- Form$2.Field,
12325
- {
12326
- control: form.control,
12327
- name: "postal_code",
12328
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12329
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12330
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12331
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12332
- ] })
12333
- }
12334
- ),
12335
- /* @__PURE__ */ jsxRuntime.jsx(
12336
- Form$2.Field,
12337
- {
12338
- control: form.control,
12339
- name: "city",
12340
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12342
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12343
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12344
- ] })
12115
+ )
12116
+ ] }) }) }),
12117
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12118
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12119
+ /* @__PURE__ */ jsxRuntime.jsx(
12120
+ ui.Button,
12121
+ {
12122
+ size: "small",
12123
+ type: "submit",
12124
+ isLoading: isPending || isUpdatingShippingMethod,
12125
+ children: data.shippingMethod ? "Update" : "Add"
12126
+ }
12127
+ )
12128
+ ] }) })
12129
+ ]
12130
+ }
12131
+ ) }) });
12132
+ };
12133
+ const shippingMethodSchema = objectType({
12134
+ location_id: stringType(),
12135
+ shipping_option_id: stringType(),
12136
+ custom_amount: unionType([numberType(), stringType()]).optional()
12137
+ });
12138
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12139
+ const matches = order.items.filter(
12140
+ (item) => {
12141
+ var _a, _b, _c;
12142
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12143
+ }
12144
+ );
12145
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12146
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12147
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12148
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12149
+ ] }) }),
12150
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12151
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12152
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12153
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12154
+ ] }),
12155
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12156
+ "div",
12157
+ {
12158
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12159
+ children: [
12160
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12161
+ /* @__PURE__ */ jsxRuntime.jsx(
12162
+ Thumbnail,
12163
+ {
12164
+ thumbnail: item.thumbnail,
12165
+ alt: item.product_title ?? void 0
12166
+ }
12167
+ ),
12168
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12169
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12170
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12171
+ /* @__PURE__ */ jsxRuntime.jsxs(
12172
+ ui.Text,
12173
+ {
12174
+ size: "small",
12175
+ leading: "compact",
12176
+ className: "text-ui-fg-subtle",
12177
+ children: [
12178
+ "(",
12179
+ item.variant_title,
12180
+ ")"
12181
+ ]
12182
+ }
12183
+ )
12184
+ ] }),
12185
+ /* @__PURE__ */ jsxRuntime.jsx(
12186
+ ui.Text,
12187
+ {
12188
+ size: "small",
12189
+ leading: "compact",
12190
+ className: "text-ui-fg-subtle",
12191
+ children: item.variant_sku
12192
+ }
12193
+ )
12194
+ ] })
12195
+ ] }),
12196
+ /* @__PURE__ */ jsxRuntime.jsxs(
12197
+ ui.Text,
12198
+ {
12199
+ size: "small",
12200
+ leading: "compact",
12201
+ className: "text-ui-fg-subtle",
12202
+ children: [
12203
+ item.quantity,
12204
+ "x"
12205
+ ]
12345
12206
  }
12346
12207
  )
12208
+ ]
12209
+ },
12210
+ item.id
12211
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12212
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12213
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12214
+ 'No items found for "',
12215
+ query,
12216
+ '".'
12217
+ ] })
12218
+ ] }) })
12219
+ ] })
12220
+ ] });
12221
+ };
12222
+ const LocationField = ({ control, setValue }) => {
12223
+ const locations = useComboboxData({
12224
+ queryKey: ["locations"],
12225
+ queryFn: async (params) => {
12226
+ return await sdk.admin.stockLocation.list(params);
12227
+ },
12228
+ getOptions: (data) => {
12229
+ return data.stock_locations.map((location) => ({
12230
+ label: location.name,
12231
+ value: location.id
12232
+ }));
12233
+ }
12234
+ });
12235
+ return /* @__PURE__ */ jsxRuntime.jsx(
12236
+ Form$2.Field,
12237
+ {
12238
+ control,
12239
+ name: "location_id",
12240
+ render: ({ field: { onChange, ...field } }) => {
12241
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12242
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12243
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12244
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12347
12245
  ] }),
12348
- /* @__PURE__ */ jsxRuntime.jsx(
12349
- Form$2.Field,
12246
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12247
+ Combobox,
12350
12248
  {
12351
- control: form.control,
12352
- name: "province",
12353
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12355
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12356
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12357
- ] })
12249
+ options: locations.options,
12250
+ fetchNextPage: locations.fetchNextPage,
12251
+ isFetchingNextPage: locations.isFetchingNextPage,
12252
+ searchValue: locations.searchValue,
12253
+ onSearchValueChange: locations.onSearchValueChange,
12254
+ placeholder: "Select location",
12255
+ onChange: (value) => {
12256
+ setValue("shipping_option_id", "", {
12257
+ shouldDirty: true,
12258
+ shouldTouch: true
12259
+ });
12260
+ onChange(value);
12261
+ },
12262
+ ...field
12358
12263
  }
12359
- ),
12264
+ ) })
12265
+ ] }) });
12266
+ }
12267
+ }
12268
+ );
12269
+ };
12270
+ const ShippingOptionField = ({
12271
+ shippingProfileId,
12272
+ preview,
12273
+ control
12274
+ }) => {
12275
+ var _a;
12276
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12277
+ const shippingOptions = useComboboxData({
12278
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12279
+ queryFn: async (params) => {
12280
+ return await sdk.admin.shippingOption.list({
12281
+ ...params,
12282
+ stock_location_id: locationId,
12283
+ shipping_profile_id: shippingProfileId
12284
+ });
12285
+ },
12286
+ getOptions: (data) => {
12287
+ return data.shipping_options.map((option) => {
12288
+ var _a2;
12289
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12290
+ (r) => r.attribute === "is_return" && r.value === "true"
12291
+ )) {
12292
+ return void 0;
12293
+ }
12294
+ return {
12295
+ label: option.name,
12296
+ value: option.id
12297
+ };
12298
+ }).filter(Boolean);
12299
+ },
12300
+ enabled: !!locationId && !!shippingProfileId,
12301
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12302
+ });
12303
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12304
+ return /* @__PURE__ */ jsxRuntime.jsx(
12305
+ Form$2.Field,
12306
+ {
12307
+ control,
12308
+ name: "shipping_option_id",
12309
+ render: ({ field }) => {
12310
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12311
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12312
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12313
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12314
+ ] }),
12360
12315
  /* @__PURE__ */ jsxRuntime.jsx(
12361
- Form$2.Field,
12316
+ ConditionalTooltip,
12362
12317
  {
12363
- control: form.control,
12364
- name: "phone",
12365
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12367
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12368
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12369
- ] })
12318
+ content: tooltipContent,
12319
+ showTooltip: !locationId || !shippingProfileId,
12320
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12321
+ Combobox,
12322
+ {
12323
+ options: shippingOptions.options,
12324
+ fetchNextPage: shippingOptions.fetchNextPage,
12325
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12326
+ searchValue: shippingOptions.searchValue,
12327
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12328
+ placeholder: "Select shipping option",
12329
+ ...field,
12330
+ disabled: !locationId || !shippingProfileId
12331
+ }
12332
+ ) }) })
12370
12333
  }
12371
12334
  )
12372
- ] }) }),
12373
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12374
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12375
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12376
- ] }) })
12377
- ]
12335
+ ] }) });
12336
+ }
12378
12337
  }
12379
- ) });
12338
+ );
12339
+ };
12340
+ const CustomAmountField = ({
12341
+ control,
12342
+ currencyCode
12343
+ }) => {
12344
+ return /* @__PURE__ */ jsxRuntime.jsx(
12345
+ Form$2.Field,
12346
+ {
12347
+ control,
12348
+ name: "custom_amount",
12349
+ render: ({ field: { onChange, ...field } }) => {
12350
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12351
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12353
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12354
+ ] }),
12355
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12356
+ ui.CurrencyInput,
12357
+ {
12358
+ ...field,
12359
+ onValueChange: (value) => onChange(value),
12360
+ symbol: getNativeSymbol(currencyCode),
12361
+ code: currencyCode
12362
+ }
12363
+ ) })
12364
+ ] });
12365
+ }
12366
+ }
12367
+ );
12380
12368
  };
12381
- const schema$2 = addressSchema;
12382
12369
  const TransferOwnership = () => {
12383
12370
  const { id } = reactRouterDom.useParams();
12384
12371
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12855,10 +12842,10 @@ const Illustration = () => {
12855
12842
  const schema$1 = objectType({
12856
12843
  customer_id: stringType().min(1)
12857
12844
  });
12858
- const BillingAddress = () => {
12845
+ const ShippingAddress = () => {
12859
12846
  const { id } = reactRouterDom.useParams();
12860
12847
  const { order, isPending, isError, error } = useOrder(id, {
12861
- fields: "+billing_address"
12848
+ fields: "+shipping_address"
12862
12849
  });
12863
12850
  if (isError) {
12864
12851
  throw error;
@@ -12866,26 +12853,26 @@ const BillingAddress = () => {
12866
12853
  const isReady = !isPending && !!order;
12867
12854
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12868
12855
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12869
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12870
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12856
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12857
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12871
12858
  ] }),
12872
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12859
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12873
12860
  ] });
12874
12861
  };
12875
- const BillingAddressForm = ({ order }) => {
12862
+ const ShippingAddressForm = ({ order }) => {
12876
12863
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12877
12864
  const form = reactHookForm.useForm({
12878
12865
  defaultValues: {
12879
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12880
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12881
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12882
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12883
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12884
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12885
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12886
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12887
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12888
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12866
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12867
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12868
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12869
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12870
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12871
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12872
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12873
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12874
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12875
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12889
12876
  },
12890
12877
  resolver: zod.zodResolver(schema)
12891
12878
  });
@@ -12893,7 +12880,20 @@ const BillingAddressForm = ({ order }) => {
12893
12880
  const { handleSuccess } = useRouteModal();
12894
12881
  const onSubmit = form.handleSubmit(async (data) => {
12895
12882
  await mutateAsync(
12896
- { billing_address: data },
12883
+ {
12884
+ shipping_address: {
12885
+ first_name: data.first_name,
12886
+ last_name: data.last_name,
12887
+ company: data.company,
12888
+ address_1: data.address_1,
12889
+ address_2: data.address_2,
12890
+ city: data.city,
12891
+ province: data.province,
12892
+ country_code: data.country_code,
12893
+ postal_code: data.postal_code,
12894
+ phone: data.phone
12895
+ }
12896
+ },
12897
12897
  {
12898
12898
  onSuccess: () => {
12899
12899
  handleSuccess();
@@ -13065,6 +13065,10 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
+ {
13069
+ Component: BillingAddress,
13070
+ path: "/draft-orders/:id/billing-address"
13071
+ },
13068
13072
  {
13069
13073
  Component: CustomItems,
13070
13074
  path: "/draft-orders/:id/custom-items"
@@ -13077,14 +13081,14 @@ const routeModule = {
13077
13081
  Component: Items,
13078
13082
  path: "/draft-orders/:id/items"
13079
13083
  },
13080
- {
13081
- Component: Promotions,
13082
- path: "/draft-orders/:id/promotions"
13083
- },
13084
13084
  {
13085
13085
  Component: Metadata,
13086
13086
  path: "/draft-orders/:id/metadata"
13087
13087
  },
13088
+ {
13089
+ Component: Promotions,
13090
+ path: "/draft-orders/:id/promotions"
13091
+ },
13088
13092
  {
13089
13093
  Component: SalesChannel,
13090
13094
  path: "/draft-orders/:id/sales-channel"
@@ -13093,17 +13097,13 @@ const routeModule = {
13093
13097
  Component: Shipping,
13094
13098
  path: "/draft-orders/:id/shipping"
13095
13099
  },
13096
- {
13097
- Component: ShippingAddress,
13098
- path: "/draft-orders/:id/shipping-address"
13099
- },
13100
13100
  {
13101
13101
  Component: TransferOwnership,
13102
13102
  path: "/draft-orders/:id/transfer-ownership"
13103
13103
  },
13104
13104
  {
13105
- Component: BillingAddress,
13106
- path: "/draft-orders/:id/billing-address"
13105
+ Component: ShippingAddress,
13106
+ path: "/draft-orders/:id/shipping-address"
13107
13107
  }
13108
13108
  ]
13109
13109
  }