@medusajs/draft-order 2.10.4-preview-20250926150202 → 2.10.4-preview-20250926180153

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.
@@ -9588,196 +9588,6 @@ const CustomItemsForm = () => {
9588
9588
  const schema$5 = objectType({
9589
9589
  email: stringType().email()
9590
9590
  });
9591
- const BillingAddress = () => {
9592
- const { id } = useParams();
9593
- const { order, isPending, isError, error } = useOrder(id, {
9594
- fields: "+billing_address"
9595
- });
9596
- if (isError) {
9597
- throw error;
9598
- }
9599
- const isReady = !isPending && !!order;
9600
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9601
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9602
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9603
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9604
- ] }),
9605
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9606
- ] });
9607
- };
9608
- const BillingAddressForm = ({ order }) => {
9609
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9610
- const form = useForm({
9611
- defaultValues: {
9612
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9613
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9614
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9615
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9616
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9617
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9618
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9619
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9620
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9621
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9622
- },
9623
- resolver: zodResolver(schema$4)
9624
- });
9625
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9626
- const { handleSuccess } = useRouteModal();
9627
- const onSubmit = form.handleSubmit(async (data) => {
9628
- await mutateAsync(
9629
- { billing_address: data },
9630
- {
9631
- onSuccess: () => {
9632
- handleSuccess();
9633
- },
9634
- onError: (error) => {
9635
- toast.error(error.message);
9636
- }
9637
- }
9638
- );
9639
- });
9640
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9641
- KeyboundForm,
9642
- {
9643
- className: "flex flex-1 flex-col overflow-hidden",
9644
- onSubmit,
9645
- children: [
9646
- /* @__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: [
9647
- /* @__PURE__ */ jsx(
9648
- Form$2.Field,
9649
- {
9650
- control: form.control,
9651
- name: "country_code",
9652
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9653
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9654
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9655
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9656
- ] })
9657
- }
9658
- ),
9659
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9660
- /* @__PURE__ */ jsx(
9661
- Form$2.Field,
9662
- {
9663
- control: form.control,
9664
- name: "first_name",
9665
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9666
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9667
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9668
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9669
- ] })
9670
- }
9671
- ),
9672
- /* @__PURE__ */ jsx(
9673
- Form$2.Field,
9674
- {
9675
- control: form.control,
9676
- name: "last_name",
9677
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9678
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9679
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9680
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9681
- ] })
9682
- }
9683
- )
9684
- ] }),
9685
- /* @__PURE__ */ jsx(
9686
- Form$2.Field,
9687
- {
9688
- control: form.control,
9689
- name: "company",
9690
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9691
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9692
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9693
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9694
- ] })
9695
- }
9696
- ),
9697
- /* @__PURE__ */ jsx(
9698
- Form$2.Field,
9699
- {
9700
- control: form.control,
9701
- name: "address_1",
9702
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9703
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9704
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9705
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9706
- ] })
9707
- }
9708
- ),
9709
- /* @__PURE__ */ jsx(
9710
- Form$2.Field,
9711
- {
9712
- control: form.control,
9713
- name: "address_2",
9714
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9715
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9716
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9717
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9718
- ] })
9719
- }
9720
- ),
9721
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9722
- /* @__PURE__ */ jsx(
9723
- Form$2.Field,
9724
- {
9725
- control: form.control,
9726
- name: "postal_code",
9727
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9728
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9729
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9730
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9731
- ] })
9732
- }
9733
- ),
9734
- /* @__PURE__ */ jsx(
9735
- Form$2.Field,
9736
- {
9737
- control: form.control,
9738
- name: "city",
9739
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9740
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9741
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9742
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9743
- ] })
9744
- }
9745
- )
9746
- ] }),
9747
- /* @__PURE__ */ jsx(
9748
- Form$2.Field,
9749
- {
9750
- control: form.control,
9751
- name: "province",
9752
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9753
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9754
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9755
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9756
- ] })
9757
- }
9758
- ),
9759
- /* @__PURE__ */ jsx(
9760
- Form$2.Field,
9761
- {
9762
- control: form.control,
9763
- name: "phone",
9764
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9765
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9766
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9767
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9768
- ] })
9769
- }
9770
- )
9771
- ] }) }),
9772
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9775
- ] }) })
9776
- ]
9777
- }
9778
- ) });
9779
- };
9780
- const schema$4 = addressSchema;
9781
9591
  const Email = () => {
9782
9592
  const { id } = useParams();
9783
9593
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9800,7 +9610,7 @@ const EmailForm = ({ order }) => {
9800
9610
  defaultValues: {
9801
9611
  email: order.email ?? ""
9802
9612
  },
9803
- resolver: zodResolver(schema$3)
9613
+ resolver: zodResolver(schema$4)
9804
9614
  });
9805
9615
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
9616
  const { handleSuccess } = useRouteModal();
@@ -9843,7 +9653,7 @@ const EmailForm = ({ order }) => {
9843
9653
  }
9844
9654
  ) });
9845
9655
  };
