@medusajs/draft-order 2.11.2-snapshot-20251031090242 → 2.11.3-preview-20251031120214

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.
@@ -13,9 +13,9 @@ import { FormProvider, Controller, useFormContext, useFormState, useForm, useWat
13
13
  import { Slot, Collapsible, Accordion } from "radix-ui";
14
14
  import { ComboboxProvider, Combobox as Combobox$1, ComboboxDisclosure, ComboboxPopover, ComboboxItem, ComboboxItemCheck, ComboboxItemValue, Separator } from "@ariakit/react";
15
15
  import { matchSorter } from "match-sorter";
16
- import debounce from "lodash.debounce";
16
+ import debounce from "lodash/debounce";
17
17
  import Primitive from "@uiw/react-json-view";
18
- import isEqual from "lodash.isequal";
18
+ import { isEqual } from "lodash";
19
19
  function useQueryParams(keys, prefix) {
20
20
  const [params] = useSearchParams();
21
21
  const result = {};
@@ -9586,196 +9586,6 @@ const CustomItemsForm = () => {
9586
9586
  const schema$5 = objectType({
9587
9587
  email: stringType().email()
9588
9588
  });
9589
- const BillingAddress = () => {
9590
- const { id } = useParams();
9591
- const { order, isPending, isError, error } = useOrder(id, {
9592
- fields: "+billing_address"
9593
- });
9594
- if (isError) {
9595
- throw error;
9596
- }
9597
- const isReady = !isPending && !!order;
9598
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9599
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9600
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9601
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9602
- ] }),
9603
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9604
- ] });
9605
- };
9606
- const BillingAddressForm = ({ order }) => {
9607
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9608
- const form = useForm({
9609
- defaultValues: {
9610
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9611
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9612
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9613
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9614
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9615
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9616
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9617
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9618
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9619
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9620
- },
9621
- resolver: zodResolver(schema$4)
9622
- });
9623
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9624
- const { handleSuccess } = useRouteModal();
9625
- const onSubmit = form.handleSubmit(async (data) => {
9626
- await mutateAsync(
9627
- { billing_address: data },
9628
- {
9629
- onSuccess: () => {
9630
- handleSuccess();
9631
- },
9632
- onError: (error) => {
9633
- toast.error(error.message);
9634
- }
9635
- }
9636
- );
9637
- });
9638
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9639
- KeyboundForm,
9640
- {
9641
- className: "flex flex-1 flex-col overflow-hidden",
9642
- onSubmit,
9643
- children: [
9644
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9645
- /* @__PURE__ */ jsx(
9646
- Form$2.Field,
9647
- {
9648
- control: form.control,
9649
- name: "country_code",
9650
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9651
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9652
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9653
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9654
- ] })
9655
- }
9656
- ),
9657
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9658
- /* @__PURE__ */ jsx(
9659
- Form$2.Field,
9660
- {
9661
- control: form.control,
9662
- name: "first_name",
9663
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9664
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9665
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9666
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9667
- ] })
9668
- }
9669
- ),
9670
- /* @__PURE__ */ jsx(
9671
- Form$2.Field,
9672
- {
9673
- control: form.control,
9674
- name: "last_name",
9675
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9676
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9677
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9678
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9679
- ] })
9680
- }
9681
- )
9682
- ] }),
9683
- /* @__PURE__ */ jsx(
9684
- Form$2.Field,
9685
- {
9686
- control: form.control,
9687
- name: "company",
9688
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9689
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9690
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9691
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9692
- ] })
9693
- }
9694
- ),
9695
- /* @__PURE__ */ jsx(
9696
- Form$2.Field,
9697
- {
9698
- control: form.control,
9699
- name: "address_1",
9700
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9701
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9702
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9703
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9704
- ] })
9705
- }
9706
- ),
9707
- /* @__PURE__ */ jsx(
9708
- Form$2.Field,
9709
- {
9710
- control: form.control,
9711
- name: "address_2",
9712
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9713
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9714
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9715
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9716
- ] })
9717
- }
9718
- ),
9719
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9720
- /* @__PURE__ */ jsx(
9721
- Form$2.Field,
9722
- {
9723
- control: form.control,
9724
- name: "postal_code",
9725
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9726
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9727
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9728
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9729
- ] })
9730
- }
9731
- ),
9732
- /* @__PURE__ */ jsx(
9733
- Form$2.Field,
9734
- {
9735
- control: form.control,
9736
- name: "city",
9737
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9738
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9739
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9740
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9741
- ] })
9742
- }
9743
- )
9744
- ] }),
9745
- /* @__PURE__ */ jsx(
9746
- Form$2.Field,
9747
- {
9748
- control: form.control,
9749
- name: "province",
9750
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9751
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9752
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9753
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9754
- ] })
9755
- }
9756
- ),
9757
- /* @__PURE__ */ jsx(
9758
- Form$2.Field,
9759
- {
9760
- control: form.control,
9761
- name: "phone",
9762
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9763
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9764
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9765
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9766
- ] })
9767
- }
9768
- )
9769
- ] }) }),
9770
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9772
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9773
- ] }) })
9774
- ]
9775
- }
9776
- ) });
9777
- };
9778
- const schema$4 = addressSchema;
9779
9589
  const NumberInput = forwardRef(
9780
9590
  ({
9781
9591
  value,
@@ -10750,74 +10560,283 @@ const customItemSchema = objectType({
10750
10560
  quantity: numberType(),
10751
10561
  unit_price: unionType([numberType(), stringType()])
10752
10562
  });
10753
- const Email = () => {
10754
- const { id } = useParams();
10755
- const { order, isPending, isError, error } = useOrder(id, {
10756
- fields: "+email"
10563
+ const PROMOTION_QUERY_KEY = "promotions";
10564
+ const promotionsQueryKeys = {
10565
+ list: (query2) => [
10566
+ PROMOTION_QUERY_KEY,
10567
+ query2 ? query2 : void 0
10568
+ ],
10569
+ detail: (id, query2) => [
10570
+ PROMOTION_QUERY_KEY,
10571
+ id,
10572
+ query2 ? query2 : void 0
10573
+ ]
10574
+ };
10575
+ const usePromotions = (query2, options) => {
10576
+ const { data, ...rest } = useQuery({
10577
+ queryKey: promotionsQueryKeys.list(query2),
10578
+ queryFn: async () => sdk.admin.promotion.list(query2),
10579
+ ...options
10757
10580
  });
10758
- if (isError) {
10759
- throw error;
10581
+ return { ...data, ...rest };
10582
+ };
10583
+ const Promotions = () => {
10584
+ const { id } = useParams();
10585
+ const {
10586
+ order: preview,
10587
+ isError: isPreviewError,
10588
+ error: previewError
10589
+ } = useOrderPreview(id, void 0);
10590
+ useInitiateOrderEdit({ preview });
10591
+ const { onCancel } = useCancelOrderEdit({ preview });
10592
+ if (isPreviewError) {
10593
+ throw previewError;
10760
10594
  }
10761
- const isReady = !isPending && !!order;
10762
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10763
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10764
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
10765
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10766
- ] }),
10767
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10595
+ const isReady = !!preview;
10596
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10597
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10598
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10768
10599
  ] });
10769
10600
  };
10770
- const EmailForm = ({ order }) => {
10771
- const form = useForm({
10772
- defaultValues: {
10773
- email: order.email ?? ""
10774
- },
10775
- resolver: zodResolver(schema$3)
10776
- });
10777
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10601
+ const PromotionForm = ({ preview }) => {
10602
+ const { items, shipping_methods } = preview;
10603
+ const [isSubmitting, setIsSubmitting] = useState(false);
10604
+ const [comboboxValue, setComboboxValue] = useState("");
10778
10605
  const { handleSuccess } = useRouteModal();
10779
- const onSubmit = form.handleSubmit(async (data) => {
10780
- await mutateAsync(
10781
- { email: data.email },
10782
- {
10783
- onSuccess: () => {
10784
- handleSuccess();
10785
- },
10786
- onError: (error) => {
10787
- toast.error(error.message);
10606
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10607
+ const promoIds = getPromotionIds(items, shipping_methods);
10608
+ const { promotions, isPending, isError, error } = usePromotions(
10609
+ {
10610
+ id: promoIds
10611
+ },
10612
+ {
10613
+ enabled: !!promoIds.length
10614
+ }
10615
+ );
10616
+ const comboboxData = useComboboxData({
10617
+ queryKey: ["promotions", "combobox", promoIds],
10618
+ queryFn: async (params) => {
10619
+ return await sdk.admin.promotion.list({
10620
+ ...params,
10621
+ id: {
10622
+ $nin: promoIds
10623
+ }
10624
+ });
10625
+ },
10626
+ getOptions: (data) => {
10627
+ return data.promotions.map((promotion) => ({
10628
+ label: promotion.code,
10629
+ value: promotion.code
10630
+ }));
10631
+ }
10632
+ });
10633
+ const add = async (value) => {
10634
+ if (!value) {
10635
+ return;
10636
+ }
10637
+ addPromotions(
10638
+ {
10639
+ promo_codes: [value]
10640
+ },
10641
+ {
10642
+ onError: (e) => {
10643
+ toast.error(e.message);
10644
+ comboboxData.onSearchValueChange("");
10645
+ setComboboxValue("");
10646
+ },
10647
+ onSuccess: () => {
10648
+ comboboxData.onSearchValueChange("");
10649
+ setComboboxValue("");
10788
10650
  }
10789
10651
  }
10790
10652
  );
10791
- });
10792
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10793
- KeyboundForm,
10653
+ };
10654
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10655
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10656
+ const onSubmit = async () => {
10657
+ setIsSubmitting(true);
10658
+ let requestSucceeded = false;
10659
+ await requestOrderEdit(void 0, {
10660
+ onError: (e) => {
10661
+ toast.error(e.message);
10662
+ },
10663
+ onSuccess: () => {
10664
+ requestSucceeded = true;
10665
+ }
10666
+ });
10667
+ if (!requestSucceeded) {
10668
+ setIsSubmitting(false);
10669
+ return;
10670
+ }
10671
+ await confirmOrderEdit(void 0, {
10672
+ onError: (e) => {
10673
+ toast.error(e.message);
10674
+ },
10675
+ onSuccess: () => {
10676
+ handleSuccess();
10677
+ },
10678
+ onSettled: () => {
10679
+ setIsSubmitting(false);
10680
+ }
10681
+ });
10682
+ };
10683
+ if (isError) {
10684
+ throw error;
10685
+ }
10686
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10687
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
10688
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
10689
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10690
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10691
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10692
+ ] }),
10693
+ /* @__PURE__ */ jsx(
10694
+ Combobox,
10695
+ {
10696
+ id: "promotion-combobox",
10697
+ "aria-describedby": "promotion-combobox-hint",
10698
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
10699
+ fetchNextPage: comboboxData.fetchNextPage,
10700
+ options: comboboxData.options,
10701
+ onSearchValueChange: comboboxData.onSearchValueChange,
10702
+ searchValue: comboboxData.searchValue,
10703
+ disabled: comboboxData.disabled || isAddingPromotions,
10704
+ onChange: add,
10705
+ value: comboboxValue
10706
+ }
10707
+ )
10708
+ ] }),
10709
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10710
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10711
+ PromotionItem,
10712
+ {
10713
+ promotion,
10714
+ orderId: preview.id,
10715
+ isLoading: isPending
10716
+ },
10717
+ promotion.id
10718
+ )) })
10719
+ ] }) }),
10720
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10721
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10722
+ /* @__PURE__ */ jsx(
10723
+ Button,
10724
+ {
10725
+ size: "small",
10726
+ type: "submit",
10727
+ isLoading: isSubmitting || isAddingPromotions,
10728
+ children: "Save"
10729
+ }
10730
+ )
10731
+ ] }) })
10732
+ ] });
10733
+ };
10734
+ const PromotionItem = ({
10735
+ promotion,
10736
+ orderId,
10737
+ isLoading
10738
+ }) => {
10739
+ var _a;
10740
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10741
+ const onRemove = async () => {
10742
+ removePromotions(
10743
+ {
10744
+ promo_codes: [promotion.code]
10745
+ },
10746
+ {
10747
+ onError: (e) => {
10748
+ toast.error(e.message);
10749
+ }
10750
+ }
10751
+ );
10752
+ };
10753
+ const displayValue = getDisplayValue(promotion);
10754
+ return /* @__PURE__ */ jsxs(
10755
+ "div",
10794
10756
  {
10795
- className: "flex flex-1 flex-col overflow-hidden",
10796
- onSubmit,
10757
+ className: clx(
10758
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
10759
+ {
10760
+ "animate-pulse": isLoading
10761
+ }
10762
+ ),
10797
10763
  children: [
10798
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
10799
- Form$2.Field,
10764
+ /* @__PURE__ */ jsxs("div", { children: [
10765
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10766
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
10767
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
10768
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
10769
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
10770
+ ] }),
10771
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10772
+ ] })
10773
+ ] }),
10774
+ /* @__PURE__ */ jsx(
10775
+ IconButton,
10800
10776
  {
10801
- control: form.control,
10802
- name: "email",
10803
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10804
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
10805
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10806
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10807
- ] })
10777
+ size: "small",
10778
+ type: "button",
10779
+ variant: "transparent",
10780
+ onClick: onRemove,
10781
+ isLoading: isPending || isLoading,
10782
+ children: /* @__PURE__ */ jsx(XMark, {})
10808
10783
  }
