@medusajs/draft-order 2.10.4-preview-20250925120212 → 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.
@@ -9573,196 +9573,6 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
- const BillingAddress = () => {
9577
- const { id } = reactRouterDom.useParams();
9578
- const { order, isPending, isError, error } = useOrder(id, {
9579
- fields: "+billing_address"
9580
- });
9581
- if (isError) {
9582
- throw error;
9583
- }
9584
- const isReady = !isPending && !!order;
9585
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9588
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9589
- ] }),
9590
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9591
- ] });
9592
- };
9593
- const BillingAddressForm = ({ order }) => {
9594
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9595
- const form = reactHookForm.useForm({
9596
- defaultValues: {
9597
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9598
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9599
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9600
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9601
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9602
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9603
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9604
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9605
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9607
- },
9608
- resolver: zod.zodResolver(schema$5)
9609
- });
9610
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
- const { handleSuccess } = useRouteModal();
9612
- const onSubmit = form.handleSubmit(async (data) => {
9613
- await mutateAsync(
9614
- { billing_address: data },
9615
- {
9616
- onSuccess: () => {
9617
- handleSuccess();
9618
- },
9619
- onError: (error) => {
9620
- ui.toast.error(error.message);
9621
- }
9622
- }
9623
- );
9624
- });
9625
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9626
- KeyboundForm,
9627
- {
9628
- className: "flex flex-1 flex-col overflow-hidden",
9629
- onSubmit,
9630
- children: [
9631
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9632
- /* @__PURE__ */ jsxRuntime.jsx(
9633
- Form$2.Field,
9634
- {
9635
- control: form.control,
9636
- name: "country_code",
9637
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9640
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9641
- ] })
9642
- }
9643
- ),
9644
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9645
- /* @__PURE__ */ jsxRuntime.jsx(
9646
- Form$2.Field,
9647
- {
9648
- control: form.control,
9649
- name: "first_name",
9650
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9652
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9653
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9654
- ] })
9655
- }
9656
- ),
9657
- /* @__PURE__ */ jsxRuntime.jsx(
9658
- Form$2.Field,
9659
- {
9660
- control: form.control,
9661
- name: "last_name",
9662
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9665
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9666
- ] })
9667
- }
9668
- )
9669
- ] }),
9670
- /* @__PURE__ */ jsxRuntime.jsx(
9671
- Form$2.Field,
9672
- {
9673
- control: form.control,
9674
- name: "company",
9675
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9678
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9679
- ] })
9680
- }
9681
- ),
9682
- /* @__PURE__ */ jsxRuntime.jsx(
9683
- Form$2.Field,
9684
- {
9685
- control: form.control,
9686
- name: "address_1",
9687
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9689
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9690
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9691
- ] })
9692
- }
9693
- ),
9694
- /* @__PURE__ */ jsxRuntime.jsx(
9695
- Form$2.Field,
9696
- {
9697
- control: form.control,
9698
- name: "address_2",
9699
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9702
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9703
- ] })
9704
- }
9705
- ),
9706
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9707
- /* @__PURE__ */ jsxRuntime.jsx(
9708
- Form$2.Field,
9709
- {
9710
- control: form.control,
9711
- name: "postal_code",
9712
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9715
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9716
- ] })
9717
- }
9718
- ),
9719
- /* @__PURE__ */ jsxRuntime.jsx(
9720
- Form$2.Field,
9721
- {
9722
- control: form.control,
9723
- name: "city",
9724
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9727
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
- ] })
9729
- }
9730
- )
9731
- ] }),
9732
- /* @__PURE__ */ jsxRuntime.jsx(
9733
- Form$2.Field,
9734
- {
9735
- control: form.control,
9736
- name: "province",
9737
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
- ] })
9742
- }
9743
- ),
9744
- /* @__PURE__ */ jsxRuntime.jsx(
9745
- Form$2.Field,
9746
- {
9747
- control: form.control,
9748
- name: "phone",
9749
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
- ] })
9754
- }
9755
- )
9756
- ] }) }),
9757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9760
- ] }) })
9761
- ]
9762
- }
9763
- ) });
9764
- };
9765
- const schema$5 = addressSchema;
9766
9576
  const Email = () => {
9767
9577
  const { id } = reactRouterDom.useParams();
9768
9578
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9785,7 +9595,7 @@ const EmailForm = ({ order }) => {
9785
9595
  defaultValues: {
9786
9596
  email: order.email ?? ""
9787
9597
  },
9788
- resolver: zod.zodResolver(schema$4)
9598
+ resolver: zod.zodResolver(schema$5)
9789
9599
  });