9846
- const schema$3 = objectType({
9656
+ const schema$4 = objectType({
9847
9657
  email: stringType().email()
9848
9658
  });
9849
9659
  const NumberInput = forwardRef(
@@ -10820,405 +10630,128 @@ const customItemSchema = objectType({
10820
10630
  quantity: numberType(),
10821
10631
  unit_price: unionType([numberType(), stringType()])
10822
10632
  });
10823
- const PROMOTION_QUERY_KEY = "promotions";
10824
- const promotionsQueryKeys = {
10825
- list: (query2) => [
10826
- PROMOTION_QUERY_KEY,
10827
- query2 ? query2 : void 0
10828
- ],
10829
- detail: (id, query2) => [
10830
- PROMOTION_QUERY_KEY,
10831
- id,
10832
- query2 ? query2 : void 0
10833
- ]
10834
- };
10835
- const usePromotions = (query2, options) => {
10836
- const { data, ...rest } = useQuery({
10837
- queryKey: promotionsQueryKeys.list(query2),
10838
- queryFn: async () => sdk.admin.promotion.list(query2),
10839
- ...options
10840
- });
10841
- return { ...data, ...rest };
10842
- };
10843
- const Promotions = () => {
10844
- const { id } = useParams();
10845
- const {
10846
- order: preview,
10847
- isError: isPreviewError,
10848
- error: previewError
10849
- } = useOrderPreview(id, void 0);
10850
- useInitiateOrderEdit({ preview });
10851
- const { onCancel } = useCancelOrderEdit({ preview });
10852
- if (isPreviewError) {
10853
- throw previewError;
10633
+ const InlineTip = forwardRef(
10634
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10635
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10636
+ return /* @__PURE__ */ jsxs(
10637
+ "div",
10638
+ {
10639
+ ref,
10640
+ className: clx(
10641
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10642
+ className
10643
+ ),
10644
+ ...props,
10645
+ children: [
10646
+ /* @__PURE__ */ jsx(
10647
+ "div",
10648
+ {
10649
+ role: "presentation",
10650
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10651
+ "bg-ui-tag-orange-icon": variant === "warning"
10652
+ })
10653
+ }
10654
+ ),
10655
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10656
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10657
+ labelValue,
10658
+ ":"
10659
+ ] }),
10660
+ " ",
10661
+ children
10662
+ ] })
10663
+ ]
10664
+ }
10665
+ );
10854
10666
  }
10855
- const isReady = !!preview;
10856
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10857
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10858
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10667
+ );
10668
+ InlineTip.displayName = "InlineTip";
10669
+ const MetadataFieldSchema = objectType({
10670
+ key: stringType(),
10671
+ disabled: booleanType().optional(),
10672
+ value: anyType()
10673
+ });
10674
+ const MetadataSchema = objectType({
10675
+ metadata: arrayType(MetadataFieldSchema)
10676
+ });
10677
+ const Metadata = () => {
10678
+ const { id } = useParams();
10679
+ const { order, isPending, isError, error } = useOrder(id, {
10680
+ fields: "metadata"
10681
+ });
10682
+ if (isError) {
10683
+ throw error;
10684
+ }
10685
+ const isReady = !isPending && !!order;
10686
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10687
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10688
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10689
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10690
+ ] }),
10691
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10859
10692
  ] });
10860
10693
  };