10809
- ) }),
10810
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10811
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10812
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10813
- ] }) })
10784
+ )
10814
10785
  ]
10815
- }
10816
- ) });
10786
+ },
10787
+ promotion.id
10788
+ );
10817
10789
  };
10818
- const schema$3 = objectType({
10819
- email: stringType().email()
10790
+ function getDisplayValue(promotion) {
10791
+ var _a, _b, _c, _d;
10792
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10793
+ if (!value) {
10794
+ return null;
10795
+ }
10796
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10797
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10798
+ if (!currency) {
10799
+ return null;
10800
+ }
10801
+ return getLocaleAmount(value, currency);
10802
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10803
+ return formatPercentage(value);
10804
+ }
10805
+ return null;
10806
+ }
10807
+ const formatter = new Intl.NumberFormat([], {
10808
+ style: "percent",
10809
+ minimumFractionDigits: 2
10820
10810
  });
10811
+ const formatPercentage = (value, isPercentageValue = false) => {
10812
+ let val = value || 0;
10813
+ if (!isPercentageValue) {
10814
+ val = val / 100;
10815
+ }
10816
+ return formatter.format(val);
10817
+ };
10818
+ function getPromotionIds(items, shippingMethods) {
10819
+ const promotionIds = /* @__PURE__ */ new Set();
10820
+ for (const item of items) {
10821
+ if (item.adjustments) {
10822
+ for (const adjustment of item.adjustments) {
10823
+ if (adjustment.promotion_id) {
10824
+ promotionIds.add(adjustment.promotion_id);
10825
+ }
10826
+ }
10827
+ }
10828
+ }
10829
+ for (const shippingMethod of shippingMethods) {
10830
+ if (shippingMethod.adjustments) {
10831
+ for (const adjustment of shippingMethod.adjustments) {
10832
+ if (adjustment.promotion_id) {
10833
+ promotionIds.add(adjustment.promotion_id);
10834
+ }
10835
+ }
10836
+ }
10837
+ }
10838
+ return Array.from(promotionIds);
10839
+ }
10821
10840
  const InlineTip = forwardRef(
10822
10841
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10823
10842
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11168,583 +11187,61 @@ function getHasUneditableRows(metadata) {
11168
11187
  (value) => !EDITABLE_TYPES.includes(typeof value)
11169
11188
  );
11170
11189
  }
11171
- const PROMOTION_QUERY_KEY = "promotions";
11172
- const promotionsQueryKeys = {
11173
- list: (query2) => [
11174
- PROMOTION_QUERY_KEY,
11175
- query2 ? query2 : void 0
11176
- ],
11177
- detail: (id, query2) => [
11178
- PROMOTION_QUERY_KEY,
11179
- id,
11180
- query2 ? query2 : void 0
11181
- ]
11182
- };
11183
- const usePromotions = (query2, options) => {
11184
- const { data, ...rest } = useQuery({
11185
- queryKey: promotionsQueryKeys.list(query2),
11186
- queryFn: async () => sdk.admin.promotion.list(query2),
11187
- ...options
11188
- });
11189
- return { ...data, ...rest };
11190
- };
11191
- const Promotions = () => {
11192
- const { id } = useParams();
11193
- const {
11194
- order: preview,
11195
- isError: isPreviewError,
11196
- error: previewError
11197
- } = useOrderPreview(id, void 0);
11198
- useInitiateOrderEdit({ preview });
11199
- const { onCancel } = useCancelOrderEdit({ preview });
11200
- if (isPreviewError) {
11201
- throw previewError;
11202
- }
11203
- const isReady = !!preview;
11204
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11205
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11206
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11207
- ] });
11208
- };
11209
- const PromotionForm = ({ preview }) => {
11210
- const { items, shipping_methods } = preview;
11211
- const [isSubmitting, setIsSubmitting] = useState(false);
11212
- const [comboboxValue, setComboboxValue] = useState("");
11213
- const { handleSuccess } = useRouteModal();
11214
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11215
- const promoIds = getPromotionIds(items, shipping_methods);
11216
- const { promotions, isPending, isError, error } = usePromotions(
11217
- {
11218
- id: promoIds
11219
- },
11220
- {
11221
- enabled: !!promoIds.length
11222
- }
11223
- );
11224
- const comboboxData = useComboboxData({
11225
- queryKey: ["promotions", "combobox", promoIds],
11226
- queryFn: async (params) => {
11227
- return await sdk.admin.promotion.list({
11228
- ...params,
11229
- id: {
11230
- $nin: promoIds
11231
- }
11232
- });
11233
- },
11234
- getOptions: (data) => {
11235
- return data.promotions.map((promotion) => ({
11236
- label: promotion.code,
11237
- value: promotion.code
11238
- }));
11239
- }
11240
- });
11241
- const add = async (value) => {
11242
- if (!value) {
11243
- return;
11244
- }
11245
- addPromotions(
11246
- {
11247
- promo_codes: [value]
11248
- },
11249
- {
11250
- onError: (e) => {
11251
- toast.error(e.message);
11252
- comboboxData.onSearchValueChange("");
11253
- setComboboxValue("");
11254
- },
11255
- onSuccess: () => {
11256
- comboboxData.onSearchValueChange("");
11257
- setComboboxValue("");
11258
- }
11259
- }
11260
- );
11261
- };
11262
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11263
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11264
- const onSubmit = async () => {
11265
- setIsSubmitting(true);
11266
- let requestSucceeded = false;
11267
- await requestOrderEdit(void 0, {
11268
- onError: (e) => {
11269
- toast.error(e.message);
11270
- },
11271
- onSuccess: () => {
11272
- requestSucceeded = true;
11273
- }
11274
- });
11275
- if (!requestSucceeded) {
11276
- setIsSubmitting(false);
11277
- return;
11278
- }
11279
- await confirmOrderEdit(void 0, {
11280
- onError: (e) => {
11281
- toast.error(e.message);
11282
- },
11283
- onSuccess: () => {
11284
- handleSuccess();
11285
- },
11286
- onSettled: () => {
11287
- setIsSubmitting(false);
11288
- }
11289
- });
11290
- };
11291
- if (isError) {
11292
- throw error;
11293
- }
11294
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11295
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11296
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11297
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11298
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11299
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11300
- ] }),
11301
- /* @__PURE__ */ jsx(
11302
- Combobox,
11303
- {
11304
- id: "promotion-combobox",
11305
- "aria-describedby": "promotion-combobox-hint",
11306
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11307
- fetchNextPage: comboboxData.fetchNextPage,
11308
- options: comboboxData.options,
11309
- onSearchValueChange: comboboxData.onSearchValueChange,
11310
- searchValue: comboboxData.searchValue,
11311
- disabled: comboboxData.disabled || isAddingPromotions,
11312
- onChange: add,
11313
- value: comboboxValue
11314
- }
11315
- )
11316
- ] }),
11317
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11318
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11319
- PromotionItem,
11320
- {
11321
- promotion,
11322
- orderId: preview.id,
11323
- isLoading: isPending
11324
- },
11325
- promotion.id
11326
- )) })
11327
- ] }) }),
11328
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11329
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11330
- /* @__PURE__ */ jsx(
11331
- Button,
11332
- {
11333
- size: "small",
11334
- type: "submit",
11335
- isLoading: isSubmitting || isAddingPromotions,
11336
- children: "Save"
11337
- }
11338
- )
11339
- ] }) })
11340
- ] });
11341
- };
11342
- const PromotionItem = ({
11343
- promotion,
11344
- orderId,
11345
- isLoading
11346
- }) => {
11347
- var _a;
11348
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11349
- const onRemove = async () => {
11350
- removePromotions(
11351
- {
11352
- promo_codes: [promotion.code]
11353
- },
11354
- {
11355
- onError: (e) => {
11356
- toast.error(e.message);
11357
- }
11358
- }
11359
- );
11360
- };
11361
- const displayValue = getDisplayValue(promotion);
11362
- return /* @__PURE__ */ jsxs(
11363
- "div",
11364
- {
11365
- className: clx(
11366
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11367
- {
11368
- "animate-pulse": isLoading
11369
- }
11370
- ),
11371
- children: [
11372
- /* @__PURE__ */ jsxs("div", { children: [
11373
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11374
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11375
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11376
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11377
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11378
- ] }),
11379
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11380
- ] })
11381
- ] }),
11382
- /* @__PURE__ */ jsx(
11383
- IconButton,
11384
- {
11385
- size: "small",
11386
- type: "button",
11387
- variant: "transparent",
11388
- onClick: onRemove,
11389
- isLoading: isPending || isLoading,
11390
- children: /* @__PURE__ */ jsx(XMark, {})
11391
- }
11392
- )
11393
- ]
11394
- },
11395
- promotion.id
11396
- );
11397
- };
11398
- function getDisplayValue(promotion) {
11399
- var _a, _b, _c, _d;
11400
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11401
- if (!value) {
11402
- return null;
11403
- }
11404
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11405
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11406
- if (!currency) {
11407
- return null;
11408
- }
11409
- return getLocaleAmount(value, currency);
11410
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11411
- return formatPercentage(value);
11412
- }
11413
- return null;
11414
- }
11415
- const formatter = new Intl.NumberFormat([], {
11416
- style: "percent",
11417
- minimumFractionDigits: 2
11418
- });
11419
- const formatPercentage = (value, isPercentageValue = false) => {
11420
- let val = value || 0;
11421
- if (!isPercentageValue) {
11422
- val = val / 100;
11423
- }
11424
- return formatter.format(val);
11425
- };
11426
- function getPromotionIds(items, shippingMethods) {
11427
- const promotionIds = /* @__PURE__ */ new Set();
11428
- for (const item of items) {
11429
- if (item.adjustments) {
11430
- for (const adjustment of item.adjustments) {
11431
- if (adjustment.promotion_id) {
11432
- promotionIds.add(adjustment.promotion_id);
11433
- }
11434
- }
11435
- }
11436
- }
11437
- for (const shippingMethod of shippingMethods) {
11438
- if (shippingMethod.adjustments) {
11439
- for (const adjustment of shippingMethod.adjustments) {
11440
- if (adjustment.promotion_id) {
11441
- promotionIds.add(adjustment.promotion_id);
11442
- }
11443
- }
11444
- }
11445
- }
11446
- return Array.from(promotionIds);
11447
- }
11448
- const SalesChannel = () => {
11449
- const { id } = useParams();
11450
- const { draft_order, isPending, isError, error } = useDraftOrder(
11451
- id,
11452
- {
11453
- fields: "+sales_channel_id"
11454
- },
11455
- {
11456
- enabled: !!id
11457
- }
11458
- );
11459
- if (isError) {
11460
- throw error;
11461
- }
11462
- const ISrEADY = !!draft_order && !isPending;
11463
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11464
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11465
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11466
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11467
- ] }),
11468
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11469
- ] });
11470
- };
11471
- const SalesChannelForm = ({ order }) => {
11472
- const form = useForm({
11473
- defaultValues: {
11474
- sales_channel_id: order.sales_channel_id || ""
11475
- },
11476
- resolver: zodResolver(schema$2)
11477
- });
11478
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11479
- const { handleSuccess } = useRouteModal();
11480
- const onSubmit = form.handleSubmit(async (data) => {
11481
- await mutateAsync(
11482
- {
11483
- sales_channel_id: data.sales_channel_id
11484
- },
11485
- {
11486
- onSuccess: () => {
11487
- toast.success("Sales channel updated");
11488
- handleSuccess();
11489
- },
11490
- onError: (error) => {
11491
- toast.error(error.message);
11492
- }
11493
- }
11494
- );
11495
- });
11496
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11497
- KeyboundForm,
11498
- {
11499
- className: "flex flex-1 flex-col overflow-hidden",
11500
- onSubmit,
11501
- children: [
11502
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11503
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11504
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11505
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11506
- ] }) })
11507
- ]
11508
- }
11509
- ) });
11510
- };
11511
- const SalesChannelField = ({ control, order }) => {
11512
- const salesChannels = useComboboxData({
11513
- queryFn: async (params) => {
11514
- return await sdk.admin.salesChannel.list(params);
11515
- },
11516
- queryKey: ["sales-channels"],
11517
- getOptions: (data) => {
11518
- return data.sales_channels.map((salesChannel) => ({
11519
- label: salesChannel.name,
11520
- value: salesChannel.id
11521
- }));
11522
- },
11523
- defaultValue: order.sales_channel_id || void 0
11524
- });
11525
- return /* @__PURE__ */ jsx(
11526
- Form$2.Field,
11527
- {
11528
- control,
11529
- name: "sales_channel_id",
11530
- render: ({ field }) => {
11531
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11532
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11533
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11534
- Combobox,
11535
- {
11536
- options: salesChannels.options,
11537
- fetchNextPage: salesChannels.fetchNextPage,
11538
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11539
- searchValue: salesChannels.searchValue,
11540
- onSearchValueChange: salesChannels.onSearchValueChange,
11541
- placeholder: "Select sales channel",
11542
- ...field
11543
- }
11544
- ) }),
11545
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11546
- ] });
11547
- }
11548
- }
11549
- );
11550
- };
11551
- const schema$2 = objectType({
11552
- sales_channel_id: stringType().min(1)
11553
- });
11554
- const ShippingAddress = () => {
11555
- const { id } = useParams();
11556
- const { order, isPending, isError, error } = useOrder(id, {
11557
- fields: "+shipping_address"
11558
- });
11559
- if (isError) {
11560
- throw error;
11561
- }
11562
- const isReady = !isPending && !!order;
11563
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11564
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11565
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11566
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11567
- ] }),
11568
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11569
- ] });
11570
- };
11571
- const ShippingAddressForm = ({ order }) => {
11572
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11573
- const form = useForm({
11574
- defaultValues: {
11575
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11576
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11577
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11578
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11579
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11580
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11581
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11582
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11583
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11584
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11585
- },
11586
- resolver: zodResolver(schema$1)
11587
- });
11588
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11589
- const { handleSuccess } = useRouteModal();
11590
- const onSubmit = form.handleSubmit(async (data) => {
11591
- await mutateAsync(
11592
- {
11593
- shipping_address: {
11594
- first_name: data.first_name,
11595
- last_name: data.last_name,
11596
- company: data.company,
11597
- address_1: data.address_1,
11598
- address_2: data.address_2,
11599
- city: data.city,
11600
- province: data.province,
11601
- country_code: data.country_code,
11602
- postal_code: data.postal_code,
11603
- phone: data.phone
11604
- }
11605
- },
11606
- {
11607
- onSuccess: () => {
11608
- handleSuccess();
11609
- },
11610
- onError: (error) => {
11611
- toast.error(error.message);
11612
- }
11613
- }
11614
- );
11615
- });
11616
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11617
- KeyboundForm,
11618
- {
11619
- className: "flex flex-1 flex-col overflow-hidden",
11620
- onSubmit,
11621
- children: [
11622
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11623
- /* @__PURE__ */ jsx(
11624
- Form$2.Field,
11625
- {
11626
- control: form.control,
11627
- name: "country_code",
11628
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11629
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11630
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11631
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11632
- ] })
11633
- }
11634
- ),
11635
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11636
- /* @__PURE__ */ jsx(
11637
- Form$2.Field,
11638
- {
11639
- control: form.control,
11640
- name: "first_name",
11641
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11642
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11643
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11644
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11645
- ] })
11646
- }
11647
- ),
11648
- /* @__PURE__ */ jsx(
11649
- Form$2.Field,
11650
- {
11651
- control: form.control,
11652
- name: "last_name",
11653
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11654
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11655
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11656
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11657
- ] })
11658
- }
11659
- )
11660
- ] }),
11661
- /* @__PURE__ */ jsx(
11662
- Form$2.Field,
11663
- {
11664
- control: form.control,
11665
- name: "company",
11666
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11667
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11668
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11669
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11670
- ] })
11671
- }
11672
- ),
11673
- /* @__PURE__ */ jsx(
11674
- Form$2.Field,
11675
- {
11676
- control: form.control,
11677
- name: "address_1",
11678
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11679
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11680
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11681
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11682
- ] })
11683
- }
11684
- ),
11685
- /* @__PURE__ */ jsx(
11686
- Form$2.Field,
11687
- {
11688
- control: form.control,
11689
- name: "address_2",
11690
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11691
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11692
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11693
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11694
- ] })
11695
- }
11696
- ),
11697
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11698
- /* @__PURE__ */ jsx(
11699
- Form$2.Field,
11700
- {
11701
- control: form.control,
11702
- name: "postal_code",
11703
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11704
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11705
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11706
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11707
- ] })
11708
- }
11709
- ),
11710
- /* @__PURE__ */ jsx(
11711
- Form$2.Field,
11712
- {
11713
- control: form.control,
11714
- name: "city",
11715
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11716
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11717
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11718
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11719
- ] })
11720
- }
11721
- )
11722
- ] }),
11723
- /* @__PURE__ */ jsx(
11724
- Form$2.Field,
11725
- {
11726
- control: form.control,
11727
- name: "province",
11728
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11729
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11730
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11731
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11732
- ] })
11733
- }
11734
- ),
11735
- /* @__PURE__ */ jsx(
11736
- Form$2.Field,
11737
- {
11738
- control: form.control,
11739
- name: "phone",
11740
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11741
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11742
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11743
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11744
- ] })
11745
- }
11746
- )
11747
- ] }) }),
11190
+ const SalesChannel = () => {
11191
+ const { id } = useParams();
11192
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11193
+ id,
11194
+ {
11195
+ fields: "+sales_channel_id"
11196
+ },
11197
+ {
11198
+ enabled: !!id
11199
+ }
11200
+ );
11201
+ if (isError) {
11202
+ throw error;
11203
+ }
11204
+ const ISrEADY = !!draft_order && !isPending;
11205
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11206
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11207
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11208
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11209
+ ] }),
11210
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11211
+ ] });
11212
+ };
11213
+ const SalesChannelForm = ({ order }) => {
11214
+ const form = useForm({
11215
+ defaultValues: {
11216
+ sales_channel_id: order.sales_channel_id || ""
11217
+ },
11218
+ resolver: zodResolver(schema$4)
11219
+ });
11220
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11221
+ const { handleSuccess } = useRouteModal();
11222
+ const onSubmit = form.handleSubmit(async (data) => {
11223
+ await mutateAsync(
11224
+ {
11225
+ sales_channel_id: data.sales_channel_id
11226
+ },
11227
+ {
11228
+ onSuccess: () => {
11229
+ toast.success("Sales channel updated");
11230
+ handleSuccess();
11231
+ },
11232
+ onError: (error) => {
11233
+ toast.error(error.message);
11234
+ }
11235
+ }
11236
+ );
11237
+ });
11238
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11239
+ KeyboundForm,
11240
+ {
11241
+ className: "flex flex-1 flex-col overflow-hidden",
11242
+ onSubmit,
11243
+ children: [
11244
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11748
11245
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11749
11246
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11750
11247
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11753,7 +11250,49 @@ const ShippingAddressForm = ({ order }) => {
11753
11250
  }
11754
11251
  ) });
