@medusajs/draft-order 2.11.0-preview-20251021031736 → 2.11.0-preview-20251021060207

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.
@@ -9761,27 +9761,6 @@ const BillingAddressForm = ({ order }) => {
9761
9761
  ) });
9762
9762
  };
9763
9763
  const schema$5 = addressSchema;
9764
- const CustomItems = () => {
9765
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9766
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9767
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9768
- ] });
9769
- };
9770
- const CustomItemsForm = () => {
9771
- const form = reactHookForm.useForm({
9772
- resolver: zod.zodResolver(schema$4)
9773
- });
9774
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9775
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9776
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9778
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9779
- ] }) })
9780
- ] }) });
9781
- };
9782
- const schema$4 = objectType({
9783
- email: stringType().email()
9784
- });
9785
9764
  const Email = () => {
9786
9765
  const { id } = reactRouterDom.useParams();
9787
9766
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9804,7 +9783,7 @@ const EmailForm = ({ order }) => {
9804
9783
  defaultValues: {
9805
9784
  email: order.email ?? ""
9806
9785
  },
9807
- resolver: zod.zodResolver(schema$3)
9786
+ resolver: zod.zodResolver(schema$4)
9808
9787
  });
9809
9788
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9810
9789
  const { handleSuccess } = useRouteModal();
@@ -9847,7 +9826,7 @@ const EmailForm = ({ order }) => {
9847
9826
  }
9848
9827
  ) });
9849
9828
  };
9850
- const schema$3 = objectType({
9829
+ const schema$4 = objectType({
9851
9830
  email: stringType().email()
9852
9831
  });
9853
9832
  const NumberInput = React.forwardRef(
@@ -11174,105 +11153,183 @@ function getHasUneditableRows(metadata) {
11174
11153
  (value) => !EDITABLE_TYPES.includes(typeof value)
11175
11154
  );
11176
11155
  }
11177
- const PROMOTION_QUERY_KEY = "promotions";
11178
- const promotionsQueryKeys = {
11179
- list: (query2) => [
11180
- PROMOTION_QUERY_KEY,
11181
- query2 ? query2 : void 0
11182
- ],
11183
- detail: (id, query2) => [
11184
- PROMOTION_QUERY_KEY,
11156
+ const SalesChannel = () => {
11157
+ const { id } = reactRouterDom.useParams();
11158
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11185
11159
  id,
11186
- query2 ? query2 : void 0
11187
- ]
11160
+ {
11161
+ fields: "+sales_channel_id"
11162
+ },
11163
+ {
11164
+ enabled: !!id
11165
+ }
11166
+ );
11167
+ if (isError) {
11168
+ throw error;
11169
+ }
11170
+ const ISrEADY = !!draft_order && !isPending;
11171
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11172
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11173
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11174
+ /* @__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" }) })
11175
+ ] }),
11176
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11177
+ ] });
11188
11178
  };
11189
- const usePromotions = (query2, options) => {
11190
- const { data, ...rest } = reactQuery.useQuery({
11191
- queryKey: promotionsQueryKeys.list(query2),
11192
- queryFn: async () => sdk.admin.promotion.list(query2),
11193
- ...options
11179
+ const SalesChannelForm = ({ order }) => {
11180
+ const form = reactHookForm.useForm({
11181
+ defaultValues: {
11182
+ sales_channel_id: order.sales_channel_id || ""
11183
+ },
11184
+ resolver: zod.zodResolver(schema$3)
11194
11185
  });
11195
- return { ...data, ...rest };
11186
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11187
+ const { handleSuccess } = useRouteModal();
11188
+ const onSubmit = form.handleSubmit(async (data) => {
11189
+ await mutateAsync(
11190
+ {
11191
+ sales_channel_id: data.sales_channel_id
11192
+ },
11193
+ {
11194
+ onSuccess: () => {
11195
+ ui.toast.success("Sales channel updated");
11196
+ handleSuccess();
11197
+ },
11198
+ onError: (error) => {
11199
+ ui.toast.error(error.message);
11200
+ }
11201
+ }
11202
+ );
11203
+ });
11204
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11205
+ KeyboundForm,
11206
+ {
11207
+ className: "flex flex-1 flex-col overflow-hidden",
11208
+ onSubmit,
11209
+ children: [
11210
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11211
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11212
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11213
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11214
+ ] }) })
11215
+ ]
11216
+ }
11217
+ ) });
11196
11218
  };
11197
- const Promotions = () => {
11219
+ const SalesChannelField = ({ control, order }) => {
11220
+ const salesChannels = useComboboxData({
11221
+ queryFn: async (params) => {
11222
+ return await sdk.admin.salesChannel.list(params);
11223
+ },
11224
+ queryKey: ["sales-channels"],
11225
+ getOptions: (data) => {
11226
+ return data.sales_channels.map((salesChannel) => ({
11227
+ label: salesChannel.name,
11228
+ value: salesChannel.id
11229
+ }));
11230
+ },
11231
+ defaultValue: order.sales_channel_id || void 0
11232
+ });
11233
+ return /* @__PURE__ */ jsxRuntime.jsx(
11234
+ Form$2.Field,
11235
+ {
11236
+ control,
11237
+ name: "sales_channel_id",
11238
+ render: ({ field }) => {
11239
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11240
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11241
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11242
+ Combobox,
11243
+ {
11244
+ options: salesChannels.options,
11245
+ fetchNextPage: salesChannels.fetchNextPage,
11246
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11247
+ searchValue: salesChannels.searchValue,
11248
+ onSearchValueChange: salesChannels.onSearchValueChange,
11249
+ placeholder: "Select sales channel",
11250
+ ...field
11251
+ }
11252
+ ) }),
11253
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11254
+ ] });
11255
+ }
11256
+ }
11257
+ );
11258
+ };
11259
+ const schema$3 = objectType({
11260
+ sales_channel_id: stringType().min(1)
11261
+ });
11262
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11263
+ const Shipping = () => {
11264
+ var _a;
11198
11265
  const { id } = reactRouterDom.useParams();
11266
+ const { order, isPending, isError, error } = useOrder(id, {
11267
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11268
+ });
11199
11269
  const {
11200
11270
  order: preview,
11271
+ isPending: isPreviewPending,
11201
11272
  isError: isPreviewError,
11202
11273
  error: previewError
11203
- } = useOrderPreview(id, void 0);
11274
+ } = useOrderPreview(id);
11204
11275
  useInitiateOrderEdit({ preview });