10861
- const PromotionForm = ({ preview }) => {
10862
- const { items, shipping_methods } = preview;
10863
- const [isSubmitting, setIsSubmitting] = useState(false);
10864
- const [comboboxValue, setComboboxValue] = useState("");
10694
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10695
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10696
+ const MetadataForm = ({ orderId, metadata }) => {
10865
10697
  const { handleSuccess } = useRouteModal();
10866
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10867
- const promoIds = getPromotionIds(items, shipping_methods);
10868
- const { promotions, isPending, isError, error } = usePromotions(
10869
- {
10870
- id: promoIds
10871
- },
10872
- {
10873
- enabled: !!promoIds.length
10874
- }
10875
- );
10876
- const comboboxData = useComboboxData({
10877
- queryKey: ["promotions", "combobox", promoIds],
10878
- queryFn: async (params) => {
10879
- return await sdk.admin.promotion.list({
10880
- ...params,
10881
- id: {
10882
- $nin: promoIds
10883
- }
10884
- });
10698
+ const hasUneditableRows = getHasUneditableRows(metadata);
10699
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10700
+ const form = useForm({
10701
+ defaultValues: {
10702
+ metadata: getDefaultValues(metadata)
10885
10703
  },
10886
- getOptions: (data) => {
10887
- return data.promotions.map((promotion) => ({
10888
- label: promotion.code,
10889
- value: promotion.code
10890
- }));
10891
- }
10704
+ resolver: zodResolver(MetadataSchema)
10892
10705
  });
10893
- const add = async (value) => {
10894
- if (!value) {
10895
- return;
10896
- }
10897
- addPromotions(
10706
+ const handleSubmit = form.handleSubmit(async (data) => {
10707
+ const parsedData = parseValues(data);
10708
+ await mutateAsync(
10898
10709
  {
10899
- promo_codes: [value]
10710
+ metadata: parsedData
10900
10711
  },
10901
10712
  {
10902
- onError: (e) => {
10903
- toast.error(e.message);
10904
- comboboxData.onSearchValueChange("");
10905
- setComboboxValue("");
10906
- },
10907
10713
  onSuccess: () => {
10908
- comboboxData.onSearchValueChange("");
10909
- setComboboxValue("");
10714
+ toast.success("Metadata updated");
10715
+ handleSuccess();
10716
+ },
10717
+ onError: (error) => {
10718
+ toast.error(error.message);
10910
10719
  }
10911
10720
  }
10912
10721
  );
10913
- };
10914
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10915
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10916
- const onSubmit = async () => {
10917
- setIsSubmitting(true);
10918
- let requestSucceeded = false;
10919
- await requestOrderEdit(void 0, {
10920
- onError: (e) => {
10921
- toast.error(e.message);
10922
- },
10923
- onSuccess: () => {
10924
- requestSucceeded = true;
10925
- }
10926
- });
10927
- if (!requestSucceeded) {
10928
- setIsSubmitting(false);
10929
- return;
10722
+ });
10723
+ const { fields, insert, remove } = useFieldArray({
10724
+ control: form.control,
10725
+ name: "metadata"
10726
+ });
10727
+ function deleteRow(index) {
10728
+ remove(index);
10729
+ if (fields.length === 1) {
10730
+ insert(0, {
10731
+ key: "",
10732
+ value: "",
10733
+ disabled: false
10734
+ });
10930
10735
  }
10931
- await confirmOrderEdit(void 0, {
10932
- onError: (e) => {
10933
- toast.error(e.message);
10934
- },
10935
- onSuccess: () => {
10936
- handleSuccess();
10937
- },
10938
- onSettled: () => {
10939
- setIsSubmitting(false);
10940
- }
10736
+ }
10737
+ function insertRow(index, position) {
10738
+ insert(index + (position === "above" ? 0 : 1), {
10739
+ key: "",
10740
+ value: "",
10741
+ disabled: false
10941
10742
  });
10942
- };
10943
- if (isError) {
10944
- throw error;
10945
10743
  }
10946
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10947
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
10948
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
10949
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10950
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10951
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10952
- ] }),
10953
- /* @__PURE__ */ jsx(
10954
- Combobox,
10955
- {
10956
- id: "promotion-combobox",
10957
- "aria-describedby": "promotion-combobox-hint",
10958
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10959
- fetchNextPage: comboboxData.fetchNextPage,
10960
- options: comboboxData.options,
10961
- onSearchValueChange: comboboxData.onSearchValueChange,
10962
- searchValue: comboboxData.searchValue,
10963
- disabled: comboboxData.disabled || isAddingPromotions,
10964
- onChange: add,
10965
- value: comboboxValue
10966
- }
10967
- )
10968
- ] }),
10969
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10970
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10971
- PromotionItem,
10972
- {
10973
- promotion,
10974
- orderId: preview.id,
10975
- isLoading: isPending
10976
- },
10977
- promotion.id
10978
- )) })
10979
- ] }) }),
10980
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10981
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10982
- /* @__PURE__ */ jsx(
10983
- Button,
10984
- {
10985
- size: "small",
10986
- type: "submit",
10987
- isLoading: isSubmitting || isAddingPromotions,
10988
- children: "Save"
10989
- }
10990
- )
10991
- ] }) })
10992
- ] });
10993
- };
10994
- const PromotionItem = ({
10995
- promotion,
10996
- orderId,
10997
- isLoading
10998
- }) => {
10999
- var _a;
11000
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11001
- const onRemove = async () => {
11002
- removePromotions(
11003
- {
11004
- promo_codes: [promotion.code]
11005
- },
11006
- {
11007
- onError: (e) => {
11008
- toast.error(e.message);
11009
- }
11010
- }
11011
- );
11012
- };
11013
- const displayValue = getDisplayValue(promotion);
11014
- return /* @__PURE__ */ jsxs(
11015
- "div",
10744
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10745
+ KeyboundForm,
11016
10746
  {
11017
- className: clx(
11018
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11019
- {
11020
- "animate-pulse": isLoading
11021
- }
11022
- ),
10747
+ onSubmit: handleSubmit,
10748
+ className: "flex flex-1 flex-col overflow-hidden",
11023
10749
  children: [
11024
- /* @__PURE__ */ jsxs("div", { children: [
11025
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11026
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11027
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11028
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11029
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11030
- ] }),
11031
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11032
- ] })
11033
- ] }),
11034
- /* @__PURE__ */ jsx(
11035
- IconButton,
11036
- {
11037
- size: "small",
11038
- type: "button",
11039
- variant: "transparent",
11040
- onClick: onRemove,
11041
- isLoading: isPending || isLoading,
11042
- children: /* @__PURE__ */ jsx(XMark, {})
11043
- }
11044
- )
11045
- ]
11046
- },
11047
- promotion.id
11048
- );
11049
- };
11050
- function getDisplayValue(promotion) {
11051
- var _a, _b, _c, _d;
11052
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11053
- if (!value) {
11054
- return null;
11055
- }
11056
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11057
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11058
- if (!currency) {
11059
- return null;
11060
- }
11061
- return getLocaleAmount(value, currency);
11062
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11063
- return formatPercentage(value);
11064
- }
11065
- return null;
11066
- }
11067
- const formatter = new Intl.NumberFormat([], {
11068
- style: "percent",
11069
- minimumFractionDigits: 2
11070
- });
11071
- const formatPercentage = (value, isPercentageValue = false) => {
11072
- let val = value || 0;
11073
- if (!isPercentageValue) {
11074
- val = val / 100;
11075
- }
11076
- return formatter.format(val);
11077
- };
11078
- function getPromotionIds(items, shippingMethods) {
11079
- const promotionIds = /* @__PURE__ */ new Set();
11080
- for (const item of items) {
11081
- if (item.adjustments) {
11082
- for (const adjustment of item.adjustments) {
11083
- if (adjustment.promotion_id) {
11084
- promotionIds.add(adjustment.promotion_id);
11085
- }
11086
- }
11087
- }
11088
- }
11089
- for (const shippingMethod of shippingMethods) {
11090
- if (shippingMethod.adjustments) {
11091
- for (const adjustment of shippingMethod.adjustments) {
11092
- if (adjustment.promotion_id) {
11093
- promotionIds.add(adjustment.promotion_id);
11094
- }
11095
- }
11096
- }
11097
- }
11098
- return Array.from(promotionIds);
11099
- }
11100
- const InlineTip = forwardRef(
11101
- ({ variant = "tip", label, className, children, ...props }, ref) => {
11102
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11103
- return /* @__PURE__ */ jsxs(
11104
- "div",
11105
- {
11106
- ref,
11107
- className: clx(
11108
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11109
- className
11110
- ),
11111
- ...props,
11112
- children: [
11113
- /* @__PURE__ */ jsx(
11114
- "div",
11115
- {
11116
- role: "presentation",
11117
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11118
- "bg-ui-tag-orange-icon": variant === "warning"
11119
- })
11120
- }
11121
- ),
11122
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
11123
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11124
- labelValue,
11125
- ":"
11126
- ] }),
11127
- " ",
11128
- children
11129
- ] })
11130
- ]
11131
- }
11132
- );
11133
- }
11134
- );
11135
- InlineTip.displayName = "InlineTip";
11136
- const MetadataFieldSchema = objectType({
11137
- key: stringType(),
11138
- disabled: booleanType().optional(),
11139
- value: anyType()
11140
- });
11141
- const MetadataSchema = objectType({
11142
- metadata: arrayType(MetadataFieldSchema)
11143
- });
11144
- const Metadata = () => {
11145
- const { id } = useParams();
11146
- const { order, isPending, isError, error } = useOrder(id, {
11147
- fields: "metadata"
11148
- });
11149
- if (isError) {
11150
- throw error;
11151
- }
11152
- const isReady = !isPending && !!order;
11153
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11154
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11155
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
11156
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11157
- ] }),
11158
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11159
- ] });
11160
- };
11161
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11162
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11163
- const MetadataForm = ({ orderId, metadata }) => {
11164
- const { handleSuccess } = useRouteModal();
11165
- const hasUneditableRows = getHasUneditableRows(metadata);
11166
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11167
- const form = useForm({
11168
- defaultValues: {
11169
- metadata: getDefaultValues(metadata)
11170
- },
11171
- resolver: zodResolver(MetadataSchema)
11172
- });
11173
- const handleSubmit = form.handleSubmit(async (data) => {
11174
- const parsedData = parseValues(data);
11175
- await mutateAsync(
11176
- {
11177
- metadata: parsedData
11178
- },
11179
- {
11180
- onSuccess: () => {
11181
- toast.success("Metadata updated");
11182
- handleSuccess();
11183
- },
11184
- onError: (error) => {
11185
- toast.error(error.message);
11186
- }
11187
- }
11188
- );
11189
- });
11190
- const { fields, insert, remove } = useFieldArray({
11191
- control: form.control,
11192
- name: "metadata"
11193
- });
11194
- function deleteRow(index) {
11195
- remove(index);
11196
- if (fields.length === 1) {
11197
- insert(0, {
11198
- key: "",
11199
- value: "",
11200
- disabled: false
11201
- });
11202
- }
11203
- }
11204
- function insertRow(index, position) {
11205
- insert(index + (position === "above" ? 0 : 1), {
11206
- key: "",
11207
- value: "",
11208
- disabled: false
11209
- });
11210
- }
11211
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11212
- KeyboundForm,
11213
- {
11214
- onSubmit: handleSubmit,
11215
- className: "flex flex-1 flex-col overflow-hidden",
11216
- children: [
11217
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11218
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11219
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11220
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
11221
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10750
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10751
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10752
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10753
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10754
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11222
10755
  ] }),
