@medusajs/draft-order 2.10.2-snapshot-20250906175938 → 2.10.2-snapshot-20250907131935

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.
@@ -9757,95 +9757,6 @@ const BillingAddressForm = ({ order }) => {
9757
9757
  ) });
9758
9758
  };
9759
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
- const Email = () => {
9782
- const { id } = useParams();
9783
- const { order, isPending, isError, error } = useOrder(id, {
9784
- fields: "+email"
9785
- });
9786
- if (isError) {
9787
- throw error;
9788
- }
9789
- const isReady = !isPending && !!order;
9790
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9791
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9792
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9793
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9794
- ] }),
9795
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9796
- ] });
9797
- };
9798
- const EmailForm = ({ order }) => {
9799
- const form = useForm({
9800
- defaultValues: {
9801
- email: order.email ?? ""
9802
- },
9803
- resolver: zodResolver(schema$3)
9804
- });
9805
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
- const { handleSuccess } = useRouteModal();
9807
- const onSubmit = form.handleSubmit(async (data) => {
9808
- await mutateAsync(
9809
- { email: data.email },
9810
- {
9811
- onSuccess: () => {
9812
- handleSuccess();
9813
- },
9814
- onError: (error) => {
9815
- toast.error(error.message);
9816
- }
9817
- }
9818
- );
9819
- });
9820
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9821
- KeyboundForm,
9822
- {
9823
- className: "flex flex-1 flex-col overflow-hidden",
9824
- onSubmit,
9825
- children: [
9826
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9827
- Form$2.Field,
9828
- {
9829
- control: form.control,
9830
- name: "email",
9831
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9832
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9833
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9834
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9835
- ] })
9836
- }
9837
- ) }),
9838
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9839
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9840
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9841
- ] }) })
9842
- ]
9843
- }
9844
- ) });
9845
- };
9846
- const schema$3 = objectType({
9847
- email: stringType().email()
9848
- });
9849
9760
  const NumberInput = forwardRef(
9850
9761
  ({
9851
9762
  value,
@@ -10820,6 +10731,95 @@ const customItemSchema = objectType({
10820
10731
  quantity: numberType(),
10821
10732
  unit_price: unionType([numberType(), stringType()])
10822
10733
  });
10734
+ const Email = () => {
10735
+ const { id } = useParams();
10736
+ const { order, isPending, isError, error } = useOrder(id, {
10737
+ fields: "+email"
10738
+ });
10739
+ if (isError) {
10740
+ throw error;
10741
+ }
10742
+ const isReady = !isPending && !!order;
10743
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10744
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10745
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
10746
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10747
+ ] }),
10748
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10749
+ ] });
10750
+ };
10751
+ const EmailForm = ({ order }) => {
10752
+ const form = useForm({
10753
+ defaultValues: {
10754
+ email: order.email ?? ""
10755
+ },
10756
+ resolver: zodResolver(schema$4)
10757
+ });
10758
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10759
+ const { handleSuccess } = useRouteModal();
10760
+ const onSubmit = form.handleSubmit(async (data) => {
10761
+ await mutateAsync(
10762
+ { email: data.email },
10763
+ {
10764
+ onSuccess: () => {
10765
+ handleSuccess();
10766
+ },
10767
+ onError: (error) => {
10768
+ toast.error(error.message);
10769
+ }
10770
+ }
10771
+ );
10772
+ });
10773
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10774
+ KeyboundForm,
10775
+ {
10776
+ className: "flex flex-1 flex-col overflow-hidden",
10777
+ onSubmit,
10778
+ children: [
10779
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
10780
+ Form$2.Field,
10781
+ {
10782
+ control: form.control,
10783
+ name: "email",
10784
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10785
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
10786
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10787
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10788
+ ] })
10789
+ }
10790
+ ) }),
10791
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10792
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10793
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10794
+ ] }) })
10795
+ ]
10796
+ }
10797
+ ) });
10798
+ };
10799
+ const schema$4 = objectType({
10800
+ email: stringType().email()
10801
+ });
10802
+ const CustomItems = () => {
10803
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10804
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
10805
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
10806
+ ] });
10807
+ };
10808
+ const CustomItemsForm = () => {
10809
+ const form = useForm({
10810
+ resolver: zodResolver(schema$3)
10811
+ });
10812
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10813
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
10814
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10815
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10816
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
10817
+ ] }) })
10818
+ ] }) });
10819
+ };
10820
+ const schema$3 = objectType({
10821
+ email: stringType().email()
10822
+ });
10823
10823
  const InlineTip = forwardRef(
10824
10824
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10825
10825
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11170,105 +11170,77 @@ function getHasUneditableRows(metadata) {
11170
11170
  (value) => !EDITABLE_TYPES.includes(typeof value)
11171
11171
  );
11172
11172
  }