11205
11276
  const { onCancel } = useCancelOrderEdit({ preview });
11277
+ if (isError) {
11278
+ throw error;
11279
+ }
11206
11280
  if (isPreviewError) {
11207
11281
  throw previewError;
11208
11282
  }
11209
- const isReady = !!preview;
11210
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11211
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11212
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11213
- ] });
11283
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11284
+ const isReady = preview && !isPreviewPending && order && !isPending;
11285
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11286
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11287
+ /* @__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: [
11288
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11289
+ /* @__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." }) })
11290
+ ] }) }) }),
11291
+ /* @__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" }) }) })
11292
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11293
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11294
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11295
+ ] }) });
11214
11296
  };
11215
- const PromotionForm = ({ preview }) => {
11216
- const { items, shipping_methods } = preview;
11297
+ const ShippingForm = ({ preview, order }) => {
11298
+ var _a;
11299
+ const { setIsOpen } = useStackedModal();
11217
11300
  const [isSubmitting, setIsSubmitting] = React.useState(false);
11218
- const [comboboxValue, setComboboxValue] = React.useState("");
11219
- const { handleSuccess } = useRouteModal();
11220
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11221
- const promoIds = getPromotionIds(items, shipping_methods);
11222
- const { promotions, isPending, isError, error } = usePromotions(
11301
+ const [data, setData] = React.useState(null);
11302
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11303
+ const { shipping_options } = useShippingOptions(
11223
11304
  {
11224
- id: promoIds
11305
+ id: appliedShippingOptionIds,
11306
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11225
11307
  },
11226
11308
  {
11227
- enabled: !!promoIds.length
11309
+ enabled: appliedShippingOptionIds.length > 0
11228
11310
  }
11229
11311
  );
11230
- const comboboxData = useComboboxData({
11231
- queryKey: ["promotions", "combobox", promoIds],
11232
- queryFn: async (params) => {
11233
- return await sdk.admin.promotion.list({
11234
- ...params,
11235
- id: {
11236
- $nin: promoIds
11237
- }
11238
- });
11239
- },
11240
- getOptions: (data) => {
11241
- return data.promotions.map((promotion) => ({
11242
- label: promotion.code,
11243
- value: promotion.code
11244
- }));
11245
- }
11246
- });
11247
- const add = async (value) => {
11248
- if (!value) {
11249
- return;
11250
- }
11251
- addPromotions(
11252
- {
11253
- promo_codes: [value]
11254
- },
11255
- {
11256
- onError: (e) => {
11257
- ui.toast.error(e.message);
11258
- comboboxData.onSearchValueChange("");
11259
- setComboboxValue("");
11260
- },
11261
- onSuccess: () => {
11262
- comboboxData.onSearchValueChange("");
11263
- setComboboxValue("");
11264
- }
11265
- }
11266
- );
11267
- };
11312
+ const uniqueShippingProfiles = React.useMemo(() => {
11313
+ const profiles = /* @__PURE__ */ new Map();
11314
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11315
+ profiles.set(profile.id, profile);
11316
+ });
11317
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11318
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11319
+ });
11320
+ return Array.from(profiles.values());
11321
+ }, [order.items, shipping_options]);
11322
+ const { handleSuccess } = useRouteModal();
11268
11323
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11269
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11324
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11325
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11326
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11270
11327
  const onSubmit = async () => {
11271
11328
  setIsSubmitting(true);
11272
11329
  let requestSucceeded = false;
11273
11330
  await requestOrderEdit(void 0, {
11274
11331
  onError: (e) => {
11275
- ui.toast.error(e.message);
11332
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11276
11333
  },
11277
11334
  onSuccess: () => {
11278
11335
  requestSucceeded = true;
@@ -11284,256 +11341,7 @@ const PromotionForm = ({ preview }) => {
11284
11341
  }
11285
11342
  await confirmOrderEdit(void 0, {
11286
11343
  onError: (e) => {
11287
- ui.toast.error(e.message);
11288
- },
11289
- onSuccess: () => {
11290
- handleSuccess();
11291
- },
11292
- onSettled: () => {
11293
- setIsSubmitting(false);
11294
- }
11295
- });
11296
- };
11297
- if (isError) {
11298
- throw error;
11299
- }
11300
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11301
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11302
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11303
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11304
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11305
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11306
- ] }),
11307
- /* @__PURE__ */ jsxRuntime.jsx(
11308
- Combobox,
11309
- {
11310
- id: "promotion-combobox",
11311
- "aria-describedby": "promotion-combobox-hint",
11312
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11313
- fetchNextPage: comboboxData.fetchNextPage,
11314
- options: comboboxData.options,
11315
- onSearchValueChange: comboboxData.onSearchValueChange,
11316
- searchValue: comboboxData.searchValue,
11317
- disabled: comboboxData.disabled || isAddingPromotions,
11318
- onChange: add,
11319
- value: comboboxValue
11320
- }
11321
- )
11322
- ] }),
11323
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11324
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11325
- PromotionItem,
11326
- {
11327
- promotion,
11328
- orderId: preview.id,
11329
- isLoading: isPending
11330
- },
11331
- promotion.id
11332
- )) })
11333
- ] }) }),
11334
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11335
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11336
- /* @__PURE__ */ jsxRuntime.jsx(
11337
- ui.Button,
11338
- {
11339
- size: "small",
11340
- type: "submit",
11341
- isLoading: isSubmitting || isAddingPromotions,
11342
- children: "Save"
11343
- }
11344
- )
11345
- ] }) })
11346
- ] });
11347
- };
11348
- const PromotionItem = ({
11349
- promotion,
11350
- orderId,
11351
- isLoading
11352
- }) => {
11353
- var _a;
11354
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11355
- const onRemove = async () => {
11356
- removePromotions(
11357
- {
11358
- promo_codes: [promotion.code]
11359
- },
11360
- {
11361
- onError: (e) => {
11362
- ui.toast.error(e.message);
11363
- }
11364
- }
11365
- );
11366
- };
11367
- const displayValue = getDisplayValue(promotion);
11368
- return /* @__PURE__ */ jsxRuntime.jsxs(
11369
- "div",
11370
- {
11371
- className: ui.clx(
11372
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11373
- {
11374
- "animate-pulse": isLoading
11375
- }
11376
- ),
11377
- children: [
11378
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11379
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11380
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11381
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11382
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11383
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11384
- ] }),
11385
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11386
- ] })
11387
- ] }),
11388
- /* @__PURE__ */ jsxRuntime.jsx(
11389
- ui.IconButton,
11390
- {
11391
- size: "small",
11392
- type: "button",
11393
- variant: "transparent",
11394
- onClick: onRemove,
11395
- isLoading: isPending || isLoading,
11396
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11397
- }
11398
- )
11399
- ]
11400
- },
11401
- promotion.id
11402
- );
11403
- };
11404
- function getDisplayValue(promotion) {
11405
- var _a, _b, _c, _d;
11406
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11407
- if (!value) {
11408
- return null;
11409
- }
11410
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11411
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11412
- if (!currency) {
11413
- return null;
11414
- }
11415
- return getLocaleAmount(value, currency);
11416
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11417
- return formatPercentage(value);
11418
- }
11419
- return null;
11420
- }
11421
- const formatter = new Intl.NumberFormat([], {
11422
- style: "percent",
11423
- minimumFractionDigits: 2
11424
- });
11425
- const formatPercentage = (value, isPercentageValue = false) => {
11426
- let val = value || 0;
11427
- if (!isPercentageValue) {
11428
- val = val / 100;
11429
- }
11430
- return formatter.format(val);
11431
- };
11432
- function getPromotionIds(items, shippingMethods) {
11433
- const promotionIds = /* @__PURE__ */ new Set();
11434
- for (const item of items) {
11435
- if (item.adjustments) {
11436
- for (const adjustment of item.adjustments) {
11437
- if (adjustment.promotion_id) {
11438
- promotionIds.add(adjustment.promotion_id);
11439
- }
11440
- }
11441
- }
11442
- }
11443
- for (const shippingMethod of shippingMethods) {
11444
- if (shippingMethod.adjustments) {
11445
- for (const adjustment of shippingMethod.adjustments) {
11446
- if (adjustment.promotion_id) {
11447
- promotionIds.add(adjustment.promotion_id);
11448
- }
11449
- }
11450
- }
11451
- }
11452
- return Array.from(promotionIds);
11453
- }
11454
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11455
- const Shipping = () => {
11456
- var _a;
11457
- const { id } = reactRouterDom.useParams();
11458
- const { order, isPending, isError, error } = useOrder(id, {
11459
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11460
- });
11461
- const {
11462
- order: preview,
11463
- isPending: isPreviewPending,
11464
- isError: isPreviewError,
11465
- error: previewError
11466
- } = useOrderPreview(id);
11467
- useInitiateOrderEdit({ preview });
11468
- const { onCancel } = useCancelOrderEdit({ preview });
11469
- if (isError) {
11470
- throw error;
11471
- }
11472
- if (isPreviewError) {
11473
- throw previewError;
11474
- }
11475
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11476
- const isReady = preview && !isPreviewPending && order && !isPending;
11477
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11478
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11479
- /* @__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: [
11480
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11481
- /* @__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." }) })
11482
- ] }) }) }),
11483
- /* @__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" }) }) })
11484
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11485
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11486
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11487
- ] }) });
11488
- };
11489
- const ShippingForm = ({ preview, order }) => {
11490
- var _a;
11491
- const { setIsOpen } = useStackedModal();
11492
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11493
- const [data, setData] = React.useState(null);
11494
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11495
- const { shipping_options } = useShippingOptions(
11496
- {
11497
- id: appliedShippingOptionIds,
11498
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11499
- },
11500
- {
11501
- enabled: appliedShippingOptionIds.length > 0
11502
- }
11503
- );
11504
- const uniqueShippingProfiles = React.useMemo(() => {
11505
- const profiles = /* @__PURE__ */ new Map();
11506
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11507
- profiles.set(profile.id, profile);
11508
- });
11509
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11510
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11511
- });
11512
- return Array.from(profiles.values());
11513
- }, [order.items, shipping_options]);
11514
- const { handleSuccess } = useRouteModal();
11515
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11516
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11517
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11518
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11519
- const onSubmit = async () => {
11520
- setIsSubmitting(true);
11521
- let requestSucceeded = false;
11522
- await requestOrderEdit(void 0, {
11523
- onError: (e) => {
11524
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11525
- },
11526
- onSuccess: () => {
11527
- requestSucceeded = true;
11528
- }
11529
- });
11530
- if (!requestSucceeded) {
11531
- setIsSubmitting(false);
11532
- return;
11533
- }
11534
- await confirmOrderEdit(void 0, {
11535
- onError: (e) => {
11536
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11344
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11537
11345
  },
11538
11346
  onSuccess: () => {
11539
11347
  handleSuccess();
@@ -12258,224 +12066,21 @@ const CustomAmountField = ({
12258
12066
  }
12259
12067
  );
12260
12068
  };
12261
- const ShippingAddress = () => {
12069
+ const TransferOwnership = () => {
12262
12070
  const { id } = reactRouterDom.useParams();
12263
- const { order, isPending, isError, error } = useOrder(id, {
12264
- fields: "+shipping_address"
12071
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12072
+ fields: "id,customer_id,customer.*"
12265
12073
  });
12266
12074
  if (isError) {
12267
12075
  throw error;
12268
12076
  }
12269
- const isReady = !isPending && !!order;
12077
+ const isReady = !isPending && !!draft_order;
12270
12078
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12271
12079
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12272
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12273
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12080
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12081
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12274
12082
  ] }),
12275
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12276
- ] });
12277
- };
12278
- const ShippingAddressForm = ({ order }) => {
12279
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12280
- const form = reactHookForm.useForm({
12281
- defaultValues: {
12282
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12283
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12284
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12285
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12286
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12287
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12288
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12289
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12290
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12291
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12292
- },
12293
- resolver: zod.zodResolver(schema$2)
12294
- });
12295
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12296
- const { handleSuccess } = useRouteModal();
12297
- const onSubmit = form.handleSubmit(async (data) => {
12298
- await mutateAsync(
12299
- {
12300
- shipping_address: {
12301
- first_name: data.first_name,
12302
- last_name: data.last_name,
12303
- company: data.company,
12304
- address_1: data.address_1,
12305
- address_2: data.address_2,
12306
- city: data.city,
12307
- province: data.province,
12308
- country_code: data.country_code,
12309
- postal_code: data.postal_code,
12310
- phone: data.phone
12311
- }
12312
- },
12313
- {
12314
- onSuccess: () => {
12315
- handleSuccess();
12316
- },
12317
- onError: (error) => {
12318
- ui.toast.error(error.message);
12319
- }
12320
- }
12321
- );
12322
- });
12323
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12324
- KeyboundForm,
12325
- {
12326
- className: "flex flex-1 flex-col overflow-hidden",
12327
- onSubmit,
12328
- children: [
12329
- /* @__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: [
12330
- /* @__PURE__ */ jsxRuntime.jsx(
12331
- Form$2.Field,
12332
- {
12333
- control: form.control,
12334
- name: "country_code",
12335
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12336
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12337
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12338
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12339
- ] })
12340
- }
12341
- ),
12342
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12343
- /* @__PURE__ */ jsxRuntime.jsx(
12344
- Form$2.Field,
12345
- {
12346
- control: form.control,
12347
- name: "first_name",
12348
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12349
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12352
- ] })
12353
- }
12354
- ),
12355
- /* @__PURE__ */ jsxRuntime.jsx(
12356
- Form$2.Field,
12357
- {
12358
- control: form.control,
12359
- name: "last_name",
12360
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12361
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12362
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12364
- ] })
12365
- }
12366
- )
12367
- ] }),
12368
- /* @__PURE__ */ jsxRuntime.jsx(
12369
- Form$2.Field,
12370
- {
12371
- control: form.control,
12372
- name: "company",
12373
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12374
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12375
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12376
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12377
- ] })
12378
- }
12379
- ),
12380
- /* @__PURE__ */ jsxRuntime.jsx(
12381
- Form$2.Field,
12382
- {
12383
- control: form.control,
12384
- name: "address_1",
12385
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12386
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12387
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12388
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12389
- ] })
12390
- }
12391
- ),
12392
- /* @__PURE__ */ jsxRuntime.jsx(
12393
- Form$2.Field,
12394
- {
12395
- control: form.control,
12396
- name: "address_2",
12397
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12398
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12399
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12400
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12401
- ] })
12402
- }
12403
- ),
12404
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12405
- /* @__PURE__ */ jsxRuntime.jsx(
12406
- Form$2.Field,
12407
- {
12408
- control: form.control,
12409
- name: "postal_code",
12410
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12411
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12412
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12413
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12414
- ] })
12415
- }
12416
- ),
12417
- /* @__PURE__ */ jsxRuntime.jsx(
12418
- Form$2.Field,
12419
- {
12420
- control: form.control,
12421
- name: "city",
12422
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12423
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12424
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12425
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12426
- ] })
12427
- }
12428
- )
12429
- ] }),
12430
- /* @__PURE__ */ jsxRuntime.jsx(
12431
- Form$2.Field,
12432
- {
12433
- control: form.control,
12434
- name: "province",
12435
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12436
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12437
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12438
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12439
- ] })
12440
- }
12441
- ),
12442
- /* @__PURE__ */ jsxRuntime.jsx(
12443
- Form$2.Field,
12444
- {
12445
- control: form.control,
12446
- name: "phone",
12447
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12448
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12450
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12451
- ] })
12452
- }
12453
- )
12454
- ] }) }),
12455
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12456
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12457
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12458
- ] }) })
12459
- ]
12460
- }
12461
- ) });
12462
- };
12463
- const schema$2 = addressSchema;
12464
- const TransferOwnership = () => {
12465
- const { id } = reactRouterDom.useParams();
12466
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12467
- fields: "id,customer_id,customer.*"
12468
- });
12469
- if (isError) {
12470
- throw error;
12471
- }
12472
- const isReady = !isPending && !!draft_order;
12473
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12474
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12475
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12476
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12477
- ] }),
12478
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12083
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12479
12084
  ] });