11755
11252
  };
11756
- const schema$1 = addressSchema;
11253
+ const SalesChannelField = ({ control, order }) => {
11254
+ const salesChannels = useComboboxData({
11255
+ queryFn: async (params) => {
11256
+ return await sdk.admin.salesChannel.list(params);
11257
+ },
11258
+ queryKey: ["sales-channels"],
11259
+ getOptions: (data) => {
11260
+ return data.sales_channels.map((salesChannel) => ({
11261
+ label: salesChannel.name,
11262
+ value: salesChannel.id
11263
+ }));
11264
+ },
11265
+ defaultValue: order.sales_channel_id || void 0
11266
+ });
11267
+ return /* @__PURE__ */ jsx(
11268
+ Form$2.Field,
11269
+ {
11270
+ control,
11271
+ name: "sales_channel_id",
11272
+ render: ({ field }) => {
11273
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11274
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11275
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11276
+ Combobox,
11277
+ {
11278
+ options: salesChannels.options,
11279
+ fetchNextPage: salesChannels.fetchNextPage,
11280
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11281
+ searchValue: salesChannels.searchValue,
11282
+ onSearchValueChange: salesChannels.onSearchValueChange,
11283
+ placeholder: "Select sales channel",
11284
+ ...field
11285
+ }
11286
+ ) }),
11287
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11288
+ ] });
11289
+ }
11290
+ }
11291
+ );
11292
+ };
11293
+ const schema$4 = objectType({
11294
+ sales_channel_id: stringType().min(1)
11295
+ });
11757
11296
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11758
11297
  const Shipping = () => {
11759
11298
  var _a;
@@ -11779,7 +11318,7 @@ const Shipping = () => {
11779
11318
  const isReady = preview && !isPreviewPending && order && !isPending;
11780
11319
  return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11781
11320
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11782
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11321
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11783
11322
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11784
11323
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11785
11324
  ] }) }) }),