9790
9600
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9791
9601
  const { handleSuccess } = useRouteModal();
@@ -9828,7 +9638,7 @@ const EmailForm = ({ order }) => {
9828
9638
  }
9829
9639
  ) });
9830
9640
  };
9831
- const schema$4 = objectType({
9641
+ const schema$5 = objectType({
9832
9642
  email: stringType().email()
9833
9643
  });
9834
9644
  const NumberInput = React.forwardRef(
@@ -11155,33 +10965,289 @@ function getHasUneditableRows(metadata) {
11155
10965
  (value) => !EDITABLE_TYPES.includes(typeof value)
11156
10966
  );
11157
10967
  }
11158
- const CustomItems = () => {
11159
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11160
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
11161
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
11162
- ] });
10968
+ const PROMOTION_QUERY_KEY = "promotions";
10969
+ const promotionsQueryKeys = {
10970
+ list: (query2) => [
10971
+ PROMOTION_QUERY_KEY,
10972
+ query2 ? query2 : void 0
10973
+ ],
10974
+ detail: (id, query2) => [
10975
+ PROMOTION_QUERY_KEY,
10976
+ id,
10977
+ query2 ? query2 : void 0
10978
+ ]
11163
10979
  };
11164
- const CustomItemsForm = () => {
11165
- const form = reactHookForm.useForm({
11166
- resolver: zod.zodResolver(schema$3)
10980
+ const usePromotions = (query2, options) => {
10981
+ const { data, ...rest } = reactQuery.useQuery({
10982
+ queryKey: promotionsQueryKeys.list(query2),
10983
+ queryFn: async () => sdk.admin.promotion.list(query2),
10984
+ ...options
11167
10985
  });
11168
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11169
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
11170
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11171
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11172
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
11173
- ] }) })
11174
- ] }) });
10986
+ return { ...data, ...rest };
11175
10987
  };