12480
12085
  };
12481
12086
  const TransferOwnershipForm = ({ order }) => {
@@ -12484,7 +12089,7 @@ const TransferOwnershipForm = ({ order }) => {
12484
12089
  defaultValues: {
12485
12090
  customer_id: order.customer_id || ""
12486
12091
  },
12487
- resolver: zod.zodResolver(schema$1)
12092
+ resolver: zod.zodResolver(schema$2)
12488
12093
  });
12489
12094
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12490
12095
  const { handleSuccess } = useRouteModal();
@@ -12934,49 +12539,63 @@ const Illustration = () => {
12934
12539
  }
12935
12540
  );
12936
12541
  };
12937
- const schema$1 = objectType({
12542
+ const schema$2 = objectType({
12938
12543
  customer_id: stringType().min(1)
12939
12544
  });
12940
- const SalesChannel = () => {
12545
+ const ShippingAddress = () => {
12941
12546
  const { id } = reactRouterDom.useParams();
12942
- const { draft_order, isPending, isError, error } = useDraftOrder(
12943
- id,
12944
- {
12945
- fields: "+sales_channel_id"
12946
- },
12947
- {
12948
- enabled: !!id
12949
- }
12950
- );
12547
+ const { order, isPending, isError, error } = useOrder(id, {
12548
+ fields: "+shipping_address"
12549
+ });
12951
12550
  if (isError) {
12952
12551
  throw error;
12953
12552
  }
12954
- const ISrEADY = !!draft_order && !isPending;
12553
+ const isReady = !isPending && !!order;
12955
12554
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12956
12555
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12957
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12958
- /* @__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" }) })
12556
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12557
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12959
12558
  ] }),
12960
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12559
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12961
12560
  ] });
12962
12561
  };
12963
- const SalesChannelForm = ({ order }) => {
12562
+ const ShippingAddressForm = ({ order }) => {
12563
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12964
12564
  const form = reactHookForm.useForm({
12965
12565
  defaultValues: {
12966
- sales_channel_id: order.sales_channel_id || ""
12566
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12567
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12568
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12569
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12570
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12571
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12572
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12573
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12574
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12575
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12967
12576
  },
12968
- resolver: zod.zodResolver(schema)
12577
+ resolver: zod.zodResolver(schema$1)
12969
12578
  });
12970
12579
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12971
12580
  const { handleSuccess } = useRouteModal();
12972
12581
  const onSubmit = form.handleSubmit(async (data) => {
12973
12582
  await mutateAsync(
12974
12583
  {
12975
- sales_channel_id: data.sales_channel_id
12584
+ shipping_address: {
12585
+ first_name: data.first_name,
12586
+ last_name: data.last_name,
12587
+ company: data.company,
12588
+ address_1: data.address_1,
12589
+ address_2: data.address_2,
12590
+ city: data.city,
12591
+ province: data.province,
12592
+ country_code: data.country_code,
12593
+ postal_code: data.postal_code,
12594
+ phone: data.phone
12595
+ }
12976
12596
  },
12977
12597
  {
12978
12598
  onSuccess: () => {
12979
- ui.toast.success("Sales channel updated");
12980
12599
  handleSuccess();
12981
12600
  },
12982
12601
  onError: (error) => {
@@ -12991,7 +12610,132 @@ const SalesChannelForm = ({ order }) => {
12991
12610
  className: "flex flex-1 flex-col overflow-hidden",
12992
12611
  onSubmit,
12993
12612
  children: [
12994
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12613
+ /* @__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: [
12614
+ /* @__PURE__ */ jsxRuntime.jsx(
12615
+ Form$2.Field,
12616
+ {
12617
+ control: form.control,
12618
+ name: "country_code",
12619
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12620
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12621
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12622
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12623
+ ] })
12624
+ }
12625
+ ),
12626
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12627
+ /* @__PURE__ */ jsxRuntime.jsx(
12628
+ Form$2.Field,
12629
+ {
12630
+ control: form.control,
12631
+ name: "first_name",
12632
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12633
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12634
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12635
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12636
+ ] })
12637
+ }
12638
+ ),
12639
+ /* @__PURE__ */ jsxRuntime.jsx(
12640
+ Form$2.Field,
12641
+ {
12642
+ control: form.control,
12643
+ name: "last_name",
12644
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12645
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12646
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12647
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12648
+ ] })
12649
+ }
12650
+ )
12651
+ ] }),
12652
+ /* @__PURE__ */ jsxRuntime.jsx(
12653
+ Form$2.Field,
12654
+ {
12655
+ control: form.control,
12656
+ name: "company",
12657
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12658
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12659
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12660
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12661
+ ] })
12662
+ }
12663
+ ),
12664
+ /* @__PURE__ */ jsxRuntime.jsx(
12665
+ Form$2.Field,
12666
+ {
12667
+ control: form.control,
12668
+ name: "address_1",
12669
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12670
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12671
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12672
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12673
+ ] })
12674
+ }
12675
+ ),
12676
+ /* @__PURE__ */ jsxRuntime.jsx(
12677
+ Form$2.Field,
12678
+ {
12679
+ control: form.control,
12680
+ name: "address_2",
12681
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12682
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12683
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12684
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12685
+ ] })
12686
+ }
12687
+ ),
12688
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12689
+ /* @__PURE__ */ jsxRuntime.jsx(
12690
+ Form$2.Field,
12691
+ {
12692
+ control: form.control,
12693
+ name: "postal_code",
12694
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12695
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12696
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12697
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12698
+ ] })
12699
+ }
12700
+ ),
12701
+ /* @__PURE__ */ jsxRuntime.jsx(
12702
+ Form$2.Field,
12703
+ {
12704
+ control: form.control,
12705
+ name: "city",
12706
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12707
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12708
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12709
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12710
+ ] })
12711
+ }
12712
+ )
12713
+ ] }),
12714
+ /* @__PURE__ */ jsxRuntime.jsx(
12715
+ Form$2.Field,
12716
+ {
12717
+ control: form.control,
12718
+ name: "province",
12719
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12720
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12721
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12722
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12723
+ ] })
12724
+ }
12725
+ ),
12726
+ /* @__PURE__ */ jsxRuntime.jsx(
12727
+ Form$2.Field,
12728
+ {
12729
+ control: form.control,
12730
+ name: "phone",
12731
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12732
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12733
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12734
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12735
+ ] })
12736
+ }
12737
+ )
12738
+ ] }) }),
12995
12739
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12996
12740
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12997
12741
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13000,48 +12744,304 @@ const SalesChannelForm = ({ order }) => {
13000
12744
  }
