@medusajs/draft-order 2.10.4-preview-20250925090152 → 2.10.4-preview-20250925180208

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.
@@ -9567,217 +9567,6 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
- const BillingAddress = () => {
9571
- const { id } = useParams();
9572
- const { order, isPending, isError, error } = useOrder(id, {
9573
- fields: "+billing_address"
9574
- });
9575
- if (isError) {
9576
- throw error;
9577
- }
9578
- const isReady = !isPending && !!order;
9579
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9580
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
- ] }),
9584
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9585
- ] });
9586
- };
9587
- const BillingAddressForm = ({ order }) => {
9588
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9589
- const form = useForm({
9590
- defaultValues: {
9591
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
- },
9602
- resolver: zodResolver(schema$5)
9603
- });
9604
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
- const { handleSuccess } = useRouteModal();
9606
- const onSubmit = form.handleSubmit(async (data) => {
9607
- await mutateAsync(
9608
- { billing_address: data },
9609
- {
9610
- onSuccess: () => {
9611
- handleSuccess();
9612
- },
9613
- onError: (error) => {
9614
- toast.error(error.message);
9615
- }
9616
- }
9617
- );
9618
- });
9619
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
- KeyboundForm,
9621
- {
9622
- className: "flex flex-1 flex-col overflow-hidden",
9623
- onSubmit,
9624
- children: [
9625
- /* @__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: [
9626
- /* @__PURE__ */ jsx(
9627
- Form$2.Field,
9628
- {
9629
- control: form.control,
9630
- name: "country_code",
9631
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
- ] })
9636
- }
9637
- ),
9638
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
- /* @__PURE__ */ jsx(
9640
- Form$2.Field,
9641
- {
9642
- control: form.control,
9643
- name: "first_name",
9644
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
- ] })
9649
- }
9650
- ),
9651
- /* @__PURE__ */ jsx(
9652
- Form$2.Field,
9653
- {
9654
- control: form.control,
9655
- name: "last_name",
9656
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
- ] })
9661
- }
9662
- )
9663
- ] }),
9664
- /* @__PURE__ */ jsx(
9665
- Form$2.Field,
9666
- {
9667
- control: form.control,
9668
- name: "company",
9669
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
- ] })
9674
- }
9675
- ),
9676
- /* @__PURE__ */ jsx(
9677
- Form$2.Field,
9678
- {
9679
- control: form.control,
9680
- name: "address_1",
9681
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
- ] })
9686
- }
9687
- ),
9688
- /* @__PURE__ */ jsx(
9689
- Form$2.Field,
9690
- {
9691
- control: form.control,
9692
- name: "address_2",
9693
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
- ] })
9698
- }
9699
- ),
9700
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
- /* @__PURE__ */ jsx(
9702
- Form$2.Field,
9703
- {
9704
- control: form.control,
9705
- name: "postal_code",
9706
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
- ] })
9711
- }
9712
- ),
9713
- /* @__PURE__ */ jsx(
9714
- Form$2.Field,
9715
- {
9716
- control: form.control,
9717
- name: "city",
9718
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
- ] })
9723
- }
9724
- )
9725
- ] }),
9726
- /* @__PURE__ */ jsx(
9727
- Form$2.Field,
9728
- {
9729
- control: form.control,
9730
- name: "province",
9731
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
- ] })
9736
- }
9737
- ),
9738
- /* @__PURE__ */ jsx(
9739
- Form$2.Field,
9740
- {
9741
- control: form.control,
9742
- name: "phone",
9743
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
- ] })
9748
- }
9749
- )
9750
- ] }) }),
9751
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
- ] }) })
9755
- ]
9756
- }
9757
- ) });
9758
- };
9759
- const schema$5 = addressSchema;
9760
- const CustomItems = () => {
9761
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
- ] });
9765
- };
9766
- const CustomItemsForm = () => {
9767
- const form = useForm({
9768
- resolver: zodResolver(schema$4)
9769
- });
9770
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
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", children: "Save" })
9775
- ] }) })
9776
- ] }) });
9777
- };
9778
- const schema$4 = objectType({
9779
- email: stringType().email()
9780
- });
9781
9570
  const Email = () => {
9782
9571
  const { id } = useParams();
9783
9572
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9800,7 +9589,7 @@ const EmailForm = ({ order }) => {
9800
9589
  defaultValues: {
9801
9590
  email: order.email ?? ""
9802
9591
  },
9803
- resolver: zodResolver(schema$3)
9592
+ resolver: zodResolver(schema$5)
9804
9593
  });