11176
- const schema$3 = objectType({
11177
- email: stringType().email()
11178
- });
11179
- const SalesChannel = () => {
10988
+ const Promotions = () => {
11180
10989
  const { id } = reactRouterDom.useParams();
11181
- const { draft_order, isPending, isError, error } = useDraftOrder(
11182
- id,
10990
+ const {
10991
+ order: preview,
10992
+ isError: isPreviewError,
10993
+ error: previewError
10994
+ } = useOrderPreview(id, void 0);
10995
+ useInitiateOrderEdit({ preview });
10996
+ const { onCancel } = useCancelOrderEdit({ preview });
10997
+ if (isPreviewError) {
10998
+ throw previewError;
10999
+ }
11000
+ const isReady = !!preview;
11001
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11002
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11003
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11004
+ ] });
11005
+ };
11006
+ const PromotionForm = ({ preview }) => {
11007
+ const { items, shipping_methods } = preview;
11008
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11009
+ const [comboboxValue, setComboboxValue] = React.useState("");
11010
+ const { handleSuccess } = useRouteModal();
11011
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11012
+ const promoIds = getPromotionIds(items, shipping_methods);
11013
+ const { promotions, isPending, isError, error } = usePromotions(
11183
11014
  {
11184
- fields: "+sales_channel_id"
11015
+ id: promoIds
11016
+ },
11017
+ {
11018
+ enabled: !!promoIds.length
11019
+ }
11020
+ );
11021
+ const comboboxData = useComboboxData({
11022
+ queryKey: ["promotions", "combobox", promoIds],
11023
+ queryFn: async (params) => {
11024
+ return await sdk.admin.promotion.list({
11025
+ ...params,
11026
+ id: {
11027
+ $nin: promoIds
11028
+ }
11029
+ });
11030
+ },
11031
+ getOptions: (data) => {
11032
+ return data.promotions.map((promotion) => ({
11033
+ label: promotion.code,
11034
+ value: promotion.code
11035
+ }));
11036
+ }
11037
+ });
11038
+ const add = async (value) => {
11039
+ if (!value) {
11040
+ return;
11041
+ }
11042
+ addPromotions(
11043
+ {
11044
+ promo_codes: [value]
11045
+ },
11046
+ {
11047
+ onError: (e) => {
11048
+ ui.toast.error(e.message);
11049
+ comboboxData.onSearchValueChange("");
11050
+ setComboboxValue("");
11051
+ },
11052
+ onSuccess: () => {
11053
+ comboboxData.onSearchValueChange("");
11054
+ setComboboxValue("");
11055
+ }
11056
+ }
11057
+ );
11058
+ };
11059
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11060
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11061
+ const onSubmit = async () => {
11062
+ setIsSubmitting(true);
11063
+ let requestSucceeded = false;
11064
+ await requestOrderEdit(void 0, {
11065
+ onError: (e) => {
11066
+ ui.toast.error(e.message);
11067
+ },
11068
+ onSuccess: () => {
11069
+ requestSucceeded = true;
11070
+ }
11071
+ });
11072
+ if (!requestSucceeded) {
11073
+ setIsSubmitting(false);
11074
+ return;
11075
+ }
11076
+ await confirmOrderEdit(void 0, {
11077
+ onError: (e) => {
11078
+ ui.toast.error(e.message);
11079
+ },
11080
+ onSuccess: () => {
11081
+ handleSuccess();
11082
+ },
11083
+ onSettled: () => {
11084
+ setIsSubmitting(false);
11085
+ }
11086
+ });
11087
+ };
11088
+ if (isError) {
11089
+ throw error;
11090
+ }
11091
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11092
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11093
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11094
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11095
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11096
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11097
+ ] }),
11098
+ /* @__PURE__ */ jsxRuntime.jsx(
11099
+ Combobox,
11100
+ {
11101
+ id: "promotion-combobox",
11102
+ "aria-describedby": "promotion-combobox-hint",
11103
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11104
+ fetchNextPage: comboboxData.fetchNextPage,
11105
+ options: comboboxData.options,
11106
+ onSearchValueChange: comboboxData.onSearchValueChange,
11107
+ searchValue: comboboxData.searchValue,
11108
+ disabled: comboboxData.disabled || isAddingPromotions,
11109
+ onChange: add,
11110
+ value: comboboxValue
11111
+ }
11112
+ )
11113
+ ] }),
11114
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11115
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11116
+ PromotionItem,
11117
+ {
11118
+ promotion,
11119
+ orderId: preview.id,
11120
+ isLoading: isPending
11121
+ },
11122
+ promotion.id
11123
+ )) })
11124
+ ] }) }),
11125
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11126
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11127
+ /* @__PURE__ */ jsxRuntime.jsx(
11128
+ ui.Button,
11129
+ {
11130
+ size: "small",
11131
+ type: "submit",
11132
+ isLoading: isSubmitting || isAddingPromotions,
11133
+ children: "Save"
11134
+ }
11135
+ )
11136
+ ] }) })
11137
+ ] });
11138
+ };
11139
+ const PromotionItem = ({
11140
+ promotion,
11141
+ orderId,
11142
+ isLoading
11143
+ }) => {
11144
+ var _a;
11145
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11146
+ const onRemove = async () => {
11147
+ removePromotions(
11148
+ {
11149
+ promo_codes: [promotion.code]
11150
+ },
11151
+ {
11152
+ onError: (e) => {
11153
+ ui.toast.error(e.message);
11154
+ }
11155
+ }
11156
+ );
11157
+ };
11158
+ const displayValue = getDisplayValue(promotion);
11159
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11160
+ "div",
11161
+ {
11162
+ className: ui.clx(
11163
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11164
+ {
11165
+ "animate-pulse": isLoading
11166
+ }
11167
+ ),
11168
+ children: [
11169
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11170
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11171
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11172
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11173
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11174
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11175
+ ] }),
11176
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11177
+ ] })
11178
+ ] }),
11179
+ /* @__PURE__ */ jsxRuntime.jsx(
11180
+ ui.IconButton,
11181
+ {
11182
+ size: "small",
11183
+ type: "button",
11184
+ variant: "transparent",
11185
+ onClick: onRemove,
11186
+ isLoading: isPending || isLoading,
11187
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11188
+ }
11189
+ )
11190
+ ]
11191
+ },
11192
+ promotion.id
11193
+ );
11194
+ };
11195
+ function getDisplayValue(promotion) {
11196
+ var _a, _b, _c, _d;
11197
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11198
+ if (!value) {
11199
+ return null;
11200
+ }
11201
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11202
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11203
+ if (!currency) {
11204
+ return null;
11205
+ }
11206
+ return getLocaleAmount(value, currency);
11207
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11208
+ return formatPercentage(value);
11209
+ }
11210
+ return null;
11211
+ }
11212
+ const formatter = new Intl.NumberFormat([], {
11213
+ style: "percent",
11214
+ minimumFractionDigits: 2
11215
+ });
11216
+ const formatPercentage = (value, isPercentageValue = false) => {
11217
+ let val = value || 0;
11218
+ if (!isPercentageValue) {
11219
+ val = val / 100;
11220
+ }
11221
+ return formatter.format(val);
11222
+ };
11223
+ function getPromotionIds(items, shippingMethods) {
11224
+ const promotionIds = /* @__PURE__ */ new Set();
11225
+ for (const item of items) {
11226
+ if (item.adjustments) {
11227
+ for (const adjustment of item.adjustments) {
11228
+ if (adjustment.promotion_id) {
11229
+ promotionIds.add(adjustment.promotion_id);
11230
+ }
11231
+ }
11232
+ }
11233
+ }
11234
+ for (const shippingMethod of shippingMethods) {
11235
+ if (shippingMethod.adjustments) {
11236
+ for (const adjustment of shippingMethod.adjustments) {
11237
+ if (adjustment.promotion_id) {
11238
+ promotionIds.add(adjustment.promotion_id);
11239
+ }
11240
+ }
11241
+ }
11242
+ }
11243
+ return Array.from(promotionIds);
11244
+ }
11245
+ const SalesChannel = () => {
11246
+ const { id } = reactRouterDom.useParams();
11247
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11248
+ id,
11249
+ {
11250
+ fields: "+sales_channel_id"
11185
11251
  },
11186
11252
  {
11187
11253
  enabled: !!id
@@ -11204,7 +11270,7 @@ const SalesChannelForm = ({ order }) => {
11204
11270
  defaultValues: {
11205
11271
  sales_channel_id: order.sales_channel_id || ""
11206
11272
  },
11207
- resolver: zod.zodResolver(schema$2)
11273
+ resolver: zod.zodResolver(schema$4)
11208
11274
  });
11209
11275
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11210
11276
  const { handleSuccess } = useRouteModal();
@@ -11279,7 +11345,7 @@ const SalesChannelField = ({ control, order }) => {
11279
11345
  }
11280
11346
  );
