@medusajs/draft-order 2.10.2-snapshot-20250907130204 → 2.10.2-snapshot-20250907131935

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.
@@ -9567,31 +9567,10 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
- const CustomItems = () => {
9571
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9573
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9574
- ] });
9575
- };
9576
- const CustomItemsForm = () => {
9577
- const form = useForm({
9578
- resolver: zodResolver(schema$5)
9579
- });
9580
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9582
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9583
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9584
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9585
- ] }) })
9586
- ] }) });
9587
- };
9588
- const schema$5 = objectType({
9589
- email: stringType().email()
9590
- });
9591
- const Email = () => {
9570
+ const BillingAddress = () => {
9592
9571
  const { id } = useParams();
9593
9572
  const { order, isPending, isError, error } = useOrder(id, {
9594
- fields: "+email"
9573
+ fields: "+billing_address"
9595
9574
  });
9596
9575
  if (isError) {
9597
9576
  throw error;
@@ -9599,24 +9578,34 @@ const Email = () => {
9599
9578
  const isReady = !isPending && !!order;
9600
9579
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9601
9580
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9602
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9603
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9604
9583
  ] }),
9605
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9584
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9606
9585
  ] });
9607
9586
  };
9608
- const EmailForm = ({ order }) => {
9587
+ const BillingAddressForm = ({ order }) => {
9588
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9609
9589
  const form = useForm({
9610
9590
  defaultValues: {
9611
- email: order.email ?? ""
9591
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9612
9601
  },
9613
- resolver: zodResolver(schema$4)
9602
+ resolver: zodResolver(schema$5)
9614
9603
  });
9615
9604
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9616
9605
  const { handleSuccess } = useRouteModal();
9617
9606
  const onSubmit = form.handleSubmit(async (data) => {
9618
9607
  await mutateAsync(
9619
- { email: data.email },
9608
+ { billing_address: data },
9620
9609
  {
9621
9610
  onSuccess: () => {
9622
9611
  handleSuccess();
@@ -9633,18 +9622,132 @@ const EmailForm = ({ order }) => {
9633
9622
  className: "flex flex-1 flex-col overflow-hidden",
9634
9623
  onSubmit,
9635
9624
  children: [
9636
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9637
- Form$2.Field,
9638
- {
9639
- control: form.control,
9640
- name: "email",
9641
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9642
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9643
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9644
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9645
- ] })
9646
- }
9647
- ) }),
9625
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9626
+ /* @__PURE__ */ jsx(
9627
+ Form$2.Field,
9628
+ {
9629
+ control: form.control,
9630
+ name: "country_code",
9631
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
+ ] })
9636
+ }
9637
+ ),
9638
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
+ /* @__PURE__ */ jsx(
9640
+ Form$2.Field,
9641
+ {
9642
+ control: form.control,
9643
+ name: "first_name",
9644
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
+ ] })
9649
+ }
9650
+ ),
9651
+ /* @__PURE__ */ jsx(
9652
+ Form$2.Field,
9653
+ {
9654
+ control: form.control,
9655
+ name: "last_name",
9656
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
+ ] })
9661
+ }
9662
+ )
9663
+ ] }),
9664
+ /* @__PURE__ */ jsx(
9665
+ Form$2.Field,
9666
+ {
9667
+ control: form.control,
9668
+ name: "company",
9669
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
+ ] })
9674
+ }
9675
+ ),
9676
+ /* @__PURE__ */ jsx(
9677
+ Form$2.Field,
9678
+ {
9679
+ control: form.control,
9680
+ name: "address_1",
9681
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
+ ] })
9686
+ }
9687
+ ),
9688
+ /* @__PURE__ */ jsx(
9689
+ Form$2.Field,
9690
+ {
9691
+ control: form.control,
9692
+ name: "address_2",
9693
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
+ ] })
9698
+ }
9699
+ ),
9700
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
+ /* @__PURE__ */ jsx(
9702
+ Form$2.Field,
9703
+ {
9704
+ control: form.control,
9705
+ name: "postal_code",
9706
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
+ ] })
9711
+ }
9712
+ ),
9713
+ /* @__PURE__ */ jsx(
9714
+ Form$2.Field,
9715
+ {
9716
+ control: form.control,
9717
+ name: "city",
9718
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
+ ] })
9723
+ }
9724
+ )
9725
+ ] }),
9726
+ /* @__PURE__ */ jsx(
9727
+ Form$2.Field,
9728
+ {
9729
+ control: form.control,
9730
+ name: "province",
9731
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
+ ] })
9736
+ }
9737
+ ),
9738
+ /* @__PURE__ */ jsx(
9739
+ Form$2.Field,
9740
+ {
9741
+ control: form.control,
9742
+ name: "phone",
9743
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
+ ] })
9748
+ }
9749
+ )
9750
+ ] }) }),
9648
9751
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9649
9752
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9650
9753
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -9653,9 +9756,7 @@ const EmailForm = ({ order }) => {
9653
9756
  }
9654
9757
  ) });
9655
9758
  };