@@ -11866,14 +11405,14 @@ const ShippingForm = ({ preview, order }) => {
11866
11405
  return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11867
11406
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11868
11407
  /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11869
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11408
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11870
11409
  /* @__PURE__ */ jsxs("div", { children: [
11871
11410
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11872
11411
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11873
11412
  ] }),
11874
11413
  /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11875
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11876
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11414
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11415
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11877
11416
  /* @__PURE__ */ jsx(
11878
11417
  Text,
11879
11418
  {
@@ -11915,8 +11454,8 @@ const ShippingForm = ({ preview, order }) => {
11915
11454
  value: profile.id,
11916
11455
  className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11917
11456
  children: [
11918
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11919
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11457
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11458
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11920
11459
  /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11921
11460
  IconButton,
11922
11461
  {
@@ -11924,12 +11463,12 @@ const ShippingForm = ({ preview, order }) => {
11924
11463
  variant: "transparent",
11925
11464
  className: "group/trigger",
11926
11465
  disabled: !hasItems,
11927
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11466
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11928
11467
  }
11929
11468
  ) }),
11930
11469
  !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11931
- /* @__PURE__ */ jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11932
- /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col", children: [
11470
+ /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11471
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11933
11472
  /* @__PURE__ */ jsx(
11934
11473
  Text,
11935
11474
  {
@@ -11953,7 +11492,7 @@ const ShippingForm = ({ preview, order }) => {
11953
11492
  }
11954
11493
  )
11955
11494
  ] })
11956
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11495
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11957
11496
  /* @__PURE__ */ jsx(
11958
11497
  Tooltip,
11959
11498
  {
@@ -11970,7 +11509,7 @@ const ShippingForm = ({ preview, order }) => {
11970
11509
  children: /* @__PURE__ */ jsxs(
11971
11510
  Badge,
11972
11511
  {
11973
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11512
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11974
11513
  size: "xsmall",
11975
11514
  children: [
11976
11515
  /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
@@ -11995,7 +11534,7 @@ const ShippingForm = ({ preview, order }) => {
11995
11534
  children: /* @__PURE__ */ jsxs(
11996
11535
  Badge,
11997
11536
  {
11998
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11537
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11999
11538
  size: "xsmall",
12000
11539
  children: [
12001
11540
  /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
@@ -12008,7 +11547,7 @@ const ShippingForm = ({ preview, order }) => {
12008
11547
  /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
12009
11548
  Badge,
12010
11549
  {
12011
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11550
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12012
11551
  size: "xsmall",
12013
11552
  children: [
12014
11553
  /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
@@ -12079,17 +11618,17 @@ const ShippingForm = ({ preview, order }) => {
12079
11618
  /* @__PURE__ */ jsxs(
12080
11619
  "div",
12081
11620
  {
12082
- className: "flex items-center gap-x-3 px-3",
11621
+ className: "px-3 flex items-center gap-x-3",
12083
11622
  children: [
12084
- /* @__PURE__ */ jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsx(
11623
+ /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
12085
11624
  Divider,
12086
11625
  {
12087
11626
  variant: "dashed",
12088
11627
  orientation: "vertical"
12089
11628
  }
12090
11629
  ) }),
12091
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12092
- /* @__PURE__ */ jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11630
+ /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11631
+ /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
12093
11632
  Text,
12094
11633
  {
12095
11634
  size: "small",
@@ -12270,7 +11809,7 @@ const ShippingProfileForm = ({
12270
11809
  onSubmit,
12271
11810
  children: [
12272
11811
  /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12273
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11812
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12274
11813
  /* @__PURE__ */ jsxs("div", { children: [
12275
11814
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12276
11815
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
@@ -12343,14 +11882,14 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
12343
11882
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12344
11883
  ] }) }),
12345
11884
  /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12346
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
11885
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12347
11886
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12348
11887
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12349
11888
  ] }),
12350
11889
  /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12351
11890
  "div",
12352
11891
  {
12353
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
11892
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12354
11893
  children: [
12355
11894
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12356
11895
  /* @__PURE__ */ jsx(
@@ -12403,7 +11942,7 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
12403
11942
  ]
12404
11943
  },
12405
11944
  item.id
12406
- )) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
11945
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12407
11946
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12408
11947
  /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12409
11948
  'No items found for "',
@@ -12508,59 +12047,262 @@ const ShippingOptionField = ({
12508
12047
  /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12509
12048
  ] }),
12510
12049
  /* @__PURE__ */ jsx(
12511
- ConditionalTooltip,
12050
+ ConditionalTooltip,
12051
+ {
12052
+ content: tooltipContent,
12053
+ showTooltip: !locationId || !shippingProfileId,
12054
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12055
+ Combobox,
12056
+ {
12057
+ options: shippingOptions.options,
12058
+ fetchNextPage: shippingOptions.fetchNextPage,
12059
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12060
+ searchValue: shippingOptions.searchValue,
12061
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12062
+ placeholder: "Select shipping option",
12063
+ ...field,
12064
+ disabled: !locationId || !shippingProfileId
12065
+ }
12066
+ ) }) })
12067
+ }
12068
+ )
12069
+ ] }) });
12070
+ }
12071
+ }
12072
+ );
12073
+ };
12074
+ const CustomAmountField = ({
12075
+ control,
12076
+ currencyCode
12077
+ }) => {
12078
+ return /* @__PURE__ */ jsx(
12079
+ Form$2.Field,
12080
+ {
12081
+ control,
12082
+ name: "custom_amount",
12083
+ render: ({ field: { onChange, ...field } }) => {
12084
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12085
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12086
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12087
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12088
+ ] }),
12089
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12090
+ CurrencyInput,
12091
+ {
12092
+ ...field,
12093
+ onValueChange: (value) => onChange(value),
12094
+ symbol: getNativeSymbol(currencyCode),
12095
+ code: currencyCode
12096
+ }
12097
+ ) })
12098
+ ] });
12099
+ }
12100
+ }
12101
+ );
12102
+ };
12103
+ const ShippingAddress = () => {
12104
+ const { id } = useParams();
12105
+ const { order, isPending, isError, error } = useOrder(id, {
12106
+ fields: "+shipping_address"
12107
+ });
12108
+ if (isError) {
12109
+ throw error;
12110
+ }
12111
+ const isReady = !isPending && !!order;
12112
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12113
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12114
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12115
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12116
+ ] }),
12117
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12118
+ ] });
12119
+ };
12120
+ const ShippingAddressForm = ({ order }) => {
12121
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12122
+ const form = useForm({
12123
+ defaultValues: {
12124
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12125
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12126
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12127
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12128
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12129
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12130
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12131
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12132
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12133
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12134
+ },
12135
+ resolver: zodResolver(schema$3)
12136
+ });
12137
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12138
+ const { handleSuccess } = useRouteModal();
12139
+ const onSubmit = form.handleSubmit(async (data) => {
12140
+ await mutateAsync(
12141
+ {
12142
+ shipping_address: {
12143
+ first_name: data.first_name,
12144
+ last_name: data.last_name,
12145
+ company: data.company,
12146
+ address_1: data.address_1,
12147
+ address_2: data.address_2,
12148
+ city: data.city,
12149
+ province: data.province,
12150
+ country_code: data.country_code,
12151
+ postal_code: data.postal_code,
12152
+ phone: data.phone
12153
+ }
12154
+ },
12155
+ {
12156
+ onSuccess: () => {
12157
+ handleSuccess();
12158
+ },
12159
+ onError: (error) => {
12160
+ toast.error(error.message);
12161
+ }
12162
+ }
12163
+ );
12164
+ });
12165
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12166
+ KeyboundForm,
12167
+ {
12168
+ className: "flex flex-1 flex-col overflow-hidden",
12169
+ onSubmit,
12170
+ children: [
12171
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12172
+ /* @__PURE__ */ jsx(
12173
+ Form$2.Field,
12174
+ {
12175
+ control: form.control,
12176
+ name: "country_code",
12177
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12178
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12179
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12180
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12181
+ ] })
12182
+ }
12183
+ ),
12184
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12185
+ /* @__PURE__ */ jsx(
12186
+ Form$2.Field,
12187
+ {
12188
+ control: form.control,
12189
+ name: "first_name",
12190
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12191
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12192
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12193
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12194
+ ] })
12195
+ }
12196
+ ),
12197
+ /* @__PURE__ */ jsx(
12198
+ Form$2.Field,
12199
+ {
12200
+ control: form.control,
12201
+ name: "last_name",
12202
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12203
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12204
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12205
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12206
+ ] })
12207
+ }
12208
+ )
12209
+ ] }),
12210
+ /* @__PURE__ */ jsx(
12211
+ Form$2.Field,
12512
12212
  {
12513
- content: tooltipContent,
12514
- showTooltip: !locationId || !shippingProfileId,
12515
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12516
- Combobox,
12517
- {
12518
- options: shippingOptions.options,
12519
- fetchNextPage: shippingOptions.fetchNextPage,
12520
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12521
- searchValue: shippingOptions.searchValue,
12522
- onSearchValueChange: shippingOptions.onSearchValueChange,
12523
- placeholder: "Select shipping option",
12524
- ...field,
12525
- disabled: !locationId || !shippingProfileId
12526
- }
12527
- ) }) })
12213
+ control: form.control,
12214
+ name: "company",
12215
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12216
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12217
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12218
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12219
+ ] })
12528
12220
  }