11281
11347
  };
11282
- const schema$2 = objectType({
11348
+ const schema$4 = objectType({
11283
11349
  sales_channel_id: stringType().min(1)
11284
11350
  });
11285
11351
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12121,7 +12187,7 @@ const ShippingAddressForm = ({ order }) => {
12121
12187
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12122
12188
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12123
12189
  },
12124
- resolver: zod.zodResolver(schema$1)
12190
+ resolver: zod.zodResolver(schema$3)
12125
12191
  });
12126
12192
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12127
12193
  const { handleSuccess } = useRouteModal();
@@ -12291,7 +12357,7 @@ const ShippingAddressForm = ({ order }) => {
12291
12357
  }
12292
12358
  ) });
12293
12359
  };
12294
- const schema$1 = addressSchema;
12360
+ const schema$3 = addressSchema;
12295
12361
  const TransferOwnership = () => {
12296
12362
  const { id } = reactRouterDom.useParams();
12297
12363
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12315,7 +12381,7 @@ const TransferOwnershipForm = ({ order }) => {
12315
12381
  defaultValues: {
12316
12382
  customer_id: order.customer_id || ""
12317
12383
  },
12318
- resolver: zod.zodResolver(schema)
12384
+ resolver: zod.zodResolver(schema$2)
12319
12385
  });