11223
10756
  fields.map((field, index) => {
11224
10757
  const isDisabled = field.disabled || false;
@@ -11363,89 +10896,366 @@ const GridInput = forwardRef(({ className, ...props }, ref) => {
11363
10896
  )
11364
10897
  }
11365
10898
  );
11366
- });
11367
- GridInput.displayName = "MetadataForm.GridInput";
11368
- const PlaceholderInner = () => {
11369
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11370
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11371
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11372
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11373
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11374
- ] }) })
11375
- ] });
10899
+ });
10900
+ GridInput.displayName = "MetadataForm.GridInput";
10901
+ const PlaceholderInner = () => {
10902
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10903
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10904
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10905
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10906
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10907
+ ] }) })
10908
+ ] });
10909
+ };
10910
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10911
+ function getDefaultValues(metadata) {
10912
+ if (!metadata || !Object.keys(metadata).length) {
10913
+ return [
10914
+ {
10915
+ key: "",
10916
+ value: "",
10917
+ disabled: false
10918
+ }
10919
+ ];
10920
+ }
10921
+ return Object.entries(metadata).map(([key, value]) => {
10922
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10923
+ return {
10924
+ key,
10925
+ value,
10926
+ disabled: true
10927
+ };
10928
+ }
10929
+ let stringValue = value;
10930
+ if (typeof value !== "string") {
10931
+ stringValue = JSON.stringify(value);
10932
+ }
10933
+ return {
10934
+ key,
10935
+ value: stringValue,
10936
+ original_key: key
10937
+ };
10938
+ });
10939
+ }
10940
+ function parseValues(values) {
10941
+ const metadata = values.metadata;
10942
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10943
+ if (isEmpty) {
10944
+ return null;
10945
+ }
10946
+ const update = {};
10947
+ metadata.forEach((field) => {
10948
+ let key = field.key;
10949
+ let value = field.value;
10950
+ const disabled = field.disabled;
10951
+ if (!key || !value) {
10952
+ return;
10953
+ }
10954
+ if (disabled) {
10955
+ update[key] = value;
10956
+ return;
10957
+ }
10958
+ key = key.trim();
10959
+ value = value.trim();
10960
+ if (value === "true") {
10961
+ update[key] = true;
10962
+ } else if (value === "false") {
10963
+ update[key] = false;
10964
+ } else {
10965
+ const parsedNumber = parseFloat(value);
10966
+ if (!isNaN(parsedNumber)) {
10967
+ update[key] = parsedNumber;
10968
+ } else {
10969
+ update[key] = value;
10970
+ }
10971
+ }
10972
+ });
10973
+ return update;
10974
+ }
10975
+ function getHasUneditableRows(metadata) {
10976
+ if (!metadata) {
10977
+ return false;
10978
+ }
10979
+ return Object.values(metadata).some(
10980
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10981
+ );
10982
+ }
10983
+ const PROMOTION_QUERY_KEY = "promotions";
10984
+ const promotionsQueryKeys = {
10985
+ list: (query2) => [
10986
+ PROMOTION_QUERY_KEY,
10987
+ query2 ? query2 : void 0
10988
+ ],
10989
+ detail: (id, query2) => [
10990
+ PROMOTION_QUERY_KEY,
10991
+ id,
10992
+ query2 ? query2 : void 0
10993
+ ]
10994
+ };
10995
+ const usePromotions = (query2, options) => {
10996
+ const { data, ...rest } = useQuery({
10997
+ queryKey: promotionsQueryKeys.list(query2),
10998
+ queryFn: async () => sdk.admin.promotion.list(query2),
10999
+ ...options
11000
+ });
11001
+ return { ...data, ...rest };
11002
+ };
11003
+ const Promotions = () => {
11004
+ const { id } = useParams();
11005
+ const {
11006
+ order: preview,
11007
+ isError: isPreviewError,
11008
+ error: previewError
11009
+ } = useOrderPreview(id, void 0);
11010
+ useInitiateOrderEdit({ preview });
11011
+ const { onCancel } = useCancelOrderEdit({ preview });
11012
+ if (isPreviewError) {
11013
+ throw previewError;
11014
+ }
11015
+ const isReady = !!preview;
11016
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11017
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11018
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11019
+ ] });
11020
+ };
11021
+ const PromotionForm = ({ preview }) => {
11022
+ const { items, shipping_methods } = preview;
11023
+ const [isSubmitting, setIsSubmitting] = useState(false);
11024
+ const [comboboxValue, setComboboxValue] = useState("");
11025
+ const { handleSuccess } = useRouteModal();
11026
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11027
+ const promoIds = getPromotionIds(items, shipping_methods);
11028
+ const { promotions, isPending, isError, error } = usePromotions(
11029
+ {
11030
+ id: promoIds
11031
+ },
11032
+ {
11033
+ enabled: !!promoIds.length
11034
+ }
11035
+ );
11036
+ const comboboxData = useComboboxData({
11037
+ queryKey: ["promotions", "combobox", promoIds],
11038
+ queryFn: async (params) => {
11039
+ return await sdk.admin.promotion.list({
11040
+ ...params,
11041
+ id: {
11042
+ $nin: promoIds
11043
+ }
11044
+ });
11045
+ },
11046
+ getOptions: (data) => {
11047
+ return data.promotions.map((promotion) => ({
11048
+ label: promotion.code,
11049
+ value: promotion.code
11050
+ }));
11051
+ }
11052
+ });
11053
+ const add = async (value) => {
11054
+ if (!value) {
11055
+ return;
11056
+ }
11057
+ addPromotions(
11058
+ {
11059
+ promo_codes: [value]
11060
+ },
11061
+ {
11062
+ onError: (e) => {
11063
+ toast.error(e.message);
11064
+ comboboxData.onSearchValueChange("");
11065
+ setComboboxValue("");
11066
+ },
11067
+ onSuccess: () => {
11068
+ comboboxData.onSearchValueChange("");
11069
+ setComboboxValue("");
11070
+ }
11071
+ }
11072
+ );
11073
+ };
11074
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11075
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11076
+ const onSubmit = async () => {
11077
+ setIsSubmitting(true);
11078
+ let requestSucceeded = false;
11079
+ await requestOrderEdit(void 0, {
11080
+ onError: (e) => {
11081
+ toast.error(e.message);
11082
+ },
11083
+ onSuccess: () => {
11084
+ requestSucceeded = true;
11085
+ }
11086
+ });
11087
+ if (!requestSucceeded) {
11088
+ setIsSubmitting(false);
11089
+ return;
11090
+ }
11091
+ await confirmOrderEdit(void 0, {
11092
+ onError: (e) => {
11093
+ toast.error(e.message);
11094
+ },
11095
+ onSuccess: () => {
11096
+ handleSuccess();
11097
+ },
11098
+ onSettled: () => {
11099
+ setIsSubmitting(false);
11100
+ }
11101
+ });
11102
+ };
11103
+ if (isError) {
11104
+ throw error;
11105
+ }
11106
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11107
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11108
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11109
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11110
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11111
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11112
+ ] }),
11113
+ /* @__PURE__ */ jsx(
11114
+ Combobox,
11115
+ {
11116
+ id: "promotion-combobox",
11117
+ "aria-describedby": "promotion-combobox-hint",
11118
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11119
+ fetchNextPage: comboboxData.fetchNextPage,
11120
+ options: comboboxData.options,
11121
+ onSearchValueChange: comboboxData.onSearchValueChange,
11122
+ searchValue: comboboxData.searchValue,
11123
+ disabled: comboboxData.disabled || isAddingPromotions,
11124
+ onChange: add,
11125
+ value: comboboxValue
11126
+ }
11127
+ )
11128
+ ] }),
11129
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11130
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11131
+ PromotionItem,
11132
+ {
11133
+ promotion,
11134
+ orderId: preview.id,
11135
+ isLoading: isPending
11136
+ },
11137
+ promotion.id
11138
+ )) })
11139
+ ] }) }),
11140
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11141
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11142
+ /* @__PURE__ */ jsx(
11143
+ Button,
11144
+ {
11145
+ size: "small",
11146
+ type: "submit",
11147
+ isLoading: isSubmitting || isAddingPromotions,
11148
+ children: "Save"
11149
+ }
11150
+ )
11151
+ ] }) })
11152
+ ] });
11153
+ };
11154
+ const PromotionItem = ({
11155
+ promotion,
11156
+ orderId,
11157
+ isLoading
11158
+ }) => {
11159
+ var _a;
11160
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11161
+ const onRemove = async () => {
11162
+ removePromotions(
11163
+ {
11164
+ promo_codes: [promotion.code]
11165
+ },
11166
+ {
11167
+ onError: (e) => {
11168
+ toast.error(e.message);
11169
+ }
11170
+ }
11171
+ );
11172
+ };
11173
+ const displayValue = getDisplayValue(promotion);
11174
+ return /* @__PURE__ */ jsxs(
11175
+ "div",
11176
+ {
11177
+ className: clx(
11178
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11179
+ {
11180
+ "animate-pulse": isLoading
11181
+ }
11182
+ ),
11183
+ children: [
11184
+ /* @__PURE__ */ jsxs("div", { children: [
11185
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11186
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11187
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11188
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11189
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11190
+ ] }),
11191
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11192
+ ] })
11193
+ ] }),
11194
+ /* @__PURE__ */ jsx(
11195
+ IconButton,
11196
+ {
11197
+ size: "small",
11198
+ type: "button",
11199
+ variant: "transparent",
11200
+ onClick: onRemove,
11201
+ isLoading: isPending || isLoading,
11202
+ children: /* @__PURE__ */ jsx(XMark, {})
11203
+ }
11204
+ )
11205
+ ]
11206
+ },
11207
+ promotion.id
11208
+ );
11376
11209
  };