11173
- const PROMOTION_QUERY_KEY = "promotions";
11174
- const promotionsQueryKeys = {
11175
- list: (query2) => [
11176
- PROMOTION_QUERY_KEY,
11177
- query2 ? query2 : void 0
11178
- ],
11179
- detail: (id, query2) => [
11180
- PROMOTION_QUERY_KEY,
11181
- id,
11182
- query2 ? query2 : void 0
11183
- ]
11184
- };
11185
- const usePromotions = (query2, options) => {
11186
- const { data, ...rest } = useQuery({
11187
- queryKey: promotionsQueryKeys.list(query2),
11188
- queryFn: async () => sdk.admin.promotion.list(query2),
11189
- ...options
11190
- });
11191
- return { ...data, ...rest };
11192
- };
11193
- const Promotions = () => {
11173
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11174
+ const Shipping = () => {
11175
+ var _a;
11194
11176
  const { id } = useParams();
11177
+ const { order, isPending, isError, error } = useOrder(id, {
11178
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11179
+ });
11195
11180
  const {
11196
11181
  order: preview,
11182
+ isPending: isPreviewPending,
11197
11183
  isError: isPreviewError,
11198
11184
  error: previewError
11199
- } = useOrderPreview(id, void 0);
11185
+ } = useOrderPreview(id);
11200
11186
  useInitiateOrderEdit({ preview });
11201
11187
  const { onCancel } = useCancelOrderEdit({ preview });
11188
+ if (isError) {
11189
+ throw error;
11190
+ }
11202
11191
  if (isPreviewError) {
11203
11192
  throw previewError;
11204
11193
  }
11205
- const isReady = !!preview;
11206
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11207
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11208
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11209
- ] });
11194
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11195
+ const isReady = preview && !isPreviewPending && order && !isPending;
11196
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11197
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11198
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11199
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11200
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11201
+ ] }) }) }),
11202
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11203
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11204
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11205
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11206
+ ] }) });
11210
11207
  };