12320
12386
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12321
12387
  const { handleSuccess } = useRouteModal();
@@ -12765,286 +12831,220 @@ const Illustration = () => {
12765
12831
  }
12766
12832
  );
12767
12833
  };
12768
- const schema = objectType({
12834
+ const schema$2 = objectType({
12769
12835
  customer_id: stringType().min(1)
12770
12836
  });
12771
- const PROMOTION_QUERY_KEY = "promotions";
12772
- const promotionsQueryKeys = {
12773
- list: (query2) => [
12774
- PROMOTION_QUERY_KEY,
12775
- query2 ? query2 : void 0
12776
- ],
12777
- detail: (id, query2) => [
12778
- PROMOTION_QUERY_KEY,
12779
- id,
12780
- query2 ? query2 : void 0
12781
- ]
12782
- };
12783
- const usePromotions = (query2, options) => {
12784
- const { data, ...rest } = reactQuery.useQuery({
12785
- queryKey: promotionsQueryKeys.list(query2),
12786
- queryFn: async () => sdk.admin.promotion.list(query2),
12787
- ...options
12788
- });
12789
- return { ...data, ...rest };
12790
- };
12791
- const Promotions = () => {
12837
+ const BillingAddress = () => {
12792
12838
  const { id } = reactRouterDom.useParams();
12793
- const {
12794
- order: preview,
12795
- isError: isPreviewError,
12796
- error: previewError
12797
- } = useOrderPreview(id, void 0);
12798
- useInitiateOrderEdit({ preview });
12799
- const { onCancel } = useCancelOrderEdit({ preview });
12800
- if (isPreviewError) {
12801
- throw previewError;
12839
+ const { order, isPending, isError, error } = useOrder(id, {
12840
+ fields: "+billing_address"
12841
+ });
12842
+ if (isError) {
12843
+ throw error;
12802
12844
  }
12803
- const isReady = !!preview;
12804
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12805
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12806
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12845
+ const isReady = !isPending && !!order;
12846
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12847
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12848
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12849
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12850
+ ] }),
12851
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12807
12852
  ] });
12808
12853
  };
