@medusajs/draft-order 2.11.4-snapshot-20251107110738 → 2.11.4-snapshot-20251107205323

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.
@@ -352,10 +352,14 @@ const DataTableAction = ({
352
352
  }
353
353
  return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { ...buttonProps, onClick: props.onClick, children: label });
354
354
  };
355
+ const backendUrl = __BACKEND_URL__ ?? "/";
356
+ const authType = __AUTH_TYPE__ ?? "session";
357
+ const jwtTokenStorageKey = __JWT_TOKEN_STORAGE_KEY__ || void 0;
355
358
  const sdk = new Medusa__default.default({
356
- baseUrl: __BACKEND_URL__ || "/",
359
+ baseUrl: backendUrl,
357
360
  auth: {
358
- type: "session"
361
+ type: authType,
362
+ jwtTokenStorageKey
359
363
  }
360
364
  });
361
365
  const CUSTOMER_QUERY_KEY = "customers";
@@ -9758,6 +9762,27 @@ const BillingAddressForm = ({ order }) => {
9758
9762
  ) });
9759
9763
  };
9760
9764
  const schema$5 = addressSchema;
9765
+ const CustomItems = () => {
9766
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9767
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9768
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9769
+ ] });
9770
+ };
9771
+ const CustomItemsForm = () => {
9772
+ const form = reactHookForm.useForm({
9773
+ resolver: zod.zodResolver(schema$4)
9774
+ });
9775
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9776
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9777
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9778
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9779
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9780
+ ] }) })
9781
+ ] }) });
9782
+ };
9783
+ const schema$4 = objectType({
9784
+ email: stringType().email()
9785
+ });
9761
9786
  const Email = () => {
9762
9787
  const { id } = reactRouterDom.useParams();
9763
9788
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9780,7 +9805,7 @@ const EmailForm = ({ order }) => {
9780
9805
  defaultValues: {
9781
9806
  email: order.email ?? ""
9782
9807
  },
9783
- resolver: zod.zodResolver(schema$4)
9808
+ resolver: zod.zodResolver(schema$3)
9784
9809
  });
9785
9810
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9786
9811
  const { handleSuccess } = useRouteModal();
@@ -9823,7 +9848,7 @@ const EmailForm = ({ order }) => {
9823
9848
  }
9824
9849
  ) });
9825
9850
  };
9826
- const schema$4 = objectType({
9851
+ const schema$3 = objectType({
9827
9852
  email: stringType().email()
9828
9853
  });
9829
9854
  const NumberInput = React.forwardRef(
@@ -11150,105 +11175,183 @@ function getHasUneditableRows(metadata) {
11150
11175
  (value) => !EDITABLE_TYPES.includes(typeof value)
11151
11176
  );
11152
11177
  }
11153
- const PROMOTION_QUERY_KEY = "promotions";
11154
- const promotionsQueryKeys = {
11155
- list: (query2) => [
11156
- PROMOTION_QUERY_KEY,
11157
- query2 ? query2 : void 0
11158
- ],
11159
- detail: (id, query2) => [
11160
- PROMOTION_QUERY_KEY,
11178
+ const SalesChannel = () => {
11179
+ const { id } = reactRouterDom.useParams();
11180
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11161
11181
  id,
11162
- query2 ? query2 : void 0
11163
- ]
11182
+ {
11183
+ fields: "+sales_channel_id"
11184
+ },
11185
+ {
11186
+ enabled: !!id
11187
+ }
11188
+ );
11189
+ if (isError) {
11190
+ throw error;
11191
+ }
11192
+ const ISrEADY = !!draft_order && !isPending;
11193
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11194
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11195
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11196
+ /* @__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" }) })
11197
+ ] }),
11198
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11199
+ ] });
11164
11200
  };
11165
- const usePromotions = (query2, options) => {
11166
- const { data, ...rest } = reactQuery.useQuery({
11167
- queryKey: promotionsQueryKeys.list(query2),
11168
- queryFn: async () => sdk.admin.promotion.list(query2),
11169
- ...options
11201
+ const SalesChannelForm = ({ order }) => {
11202
+ const form = reactHookForm.useForm({
11203
+ defaultValues: {
11204
+ sales_channel_id: order.sales_channel_id || ""
11205
+ },
11206
+ resolver: zod.zodResolver(schema$2)
11170
11207
  });
11171
- return { ...data, ...rest };
11208
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11209
+ const { handleSuccess } = useRouteModal();
11210
+ const onSubmit = form.handleSubmit(async (data) => {
11211
+ await mutateAsync(
11212
+ {
11213
+ sales_channel_id: data.sales_channel_id
11214
+ },
11215
+ {
11216
+ onSuccess: () => {
11217
+ ui.toast.success("Sales channel updated");
11218
+ handleSuccess();
11219
+ },
11220
+ onError: (error) => {
11221
+ ui.toast.error(error.message);
11222
+ }
11223
+ }
11224
+ );
11225
+ });
11226
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11227
+ KeyboundForm,
11228
+ {
11229
+ className: "flex flex-1 flex-col overflow-hidden",
11230
+ onSubmit,
11231
+ children: [
11232
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11233
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11234
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11235
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11236
+ ] }) })
11237
+ ]
11238
+ }
11239
+ ) });
11172
11240
  };
11173
- const Promotions = () => {
11241
+ const SalesChannelField = ({ control, order }) => {
11242
+ const salesChannels = useComboboxData({
11243
+ queryFn: async (params) => {
11244
+ return await sdk.admin.salesChannel.list(params);
11245
+ },
11246
+ queryKey: ["sales-channels"],
11247
+ getOptions: (data) => {
11248
+ return data.sales_channels.map((salesChannel) => ({
11249
+ label: salesChannel.name,
11250
+ value: salesChannel.id
11251
+ }));
11252
+ },
11253
+ defaultValue: order.sales_channel_id || void 0
11254
+ });
11255
+ return /* @__PURE__ */ jsxRuntime.jsx(
11256
+ Form$2.Field,
11257
+ {
11258
+ control,
11259
+ name: "sales_channel_id",
11260
+ render: ({ field }) => {
11261
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11262
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11263
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11264
+ Combobox,
11265
+ {
11266
+ options: salesChannels.options,
11267
+ fetchNextPage: salesChannels.fetchNextPage,
11268
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11269
+ searchValue: salesChannels.searchValue,
11270
+ onSearchValueChange: salesChannels.onSearchValueChange,
11271
+ placeholder: "Select sales channel",
11272
+ ...field
11273
+ }
11274
+ ) }),
11275
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11276
+ ] });
11277
+ }
11278
+ }
11279
+ );
11280
+ };
11281
+ const schema$2 = objectType({
11282
+ sales_channel_id: stringType().min(1)
11283
+ });
11284
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11285
+ const Shipping = () => {
11286
+ var _a;
11174
11287
  const { id } = reactRouterDom.useParams();
11288
+ const { order, isPending, isError, error } = useOrder(id, {
11289
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11290
+ });
11175
11291
  const {
11176
11292
  order: preview,
11293
+ isPending: isPreviewPending,
11177
11294
  isError: isPreviewError,
11178
11295
  error: previewError
11179
- } = useOrderPreview(id, void 0);
11296
+ } = useOrderPreview(id);
11180
11297
  useInitiateOrderEdit({ preview });