9805
9594
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
9595
  const { handleSuccess } = useRouteModal();
@@ -9843,7 +9632,7 @@ const EmailForm = ({ order }) => {
9843
9632
  }
9844
9633
  ) });
9845
9634
  };
9846
- const schema$3 = objectType({
9635
+ const schema$5 = objectType({
9847
9636
  email: stringType().email()
9848
9637
  });
9849
9638
  const NumberInput = forwardRef(
@@ -10820,283 +10609,6 @@ const customItemSchema = objectType({
10820
10609
  quantity: numberType(),
10821
10610
  unit_price: unionType([numberType(), stringType()])
10822
10611
  });
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;
10854
- }
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 })
10859
- ] });
10860
- };
10861
- const PromotionForm = ({ preview }) => {
10862
- const { items, shipping_methods } = preview;
10863
- const [isSubmitting, setIsSubmitting] = useState(false);
10864
- const [comboboxValue, setComboboxValue] = useState("");
10865
- 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
- });
10885
- },
10886
- getOptions: (data) => {
10887
- return data.promotions.map((promotion) => ({
10888
- label: promotion.code,
10889
- value: promotion.code
10890
- }));
10891
- }
10892
- });
10893
- const add = async (value) => {
10894
- if (!value) {
10895
- return;
10896
- }
10897
- addPromotions(
10898
- {
10899
- promo_codes: [value]
10900
- },
10901
- {
10902
- onError: (e) => {
10903
- toast.error(e.message);
10904
- comboboxData.onSearchValueChange("");
10905
- setComboboxValue("");
10906
- },
10907
- onSuccess: () => {
10908
- comboboxData.onSearchValueChange("");
10909
- setComboboxValue("");
10910
- }
10911
- }
10912
- );
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;
10930
- }
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
- }
10941
- });
10942
- };
10943
- if (isError) {
10944
- throw error;
10945
- }
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",
11016
- {
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
- ),
11023
- 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
10612
  const InlineTip = forwardRef(
11101
10613
  ({ variant = "tip", label, className, children, ...props }, ref) => {
11102
10614
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11374,78 +10886,355 @@ const PlaceholderInner = () => {
11374
10886
  ] }) })
11375
10887
  ] });
