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