11181
11298
  const { onCancel } = useCancelOrderEdit({ preview });
11299
+ if (isError) {
11300
+ throw error;
11301
+ }
11182
11302
  if (isPreviewError) {
11183
11303
  throw previewError;
11184
11304
  }
11185
- const isReady = !!preview;
11186
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11187
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11188
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11189
- ] });
11305
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11306
+ const isReady = preview && !isPreviewPending && order && !isPending;
11307
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11308
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11309
+ /* @__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 px-6 py-16", children: [
11310
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11311
+ /* @__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." }) })
11312
+ ] }) }) }),
11313
+ /* @__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" }) }) })
11314
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11315
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11316
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11317
+ ] }) });
11190
11318
  };
11191
- const PromotionForm = ({ preview }) => {
11192
- const { items, shipping_methods } = preview;
11319
+ const ShippingForm = ({ preview, order }) => {
11320
+ var _a;
11321
+ const { setIsOpen } = useStackedModal();
11193
11322
  const [isSubmitting, setIsSubmitting] = React.useState(false);
11194
- const [comboboxValue, setComboboxValue] = React.useState("");
11195
- const { handleSuccess } = useRouteModal();
11196
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11197
- const promoIds = getPromotionIds(items, shipping_methods);
11198
- const { promotions, isPending, isError, error } = usePromotions(
11323
+ const [data, setData] = React.useState(null);
11324
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11325
+ const { shipping_options } = useShippingOptions(
11199
11326
  {
11200
- id: promoIds
11327
+ id: appliedShippingOptionIds,
11328
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11201
11329
  },
11202
11330
  {
11203
- enabled: !!promoIds.length
11331
+ enabled: appliedShippingOptionIds.length > 0
11204
11332
  }
11205
11333
  );
11206
- const comboboxData = useComboboxData({
11207
- queryKey: ["promotions", "combobox", promoIds],
11208
- queryFn: async (params) => {
11209
- return await sdk.admin.promotion.list({
11210
- ...params,
11211
- id: {
11212
- $nin: promoIds
11213
- }
11214
- });
11215
- },
11216
- getOptions: (data) => {
11217
- return data.promotions.map((promotion) => ({
11218
- label: promotion.code,
11219
- value: promotion.code
11220
- }));
11221
- }
11222
- });
11223
- const add = async (value) => {
11224
- if (!value) {
11225
- return;
11226
- }
11227
- addPromotions(
11228
- {
11229
- promo_codes: [value]
11230
- },
11231
- {
11232
- onError: (e) => {
11233
- ui.toast.error(e.message);
11234
- comboboxData.onSearchValueChange("");
11235
- setComboboxValue("");
11236
- },
11237
- onSuccess: () => {
11238
- comboboxData.onSearchValueChange("");
11239
- setComboboxValue("");
11240
- }
11241
- }
11242
- );
11243
- };
11334
+ const uniqueShippingProfiles = React.useMemo(() => {
11335
+ const profiles = /* @__PURE__ */ new Map();
11336
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11337
+ profiles.set(profile.id, profile);
11338
+ });
11339
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11340
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11341
+ });
11342
+ return Array.from(profiles.values());
11343
+ }, [order.items, shipping_options]);
11344
+ const { handleSuccess } = useRouteModal();
11244
11345
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11245
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11346
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11347
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11348
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11246
11349
  const onSubmit = async () => {
11247
11350
  setIsSubmitting(true);
11248
11351
  let requestSucceeded = false;
11249
11352
  await requestOrderEdit(void 0, {
11250
11353
  onError: (e) => {
11251
- ui.toast.error(e.message);
11354
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11252
11355
  },
11253
11356
  onSuccess: () => {
11254
11357
  requestSucceeded = true;
@@ -11260,383 +11363,7 @@ const PromotionForm = ({ preview }) => {
11260
11363
  }
11261
11364
  await confirmOrderEdit(void 0, {
11262
11365
  onError: (e) => {
11263
- ui.toast.error(e.message);
11264
- },
11265
- onSuccess: () => {
11266
- handleSuccess();
11267
- },
11268
- onSettled: () => {
11269
- setIsSubmitting(false);
11270
- }
11271
- });
11272
- };
11273
- if (isError) {
11274
- throw error;
11275
- }
11276
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11277
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11278
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11279
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11280
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11281
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11282
- ] }),
11283
- /* @__PURE__ */ jsxRuntime.jsx(
11284
- Combobox,
11285
- {
11286
- id: "promotion-combobox",
11287
- "aria-describedby": "promotion-combobox-hint",
11288
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11289
- fetchNextPage: comboboxData.fetchNextPage,
11290
- options: comboboxData.options,
11291
- onSearchValueChange: comboboxData.onSearchValueChange,
11292
- searchValue: comboboxData.searchValue,
11293
- disabled: comboboxData.disabled || isAddingPromotions,
11294
- onChange: add,
11295
- value: comboboxValue
11296
- }
11297
- )
11298
- ] }),
11299
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11300
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11301
- PromotionItem,
11302
- {
11303
- promotion,
11304
- orderId: preview.id,
11305
- isLoading: isPending
11306
- },
11307
- promotion.id
11308
- )) })
11309
- ] }) }),
11310
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11311
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11312
- /* @__PURE__ */ jsxRuntime.jsx(
11313
- ui.Button,
11314
- {
11315
- size: "small",
11316
- type: "submit",
11317
- isLoading: isSubmitting || isAddingPromotions,
11318
- children: "Save"
11319
- }
11320
- )
11321
- ] }) })
11322
- ] });
11323
- };
11324
- const PromotionItem = ({
11325
- promotion,
11326
- orderId,
11327
- isLoading
11328
- }) => {
11329
- var _a;
11330
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11331
- const onRemove = async () => {
11332
- removePromotions(
11333
- {
11334
- promo_codes: [promotion.code]
11335
- },
11336
- {
11337
- onError: (e) => {
11338
- ui.toast.error(e.message);
11339
- }
11340
- }
11341
- );
11342
- };
11343
- const displayValue = getDisplayValue(promotion);
11344
- return /* @__PURE__ */ jsxRuntime.jsxs(
11345
- "div",
11346
- {
11347
- className: ui.clx(
11348
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11349
- {
11350
- "animate-pulse": isLoading
11351
- }
11352
- ),
11353
- children: [
11354
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11355
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11356
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11357
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11358
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11359
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11360
- ] }),
11361
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11362
- ] })
11363
- ] }),
11364
- /* @__PURE__ */ jsxRuntime.jsx(
11365
- ui.IconButton,
11366
- {
11367
- size: "small",
11368
- type: "button",
11369
- variant: "transparent",
11370
- onClick: onRemove,
11371
- isLoading: isPending || isLoading,
11372
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11373
- }
11374
- )
11375
- ]
11376
- },
11377
- promotion.id
11378
- );
11379
- };
11380
- function getDisplayValue(promotion) {
11381
- var _a, _b, _c, _d;
11382
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11383
- if (!value) {
11384
- return null;
11385
- }
11386
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11387
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11388
- if (!currency) {
11389
- return null;
11390
- }
11391
- return getLocaleAmount(value, currency);
11392
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11393
- return formatPercentage(value);
11394
- }
11395
- return null;
11396
- }
11397
- const formatter = new Intl.NumberFormat([], {
11398
- style: "percent",
11399
- minimumFractionDigits: 2
11400
- });
11401
- const formatPercentage = (value, isPercentageValue = false) => {
11402
- let val = value || 0;
11403
- if (!isPercentageValue) {
11404
- val = val / 100;
11405
- }
11406
- return formatter.format(val);
11407
- };
11408
- function getPromotionIds(items, shippingMethods) {
11409
- const promotionIds = /* @__PURE__ */ new Set();
11410
- for (const item of items) {
11411
- if (item.adjustments) {
11412
- for (const adjustment of item.adjustments) {
11413
- if (adjustment.promotion_id) {
11414
- promotionIds.add(adjustment.promotion_id);
11415
- }
11416
- }
11417
- }
11418
- }
11419
- for (const shippingMethod of shippingMethods) {
11420
- if (shippingMethod.adjustments) {
11421
- for (const adjustment of shippingMethod.adjustments) {
11422
- if (adjustment.promotion_id) {
11423
- promotionIds.add(adjustment.promotion_id);
11424
- }
11425
- }
11426
- }
11427
- }
11428
- return Array.from(promotionIds);
11429
- }
11430
- const CustomItems = () => {
11431
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11432
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
11433
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
11434
- ] });
11435
- };
11436
- const CustomItemsForm = () => {
11437
- const form = reactHookForm.useForm({
11438
- resolver: zod.zodResolver(schema$3)
11439
- });
11440
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11441
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
11442
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11443
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11444
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
11445
- ] }) })
11446
- ] }) });
11447
- };
11448
- const schema$3 = objectType({
11449
- email: stringType().email()
11450
- });
11451
- const SalesChannel = () => {
11452
- const { id } = reactRouterDom.useParams();
11453
- const { draft_order, isPending, isError, error } = useDraftOrder(
11454
- id,
11455
- {
11456
- fields: "+sales_channel_id"
11457
- },
11458
- {
11459
- enabled: !!id
11460
- }
11461
- );
11462
- if (isError) {
11463
- throw error;
11464
- }
11465
- const ISrEADY = !!draft_order && !isPending;
11466
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11467
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11468
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11469
- /* @__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" }) })
11470
- ] }),
11471
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11472
- ] });
11473
- };
11474
- const SalesChannelForm = ({ order }) => {
11475
- const form = reactHookForm.useForm({
11476
- defaultValues: {
11477
- sales_channel_id: order.sales_channel_id || ""
11478
- },
11479
- resolver: zod.zodResolver(schema$2)
11480
- });
11481
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11482
- const { handleSuccess } = useRouteModal();
11483
- const onSubmit = form.handleSubmit(async (data) => {
11484
- await mutateAsync(
11485
- {
11486
- sales_channel_id: data.sales_channel_id
11487
- },
11488
- {
11489
- onSuccess: () => {
11490
- ui.toast.success("Sales channel updated");
11491
- handleSuccess();
11492
- },
11493
- onError: (error) => {
11494
- ui.toast.error(error.message);
11495
- }
11496
- }
11497
- );
11498
- });
11499
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11500
- KeyboundForm,
11501
- {
11502
- className: "flex flex-1 flex-col overflow-hidden",
11503
- onSubmit,
11504
- children: [
11505
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11506
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11507
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11508
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11509
- ] }) })
11510
- ]
11511
- }
11512
- ) });
11513
- };
11514
- const SalesChannelField = ({ control, order }) => {
11515
- const salesChannels = useComboboxData({
11516
- queryFn: async (params) => {
11517
- return await sdk.admin.salesChannel.list(params);
11518
- },
11519
- queryKey: ["sales-channels"],
11520
- getOptions: (data) => {
11521
- return data.sales_channels.map((salesChannel) => ({
11522
- label: salesChannel.name,
11523
- value: salesChannel.id
11524
- }));
11525
- },
11526
- defaultValue: order.sales_channel_id || void 0
11527
- });
11528
- return /* @__PURE__ */ jsxRuntime.jsx(
11529
- Form$2.Field,
11530
- {
11531
- control,
11532
- name: "sales_channel_id",
11533
- render: ({ field }) => {
11534
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11535
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11536
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11537
- Combobox,
11538
- {
11539
- options: salesChannels.options,
11540
- fetchNextPage: salesChannels.fetchNextPage,
11541
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11542
- searchValue: salesChannels.searchValue,
11543
- onSearchValueChange: salesChannels.onSearchValueChange,
11544
- placeholder: "Select sales channel",
11545
- ...field
11546
- }
11547
- ) }),
11548
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11549
- ] });
11550
- }
11551
- }
11552
- );
11553
- };
11554
- const schema$2 = objectType({
11555
- sales_channel_id: stringType().min(1)
11556
- });
11557
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11558
- const Shipping = () => {
11559
- var _a;
11560
- const { id } = reactRouterDom.useParams();
11561
- const { order, isPending, isError, error } = useOrder(id, {
11562
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11563
- });
11564
- const {
11565
- order: preview,
11566
- isPending: isPreviewPending,
11567
- isError: isPreviewError,
11568
- error: previewError
11569
- } = useOrderPreview(id);
11570
- useInitiateOrderEdit({ preview });
11571
- const { onCancel } = useCancelOrderEdit({ preview });
11572
- if (isError) {
11573
- throw error;
11574
- }
11575
- if (isPreviewError) {
11576
- throw previewError;
11577
- }
11578
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11579
- const isReady = preview && !isPreviewPending && order && !isPending;
11580
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11581
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11582
- /* @__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 px-6 py-16", children: [
11583
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11584
- /* @__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." }) })
11585
- ] }) }) }),
11586
- /* @__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" }) }) })
11587
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11588
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11589
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11590
- ] }) });
11591
- };
11592
- const ShippingForm = ({ preview, order }) => {
11593
- var _a;
11594
- const { setIsOpen } = useStackedModal();
11595
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11596
- const [data, setData] = React.useState(null);
11597
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11598
- const { shipping_options } = useShippingOptions(
11599
- {
11600
- id: appliedShippingOptionIds,
11601
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11602
- },
11603
- {
11604
- enabled: appliedShippingOptionIds.length > 0
11605
- }
11606
- );
11607
- const uniqueShippingProfiles = React.useMemo(() => {
11608
- const profiles = /* @__PURE__ */ new Map();
11609
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11610
- profiles.set(profile.id, profile);
11611
- });
11612
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11613
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11614
- });
11615
- return Array.from(profiles.values());
11616
- }, [order.items, shipping_options]);
11617
- const { handleSuccess } = useRouteModal();
11618
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11619
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11620
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11621
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11622
- const onSubmit = async () => {
11623
- setIsSubmitting(true);
11624
- let requestSucceeded = false;
11625
- await requestOrderEdit(void 0, {
11626
- onError: (e) => {
11627
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11628
- },
11629
- onSuccess: () => {
11630
- requestSucceeded = true;
11631
- }
11632
- });
11633
- if (!requestSucceeded) {
11634
- setIsSubmitting(false);
11635
- return;
11636
- }
11637
- await confirmOrderEdit(void 0, {
11638
- onError: (e) => {
11639
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11366
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11640
11367
  },
11641
11368
  onSuccess: () => {
11642
11369
  handleSuccess();
@@ -12347,20 +12074,223 @@ const CustomAmountField = ({
12347
12074
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12348
12075
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12349
12076
  ] }),
12350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12351
- ui.CurrencyInput,
12077
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12078
+ ui.CurrencyInput,
12079
+ {
12080
+ ...field,
12081
+ onValueChange: (value) => onChange(value),
12082
+ symbol: getNativeSymbol(currencyCode),
12083
+ code: currencyCode
12084
+ }
12085
+ ) })
12086
+ ] });
12087
+ }
12088
+ }
12089
+ );
12090
+ };
12091
+ const ShippingAddress = () => {
12092
+ const { id } = reactRouterDom.useParams();
12093
+ const { order, isPending, isError, error } = useOrder(id, {
12094
+ fields: "+shipping_address"
12095
+ });
12096
+ if (isError) {
12097
+ throw error;
12098
+ }
12099
+ const isReady = !isPending && !!order;
12100
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12101
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12102
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12103
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12104
+ ] }),
12105
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12106
+ ] });
12107
+ };
12108
+ const ShippingAddressForm = ({ order }) => {
12109
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12110
+ const form = reactHookForm.useForm({
12111
+ defaultValues: {
12112
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12113
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12114
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12115
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12116
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12117
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12118
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12119
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12120
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12121
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12122
+ },
12123
+ resolver: zod.zodResolver(schema$1)
12124
+ });
12125
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12126
+ const { handleSuccess } = useRouteModal();
12127
+ const onSubmit = form.handleSubmit(async (data) => {
12128
+ await mutateAsync(
12129
+ {
12130
+ shipping_address: {
12131
+ first_name: data.first_name,
12132
+ last_name: data.last_name,
12133
+ company: data.company,
12134
+ address_1: data.address_1,
12135
+ address_2: data.address_2,
12136
+ city: data.city,
12137
+ province: data.province,
12138
+ country_code: data.country_code,
12139
+ postal_code: data.postal_code,
12140
+ phone: data.phone
12141
+ }
12142
+ },
12143
+ {
12144
+ onSuccess: () => {
12145
+ handleSuccess();
12146
+ },
12147
+ onError: (error) => {
12148
+ ui.toast.error(error.message);
12149
+ }
12150
+ }
12151
+ );
12152
+ });
12153
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12154
+ KeyboundForm,
12155
+ {
12156
+ className: "flex flex-1 flex-col overflow-hidden",
12157
+ onSubmit,
12158
+ children: [
12159
+ /* @__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: [
12160
+ /* @__PURE__ */ jsxRuntime.jsx(
12161
+ Form$2.Field,
12162
+ {
12163
+ control: form.control,
12164
+ name: "country_code",
12165
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12166
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12167
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12168
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12169
+ ] })
12170
+ }
12171
+ ),
12172
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12173
+ /* @__PURE__ */ jsxRuntime.jsx(
12174
+ Form$2.Field,
12175
+ {
12176
+ control: form.control,
12177
+ name: "first_name",
12178
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12179
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12180
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12181
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12182
+ ] })
12183
+ }
12184
+ ),
12185
+ /* @__PURE__ */ jsxRuntime.jsx(
12186
+ Form$2.Field,
12187
+ {
12188
+ control: form.control,
12189
+ name: "last_name",
12190
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12191
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12192
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12193
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12194
+ ] })
12195
+ }
12196
+ )
12197
+ ] }),
12198
+ /* @__PURE__ */ jsxRuntime.jsx(
12199
+ Form$2.Field,
12200
+ {
12201
+ control: form.control,
12202
+ name: "company",
12203
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12204
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12205
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12206
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12207
+ ] })
12208
+ }
12209
+ ),
12210
+ /* @__PURE__ */ jsxRuntime.jsx(
12211
+ Form$2.Field,
12212
+ {
12213
+ control: form.control,
12214
+ name: "address_1",
12215
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12216
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12217
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12218
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12219
+ ] })
12220
+ }
12221
+ ),
12222
+ /* @__PURE__ */ jsxRuntime.jsx(
12223
+ Form$2.Field,
12224
+ {
12225
+ control: form.control,
12226
+ name: "address_2",
12227
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12228
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12229
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12230
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12231
+ ] })
12232
+ }
12233
+ ),
12234
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12235
+ /* @__PURE__ */ jsxRuntime.jsx(
12236
+ Form$2.Field,
12237
+ {
12238
+ control: form.control,
12239
+ name: "postal_code",
12240
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12241
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12242
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12243
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12244
+ ] })
12245
+ }
12246
+ ),
12247
+ /* @__PURE__ */ jsxRuntime.jsx(
12248
+ Form$2.Field,
12249
+ {
12250
+ control: form.control,
12251
+ name: "city",
12252
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12253
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12254
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12255
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12256
+ ] })
12257
+ }
12258
+ )
12259
+ ] }),
12260
+ /* @__PURE__ */ jsxRuntime.jsx(
12261
+ Form$2.Field,
12352
12262
  {
12353
- ...field,
12354
- onValueChange: (value) => onChange(value),
12355
- symbol: getNativeSymbol(currencyCode),
12356
- code: currencyCode
12263
+ control: form.control,
12264
+ name: "province",
12265
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12266
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12267
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12268
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12269
+ ] })
12357
12270
  }