9656
- const schema$4 = objectType({
9657
- email: stringType().email()
9658
- });
9759
+ const schema$5 = addressSchema;
9659
9760
  const NumberInput = forwardRef(
9660
9761
  ({
9661
9762
  value,
@@ -10630,54 +10731,10 @@ const customItemSchema = objectType({
10630
10731
  quantity: numberType(),
10631
10732
  unit_price: unionType([numberType(), stringType()])
10632
10733
  });
10633
- const InlineTip = forwardRef(
10634
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10635
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10636
- return /* @__PURE__ */ jsxs(
10637
- "div",
10638
- {
10639
- ref,
10640
- className: clx(
10641
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10642
- className
10643
- ),
10644
- ...props,
10645
- children: [
10646
- /* @__PURE__ */ jsx(
10647
- "div",
10648
- {
10649
- role: "presentation",
10650
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10651
- "bg-ui-tag-orange-icon": variant === "warning"
10652
- })
10653
- }
10654
- ),
10655
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10656
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10657
- labelValue,
10658
- ":"
10659
- ] }),
10660
- " ",
10661
- children
10662
- ] })
10663
- ]
10664
- }
10665
- );
10666
- }
10667
- );
10668
- InlineTip.displayName = "InlineTip";
10669
- const MetadataFieldSchema = objectType({
10670
- key: stringType(),
10671
- disabled: booleanType().optional(),
10672
- value: anyType()
10673
- });
10674
- const MetadataSchema = objectType({
10675
- metadata: arrayType(MetadataFieldSchema)
10676
- });
10677
- const Metadata = () => {
10734
+ const Email = () => {
10678
10735
  const { id } = useParams();
10679
10736
  const { order, isPending, isError, error } = useOrder(id, {
10680
- fields: "metadata"
10737
+ fields: "+email"
10681
10738
  });
10682
10739
  if (isError) {
10683
10740
  throw error;
@@ -10685,26 +10742,159 @@ const Metadata = () => {
10685
10742
  const isReady = !isPending && !!order;
10686
10743
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10687
10744
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10688
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10689
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10745
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
10746
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10690
10747
  ] }),
10691
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10748
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10692
10749
  ] });
10693
10750
  };
10694
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10695
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10696
- const MetadataForm = ({ orderId, metadata }) => {
10697
- const { handleSuccess } = useRouteModal();
10698
- const hasUneditableRows = getHasUneditableRows(metadata);
10699
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10751
+ const EmailForm = ({ order }) => {
10700
10752
  const form = useForm({
10701
10753
  defaultValues: {
10702
- metadata: getDefaultValues(metadata)
10754
+ email: order.email ?? ""
10703
10755
  },
10704
- resolver: zodResolver(MetadataSchema)
10756
+ resolver: zodResolver(schema$4)
10705
10757
  });
10706
- const handleSubmit = form.handleSubmit(async (data) => {
10707
- const parsedData = parseValues(data);
10758
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10759
+ const { handleSuccess } = useRouteModal();
10760
+ const onSubmit = form.handleSubmit(async (data) => {
10761
+ await mutateAsync(
10762
+ { email: data.email },
10763
+ {
10764
+ onSuccess: () => {
10765
+ handleSuccess();
10766
+ },
10767
+ onError: (error) => {
10768
+ toast.error(error.message);
10769
+ }
10770
+ }
10771
+ );
10772
+ });
10773
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10774
+ KeyboundForm,
10775
+ {
10776
+ className: "flex flex-1 flex-col overflow-hidden",
10777
+ onSubmit,
10778
+ children: [
10779
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
10780
+ Form$2.Field,
10781
+ {
10782
+ control: form.control,
10783
+ name: "email",
10784
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10785
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
10786
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10787
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10788
+ ] })
10789
+ }
10790
+ ) }),
10791
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10792
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10793
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10794
+ ] }) })
10795
+ ]
10796
+ }
10797
+ ) });
10798
+ };
10799
+ const schema$4 = objectType({
10800
+ email: stringType().email()
10801
+ });
10802
+ const CustomItems = () => {
10803
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10804
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
10805
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
10806
+ ] });
10807
+ };
10808
+ const CustomItemsForm = () => {
10809
+ const form = useForm({
10810
+ resolver: zodResolver(schema$3)
10811
+ });
10812
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10813
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
10814
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10815
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10816
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
10817
+ ] }) })
10818
+ ] }) });
10819
+ };
10820
+ const schema$3 = objectType({
10821
+ email: stringType().email()
10822
+ });
10823
+ const InlineTip = forwardRef(
10824
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10825
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10826
+ return /* @__PURE__ */ jsxs(
10827
+ "div",
10828
+ {
10829
+ ref,
10830
+ className: clx(
10831
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10832
+ className
10833
+ ),
10834
+ ...props,
10835
+ children: [
10836
+ /* @__PURE__ */ jsx(
10837
+ "div",
10838
+ {
10839
+ role: "presentation",
10840
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10841
+ "bg-ui-tag-orange-icon": variant === "warning"
10842
+ })
10843
+ }
10844
+ ),
10845
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10846
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10847
+ labelValue,
10848
+ ":"
10849
+ ] }),
10850
+ " ",
10851
+ children
10852
+ ] })
10853
+ ]
10854
+ }
10855
+ );
10856
+ }
10857
+ );
10858
+ InlineTip.displayName = "InlineTip";
10859
+ const MetadataFieldSchema = objectType({
10860
+ key: stringType(),
10861
+ disabled: booleanType().optional(),
10862
+ value: anyType()
10863
+ });
10864
+ const MetadataSchema = objectType({
10865
+ metadata: arrayType(MetadataFieldSchema)
10866
+ });
10867
+ const Metadata = () => {
10868
+ const { id } = useParams();
10869
+ const { order, isPending, isError, error } = useOrder(id, {
10870
+ fields: "metadata"
10871
+ });
10872
+ if (isError) {
10873
+ throw error;
10874
+ }
10875
+ const isReady = !isPending && !!order;
10876
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10877
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10878
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10879
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10880
+ ] }),
10881
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10882
+ ] });
10883
+ };
10884
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10885
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10886
+ const MetadataForm = ({ orderId, metadata }) => {
10887
+ const { handleSuccess } = useRouteModal();
10888
+ const hasUneditableRows = getHasUneditableRows(metadata);
10889
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10890
+ const form = useForm({
10891
+ defaultValues: {
10892
+ metadata: getDefaultValues(metadata)
10893
+ },
10894
+ resolver: zodResolver(MetadataSchema)
10895
+ });
10896
+ const handleSubmit = form.handleSubmit(async (data) => {
10897
+ const parsedData = parseValues(data);
10708
10898
  await mutateAsync(
10709
10899
  {
10710
10900
  metadata: parsedData
@@ -10980,467 +11170,84 @@ function getHasUneditableRows(metadata) {
10980
11170
  (value) => !EDITABLE_TYPES.includes(typeof value)
10981
11171
  );
10982
11172
  }
10983
- const PROMOTION_QUERY_KEY = "promotions";
10984
- const promotionsQueryKeys = {
10985
- list: (query2) => [
10986
- PROMOTION_QUERY_KEY,
10987
- query2 ? query2 : void 0
10988
- ],
10989
- detail: (id, query2) => [
10990
- PROMOTION_QUERY_KEY,
10991
- id,
10992
- query2 ? query2 : void 0
10993
- ]
10994
- };
10995
- const usePromotions = (query2, options) => {
10996
- const { data, ...rest } = useQuery({
10997
- queryKey: promotionsQueryKeys.list(query2),
10998
- queryFn: async () => sdk.admin.promotion.list(query2),
10999
- ...options
11000
- });
11001
- return { ...data, ...rest };
11002
- };
11003
- const Promotions = () => {
11173
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11174
+ const Shipping = () => {
11175
+ var _a;
11004
11176
  const { id } = useParams();
11177
+ const { order, isPending, isError, error } = useOrder(id, {
11178
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11179
+ });
11005
11180
  const {
11006
11181
  order: preview,
11182
+ isPending: isPreviewPending,
11007
11183
  isError: isPreviewError,
11008
11184
  error: previewError
11009
- } = useOrderPreview(id, void 0);
11185
+ } = useOrderPreview(id);
11010
11186
  useInitiateOrderEdit({ preview });
11011
11187
  const { onCancel } = useCancelOrderEdit({ preview });
11188
+ if (isError) {
11189
+ throw error;
11190
+ }
11012
11191
  if (isPreviewError) {
11013
11192
  throw previewError;
11014
11193
  }
11015
- const isReady = !!preview;
11016
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11017
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11018
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11019
- ] });
11194
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11195
+ const isReady = preview && !isPreviewPending && order && !isPending;
11196
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11197
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11198
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11199
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11200
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11201
+ ] }) }) }),
11202
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11203
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11204
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11205
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11206
+ ] }) });
11020
11207
  };