12529
- )
12530
- ] }) });
12531
- }
12532
- }
12533
- );
12534
- };
12535
- const CustomAmountField = ({
12536
- control,
12537
- currencyCode
12538
- }) => {
12539
- return /* @__PURE__ */ jsx(
12540
- Form$2.Field,
12541
- {
12542
- control,
12543
- name: "custom_amount",
12544
- render: ({ field: { onChange, ...field } }) => {
12545
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12546
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12547
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12548
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12221
+ ),
12222
+ /* @__PURE__ */ jsx(
12223
+ Form$2.Field,
12224
+ {
12225
+ control: form.control,
12226
+ name: "address_1",
12227
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12228
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12229
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12230
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12231
+ ] })
12232
+ }
12233
+ ),
12234
+ /* @__PURE__ */ jsx(
12235
+ Form$2.Field,
12236
+ {
12237
+ control: form.control,
12238
+ name: "address_2",
12239
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12240
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12241
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12242
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12243
+ ] })
12244
+ }
12245
+ ),
12246
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12247
+ /* @__PURE__ */ jsx(
12248
+ Form$2.Field,
12249
+ {
12250
+ control: form.control,
12251
+ name: "postal_code",
12252
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12253
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12254
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12255
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12256
+ ] })
12257
+ }
12258
+ ),
12259
+ /* @__PURE__ */ jsx(
12260
+ Form$2.Field,
12261
+ {
12262
+ control: form.control,
12263
+ name: "city",
12264
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12265
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12266
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12267
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12268
+ ] })
12269
+ }
12270
+ )
12549
12271
  ] }),