12358
- ) })
12359
- ] });
12360
- }
12271
+ ),
12272
+ /* @__PURE__ */ jsxRuntime.jsx(
12273
+ Form$2.Field,
12274
+ {
12275
+ control: form.control,
12276
+ name: "phone",
12277
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12278
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12279
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12280
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12281
+ ] })
12282
+ }
12283
+ )
12284
+ ] }) }),
12285
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12286
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12287
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12288
+ ] }) })
12289
+ ]
12361
12290
  }
12362
- );
12291
+ ) });
12363
12292
  };
12293
+ const schema$1 = addressSchema;
12364
12294
  const TransferOwnership = () => {
12365
12295
  const { id } = reactRouterDom.useParams();
12366
12296
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12384,7 +12314,7 @@ const TransferOwnershipForm = ({ order }) => {
12384
12314
  defaultValues: {
12385
12315
  customer_id: order.customer_id || ""
12386
12316
  },
12387
- resolver: zod.zodResolver(schema$1)
12317
+ resolver: zod.zodResolver(schema)
12388
12318
  });
12389
12319
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12390
12320
  const { handleSuccess } = useRouteModal();
@@ -12834,212 +12764,286 @@ const Illustration = () => {
12834
12764
  }
12835
12765
  );
12836
12766
  };