11377
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11378
- function getDefaultValues(metadata) {
11379
- if (!metadata || !Object.keys(metadata).length) {
11380
- return [
11381
- {
11382
- key: "",
11383
- value: "",
11384
- disabled: false
11385
- }
11386
- ];
11210
+ function getDisplayValue(promotion) {
11211
+ var _a, _b, _c, _d;
11212
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11213
+ if (!value) {
11214
+ return null;
11387
11215
  }
11388
- return Object.entries(metadata).map(([key, value]) => {
11389
- if (!EDITABLE_TYPES.includes(typeof value)) {
11390
- return {
11391
- key,
11392
- value,
11393
- disabled: true
11394
- };
11395
- }
11396
- let stringValue = value;
11397
- if (typeof value !== "string") {
11398
- stringValue = JSON.stringify(value);
11216
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11217
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11218
+ if (!currency) {
11219
+ return null;
11399
11220
  }
11400
- return {
11401
- key,
11402
- value: stringValue,
11403
- original_key: key
11404
- };
11405
- });
11221
+ return getLocaleAmount(value, currency);
11222
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11223
+ return formatPercentage(value);
11224
+ }
11225
+ return null;
11406
11226
  }
11407
- function parseValues(values) {
11408
- const metadata = values.metadata;
11409
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11410
- if (isEmpty) {
11411
- return null;
11227
+ const formatter = new Intl.NumberFormat([], {
11228
+ style: "percent",
11229
+ minimumFractionDigits: 2
11230
+ });
11231
+ const formatPercentage = (value, isPercentageValue = false) => {
11232
+ let val = value || 0;
11233
+ if (!isPercentageValue) {
11234
+ val = val / 100;
11412
11235
  }
11413
- const update = {};
11414
- metadata.forEach((field) => {
11415
- let key = field.key;
11416
- let value = field.value;
11417
- const disabled = field.disabled;
11418
- if (!key || !value) {
11419
- return;
11420
- }
11421
- if (disabled) {
11422
- update[key] = value;
11423
- return;
11236
+ return formatter.format(val);
11237
+ };
11238
+ function getPromotionIds(items, shippingMethods) {
11239
+ const promotionIds = /* @__PURE__ */ new Set();
11240
+ for (const item of items) {
11241
+ if (item.adjustments) {
11242
+ for (const adjustment of item.adjustments) {
11243
+ if (adjustment.promotion_id) {
11244
+ promotionIds.add(adjustment.promotion_id);
11245
+ }
11246
+ }
11424
11247
  }
11425
- key = key.trim();
11426
- value = value.trim();
11427
- if (value === "true") {
11428
- update[key] = true;
11429
- } else if (value === "false") {
11430
- update[key] = false;
11431
- } else {
11432
- const parsedNumber = parseFloat(value);
11433
- if (!isNaN(parsedNumber)) {
11434
- update[key] = parsedNumber;
11435
- } else {
11436
- update[key] = value;
11248
+ }
11249
+ for (const shippingMethod of shippingMethods) {
11250
+ if (shippingMethod.adjustments) {
11251
+ for (const adjustment of shippingMethod.adjustments) {
11252
+ if (adjustment.promotion_id) {
11253
+ promotionIds.add(adjustment.promotion_id);
11254
+ }
11437
11255
  }
11438
11256
  }
11439
- });
11440
- return update;
11441
- }
11442
- function getHasUneditableRows(metadata) {
11443
- if (!metadata) {
11444
- return false;
11445
11257
  }
11446
- return Object.values(metadata).some(
11447
- (value) => !EDITABLE_TYPES.includes(typeof value)
11448
- );
11258
+ return Array.from(promotionIds);
11449
11259
  }
11450
11260
  const SalesChannel = () => {
11451
11261
  const { id } = useParams();
@@ -11475,7 +11285,7 @@ const SalesChannelForm = ({ order }) => {
11475
11285
  defaultValues: {
11476
11286
  sales_channel_id: order.sales_channel_id || ""
11477
11287
  },
11478
- resolver: zodResolver(schema$2)
11288
+ resolver: zodResolver(schema$3)
11479
11289
  });
11480
11290
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
11291
  const { handleSuccess } = useRouteModal();
@@ -11550,7 +11360,7 @@ const SalesChannelField = ({ control, order }) => {
11550
11360
  }
11551
11361
  );
11552
11362
  };
11553
- const schema$2 = objectType({
11363
+ const schema$3 = objectType({
11554
11364
  sales_channel_id: stringType().min(1)
11555
11365
  });
11556
11366
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12294,72 +12104,275 @@ const ShippingOptionField = ({
12294
12104
  enabled: !!locationId && !!shippingProfileId,
12295
12105
  defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12296
12106
  });
12297
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12298
- return /* @__PURE__ */ jsx(
12299
- Form$2.Field,
12107
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12108
+ return /* @__PURE__ */ jsx(
12109
+ Form$2.Field,
12110
+ {
12111
+ control,
12112
+ name: "shipping_option_id",
12113
+ render: ({ field }) => {
12114
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12115
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12116
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12117
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12118
+ ] }),
12119
+ /* @__PURE__ */ jsx(
12120
+ ConditionalTooltip,
12121
+ {
12122
+ content: tooltipContent,
12123
+ showTooltip: !locationId || !shippingProfileId,
12124
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12125
+ Combobox,
12126
+ {
12127
+ options: shippingOptions.options,
12128
+ fetchNextPage: shippingOptions.fetchNextPage,
12129
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12130
+ searchValue: shippingOptions.searchValue,
12131
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12132
+ placeholder: "Select shipping option",
12133
+ ...field,
12134
+ disabled: !locationId || !shippingProfileId
12135
+ }
12136
+ ) }) })
12137
+ }
12138
+ )
12139
+ ] }) });
12140
+ }
12141
+ }
12142
+ );
12143
+ };
12144
+ const CustomAmountField = ({
12145
+ control,
12146
+ currencyCode
12147
+ }) => {
12148
+ return /* @__PURE__ */ jsx(
12149
+ Form$2.Field,
12150
+ {
12151
+ control,
12152
+ name: "custom_amount",
12153
+ render: ({ field: { onChange, ...field } }) => {
12154
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12155
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12156
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12157
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12158
+ ] }),
12159
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12160
+ CurrencyInput,
12161
+ {
12162
+ ...field,
12163
+ onValueChange: (value) => onChange(value),
12164
+ symbol: getNativeSymbol(currencyCode),
12165
+ code: currencyCode
12166
+ }
12167
+ ) })
12168
+ ] });
12169
+ }
12170
+ }
12171
+ );
12172
+ };
12173
+ const ShippingAddress = () => {
12174
+ const { id } = useParams();
12175
+ const { order, isPending, isError, error } = useOrder(id, {
12176
+ fields: "+shipping_address"
12177
+ });
12178
+ if (isError) {
12179
+ throw error;
12180
+ }
12181
+ const isReady = !isPending && !!order;
12182
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12183
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12184
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12185
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12186
+ ] }),
12187
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12188
+ ] });
12189
+ };
12190
+ const ShippingAddressForm = ({ order }) => {
12191
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12192
+ const form = useForm({
12193
+ defaultValues: {
12194
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12195
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12196
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12197
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12198
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12199
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12200
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12201
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12202
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12203
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12204
+ },
12205
+ resolver: zodResolver(schema$2)
12206
+ });
12207
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12208
+ const { handleSuccess } = useRouteModal();
12209
+ const onSubmit = form.handleSubmit(async (data) => {
12210
+ await mutateAsync(
12211
+ {
12212
+ shipping_address: {
12213
+ first_name: data.first_name,
12214
+ last_name: data.last_name,
12215
+ company: data.company,
12216
+ address_1: data.address_1,
12217
+ address_2: data.address_2,
12218
+ city: data.city,
12219
+ province: data.province,
12220
+ country_code: data.country_code,
12221
+ postal_code: data.postal_code,
12222
+ phone: data.phone
12223
+ }
12224
+ },
12225
+ {
12226
+ onSuccess: () => {
12227
+ handleSuccess();
12228
+ },
12229
+ onError: (error) => {
12230
+ toast.error(error.message);
12231
+ }
12232
+ }
12233
+ );
12234
+ });
12235
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12236
+ KeyboundForm,
12300
12237
  {
12301
- control,
12302
- name: "shipping_option_id",
12303
- render: ({ field }) => {
12304
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12305
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12306
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12307
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12238
+ className: "flex flex-1 flex-col overflow-hidden",
12239
+ onSubmit,
12240
+ children: [
12241
+ /* @__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: [
12242
+ /* @__PURE__ */ jsx(
12243
+ Form$2.Field,
12244
+ {
12245
+ control: form.control,
12246
+ name: "country_code",
12247
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12248
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12249
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12250
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12251
+ ] })
12252
+ }
12253
+ ),
12254
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12255
+ /* @__PURE__ */ jsx(
12256
+ Form$2.Field,
12257
+ {
12258
+ control: form.control,
12259
+ name: "first_name",
12260
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12261
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12262
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12263
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12264
+ ] })
12265
+ }
12266
+ ),
12267
+ /* @__PURE__ */ jsx(
12268
+ Form$2.Field,
12269
+ {
12270
+ control: form.control,
12271
+ name: "last_name",
12272
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12273
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12274
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12275
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12276
+ ] })
12277
+ }
12278
+ )
12308
12279
  ] }),