11021
- const PromotionForm = ({ preview }) => {
11022
- const { items, shipping_methods } = preview;
11208
+ const ShippingForm = ({ preview, order }) => {
11209
+ var _a;
11210
+ const { setIsOpen } = useStackedModal();
11023
11211
  const [isSubmitting, setIsSubmitting] = useState(false);
11024
- const [comboboxValue, setComboboxValue] = useState("");
11025
- const { handleSuccess } = useRouteModal();
11026
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11027
- const promoIds = getPromotionIds(items, shipping_methods);
11028
- const { promotions, isPending, isError, error } = usePromotions(
11212
+ const [data, setData] = useState(null);
11213
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11214
+ const { shipping_options } = useShippingOptions(
11029
11215
  {
11030
- id: promoIds
11216
+ id: appliedShippingOptionIds,
11217
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11031
11218
  },
11032
11219
  {
11033
- enabled: !!promoIds.length
11220
+ enabled: appliedShippingOptionIds.length > 0
11034
11221
  }
11035
11222
  );
11036
- const comboboxData = useComboboxData({
11037
- queryKey: ["promotions", "combobox", promoIds],
11038
- queryFn: async (params) => {
11039
- return await sdk.admin.promotion.list({
11040
- ...params,
11041
- id: {
11042
- $nin: promoIds
11043
- }
11044
- });
11045
- },
11046
- getOptions: (data) => {
11047
- return data.promotions.map((promotion) => ({
11048
- label: promotion.code,
11049
- value: promotion.code
11050
- }));
11051
- }
11052
- });
11053
- const add = async (value) => {
11054
- if (!value) {
11055
- return;
11056
- }
11057
- addPromotions(
11058
- {
11059
- promo_codes: [value]
11060
- },
11061
- {
11062
- onError: (e) => {
11063
- toast.error(e.message);
11064
- comboboxData.onSearchValueChange("");
11065
- setComboboxValue("");
11066
- },
11067
- onSuccess: () => {
11068
- comboboxData.onSearchValueChange("");
11069
- setComboboxValue("");
11070
- }
11071
- }
11072
- );
11073
- };
11074
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11075
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11076
- const onSubmit = async () => {
11077
- setIsSubmitting(true);
11078
- let requestSucceeded = false;
11079
- await requestOrderEdit(void 0, {
11080
- onError: (e) => {
11081
- toast.error(e.message);
11082
- },
11083
- onSuccess: () => {
11084
- requestSucceeded = true;
11085
- }
11086
- });
11087
- if (!requestSucceeded) {
11088
- setIsSubmitting(false);
11089
- return;
11090
- }
11091
- await confirmOrderEdit(void 0, {
11092
- onError: (e) => {
11093
- toast.error(e.message);
11094
- },
11095
- onSuccess: () => {
11096
- handleSuccess();
11097
- },
11098
- onSettled: () => {
11099
- setIsSubmitting(false);
11100
- }
11101
- });
11102
- };
11103
- if (isError) {
11104
- throw error;
11105
- }
11106
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11107
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11108
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11109
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11110
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11111
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11112
- ] }),
11113
- /* @__PURE__ */ jsx(
11114
- Combobox,
11115
- {
11116
- id: "promotion-combobox",
11117
- "aria-describedby": "promotion-combobox-hint",
11118
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11119
- fetchNextPage: comboboxData.fetchNextPage,
11120
- options: comboboxData.options,
11121
- onSearchValueChange: comboboxData.onSearchValueChange,
11122
- searchValue: comboboxData.searchValue,
11123
- disabled: comboboxData.disabled || isAddingPromotions,
11124
- onChange: add,
11125
- value: comboboxValue
11126
- }
11127
- )
11128
- ] }),
11129
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11130
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11131
- PromotionItem,
11132
- {
11133
- promotion,
11134
- orderId: preview.id,
11135
- isLoading: isPending
11136
- },
11137
- promotion.id
11138
- )) })
11139
- ] }) }),
11140
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11141
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11142
- /* @__PURE__ */ jsx(
11143
- Button,
11144
- {
11145
- size: "small",
11146
- type: "submit",
11147
- isLoading: isSubmitting || isAddingPromotions,
11148
- children: "Save"
11149
- }
11150
- )
11151
- ] }) })
11152
- ] });
11153
- };
11154
- const PromotionItem = ({
11155
- promotion,
11156
- orderId,
11157
- isLoading
11158
- }) => {
11159
- var _a;
11160
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11161
- const onRemove = async () => {
11162
- removePromotions(
11163
- {
11164
- promo_codes: [promotion.code]
11165
- },
11166
- {
11167
- onError: (e) => {
11168
- toast.error(e.message);
11169
- }
11170
- }
11171
- );
11172
- };
11173
- const displayValue = getDisplayValue(promotion);
11174
- return /* @__PURE__ */ jsxs(
11175
- "div",
11176
- {
11177
- className: clx(
11178
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11179
- {
11180
- "animate-pulse": isLoading
11181
- }
11182
- ),
11183
- children: [
11184
- /* @__PURE__ */ jsxs("div", { children: [
11185
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11186
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11187
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11188
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11189
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11190
- ] }),
11191
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11192
- ] })
11193
- ] }),
11194
- /* @__PURE__ */ jsx(
11195
- IconButton,
11196
- {
11197
- size: "small",
11198
- type: "button",
11199
- variant: "transparent",
11200
- onClick: onRemove,
11201
- isLoading: isPending || isLoading,
11202
- children: /* @__PURE__ */ jsx(XMark, {})
11203
- }
11204
- )
11205
- ]
11206
- },
11207
- promotion.id
11208
- );
11209
- };
11210
- function getDisplayValue(promotion) {
11211
- var _a, _b, _c, _d;
11212
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11213
- if (!value) {
11214
- return null;
11215
- }
11216
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11217
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11218
- if (!currency) {
11219
- return null;
11220
- }
11221
- return getLocaleAmount(value, currency);
11222
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11223
- return formatPercentage(value);
11224
- }
11225
- return null;
11226
- }
11227
- const formatter = new Intl.NumberFormat([], {
11228
- style: "percent",
11229
- minimumFractionDigits: 2
11230
- });
11231
- const formatPercentage = (value, isPercentageValue = false) => {
11232
- let val = value || 0;
11233
- if (!isPercentageValue) {
11234
- val = val / 100;
11235
- }
11236
- return formatter.format(val);
11237
- };
11238
- function getPromotionIds(items, shippingMethods) {
11239
- const promotionIds = /* @__PURE__ */ new Set();
11240
- for (const item of items) {
11241
- if (item.adjustments) {
11242
- for (const adjustment of item.adjustments) {
11243
- if (adjustment.promotion_id) {
11244
- promotionIds.add(adjustment.promotion_id);
11245
- }
11246
- }
11247
- }
11248
- }
11249
- for (const shippingMethod of shippingMethods) {
11250
- if (shippingMethod.adjustments) {
11251
- for (const adjustment of shippingMethod.adjustments) {
11252
- if (adjustment.promotion_id) {
11253
- promotionIds.add(adjustment.promotion_id);
11254
- }
11255
- }
11256
- }
11257
- }
11258
- return Array.from(promotionIds);
11259
- }
11260
- const SalesChannel = () => {
11261
- const { id } = useParams();
11262
- const { draft_order, isPending, isError, error } = useDraftOrder(
11263
- id,
11264
- {
11265
- fields: "+sales_channel_id"
11266
- },
11267
- {
11268
- enabled: !!id
11269
- }
11270
- );
11271
- if (isError) {
11272
- throw error;
11273
- }
11274
- const ISrEADY = !!draft_order && !isPending;
11275
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11276
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11277
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11278
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11279
- ] }),
11280
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11281
- ] });
11282
- };
11283
- const SalesChannelForm = ({ order }) => {
11284
- const form = useForm({
11285
- defaultValues: {
11286
- sales_channel_id: order.sales_channel_id || ""
11287
- },
11288
- resolver: zodResolver(schema$3)
11289
- });
11290
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11291
- const { handleSuccess } = useRouteModal();
11292
- const onSubmit = form.handleSubmit(async (data) => {
11293
- await mutateAsync(
11294
- {
11295
- sales_channel_id: data.sales_channel_id
11296
- },
11297
- {
11298
- onSuccess: () => {
11299
- toast.success("Sales channel updated");
11300
- handleSuccess();
11301
- },
11302
- onError: (error) => {
11303
- toast.error(error.message);
11304
- }
11305
- }
11306
- );
11307
- });
11308
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11309
- KeyboundForm,
11310
- {
11311
- className: "flex flex-1 flex-col overflow-hidden",
11312
- onSubmit,
11313
- children: [
11314
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11315
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11316
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11317
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11318
- ] }) })
11319
- ]
11320
- }
11321
- ) });
11322
- };
11323
- const SalesChannelField = ({ control, order }) => {
11324
- const salesChannels = useComboboxData({
11325
- queryFn: async (params) => {
11326
- return await sdk.admin.salesChannel.list(params);
11327
- },
11328
- queryKey: ["sales-channels"],
11329
- getOptions: (data) => {
11330
- return data.sales_channels.map((salesChannel) => ({
11331
- label: salesChannel.name,
11332
- value: salesChannel.id
11333
- }));
11334
- },
11335
- defaultValue: order.sales_channel_id || void 0
11336
- });
11337
- return /* @__PURE__ */ jsx(
11338
- Form$2.Field,
11339
- {
11340
- control,
11341
- name: "sales_channel_id",
11342
- render: ({ field }) => {
11343
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11344
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11345
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11346
- Combobox,
11347
- {
11348
- options: salesChannels.options,
11349
- fetchNextPage: salesChannels.fetchNextPage,
11350
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11351
- searchValue: salesChannels.searchValue,
11352
- onSearchValueChange: salesChannels.onSearchValueChange,
11353
- placeholder: "Select sales channel",
11354
- ...field
11355
- }
11356
- ) }),
11357
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11358
- ] });
11359
- }
11360
- }
11361
- );
11362
- };
11363
- const schema$3 = objectType({
11364
- sales_channel_id: stringType().min(1)
11365
- });
11366
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11367
- const Shipping = () => {
11368
- var _a;
11369
- const { id } = useParams();
11370
- const { order, isPending, isError, error } = useOrder(id, {
11371
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11372
- });
11373
- const {
11374
- order: preview,
11375
- isPending: isPreviewPending,
11376
- isError: isPreviewError,
11377
- error: previewError
11378
- } = useOrderPreview(id);
11379
- useInitiateOrderEdit({ preview });
11380
- const { onCancel } = useCancelOrderEdit({ preview });
11381
- if (isError) {
11382
- throw error;
11383
- }
11384
- if (isPreviewError) {
11385
- throw previewError;
11386
- }
11387
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11388
- const isReady = preview && !isPreviewPending && order && !isPending;
11389
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11390
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11391
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11392
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11393
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11394
- ] }) }) }),
11395
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11396
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11397
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11398
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11399
- ] }) });
11400
- };
11401
- const ShippingForm = ({ preview, order }) => {
11402
- var _a;
11403
- const { setIsOpen } = useStackedModal();
11404
- const [isSubmitting, setIsSubmitting] = useState(false);
11405
- const [data, setData] = useState(null);
11406
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11407
- const { shipping_options } = useShippingOptions(
11408
- {
11409
- id: appliedShippingOptionIds,
11410
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11411
- },
11412
- {
11413
- enabled: appliedShippingOptionIds.length > 0
11414
- }
11415
- );
11416
- const uniqueShippingProfiles = useMemo(() => {
11417
- const profiles = /* @__PURE__ */ new Map();
11418
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11419
- profiles.set(profile.id, profile);
11420
- });
11421
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11422
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11423
- });
11424
- return Array.from(profiles.values());
11425
- }, [order.items, shipping_options]);
11426
- const { handleSuccess } = useRouteModal();
11427
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11428
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11429
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11430
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11431
- const onSubmit = async () => {
11432
- setIsSubmitting(true);
11433
- let requestSucceeded = false;
11434
- await requestOrderEdit(void 0, {
11435
- onError: (e) => {
11436
- toast.error(`Failed to request order edit: ${e.message}`);
11437
- },
11438
- onSuccess: () => {
11439
- requestSucceeded = true;
11440
- }
11441
- });
11442
- if (!requestSucceeded) {
11443
- setIsSubmitting(false);
11223
+ const uniqueShippingProfiles = useMemo(() => {
11224
+ const profiles = /* @__PURE__ */ new Map();
11225
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11226
+ profiles.set(profile.id, profile);
11227
+ });
11228
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11229
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11230
+ });
11231
+ return Array.from(profiles.values());
11232
+ }, [order.items, shipping_options]);
11233
+ const { handleSuccess } = useRouteModal();
11234
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11235
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11236
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11237
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11238
+ const onSubmit = async () => {
11239
+ setIsSubmitting(true);
11240
+ let requestSucceeded = false;
11241
+ await requestOrderEdit(void 0, {
11242
+ onError: (e) => {
11243
+ toast.error(`Failed to request order edit: ${e.message}`);
11244
+ },
11245
+ onSuccess: () => {
11246
+ requestSucceeded = true;
11247
+ }
11248
+ });
11249
+ if (!requestSucceeded) {
11250
+ setIsSubmitting(false);
11444
11251
  return;
11445
11252
  }
11446
11253
  await confirmOrderEdit(void 0, {
@@ -12164,12 +11971,118 @@ const CustomAmountField = ({
12164
11971
  symbol: getNativeSymbol(currencyCode),
12165
11972
  code: currencyCode
12166
11973
  }
12167
- ) })
11974
+ ) })
11975
+ ] });
11976
+ }
11977
+ }
11978
+ );
11979
+ };
11980
+ const SalesChannel = () => {
11981
+ const { id } = useParams();
11982
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11983
+ id,
11984
+ {
11985
+ fields: "+sales_channel_id"
11986
+ },
11987
+ {
11988
+ enabled: !!id
11989
+ }
11990
+ );
11991
+ if (isError) {
11992
+ throw error;
11993
+ }
11994
+ const ISrEADY = !!draft_order && !isPending;
11995
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11996
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11997
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11998
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11999
+ ] }),
12000
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12001
+ ] });
12002
+ };
12003
+ const SalesChannelForm = ({ order }) => {
12004
+ const form = useForm({
12005
+ defaultValues: {
12006
+ sales_channel_id: order.sales_channel_id || ""
12007
+ },
12008
+ resolver: zodResolver(schema$2)
12009
+ });
12010
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12011
+ const { handleSuccess } = useRouteModal();
12012
+ const onSubmit = form.handleSubmit(async (data) => {
12013
+ await mutateAsync(
12014
+ {
12015
+ sales_channel_id: data.sales_channel_id
12016
+ },
12017
+ {
12018
+ onSuccess: () => {
12019
+ toast.success("Sales channel updated");
12020
+ handleSuccess();
12021
+ },
12022
+ onError: (error) => {
12023
+ toast.error(error.message);
12024
+ }
12025
+ }
12026
+ );
12027
+ });
12028
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12029
+ KeyboundForm,
12030
+ {
12031
+ className: "flex flex-1 flex-col overflow-hidden",
12032
+ onSubmit,
12033
+ children: [
12034
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12035
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12036
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12037
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12038
+ ] }) })
12039
+ ]
12040
+ }
12041
+ ) });
12042
+ };
12043
+ const SalesChannelField = ({ control, order }) => {
12044
+ const salesChannels = useComboboxData({
12045
+ queryFn: async (params) => {
12046
+ return await sdk.admin.salesChannel.list(params);
12047
+ },
12048
+ queryKey: ["sales-channels"],
12049
+ getOptions: (data) => {
12050
+ return data.sales_channels.map((salesChannel) => ({
12051
+ label: salesChannel.name,
12052
+ value: salesChannel.id
12053
+ }));
12054
+ },
12055
+ defaultValue: order.sales_channel_id || void 0
12056
+ });
12057
+ return /* @__PURE__ */ jsx(
12058
+ Form$2.Field,
12059
+ {
12060
+ control,
12061
+ name: "sales_channel_id",
12062
+ render: ({ field }) => {
12063
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12064
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12065
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12066
+ Combobox,
12067
+ {
12068
+ options: salesChannels.options,
12069
+ fetchNextPage: salesChannels.fetchNextPage,
12070
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12071
+ searchValue: salesChannels.searchValue,
12072
+ onSearchValueChange: salesChannels.onSearchValueChange,
12073
+ placeholder: "Select sales channel",
12074
+ ...field
12075
+ }
12076
+ ) }),
12077
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12168
12078
  ] });