12837
- const schema$1 = objectType({
12767
+ const schema = objectType({
12838
12768
  customer_id: stringType().min(1)
12839
12769
  });
12840
- const ShippingAddress = () => {
12841
- const { id } = reactRouterDom.useParams();
12842
- const { order, isPending, isError, error } = useOrder(id, {
12843
- fields: "+shipping_address"
12770
+ const PROMOTION_QUERY_KEY = "promotions";
12771
+ const promotionsQueryKeys = {
12772
+ list: (query2) => [
12773
+ PROMOTION_QUERY_KEY,
12774
+ query2 ? query2 : void 0
12775
+ ],
12776
+ detail: (id, query2) => [
12777
+ PROMOTION_QUERY_KEY,
12778
+ id,
12779
+ query2 ? query2 : void 0
12780
+ ]
12781
+ };
12782
+ const usePromotions = (query2, options) => {
12783
+ const { data, ...rest } = reactQuery.useQuery({
12784
+ queryKey: promotionsQueryKeys.list(query2),
12785
+ queryFn: async () => sdk.admin.promotion.list(query2),
12786
+ ...options
12844
12787
  });
12845
- if (isError) {
12846
- throw error;
12788
+ return { ...data, ...rest };
12789
+ };
12790
+ const Promotions = () => {
12791
+ const { id } = reactRouterDom.useParams();
12792
+ const {
12793
+ order: preview,
12794
+ isError: isPreviewError,
12795
+ error: previewError
12796
+ } = useOrderPreview(id, void 0);
12797
+ useInitiateOrderEdit({ preview });
12798
+ const { onCancel } = useCancelOrderEdit({ preview });
12799
+ if (isPreviewError) {
12800
+ throw previewError;
12847
12801
  }
12848
- const isReady = !isPending && !!order;
12849
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12850
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12851
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12852
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12853
- ] }),
12854
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12802
+ const isReady = !!preview;
12803
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12804
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12805
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12855
12806
  ] });
12856
12807
  };