12309
12280
  /* @__PURE__ */ jsx(
12310
- ConditionalTooltip,
12281
+ Form$2.Field,
12311
12282
  {
12312
- content: tooltipContent,
12313
- showTooltip: !locationId || !shippingProfileId,
12314
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12315
- Combobox,
12316
- {
12317
- options: shippingOptions.options,
12318
- fetchNextPage: shippingOptions.fetchNextPage,
12319
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12320
- searchValue: shippingOptions.searchValue,
12321
- onSearchValueChange: shippingOptions.onSearchValueChange,
12322
- placeholder: "Select shipping option",
12323
- ...field,
12324
- disabled: !locationId || !shippingProfileId
12325
- }
12326
- ) }) })
12283
+ control: form.control,
12284
+ name: "company",
12285
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12286
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12287
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12288
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12289
+ ] })
12327
12290
  }
12328
- )
12329
- ] }) });
12330
- }
12331
- }
12332
- );
12333
- };
12334
- const CustomAmountField = ({
12335
- control,
12336
- currencyCode
12337
- }) => {
12338
- return /* @__PURE__ */ jsx(
12339
- Form$2.Field,
12340
- {
12341
- control,
12342
- name: "custom_amount",
12343
- render: ({ field: { onChange, ...field } }) => {
12344
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12345
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12346
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12347
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12291
+ ),
12292
+ /* @__PURE__ */ jsx(
12293
+ Form$2.Field,
12294
+ {
12295
+ control: form.control,
12296
+ name: "address_1",
12297
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12298
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12299
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12300
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12301
+ ] })
12302
+ }
12303
+ ),
12304
+ /* @__PURE__ */ jsx(
12305
+ Form$2.Field,
12306
+ {
12307
+ control: form.control,
12308
+ name: "address_2",
12309
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12310
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12311
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12312
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12313
+ ] })
12314
+ }
12315
+ ),
12316
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12317
+ /* @__PURE__ */ jsx(
12318
+ Form$2.Field,
12319
+ {
12320
+ control: form.control,
12321
+ name: "postal_code",
12322
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12323
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12324
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12325
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12326
+ ] })
12327
+ }
12328
+ ),
12329
+ /* @__PURE__ */ jsx(
12330
+ Form$2.Field,
12331
+ {
12332
+ control: form.control,
12333
+ name: "city",
12334
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12335
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12336
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12337
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12338
+ ] })
12339
+ }
12340
+ )
12348
12341
  ] }),