11376
10888
  };
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
- ];
10889
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10890
+ function getDefaultValues(metadata) {
10891
+ if (!metadata || !Object.keys(metadata).length) {
10892
+ return [
10893
+ {
10894
+ key: "",
10895
+ value: "",
10896
+ disabled: false
10897
+ }
10898
+ ];
10899
+ }
10900
+ return Object.entries(metadata).map(([key, value]) => {
10901
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10902
+ return {
10903
+ key,
10904
+ value,
10905
+ disabled: true
10906
+ };
10907
+ }
10908
+ let stringValue = value;
10909
+ if (typeof value !== "string") {
10910
+ stringValue = JSON.stringify(value);
10911
+ }
10912
+ return {
10913
+ key,
10914
+ value: stringValue,
10915
+ original_key: key
10916
+ };
10917
+ });
10918
+ }
10919
+ function parseValues(values) {
10920
+ const metadata = values.metadata;
10921
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10922
+ if (isEmpty) {
10923
+ return null;
10924
+ }
10925
+ const update = {};
10926
+ metadata.forEach((field) => {
10927
+ let key = field.key;
10928
+ let value = field.value;
10929
+ const disabled = field.disabled;
10930
+ if (!key || !value) {
10931
+ return;
10932
+ }
10933
+ if (disabled) {
10934
+ update[key] = value;
10935
+ return;
10936
+ }
10937
+ key = key.trim();
10938
+ value = value.trim();
10939
+ if (value === "true") {
10940
+ update[key] = true;
10941
+ } else if (value === "false") {
10942
+ update[key] = false;
10943
+ } else {
10944
+ const parsedNumber = parseFloat(value);
10945
+ if (!isNaN(parsedNumber)) {
10946
+ update[key] = parsedNumber;
10947
+ } else {
10948
+ update[key] = value;
10949
+ }
10950
+ }
10951
+ });
10952
+ return update;
10953
+ }
10954
+ function getHasUneditableRows(metadata) {
10955
+ if (!metadata) {
10956
+ return false;
10957
+ }
10958
+ return Object.values(metadata).some(
10959
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10960
+ );
10961
+ }
10962
+ const PROMOTION_QUERY_KEY = "promotions";
10963
+ const promotionsQueryKeys = {
10964
+ list: (query2) => [
10965
+ PROMOTION_QUERY_KEY,
10966
+ query2 ? query2 : void 0
10967
+ ],
10968
+ detail: (id, query2) => [
10969
+ PROMOTION_QUERY_KEY,
10970
+ id,
10971
+ query2 ? query2 : void 0
10972
+ ]
10973
+ };
10974
+ const usePromotions = (query2, options) => {
10975
+ const { data, ...rest } = useQuery({
10976
+ queryKey: promotionsQueryKeys.list(query2),
10977
+ queryFn: async () => sdk.admin.promotion.list(query2),
10978
+ ...options
10979
+ });
10980
+ return { ...data, ...rest };
10981
+ };
10982
+ const Promotions = () => {
10983
+ const { id } = useParams();
10984
+ const {
10985
+ order: preview,
10986
+ isError: isPreviewError,
10987
+ error: previewError
10988
+ } = useOrderPreview(id, void 0);
10989
+ useInitiateOrderEdit({ preview });
10990
+ const { onCancel } = useCancelOrderEdit({ preview });
10991
+ if (isPreviewError) {
10992
+ throw previewError;
10993
+ }
10994
+ const isReady = !!preview;
10995
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10996
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10997
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10998
+ ] });
10999
+ };
11000
+ const PromotionForm = ({ preview }) => {
11001
+ const { items, shipping_methods } = preview;
11002
+ const [isSubmitting, setIsSubmitting] = useState(false);
11003
+ const [comboboxValue, setComboboxValue] = useState("");
11004
+ const { handleSuccess } = useRouteModal();
11005
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11006
+ const promoIds = getPromotionIds(items, shipping_methods);
11007
+ const { promotions, isPending, isError, error } = usePromotions(
11008
+ {
11009
+ id: promoIds
11010
+ },
11011
+ {
11012
+ enabled: !!promoIds.length
11013
+ }
11014
+ );
11015
+ const comboboxData = useComboboxData({
11016
+ queryKey: ["promotions", "combobox", promoIds],
11017
+ queryFn: async (params) => {
11018
+ return await sdk.admin.promotion.list({
11019
+ ...params,
11020
+ id: {
11021
+ $nin: promoIds
11022
+ }
11023
+ });
11024
+ },
11025
+ getOptions: (data) => {
11026
+ return data.promotions.map((promotion) => ({
11027
+ label: promotion.code,
11028
+ value: promotion.code
11029
+ }));
11030
+ }
11031
+ });
11032
+ const add = async (value) => {
11033
+ if (!value) {
11034
+ return;
11035
+ }
11036
+ addPromotions(
11037
+ {
11038
+ promo_codes: [value]
11039
+ },
11040
+ {
11041
+ onError: (e) => {
11042
+ toast.error(e.message);
11043
+ comboboxData.onSearchValueChange("");
11044
+ setComboboxValue("");
11045
+ },
11046
+ onSuccess: () => {
11047
+ comboboxData.onSearchValueChange("");
11048
+ setComboboxValue("");
11049
+ }
11050
+ }
11051
+ );
11052
+ };
11053
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11054
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11055
+ const onSubmit = async () => {
11056
+ setIsSubmitting(true);
11057
+ let requestSucceeded = false;
11058
+ await requestOrderEdit(void 0, {
11059
+ onError: (e) => {
11060
+ toast.error(e.message);
11061
+ },
11062
+ onSuccess: () => {
11063
+ requestSucceeded = true;
11064
+ }
11065
+ });
11066
+ if (!requestSucceeded) {
11067
+ setIsSubmitting(false);
11068
+ return;
11069
+ }
11070
+ await confirmOrderEdit(void 0, {
11071
+ onError: (e) => {
11072
+ toast.error(e.message);
11073
+ },
11074
+ onSuccess: () => {
11075
+ handleSuccess();
11076
+ },
11077
+ onSettled: () => {
11078
+ setIsSubmitting(false);
11079
+ }
11080
+ });
11081
+ };
11082
+ if (isError) {
11083
+ throw error;
11084
+ }
11085
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11086
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11087
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11088
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11089
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11090
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11091
+ ] }),
11092
+ /* @__PURE__ */ jsx(
11093
+ Combobox,
11094
+ {
11095
+ id: "promotion-combobox",
11096
+ "aria-describedby": "promotion-combobox-hint",
11097
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11098
+ fetchNextPage: comboboxData.fetchNextPage,
11099
+ options: comboboxData.options,
11100
+ onSearchValueChange: comboboxData.onSearchValueChange,
11101
+ searchValue: comboboxData.searchValue,
11102
+ disabled: comboboxData.disabled || isAddingPromotions,
11103
+ onChange: add,
11104
+ value: comboboxValue
11105
+ }
11106
+ )
11107
+ ] }),
11108
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11109
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11110
+ PromotionItem,
11111
+ {
11112
+ promotion,
11113
+ orderId: preview.id,
11114
+ isLoading: isPending
11115
+ },
11116
+ promotion.id
11117
+ )) })
11118
+ ] }) }),
11119
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11120
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11121
+ /* @__PURE__ */ jsx(
11122
+ Button,
11123
+ {
11124
+ size: "small",
11125
+ type: "submit",
11126
+ isLoading: isSubmitting || isAddingPromotions,
11127
+ children: "Save"
11128
+ }
11129
+ )
11130
+ ] }) })
11131
+ ] });
11132
+ };
11133
+ const PromotionItem = ({
11134
+ promotion,
11135
+ orderId,
11136
+ isLoading
11137
+ }) => {
11138
+ var _a;
11139
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11140
+ const onRemove = async () => {
11141
+ removePromotions(
11142
+ {
11143
+ promo_codes: [promotion.code]
11144
+ },
11145
+ {
11146
+ onError: (e) => {
11147
+ toast.error(e.message);
11148
+ }
11149
+ }
11150
+ );
11151
+ };
11152
+ const displayValue = getDisplayValue(promotion);
11153
+ return /* @__PURE__ */ jsxs(
11154
+ "div",
11155
+ {
11156
+ className: clx(
11157
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11158
+ {
11159
+ "animate-pulse": isLoading
11160
+ }
11161
+ ),
11162
+ children: [
11163
+ /* @__PURE__ */ jsxs("div", { children: [
11164
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11165
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11166
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11167
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11168
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11169
+ ] }),
11170
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11171
+ ] })
11172
+ ] }),
11173
+ /* @__PURE__ */ jsx(
11174
+ IconButton,
11175
+ {
11176
+ size: "small",
11177
+ type: "button",
11178
+ variant: "transparent",
11179
+ onClick: onRemove,
11180
+ isLoading: isPending || isLoading,
11181
+ children: /* @__PURE__ */ jsx(XMark, {})
11182
+ }
11183
+ )
11184
+ ]
11185
+ },
11186
+ promotion.id
11187
+ );
11188
+ };
11189
+ function getDisplayValue(promotion) {
11190
+ var _a, _b, _c, _d;
11191
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11192
+ if (!value) {
11193
+ return null;
11387
11194
  }
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);
11195
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11196
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11197
+ if (!currency) {
11198
+ return null;
11399
11199
  }