12809
- const PromotionForm = ({ preview }) => {
12810
- const { items, shipping_methods } = preview;
12811
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12812
- const [comboboxValue, setComboboxValue] = React.useState("");
12813
- const { handleSuccess } = useRouteModal();
12814
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12815
- const promoIds = getPromotionIds(items, shipping_methods);
12816
- const { promotions, isPending, isError, error } = usePromotions(
12817
- {
12818
- id: promoIds
12819
- },
12820
- {
12821
- enabled: !!promoIds.length
12822
- }
12823
- );
12824
- const comboboxData = useComboboxData({
12825
- queryKey: ["promotions", "combobox", promoIds],
12826
- queryFn: async (params) => {
12827
- return await sdk.admin.promotion.list({
12828
- ...params,
12829
- id: {
12830
- $nin: promoIds
12831
- }
12832
- });
12854
+ const BillingAddressForm = ({ order }) => {
12855
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12856
+ const form = reactHookForm.useForm({
12857
+ defaultValues: {
12858
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12859
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12860
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12861
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12862
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12863
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12864
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12865
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12866
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12867
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12833
12868
  },
12834
- getOptions: (data) => {
12835
- return data.promotions.map((promotion) => ({
12836
- label: promotion.code,
12837
- value: promotion.code
12838
- }));
12839
- }
12869
+ resolver: zod.zodResolver(schema$1)
12840
12870
  });
12841
- const add = async (value) => {
12842
- if (!value) {
12843
- return;
12844
- }
12845
- addPromotions(
12846
- {
12847
- promo_codes: [value]
12848
- },
12871
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12872
+ const { handleSuccess } = useRouteModal();
12873
+ const onSubmit = form.handleSubmit(async (data) => {
12874
+ await mutateAsync(
12875
+ { billing_address: data },
12849
12876
  {
12850
- onError: (e) => {
12851
- ui.toast.error(e.message);
12852
- comboboxData.onSearchValueChange("");
12853
- setComboboxValue("");
12854
- },
12855
12877
  onSuccess: () => {
12856
- comboboxData.onSearchValueChange("");
12857
- setComboboxValue("");
12858
- }
12859
- }
12860
- );
12861
- };
12862
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12863
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12864
- const onSubmit = async () => {
12865
- setIsSubmitting(true);
12866
- let requestSucceeded = false;
12867
- await requestOrderEdit(void 0, {
12868
- onError: (e) => {
12869
- ui.toast.error(e.message);
12870
- },
12871
- onSuccess: () => {
12872
- requestSucceeded = true;
12873
- }
12874
- });
12875
- if (!requestSucceeded) {
12876
- setIsSubmitting(false);
12877
- return;
12878
- }
12879
- await confirmOrderEdit(void 0, {
12880
- onError: (e) => {
12881
- ui.toast.error(e.message);
12882
- },
12883
- onSuccess: () => {
12884
- handleSuccess();
12885
- },
12886
- onSettled: () => {
12887
- setIsSubmitting(false);
12888
- }
12889
- });
12890
- };
12891
- if (isError) {
12892
- throw error;
12893
- }
12894
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12895
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12896
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12897
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12898
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12899
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12900
- ] }),
12901
- /* @__PURE__ */ jsxRuntime.jsx(
12902
- Combobox,
12903
- {
12904
- id: "promotion-combobox",
12905
- "aria-describedby": "promotion-combobox-hint",
12906
- isFetchingNextPage: comboboxData.isFetchingNextPage,
12907
- fetchNextPage: comboboxData.fetchNextPage,
12908
- options: comboboxData.options,
12909
- onSearchValueChange: comboboxData.onSearchValueChange,
12910
- searchValue: comboboxData.searchValue,
12911
- disabled: comboboxData.disabled || isAddingPromotions,
12912
- onChange: add,
12913
- value: comboboxValue
12914
- }
12915
- )
12916
- ] }),
12917
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12918
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12919
- PromotionItem,
12920
- {
12921
- promotion,
12922
- orderId: preview.id,
12923
- isLoading: isPending
12878
+ handleSuccess();
12924
12879
  },
12925
- promotion.id
12926
- )) })
12927
- ] }) }),
12928
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12929
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12930
- /* @__PURE__ */ jsxRuntime.jsx(
12931
- ui.Button,
12932
- {
12933
- size: "small",
12934
- type: "submit",
12935
- isLoading: isSubmitting || isAddingPromotions,
12936
- children: "Save"
12937
- }
12938
- )
12939
- ] }) })
12940
- ] });
12941
- };
12942
- const PromotionItem = ({
12943
- promotion,
12944
- orderId,
12945
- isLoading
12946
- }) => {
12947
- var _a;
12948
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12949
- const onRemove = async () => {
12950
- removePromotions(
12951
- {
12952
- promo_codes: [promotion.code]
12953
- },
12954
- {
12955
- onError: (e) => {
12956
- ui.toast.error(e.message);
12880
+ onError: (error) => {
12881
+ ui.toast.error(error.message);
12957
12882
  }
12958
12883
  }
12959
12884
  );
12960
- };
12961
- const displayValue = getDisplayValue(promotion);
12962
- return /* @__PURE__ */ jsxRuntime.jsxs(
12963
- "div",
12885
+ });
12886
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12887
+ KeyboundForm,
12964
12888
  {
12965
- className: ui.clx(
12966
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12967
- {
12968
- "animate-pulse": isLoading
12969
- }
12970
- ),
12889
+ className: "flex flex-1 flex-col overflow-hidden",
12890
+ onSubmit,
12971
12891
  children: [
12972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12973
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12974
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12975
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12976
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12978
- ] }),
12979
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12980
- ] })
12981
- ] }),
12982
- /* @__PURE__ */ jsxRuntime.jsx(
12983
- ui.IconButton,
12984
- {
12985
- size: "small",
12986
- type: "button",
12987
- variant: "transparent",
12988
- onClick: onRemove,
12989
- isLoading: isPending || isLoading,
12990
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12991
- }
12992
- )
12892
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12893
+ /* @__PURE__ */ jsxRuntime.jsx(
12894
+ Form$2.Field,
12895
+ {
12896
+ control: form.control,
12897
+ name: "country_code",
12898
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12899
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12900
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12901
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12902
+ ] })
12903
+ }
12904
+ ),
12905
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12906
+ /* @__PURE__ */ jsxRuntime.jsx(
12907
+ Form$2.Field,
12908
+ {
12909
+ control: form.control,
12910
+ name: "first_name",
12911
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12912
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12913
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12914
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12915
+ ] })
12916
+ }
12917
+ ),
12918
+ /* @__PURE__ */ jsxRuntime.jsx(
12919
+ Form$2.Field,
12920
+ {
12921
+ control: form.control,
12922
+ name: "last_name",
12923
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12924
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12925
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12926
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12927
+ ] })
12928
+ }
12929
+ )
12930
+ ] }),
12931
+ /* @__PURE__ */ jsxRuntime.jsx(
12932
+ Form$2.Field,
12933
+ {
12934
+ control: form.control,
12935
+ name: "company",
12936
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12937
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12938
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12939
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12940
+ ] })
12941
+ }
12942
+ ),
12943
+ /* @__PURE__ */ jsxRuntime.jsx(
12944
+ Form$2.Field,
12945
+ {
12946
+ control: form.control,
12947
+ name: "address_1",
12948
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12949
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12950
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12952
+ ] })
12953
+ }
12954
+ ),
12955
+ /* @__PURE__ */ jsxRuntime.jsx(
12956
+ Form$2.Field,
12957
+ {
12958
+ control: form.control,
12959
+ name: "address_2",
12960
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12961
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12962
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12964
+ ] })
12965
+ }
12966
+ ),
12967
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12968
+ /* @__PURE__ */ jsxRuntime.jsx(
12969
+ Form$2.Field,
12970
+ {
12971
+ control: form.control,
12972
+ name: "postal_code",
12973
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12974
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12975
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12976
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12977
+ ] })
12978
+ }
12979
+ ),
12980
+ /* @__PURE__ */ jsxRuntime.jsx(
12981
+ Form$2.Field,
12982
+ {
12983
+ control: form.control,
12984
+ name: "city",
12985
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12986
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12987
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12988
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12989
+ ] })
12990
+ }
12991
+ )
12992
+ ] }),
12993
+ /* @__PURE__ */ jsxRuntime.jsx(
12994
+ Form$2.Field,
12995
+ {
12996
+ control: form.control,
12997
+ name: "province",
12998
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12999
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13000
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13002
+ ] })
13003
+ }
13004
+ ),
13005
+ /* @__PURE__ */ jsxRuntime.jsx(
13006
+ Form$2.Field,
13007
+ {
13008
+ control: form.control,
13009
+ name: "phone",
13010
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13011
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13012
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13014
+ ] })
13015
+ }
13016
+ )
13017
+ ] }) }),
13018
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13019
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13021
+ ] }) })
12993
13022
  ]
