@medusajs/draft-order 2.11.1-preview-20251023000334 → 2.11.1-preview-20251023060204

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.
@@ -9565,27 +9565,196 @@ const ID = () => {
9565
9565
  /* @__PURE__ */ jsx(Outlet, {})
9566
9566
  ] });
9567
9567
  };
9568
- const CustomItems = () => {
9568
+ const BillingAddress = () => {
9569
+ const { id } = useParams();
9570
+ const { order, isPending, isError, error } = useOrder(id, {
9571
+ fields: "+billing_address"
9572
+ });
9573
+ if (isError) {
9574
+ throw error;
9575
+ }
9576
+ const isReady = !isPending && !!order;
9569
9577
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9570
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9571
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9578
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9579
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9580
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9581
+ ] }),
9582
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9572
9583
  ] });
9573
9584
  };
9574
- const CustomItemsForm = () => {
9585
+ const BillingAddressForm = ({ order }) => {
9586
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9575
9587
  const form = useForm({
9588
+ defaultValues: {
9589
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9590
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9591
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9592
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9593
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9594
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9595
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9596
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9597
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9598
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9599
+ },
9576
9600
  resolver: zodResolver(schema$5)
9577
9601
  });
9578
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9579
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9580
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9582
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9583
- ] }) })
9584
- ] }) });
9602
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9603
+ const { handleSuccess } = useRouteModal();
9604
+ const onSubmit = form.handleSubmit(async (data) => {
9605
+ await mutateAsync(
9606
+ { billing_address: data },
9607
+ {
9608
+ onSuccess: () => {
9609
+ handleSuccess();
9610
+ },
9611
+ onError: (error) => {
9612
+ toast.error(error.message);
9613
+ }
9614
+ }
9615
+ );
9616
+ });
9617
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9618
+ KeyboundForm,
9619
+ {
9620
+ className: "flex flex-1 flex-col overflow-hidden",
9621
+ onSubmit,
9622
+ children: [
9623
+ /* @__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: [
9624
+ /* @__PURE__ */ jsx(
9625
+ Form$2.Field,
9626
+ {
9627
+ control: form.control,
9628
+ name: "country_code",
9629
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9630
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9631
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9632
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9633
+ ] })
9634
+ }
9635
+ ),
9636
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9637
+ /* @__PURE__ */ jsx(
9638
+ Form$2.Field,
9639
+ {
9640
+ control: form.control,
9641
+ name: "first_name",
9642
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9643
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9644
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9645
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9646
+ ] })
9647
+ }
9648
+ ),
9649
+ /* @__PURE__ */ jsx(
9650
+ Form$2.Field,
9651
+ {
9652
+ control: form.control,
9653
+ name: "last_name",
9654
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9655
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9656
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9657
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9658
+ ] })
9659
+ }
9660
+ )
9661
+ ] }),
9662
+ /* @__PURE__ */ jsx(
9663
+ Form$2.Field,
9664
+ {
9665
+ control: form.control,
9666
+ name: "company",
9667
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9668
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9669
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9670
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9671
+ ] })
9672
+ }
9673
+ ),
9674
+ /* @__PURE__ */ jsx(
9675
+ Form$2.Field,
9676
+ {
9677
+ control: form.control,
9678
+ name: "address_1",
9679
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9680
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9681
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9682
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9683
+ ] })
9684
+ }
9685
+ ),
9686
+ /* @__PURE__ */ jsx(
9687
+ Form$2.Field,
9688
+ {
9689
+ control: form.control,
9690
+ name: "address_2",
9691
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9692
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9693
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9694
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9695
+ ] })
9696
+ }
9697
+ ),
9698
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9699
+ /* @__PURE__ */ jsx(
9700
+ Form$2.Field,
9701
+ {
9702
+ control: form.control,
9703
+ name: "postal_code",
9704
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9705
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9706
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9707
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9708
+ ] })
9709
+ }
9710
+ ),
9711
+ /* @__PURE__ */ jsx(
9712
+ Form$2.Field,
9713
+ {
9714
+ control: form.control,
9715
+ name: "city",
9716
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9717
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9718
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9719
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9720
+ ] })
9721
+ }
9722
+ )
9723
+ ] }),
9724
+ /* @__PURE__ */ jsx(
9725
+ Form$2.Field,
9726
+ {
9727
+ control: form.control,
9728
+ name: "province",
9729
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9730
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9731
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9732
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9733
+ ] })
9734
+ }
9735
+ ),
9736
+ /* @__PURE__ */ jsx(
9737
+ Form$2.Field,
9738
+ {
9739
+ control: form.control,
9740
+ name: "phone",
9741
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9742
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9743
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9744
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9745
+ ] })
9746
+ }
9747
+ )
9748
+ ] }) }),
9749
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9750
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9751
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9752
+ ] }) })
9753
+ ]
9754
+ }
9755
+ ) });
9585
9756
  };