11211
- const PromotionForm = ({ preview }) => {
11212
- const { items, shipping_methods } = preview;
11208
+ const ShippingForm = ({ preview, order }) => {
11209
+ var _a;
11210
+ const { setIsOpen } = useStackedModal();
11213
11211
  const [isSubmitting, setIsSubmitting] = useState(false);
11214
- const [comboboxValue, setComboboxValue] = useState("");
11215
- const { handleSuccess } = useRouteModal();
11216
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11217
- const promoIds = getPromotionIds(items, shipping_methods);
11218
- const { promotions, isPending, isError, error } = usePromotions(
11212
+ const [data, setData] = useState(null);
11213
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11214
+ const { shipping_options } = useShippingOptions(
11219
11215
  {
11220
- id: promoIds
11216
+ id: appliedShippingOptionIds,
11217
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11221
11218
  },
11222
11219
  {
11223
- enabled: !!promoIds.length
11220
+ enabled: appliedShippingOptionIds.length > 0
11224
11221
  }
11225
11222
  );
11226
- const comboboxData = useComboboxData({
11227
- queryKey: ["promotions", "combobox", promoIds],
11228
- queryFn: async (params) => {
11229
- return await sdk.admin.promotion.list({
11230
- ...params,
11231
- id: {
11232
- $nin: promoIds
11233
- }
11234
- });
11235
- },
11236
- getOptions: (data) => {
11237
- return data.promotions.map((promotion) => ({
11238
- label: promotion.code,
11239
- value: promotion.code
11240
- }));
11241
- }
11242
- });
11243
- const add = async (value) => {
11244
- if (!value) {
11245
- return;
11246
- }
11247
- addPromotions(
11248
- {
11249
- promo_codes: [value]
11250
- },
11251
- {
11252
- onError: (e) => {
11253
- toast.error(e.message);
11254
- comboboxData.onSearchValueChange("");
11255
- setComboboxValue("");
11256
- },
11257
- onSuccess: () => {
11258
- comboboxData.onSearchValueChange("");
11259
- setComboboxValue("");
11260
- }
11261
- }
11262
- );
11263
- };
11223
+ const uniqueShippingProfiles = useMemo(() => {
11224
+ const profiles = /* @__PURE__ */ new Map();
11225
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11226
+ profiles.set(profile.id, profile);
11227
+ });
11228
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11229
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11230
+ });
11231
+ return Array.from(profiles.values());
11232
+ }, [order.items, shipping_options]);
11233
+ const { handleSuccess } = useRouteModal();
11264
11234
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11265
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11235
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11236
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11237
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11266
11238
  const onSubmit = async () => {
11267
11239
  setIsSubmitting(true);
11268
11240
  let requestSucceeded = false;
11269
11241
  await requestOrderEdit(void 0, {
11270
11242
  onError: (e) => {
11271
- toast.error(e.message);
11243
+ toast.error(`Failed to request order edit: ${e.message}`);
11272
11244
  },
11273
11245
  onSuccess: () => {
11274
11246
  requestSucceeded = true;
@@ -11280,7 +11252,7 @@ const PromotionForm = ({ preview }) => {
11280
11252
  }
11281
11253
  await confirmOrderEdit(void 0, {
11282
11254
  onError: (e) => {
11283
- toast.error(e.message);
11255
+ toast.error(`Failed to confirm order edit: ${e.message}`);
11284
11256
  },
11285
11257
  onSuccess: () => {
11286
11258
  handleSuccess();
@@ -11290,371 +11262,16 @@ const PromotionForm = ({ preview }) => {
11290
11262
  }
11291
11263
  });
11292
11264
  };
11293
- if (isError) {
11294
- throw error;
11295
- }
11296
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11297
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11298
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11299
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11300
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11301
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11302
- ] }),
11303
- /* @__PURE__ */ jsx(
11304
- Combobox,
11305
- {
11306
- id: "promotion-combobox",
11307
- "aria-describedby": "promotion-combobox-hint",
11308
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11309
- fetchNextPage: comboboxData.fetchNextPage,
11310
- options: comboboxData.options,
11311
- onSearchValueChange: comboboxData.onSearchValueChange,
11312
- searchValue: comboboxData.searchValue,
11313
- disabled: comboboxData.disabled || isAddingPromotions,
11314
- onChange: add,
11315
- value: comboboxValue
11316
- }
11317
- )
11318
- ] }),
11319
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11320
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11321
- PromotionItem,
11322
- {
11323
- promotion,
11324
- orderId: preview.id,
11325
- isLoading: isPending
11326
- },
11327
- promotion.id
11328
- )) })
11329
- ] }) }),
11330
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11331
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11332
- /* @__PURE__ */ jsx(
11333
- Button,
11334
- {
11335
- size: "small",
11336
- type: "submit",
11337
- isLoading: isSubmitting || isAddingPromotions,
11338
- children: "Save"
11339
- }
11340
- )
11341
- ] }) })
11342
- ] });
11343
- };
11344
- const PromotionItem = ({
11345
- promotion,
11346
- orderId,
11347
- isLoading
11348
- }) => {
11349
- var _a;
11350
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11351
- const onRemove = async () => {
11352
- removePromotions(
11353
- {
11354
- promo_codes: [promotion.code]
11355
- },
11356
- {
11357
- onError: (e) => {
11358
- toast.error(e.message);
11359
- }
11360
- }
11361
- );
11362
- };
11363
- const displayValue = getDisplayValue(promotion);
11364
- return /* @__PURE__ */ jsxs(
11365
- "div",
11366
- {
11367
- className: clx(
11368
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11369
- {
11370
- "animate-pulse": isLoading
11371
- }
11372
- ),
11373
- children: [
11374
- /* @__PURE__ */ jsxs("div", { children: [
11375
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11376
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11377
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11378
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11379
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11380
- ] }),
11381
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11382
- ] })
11383
- ] }),
11384
- /* @__PURE__ */ jsx(
11385
- IconButton,
11386
- {
11387
- size: "small",
11388
- type: "button",
11389
- variant: "transparent",
11390
- onClick: onRemove,
11391
- isLoading: isPending || isLoading,
11392
- children: /* @__PURE__ */ jsx(XMark, {})
11393
- }
11394
- )
11395
- ]
11396
- },
11397
- promotion.id
11398
- );
11399
- };
11400
- function getDisplayValue(promotion) {
11401
- var _a, _b, _c, _d;
11402
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11403
- if (!value) {
11404
- return null;
11405
- }
11406
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11407
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11408
- if (!currency) {
11409
- return null;
11410
- }
11411
- return getLocaleAmount(value, currency);
11412
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11413
- return formatPercentage(value);
11414
- }
11415
- return null;
11416
- }
11417
- const formatter = new Intl.NumberFormat([], {
11418
- style: "percent",
11419
- minimumFractionDigits: 2
11420
- });
11421
- const formatPercentage = (value, isPercentageValue = false) => {
11422
- let val = value || 0;
11423
- if (!isPercentageValue) {
11424
- val = val / 100;
11425
- }
11426
- return formatter.format(val);
11427
- };
11428
- function getPromotionIds(items, shippingMethods) {
11429
- const promotionIds = /* @__PURE__ */ new Set();
11430
- for (const item of items) {
11431
- if (item.adjustments) {
11432
- for (const adjustment of item.adjustments) {
11433
- if (adjustment.promotion_id) {
11434
- promotionIds.add(adjustment.promotion_id);
11435
- }
11436
- }
11437
- }
11438
- }
11439
- for (const shippingMethod of shippingMethods) {
11440
- if (shippingMethod.adjustments) {
11441
- for (const adjustment of shippingMethod.adjustments) {
11442
- if (adjustment.promotion_id) {
11443
- promotionIds.add(adjustment.promotion_id);
11265
+ const onKeydown = useCallback(
11266
+ (e) => {
11267
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11268
+ if (data || isSubmitting) {
11269
+ return;
11444
11270
  }
11271
+ onSubmit();
11445
11272
  }
11446
- }
11447
- }
11448
- return Array.from(promotionIds);
11449
- }
11450
- const SalesChannel = () => {
11451
- const { id } = useParams();
11452
- const { draft_order, isPending, isError, error } = useDraftOrder(
11453
- id,
11454
- {
11455
- fields: "+sales_channel_id"
11456
11273
  },
11457
- {
11458
- enabled: !!id
11459
- }
11460
- );
11461
- if (isError) {
11462
- throw error;
11463
- }
11464
- const ISrEADY = !!draft_order && !isPending;
11465
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11467
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11468
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11469
- ] }),
11470
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11471
- ] });
11472
- };
11473
- const SalesChannelForm = ({ order }) => {
11474
- const form = useForm({
11475
- defaultValues: {
11476
- sales_channel_id: order.sales_channel_id || ""
11477
- },
11478
- resolver: zodResolver(schema$2)
11479
- });
11480
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
- const { handleSuccess } = useRouteModal();
11482
- const onSubmit = form.handleSubmit(async (data) => {
11483
- await mutateAsync(
11484
- {
11485
- sales_channel_id: data.sales_channel_id
11486
- },
11487
- {
11488
- onSuccess: () => {
11489
- toast.success("Sales channel updated");
11490
- handleSuccess();
11491
- },
11492
- onError: (error) => {
11493
- toast.error(error.message);
11494
- }
11495
- }
11496
- );
11497
- });
11498
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11499
- KeyboundForm,
11500
- {
11501
- className: "flex flex-1 flex-col overflow-hidden",
11502
- onSubmit,
11503
- children: [
11504
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11505
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11506
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11507
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
- ] }) })
11509
- ]
11510
- }
11511
- ) });
11512
- };
11513
- const SalesChannelField = ({ control, order }) => {
11514
- const salesChannels = useComboboxData({
11515
- queryFn: async (params) => {
11516
- return await sdk.admin.salesChannel.list(params);
11517
- },
11518
- queryKey: ["sales-channels"],
11519
- getOptions: (data) => {
11520
- return data.sales_channels.map((salesChannel) => ({
11521
- label: salesChannel.name,
11522
- value: salesChannel.id
11523
- }));
11524
- },
11525
- defaultValue: order.sales_channel_id || void 0
11526
- });
11527
- return /* @__PURE__ */ jsx(
11528
- Form$2.Field,
11529
- {
11530
- control,
11531
- name: "sales_channel_id",
11532
- render: ({ field }) => {
11533
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
- Combobox,
11537
- {
11538
- options: salesChannels.options,
11539
- fetchNextPage: salesChannels.fetchNextPage,
11540
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
- searchValue: salesChannels.searchValue,
11542
- onSearchValueChange: salesChannels.onSearchValueChange,
11543
- placeholder: "Select sales channel",
11544
- ...field
11545
- }
11546
- ) }),
11547
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
- ] });
11549
- }
11550
- }
11551
- );
11552
- };
11553
- const schema$2 = objectType({
11554
- sales_channel_id: stringType().min(1)
11555
- });
11556
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
- const Shipping = () => {
11558
- var _a;
11559
- const { id } = useParams();
11560
- const { order, isPending, isError, error } = useOrder(id, {
11561
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11562
- });
11563
- const {
11564
- order: preview,
11565
- isPending: isPreviewPending,
11566
- isError: isPreviewError,
11567
- error: previewError
11568
- } = useOrderPreview(id);
11569
- useInitiateOrderEdit({ preview });
11570
- const { onCancel } = useCancelOrderEdit({ preview });
11571
- if (isError) {
11572
- throw error;
11573
- }
11574
- if (isPreviewError) {
11575
- throw previewError;
11576
- }
11577
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11578
- const isReady = preview && !isPreviewPending && order && !isPending;
11579
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11580
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11581
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11582
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11583
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11584
- ] }) }) }),
11585
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11586
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11587
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11588
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11589
- ] }) });
11590
- };
11591
- const ShippingForm = ({ preview, order }) => {
11592
- var _a;
11593
- const { setIsOpen } = useStackedModal();
11594
- const [isSubmitting, setIsSubmitting] = useState(false);
11595
- const [data, setData] = useState(null);
11596
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11597
- const { shipping_options } = useShippingOptions(
11598
- {
11599
- id: appliedShippingOptionIds,
11600
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11601
- },
11602
- {
11603
- enabled: appliedShippingOptionIds.length > 0
11604
- }
11605
- );
11606
- const uniqueShippingProfiles = useMemo(() => {
11607
- const profiles = /* @__PURE__ */ new Map();
11608
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11609
- profiles.set(profile.id, profile);
11610
- });
11611
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11612
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11613
- });
11614
- return Array.from(profiles.values());
11615
- }, [order.items, shipping_options]);
11616
- const { handleSuccess } = useRouteModal();
11617
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11618
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11619
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11620
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11621
- const onSubmit = async () => {
11622
- setIsSubmitting(true);
11623
- let requestSucceeded = false;
11624
- await requestOrderEdit(void 0, {
11625
- onError: (e) => {
11626
- toast.error(`Failed to request order edit: ${e.message}`);
11627
- },
11628
- onSuccess: () => {
11629
- requestSucceeded = true;
11630
- }
11631
- });
11632
- if (!requestSucceeded) {
11633
- setIsSubmitting(false);
11634
- return;
11635
- }
11636
- await confirmOrderEdit(void 0, {
11637
- onError: (e) => {
11638
- toast.error(`Failed to confirm order edit: ${e.message}`);
11639
- },
11640
- onSuccess: () => {
11641
- handleSuccess();
11642
- },
11643
- onSettled: () => {
11644
- setIsSubmitting(false);
11645
- }
11646
- });
11647
- };
11648
- const onKeydown = useCallback(
11649
- (e) => {
11650
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11651
- if (data || isSubmitting) {
11652
- return;
11653
- }
11654
- onSubmit();
11655
- }
11656
- },
11657
- [data, isSubmitting, onSubmit]
11274
+ [data, isSubmitting, onSubmit]
11658
11275
  );