12550
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12551
- CurrencyInput,
12272
+ /* @__PURE__ */ jsx(
12273
+ Form$2.Field,
12552
12274
  {
12553
- ...field,
12554
- onValueChange: (value) => onChange(value),
12555
- symbol: getNativeSymbol(currencyCode),
12556
- code: currencyCode
12275
+ control: form.control,
12276
+ name: "province",
12277
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12278
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12279
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12280
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12281
+ ] })
12557
12282
  }
12558
- ) })
12559
- ] });
12560
- }
12283
+ ),
12284
+ /* @__PURE__ */ jsx(
12285
+ Form$2.Field,
12286
+ {
12287
+ control: form.control,
12288
+ name: "phone",
12289
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12290
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12291
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12292
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12293
+ ] })
12294
+ }
12295
+ )
12296
+ ] }) }),
12297
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12298
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12299
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12300
+ ] }) })
12301
+ ]
12561
12302
  }
12562
- );
12303
+ ) });
12563
12304
  };
12305
+ const schema$3 = addressSchema;
12564
12306
  const TransferOwnership = () => {
12565
12307
  const { id } = useParams();
12566
12308
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12584,7 +12326,7 @@ const TransferOwnershipForm = ({ order }) => {
12584
12326
  defaultValues: {
12585
12327
  customer_id: order.customer_id || ""
12586
12328
  },
12587
- resolver: zodResolver(schema)
12329
+ resolver: zodResolver(schema$2)
12588
12330
  });
