@medusajs/draft-order 2.11.2-preview-20251027120200 → 2.11.2-preview-20251027180157

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