12169
12079
  }
12170
12080
  }
12171
12081
  );
12172
12082
  };
12083
+ const schema$2 = objectType({
12084
+ sales_channel_id: stringType().min(1)
12085
+ });
12173
12086
  const ShippingAddress = () => {
12174
12087
  const { id } = useParams();
12175
12088
  const { order, isPending, isError, error } = useOrder(id, {
@@ -12202,7 +12115,7 @@ const ShippingAddressForm = ({ order }) => {
12202
12115
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12203
12116
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12204
12117
  },
12205
- resolver: zodResolver(schema$2)
12118
+ resolver: zodResolver(schema$1)
12206
12119
  });
12207
12120
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12208
12121
  const { handleSuccess } = useRouteModal();
@@ -12372,7 +12285,284 @@ const ShippingAddressForm = ({ order }) => {
12372
12285
  }
12373
12286
  ) });
12374
12287
  };
12375
- const schema$2 = addressSchema;
12288
+ const schema$1 = addressSchema;
12289
+ const PROMOTION_QUERY_KEY = "promotions";
12290
+ const promotionsQueryKeys = {
12291
+ list: (query2) => [
12292
+ PROMOTION_QUERY_KEY,
12293
+ query2 ? query2 : void 0
12294
+ ],
12295
+ detail: (id, query2) => [
12296
+ PROMOTION_QUERY_KEY,
12297
+ id,
12298
+ query2 ? query2 : void 0
12299
+ ]
12300
+ };
12301
+ const usePromotions = (query2, options) => {
12302
+ const { data, ...rest } = useQuery({
12303
+ queryKey: promotionsQueryKeys.list(query2),
12304
+ queryFn: async () => sdk.admin.promotion.list(query2),
12305
+ ...options
12306
+ });
12307
+ return { ...data, ...rest };
12308
+ };
12309
+ const Promotions = () => {
12310
+ const { id } = useParams();
12311
+ const {
12312
+ order: preview,
12313
+ isError: isPreviewError,
12314
+ error: previewError
12315
+ } = useOrderPreview(id, void 0);
12316
+ useInitiateOrderEdit({ preview });
12317
+ const { onCancel } = useCancelOrderEdit({ preview });
12318
+ if (isPreviewError) {
12319
+ throw previewError;
12320
+ }
12321
+ const isReady = !!preview;
12322
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
12323
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
12324
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
12325
+ ] });
12326
+ };
12327
+ const PromotionForm = ({ preview }) => {
12328
+ const { items, shipping_methods } = preview;
12329
+ const [isSubmitting, setIsSubmitting] = useState(false);
12330
+ const [comboboxValue, setComboboxValue] = useState("");
12331
+ const { handleSuccess } = useRouteModal();
12332
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12333
+ const promoIds = getPromotionIds(items, shipping_methods);
12334
+ const { promotions, isPending, isError, error } = usePromotions(
12335
+ {
12336
+ id: promoIds
12337
+ },
12338
+ {
12339
+ enabled: !!promoIds.length
12340
+ }
12341
+ );
12342
+ const comboboxData = useComboboxData({
12343
+ queryKey: ["promotions", "combobox", promoIds],
12344
+ queryFn: async (params) => {
12345
+ return await sdk.admin.promotion.list({
12346
+ ...params,
12347
+ id: {
12348
+ $nin: promoIds
12349
+ }
12350
+ });
12351
+ },
12352
+ getOptions: (data) => {
12353
+ return data.promotions.map((promotion) => ({
12354
+ label: promotion.code,
12355
+ value: promotion.code
12356
+ }));
12357
+ }
12358
+ });
12359
+ const add = async (value) => {
12360
+ if (!value) {
12361
+ return;
12362
+ }
12363
+ addPromotions(
12364
+ {
12365
+ promo_codes: [value]
12366
+ },
12367
+ {
12368
+ onError: (e) => {
12369
+ toast.error(e.message);
12370
+ comboboxData.onSearchValueChange("");
12371
+ setComboboxValue("");
12372
+ },
12373
+ onSuccess: () => {
12374
+ comboboxData.onSearchValueChange("");
12375
+ setComboboxValue("");
12376
+ }
12377
+ }
12378
+ );
12379
+ };
12380
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12381
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12382
+ const onSubmit = async () => {
12383
+ setIsSubmitting(true);
12384
+ let requestSucceeded = false;
12385
+ await requestOrderEdit(void 0, {
12386
+ onError: (e) => {
12387
+ toast.error(e.message);
12388
+ },
12389
+ onSuccess: () => {
12390
+ requestSucceeded = true;
12391
+ }
12392
+ });
12393
+ if (!requestSucceeded) {
12394
+ setIsSubmitting(false);
12395
+ return;
12396
+ }
12397
+ await confirmOrderEdit(void 0, {
12398
+ onError: (e) => {
12399
+ toast.error(e.message);
12400
+ },
12401
+ onSuccess: () => {
12402
+ handleSuccess();
12403
+ },
12404
+ onSettled: () => {
12405
+ setIsSubmitting(false);
12406
+ }
12407
+ });
12408
+ };
12409
+ if (isError) {
12410
+ throw error;
12411
+ }
12412
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12413
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
12414
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
12415
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12416
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12417
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12418
+ ] }),
12419
+ /* @__PURE__ */ jsx(
12420
+ Combobox,
12421
+ {
12422
+ id: "promotion-combobox",
12423
+ "aria-describedby": "promotion-combobox-hint",
12424
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12425
+ fetchNextPage: comboboxData.fetchNextPage,
12426
+ options: comboboxData.options,
12427
+ onSearchValueChange: comboboxData.onSearchValueChange,
12428
+ searchValue: comboboxData.searchValue,
12429
+ disabled: comboboxData.disabled || isAddingPromotions,
12430
+ onChange: add,
12431
+ value: comboboxValue
12432
+ }
12433
+ )
12434
+ ] }),
12435
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12436
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
12437
+ PromotionItem,
12438
+ {
12439
+ promotion,
12440
+ orderId: preview.id,
12441
+ isLoading: isPending
12442
+ },
12443
+ promotion.id
12444
+ )) })
12445
+ ] }) }),
12446
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12447
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12448
+ /* @__PURE__ */ jsx(
12449
+ Button,
12450
+ {
12451
+ size: "small",
12452
+ type: "submit",
12453
+ isLoading: isSubmitting || isAddingPromotions,
12454
+ children: "Save"
12455
+ }
12456
+ )
12457
+ ] }) })
12458
+ ] });
12459
+ };
12460
+ const PromotionItem = ({
12461
+ promotion,
12462
+ orderId,
12463
+ isLoading
12464
+ }) => {
12465
+ var _a;
12466
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12467
+ const onRemove = async () => {
12468
+ removePromotions(
12469
+ {
12470
+ promo_codes: [promotion.code]
12471
+ },
12472
+ {
12473
+ onError: (e) => {
12474
+ toast.error(e.message);
12475
+ }
12476
+ }
12477
+ );
12478
+ };
12479
+ const displayValue = getDisplayValue(promotion);
12480
+ return /* @__PURE__ */ jsxs(
12481
+ "div",
12482
+ {
12483
+ className: clx(
12484
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12485
+ {
12486
+ "animate-pulse": isLoading
12487
+ }
12488
+ ),
12489
+ children: [
12490
+ /* @__PURE__ */ jsxs("div", { children: [
12491
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12492
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12493
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
12494
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
12495
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
12496
+ ] }),
12497
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12498
+ ] })
12499
+ ] }),
12500
+ /* @__PURE__ */ jsx(
12501
+ IconButton,
12502
+ {
12503
+ size: "small",
12504
+ type: "button",
12505
+ variant: "transparent",
12506
+ onClick: onRemove,
12507
+ isLoading: isPending || isLoading,
12508
+ children: /* @__PURE__ */ jsx(XMark, {})
12509
+ }
12510
+ )
12511
+ ]
12512
+ },
12513
+ promotion.id
12514
+ );
12515
+ };
12516
+ function getDisplayValue(promotion) {
12517
+ var _a, _b, _c, _d;
12518
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12519
+ if (!value) {
12520
+ return null;
12521
+ }
12522
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12523
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
12524
+ if (!currency) {
12525
+ return null;
12526
+ }
12527
+ return getLocaleAmount(value, currency);
12528
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
12529
+ return formatPercentage(value);
12530
+ }
12531
+ return null;
12532
+ }
12533
+ const formatter = new Intl.NumberFormat([], {
12534
+ style: "percent",
12535
+ minimumFractionDigits: 2
12536
+ });
12537
+ const formatPercentage = (value, isPercentageValue = false) => {
12538
+ let val = value || 0;
12539
+ if (!isPercentageValue) {
12540
+ val = val / 100;
12541
+ }
12542
+ return formatter.format(val);
12543
+ };
12544
+ function getPromotionIds(items, shippingMethods) {
12545
+ const promotionIds = /* @__PURE__ */ new Set();
12546
+ for (const item of items) {
12547
+ if (item.adjustments) {
12548
+ for (const adjustment of item.adjustments) {
12549
+ if (adjustment.promotion_id) {
12550
+ promotionIds.add(adjustment.promotion_id);
12551
+ }
12552
+ }
12553
+ }
12554
+ }
12555
+ for (const shippingMethod of shippingMethods) {
12556
+ if (shippingMethod.adjustments) {
12557
+ for (const adjustment of shippingMethod.adjustments) {
12558
+ if (adjustment.promotion_id) {
12559
+ promotionIds.add(adjustment.promotion_id);
12560
+ }
12561
+ }
12562
+ }
12563
+ }
12564
+ return Array.from(promotionIds);
12565
+ }
12376
12566
  const TransferOwnership = () => {
12377
12567
  const { id } = useParams();
12378
12568
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12396,7 +12586,7 @@ const TransferOwnershipForm = ({ order }) => {
12396
12586
  defaultValues: {
12397
12587
  customer_id: order.customer_id || ""
12398
12588
  },
12399
- resolver: zodResolver(schema$1)
12589
+ resolver: zodResolver(schema)
12400
12590
  });