9586
- const schema$5 = objectType({
9587
- email: stringType().email()
9588
- });
9757
+ const schema$5 = addressSchema;
9589
9758
  const Email = () => {
9590
9759
  const { id } = useParams();
9591
9760
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9654,6 +9823,27 @@ const EmailForm = ({ order }) => {
9654
9823
  const schema$4 = objectType({
9655
9824
  email: stringType().email()
9656
9825
  });
9826
+ const CustomItems = () => {
9827
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9828
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9829
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9830
+ ] });
9831
+ };
9832
+ const CustomItemsForm = () => {
9833
+ const form = useForm({
9834
+ resolver: zodResolver(schema$3)
9835
+ });
9836
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9837
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9838
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9839
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9840
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9841
+ ] }) })
9842
+ ] }) });
9843
+ };
9844
+ const schema$3 = objectType({
9845
+ email: stringType().email()
9846
+ });
9657
9847
  const NumberInput = forwardRef(
9658
9848
  ({
9659
9849
  value,
@@ -10628,229 +10818,39 @@ const customItemSchema = objectType({
10628
10818
  quantity: numberType(),
10629
10819
  unit_price: unionType([numberType(), stringType()])
10630
10820
  });
10631
- const BillingAddress = () => {
10632
- const { id } = useParams();
10633
- const { order, isPending, isError, error } = useOrder(id, {
10634
- fields: "+billing_address"
10635
- });
10636
- if (isError) {
10637
- throw error;
10638
- }
10639
- const isReady = !isPending && !!order;
10640
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10641
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10642
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
10643
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
10644
- ] }),
10645
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
10646
- ] });
10647
- };
10648
- const BillingAddressForm = ({ order }) => {
10649
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10650
- const form = useForm({
10651
- defaultValues: {
10652
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
10653
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
10654
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
10655
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
10656
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
10657
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
10658
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
10659
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
10660
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
10661
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
10662
- },
10663
- resolver: zodResolver(schema$3)
10664
- });
10665
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10666
- const { handleSuccess } = useRouteModal();
10667
- const onSubmit = form.handleSubmit(async (data) => {
10668
- await mutateAsync(
10669
- { billing_address: data },
10670
- {
10671
- onSuccess: () => {
10672
- handleSuccess();
10673
- },
10674
- onError: (error) => {
10675
- toast.error(error.message);
10676
- }
10677
- }
10678
- );
10679
- });
10680
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10681
- KeyboundForm,
10682
- {
10683
- className: "flex flex-1 flex-col overflow-hidden",
10684
- onSubmit,
10685
- children: [
10686
- /* @__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: [
10687
- /* @__PURE__ */ jsx(
10688
- Form$2.Field,
10689
- {
10690
- control: form.control,
10691
- name: "country_code",
10692
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10693
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
10694
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
10695
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10696
- ] })
10697
- }
10698
- ),
10699
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10700
- /* @__PURE__ */ jsx(
10701
- Form$2.Field,
10702
- {
10703
- control: form.control,
10704
- name: "first_name",
10705
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10706
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
10707
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10708
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10709
- ] })
10710
- }
10711
- ),
10712
- /* @__PURE__ */ jsx(
10713
- Form$2.Field,
10714
- {
10715
- control: form.control,
10716
- name: "last_name",
10717
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10718
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
10719
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10720
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10721
- ] })
10722
- }
10723
- )
10724
- ] }),
10725
- /* @__PURE__ */ jsx(
10726
- Form$2.Field,
10727
- {
10728
- control: form.control,
10729
- name: "company",
10730
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10731
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
10732
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10733
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10734
- ] })
10735
- }
10736
- ),
10737
- /* @__PURE__ */ jsx(
10738
- Form$2.Field,
10739
- {
10740
- control: form.control,
10741
- name: "address_1",
10742
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10743
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
10744
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10745
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10746
- ] })
10747
- }
10748
- ),
10749
- /* @__PURE__ */ jsx(
10750
- Form$2.Field,
10751
- {
10752
- control: form.control,
10753
- name: "address_2",
10754
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10755
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
10756
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10757
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10758
- ] })
10759
- }
10760
- ),
10761
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10762
- /* @__PURE__ */ jsx(
10763
- Form$2.Field,
10764
- {
10765
- control: form.control,
10766
- name: "postal_code",
10767
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10768
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
10769
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10770
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10771
- ] })
10772
- }
10773
- ),
10774
- /* @__PURE__ */ jsx(
10775
- Form$2.Field,
10776
- {
10777
- control: form.control,
10778
- name: "city",
10779
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10780
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
10781
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10782
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10783
- ] })
10784
- }
10785
- )
10786
- ] }),
10787
- /* @__PURE__ */ jsx(
10788
- Form$2.Field,
10789
- {
10790
- control: form.control,
10791
- name: "province",
10792
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10793
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
10794
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10795
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10796
- ] })
10797
- }
10798
- ),
10799
- /* @__PURE__ */ jsx(
10800
- Form$2.Field,
10801
- {
10802
- control: form.control,
10803
- name: "phone",
10804
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10805
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
10806
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10807
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10808
- ] })
10809
- }
10810
- )
10811
- ] }) }),
10812
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10813
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10814
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10815
- ] }) })
10816
- ]
10817
- }
10818
- ) });
10819
- };
10820
- const schema$3 = addressSchema;
10821
- const InlineTip = forwardRef(
10822
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10823
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10824
- return /* @__PURE__ */ jsxs(
10825
- "div",
10826
- {
10827
- ref,
10828
- className: clx(
10829
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10830
- className
10831
- ),
10832
- ...props,
10833
- children: [
10834
- /* @__PURE__ */ jsx(
10835
- "div",
10836
- {
10837
- role: "presentation",
10838
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10839
- "bg-ui-tag-orange-icon": variant === "warning"
10840
- })
10841
- }
10842
- ),
10843
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10844
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10845
- labelValue,
10846
- ":"
10847
- ] }),
10848
- " ",
10849
- children
10850
- ] })
10851
- ]
10852
- }
10853
- );
10821
+ const InlineTip = forwardRef(
10822
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10823
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10824
+ return /* @__PURE__ */ jsxs(
10825
+ "div",
10826
+ {
10827
+ ref,
10828
+ className: clx(
10829
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10830
+ className
10831
+ ),
10832
+ ...props,
10833
+ children: [
10834
+ /* @__PURE__ */ jsx(
10835
+ "div",
10836
+ {
10837
+ role: "presentation",
10838
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10839
+ "bg-ui-tag-orange-icon": variant === "warning"
10840
+ })
10841
+ }
10842
+ ),
10843
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10844
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10845
+ labelValue,
10846
+ ":"
10847
+ ] }),
10848
+ " ",
10849
+ children
10850
+ ] })
10851
+ ]
10852
+ }
10853
+ );
10854
10854
  }
10855
10855
  );
10856
10856
  InlineTip.displayName = "InlineTip";
@@ -11168,583 +11168,61 @@ function getHasUneditableRows(metadata) {
11168
11168
  (value) => !EDITABLE_TYPES.includes(typeof value)
11169
11169
  );
11170
11170
  }
11171
- const PROMOTION_QUERY_KEY = "promotions";
11172
- const promotionsQueryKeys = {
11173
- list: (query2) => [
11174
- PROMOTION_QUERY_KEY,
11175
- query2 ? query2 : void 0
11176
- ],
11177
- detail: (id, query2) => [
11178
- PROMOTION_QUERY_KEY,
11171
+ const SalesChannel = () => {
11172
+ const { id } = useParams();
11173
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11179
11174
  id,
11180
- query2 ? query2 : void 0
11181
- ]
11175
+ {
11176
+ fields: "+sales_channel_id"
11177
+ },
11178
+ {
11179
+ enabled: !!id
11180
+ }
11181
+ );
11182
+ if (isError) {
11183
+ throw error;
11184
+ }
11185
+ const ISrEADY = !!draft_order && !isPending;
11186
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11187
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11188
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11189
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11190
+ ] }),
11191
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11192
+ ] });
11182
11193
  };