11400
- return {
11401
- key,
11402
- value: stringValue,
11403
- original_key: key
11404
- };
11405
- });
11200
+ return getLocaleAmount(value, currency);
11201
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11202
+ return formatPercentage(value);
11203
+ }
11204
+ return null;
11406
11205
  }
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;
11206
+ const formatter = new Intl.NumberFormat([], {
11207
+ style: "percent",
11208
+ minimumFractionDigits: 2
11209
+ });
11210
+ const formatPercentage = (value, isPercentageValue = false) => {
11211
+ let val = value || 0;
11212
+ if (!isPercentageValue) {
11213
+ val = val / 100;
11412
11214
  }
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;
11215
+ return formatter.format(val);
11216
+ };
11217
+ function getPromotionIds(items, shippingMethods) {
11218
+ const promotionIds = /* @__PURE__ */ new Set();
11219
+ for (const item of items) {
11220
+ if (item.adjustments) {
11221
+ for (const adjustment of item.adjustments) {
11222
+ if (adjustment.promotion_id) {
11223
+ promotionIds.add(adjustment.promotion_id);
11224
+ }
11225
+ }
11424
11226
  }
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;
11227
+ }
11228
+ for (const shippingMethod of shippingMethods) {
11229
+ if (shippingMethod.adjustments) {
11230
+ for (const adjustment of shippingMethod.adjustments) {
11231
+ if (adjustment.promotion_id) {
11232
+ promotionIds.add(adjustment.promotion_id);
11233
+ }
11437
11234
  }
11438
11235
  }
11439
- });
11440
- return update;
11441
- }
11442
- function getHasUneditableRows(metadata) {
11443
- if (!metadata) {
11444
- return false;
11445
11236
  }
11446
- return Object.values(metadata).some(
11447
- (value) => !EDITABLE_TYPES.includes(typeof value)
11448
- );
11237
+ return Array.from(promotionIds);
11449
11238
  }