12994
- },
12995
- promotion.id
12996
- );
12997
- };
12998
- function getDisplayValue(promotion) {
12999
- var _a, _b, _c, _d;
13000
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
13001
- if (!value) {
13002
- return null;
13003
- }
13004
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
13005
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13006
- if (!currency) {
13007
- return null;
13008
13023
  }
13009
- return getLocaleAmount(value, currency);
13010
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13011
- return formatPercentage(value);
13012
- }
13013
- return null;
13014
- }
13015
- const formatter = new Intl.NumberFormat([], {
13016
- style: "percent",
13017
- minimumFractionDigits: 2
13018
- });
13019
- const formatPercentage = (value, isPercentageValue = false) => {
13020
- let val = value || 0;
13021
- if (!isPercentageValue) {
13022
- val = val / 100;
13023
- }
13024
- return formatter.format(val);
13024
+ ) });
13025
13025
  };
13026
- function getPromotionIds(items, shippingMethods) {
13027
- const promotionIds = /* @__PURE__ */ new Set();
13028
- for (const item of items) {
13029
- if (item.adjustments) {
13030
- for (const adjustment of item.adjustments) {
13031
- if (adjustment.promotion_id) {
13032
- promotionIds.add(adjustment.promotion_id);
13033
- }
13034
- }
13035
- }
13036
- }
13037
- for (const shippingMethod of shippingMethods) {
13038
- if (shippingMethod.adjustments) {
13039
- for (const adjustment of shippingMethod.adjustments) {
13040
- if (adjustment.promotion_id) {
13041
- promotionIds.add(adjustment.promotion_id);
13042
- }
13043
- }
13044
- }
13045
- }
13046
- return Array.from(promotionIds);
13047
- }
13026
+ const schema$1 = addressSchema;
13027
+ const CustomItems = () => {
13028
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
13029
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
13030
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
13031
+ ] });
13032
+ };
13033
+ const CustomItemsForm = () => {
13034
+ const form = reactHookForm.useForm({
13035
+ resolver: zod.zodResolver(schema)
13036
+ });
13037
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
13042
+ ] }) })
13043
+ ] }) });
13044
+ };
13045
+ const schema = objectType({
13046
+ email: stringType().email()
13047
+ });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13065,10 +13065,6 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
- {
13069
- Component: BillingAddress,
13070
- path: "/draft-orders/:id/billing-address"
13071
- },
13072
13068
  {
13073
13069
  Component: Email,
13074
13070
  path: "/draft-orders/:id/email"
@@ -13082,8 +13078,8 @@ const routeModule = {
13082
13078
  path: "/draft-orders/:id/metadata"
13083
13079
  },
13084
13080
  {
13085
- Component: CustomItems,
13086
- path: "/draft-orders/:id/custom-items"
13081
+ Component: Promotions,
13082
+ path: "/draft-orders/:id/promotions"
13087
13083
  },
13088
13084
  {
13089
13085
  Component: SalesChannel,
@@ -13102,8 +13098,12 @@ const routeModule = {
13102
13098
  path: "/draft-orders/:id/transfer-ownership"
13103
13099
  },
13104
13100
  {
13105
- Component: Promotions,
13106
- path: "/draft-orders/:id/promotions"
13101
+ Component: BillingAddress,
13102
+ path: "/draft-orders/:id/billing-address"
13103
+ },
13104
+ {
13105
+ Component: CustomItems,
13106
+ path: "/draft-orders/:id/custom-items"
13107
13107
  }
13108
13108
  ]
13109
13109
  }