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