13001
12745
  ) });
13002
12746
  };
13003
- const SalesChannelField = ({ control, order }) => {
13004
- const salesChannels = useComboboxData({
12747
+ const schema$1 = addressSchema;
12748
+ const PROMOTION_QUERY_KEY = "promotions";
12749
+ const promotionsQueryKeys = {
12750
+ list: (query2) => [
12751
+ PROMOTION_QUERY_KEY,
12752
+ query2 ? query2 : void 0
12753
+ ],
12754
+ detail: (id, query2) => [
12755
+ PROMOTION_QUERY_KEY,
12756
+ id,
12757
+ query2 ? query2 : void 0
12758
+ ]
12759
+ };
12760
+ const usePromotions = (query2, options) => {
12761
+ const { data, ...rest } = reactQuery.useQuery({
12762
+ queryKey: promotionsQueryKeys.list(query2),
12763
+ queryFn: async () => sdk.admin.promotion.list(query2),
12764
+ ...options
12765
+ });
12766
+ return { ...data, ...rest };
12767
+ };
12768
+ const Promotions = () => {
12769
+ const { id } = reactRouterDom.useParams();
12770
+ const {
12771
+ order: preview,
12772
+ isError: isPreviewError,
12773
+ error: previewError
12774
+ } = useOrderPreview(id, void 0);
12775
+ useInitiateOrderEdit({ preview });
12776
+ const { onCancel } = useCancelOrderEdit({ preview });
12777
+ if (isPreviewError) {
12778
+ throw previewError;
12779
+ }
12780
+ const isReady = !!preview;
12781
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12782
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12783
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12784
+ ] });
12785
+ };
12786
+ const PromotionForm = ({ preview }) => {
12787
+ const { items, shipping_methods } = preview;
12788
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12789
+ const [comboboxValue, setComboboxValue] = React.useState("");
12790
+ const { handleSuccess } = useRouteModal();
12791
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12792
+ const promoIds = getPromotionIds(items, shipping_methods);
12793
+ const { promotions, isPending, isError, error } = usePromotions(
12794
+ {
12795
+ id: promoIds
12796
+ },
12797
+ {
12798
+ enabled: !!promoIds.length
12799
+ }
12800
+ );
12801
+ const comboboxData = useComboboxData({
12802
+ queryKey: ["promotions", "combobox", promoIds],
13005
12803
  queryFn: async (params) => {
13006
- return await sdk.admin.salesChannel.list(params);
12804
+ return await sdk.admin.promotion.list({
12805
+ ...params,
12806
+ id: {
12807
+ $nin: promoIds
12808
+ }
12809
+ });
13007
12810
  },
13008
- queryKey: ["sales-channels"],
13009
12811
  getOptions: (data) => {
13010
- return data.sales_channels.map((salesChannel) => ({
13011
- label: salesChannel.name,
13012
- value: salesChannel.id
12812
+ return data.promotions.map((promotion) => ({
12813
+ label: promotion.code,
12814
+ value: promotion.code
13013
12815
  }));
13014
- },
13015
- defaultValue: order.sales_channel_id || void 0
12816
+ }
13016
12817
  });
13017
- return /* @__PURE__ */ jsxRuntime.jsx(
13018
- Form$2.Field,
13019
- {
13020
- control,
13021
- name: "sales_channel_id",
13022
- render: ({ field }) => {
13023
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13024
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13025
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13026
- Combobox,
13027
- {
13028
- options: salesChannels.options,
13029
- fetchNextPage: salesChannels.fetchNextPage,
13030
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13031
- searchValue: salesChannels.searchValue,
13032
- onSearchValueChange: salesChannels.onSearchValueChange,
13033
- placeholder: "Select sales channel",
13034
- ...field
13035
- }
13036
- ) }),
13037
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13038
- ] });
12818
+ const add = async (value) => {
12819
+ if (!value) {
12820
+ return;
12821
+ }
12822
+ addPromotions(
12823
+ {
12824
+ promo_codes: [value]
12825
+ },
12826
+ {
12827
+ onError: (e) => {
12828
+ ui.toast.error(e.message);
12829
+ comboboxData.onSearchValueChange("");
12830
+ setComboboxValue("");
12831
+ },
12832
+ onSuccess: () => {
12833
+ comboboxData.onSearchValueChange("");
12834
+ setComboboxValue("");
12835
+ }
12836
+ }
12837
+ );
12838
+ };
12839
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12840
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12841
+ const onSubmit = async () => {
12842
+ setIsSubmitting(true);
12843
+ let requestSucceeded = false;
12844
+ await requestOrderEdit(void 0, {
12845
+ onError: (e) => {
12846
+ ui.toast.error(e.message);
12847
+ },
12848
+ onSuccess: () => {
12849
+ requestSucceeded = true;
13039
12850
  }
12851
+ });
12852
+ if (!requestSucceeded) {
12853
+ setIsSubmitting(false);
12854
+ return;
13040
12855
  }
12856
+ await confirmOrderEdit(void 0, {
12857
+ onError: (e) => {
12858
+ ui.toast.error(e.message);
12859
+ },
12860
+ onSuccess: () => {
12861
+ handleSuccess();
12862
+ },
12863
+ onSettled: () => {
12864
+ setIsSubmitting(false);
12865
+ }
12866
+ });
12867
+ };
12868
+ if (isError) {
12869
+ throw error;
12870
+ }
12871
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12872
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12873
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12874
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12875
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12876
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12877
+ ] }),
12878
+ /* @__PURE__ */ jsxRuntime.jsx(
12879
+ Combobox,
12880
+ {
12881
+ id: "promotion-combobox",
12882
+ "aria-describedby": "promotion-combobox-hint",
12883
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12884
+ fetchNextPage: comboboxData.fetchNextPage,
12885
+ options: comboboxData.options,
12886
+ onSearchValueChange: comboboxData.onSearchValueChange,
12887
+ searchValue: comboboxData.searchValue,
12888
+ disabled: comboboxData.disabled || isAddingPromotions,
12889
+ onChange: add,
12890
+ value: comboboxValue
12891
+ }
12892
+ )
12893
+ ] }),
12894
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12895
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12896
+ PromotionItem,
12897
+ {
12898
+ promotion,
12899
+ orderId: preview.id,
12900
+ isLoading: isPending
12901
+ },
12902
+ promotion.id
12903
+ )) })
12904
+ ] }) }),
12905
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12906
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12907
+ /* @__PURE__ */ jsxRuntime.jsx(
12908
+ ui.Button,
12909
+ {
12910
+ size: "small",
12911
+ type: "submit",
12912
+ isLoading: isSubmitting || isAddingPromotions,
12913
+ children: "Save"
12914
+ }
12915
+ )
12916
+ ] }) })
12917
+ ] });
12918
+ };
12919
+ const PromotionItem = ({
12920
+ promotion,
12921
+ orderId,
12922
+ isLoading
12923
+ }) => {
12924
+ var _a;
12925
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12926
+ const onRemove = async () => {
12927
+ removePromotions(
12928
+ {
12929
+ promo_codes: [promotion.code]
12930
+ },
12931
+ {
12932
+ onError: (e) => {
12933
+ ui.toast.error(e.message);
12934
+ }
12935
+ }
12936
+ );
12937
+ };
12938
+ const displayValue = getDisplayValue(promotion);
12939
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12940
+ "div",
12941
+ {
12942
+ className: ui.clx(
12943
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12944
+ {
12945
+ "animate-pulse": isLoading
12946
+ }
12947
+ ),
12948
+ children: [
12949
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12950
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12951
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12952
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12953
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12954
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12955
+ ] }),
12956
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12957
+ ] })
12958
+ ] }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(
12960
+ ui.IconButton,
12961
+ {
12962
+ size: "small",
12963
+ type: "button",
12964
+ variant: "transparent",
12965
+ onClick: onRemove,
12966
+ isLoading: isPending || isLoading,
12967
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12968
+ }
12969
+ )
12970
+ ]
12971
+ },
12972
+ promotion.id
13041
12973
  );