11659
11276
  useEffect(() => {
11660
11277
  document.addEventListener("keydown", onKeydown);
@@ -12360,209 +11977,592 @@ const CustomAmountField = ({
12360
11977
  }
12361
11978
  );
12362
11979
  };
12363
- const ShippingAddress = () => {
11980
+ const SalesChannel = () => {
12364
11981
  const { id } = useParams();
12365
- const { order, isPending, isError, error } = useOrder(id, {
12366
- fields: "+shipping_address"
12367
- });
11982
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11983
+ id,
11984
+ {
11985
+ fields: "+sales_channel_id"
11986
+ },
11987
+ {
11988
+ enabled: !!id
11989
+ }
11990
+ );
12368
11991
  if (isError) {
12369
11992
  throw error;
12370
11993
  }
12371
- const isReady = !isPending && !!order;
11994
+ const ISrEADY = !!draft_order && !isPending;
12372
11995
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12373
11996
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12374
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11997
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11998
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12376
11999
  ] }),
12377
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12000
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12378
12001
  ] });
12379
12002
  };
12380
- const ShippingAddressForm = ({ order }) => {
12381
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12003
+ const SalesChannelForm = ({ order }) => {
12382
12004
  const form = useForm({
12383
12005
  defaultValues: {
12384
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12006
+ sales_channel_id: order.sales_channel_id || ""
12394
12007
  },
12395
- resolver: zodResolver(schema$1)
12008
+ resolver: zodResolver(schema$2)
12396
12009
  });
12397
12010
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12398
12011
  const { handleSuccess } = useRouteModal();
12399
12012
  const onSubmit = form.handleSubmit(async (data) => {
12400
12013
  await mutateAsync(
12401
12014
  {
12402
- shipping_address: {
12403
- first_name: data.first_name,
12404
- last_name: data.last_name,
12405
- company: data.company,
12406
- address_1: data.address_1,
12407
- address_2: data.address_2,
12408
- city: data.city,
12409
- province: data.province,
12410
- country_code: data.country_code,
12411
- postal_code: data.postal_code,
12412
- phone: data.phone
12015
+ sales_channel_id: data.sales_channel_id
12016
+ },
12017
+ {
12018
+ onSuccess: () => {
12019
+ toast.success("Sales channel updated");
12020
+ handleSuccess();
12021
+ },
12022
+ onError: (error) => {
12023
+ toast.error(error.message);
12413
12024
  }
12025
+ }
12026
+ );
12027
+ });
12028
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12029
+ KeyboundForm,
12030
+ {
12031
+ className: "flex flex-1 flex-col overflow-hidden",
12032
+ onSubmit,
12033
+ children: [
12034
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12035
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12036
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12037
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12038
+ ] }) })
12039
+ ]
12040
+ }
12041
+ ) });
12042
+ };
12043
+ const SalesChannelField = ({ control, order }) => {
12044
+ const salesChannels = useComboboxData({
12045
+ queryFn: async (params) => {
12046
+ return await sdk.admin.salesChannel.list(params);
12047
+ },
12048
+ queryKey: ["sales-channels"],
12049
+ getOptions: (data) => {
12050
+ return data.sales_channels.map((salesChannel) => ({
12051
+ label: salesChannel.name,
12052
+ value: salesChannel.id
12053
+ }));
12054
+ },
12055
+ defaultValue: order.sales_channel_id || void 0
12056
+ });
12057
+ return /* @__PURE__ */ jsx(
12058
+ Form$2.Field,
12059
+ {
12060
+ control,
12061
+ name: "sales_channel_id",
12062
+ render: ({ field }) => {
12063
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12064
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12065
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12066
+ Combobox,
12067
+ {
12068
+ options: salesChannels.options,
12069
+ fetchNextPage: salesChannels.fetchNextPage,
12070
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12071
+ searchValue: salesChannels.searchValue,
12072
+ onSearchValueChange: salesChannels.onSearchValueChange,
12073
+ placeholder: "Select sales channel",
12074
+ ...field
12075
+ }
12076
+ ) }),
12077
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12078
+ ] });
12079
+ }
12080
+ }
12081
+ );
12082
+ };
12083
+ const schema$2 = objectType({
12084
+ sales_channel_id: stringType().min(1)
12085
+ });
12086
+ const ShippingAddress = () => {
12087
+ const { id } = useParams();
12088
+ const { order, isPending, isError, error } = useOrder(id, {
12089
+ fields: "+shipping_address"
12090
+ });
12091
+ if (isError) {
12092
+ throw error;
12093
+ }
12094
+ const isReady = !isPending && !!order;
12095
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12096
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12097
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12098
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12099
+ ] }),
12100
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12101
+ ] });
12102
+ };
12103
+ const ShippingAddressForm = ({ order }) => {
12104
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12105
+ const form = useForm({
12106
+ defaultValues: {
12107
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12108
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12109
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12110
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12111
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12112
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12113
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12114
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12115
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12116
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12117
+ },
12118
+ resolver: zodResolver(schema$1)
12119
+ });
12120
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12121
+ const { handleSuccess } = useRouteModal();
12122
+ const onSubmit = form.handleSubmit(async (data) => {
12123
+ await mutateAsync(
12124
+ {
12125
+ shipping_address: {
12126
+ first_name: data.first_name,
12127
+ last_name: data.last_name,
12128
+ company: data.company,
12129
+ address_1: data.address_1,
12130
+ address_2: data.address_2,
12131
+ city: data.city,
12132
+ province: data.province,
12133
+ country_code: data.country_code,
12134
+ postal_code: data.postal_code,
12135
+ phone: data.phone
12136
+ }
12137
+ },
12138
+ {
12139
+ onSuccess: () => {
12140
+ handleSuccess();
12141
+ },
12142
+ onError: (error) => {
12143
+ toast.error(error.message);
12144
+ }
12145
+ }
12146
+ );
12147
+ });
12148
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12149
+ KeyboundForm,
12150
+ {
12151
+ className: "flex flex-1 flex-col overflow-hidden",
12152
+ onSubmit,
12153
+ children: [
12154
+ /* @__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: [
12155
+ /* @__PURE__ */ jsx(
12156
+ Form$2.Field,
12157
+ {
12158
+ control: form.control,
12159
+ name: "country_code",
12160
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12161
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12162
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12163
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12164
+ ] })
12165
+ }
12166
+ ),
12167
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12168
+ /* @__PURE__ */ jsx(
12169
+ Form$2.Field,
12170
+ {
12171
+ control: form.control,
12172
+ name: "first_name",
12173
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12174
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12175
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12176
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12177
+ ] })
12178
+ }
12179
+ ),
12180
+ /* @__PURE__ */ jsx(
12181
+ Form$2.Field,
12182
+ {
12183
+ control: form.control,
12184
+ name: "last_name",
12185
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12186
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12187
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12188
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12189
+ ] })
12190
+ }
12191
+ )
12192
+ ] }),
12193
+ /* @__PURE__ */ jsx(
12194
+ Form$2.Field,
12195
+ {
12196
+ control: form.control,
12197
+ name: "company",
12198
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12199
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12200
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12201
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12202
+ ] })
12203
+ }
12204
+ ),
12205
+ /* @__PURE__ */ jsx(
12206
+ Form$2.Field,
12207
+ {
12208
+ control: form.control,
12209
+ name: "address_1",
12210
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12211
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12212
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12213
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12214
+ ] })
12215
+ }
12216
+ ),
12217
+ /* @__PURE__ */ jsx(
12218
+ Form$2.Field,
12219
+ {
12220
+ control: form.control,
12221
+ name: "address_2",
12222
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12223
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12224
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12225
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12226
+ ] })
12227
+ }
12228
+ ),
12229
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12230
+ /* @__PURE__ */ jsx(
12231
+ Form$2.Field,
12232
+ {
12233
+ control: form.control,
12234
+ name: "postal_code",
12235
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12236
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12237
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12238
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12239
+ ] })
12240
+ }
12241
+ ),
12242
+ /* @__PURE__ */ jsx(
12243
+ Form$2.Field,
12244
+ {
12245
+ control: form.control,
12246
+ name: "city",
12247
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12248
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12249
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12250
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12251
+ ] })
12252
+ }
12253
+ )
12254
+ ] }),
12255
+ /* @__PURE__ */ jsx(
12256
+ Form$2.Field,
12257
+ {
12258
+ control: form.control,
12259
+ name: "province",
12260
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12261
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12262
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12263
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12264
+ ] })
12265
+ }
12266
+ ),
12267
+ /* @__PURE__ */ jsx(
12268
+ Form$2.Field,
12269
+ {
12270
+ control: form.control,
12271
+ name: "phone",
12272
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12273
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12274
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12275
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12276
+ ] })
12277
+ }
12278
+ )
12279
+ ] }) }),
12280
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12281
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12282
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12283
+ ] }) })
12284
+ ]
12285
+ }
12286
+ ) });
12287
+ };
12288
+ const schema$1 = addressSchema;
12289
+ const PROMOTION_QUERY_KEY = "promotions";
12290
+ const promotionsQueryKeys = {
12291
+ list: (query2) => [
12292
+ PROMOTION_QUERY_KEY,
12293
+ query2 ? query2 : void 0
12294
+ ],
12295
+ detail: (id, query2) => [
12296
+ PROMOTION_QUERY_KEY,
12297
+ id,
12298
+ query2 ? query2 : void 0
12299
+ ]
12300
+ };
12301
+ const usePromotions = (query2, options) => {
12302
+ const { data, ...rest } = useQuery({
12303
+ queryKey: promotionsQueryKeys.list(query2),
12304
+ queryFn: async () => sdk.admin.promotion.list(query2),
12305
+ ...options
12306
+ });
12307
+ return { ...data, ...rest };
12308
+ };
12309
+ const Promotions = () => {
12310
+ const { id } = useParams();
12311
+ const {
12312
+ order: preview,
12313
+ isError: isPreviewError,
12314
+ error: previewError
12315
+ } = useOrderPreview(id, void 0);
12316
+ useInitiateOrderEdit({ preview });
12317
+ const { onCancel } = useCancelOrderEdit({ preview });
12318
+ if (isPreviewError) {
12319
+ throw previewError;
12320
+ }
12321
+ const isReady = !!preview;
12322
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
12323
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
12324
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
12325
+ ] });
12326
+ };
12327
+ const PromotionForm = ({ preview }) => {
12328
+ const { items, shipping_methods } = preview;
12329
+ const [isSubmitting, setIsSubmitting] = useState(false);
12330
+ const [comboboxValue, setComboboxValue] = useState("");
12331
+ const { handleSuccess } = useRouteModal();
12332
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12333
+ const promoIds = getPromotionIds(items, shipping_methods);
12334
+ const { promotions, isPending, isError, error } = usePromotions(
12335
+ {
12336
+ id: promoIds
12337
+ },
12338
+ {
12339
+ enabled: !!promoIds.length
12340
+ }
12341
+ );
12342
+ const comboboxData = useComboboxData({
12343
+ queryKey: ["promotions", "combobox", promoIds],
12344
+ queryFn: async (params) => {
12345
+ return await sdk.admin.promotion.list({
12346
+ ...params,
12347
+ id: {
12348
+ $nin: promoIds
12349
+ }
12350
+ });
12351
+ },
12352
+ getOptions: (data) => {
12353
+ return data.promotions.map((promotion) => ({
12354
+ label: promotion.code,
12355
+ value: promotion.code
12356
+ }));
12357
+ }
12358
+ });
12359
+ const add = async (value) => {
12360
+ if (!value) {
12361
+ return;
12362
+ }
12363
+ addPromotions(
12364
+ {
12365
+ promo_codes: [value]
12366
+ },
12367
+ {
12368
+ onError: (e) => {
12369
+ toast.error(e.message);
12370
+ comboboxData.onSearchValueChange("");
12371
+ setComboboxValue("");
12372
+ },
12373
+ onSuccess: () => {
12374
+ comboboxData.onSearchValueChange("");
12375
+ setComboboxValue("");
12376
+ }
12377
+ }
12378
+ );
12379
+ };
12380
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12381
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12382
+ const onSubmit = async () => {
12383
+ setIsSubmitting(true);
12384
+ let requestSucceeded = false;
12385
+ await requestOrderEdit(void 0, {
12386
+ onError: (e) => {
12387
+ toast.error(e.message);
12388
+ },
12389
+ onSuccess: () => {
12390
+ requestSucceeded = true;
12391
+ }
12392
+ });
12393
+ if (!requestSucceeded) {
12394
+ setIsSubmitting(false);
12395
+ return;
12396
+ }
12397
+ await confirmOrderEdit(void 0, {
12398
+ onError: (e) => {
12399
+ toast.error(e.message);
12400
+ },
12401
+ onSuccess: () => {
12402
+ handleSuccess();
12403
+ },
12404
+ onSettled: () => {
12405
+ setIsSubmitting(false);
12406
+ }
12407
+ });
12408
+ };
12409
+ if (isError) {
12410
+ throw error;
12411
+ }
12412
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12413
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
12414
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
12415
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12416
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12417
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12418
+ ] }),
12419
+ /* @__PURE__ */ jsx(
12420
+ Combobox,
12421
+ {
12422
+ id: "promotion-combobox",
12423
+ "aria-describedby": "promotion-combobox-hint",
12424
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12425
+ fetchNextPage: comboboxData.fetchNextPage,
12426
+ options: comboboxData.options,
12427
+ onSearchValueChange: comboboxData.onSearchValueChange,
12428
+ searchValue: comboboxData.searchValue,
12429
+ disabled: comboboxData.disabled || isAddingPromotions,
12430
+ onChange: add,
12431
+ value: comboboxValue
12432
+ }
12433
+ )
12434
+ ] }),
12435
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12436
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
12437
+ PromotionItem,
12438
+ {
12439
+ promotion,
12440
+ orderId: preview.id,
12441
+ isLoading: isPending
12442
+ },
12443
+ promotion.id
12444
+ )) })
12445
+ ] }) }),
12446
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12447
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12448
+ /* @__PURE__ */ jsx(
12449
+ Button,
12450
+ {
12451
+ size: "small",
12452
+ type: "submit",
12453
+ isLoading: isSubmitting || isAddingPromotions,
12454
+ children: "Save"
12455
+ }
12456
+ )
12457
+ ] }) })
12458
+ ] });
12459
+ };
12460
+ const PromotionItem = ({
12461
+ promotion,
12462
+ orderId,
12463
+ isLoading
12464
+ }) => {
12465
+ var _a;
12466
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12467
+ const onRemove = async () => {
12468
+ removePromotions(
12469
+ {
12470
+ promo_codes: [promotion.code]
12414
12471
  },
12415
12472
  {
12416
- onSuccess: () => {
12417
- handleSuccess();
12418
- },
12419
- onError: (error) => {
12420
- toast.error(error.message);
12473
+ onError: (e) => {
12474
+ toast.error(e.message);
12421
12475
  }
12422
12476
  }
12423
12477
  );
12424
- });
12425
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12426
- KeyboundForm,
12478
+ };
12479
+ const displayValue = getDisplayValue(promotion);
12480
+ return /* @__PURE__ */ jsxs(
12481
+ "div",
12427
12482
  {
12428
- className: "flex flex-1 flex-col overflow-hidden",
12429
- onSubmit,
12483
+ className: clx(
12484
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12485
+ {
12486
+ "animate-pulse": isLoading
12487
+ }
12488
+ ),
12430
12489
  children: [
12431
- /* @__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: [
12432
- /* @__PURE__ */ jsx(
12433
- Form$2.Field,
12434
- {
12435
- control: form.control,
12436
- name: "country_code",
12437
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
- ] })
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
- /* @__PURE__ */ jsx(
12446
- Form$2.Field,
12447
- {
12448
- control: form.control,
12449
- name: "first_name",
12450
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
- ] })
12455
- }
12456
- ),
12457
- /* @__PURE__ */ jsx(
12458
- Form$2.Field,
12459
- {
12460
- control: form.control,
12461
- name: "last_name",
12462
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
- ] })
12467
- }
12468
- )
12469
- ] }),
12470
- /* @__PURE__ */ jsx(
12471
- Form$2.Field,
12472
- {
12473
- control: form.control,
12474
- name: "company",
12475
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
- ] })
12480
- }
12481
- ),
12482
- /* @__PURE__ */ jsx(
12483
- Form$2.Field,
12484
- {
12485
- control: form.control,
12486
- name: "address_1",
12487
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
- ] })
12492
- }
12493
- ),
12494
- /* @__PURE__ */ jsx(
12495
- Form$2.Field,
12496
- {
12497
- control: form.control,
12498
- name: "address_2",
12499
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
- ] })
12504
- }
12505
- ),
12506
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
- /* @__PURE__ */ jsx(
12508
- Form$2.Field,
12509
- {
12510
- control: form.control,
12511
- name: "postal_code",
12512
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
- ] })
12517
- }
12518
- ),
12519
- /* @__PURE__ */ jsx(
12520
- Form$2.Field,
12521
- {
12522
- control: form.control,
12523
- name: "city",
12524
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
- ] })
12529
- }
12530
- )
12531
- ] }),
12532
- /* @__PURE__ */ jsx(
12533
- Form$2.Field,
12534
- {
12535
- control: form.control,
12536
- name: "province",
12537
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
- ] })
12542
- }
12543
- ),
12544
- /* @__PURE__ */ jsx(
12545
- Form$2.Field,
12546
- {
12547
- control: form.control,
12548
- name: "phone",
12549
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
- ] })
12554
- }
12555
- )
12556
- ] }) }),
12557
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12558
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12559
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12560
- ] }) })
12490
+ /* @__PURE__ */ jsxs("div", { children: [
12491
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12492
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12493
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
12494
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
12495
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
12496
+ ] }),
12497
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12498
+ ] })
12499
+ ] }),
12500
+ /* @__PURE__ */ jsx(
12501
+ IconButton,
12502
+ {
12503
+ size: "small",
12504
+ type: "button",
12505
+ variant: "transparent",
12506
+ onClick: onRemove,
12507
+ isLoading: isPending || isLoading,
12508
+ children: /* @__PURE__ */ jsx(XMark, {})
12509
+ }
12510
+ )
12561
12511
  ]