12857
- const ShippingAddressForm = ({ order }) => {
12858
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12859
- const form = reactHookForm.useForm({
12860
- defaultValues: {
12861
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12862
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12863
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12864
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12865
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12866
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12867
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12868
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12869
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12870
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12808
+ const PromotionForm = ({ preview }) => {
12809
+ const { items, shipping_methods } = preview;
12810
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12811
+ const [comboboxValue, setComboboxValue] = React.useState("");
12812
+ const { handleSuccess } = useRouteModal();
12813
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12814
+ const promoIds = getPromotionIds(items, shipping_methods);
12815
+ const { promotions, isPending, isError, error } = usePromotions(
12816
+ {
12817
+ id: promoIds
12871
12818
  },
12872
- resolver: zod.zodResolver(schema)
12819
+ {
12820
+ enabled: !!promoIds.length
12821
+ }
12822
+ );
12823
+ const comboboxData = useComboboxData({
12824
+ queryKey: ["promotions", "combobox", promoIds],
12825
+ queryFn: async (params) => {
12826
+ return await sdk.admin.promotion.list({
12827
+ ...params,
12828
+ id: {
12829
+ $nin: promoIds
12830
+ }
12831
+ });
12832
+ },
12833
+ getOptions: (data) => {
12834
+ return data.promotions.map((promotion) => ({
12835
+ label: promotion.code,
12836
+ value: promotion.code
12837
+ }));
12838
+ }
12873
12839
  });
12874
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12875
- const { handleSuccess } = useRouteModal();
12876
- const onSubmit = form.handleSubmit(async (data) => {
12877
- await mutateAsync(
12840
+ const add = async (value) => {
12841
+ if (!value) {
12842
+ return;
12843
+ }
12844
+ addPromotions(
12878
12845
  {
12879
- shipping_address: {
12880
- first_name: data.first_name,
12881
- last_name: data.last_name,
12882
- company: data.company,
12883
- address_1: data.address_1,
12884
- address_2: data.address_2,
12885
- city: data.city,
12886
- province: data.province,
12887
- country_code: data.country_code,
12888
- postal_code: data.postal_code,
12889
- phone: data.phone
12846
+ promo_codes: [value]
12847
+ },
12848
+ {
12849
+ onError: (e) => {
12850
+ ui.toast.error(e.message);
12851
+ comboboxData.onSearchValueChange("");
12852
+ setComboboxValue("");
12853
+ },
12854
+ onSuccess: () => {
12855
+ comboboxData.onSearchValueChange("");
12856
+ setComboboxValue("");
12857
+ }
12858
+ }
12859
+ );
12860
+ };
12861
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12862
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12863
+ const onSubmit = async () => {
12864
+ setIsSubmitting(true);
12865
+ let requestSucceeded = false;
12866
+ await requestOrderEdit(void 0, {
12867
+ onError: (e) => {
12868
+ ui.toast.error(e.message);
12869
+ },
12870
+ onSuccess: () => {
12871
+ requestSucceeded = true;
12872
+ }
12873
+ });
12874
+ if (!requestSucceeded) {
12875
+ setIsSubmitting(false);
12876
+ return;
12877
+ }
12878
+ await confirmOrderEdit(void 0, {
12879
+ onError: (e) => {
12880
+ ui.toast.error(e.message);
12881
+ },
12882
+ onSuccess: () => {
12883
+ handleSuccess();
12884
+ },
12885
+ onSettled: () => {
12886
+ setIsSubmitting(false);
12887
+ }
12888
+ });
12889
+ };
12890
+ if (isError) {
12891
+ throw error;
12892
+ }
12893
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12894
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12895
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12896
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12897
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12898
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12899
+ ] }),
12900
+ /* @__PURE__ */ jsxRuntime.jsx(
12901
+ Combobox,
12902
+ {
12903
+ id: "promotion-combobox",
12904
+ "aria-describedby": "promotion-combobox-hint",
12905
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12906
+ fetchNextPage: comboboxData.fetchNextPage,
12907
+ options: comboboxData.options,
12908
+ onSearchValueChange: comboboxData.onSearchValueChange,
12909
+ searchValue: comboboxData.searchValue,
12910
+ disabled: comboboxData.disabled || isAddingPromotions,
12911
+ onChange: add,
12912
+ value: comboboxValue
12913
+ }
12914
+ )
12915
+ ] }),
12916
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12917
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12918
+ PromotionItem,
12919
+ {
12920
+ promotion,
12921
+ orderId: preview.id,
12922
+ isLoading: isPending
12923
+ },
12924
+ promotion.id
12925
+ )) })
12926
+ ] }) }),
12927
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12928
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12929
+ /* @__PURE__ */ jsxRuntime.jsx(
12930
+ ui.Button,
12931
+ {
12932
+ size: "small",
12933
+ type: "submit",
12934
+ isLoading: isSubmitting || isAddingPromotions,
12935
+ children: "Save"
12890
12936
  }
12937
+ )
12938
+ ] }) })
12939
+ ] });
12940
+ };
12941
+ const PromotionItem = ({
12942
+ promotion,
12943
+ orderId,
12944
+ isLoading
12945
+ }) => {
12946
+ var _a;
12947
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12948
+ const onRemove = async () => {
12949
+ removePromotions(
12950
+ {
12951
+ promo_codes: [promotion.code]
12891
12952
  },
12892
12953
  {
12893
- onSuccess: () => {
12894
- handleSuccess();
12895
- },
12896
- onError: (error) => {
12897
- ui.toast.error(error.message);
12954
+ onError: (e) => {
12955
+ ui.toast.error(e.message);
12898
12956
  }
12899
12957
  }
12900
12958
  );
12901
- });
12902
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12903
- KeyboundForm,
12959
+ };
12960
+ const displayValue = getDisplayValue(promotion);
12961
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12962
+ "div",
12904
12963
  {
12905
- className: "flex flex-1 flex-col overflow-hidden",
12906
- onSubmit,
12964
+ className: ui.clx(
12965
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12966
+ {
12967
+ "animate-pulse": isLoading
12968
+ }
12969
+ ),
12907
12970
  children: [
12908
- /* @__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: [
12909
- /* @__PURE__ */ jsxRuntime.jsx(
12910
- Form$2.Field,
12911
- {
12912
- control: form.control,
12913
- name: "country_code",
12914
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12915
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12916
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12917
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12918
- ] })
12919
- }
12920
- ),
12921
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12922
- /* @__PURE__ */ jsxRuntime.jsx(
12923
- Form$2.Field,
12924
- {
12925
- control: form.control,
12926
- name: "first_name",
12927
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12928
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12929
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12930
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12931
- ] })
12932
- }
12933
- ),
12934
- /* @__PURE__ */ jsxRuntime.jsx(
12935
- Form$2.Field,
12936
- {
12937
- control: form.control,
12938
- name: "last_name",
12939
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12940
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12941
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12942
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12943
- ] })
12944
- }
12945
- )
12946
- ] }),
12947
- /* @__PURE__ */ jsxRuntime.jsx(
12948
- Form$2.Field,
12949
- {
12950
- control: form.control,
12951
- name: "company",
12952
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12953
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12954
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12955
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12956
- ] })
12957
- }
12958
- ),
12959
- /* @__PURE__ */ jsxRuntime.jsx(
12960
- Form$2.Field,
12961
- {
12962
- control: form.control,
12963
- name: "address_1",
12964
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12965
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12966
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12967
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12968
- ] })
12969
- }
12970
- ),
12971
- /* @__PURE__ */ jsxRuntime.jsx(
12972
- Form$2.Field,
12973
- {
12974
- control: form.control,
12975
- name: "address_2",
12976
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12977
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12978
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12979
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12980
- ] })
12981
- }
12982
- ),
12983
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12984
- /* @__PURE__ */ jsxRuntime.jsx(
12985
- Form$2.Field,
12986
- {
12987
- control: form.control,
12988
- name: "postal_code",
12989
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12990
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12991
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12992
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12993
- ] })
12994
- }
12995
- ),
12996
- /* @__PURE__ */ jsxRuntime.jsx(
12997
- Form$2.Field,
12998
- {
12999
- control: form.control,
13000
- name: "city",
13001
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13002
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13003
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13004
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13005
- ] })
13006
- }
13007
- )
13008
- ] }),
13009
- /* @__PURE__ */ jsxRuntime.jsx(
13010
- Form$2.Field,
13011
- {
13012
- control: form.control,
13013
- name: "province",
13014
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13015
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13016
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13017
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13018
- ] })
13019
- }
13020
- ),
13021
- /* @__PURE__ */ jsxRuntime.jsx(
13022
- Form$2.Field,
13023
- {
13024
- control: form.control,
13025
- name: "phone",
13026
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13028
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13029
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13030
- ] })
13031
- }
13032
- )
13033
- ] }) }),
13034
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13035
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13036
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13037
- ] }) })
12971
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12972
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12973
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12974
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12975
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12976
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12977
+ ] }),
12978
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12979
+ ] })
12980
+ ] }),
12981
+ /* @__PURE__ */ jsxRuntime.jsx(
12982
+ ui.IconButton,
12983
+ {
12984
+ size: "small",
12985
+ type: "button",
12986
+ variant: "transparent",
12987
+ onClick: onRemove,
12988
+ isLoading: isPending || isLoading,
12989
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12990
+ }
12991
+ )
13038
12992
  ]