12589
12331
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
12332
  const { handleSuccess } = useRouteModal();
@@ -12978,65 +12720,323 @@ const Illustration = () => {
12978
12720
  /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12979
12721
  "rect",
12980
12722
  {
12981
- width: "12",
12982
- height: "12",
12983
- fill: "white",
12984
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12723
+ width: "12",
12724
+ height: "12",
12725
+ fill: "white",
12726
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12727
+ }
12728
+ ) }),
12729
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12730
+ "rect",
12731
+ {
12732
+ width: "12",
12733
+ height: "12",
12734
+ fill: "white",
12735
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12736
+ }
12737
+ ) }),
12738
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12739
+ "rect",
12740
+ {
12741
+ width: "12",
12742
+ height: "12",
12743
+ fill: "white",
12744
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12745
+ }
12746
+ ) }),
12747
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12748
+ "rect",
12749
+ {
12750
+ width: "12",
12751
+ height: "12",
12752
+ fill: "white",
12753
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12754
+ }
12755
+ ) }),
12756
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12757
+ "rect",
12758
+ {
12759
+ width: "12",
12760
+ height: "12",
12761
+ fill: "white",
12762
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12763
+ }
12764
+ ) }),
12765
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12766
+ "rect",
12767
+ {
12768
+ width: "12",
12769
+ height: "12",
12770
+ fill: "white",
12771
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12772
+ }
12773
+ ) })
12774
+ ] })
12775
+ ]
12776
+ }
12777
+ );
12778
+ };
12779
+ const schema$2 = objectType({
12780
+ customer_id: stringType().min(1)
12781
+ });
12782
+ const Email = () => {
12783
+ const { id } = useParams();
12784
+ const { order, isPending, isError, error } = useOrder(id, {
12785
+ fields: "+email"
12786
+ });
12787
+ if (isError) {
12788
+ throw error;
12789
+ }
12790
+ const isReady = !isPending && !!order;
12791
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12792
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12793
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12794
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12795
+ ] }),
12796
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12797
+ ] });
12798
+ };
12799
+ const EmailForm = ({ order }) => {
12800
+ const form = useForm({
12801
+ defaultValues: {
12802
+ email: order.email ?? ""
12803
+ },
12804
+ resolver: zodResolver(schema$1)
12805
+ });
12806
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12807
+ const { handleSuccess } = useRouteModal();
12808
+ const onSubmit = form.handleSubmit(async (data) => {
12809
+ await mutateAsync(
12810
+ { email: data.email },
12811
+ {
12812
+ onSuccess: () => {
12813
+ handleSuccess();
12814
+ },
12815
+ onError: (error) => {
12816
+ toast.error(error.message);
12817
+ }
12818
+ }
12819
+ );
12820
+ });
12821
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12822
+ KeyboundForm,
12823
+ {
12824
+ className: "flex flex-1 flex-col overflow-hidden",
12825
+ onSubmit,
12826
+ children: [
12827
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
12828
+ Form$2.Field,
12829
+ {
12830
+ control: form.control,
12831
+ name: "email",
12832
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12833
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
12834
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12835
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12836
+ ] })
12837
+ }
12838
+ ) }),
12839
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12840
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12841
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12842
+ ] }) })
12843
+ ]
12844
+ }
12845
+ ) });
12846
+ };
12847
+ const schema$1 = objectType({
12848
+ email: stringType().email()
12849
+ });
12850
+ const BillingAddress = () => {
12851
+ const { id } = useParams();
12852
+ const { order, isPending, isError, error } = useOrder(id, {
12853
+ fields: "+billing_address"
12854
+ });
12855
+ if (isError) {
12856
+ throw error;
12857
+ }
12858
+ const isReady = !isPending && !!order;
12859
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12860
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12861
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12862
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12863
+ ] }),
12864
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12865
+ ] });
12866
+ };
12867
+ const BillingAddressForm = ({ order }) => {
12868
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12869
+ const form = useForm({
12870
+ defaultValues: {
12871
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12872
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12873
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12874
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12875
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12876
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12877
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12878
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12879
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12880
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12881
+ },
12882
+ resolver: zodResolver(schema)
12883
+ });
12884
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12885
+ const { handleSuccess } = useRouteModal();
12886
+ const onSubmit = form.handleSubmit(async (data) => {
12887
+ await mutateAsync(
12888
+ { billing_address: data },
12889
+ {
12890
+ onSuccess: () => {
12891
+ handleSuccess();
12892
+ },
12893
+ onError: (error) => {
12894
+ toast.error(error.message);
12895
+ }
12896
+ }
12897
+ );
12898
+ });
12899
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12900
+ KeyboundForm,
12901
+ {
12902
+ className: "flex flex-1 flex-col overflow-hidden",
12903
+ onSubmit,
12904
+ children: [
12905
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12906
+ /* @__PURE__ */ jsx(
12907
+ Form$2.Field,
12908
+ {
12909
+ control: form.control,
12910
+ name: "country_code",
12911
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12912
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12913
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12914
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12915
+ ] })
12985
12916
  }
12986
- ) }),
12987
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12988
- "rect",
12917
+ ),
12918
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12919
+ /* @__PURE__ */ jsx(
12920
+ Form$2.Field,
12921
+ {
12922
+ control: form.control,
12923
+ name: "first_name",
12924
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12925
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12926
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12927
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12928
+ ] })
12929
+ }
12930
+ ),
12931
+ /* @__PURE__ */ jsx(
12932
+ Form$2.Field,
12933
+ {
12934
+ control: form.control,
12935
+ name: "last_name",
12936
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12937
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12938
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12939
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12940
+ ] })
12941
+ }
12942
+ )
12943
+ ] }),
12944
+ /* @__PURE__ */ jsx(
12945
+ Form$2.Field,
12989
12946
  {
12990
- width: "12",
12991
- height: "12",
12992
- fill: "white",
12993
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12947
+ control: form.control,
12948
+ name: "company",
12949
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12950
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12951
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12952
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12953
+ ] })
12994
12954
  }