11183
- const usePromotions = (query2, options) => {
11184
- const { data, ...rest } = useQuery({
11185
- queryKey: promotionsQueryKeys.list(query2),
11186
- queryFn: async () => sdk.admin.promotion.list(query2),
11187
- ...options
11194
+ const SalesChannelForm = ({ order }) => {
11195
+ const form = useForm({
11196
+ defaultValues: {
11197
+ sales_channel_id: order.sales_channel_id || ""
11198
+ },
11199
+ resolver: zodResolver(schema$2)
11188
11200
  });
11189
- return { ...data, ...rest };
11190
- };
11191
- const Promotions = () => {
11192
- const { id } = useParams();
11193
- const {
11194
- order: preview,
11195
- isError: isPreviewError,
11196
- error: previewError
11197
- } = useOrderPreview(id, void 0);
11198
- useInitiateOrderEdit({ preview });
11199
- const { onCancel } = useCancelOrderEdit({ preview });
11200
- if (isPreviewError) {
11201
- throw previewError;
11202
- }
11203
- const isReady = !!preview;
11204
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11205
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11206
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11207
- ] });
11208
- };
11209
- const PromotionForm = ({ preview }) => {
11210
- const { items, shipping_methods } = preview;
11211
- const [isSubmitting, setIsSubmitting] = useState(false);
11212
- const [comboboxValue, setComboboxValue] = useState("");
11213
- const { handleSuccess } = useRouteModal();
11214
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11215
- const promoIds = getPromotionIds(items, shipping_methods);
11216
- const { promotions, isPending, isError, error } = usePromotions(
11217
- {
11218
- id: promoIds
11219
- },
11220
- {
11221
- enabled: !!promoIds.length
11222
- }
11223
- );
11224
- const comboboxData = useComboboxData({
11225
- queryKey: ["promotions", "combobox", promoIds],
11226
- queryFn: async (params) => {
11227
- return await sdk.admin.promotion.list({
11228
- ...params,
11229
- id: {
11230
- $nin: promoIds
11231
- }
11232
- });
11233
- },
11234
- getOptions: (data) => {
11235
- return data.promotions.map((promotion) => ({
11236
- label: promotion.code,
11237
- value: promotion.code
11238
- }));
11239
- }
11240
- });
11241
- const add = async (value) => {
11242
- if (!value) {
11243
- return;
11244
- }
11245
- addPromotions(
11246
- {
11247
- promo_codes: [value]
11248
- },
11249
- {
11250
- onError: (e) => {
11251
- toast.error(e.message);
11252
- comboboxData.onSearchValueChange("");
11253
- setComboboxValue("");
11254
- },
11255
- onSuccess: () => {
11256
- comboboxData.onSearchValueChange("");
11257
- setComboboxValue("");
11258
- }
11259
- }
11260
- );
11261
- };
11262
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11263
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11264
- const onSubmit = async () => {
11265
- setIsSubmitting(true);
11266
- let requestSucceeded = false;
11267
- await requestOrderEdit(void 0, {
11268
- onError: (e) => {
11269
- toast.error(e.message);
11270
- },
11271
- onSuccess: () => {
11272
- requestSucceeded = true;
11273
- }
11274
- });
11275
- if (!requestSucceeded) {
11276
- setIsSubmitting(false);
11277
- return;
11278
- }
11279
- await confirmOrderEdit(void 0, {
11280
- onError: (e) => {
11281
- toast.error(e.message);
11282
- },
11283
- onSuccess: () => {
11284
- handleSuccess();
11285
- },
11286
- onSettled: () => {
11287
- setIsSubmitting(false);
11288
- }
11289
- });
11290
- };
11291
- if (isError) {
11292
- throw error;
11293
- }
11294
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11295
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11296
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11297
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11298
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11299
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11300
- ] }),
11301
- /* @__PURE__ */ jsx(
11302
- Combobox,
11303
- {
11304
- id: "promotion-combobox",
11305
- "aria-describedby": "promotion-combobox-hint",
11306
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11307
- fetchNextPage: comboboxData.fetchNextPage,
11308
- options: comboboxData.options,
11309
- onSearchValueChange: comboboxData.onSearchValueChange,
11310
- searchValue: comboboxData.searchValue,
11311
- disabled: comboboxData.disabled || isAddingPromotions,
11312
- onChange: add,
11313
- value: comboboxValue
11314
- }
11315
- )
11316
- ] }),
11317
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11318
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11319
- PromotionItem,
11320
- {
11321
- promotion,
11322
- orderId: preview.id,
11323
- isLoading: isPending
11324
- },
11325
- promotion.id
11326
- )) })
11327
- ] }) }),
11328
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11329
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11330
- /* @__PURE__ */ jsx(
11331
- Button,
11332
- {
11333
- size: "small",
11334
- type: "submit",
11335
- isLoading: isSubmitting || isAddingPromotions,
11336
- children: "Save"
11337
- }
11338
- )
11339
- ] }) })
11340
- ] });
11341
- };
11342
- const PromotionItem = ({
11343
- promotion,
11344
- orderId,
11345
- isLoading
11346
- }) => {
11347
- var _a;
11348
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11349
- const onRemove = async () => {
11350
- removePromotions(
11351
- {
11352
- promo_codes: [promotion.code]
11353
- },
11354
- {
11355
- onError: (e) => {
11356
- toast.error(e.message);
11357
- }
11358
- }
11359
- );
11360
- };
11361
- const displayValue = getDisplayValue(promotion);
11362
- return /* @__PURE__ */ jsxs(
11363
- "div",
11364
- {
11365
- className: clx(
11366
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11367
- {
11368
- "animate-pulse": isLoading
11369
- }
11370
- ),
11371
- children: [
11372
- /* @__PURE__ */ jsxs("div", { children: [
11373
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11374
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11375
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11376
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11377
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11378
- ] }),
11379
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11380
- ] })
11381
- ] }),
11382
- /* @__PURE__ */ jsx(
11383
- IconButton,
11384
- {
11385
- size: "small",
11386
- type: "button",
11387
- variant: "transparent",
11388
- onClick: onRemove,
11389
- isLoading: isPending || isLoading,
11390
- children: /* @__PURE__ */ jsx(XMark, {})
11391
- }
11392
- )
11393
- ]
11394
- },
11395
- promotion.id
11396
- );
11397
- };
11398
- function getDisplayValue(promotion) {
11399
- var _a, _b, _c, _d;
11400
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11401
- if (!value) {
11402
- return null;
11403
- }
11404
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11405
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11406
- if (!currency) {
11407
- return null;
11408
- }
11409
- return getLocaleAmount(value, currency);
11410
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11411
- return formatPercentage(value);
11412
- }
11413
- return null;
11414
- }
11415
- const formatter = new Intl.NumberFormat([], {
11416
- style: "percent",
11417
- minimumFractionDigits: 2
11418
- });
11419
- const formatPercentage = (value, isPercentageValue = false) => {
11420
- let val = value || 0;
11421
- if (!isPercentageValue) {
11422
- val = val / 100;
11423
- }
11424
- return formatter.format(val);
11425
- };
11426
- function getPromotionIds(items, shippingMethods) {
11427
- const promotionIds = /* @__PURE__ */ new Set();
11428
- for (const item of items) {
11429
- if (item.adjustments) {
11430
- for (const adjustment of item.adjustments) {
11431
- if (adjustment.promotion_id) {
11432
- promotionIds.add(adjustment.promotion_id);
11433
- }
11434
- }
11435
- }
11436
- }
11437
- for (const shippingMethod of shippingMethods) {
11438
- if (shippingMethod.adjustments) {
11439
- for (const adjustment of shippingMethod.adjustments) {
11440
- if (adjustment.promotion_id) {
11441
- promotionIds.add(adjustment.promotion_id);
11442
- }
11443
- }
11444
- }
11445
- }
11446
- return Array.from(promotionIds);
11447
- }
11448
- const SalesChannel = () => {
11449
- const { id } = useParams();
11450
- const { draft_order, isPending, isError, error } = useDraftOrder(
11451
- id,
11452
- {
11453
- fields: "+sales_channel_id"
11454
- },
11455
- {
11456
- enabled: !!id
11457
- }
11458
- );
11459
- if (isError) {
11460
- throw error;
11461
- }
11462
- const ISrEADY = !!draft_order && !isPending;
11463
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11464
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11465
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11466
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11467
- ] }),
11468
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11469
- ] });
11470
- };
11471
- const SalesChannelForm = ({ order }) => {
11472
- const form = useForm({
11473
- defaultValues: {
11474
- sales_channel_id: order.sales_channel_id || ""
11475
- },
11476
- resolver: zodResolver(schema$2)
11477
- });
11478
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11479
- const { handleSuccess } = useRouteModal();
11480
- const onSubmit = form.handleSubmit(async (data) => {
11481
- await mutateAsync(
11482
- {
11483
- sales_channel_id: data.sales_channel_id
11484
- },
11485
- {
11486
- onSuccess: () => {
11487
- toast.success("Sales channel updated");
11488
- handleSuccess();
11489
- },
11490
- onError: (error) => {
11491
- toast.error(error.message);
11492
- }
11493
- }
11494
- );
11495
- });
11496
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11497
- KeyboundForm,
11498
- {
11499
- className: "flex flex-1 flex-col overflow-hidden",
11500
- onSubmit,
11501
- children: [
11502
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11503
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11504
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11505
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11506
- ] }) })
11507
- ]
11508
- }
11509
- ) });
11510
- };
11511
- const SalesChannelField = ({ control, order }) => {
11512
- const salesChannels = useComboboxData({
11513
- queryFn: async (params) => {
11514
- return await sdk.admin.salesChannel.list(params);
11515
- },
11516
- queryKey: ["sales-channels"],
11517
- getOptions: (data) => {
11518
- return data.sales_channels.map((salesChannel) => ({
11519
- label: salesChannel.name,
11520
- value: salesChannel.id
11521
- }));
11522
- },
11523
- defaultValue: order.sales_channel_id || void 0
11524
- });
11525
- return /* @__PURE__ */ jsx(
11526
- Form$2.Field,
11527
- {
11528
- control,
11529
- name: "sales_channel_id",
11530
- render: ({ field }) => {
11531
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11532
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11533
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11534
- Combobox,
11535
- {
11536
- options: salesChannels.options,
11537
- fetchNextPage: salesChannels.fetchNextPage,
11538
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11539
- searchValue: salesChannels.searchValue,
11540
- onSearchValueChange: salesChannels.onSearchValueChange,
11541
- placeholder: "Select sales channel",
11542
- ...field
11543
- }
11544
- ) }),
11545
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11546
- ] });
11547
- }
11548
- }
11549
- );
11550
- };
11551
- const schema$2 = objectType({
11552
- sales_channel_id: stringType().min(1)
11553
- });
11554
- const ShippingAddress = () => {
11555
- const { id } = useParams();
11556
- const { order, isPending, isError, error } = useOrder(id, {
11557
- fields: "+shipping_address"
11558
- });
11559
- if (isError) {
11560
- throw error;
11561
- }
11562
- const isReady = !isPending && !!order;
11563
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11564
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11565
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11566
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11567
- ] }),
11568
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11569
- ] });
11570
- };
11571
- const ShippingAddressForm = ({ order }) => {
11572
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11573
- const form = useForm({
11574
- defaultValues: {
11575
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11576
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11577
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11578
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11579
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11580
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11581
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11582
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11583
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11584
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11585
- },
11586
- resolver: zodResolver(schema$1)
11587
- });
11588
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11589
- const { handleSuccess } = useRouteModal();
11590
- const onSubmit = form.handleSubmit(async (data) => {
11591
- await mutateAsync(
11592
- {
11593
- shipping_address: {
11594
- first_name: data.first_name,
11595
- last_name: data.last_name,
11596
- company: data.company,
11597
- address_1: data.address_1,
11598
- address_2: data.address_2,
11599
- city: data.city,
11600
- province: data.province,
11601
- country_code: data.country_code,
11602
- postal_code: data.postal_code,
11603
- phone: data.phone
11604
- }
11605
- },
11606
- {
11607
- onSuccess: () => {
11608
- handleSuccess();
11609
- },
11610
- onError: (error) => {
11611
- toast.error(error.message);
11612
- }
11613
- }
11614
- );
11615
- });
11616
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11617
- KeyboundForm,
11618
- {
11619
- className: "flex flex-1 flex-col overflow-hidden",
11620
- onSubmit,
11621
- children: [
11622
- /* @__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: [
11623
- /* @__PURE__ */ jsx(
11624
- Form$2.Field,
11625
- {
11626
- control: form.control,
11627
- name: "country_code",
11628
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11629
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11630
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11631
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11632
- ] })
11633
- }
11634
- ),
11635
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11636
- /* @__PURE__ */ jsx(
11637
- Form$2.Field,
11638
- {
11639
- control: form.control,
11640
- name: "first_name",
11641
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11642
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11643
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11644
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11645
- ] })
11646
- }
11647
- ),
11648
- /* @__PURE__ */ jsx(
11649
- Form$2.Field,
11650
- {
11651
- control: form.control,
11652
- name: "last_name",
11653
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11654
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11655
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11656
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11657
- ] })
11658
- }
11659
- )
11660
- ] }),
11661
- /* @__PURE__ */ jsx(
11662
- Form$2.Field,
11663
- {
11664
- control: form.control,
11665
- name: "company",
11666
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11667
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11668
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11669
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11670
- ] })
11671
- }
11672
- ),
11673
- /* @__PURE__ */ jsx(
11674
- Form$2.Field,
11675
- {
11676
- control: form.control,
11677
- name: "address_1",
11678
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11679
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11680
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11681
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11682
- ] })
11683
- }
11684
- ),
11685
- /* @__PURE__ */ jsx(
11686
- Form$2.Field,
11687
- {
11688
- control: form.control,
11689
- name: "address_2",
11690
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11691
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11692
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11693
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11694
- ] })
11695
- }
11696
- ),
11697
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11698
- /* @__PURE__ */ jsx(
11699
- Form$2.Field,
11700
- {
11701
- control: form.control,
11702
- name: "postal_code",
11703
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11704
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11705
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11706
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11707
- ] })
11708
- }
11709
- ),
11710
- /* @__PURE__ */ jsx(
11711
- Form$2.Field,
11712
- {
11713
- control: form.control,
11714
- name: "city",
11715
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11716
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11717
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11718
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11719
- ] })
11720
- }
11721
- )
11722
- ] }),
11723
- /* @__PURE__ */ jsx(
11724
- Form$2.Field,
11725
- {
11726
- control: form.control,
11727
- name: "province",
11728
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11729
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11730
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11731
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11732
- ] })
11733
- }
11734
- ),
11735
- /* @__PURE__ */ jsx(
11736
- Form$2.Field,
11737
- {
11738
- control: form.control,
11739
- name: "phone",
11740
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11741
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11742
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11743
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11744
- ] })
11745
- }
11746
- )
11747
- ] }) }),
11201
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11202
+ const { handleSuccess } = useRouteModal();
11203
+ const onSubmit = form.handleSubmit(async (data) => {
11204
+ await mutateAsync(
11205
+ {
11206
+ sales_channel_id: data.sales_channel_id
11207
+ },
11208
+ {
11209
+ onSuccess: () => {
11210
+ toast.success("Sales channel updated");
11211
+ handleSuccess();
11212
+ },
11213
+ onError: (error) => {
11214
+ toast.error(error.message);
11215
+ }
11216
+ }
11217
+ );
11218
+ });
11219
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11220
+ KeyboundForm,
11221
+ {
11222
+ className: "flex flex-1 flex-col overflow-hidden",
11223
+ onSubmit,
11224
+ children: [
11225
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11748
11226
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11749
11227
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11750
11228
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11753,7 +11231,49 @@ const ShippingAddressForm = ({ order }) => {
11753
11231
  }
11754
11232
  ) });