13042
12974
  };
12975
+ function getDisplayValue(promotion) {
12976
+ var _a, _b, _c, _d;
12977
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12978
+ if (!value) {
12979
+ return null;
12980
+ }
12981
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12982
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
12983
+ if (!currency) {
12984
+ return null;
12985
+ }
12986
+ return getLocaleAmount(value, currency);
12987
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
12988
+ return formatPercentage(value);
12989
+ }
12990
+ return null;
12991
+ }
12992
+ const formatter = new Intl.NumberFormat([], {
12993
+ style: "percent",
12994
+ minimumFractionDigits: 2
12995
+ });
12996
+ const formatPercentage = (value, isPercentageValue = false) => {
12997
+ let val = value || 0;
12998
+ if (!isPercentageValue) {
12999
+ val = val / 100;
13000
+ }
13001
+ return formatter.format(val);
13002
+ };
13003
+ function getPromotionIds(items, shippingMethods) {
13004
+ const promotionIds = /* @__PURE__ */ new Set();
13005
+ for (const item of items) {
13006
+ if (item.adjustments) {
13007
+ for (const adjustment of item.adjustments) {
13008
+ if (adjustment.promotion_id) {
13009
+ promotionIds.add(adjustment.promotion_id);
13010
+ }
13011
+ }
13012
+ }
13013
+ }
13014
+ for (const shippingMethod of shippingMethods) {
13015
+ if (shippingMethod.adjustments) {
13016
+ for (const adjustment of shippingMethod.adjustments) {
13017
+ if (adjustment.promotion_id) {
13018
+ promotionIds.add(adjustment.promotion_id);
13019
+ }
13020
+ }
13021
+ }
13022
+ }
13023
+ return Array.from(promotionIds);
13024
+ }
13025
+ const CustomItems = () => {
13026
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
13027
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
13028
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
13029
+ ] });
13030
+ };
13031
+ const CustomItemsForm = () => {
13032
+ const form = reactHookForm.useForm({
13033
+ resolver: zod.zodResolver(schema)
13034
+ });
13035
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13036
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
13037
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
13040
+ ] }) })
13041
+ ] }) });
13042
+ };
13043
13043
  const schema = objectType({
13044
- sales_channel_id: stringType().min(1)
13044
+ email: stringType().email()
13045
13045
  });
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
@@ -13067,10 +13067,6 @@ const routeModule = {
13067
13067
  Component: BillingAddress,
13068
13068
  path: "/draft-orders/:id/billing-address"
13069
13069
  },