11450
11239
  const SalesChannel = () => {
11451
11240
  const { id } = useParams();
@@ -11475,7 +11264,7 @@ const SalesChannelForm = ({ order }) => {
11475
11264
  defaultValues: {
11476
11265
  sales_channel_id: order.sales_channel_id || ""
11477
11266
  },
11478
- resolver: zodResolver(schema$2)
11267
+ resolver: zodResolver(schema$4)
11479
11268
  });
11480
11269
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
11270
  const { handleSuccess } = useRouteModal();
@@ -11550,7 +11339,7 @@ const SalesChannelField = ({ control, order }) => {
11550
11339
  }
11551
11340
  );
11552
11341
  };
11553
- const schema$2 = objectType({
11342
+ const schema$4 = objectType({
11554
11343
  sales_channel_id: stringType().min(1)
11555
11344
  });
11556
11345
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12307,59 +12096,262 @@ const ShippingOptionField = ({
12307
12096
  /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12308
12097
  ] }),
12309
12098
  /* @__PURE__ */ jsx(
12310
- ConditionalTooltip,
12099
+ ConditionalTooltip,
12100
+ {
12101
+ content: tooltipContent,
12102
+ showTooltip: !locationId || !shippingProfileId,
12103
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12104
+ Combobox,
12105
+ {
12106
+ options: shippingOptions.options,
12107
+ fetchNextPage: shippingOptions.fetchNextPage,
12108
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12109
+ searchValue: shippingOptions.searchValue,
12110
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12111
+ placeholder: "Select shipping option",
12112
+ ...field,
12113
+ disabled: !locationId || !shippingProfileId
12114
+ }
12115
+ ) }) })
12116
+ }
12117
+ )
12118
+ ] }) });
12119
+ }
12120
+ }
12121
+ );
12122
+ };
12123
+ const CustomAmountField = ({
12124
+ control,
12125
+ currencyCode
12126
+ }) => {
12127
+ return /* @__PURE__ */ jsx(
12128
+ Form$2.Field,
12129
+ {
12130
+ control,
12131
+ name: "custom_amount",
12132
+ render: ({ field: { onChange, ...field } }) => {
12133
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12134
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12135
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12136
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12137
+ ] }),
12138
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12139
+ CurrencyInput,
12140
+ {
12141
+ ...field,
12142
+ onValueChange: (value) => onChange(value),
12143
+ symbol: getNativeSymbol(currencyCode),
12144
+ code: currencyCode
12145
+ }
12146
+ ) })
12147
+ ] });
12148
+ }
12149
+ }
12150
+ );
12151
+ };
12152
+ const ShippingAddress = () => {
12153
+ const { id } = useParams();
12154
+ const { order, isPending, isError, error } = useOrder(id, {
12155
+ fields: "+shipping_address"
12156
+ });
12157
+ if (isError) {
12158
+ throw error;
12159
+ }
12160
+ const isReady = !isPending && !!order;
12161
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12162
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12163
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12164
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12165
+ ] }),
12166
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12167
+ ] });
12168
+ };
12169
+ const ShippingAddressForm = ({ order }) => {
12170
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12171
+ const form = useForm({
12172
+ defaultValues: {
12173
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12174
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12175
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12176
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12177
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12178
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12179
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12180
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12181
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12182
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12183
+ },
12184
+ resolver: zodResolver(schema$3)
12185
+ });
12186
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12187
+ const { handleSuccess } = useRouteModal();
12188
+ const onSubmit = form.handleSubmit(async (data) => {
12189
+ await mutateAsync(
12190
+ {
12191
+ shipping_address: {
12192
+ first_name: data.first_name,
12193
+ last_name: data.last_name,
12194
+ company: data.company,
12195
+ address_1: data.address_1,
12196
+ address_2: data.address_2,
12197
+ city: data.city,
12198
+ province: data.province,
12199
+ country_code: data.country_code,
12200
+ postal_code: data.postal_code,
12201
+ phone: data.phone
12202
+ }
12203
+ },
12204
+ {
12205
+ onSuccess: () => {
12206
+ handleSuccess();
12207
+ },
12208
+ onError: (error) => {
12209
+ toast.error(error.message);
12210
+ }
12211
+ }
12212
+ );
12213
+ });
12214
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12215
+ KeyboundForm,
12216
+ {
12217
+ className: "flex flex-1 flex-col overflow-hidden",
12218
+ onSubmit,
12219
+ children: [
12220
+ /* @__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: [
12221
+ /* @__PURE__ */ jsx(
12222
+ Form$2.Field,
12223
+ {
12224
+ control: form.control,
12225
+ name: "country_code",
12226
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12227
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12228
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12229
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12230
+ ] })
12231
+ }
12232
+ ),
12233
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12234
+ /* @__PURE__ */ jsx(
12235
+ Form$2.Field,
12236
+ {
12237
+ control: form.control,
12238
+ name: "first_name",
12239
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12240
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12241
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12242
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12243
+ ] })
12244
+ }
12245
+ ),
12246
+ /* @__PURE__ */ jsx(
12247
+ Form$2.Field,
12248
+ {
12249
+ control: form.control,
12250
+ name: "last_name",
12251
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12252
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12253
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12254
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12255
+ ] })
12256
+ }
12257
+ )
12258
+ ] }),
12259
+ /* @__PURE__ */ jsx(
12260
+ Form$2.Field,
12311
12261
  {
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
- ) }) })
12262
+ control: form.control,
12263
+ name: "company",
12264
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12265
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12266
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12267
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12268
+ ] })
12327
12269
  }
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." })
12270
+ ),
12271
+ /* @__PURE__ */ jsx(
12272
+ Form$2.Field,
12273
+ {
12274
+ control: form.control,
12275
+ name: "address_1",
12276
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12277
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12278
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12279
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12280
+ ] })
12281
+ }
12282
+ ),
12283
+ /* @__PURE__ */ jsx(
12284
+ Form$2.Field,
12285
+ {
12286
+ control: form.control,
12287
+ name: "address_2",
12288
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12289
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12290
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12291
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12292
+ ] })
12293
+ }
12294
+ ),
12295
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12296
+ /* @__PURE__ */ jsx(
12297
+ Form$2.Field,
12298
+ {
12299
+ control: form.control,
12300
+ name: "postal_code",
12301
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12302
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12303
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12304
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12305
+ ] })
12306
+ }
12307
+ ),
12308
+ /* @__PURE__ */ jsx(
12309
+ Form$2.Field,
12310
+ {
12311
+ control: form.control,
12312
+ name: "city",
12313
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12314
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12315
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12316
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12317
+ ] })
12318
+ }
12319
+ )
12348
12320
  ] }),