12512
+ },
12513
+ promotion.id
12514
+ );
12515
+ };
12516
+ function getDisplayValue(promotion) {
12517
+ var _a, _b, _c, _d;
12518
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12519
+ if (!value) {
12520
+ return null;
12521
+ }
12522
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12523
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
12524
+ if (!currency) {
12525
+ return null;
12562
12526
  }
12563
- ) });
12527
+ return getLocaleAmount(value, currency);
12528
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
12529
+ return formatPercentage(value);
12530
+ }
12531
+ return null;
12532
+ }
12533
+ const formatter = new Intl.NumberFormat([], {
12534
+ style: "percent",
12535
+ minimumFractionDigits: 2
12536
+ });
12537
+ const formatPercentage = (value, isPercentageValue = false) => {
12538
+ let val = value || 0;
12539
+ if (!isPercentageValue) {
12540
+ val = val / 100;
12541
+ }
12542
+ return formatter.format(val);
12564
12543
  };
12565
- const schema$1 = addressSchema;
12544
+ function getPromotionIds(items, shippingMethods) {
12545
+ const promotionIds = /* @__PURE__ */ new Set();
12546
+ for (const item of items) {
12547
+ if (item.adjustments) {
12548
+ for (const adjustment of item.adjustments) {
12549
+ if (adjustment.promotion_id) {
12550
+ promotionIds.add(adjustment.promotion_id);
12551
+ }
12552
+ }
12553
+ }
12554
+ }
12555
+ for (const shippingMethod of shippingMethods) {
12556
+ if (shippingMethod.adjustments) {
12557
+ for (const adjustment of shippingMethod.adjustments) {
12558
+ if (adjustment.promotion_id) {
12559
+ promotionIds.add(adjustment.promotion_id);
12560
+ }
12561
+ }
12562
+ }
12563
+ }
12564
+ return Array.from(promotionIds);
12565
+ }
12566
12566
  const TransferOwnership = () => {
12567
12567
  const { id } = useParams();
12568
12568
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13064,37 +13064,37 @@ const routeModule = {
13064
13064
  path: "/draft-orders/:id/billing-address"
13065
13065
  },
13066
13066
  {
13067
- Component: CustomItems,
13068
- path: "/draft-orders/:id/custom-items"
13067
+ Component: Items,
13068
+ path: "/draft-orders/:id/items"
13069
13069
  },
13070
13070
  {
13071
13071
  Component: Email,
13072
13072
  path: "/draft-orders/:id/email"
13073
13073
  },
13074
13074
  {
13075
- Component: Items,
13076
- path: "/draft-orders/:id/items"
13075
+ Component: CustomItems,
13076
+ path: "/draft-orders/:id/custom-items"
13077
13077
  },
13078
13078
  {
13079
13079
  Component: Metadata,
13080
13080
  path: "/draft-orders/:id/metadata"
13081
13081
  },
13082
13082
  {
13083
- Component: Promotions,
13084
- path: "/draft-orders/:id/promotions"
13083
+ Component: Shipping,
13084
+ path: "/draft-orders/:id/shipping"
13085
13085
  },
13086
13086
  {
13087
13087
  Component: SalesChannel,
13088
13088
  path: "/draft-orders/:id/sales-channel"
13089
13089
  },
13090
- {
13091
- Component: Shipping,
13092
- path: "/draft-orders/:id/shipping"
13093
- },
13094
13090
  {
13095
13091
  Component: ShippingAddress,
13096
13092
  path: "/draft-orders/:id/shipping-address"
13097
13093
  },
13094
+ {
13095
+ Component: Promotions,
13096
+ path: "/draft-orders/:id/promotions"
13097
+ },
13098
13098
  {
13099
13099
  Component: TransferOwnership,
13100
13100
  path: "/draft-orders/:id/transfer-ownership"