11755
11233
  };
11756
- const schema$1 = addressSchema;
11234
+ const SalesChannelField = ({ control, order }) => {
11235
+ const salesChannels = useComboboxData({
11236
+ queryFn: async (params) => {
11237
+ return await sdk.admin.salesChannel.list(params);
11238
+ },
11239
+ queryKey: ["sales-channels"],
11240
+ getOptions: (data) => {
11241
+ return data.sales_channels.map((salesChannel) => ({
11242
+ label: salesChannel.name,
11243
+ value: salesChannel.id
11244
+ }));
11245
+ },
11246
+ defaultValue: order.sales_channel_id || void 0
11247
+ });
11248
+ return /* @__PURE__ */ jsx(
11249
+ Form$2.Field,
11250
+ {
11251
+ control,
11252
+ name: "sales_channel_id",
11253
+ render: ({ field }) => {
11254
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11255
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11256
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11257
+ Combobox,
11258
+ {
11259
+ options: salesChannels.options,
11260
+ fetchNextPage: salesChannels.fetchNextPage,
11261
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11262
+ searchValue: salesChannels.searchValue,
11263
+ onSearchValueChange: salesChannels.onSearchValueChange,
11264
+ placeholder: "Select sales channel",
11265
+ ...field
11266
+ }
11267
+ ) }),
11268
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11269
+ ] });
11270
+ }
11271
+ }
11272
+ );
11273
+ };
11274
+ const schema$2 = objectType({
11275
+ sales_channel_id: stringType().min(1)
11276
+ });
11757
11277
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11758
11278
  const Shipping = () => {
11759
11279
  var _a;
@@ -12547,20 +12067,223 @@ const CustomAmountField = ({
12547
12067
  /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12548
12068
  /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12549
12069
  ] }),