12349
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
- CurrencyInput,
12342
+ /* @__PURE__ */ jsx(
12343
+ Form$2.Field,
12351
12344
  {
12352
- ...field,
12353
- onValueChange: (value) => onChange(value),
12354
- symbol: getNativeSymbol(currencyCode),
12355
- code: currencyCode
12345
+ control: form.control,
12346
+ name: "province",
12347
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12348
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12349
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12350
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12351
+ ] })
12356
12352
  }
12357
- ) })
12358
- ] });
12359
- }
12353
+ ),
12354
+ /* @__PURE__ */ jsx(
12355
+ Form$2.Field,
12356
+ {
12357
+ control: form.control,
12358
+ name: "phone",
12359
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12360
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12361
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12362
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12363
+ ] })
12364
+ }
12365
+ )
12366
+ ] }) }),
12367
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12368
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12369
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12370
+ ] }) })
12371
+ ]
12360
12372
  }
12361
- );
12373
+ ) });
12362
12374
  };
12375
+ const schema$2 = addressSchema;
12363
12376
  const TransferOwnership = () => {
12364
12377
  const { id } = useParams();
12365
12378
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12836,10 +12849,10 @@ const Illustration = () => {
12836
12849
  const schema$1 = objectType({
12837
12850
  customer_id: stringType().min(1)
12838
12851
  });
12839
- const ShippingAddress = () => {
12852
+ const BillingAddress = () => {
12840
12853
  const { id } = useParams();
12841
12854
  const { order, isPending, isError, error } = useOrder(id, {
12842
- fields: "+shipping_address"
12855
+ fields: "+billing_address"
12843
12856
  });
12844
12857
  if (isError) {
12845
12858
  throw error;
@@ -12847,26 +12860,26 @@ const ShippingAddress = () => {
12847
12860
  const isReady = !isPending && !!order;
12848
12861
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12849
12862
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12850
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12851
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12863
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12864
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12852
12865
  ] }),
12853
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12866
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12854
12867
  ] });