12401
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12402
12592
  const { handleSuccess } = useRouteModal();
@@ -12846,199 +13036,9 @@ const Illustration = () => {
12846
13036
  }
12847
13037
  );
12848
13038
  };
12849
- const schema$1 = objectType({
13039
+ const schema = objectType({
12850
13040
  customer_id: stringType().min(1)
12851
13041
  });
12852
- const BillingAddress = () => {
12853
- const { id } = useParams();
12854
- const { order, isPending, isError, error } = useOrder(id, {
12855
- fields: "+billing_address"
12856
- });
12857
- if (isError) {
12858
- throw error;
12859
- }
12860
- const isReady = !isPending && !!order;
12861
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12863
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12864
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12865
- ] }),
12866
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12867
- ] });
12868
- };
12869
- const BillingAddressForm = ({ order }) => {
12870
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12871
- const form = useForm({
12872
- defaultValues: {
12873
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12874
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12875
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12876
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12877
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12878
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12879
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12880
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12881
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12882
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12883
- },
12884
- resolver: zodResolver(schema)
12885
- });
12886
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
- const { handleSuccess } = useRouteModal();
12888
- const onSubmit = form.handleSubmit(async (data) => {
12889
- await mutateAsync(
12890
- { billing_address: data },
12891
- {
12892
- onSuccess: () => {
12893
- handleSuccess();
12894
- },
12895
- onError: (error) => {
12896
- toast.error(error.message);
12897
- }
12898
- }
12899
- );
12900
- });
12901
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
- KeyboundForm,
12903
- {
12904
- className: "flex flex-1 flex-col overflow-hidden",
12905
- onSubmit,
12906
- children: [
12907
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12908
- /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12910
- {
12911
- control: form.control,
12912
- name: "country_code",
12913
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
- ] })
12918
- }
12919
- ),
12920
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
- /* @__PURE__ */ jsx(
12922
- Form$2.Field,
12923
- {
12924
- control: form.control,
12925
- name: "first_name",
12926
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
- ] })
12931
- }
12932
- ),
12933
- /* @__PURE__ */ jsx(
12934
- Form$2.Field,
12935
- {
12936
- control: form.control,
12937
- name: "last_name",
12938
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
- ] })
12943
- }
12944
- )
12945
- ] }),
12946
- /* @__PURE__ */ jsx(
12947
- Form$2.Field,
12948
- {
12949
- control: form.control,
12950
- name: "company",
12951
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
- ] })
12956
- }
12957
- ),
12958
- /* @__PURE__ */ jsx(
12959
- Form$2.Field,
12960
- {
12961
- control: form.control,
12962
- name: "address_1",
12963
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
- ] })
12968
- }
12969
- ),
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
12972
- {
12973
- control: form.control,
12974
- name: "address_2",
12975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
- ] })
12980
- }
12981
- ),
12982
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
- /* @__PURE__ */ jsx(
12984
- Form$2.Field,
12985
- {
12986
- control: form.control,
12987
- name: "postal_code",
12988
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
- ] })
12993
- }
12994
- ),
12995
- /* @__PURE__ */ jsx(
12996
- Form$2.Field,
12997
- {
12998
- control: form.control,
12999
- name: "city",
13000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
- ] })
13005
- }
13006
- )
13007
- ] }),
13008
- /* @__PURE__ */ jsx(
13009
- Form$2.Field,
13010
- {
13011
- control: form.control,
13012
- name: "province",
13013
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
- ] })
13018
- }
13019
- ),
13020
- /* @__PURE__ */ jsx(
13021
- Form$2.Field,
13022
- {
13023
- control: form.control,
13024
- name: "phone",
13025
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
- ] })
13030
- }
13031
- )
13032
- ] }) }),
13033
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13036
- ] }) })
13037
- ]
13038
- }
13039
- ) });
13040
- };
13041
- const schema = addressSchema;
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13060,44 +13060,44 @@ const routeModule = {
13060
13060
  loader,
13061
13061
  children: [
13062
13062
  {
13063
- Component: CustomItems,
13064
- path: "/draft-orders/:id/custom-items"
13063
+ Component: BillingAddress,
13064
+ path: "/draft-orders/:id/billing-address"
13065
+ },
13066
+ {
13067
+ Component: Items,
13068
+ path: "/draft-orders/:id/items"
13065
13069
  },
13066
13070
  {
13067
13071
  Component: Email,
13068
13072
  path: "/draft-orders/:id/email"
13069
13073
  },
13070
13074
  {
13071
- Component: Items,
13072
- path: "/draft-orders/:id/items"
13075
+ Component: CustomItems,
13076
+ path: "/draft-orders/:id/custom-items"
13073
13077
  },
13074
13078
  {
13075
13079
  Component: Metadata,
13076
13080
  path: "/draft-orders/:id/metadata"
13077
13081
  },
13078
13082
  {
13079
- Component: Promotions,
13080
- path: "/draft-orders/:id/promotions"
13083
+ Component: Shipping,
13084
+ path: "/draft-orders/:id/shipping"
13081
13085
  },
13082
13086
  {
13083
13087
  Component: SalesChannel,
13084
13088
  path: "/draft-orders/:id/sales-channel"
13085
13089
  },
13086
- {
13087
- Component: Shipping,
13088
- path: "/draft-orders/:id/shipping"
13089
- },
13090
13090
  {
13091
13091
  Component: ShippingAddress,
13092
13092
  path: "/draft-orders/:id/shipping-address"
13093
13093
  },
13094
13094
  {
13095
- Component: TransferOwnership,
13096
- path: "/draft-orders/:id/transfer-ownership"
13095
+ Component: Promotions,
13096
+ path: "/draft-orders/:id/promotions"
13097
13097
  },
13098
13098
  {
13099
- Component: BillingAddress,
13100
- path: "/draft-orders/:id/billing-address"
13099
+ Component: TransferOwnership,
13100
+ path: "/draft-orders/:id/transfer-ownership"
13101
13101
  }
13102
13102
  ]
13103
13103
  }