12550
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12551
- CurrencyInput,
12070
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12071
+ CurrencyInput,
12072
+ {
12073
+ ...field,
12074
+ onValueChange: (value) => onChange(value),
12075
+ symbol: getNativeSymbol(currencyCode),
12076
+ code: currencyCode
12077
+ }
12078
+ ) })
12079
+ ] });
12080
+ }
12081
+ }
12082
+ );
12083
+ };
12084
+ const ShippingAddress = () => {
12085
+ const { id } = useParams();
12086
+ const { order, isPending, isError, error } = useOrder(id, {
12087
+ fields: "+shipping_address"
12088
+ });
12089
+ if (isError) {
12090
+ throw error;
12091
+ }
12092
+ const isReady = !isPending && !!order;
12093
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12094
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12095
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12096
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12097
+ ] }),
12098
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12099
+ ] });
12100
+ };
12101
+ const ShippingAddressForm = ({ order }) => {
12102
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12103
+ const form = useForm({
12104
+ defaultValues: {
12105
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12106
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12107
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12108
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12109
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12110
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12111
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12112
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12113
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12114
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12115
+ },
12116
+ resolver: zodResolver(schema$1)
12117
+ });
12118
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12119
+ const { handleSuccess } = useRouteModal();
12120
+ const onSubmit = form.handleSubmit(async (data) => {
12121
+ await mutateAsync(
12122
+ {
12123
+ shipping_address: {
12124
+ first_name: data.first_name,
12125
+ last_name: data.last_name,
12126
+ company: data.company,
12127
+ address_1: data.address_1,
12128
+ address_2: data.address_2,
12129
+ city: data.city,
12130
+ province: data.province,
12131
+ country_code: data.country_code,
12132
+ postal_code: data.postal_code,
12133
+ phone: data.phone
12134
+ }
12135
+ },
12136
+ {
12137
+ onSuccess: () => {
12138
+ handleSuccess();
12139
+ },
12140
+ onError: (error) => {
12141
+ toast.error(error.message);
12142
+ }
12143
+ }
12144
+ );
12145
+ });
12146
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12147
+ KeyboundForm,
12148
+ {
12149
+ className: "flex flex-1 flex-col overflow-hidden",
12150
+ onSubmit,
12151
+ children: [
12152
+ /* @__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: [
12153
+ /* @__PURE__ */ jsx(
12154
+ Form$2.Field,
12155
+ {
12156
+ control: form.control,
12157
+ name: "country_code",
12158
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12159
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12160
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12161
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12162
+ ] })
12163
+ }
12164
+ ),
12165
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12166
+ /* @__PURE__ */ jsx(
12167
+ Form$2.Field,
12168
+ {
12169
+ control: form.control,
12170
+ name: "first_name",
12171
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12172
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12173
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12174
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12175
+ ] })
12176
+ }
12177
+ ),
12178
+ /* @__PURE__ */ jsx(
12179
+ Form$2.Field,
12180
+ {
12181
+ control: form.control,
12182
+ name: "last_name",
12183
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12184
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12185
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12186
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12187
+ ] })
12188
+ }
12189
+ )
12190
+ ] }),
12191
+ /* @__PURE__ */ jsx(
12192
+ Form$2.Field,
12193
+ {
12194
+ control: form.control,
12195
+ name: "company",
12196
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12197
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12198
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12199
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12200
+ ] })
12201
+ }
12202
+ ),
12203
+ /* @__PURE__ */ jsx(
12204
+ Form$2.Field,
12205
+ {
12206
+ control: form.control,
12207
+ name: "address_1",
12208
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12209
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12210
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12211
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12212
+ ] })
12213
+ }
12214
+ ),
12215
+ /* @__PURE__ */ jsx(
12216
+ Form$2.Field,
12217
+ {
12218
+ control: form.control,
12219
+ name: "address_2",
12220
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12221
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12222
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12223
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12224
+ ] })
12225
+ }
12226
+ ),
12227
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12228
+ /* @__PURE__ */ jsx(
12229
+ Form$2.Field,
12230
+ {
12231
+ control: form.control,
12232
+ name: "postal_code",
12233
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12234
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12235
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12236
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12237
+ ] })
12238
+ }
12239
+ ),
12240
+ /* @__PURE__ */ jsx(
12241
+ Form$2.Field,
12242
+ {
12243
+ control: form.control,
12244
+ name: "city",
12245
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12246
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12247
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12248
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12249
+ ] })
12250
+ }
12251
+ )
12252
+ ] }),
12253
+ /* @__PURE__ */ jsx(
12254
+ Form$2.Field,
12552
12255
  {
12553
- ...field,
12554
- onValueChange: (value) => onChange(value),
12555
- symbol: getNativeSymbol(currencyCode),
12556
- code: currencyCode
12256
+ control: form.control,
12257
+ name: "province",
12258
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12259
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12260
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12261
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12262
+ ] })
12557
12263
  }