13070
- {
13071
- Component: CustomItems,
13072
- path: "/draft-orders/:id/custom-items"
13073
- },
13074
13070
  {
13075
13071
  Component: Email,
13076
13072
  path: "/draft-orders/:id/email"
@@ -13084,24 +13080,28 @@ const routeModule = {
13084
13080
  path: "/draft-orders/:id/metadata"
13085
13081
  },
13086
13082
  {
13087
- Component: Promotions,
13088
- path: "/draft-orders/:id/promotions"
13083
+ Component: SalesChannel,
13084
+ path: "/draft-orders/:id/sales-channel"
13089
13085
  },
13090
13086
  {
13091
13087
  Component: Shipping,
13092
13088
  path: "/draft-orders/:id/shipping"
13093
13089
  },
13090
+ {
13091
+ Component: TransferOwnership,
13092
+ path: "/draft-orders/:id/transfer-ownership"
13093
+ },
13094
13094
  {
13095
13095
  Component: ShippingAddress,
13096
13096
  path: "/draft-orders/:id/shipping-address"
13097
13097
  },
13098
13098
  {
13099
- Component: TransferOwnership,
13100
- path: "/draft-orders/:id/transfer-ownership"
13099
+ Component: Promotions,
13100
+ path: "/draft-orders/:id/promotions"
13101
13101
  },
13102
13102
  {
13103
- Component: SalesChannel,
13104
- path: "/draft-orders/:id/sales-channel"
13103
+ Component: CustomItems,
13104
+ path: "/draft-orders/:id/custom-items"
13105
13105
  }
13106
13106
  ]
13107
13107
  }