12349
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
- CurrencyInput,
12321
+ /* @__PURE__ */ jsx(
12322
+ Form$2.Field,
12351
12323
  {
12352
- ...field,
12353
- onValueChange: (value) => onChange(value),
12354
- symbol: getNativeSymbol(currencyCode),
12355
- code: currencyCode
12324
+ control: form.control,
12325
+ name: "province",
12326
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12327
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12328
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12329
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12330
+ ] })
12356
12331
  }
12357
- ) })
12358
- ] });
12359
- }
12332
+ ),
12333
+ /* @__PURE__ */ jsx(
12334
+ Form$2.Field,
12335
+ {
12336
+ control: form.control,
12337
+ name: "phone",
12338
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12339
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12340
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12341
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12342
+ ] })
12343
+ }
12344
+ )
12345
+ ] }) }),
12346
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12347
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12348
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12349
+ ] }) })
12350
+ ]
12360
12351
  }
12361
- );
12352
+ ) });
12362
12353
  };
12354
+ const schema$3 = addressSchema;
12363
12355
  const TransferOwnership = () => {
12364
12356
  const { id } = useParams();
12365
12357
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12383,7 +12375,7 @@ const TransferOwnershipForm = ({ order }) => {
12383
12375
  defaultValues: {
12384
12376
  customer_id: order.customer_id || ""
12385
12377
  },
12386
- resolver: zodResolver(schema$1)
12378
+ resolver: zodResolver(schema$2)
12387
12379
  });
12388
12380
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12389
12381
  const { handleSuccess } = useRouteModal();