12558
- ) })
12559
- ] });
12560
- }
12264
+ ),
12265
+ /* @__PURE__ */ jsx(
12266
+ Form$2.Field,
12267
+ {
12268
+ control: form.control,
12269
+ name: "phone",
12270
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12271
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12272
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12273
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12274
+ ] })
12275
+ }
12276
+ )
12277
+ ] }) }),
12278
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12279
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12280
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12281
+ ] }) })
12282
+ ]
12561
12283
  }
12562
- );
12284
+ ) });
12563
12285
  };
12286
+ const schema$1 = addressSchema;
12564
12287
  const TransferOwnership = () => {
12565
12288
  const { id } = useParams();
12566
12289
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12957,86 +12680,363 @@ const Illustration = () => {
12957
12680
  /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12958
12681
  "path",
12959
12682
  {
12960
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12961
- stroke: "#A1A1AA",
12962
- strokeWidth: "1.5",
12963
- strokeLinecap: "round",
12964
- strokeLinejoin: "round"
12683
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12684
+ stroke: "#A1A1AA",
12685
+ strokeWidth: "1.5",
12686
+ strokeLinecap: "round",
12687
+ strokeLinejoin: "round"
12688
+ }
12689
+ ) }),
12690
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12691
+ "path",
12692
+ {
12693
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12694
+ stroke: "#A1A1AA",
12695
+ strokeWidth: "1.5",
12696
+ strokeLinecap: "round",
12697
+ strokeLinejoin: "round"
12698
+ }
12699
+ ) }),
12700
+ /* @__PURE__ */ jsxs("defs", { children: [
12701
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12702
+ "rect",
12703
+ {
12704
+ width: "12",
12705
+ height: "12",
12706
+ fill: "white",
12707
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12708
+ }
12709
+ ) }),
12710
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12711
+ "rect",
12712
+ {
12713
+ width: "12",
12714
+ height: "12",
12715
+ fill: "white",
12716
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12717
+ }
12718
+ ) }),
12719
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12720
+ "rect",
12721
+ {
12722
+ width: "12",
12723
+ height: "12",
12724
+ fill: "white",
12725
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12726
+ }
12727
+ ) }),
12728
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12729
+ "rect",
12730
+ {
12731
+ width: "12",
12732
+ height: "12",
12733
+ fill: "white",
12734
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12735
+ }
12736
+ ) }),
12737
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12738
+ "rect",
12739
+ {
12740
+ width: "12",
12741
+ height: "12",
12742
+ fill: "white",
12743
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12744
+ }
12745
+ ) }),
12746
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12747
+ "rect",
12748
+ {
12749
+ width: "12",
12750
+ height: "12",
12751
+ fill: "white",
12752
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12753
+ }
12754
+ ) })
12755
+ ] })
12756
+ ]
12757
+ }
12758
+ );
12759
+ };
12760
+ const schema = objectType({
12761
+ customer_id: stringType().min(1)
12762
+ });
12763
+ const PROMOTION_QUERY_KEY = "promotions";
12764
+ const promotionsQueryKeys = {
12765
+ list: (query2) => [
12766
+ PROMOTION_QUERY_KEY,
12767
+ query2 ? query2 : void 0
12768
+ ],
12769
+ detail: (id, query2) => [
12770
+ PROMOTION_QUERY_KEY,
12771
+ id,
12772
+ query2 ? query2 : void 0
12773
+ ]
12774
+ };
12775
+ const usePromotions = (query2, options) => {
12776
+ const { data, ...rest } = useQuery({
12777
+ queryKey: promotionsQueryKeys.list(query2),
12778
+ queryFn: async () => sdk.admin.promotion.list(query2),
12779
+ ...options
12780
+ });
12781
+ return { ...data, ...rest };
12782
+ };
12783
+ const Promotions = () => {
12784
+ const { id } = useParams();
12785
+ const {
12786
+ order: preview,
12787
+ isError: isPreviewError,
12788
+ error: previewError
12789
+ } = useOrderPreview(id, void 0);
12790
+ useInitiateOrderEdit({ preview });
12791
+ const { onCancel } = useCancelOrderEdit({ preview });
12792
+ if (isPreviewError) {
12793
+ throw previewError;
12794
+ }
12795
+ const isReady = !!preview;
12796
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
12797
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
12798
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
12799
+ ] });
12800
+ };
12801
+ const PromotionForm = ({ preview }) => {
12802
+ const { items, shipping_methods } = preview;
12803
+ const [isSubmitting, setIsSubmitting] = useState(false);
12804
+ const [comboboxValue, setComboboxValue] = useState("");
12805
+ const { handleSuccess } = useRouteModal();
12806
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12807
+ const promoIds = getPromotionIds(items, shipping_methods);
12808
+ const { promotions, isPending, isError, error } = usePromotions(
12809
+ {
12810
+ id: promoIds
12811
+ },
12812
+ {
12813
+ enabled: !!promoIds.length
12814
+ }
12815
+ );
12816
+ const comboboxData = useComboboxData({
12817
+ queryKey: ["promotions", "combobox", promoIds],
12818
+ queryFn: async (params) => {
12819
+ return await sdk.admin.promotion.list({
12820
+ ...params,
12821
+ id: {
12822
+ $nin: promoIds
12823
+ }
12824
+ });
12825
+ },
12826
+ getOptions: (data) => {
12827
+ return data.promotions.map((promotion) => ({
12828
+ label: promotion.code,
12829
+ value: promotion.code
12830
+ }));
12831
+ }
12832
+ });
12833
+ const add = async (value) => {
12834
+ if (!value) {
12835
+ return;
12836
+ }
12837
+ addPromotions(
12838
+ {
12839
+ promo_codes: [value]
12840
+ },
12841
+ {
12842
+ onError: (e) => {
12843
+ toast.error(e.message);
12844
+ comboboxData.onSearchValueChange("");
12845
+ setComboboxValue("");
12846
+ },
12847
+ onSuccess: () => {
12848
+ comboboxData.onSearchValueChange("");
12849
+ setComboboxValue("");
12850
+ }
12851
+ }
12852
+ );
12853
+ };
12854
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12855
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12856
+ const onSubmit = async () => {
12857
+ setIsSubmitting(true);
12858
+ let requestSucceeded = false;
12859
+ await requestOrderEdit(void 0, {
12860
+ onError: (e) => {
12861
+ toast.error(e.message);
12862
+ },
12863
+ onSuccess: () => {
12864
+ requestSucceeded = true;
12865
+ }
12866
+ });
12867
+ if (!requestSucceeded) {
12868
+ setIsSubmitting(false);
12869
+ return;
12870
+ }
12871
+ await confirmOrderEdit(void 0, {
12872
+ onError: (e) => {
12873
+ toast.error(e.message);
12874
+ },
12875
+ onSuccess: () => {
12876
+ handleSuccess();
12877
+ },
12878
+ onSettled: () => {
12879
+ setIsSubmitting(false);
12880
+ }
12881
+ });
12882
+ };
12883
+ if (isError) {
12884
+ throw error;
12885
+ }
12886
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12887
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
12888
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
12889
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12890
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12891
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12892
+ ] }),
12893
+ /* @__PURE__ */ jsx(
12894
+ Combobox,
12895
+ {
12896
+ id: "promotion-combobox",
12897
+ "aria-describedby": "promotion-combobox-hint",
12898
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12899
+ fetchNextPage: comboboxData.fetchNextPage,
12900
+ options: comboboxData.options,
12901
+ onSearchValueChange: comboboxData.onSearchValueChange,
12902
+ searchValue: comboboxData.searchValue,
12903
+ disabled: comboboxData.disabled || isAddingPromotions,
12904
+ onChange: add,
12905
+ value: comboboxValue
12965
12906
  }
12966
- ) }),
12967
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12968
- "path",
12907
+ )
12908
+ ] }),
12909
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12910
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
12911
+ PromotionItem,
12912
+ {
12913
+ promotion,
12914
+ orderId: preview.id,
12915
+ isLoading: isPending
12916
+ },
12917
+ promotion.id
12918
+ )) })
12919
+ ] }) }),
12920
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12921
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12922
+ /* @__PURE__ */ jsx(
12923
+ Button,
12924
+ {
12925
+ size: "small",
12926
+ type: "submit",
12927
+ isLoading: isSubmitting || isAddingPromotions,
12928
+ children: "Save"
12929
+ }
12930
+ )
12931
+ ] }) })
12932
+ ] });
12933
+ };
12934
+ const PromotionItem = ({
12935
+ promotion,
12936
+ orderId,
12937
+ isLoading
12938
+ }) => {
12939
+ var _a;
12940
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12941
+ const onRemove = async () => {
12942
+ removePromotions(
12943
+ {
12944
+ promo_codes: [promotion.code]
12945
+ },
12946
+ {
12947
+ onError: (e) => {
12948
+ toast.error(e.message);
12949
+ }
12950
+ }
12951
+ );
12952
+ };
12953
+ const displayValue = getDisplayValue(promotion);
12954
+ return /* @__PURE__ */ jsxs(
12955
+ "div",
12956
+ {
12957
+ className: clx(
12958
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12959
+ {
12960
+ "animate-pulse": isLoading
12961
+ }
12962
+ ),
12963
+ children: [
12964
+ /* @__PURE__ */ jsxs("div", { children: [
12965
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12966
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12967
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
12968
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
12969
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
12970
+ ] }),
12971
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12972
+ ] })
12973
+ ] }),
12974
+ /* @__PURE__ */ jsx(
12975
+ IconButton,
12969
12976
  {
12970
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12971
- stroke: "#A1A1AA",
12972
- strokeWidth: "1.5",
12973
- strokeLinecap: "round",
12974
- strokeLinejoin: "round"
12977
+ size: "small",
12978
+ type: "button",
12979
+ variant: "transparent",
12980
+ onClick: onRemove,
12981
+ isLoading: isPending || isLoading,
12982
+ children: /* @__PURE__ */ jsx(XMark, {})
12975
12983
  }
12976
- ) }),
12977
- /* @__PURE__ */ jsxs("defs", { children: [
12978
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12979
- "rect",
12980
- {
12981
- width: "12",
12982
- height: "12",
12983
- fill: "white",
12984
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12985
- }
12986
- ) }),
12987
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12988
- "rect",
12989
- {
12990
- width: "12",
12991
- height: "12",
12992
- fill: "white",
12993
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12994
- }
12995
- ) }),
12996
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12997
- "rect",
12998
- {
12999
- width: "12",
13000
- height: "12",
13001
- fill: "white",
13002
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13003
- }
13004
- ) }),
13005
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13006
- "rect",
13007
- {
13008
- width: "12",
13009
- height: "12",
13010
- fill: "white",
13011
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13012
- }
13013
- ) }),
13014
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13015
- "rect",
13016
- {
13017
- width: "12",
13018
- height: "12",
13019
- fill: "white",
13020
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13021
- }
13022
- ) }),
13023
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13024
- "rect",
13025
- {
13026
- width: "12",
13027
- height: "12",
13028
- fill: "white",
13029
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13030
- }
13031
- ) })
13032
- ] })
12984
+ )
13033
12985
  ]