12993
+ },
12994
+ promotion.id
12995
+ );
12996
+ };
12997
+ function getDisplayValue(promotion) {
12998
+ var _a, _b, _c, _d;
12999
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
13000
+ if (!value) {
13001
+ return null;
13002
+ }
13003
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
13004
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13005
+ if (!currency) {
13006
+ return null;
13039
13007
  }
13040
- ) });
13008
+ return getLocaleAmount(value, currency);
13009
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13010
+ return formatPercentage(value);
13011
+ }
13012
+ return null;
13013
+ }
13014
+ const formatter = new Intl.NumberFormat([], {
13015
+ style: "percent",
13016
+ minimumFractionDigits: 2
13017
+ });
13018
+ const formatPercentage = (value, isPercentageValue = false) => {
13019
+ let val = value || 0;
13020
+ if (!isPercentageValue) {
13021
+ val = val / 100;
13022
+ }
13023
+ return formatter.format(val);
13041
13024
  };
13042
- const schema = addressSchema;
13025
+ function getPromotionIds(items, shippingMethods) {
13026
+ const promotionIds = /* @__PURE__ */ new Set();
13027
+ for (const item of items) {
13028
+ if (item.adjustments) {
13029
+ for (const adjustment of item.adjustments) {
13030
+ if (adjustment.promotion_id) {
13031
+ promotionIds.add(adjustment.promotion_id);
13032
+ }
13033
+ }
13034
+ }
13035
+ }
13036
+ for (const shippingMethod of shippingMethods) {
13037
+ if (shippingMethod.adjustments) {
13038
+ for (const adjustment of shippingMethod.adjustments) {
13039
+ if (adjustment.promotion_id) {
13040
+ promotionIds.add(adjustment.promotion_id);
13041
+ }
13042
+ }
13043
+ }
13044
+ }
13045
+ return Array.from(promotionIds);
13046
+ }
13043
13047
  const widgetModule = { widgets: [] };