@@ -12833,13 +12825,13 @@ const Illustration = () => {
12833
12825
  }
12834
12826
  );
12835
12827
  };
12836
- const schema$1 = objectType({
12828
+ const schema$2 = objectType({
12837
12829
  customer_id: stringType().min(1)
12838
12830
  });
12839
- const ShippingAddress = () => {
12831
+ const BillingAddress = () => {
12840
12832
  const { id } = useParams();
12841
12833
  const { order, isPending, isError, error } = useOrder(id, {
12842
- fields: "+shipping_address"
12834
+ fields: "+billing_address"
12843
12835
  });
12844
12836
  if (isError) {
12845
12837
  throw error;
@@ -12847,47 +12839,34 @@ const ShippingAddress = () => {
12847
12839
  const isReady = !isPending && !!order;
12848
12840
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12849
12841
  /* @__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" }) })
12842
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12843
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12852
12844
  ] }),
12853
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12845
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12854
12846
  ] });
12855
12847
  };
12856
- const ShippingAddressForm = ({ order }) => {
12848
+ const BillingAddressForm = ({ order }) => {
12857
12849
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12858
12850
  const form = useForm({
12859
12851
  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) ?? ""
12852
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12853
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12854
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12855
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12856
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12857
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12858
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12859
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12860
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12861
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12870
12862
  },
12871
- resolver: zodResolver(schema)
12863
+ resolver: zodResolver(schema$1)
12872
12864
  });
12873
12865
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12874
12866
  const { handleSuccess } = useRouteModal();
12875
12867
  const onSubmit = form.handleSubmit(async (data) => {
12876
12868
  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
- },
12869
+ { billing_address: data },
12891
12870
  {
12892
12871
  onSuccess: () => {
12893
12872
  handleSuccess();
@@ -13038,7 +13017,28 @@ const ShippingAddressForm = ({ order }) => {
13038
13017
  }
13039
13018
  ) });
13040
13019
  };
13041
- const schema = addressSchema;
13020
+ const schema$1 = addressSchema;
13021
+ const CustomItems = () => {
13022
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
13023
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
13024
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
13025
+ ] });
13026
+ };
13027
+ const CustomItemsForm = () => {
13028
+ const form = useForm({
13029
+ resolver: zodResolver(schema)
13030
+ });
13031
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13032
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
13033
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
13036
+ ] }) })
13037
+ ] }) });
13038
+ };
13039
+ const schema = objectType({
13040
+ email: stringType().email()
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,14 +13059,6 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
- {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13065
- },
13066
- {
13067
- Component: CustomItems,
13068
- path: "/draft-orders/:id/custom-items"
13069
- },
13070
13062
  {
13071
13063
  Component: Email,
13072
13064
  path: "/draft-orders/:id/email"
@@ -13075,14 +13067,14 @@ const routeModule = {
13075
13067
  Component: Items,
13076
13068
  path: "/draft-orders/:id/items"
13077
13069
  },
13078
- {
13079
- Component: Promotions,
13080
- path: "/draft-orders/:id/promotions"
13081
- },
13082
13070
  {
13083
13071
  Component: Metadata,
13084
13072
  path: "/draft-orders/:id/metadata"
13085
13073
  },
13074
+ {
13075
+ Component: Promotions,
13076
+ path: "/draft-orders/:id/promotions"
13077
+ },
13086
13078
  {
13087
13079
  Component: SalesChannel,
13088
13080
  path: "/draft-orders/:id/sales-channel"
@@ -13091,13 +13083,21 @@ const routeModule = {
13091
13083
  Component: Shipping,
13092
13084
  path: "/draft-orders/:id/shipping"
13093
13085
  },
13086
+ {
13087
+ Component: ShippingAddress,
13088
+ path: "/draft-orders/:id/shipping-address"
13089
+ },
13094
13090
  {
13095
13091
  Component: TransferOwnership,
13096
13092
  path: "/draft-orders/:id/transfer-ownership"
13097
13093
  },
13098
13094
  {
13099
- Component: ShippingAddress,
13100
- path: "/draft-orders/:id/shipping-address"
13095
+ Component: BillingAddress,
13096
+ path: "/draft-orders/:id/billing-address"
13097
+ },
13098
+ {
13099
+ Component: CustomItems,
13100
+ path: "/draft-orders/:id/custom-items"
13101
13101
  }
13102
13102
  ]
13103
13103
  }