13034
- }
12986
+ },
12987
+ promotion.id
13035
12988
  );
13036
12989
  };
13037
- const schema = objectType({
13038
- customer_id: stringType().min(1)
12990
+ function getDisplayValue(promotion) {
12991
+ var _a, _b, _c, _d;
12992
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12993
+ if (!value) {
12994
+ return null;
12995
+ }
12996
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12997
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
12998
+ if (!currency) {
12999
+ return null;
13000
+ }
13001
+ return getLocaleAmount(value, currency);
13002
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13003
+ return formatPercentage(value);
13004
+ }
13005
+ return null;
13006
+ }
13007
+ const formatter = new Intl.NumberFormat([], {
13008
+ style: "percent",
13009
+ minimumFractionDigits: 2
13039
13010
  });
13011
+ const formatPercentage = (value, isPercentageValue = false) => {
13012
+ let val = value || 0;
13013
+ if (!isPercentageValue) {
13014
+ val = val / 100;
13015
+ }
13016
+ return formatter.format(val);
13017
+ };
13018
+ function getPromotionIds(items, shippingMethods) {
13019
+ const promotionIds = /* @__PURE__ */ new Set();
13020
+ for (const item of items) {
13021
+ if (item.adjustments) {
13022
+ for (const adjustment of item.adjustments) {
13023
+ if (adjustment.promotion_id) {
13024
+ promotionIds.add(adjustment.promotion_id);
13025
+ }
13026
+ }
13027
+ }
13028
+ }
13029
+ for (const shippingMethod of shippingMethods) {
13030
+ if (shippingMethod.adjustments) {
13031
+ for (const adjustment of shippingMethod.adjustments) {
13032
+ if (adjustment.promotion_id) {
13033
+ promotionIds.add(adjustment.promotion_id);
13034
+ }
13035
+ }
13036
+ }
13037
+ }
13038
+ return Array.from(promotionIds);
13039
+ }
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13058,44 +13058,44 @@ const routeModule = {
13058
13058
  loader,
13059
13059
  children: [
13060
13060
  {
13061
- Component: CustomItems,
13062
- path: "/draft-orders/:id/custom-items"
13061
+ Component: BillingAddress,
13062
+ path: "/draft-orders/:id/billing-address"
13063
13063
  },
13064
13064
  {
13065
13065
  Component: Email,
13066
13066
  path: "/draft-orders/:id/email"
13067
13067
  },
13068
13068
  {
13069
- Component: Items,
13070
- path: "/draft-orders/:id/items"
13069
+ Component: CustomItems,
13070
+ path: "/draft-orders/:id/custom-items"
13071
13071
  },
13072
13072
  {
13073
- Component: BillingAddress,
13074
- path: "/draft-orders/:id/billing-address"
13073
+ Component: Items,
13074
+ path: "/draft-orders/:id/items"
13075
13075
  },
13076
13076
  {
13077
13077
  Component: Metadata,
13078
13078
  path: "/draft-orders/:id/metadata"
13079
13079
  },
13080
- {
13081
- Component: Promotions,
13082
- path: "/draft-orders/:id/promotions"
13083
- },
13084
13080
  {
13085
13081
  Component: SalesChannel,
13086
13082
  path: "/draft-orders/:id/sales-channel"
13087
13083
  },
13088
- {
13089
- Component: ShippingAddress,
13090
- path: "/draft-orders/:id/shipping-address"
13091
- },
13092
13084
  {
13093
13085
  Component: Shipping,
13094
13086
  path: "/draft-orders/:id/shipping"
13095
13087
  },
13088
+ {
13089
+ Component: ShippingAddress,
13090
+ path: "/draft-orders/:id/shipping-address"
13091
+ },
13096
13092
  {
13097
13093
  Component: TransferOwnership,
13098
13094
  path: "/draft-orders/:id/transfer-ownership"
13095
+ },
13096
+ {
13097
+ Component: Promotions,
13098
+ path: "/draft-orders/:id/promotions"
13099
13099
  }
13100
13100
  ]
13101
13101
  }