12855
12868
  };
12856
- const ShippingAddressForm = ({ order }) => {
12869
+ const BillingAddressForm = ({ order }) => {
12857
12870
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12858
12871
  const form = useForm({
12859
12872
  defaultValues: {
12860
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12861
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12862
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12863
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12864
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12865
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12866
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12867
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12868
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12869
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12873
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12874
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12875
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12876
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12877
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12878
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12879
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12880
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12881
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12882
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12870
12883
  },
12871
12884
  resolver: zodResolver(schema)
12872
12885
  });
@@ -12874,20 +12887,7 @@ const ShippingAddressForm = ({ order }) => {
12874
12887
  const { handleSuccess } = useRouteModal();
12875
12888
  const onSubmit = form.handleSubmit(async (data) => {
12876
12889
  await mutateAsync(
12877
- {
12878
- shipping_address: {
12879
- first_name: data.first_name,
12880
- last_name: data.last_name,
12881
- company: data.company,
12882
- address_1: data.address_1,
12883
- address_2: data.address_2,
12884
- city: data.city,
12885
- province: data.province,
12886
- country_code: data.country_code,
12887
- postal_code: data.postal_code,
12888
- phone: data.phone
12889
- }
12890
- },
12890
+ { billing_address: data },
12891
12891
  {
12892
12892
  onSuccess: () => {
12893
12893
  handleSuccess();
@@ -13063,10 +13063,6 @@ const routeModule = {
13063
13063
  Component: CustomItems,
13064
13064
  path: "/draft-orders/:id/custom-items"
13065
13065
  },
13066
- {
13067
- Component: BillingAddress,
13068
- path: "/draft-orders/:id/billing-address"
13069
- },
13070
13066
  {
13071
13067
  Component: Email,
13072
13068
  path: "/draft-orders/:id/email"
@@ -13075,14 +13071,14 @@ const routeModule = {
13075
13071
  Component: Items,
13076
13072
  path: "/draft-orders/:id/items"
13077
13073
  },
13078
- {
13079
- Component: Promotions,
13080
- path: "/draft-orders/:id/promotions"
13081
- },
13082
13074
  {
13083
13075
  Component: Metadata,
13084
13076
  path: "/draft-orders/:id/metadata"
13085
13077
  },
13078
+ {
13079
+ Component: Promotions,
13080
+ path: "/draft-orders/:id/promotions"
13081
+ },
13086
13082
  {
13087
13083
  Component: SalesChannel,
13088
13084
  path: "/draft-orders/:id/sales-channel"
@@ -13091,13 +13087,17 @@ const routeModule = {
13091
13087
  Component: Shipping,
13092
13088
  path: "/draft-orders/:id/shipping"
13093
13089
  },
13090
+ {
13091
+ Component: ShippingAddress,
13092
+ path: "/draft-orders/:id/shipping-address"
13093
+ },
13094
13094
  {
13095
13095
  Component: TransferOwnership,
13096
13096
  path: "/draft-orders/:id/transfer-ownership"
13097
13097
  },
13098
13098
  {
13099
- Component: ShippingAddress,
13100
- path: "/draft-orders/:id/shipping-address"
13099
+ Component: BillingAddress,
13100
+ path: "/draft-orders/:id/billing-address"
13101
13101
  }
13102
13102
  ]
13103
13103
  }