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

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