13044
13048
  const routeModule = {
13045
13049
  routes: [
@@ -13064,6 +13068,10 @@ const routeModule = {
13064
13068
  Component: BillingAddress,
13065
13069
  path: "/draft-orders/:id/billing-address"
13066
13070
  },
13071
+ {
13072
+ Component: CustomItems,
13073
+ path: "/draft-orders/:id/custom-items"
13074
+ },
13067
13075
  {
13068
13076
  Component: Email,
13069
13077
  path: "/draft-orders/:id/email"
@@ -13076,14 +13084,6 @@ const routeModule = {
13076
13084
  Component: Metadata,
13077
13085
  path: "/draft-orders/:id/metadata"
13078
13086
  },
13079
- {
13080
- Component: Promotions,
13081
- path: "/draft-orders/:id/promotions"
13082
- },
13083
- {
13084
- Component: CustomItems,
13085
- path: "/draft-orders/:id/custom-items"
13086
- },
13087
13087
  {
13088
13088
  Component: SalesChannel,
13089
13089
  path: "/draft-orders/:id/sales-channel"
@@ -13092,13 +13092,17 @@ const routeModule = {
13092
13092
  Component: Shipping,
13093
13093
  path: "/draft-orders/:id/shipping"
13094
13094
  },
13095
+ {
13096
+ Component: ShippingAddress,
13097
+ path: "/draft-orders/:id/shipping-address"
13098
+ },
13095
13099
  {
13096
13100
  Component: TransferOwnership,
13097
13101
  path: "/draft-orders/:id/transfer-ownership"
13098
13102
  },
13099
13103
  {
13100
- Component: ShippingAddress,
13101
- path: "/draft-orders/:id/shipping-address"
13104
+ Component: Promotions,
13105
+ path: "/draft-orders/:id/promotions"
13102
13106
  }
13103
13107
  ]
13104
13108
  }