12995
- ) }),
12996
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12997
- "rect",
12955
+ ),
12956
+ /* @__PURE__ */ jsx(
12957
+ Form$2.Field,
12998
12958
  {
12999
- width: "12",
13000
- height: "12",
13001
- fill: "white",
13002
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12959
+ control: form.control,
12960
+ name: "address_1",
12961
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12962
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12963
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12964
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12965
+ ] })
13003
12966
  }
13004
- ) }),
13005
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13006
- "rect",
12967
+ ),
12968
+ /* @__PURE__ */ jsx(
12969
+ Form$2.Field,
13007
12970
  {
13008
- width: "12",
13009
- height: "12",
13010
- fill: "white",
13011
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12971
+ control: form.control,
12972
+ name: "address_2",
12973
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12974
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12975
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12976
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12977
+ ] })
13012
12978
  }
13013
- ) }),
13014
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13015
- "rect",
12979
+ ),
12980
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12981
+ /* @__PURE__ */ jsx(
12982
+ Form$2.Field,
12983
+ {
12984
+ control: form.control,
12985
+ name: "postal_code",
12986
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12987
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12988
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12989
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12990
+ ] })
12991
+ }
12992
+ ),
12993
+ /* @__PURE__ */ jsx(
12994
+ Form$2.Field,
12995
+ {
12996
+ control: form.control,
12997
+ name: "city",
12998
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12999
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13000
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13001
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13002
+ ] })
13003
+ }
13004
+ )
13005
+ ] }),
13006
+ /* @__PURE__ */ jsx(
13007
+ Form$2.Field,
13016
13008
  {
13017
- width: "12",
13018
- height: "12",
13019
- fill: "white",
13020
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13009
+ control: form.control,
13010
+ name: "province",
13011
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13012
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13013
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13014
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13015
+ ] })
13021
13016
  }
13022
- ) }),
13023
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13024
- "rect",
13017
+ ),
13018
+ /* @__PURE__ */ jsx(
13019
+ Form$2.Field,
13025
13020
  {
13026
- width: "12",
13027
- height: "12",
13028
- fill: "white",
13029
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13021
+ control: form.control,
13022
+ name: "phone",
13023
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13024
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13025
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13026
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13027
+ ] })
13030
13028
  }
13031
- ) })
13032
- ] })
13029
+ )
13030
+ ] }) }),
13031
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13032
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13033
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13034
+ ] }) })
13033
13035
  ]
13034
13036
  }
13035
- );
13037
+ ) });
13036
13038
  };
13037
- const schema = objectType({
13038
- customer_id: stringType().min(1)
13039
- });
13039
+ const schema = addressSchema;
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13061,41 +13061,41 @@ const routeModule = {
13061
13061
  Component: CustomItems,
13062
13062
  path: "/draft-orders/:id/custom-items"
13063
13063
  },
13064
- {
13065
- Component: BillingAddress,
13066
- path: "/draft-orders/:id/billing-address"
13067
- },
13068
13064
  {
13069
13065
  Component: Items,
13070
13066
  path: "/draft-orders/:id/items"
13071
13067
  },
13072
13068
  {
13073
- Component: Email,
13074
- path: "/draft-orders/:id/email"
13069
+ Component: Promotions,
13070
+ path: "/draft-orders/:id/promotions"
13075
13071
  },
13076
13072
  {
13077
13073
  Component: Metadata,
13078
13074
  path: "/draft-orders/:id/metadata"
13079
13075
  },
13080
- {
13081
- Component: Promotions,
13082
- path: "/draft-orders/:id/promotions"
13083
- },
13084
13076
  {
13085
13077
  Component: SalesChannel,
13086
13078
  path: "/draft-orders/:id/sales-channel"
13087
13079
  },
13088
- {
13089
- Component: ShippingAddress,
13090
- path: "/draft-orders/:id/shipping-address"
13091
- },
13092
13080
  {
13093
13081
  Component: Shipping,
13094
13082
  path: "/draft-orders/:id/shipping"
13095
13083
  },
13084
+ {
13085
+ Component: ShippingAddress,
13086
+ path: "/draft-orders/:id/shipping-address"
13087
+ },
13096
13088
  {
13097
13089
  Component: TransferOwnership,
13098
13090
  path: "/draft-orders/:id/transfer-ownership"
13091
+ },
13092
+ {
13093
+ Component: Email,
13094
+ path: "/draft-orders/:id/email"
13095
+ },
13096
+ {
13097
+ Component: BillingAddress,
13098
+ path: "/draft-orders/:id/billing-address"
13099
13099
  }
13100
13100
  ]
13101
13101
  }