@medusajs/draft-order 2.10.4-preview-20250920090150 → 2.10.4-preview-20250920150155

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.
@@ -9573,6 +9573,27 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
+ const CustomItems = () => {
9577
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9579
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9580
+ ] });
9581
+ };
9582
+ const CustomItemsForm = () => {
9583
+ const form = reactHookForm.useForm({
9584
+ resolver: zod.zodResolver(schema$5)
9585
+ });
9586
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9590
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9591
+ ] }) })
9592
+ ] }) });
9593
+ };
9594
+ const schema$5 = objectType({
9595
+ email: stringType().email()
9596
+ });
9576
9597
  const BillingAddress = () => {
9577
9598
  const { id } = reactRouterDom.useParams();
9578
9599
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9605,7 +9626,7 @@ const BillingAddressForm = ({ order }) => {
9605
9626
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
9627
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9607
9628
  },
9608
- resolver: zod.zodResolver(schema$5)
9629
+ resolver: zod.zodResolver(schema$4)
9609
9630
  });
9610
9631
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
9632
  const { handleSuccess } = useRouteModal();
@@ -9762,28 +9783,7 @@ const BillingAddressForm = ({ order }) => {
9762
9783
  }
9763
9784
  ) });
9764
9785
  };
9765
- const schema$5 = addressSchema;
9766
- const CustomItems = () => {
9767
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9769
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9770
- ] });
9771
- };
9772
- const CustomItemsForm = () => {
9773
- const form = reactHookForm.useForm({
9774
- resolver: zod.zodResolver(schema$4)
9775
- });
9776
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9778
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9779
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9780
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9781
- ] }) })
9782
- ] }) });
9783
- };
9784
- const schema$4 = objectType({
9785
- email: stringType().email()
9786
- });
9786
+ const schema$4 = addressSchema;
9787
9787
  const Email = () => {
9788
9788
  const { id } = reactRouterDom.useParams();
9789
9789
  const { order, isPending, isError, error } = useOrder(id, {
@@ -11176,166 +11176,323 @@ function getHasUneditableRows(metadata) {
11176
11176
  (value) => !EDITABLE_TYPES.includes(typeof value)
11177
11177
  );
11178
11178
  }
11179
- const SalesChannel = () => {
11180
- const { id } = reactRouterDom.useParams();
11181
- const { draft_order, isPending, isError, error } = useDraftOrder(
11179
+ const PROMOTION_QUERY_KEY = "promotions";
11180
+ const promotionsQueryKeys = {
11181
+ list: (query2) => [
11182
+ PROMOTION_QUERY_KEY,
11183
+ query2 ? query2 : void 0
11184
+ ],
11185
+ detail: (id, query2) => [
11186
+ PROMOTION_QUERY_KEY,
11182
11187
  id,
11188
+ query2 ? query2 : void 0
11189
+ ]
11190
+ };
11191
+ const usePromotions = (query2, options) => {
11192
+ const { data, ...rest } = reactQuery.useQuery({
11193
+ queryKey: promotionsQueryKeys.list(query2),
11194
+ queryFn: async () => sdk.admin.promotion.list(query2),
11195
+ ...options
11196
+ });
11197
+ return { ...data, ...rest };
11198
+ };
11199
+ const Promotions = () => {
11200
+ const { id } = reactRouterDom.useParams();
11201
+ const {
11202
+ order: preview,
11203
+ isError: isPreviewError,
11204
+ error: previewError
11205
+ } = useOrderPreview(id, void 0);
11206
+ useInitiateOrderEdit({ preview });
11207
+ const { onCancel } = useCancelOrderEdit({ preview });
11208
+ if (isPreviewError) {
11209
+ throw previewError;
11210
+ }
11211
+ const isReady = !!preview;
11212
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11213
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11214
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11215
+ ] });
11216
+ };
11217
+ const PromotionForm = ({ preview }) => {
11218
+ const { items, shipping_methods } = preview;
11219
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11220
+ const [comboboxValue, setComboboxValue] = React.useState("");
11221
+ const { handleSuccess } = useRouteModal();
11222
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11223
+ const promoIds = getPromotionIds(items, shipping_methods);
11224
+ const { promotions, isPending, isError, error } = usePromotions(
11183
11225
  {
11184
- fields: "+sales_channel_id"
11226
+ id: promoIds
11185
11227
  },
11186
11228
  {
11187
- enabled: !!id
11229
+ enabled: !!promoIds.length
11188
11230
  }
11189
11231
  );
11190
- if (isError) {
11191
- throw error;
11192
- }
11193
- const ISrEADY = !!draft_order && !isPending;
11194
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11195
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11196
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11197
- /* @__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" }) })
11198
- ] }),
11199
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11200
- ] });
11201
- };
11202
- const SalesChannelForm = ({ order }) => {
11203
- const form = reactHookForm.useForm({
11204
- defaultValues: {
11205
- sales_channel_id: order.sales_channel_id || ""
11232
+ const comboboxData = useComboboxData({
11233
+ queryKey: ["promotions", "combobox", promoIds],
11234
+ queryFn: async (params) => {
11235
+ return await sdk.admin.promotion.list({
11236
+ ...params,
11237
+ id: {
11238
+ $nin: promoIds
11239
+ }
11240
+ });
11206
11241
  },
11207
- resolver: zod.zodResolver(schema$2)
11242
+ getOptions: (data) => {
11243
+ return data.promotions.map((promotion) => ({
11244
+ label: promotion.code,
11245
+ value: promotion.code
11246
+ }));
11247
+ }
11208
11248
  });
11209
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11210
- const { handleSuccess } = useRouteModal();
11211
- const onSubmit = form.handleSubmit(async (data) => {
11212
- await mutateAsync(
11249
+ const add = async (value) => {
11250
+ if (!value) {
11251
+ return;
11252
+ }
11253
+ addPromotions(
11213
11254
  {
11214
- sales_channel_id: data.sales_channel_id
11255
+ promo_codes: [value]
11215
11256
  },
11216
11257
  {
11217
- onSuccess: () => {
11218
- ui.toast.success("Sales channel updated");
11219
- handleSuccess();
11258
+ onError: (e) => {
11259
+ ui.toast.error(e.message);
11260
+ comboboxData.onSearchValueChange("");
11261
+ setComboboxValue("");
11220
11262
  },
11221
- onError: (error) => {
11222
- ui.toast.error(error.message);
11263
+ onSuccess: () => {
11264
+ comboboxData.onSearchValueChange("");
11265
+ setComboboxValue("");
11223
11266
  }
11224
11267
  }
11225
11268
  );
11226
- });
11227
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11228
- KeyboundForm,
11229
- {
11230
- className: "flex flex-1 flex-col overflow-hidden",
11231
- onSubmit,
11232
- children: [
11233
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11234
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11235
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11236
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11237
- ] }) })
11238
- ]
11239
- }
11240
- ) });
11241
- };
11242
- const SalesChannelField = ({ control, order }) => {
11243
- const salesChannels = useComboboxData({
11244
- queryFn: async (params) => {
11245
- return await sdk.admin.salesChannel.list(params);
11246
- },
11247
- queryKey: ["sales-channels"],
11248
- getOptions: (data) => {
11249
- return data.sales_channels.map((salesChannel) => ({
11250
- label: salesChannel.name,
11251
- value: salesChannel.id
11252
- }));
11253
- },
11254
- defaultValue: order.sales_channel_id || void 0
11255
- });
11256
- return /* @__PURE__ */ jsxRuntime.jsx(
11257
- Form$2.Field,
11258
- {
11259
- control,
11260
- name: "sales_channel_id",
11261
- render: ({ field }) => {
11262
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11263
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11264
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11265
- Combobox,
11266
- {
11267
- options: salesChannels.options,
11268
- fetchNextPage: salesChannels.fetchNextPage,
11269
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11270
- searchValue: salesChannels.searchValue,
11271
- onSearchValueChange: salesChannels.onSearchValueChange,
11272
- placeholder: "Select sales channel",
11273
- ...field
11274
- }
11275
- ) }),
11276
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11277
- ] });
11269
+ };
11270
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11271
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11272
+ const onSubmit = async () => {
11273
+ setIsSubmitting(true);
11274
+ let requestSucceeded = false;
11275
+ await requestOrderEdit(void 0, {
11276
+ onError: (e) => {
11277
+ ui.toast.error(e.message);
11278
+ },
11279
+ onSuccess: () => {
11280
+ requestSucceeded = true;
11278
11281
  }
11282
+ });
11283
+ if (!requestSucceeded) {
11284
+ setIsSubmitting(false);
11285
+ return;
11279
11286
  }
11280
- );
11281
- };
11282
- const schema$2 = objectType({
11283
- sales_channel_id: stringType().min(1)
11284
- });
11285
- const ShippingAddress = () => {
11286
- const { id } = reactRouterDom.useParams();
11287
- const { order, isPending, isError, error } = useOrder(id, {
11288
- fields: "+shipping_address"
11289
- });
11287
+ await confirmOrderEdit(void 0, {
11288
+ onError: (e) => {
11289
+ ui.toast.error(e.message);
11290
+ },
11291
+ onSuccess: () => {
11292
+ handleSuccess();
11293
+ },
11294
+ onSettled: () => {
11295
+ setIsSubmitting(false);
11296
+ }
11297
+ });
11298
+ };
11290
11299
  if (isError) {
11291
11300
  throw error;
11292
11301
  }
11293
- const isReady = !isPending && !!order;
11294
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11295
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11296
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11297
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11298
- ] }),
11299
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11300
- ] });
11301
- };
11302
- const ShippingAddressForm = ({ order }) => {
11303
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11304
- const form = reactHookForm.useForm({
11305
- defaultValues: {
11306
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11307
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11308
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11309
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11310
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11311
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11312
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11313
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11314
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11315
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11302
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11304
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11305
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11306
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11307
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11308
+ ] }),
11309
+ /* @__PURE__ */ jsxRuntime.jsx(
11310
+ Combobox,
11311
+ {
11312
+ id: "promotion-combobox",
11313
+ "aria-describedby": "promotion-combobox-hint",
11314
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11315
+ fetchNextPage: comboboxData.fetchNextPage,
11316
+ options: comboboxData.options,
11317
+ onSearchValueChange: comboboxData.onSearchValueChange,
11318
+ searchValue: comboboxData.searchValue,
11319
+ disabled: comboboxData.disabled || isAddingPromotions,
11320
+ onChange: add,
11321
+ value: comboboxValue
11322
+ }
11323
+ )
11324
+ ] }),
11325
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11326
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11327
+ PromotionItem,
11328
+ {
11329
+ promotion,
11330
+ orderId: preview.id,
11331
+ isLoading: isPending
11332
+ },
11333
+ promotion.id
11334
+ )) })
11335
+ ] }) }),
11336
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11337
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11338
+ /* @__PURE__ */ jsxRuntime.jsx(
11339
+ ui.Button,
11340
+ {
11341
+ size: "small",
11342
+ type: "submit",
11343
+ isLoading: isSubmitting || isAddingPromotions,
11344
+ children: "Save"
11345
+ }
11346
+ )
11347
+ ] }) })
11348
+ ] });
11349
+ };
11350
+ const PromotionItem = ({
11351
+ promotion,
11352
+ orderId,
11353
+ isLoading
11354
+ }) => {
11355
+ var _a;
11356
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11357
+ const onRemove = async () => {
11358
+ removePromotions(
11359
+ {
11360
+ promo_codes: [promotion.code]
11361
+ },
11362
+ {
11363
+ onError: (e) => {
11364
+ ui.toast.error(e.message);
11365
+ }
11366
+ }
11367
+ );
11368
+ };
11369
+ const displayValue = getDisplayValue(promotion);
11370
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11371
+ "div",
11372
+ {
11373
+ className: ui.clx(
11374
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11375
+ {
11376
+ "animate-pulse": isLoading
11377
+ }
11378
+ ),
11379
+ children: [
11380
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11381
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11382
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11383
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11384
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11385
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11386
+ ] }),
11387
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11388
+ ] })
11389
+ ] }),
11390
+ /* @__PURE__ */ jsxRuntime.jsx(
11391
+ ui.IconButton,
11392
+ {
11393
+ size: "small",
11394
+ type: "button",
11395
+ variant: "transparent",
11396
+ onClick: onRemove,
11397
+ isLoading: isPending || isLoading,
11398
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11399
+ }
11400
+ )
11401
+ ]
11316
11402
  },
11317
- resolver: zod.zodResolver(schema$1)
11403
+ promotion.id
11404
+ );
11405
+ };
11406
+ function getDisplayValue(promotion) {
11407
+ var _a, _b, _c, _d;
11408
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11409
+ if (!value) {
11410
+ return null;
11411
+ }
11412
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11413
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11414
+ if (!currency) {
11415
+ return null;
11416
+ }
11417
+ return getLocaleAmount(value, currency);
11418
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11419
+ return formatPercentage(value);
11420
+ }
11421
+ return null;
11422
+ }
11423
+ const formatter = new Intl.NumberFormat([], {
11424
+ style: "percent",
11425
+ minimumFractionDigits: 2
11426
+ });
11427
+ const formatPercentage = (value, isPercentageValue = false) => {
11428
+ let val = value || 0;
11429
+ if (!isPercentageValue) {
11430
+ val = val / 100;
11431
+ }
11432
+ return formatter.format(val);
11433
+ };
11434
+ function getPromotionIds(items, shippingMethods) {
11435
+ const promotionIds = /* @__PURE__ */ new Set();
11436
+ for (const item of items) {
11437
+ if (item.adjustments) {
11438
+ for (const adjustment of item.adjustments) {
11439
+ if (adjustment.promotion_id) {
11440
+ promotionIds.add(adjustment.promotion_id);
11441
+ }
11442
+ }
11443
+ }
11444
+ }
11445
+ for (const shippingMethod of shippingMethods) {
11446
+ if (shippingMethod.adjustments) {
11447
+ for (const adjustment of shippingMethod.adjustments) {
11448
+ if (adjustment.promotion_id) {
11449
+ promotionIds.add(adjustment.promotion_id);
11450
+ }
11451
+ }
11452
+ }
11453
+ }
11454
+ return Array.from(promotionIds);
11455
+ }
11456
+ const SalesChannel = () => {
11457
+ const { id } = reactRouterDom.useParams();
11458
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11459
+ id,
11460
+ {
11461
+ fields: "+sales_channel_id"
11462
+ },
11463
+ {
11464
+ enabled: !!id
11465
+ }
11466
+ );
11467
+ if (isError) {
11468
+ throw error;
11469
+ }
11470
+ const ISrEADY = !!draft_order && !isPending;
11471
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11473
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11474
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11475
+ ] }),
11476
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11477
+ ] });
11478
+ };
11479
+ const SalesChannelForm = ({ order }) => {
11480
+ const form = reactHookForm.useForm({
11481
+ defaultValues: {
11482
+ sales_channel_id: order.sales_channel_id || ""
11483
+ },
11484
+ resolver: zod.zodResolver(schema$2)
11318
11485
  });
11319
11486
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11320
11487
  const { handleSuccess } = useRouteModal();
11321
11488
  const onSubmit = form.handleSubmit(async (data) => {
11322
11489
  await mutateAsync(
11323
11490
  {
11324
- shipping_address: {
11325
- first_name: data.first_name,
11326
- last_name: data.last_name,
11327
- company: data.company,
11328
- address_1: data.address_1,
11329
- address_2: data.address_2,
11330
- city: data.city,
11331
- province: data.province,
11332
- country_code: data.country_code,
11333
- postal_code: data.postal_code,
11334
- phone: data.phone
11335
- }
11491
+ sales_channel_id: data.sales_channel_id
11336
11492
  },
11337
11493
  {
11338
11494
  onSuccess: () => {
11495
+ ui.toast.success("Sales channel updated");
11339
11496
  handleSuccess();
11340
11497
  },
11341
11498
  onError: (error) => {
@@ -11350,719 +11507,160 @@ const ShippingAddressForm = ({ order }) => {
11350
11507
  className: "flex flex-1 flex-col overflow-hidden",
11351
11508
  onSubmit,
11352
11509
  children: [
11353
- /* @__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: [
11354
- /* @__PURE__ */ jsxRuntime.jsx(
11355
- Form$2.Field,
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11512
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11513
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11514
+ ] }) })
11515
+ ]
11516
+ }
11517
+ ) });
11518
+ };
11519
+ const SalesChannelField = ({ control, order }) => {
11520
+ const salesChannels = useComboboxData({
11521
+ queryFn: async (params) => {
11522
+ return await sdk.admin.salesChannel.list(params);
11523
+ },
11524
+ queryKey: ["sales-channels"],
11525
+ getOptions: (data) => {
11526
+ return data.sales_channels.map((salesChannel) => ({
11527
+ label: salesChannel.name,
11528
+ value: salesChannel.id
11529
+ }));
11530
+ },
11531
+ defaultValue: order.sales_channel_id || void 0
11532
+ });
11533
+ return /* @__PURE__ */ jsxRuntime.jsx(
11534
+ Form$2.Field,
11535
+ {
11536
+ control,
11537
+ name: "sales_channel_id",
11538
+ render: ({ field }) => {
11539
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11541
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11542
+ Combobox,
11356
11543
  {
11357
- control: form.control,
11358
- name: "country_code",
11359
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11360
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11361
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11362
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11363
- ] })
11544
+ options: salesChannels.options,
11545
+ fetchNextPage: salesChannels.fetchNextPage,
11546
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11547
+ searchValue: salesChannels.searchValue,
11548
+ onSearchValueChange: salesChannels.onSearchValueChange,
11549
+ placeholder: "Select sales channel",
11550
+ ...field
11364
11551
  }
11365
- ),
11366
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11367
- /* @__PURE__ */ jsxRuntime.jsx(
11368
- Form$2.Field,
11369
- {
11370
- control: form.control,
11371
- name: "first_name",
11372
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11373
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11374
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11375
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11376
- ] })
11377
- }
11378
- ),
11379
- /* @__PURE__ */ jsxRuntime.jsx(
11380
- Form$2.Field,
11381
- {
11382
- control: form.control,
11383
- name: "last_name",
11384
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11385
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11386
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11387
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11388
- ] })
11389
- }
11390
- )
11391
- ] }),
11392
- /* @__PURE__ */ jsxRuntime.jsx(
11393
- Form$2.Field,
11394
- {
11395
- control: form.control,
11396
- name: "company",
11397
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11398
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11399
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11400
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11401
- ] })
11402
- }
11403
- ),
11404
- /* @__PURE__ */ jsxRuntime.jsx(
11405
- Form$2.Field,
11406
- {
11407
- control: form.control,
11408
- name: "address_1",
11409
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11410
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11411
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11412
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11413
- ] })
11414
- }
11415
- ),
11416
- /* @__PURE__ */ jsxRuntime.jsx(
11417
- Form$2.Field,
11418
- {
11419
- control: form.control,
11420
- name: "address_2",
11421
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11422
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11423
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11424
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11425
- ] })
11426
- }
11427
- ),
11428
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11429
- /* @__PURE__ */ jsxRuntime.jsx(
11430
- Form$2.Field,
11431
- {
11432
- control: form.control,
11433
- name: "postal_code",
11434
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11435
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11436
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11437
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11438
- ] })
11439
- }
11440
- ),
11441
- /* @__PURE__ */ jsxRuntime.jsx(
11442
- Form$2.Field,
11443
- {
11444
- control: form.control,
11445
- name: "city",
11446
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11447
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11448
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11450
- ] })
11451
- }
11452
- )
11453
- ] }),
11454
- /* @__PURE__ */ jsxRuntime.jsx(
11455
- Form$2.Field,
11456
- {
11457
- control: form.control,
11458
- name: "province",
11459
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11460
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11461
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11462
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11463
- ] })
11464
- }
11465
- ),
11466
- /* @__PURE__ */ jsxRuntime.jsx(
11467
- Form$2.Field,
11468
- {
11469
- control: form.control,
11470
- name: "phone",
11471
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11472
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11473
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11474
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11475
- ] })
11476
- }
11477
- )
11478
- ] }) }),
11479
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11480
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11481
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11482
- ] }) })
11483
- ]
11552
+ ) }),
11553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11554
+ ] });
11555
+ }
11484
11556
  }
11485
- ) });
11557
+ );
11486
11558
  };
11487
- const schema$1 = addressSchema;
11488
- const TransferOwnership = () => {
11559
+ const schema$2 = objectType({
11560
+ sales_channel_id: stringType().min(1)
11561
+ });
11562
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11563
+ const Shipping = () => {
11564
+ var _a;
11489
11565
  const { id } = reactRouterDom.useParams();
11490
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11491
- fields: "id,customer_id,customer.*"
11566
+ const { order, isPending, isError, error } = useOrder(id, {
11567
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11492
11568
  });
11569
+ const {
11570
+ order: preview,
11571
+ isPending: isPreviewPending,
11572
+ isError: isPreviewError,
11573
+ error: previewError
11574
+ } = useOrderPreview(id);
11575
+ useInitiateOrderEdit({ preview });
11576
+ const { onCancel } = useCancelOrderEdit({ preview });
11493
11577
  if (isError) {
11494
11578
  throw error;
11495
11579
  }
11496
- const isReady = !isPending && !!draft_order;
11497
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11498
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11499
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11500
- /* @__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" }) })
11501
- ] }),
11502
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11503
- ] });
11580
+ if (isPreviewError) {
11581
+ throw previewError;
11582
+ }
11583
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11584
+ const isReady = preview && !isPreviewPending && order && !isPending;
11585
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11590
+ ] }) }) }),
11591
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11592
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11593
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11594
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11595
+ ] }) });
11504
11596
  };
11505
- const TransferOwnershipForm = ({ order }) => {
11506
- var _a, _b;
11507
- const form = reactHookForm.useForm({
11508
- defaultValues: {
11509
- customer_id: order.customer_id || ""
11597
+ const ShippingForm = ({ preview, order }) => {
11598
+ var _a;
11599
+ const { setIsOpen } = useStackedModal();
11600
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11601
+ const [data, setData] = React.useState(null);
11602
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11603
+ const { shipping_options } = useShippingOptions(
11604
+ {
11605
+ id: appliedShippingOptionIds,
11606
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11510
11607
  },
11511
- resolver: zod.zodResolver(schema)
11512
- });
11513
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11608
+ {
11609
+ enabled: appliedShippingOptionIds.length > 0
11610
+ }
11611
+ );
11612
+ const uniqueShippingProfiles = React.useMemo(() => {
11613
+ const profiles = /* @__PURE__ */ new Map();
11614
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11615
+ profiles.set(profile.id, profile);
11616
+ });
11617
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11618
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11619
+ });
11620
+ return Array.from(profiles.values());
11621
+ }, [order.items, shipping_options]);
11514
11622
  const { handleSuccess } = useRouteModal();
11515
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11516
- const currentCustomer = order.customer ? {
11517
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11518
- value: order.customer.id
11519
- } : null;
11520
- const onSubmit = form.handleSubmit(async (data) => {
11521
- await mutateAsync(
11522
- { customer_id: data.customer_id },
11523
- {
11524
- onSuccess: () => {
11525
- ui.toast.success("Customer updated");
11526
- handleSuccess();
11527
- },
11528
- onError: (error) => {
11529
- ui.toast.error(error.message);
11623
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11624
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11625
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11626
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11627
+ const onSubmit = async () => {
11628
+ setIsSubmitting(true);
11629
+ let requestSucceeded = false;
11630
+ await requestOrderEdit(void 0, {
11631
+ onError: (e) => {
11632
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11633
+ },
11634
+ onSuccess: () => {
11635
+ requestSucceeded = true;
11636
+ }
11637
+ });
11638
+ if (!requestSucceeded) {
11639
+ setIsSubmitting(false);
11640
+ return;
11641
+ }
11642
+ await confirmOrderEdit(void 0, {
11643
+ onError: (e) => {
11644
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11645
+ },
11646
+ onSuccess: () => {
11647
+ handleSuccess();
11648
+ },
11649
+ onSettled: () => {
11650
+ setIsSubmitting(false);
11651
+ }
11652
+ });
11653
+ };
11654
+ const onKeydown = React.useCallback(
11655
+ (e) => {
11656
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11657
+ if (data || isSubmitting) {
11658
+ return;
11530
11659
  }
11660
+ onSubmit();
11531
11661
  }
11532
- );
11533
- });
11534
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11535
- KeyboundForm,
11536
- {
11537
- className: "flex flex-1 flex-col overflow-hidden",
11538
- onSubmit,
11539
- children: [
11540
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11541
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11542
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11543
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11544
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11545
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11546
- ] }),
11547
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11548
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11549
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11550
- ] })
11551
- ] }),
11552
- /* @__PURE__ */ jsxRuntime.jsx(
11553
- CustomerField,
11554
- {
11555
- control: form.control,
11556
- currentCustomerId: order.customer_id
11557
- }
11558
- )
11559
- ] }),
11560
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11561
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11562
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11563
- ] }) })
11564
- ]
11565
- }
11566
- ) });
11567
- };
11568
- const CustomerField = ({ control, currentCustomerId }) => {
11569
- const customers = useComboboxData({
11570
- queryFn: async (params) => {
11571
- return await sdk.admin.customer.list({
11572
- ...params,
11573
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11574
- });
11575
11662
  },
11576
- queryKey: ["customers"],
11577
- getOptions: (data) => {
11578
- return data.customers.map((customer) => {
11579
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11580
- return {
11581
- label: name ? `${name} (${customer.email})` : customer.email,
11582
- value: customer.id
11583
- };
11584
- });
11585
- }
11586
- });
11587
- return /* @__PURE__ */ jsxRuntime.jsx(
11588
- Form$2.Field,
11589
- {
11590
- name: "customer_id",
11591
- control,
11592
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11593
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11594
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11595
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11596
- ] }),
11597
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11598
- Combobox,
11599
- {
11600
- options: customers.options,
11601
- fetchNextPage: customers.fetchNextPage,
11602
- isFetchingNextPage: customers.isFetchingNextPage,
11603
- searchValue: customers.searchValue,
11604
- onSearchValueChange: customers.onSearchValueChange,
11605
- placeholder: "Select customer",
11606
- ...field
11607
- }
11608
- ) }),
11609
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11610
- ] })
11611
- }
11612
- );
11613
- };
11614
- const Illustration = () => {
11615
- return /* @__PURE__ */ jsxRuntime.jsxs(
11616
- "svg",
11617
- {
11618
- width: "280",
11619
- height: "180",
11620
- viewBox: "0 0 280 180",
11621
- fill: "none",
11622
- xmlns: "http://www.w3.org/2000/svg",
11623
- children: [
11624
- /* @__PURE__ */ jsxRuntime.jsx(
11625
- "rect",
11626
- {
11627
- x: "0.00428286",
11628
- y: "-0.742904",
11629
- width: "33.5",
11630
- height: "65.5",
11631
- rx: "6.75",
11632
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11633
- fill: "#D4D4D8",
11634
- stroke: "#52525B",
11635
- strokeWidth: "1.5"
11636
- }
11637
- ),
11638
- /* @__PURE__ */ jsxRuntime.jsx(
11639
- "rect",
11640
- {
11641
- x: "0.00428286",
11642
- y: "-0.742904",
11643
- width: "33.5",
11644
- height: "65.5",
11645
- rx: "6.75",
11646
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11647
- fill: "white",
11648
- stroke: "#52525B",
11649
- strokeWidth: "1.5"
11650
- }
11651
- ),
11652
- /* @__PURE__ */ jsxRuntime.jsx(
11653
- "path",
11654
- {
11655
- d: "M180.579 107.142L179.126 107.959",
11656
- stroke: "#52525B",
11657
- strokeWidth: "1.5",
11658
- strokeLinecap: "round",
11659
- strokeLinejoin: "round"
11660
- }
11661
- ),
11662
- /* @__PURE__ */ jsxRuntime.jsx(
11663
- "path",
11664
- {
11665
- opacity: "0.88",
11666
- d: "M182.305 109.546L180.257 109.534",
11667
- stroke: "#52525B",
11668
- strokeWidth: "1.5",
11669
- strokeLinecap: "round",
11670
- strokeLinejoin: "round"
11671
- }
11672
- ),
11673
- /* @__PURE__ */ jsxRuntime.jsx(
11674
- "path",
11675
- {
11676
- opacity: "0.75",
11677
- d: "M180.551 111.93L179.108 111.096",
11678
- stroke: "#52525B",
11679
- strokeWidth: "1.5",
11680
- strokeLinecap: "round",
11681
- strokeLinejoin: "round"
11682
- }
11683
- ),
11684
- /* @__PURE__ */ jsxRuntime.jsx(
11685
- "path",
11686
- {
11687
- opacity: "0.63",
11688
- d: "M176.347 112.897L176.354 111.73",
11689
- stroke: "#52525B",
11690
- strokeWidth: "1.5",
11691
- strokeLinecap: "round",
11692
- strokeLinejoin: "round"
11693
- }
11694
- ),
11695
- /* @__PURE__ */ jsxRuntime.jsx(
11696
- "path",
11697
- {
11698
- opacity: "0.5",
11699
- d: "M172.153 111.881L173.606 111.064",
11700
- stroke: "#52525B",
11701
- strokeWidth: "1.5",
11702
- strokeLinecap: "round",
11703
- strokeLinejoin: "round"
11704
- }
11705
- ),
11706
- /* @__PURE__ */ jsxRuntime.jsx(
11707
- "path",
11708
- {
11709
- opacity: "0.38",
11710
- d: "M170.428 109.478L172.476 109.489",
11711
- stroke: "#52525B",
11712
- strokeWidth: "1.5",
11713
- strokeLinecap: "round",
11714
- strokeLinejoin: "round"
11715
- }
11716
- ),
11717
- /* @__PURE__ */ jsxRuntime.jsx(
11718
- "path",
11719
- {
11720
- opacity: "0.25",
11721
- d: "M172.181 107.094L173.624 107.928",
11722
- stroke: "#52525B",
11723
- strokeWidth: "1.5",
11724
- strokeLinecap: "round",
11725
- strokeLinejoin: "round"
11726
- }
11727
- ),
11728
- /* @__PURE__ */ jsxRuntime.jsx(
11729
- "path",
11730
- {
11731
- opacity: "0.13",
11732
- d: "M176.386 106.126L176.379 107.294",
11733
- stroke: "#52525B",
11734
- strokeWidth: "1.5",
11735
- strokeLinecap: "round",
11736
- strokeLinejoin: "round"
11737
- }
11738
- ),
11739
- /* @__PURE__ */ jsxRuntime.jsx(
11740
- "rect",
11741
- {
11742
- width: "12",
11743
- height: "3",
11744
- rx: "1.5",
11745
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11746
- fill: "#D4D4D8"
11747
- }
11748
- ),
11749
- /* @__PURE__ */ jsxRuntime.jsx(
11750
- "rect",
11751
- {
11752
- x: "0.00428286",
11753
- y: "-0.742904",
11754
- width: "33.5",
11755
- height: "65.5",
11756
- rx: "6.75",
11757
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11758
- fill: "#D4D4D8",
11759
- stroke: "#52525B",
11760
- strokeWidth: "1.5"
11761
- }
11762
- ),
11763
- /* @__PURE__ */ jsxRuntime.jsx(
11764
- "rect",
11765
- {
11766
- x: "0.00428286",
11767
- y: "-0.742904",
11768
- width: "33.5",
11769
- height: "65.5",
11770
- rx: "6.75",
11771
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11772
- fill: "white",
11773
- stroke: "#52525B",
11774
- strokeWidth: "1.5"
11775
- }
11776
- ),
11777
- /* @__PURE__ */ jsxRuntime.jsx(
11778
- "rect",
11779
- {
11780
- width: "12",
11781
- height: "3",
11782
- rx: "1.5",
11783
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11784
- fill: "#D4D4D8"
11785
- }
11786
- ),
11787
- /* @__PURE__ */ jsxRuntime.jsx(
11788
- "rect",
11789
- {
11790
- width: "17",
11791
- height: "3",
11792
- rx: "1.5",
11793
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11794
- fill: "#D4D4D8"
11795
- }
11796
- ),
11797
- /* @__PURE__ */ jsxRuntime.jsx(
11798
- "rect",
11799
- {
11800
- width: "12",
11801
- height: "3",
11802
- rx: "1.5",
11803
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11804
- fill: "#D4D4D8"
11805
- }
11806
- ),
11807
- /* @__PURE__ */ jsxRuntime.jsx(
11808
- "path",
11809
- {
11810
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11811
- fill: "#A1A1AA"
11812
- }
11813
- ),
11814
- /* @__PURE__ */ jsxRuntime.jsx(
11815
- "rect",
11816
- {
11817
- width: "17",
11818
- height: "3",
11819
- rx: "1.5",
11820
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11821
- fill: "#A1A1AA"
11822
- }
11823
- ),
11824
- /* @__PURE__ */ jsxRuntime.jsx(
11825
- "rect",
11826
- {
11827
- width: "12",
11828
- height: "3",
11829
- rx: "1.5",
11830
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11831
- fill: "#A1A1AA"
11832
- }
11833
- ),
11834
- /* @__PURE__ */ jsxRuntime.jsx(
11835
- "path",
11836
- {
11837
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11838
- fill: "#52525B"
11839
- }
11840
- ),
11841
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11842
- "path",
11843
- {
11844
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11845
- stroke: "#A1A1AA",
11846
- strokeWidth: "1.5",
11847
- strokeLinecap: "round",
11848
- strokeLinejoin: "round"
11849
- }
11850
- ) }),
11851
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11852
- "path",
11853
- {
11854
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11855
- stroke: "#A1A1AA",
11856
- strokeWidth: "1.5",
11857
- strokeLinecap: "round",
11858
- strokeLinejoin: "round"
11859
- }
11860
- ) }),
11861
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11862
- "path",
11863
- {
11864
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11865
- stroke: "#A1A1AA",
11866
- strokeWidth: "1.5",
11867
- strokeLinecap: "round",
11868
- strokeLinejoin: "round"
11869
- }
11870
- ) }),
11871
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11872
- "path",
11873
- {
11874
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11875
- stroke: "#A1A1AA",
11876
- strokeWidth: "1.5",
11877
- strokeLinecap: "round",
11878
- strokeLinejoin: "round"
11879
- }
11880
- ) }),
11881
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11882
- "path",
11883
- {
11884
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11885
- stroke: "#A1A1AA",
11886
- strokeWidth: "1.5",
11887
- strokeLinecap: "round",
11888
- strokeLinejoin: "round"
11889
- }
11890
- ) }),
11891
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11892
- "path",
11893
- {
11894
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11895
- stroke: "#A1A1AA",
11896
- strokeWidth: "1.5",
11897
- strokeLinecap: "round",
11898
- strokeLinejoin: "round"
11899
- }
11900
- ) }),
11901
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
11902
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11903
- "rect",
11904
- {
11905
- width: "12",
11906
- height: "12",
11907
- fill: "white",
11908
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11909
- }
11910
- ) }),
11911
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11912
- "rect",
11913
- {
11914
- width: "12",
11915
- height: "12",
11916
- fill: "white",
11917
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11918
- }
11919
- ) }),
11920
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11921
- "rect",
11922
- {
11923
- width: "12",
11924
- height: "12",
11925
- fill: "white",
11926
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11927
- }
11928
- ) }),
11929
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11930
- "rect",
11931
- {
11932
- width: "12",
11933
- height: "12",
11934
- fill: "white",
11935
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
11936
- }
11937
- ) }),
11938
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11939
- "rect",
11940
- {
11941
- width: "12",
11942
- height: "12",
11943
- fill: "white",
11944
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
11945
- }
11946
- ) }),
11947
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11948
- "rect",
11949
- {
11950
- width: "12",
11951
- height: "12",
11952
- fill: "white",
11953
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
11954
- }
11955
- ) })
11956
- ] })
11957
- ]
11958
- }
11959
- );
11960
- };
11961
- const schema = objectType({
11962
- customer_id: stringType().min(1)
11963
- });
11964
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11965
- const Shipping = () => {
11966
- var _a;
11967
- const { id } = reactRouterDom.useParams();
11968
- const { order, isPending, isError, error } = useOrder(id, {
11969
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11970
- });
11971
- const {
11972
- order: preview,
11973
- isPending: isPreviewPending,
11974
- isError: isPreviewError,
11975
- error: previewError
11976
- } = useOrderPreview(id);
11977
- useInitiateOrderEdit({ preview });
11978
- const { onCancel } = useCancelOrderEdit({ preview });
11979
- if (isError) {
11980
- throw error;
11981
- }
11982
- if (isPreviewError) {
11983
- throw previewError;
11984
- }
11985
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11986
- const isReady = preview && !isPreviewPending && order && !isPending;
11987
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11988
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11989
- /* @__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: [
11990
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11991
- /* @__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." }) })
11992
- ] }) }) }),
11993
- /* @__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" }) }) })
11994
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11995
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11996
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11997
- ] }) });
11998
- };
11999
- const ShippingForm = ({ preview, order }) => {
12000
- var _a;
12001
- const { setIsOpen } = useStackedModal();
12002
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12003
- const [data, setData] = React.useState(null);
12004
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12005
- const { shipping_options } = useShippingOptions(
12006
- {
12007
- id: appliedShippingOptionIds,
12008
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12009
- },
12010
- {
12011
- enabled: appliedShippingOptionIds.length > 0
12012
- }
12013
- );
12014
- const uniqueShippingProfiles = React.useMemo(() => {
12015
- const profiles = /* @__PURE__ */ new Map();
12016
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12017
- profiles.set(profile.id, profile);
12018
- });
12019
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12020
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12021
- });
12022
- return Array.from(profiles.values());
12023
- }, [order.items, shipping_options]);
12024
- const { handleSuccess } = useRouteModal();
12025
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12026
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12027
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12028
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12029
- const onSubmit = async () => {
12030
- setIsSubmitting(true);
12031
- let requestSucceeded = false;
12032
- await requestOrderEdit(void 0, {
12033
- onError: (e) => {
12034
- ui.toast.error(`Failed to request order edit: ${e.message}`);
12035
- },
12036
- onSuccess: () => {
12037
- requestSucceeded = true;
12038
- }
12039
- });
12040
- if (!requestSucceeded) {
12041
- setIsSubmitting(false);
12042
- return;
12043
- }
12044
- await confirmOrderEdit(void 0, {
12045
- onError: (e) => {
12046
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12047
- },
12048
- onSuccess: () => {
12049
- handleSuccess();
12050
- },
12051
- onSettled: () => {
12052
- setIsSubmitting(false);
12053
- }
12054
- });
12055
- };
12056
- const onKeydown = React.useCallback(
12057
- (e) => {
12058
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12059
- if (data || isSubmitting) {
12060
- return;
12061
- }
12062
- onSubmit();
12063
- }
12064
- },
12065
- [data, isSubmitting, onSubmit]
11663
+ [data, isSubmitting, onSubmit]
12066
11664
  );
12067
11665
  React.useEffect(() => {
12068
11666
  document.addEventListener("keydown", onKeydown);
@@ -12754,297 +12352,699 @@ const CustomAmountField = ({
12754
12352
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12755
12353
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12756
12354
  ] }),
12757
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12758
- ui.CurrencyInput,
12355
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12356
+ ui.CurrencyInput,
12357
+ {
12358
+ ...field,
12359
+ onValueChange: (value) => onChange(value),
12360
+ symbol: getNativeSymbol(currencyCode),
12361
+ code: currencyCode
12362
+ }
12363
+ ) })
12364
+ ] });
12365
+ }
12366
+ }
12367
+ );
12368
+ };
12369
+ const ShippingAddress = () => {
12370
+ const { id } = reactRouterDom.useParams();
12371
+ const { order, isPending, isError, error } = useOrder(id, {
12372
+ fields: "+shipping_address"
12373
+ });
12374
+ if (isError) {
12375
+ throw error;
12376
+ }
12377
+ const isReady = !isPending && !!order;
12378
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12379
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12380
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12381
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12382
+ ] }),
12383
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12384
+ ] });
12385
+ };
12386
+ const ShippingAddressForm = ({ order }) => {
12387
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12388
+ const form = reactHookForm.useForm({
12389
+ defaultValues: {
12390
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12391
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12392
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12393
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12394
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12395
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12396
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12397
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12398
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12399
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12400
+ },
12401
+ resolver: zod.zodResolver(schema$1)
12402
+ });
12403
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12404
+ const { handleSuccess } = useRouteModal();
12405
+ const onSubmit = form.handleSubmit(async (data) => {
12406
+ await mutateAsync(
12407
+ {
12408
+ shipping_address: {
12409
+ first_name: data.first_name,
12410
+ last_name: data.last_name,
12411
+ company: data.company,
12412
+ address_1: data.address_1,
12413
+ address_2: data.address_2,
12414
+ city: data.city,
12415
+ province: data.province,
12416
+ country_code: data.country_code,
12417
+ postal_code: data.postal_code,
12418
+ phone: data.phone
12419
+ }
12420
+ },
12421
+ {
12422
+ onSuccess: () => {
12423
+ handleSuccess();
12424
+ },
12425
+ onError: (error) => {
12426
+ ui.toast.error(error.message);
12427
+ }
12428
+ }
12429
+ );
12430
+ });
12431
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12432
+ KeyboundForm,
12433
+ {
12434
+ className: "flex flex-1 flex-col overflow-hidden",
12435
+ onSubmit,
12436
+ children: [
12437
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12438
+ /* @__PURE__ */ jsxRuntime.jsx(
12439
+ Form$2.Field,
12440
+ {
12441
+ control: form.control,
12442
+ name: "country_code",
12443
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12447
+ ] })
12448
+ }
12449
+ ),
12450
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12451
+ /* @__PURE__ */ jsxRuntime.jsx(
12452
+ Form$2.Field,
12453
+ {
12454
+ control: form.control,
12455
+ name: "first_name",
12456
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12459
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12460
+ ] })
12461
+ }
12462
+ ),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(
12464
+ Form$2.Field,
12465
+ {
12466
+ control: form.control,
12467
+ name: "last_name",
12468
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12470
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12471
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12472
+ ] })
12473
+ }
12474
+ )
12475
+ ] }),
12476
+ /* @__PURE__ */ jsxRuntime.jsx(
12477
+ Form$2.Field,
12478
+ {
12479
+ control: form.control,
12480
+ name: "company",
12481
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12484
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12485
+ ] })
12486
+ }
12487
+ ),
12488
+ /* @__PURE__ */ jsxRuntime.jsx(
12489
+ Form$2.Field,
12490
+ {
12491
+ control: form.control,
12492
+ name: "address_1",
12493
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12496
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12497
+ ] })
12498
+ }
12499
+ ),
12500
+ /* @__PURE__ */ jsxRuntime.jsx(
12501
+ Form$2.Field,
12502
+ {
12503
+ control: form.control,
12504
+ name: "address_2",
12505
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12509
+ ] })
12510
+ }
12511
+ ),
12512
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12513
+ /* @__PURE__ */ jsxRuntime.jsx(
12514
+ Form$2.Field,
12515
+ {
12516
+ control: form.control,
12517
+ name: "postal_code",
12518
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12521
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12522
+ ] })
12523
+ }
12524
+ ),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(
12526
+ Form$2.Field,
12527
+ {
12528
+ control: form.control,
12529
+ name: "city",
12530
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12533
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12534
+ ] })
12535
+ }
12536
+ )
12537
+ ] }),
12538
+ /* @__PURE__ */ jsxRuntime.jsx(
12539
+ Form$2.Field,
12759
12540
  {
12760
- ...field,
12761
- onValueChange: (value) => onChange(value),
12762
- symbol: getNativeSymbol(currencyCode),
12763
- code: currencyCode
12541
+ control: form.control,
12542
+ name: "province",
12543
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12546
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12547
+ ] })
12764
12548
  }
12765
- ) })
12766
- ] });
12767
- }
12549
+ ),
12550
+ /* @__PURE__ */ jsxRuntime.jsx(
12551
+ Form$2.Field,
12552
+ {
12553
+ control: form.control,
12554
+ name: "phone",
12555
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12558
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12559
+ ] })
12560
+ }
12561
+ )
12562
+ ] }) }),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12564
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12565
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12566
+ ] }) })
12567
+ ]
12768
12568
  }
12769
- );
12770
- };
12771
- const PROMOTION_QUERY_KEY = "promotions";
12772
- const promotionsQueryKeys = {
12773
- list: (query2) => [
12774
- PROMOTION_QUERY_KEY,
12775
- query2 ? query2 : void 0
12776
- ],
12777
- detail: (id, query2) => [
12778
- PROMOTION_QUERY_KEY,
12779
- id,
12780
- query2 ? query2 : void 0
12781
- ]
12782
- };
12783
- const usePromotions = (query2, options) => {
12784
- const { data, ...rest } = reactQuery.useQuery({
12785
- queryKey: promotionsQueryKeys.list(query2),
12786
- queryFn: async () => sdk.admin.promotion.list(query2),
12787
- ...options
12788
- });
12789
- return { ...data, ...rest };
12569
+ ) });
12790
12570
  };
12791
- const Promotions = () => {
12571
+ const schema$1 = addressSchema;
12572
+ const TransferOwnership = () => {
12792
12573
  const { id } = reactRouterDom.useParams();
12793
- const {
12794
- order: preview,
12795
- isError: isPreviewError,
12796
- error: previewError
12797
- } = useOrderPreview(id, void 0);
12798
- useInitiateOrderEdit({ preview });
12799
- const { onCancel } = useCancelOrderEdit({ preview });
12800
- if (isPreviewError) {
12801
- throw previewError;
12574
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12575
+ fields: "id,customer_id,customer.*"
12576
+ });
12577
+ if (isError) {
12578
+ throw error;
12802
12579
  }
12803
- const isReady = !!preview;
12804
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12805
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12806
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12580
+ const isReady = !isPending && !!draft_order;
12581
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12582
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12583
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12584
+ /* @__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" }) })
12585
+ ] }),
12586
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12807
12587
  ] });
12808
12588
  };
12809
- const PromotionForm = ({ preview }) => {
12810
- const { items, shipping_methods } = preview;
12811
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12812
- const [comboboxValue, setComboboxValue] = React.useState("");
12813
- const { handleSuccess } = useRouteModal();
12814
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12815
- const promoIds = getPromotionIds(items, shipping_methods);
12816
- const { promotions, isPending, isError, error } = usePromotions(
12817
- {
12818
- id: promoIds
12589
+ const TransferOwnershipForm = ({ order }) => {
12590
+ var _a, _b;
12591
+ const form = reactHookForm.useForm({
12592
+ defaultValues: {
12593
+ customer_id: order.customer_id || ""
12819
12594
  },
12595
+ resolver: zod.zodResolver(schema)
12596
+ });
12597
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12598
+ const { handleSuccess } = useRouteModal();
12599
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12600
+ const currentCustomer = order.customer ? {
12601
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12602
+ value: order.customer.id
12603
+ } : null;
12604
+ const onSubmit = form.handleSubmit(async (data) => {
12605
+ await mutateAsync(
12606
+ { customer_id: data.customer_id },
12607
+ {
12608
+ onSuccess: () => {
12609
+ ui.toast.success("Customer updated");
12610
+ handleSuccess();
12611
+ },
12612
+ onError: (error) => {
12613
+ ui.toast.error(error.message);
12614
+ }
12615
+ }
12616
+ );
12617
+ });
12618
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12619
+ KeyboundForm,
12820
12620
  {
12821
- enabled: !!promoIds.length
12621
+ className: "flex flex-1 flex-col overflow-hidden",
12622
+ onSubmit,
12623
+ children: [
12624
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12625
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12626
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12627
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12628
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12629
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12630
+ ] }),
12631
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12632
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12633
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12634
+ ] })
12635
+ ] }),
12636
+ /* @__PURE__ */ jsxRuntime.jsx(
12637
+ CustomerField,
12638
+ {
12639
+ control: form.control,
12640
+ currentCustomerId: order.customer_id
12641
+ }
12642
+ )
12643
+ ] }),
12644
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12645
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12646
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12647
+ ] }) })
12648
+ ]
12822
12649
  }
12823
- );
12824
- const comboboxData = useComboboxData({
12825
- queryKey: ["promotions", "combobox", promoIds],
12650
+ ) });
12651
+ };
12652
+ const CustomerField = ({ control, currentCustomerId }) => {
12653
+ const customers = useComboboxData({
12826
12654
  queryFn: async (params) => {
12827
- return await sdk.admin.promotion.list({
12655
+ return await sdk.admin.customer.list({
12828
12656
  ...params,
12829
- id: {
12830
- $nin: promoIds
12831
- }
12657
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12832
12658
  });
12833
12659
  },
12660
+ queryKey: ["customers"],
12834
12661
  getOptions: (data) => {
12835
- return data.promotions.map((promotion) => ({
12836
- label: promotion.code,
12837
- value: promotion.code
12838
- }));
12662
+ return data.customers.map((customer) => {
12663
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12664
+ return {
12665
+ label: name ? `${name} (${customer.email})` : customer.email,
12666
+ value: customer.id
12667
+ };
12668
+ });
12839
12669
  }
12840
12670
  });
12841
- const add = async (value) => {
12842
- if (!value) {
12843
- return;
12844
- }
12845
- addPromotions(
12846
- {
12847
- promo_codes: [value]
12848
- },
12849
- {
12850
- onError: (e) => {
12851
- ui.toast.error(e.message);
12852
- comboboxData.onSearchValueChange("");
12853
- setComboboxValue("");
12854
- },
12855
- onSuccess: () => {
12856
- comboboxData.onSearchValueChange("");
12857
- setComboboxValue("");
12858
- }
12859
- }
12860
- );
12861
- };
12862
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12863
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12864
- const onSubmit = async () => {
12865
- setIsSubmitting(true);
12866
- let requestSucceeded = false;
12867
- await requestOrderEdit(void 0, {
12868
- onError: (e) => {
12869
- ui.toast.error(e.message);
12870
- },
12871
- onSuccess: () => {
12872
- requestSucceeded = true;
12873
- }
12874
- });
12875
- if (!requestSucceeded) {
12876
- setIsSubmitting(false);
12877
- return;
12878
- }
12879
- await confirmOrderEdit(void 0, {
12880
- onError: (e) => {
12881
- ui.toast.error(e.message);
12882
- },
12883
- onSuccess: () => {
12884
- handleSuccess();
12885
- },
12886
- onSettled: () => {
12887
- setIsSubmitting(false);
12888
- }
12889
- });
12890
- };
12891
- if (isError) {
12892
- throw error;
12893
- }
12894
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12895
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12896
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12671
+ return /* @__PURE__ */ jsxRuntime.jsx(
12672
+ Form$2.Field,
12673
+ {
12674
+ name: "customer_id",
12675
+ control,
12676
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12897
12677
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12898
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12899
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12678
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12679
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12900
12680
  ] }),
12681
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12682
+ Combobox,
12683
+ {
12684
+ options: customers.options,
12685
+ fetchNextPage: customers.fetchNextPage,
12686
+ isFetchingNextPage: customers.isFetchingNextPage,
12687
+ searchValue: customers.searchValue,
12688
+ onSearchValueChange: customers.onSearchValueChange,
12689
+ placeholder: "Select customer",
12690
+ ...field
12691
+ }
12692
+ ) }),
12693
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12694
+ ] })
12695
+ }
12696
+ );
12697
+ };
12698
+ const Illustration = () => {
12699
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12700
+ "svg",
12701
+ {
12702
+ width: "280",
12703
+ height: "180",
12704
+ viewBox: "0 0 280 180",
12705
+ fill: "none",
12706
+ xmlns: "http://www.w3.org/2000/svg",
12707
+ children: [
12901
12708
  /* @__PURE__ */ jsxRuntime.jsx(
12902
- Combobox,
12709
+ "rect",
12710
+ {
12711
+ x: "0.00428286",
12712
+ y: "-0.742904",
12713
+ width: "33.5",
12714
+ height: "65.5",
12715
+ rx: "6.75",
12716
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12717
+ fill: "#D4D4D8",
12718
+ stroke: "#52525B",
12719
+ strokeWidth: "1.5"
12720
+ }
12721
+ ),
12722
+ /* @__PURE__ */ jsxRuntime.jsx(
12723
+ "rect",
12724
+ {
12725
+ x: "0.00428286",
12726
+ y: "-0.742904",
12727
+ width: "33.5",
12728
+ height: "65.5",
12729
+ rx: "6.75",
12730
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12731
+ fill: "white",
12732
+ stroke: "#52525B",
12733
+ strokeWidth: "1.5"
12734
+ }
12735
+ ),
12736
+ /* @__PURE__ */ jsxRuntime.jsx(
12737
+ "path",
12738
+ {
12739
+ d: "M180.579 107.142L179.126 107.959",
12740
+ stroke: "#52525B",
12741
+ strokeWidth: "1.5",
12742
+ strokeLinecap: "round",
12743
+ strokeLinejoin: "round"
12744
+ }
12745
+ ),
12746
+ /* @__PURE__ */ jsxRuntime.jsx(
12747
+ "path",
12748
+ {
12749
+ opacity: "0.88",
12750
+ d: "M182.305 109.546L180.257 109.534",
12751
+ stroke: "#52525B",
12752
+ strokeWidth: "1.5",
12753
+ strokeLinecap: "round",
12754
+ strokeLinejoin: "round"
12755
+ }
12756
+ ),
12757
+ /* @__PURE__ */ jsxRuntime.jsx(
12758
+ "path",
12759
+ {
12760
+ opacity: "0.75",
12761
+ d: "M180.551 111.93L179.108 111.096",
12762
+ stroke: "#52525B",
12763
+ strokeWidth: "1.5",
12764
+ strokeLinecap: "round",
12765
+ strokeLinejoin: "round"
12766
+ }
12767
+ ),
12768
+ /* @__PURE__ */ jsxRuntime.jsx(
12769
+ "path",
12770
+ {
12771
+ opacity: "0.63",
12772
+ d: "M176.347 112.897L176.354 111.73",
12773
+ stroke: "#52525B",
12774
+ strokeWidth: "1.5",
12775
+ strokeLinecap: "round",
12776
+ strokeLinejoin: "round"
12777
+ }
12778
+ ),
12779
+ /* @__PURE__ */ jsxRuntime.jsx(
12780
+ "path",
12781
+ {
12782
+ opacity: "0.5",
12783
+ d: "M172.153 111.881L173.606 111.064",
12784
+ stroke: "#52525B",
12785
+ strokeWidth: "1.5",
12786
+ strokeLinecap: "round",
12787
+ strokeLinejoin: "round"
12788
+ }
12789
+ ),
12790
+ /* @__PURE__ */ jsxRuntime.jsx(
12791
+ "path",
12792
+ {
12793
+ opacity: "0.38",
12794
+ d: "M170.428 109.478L172.476 109.489",
12795
+ stroke: "#52525B",
12796
+ strokeWidth: "1.5",
12797
+ strokeLinecap: "round",
12798
+ strokeLinejoin: "round"
12799
+ }
12800
+ ),
12801
+ /* @__PURE__ */ jsxRuntime.jsx(
12802
+ "path",
12803
+ {
12804
+ opacity: "0.25",
12805
+ d: "M172.181 107.094L173.624 107.928",
12806
+ stroke: "#52525B",
12807
+ strokeWidth: "1.5",
12808
+ strokeLinecap: "round",
12809
+ strokeLinejoin: "round"
12810
+ }
12811
+ ),
12812
+ /* @__PURE__ */ jsxRuntime.jsx(
12813
+ "path",
12814
+ {
12815
+ opacity: "0.13",
12816
+ d: "M176.386 106.126L176.379 107.294",
12817
+ stroke: "#52525B",
12818
+ strokeWidth: "1.5",
12819
+ strokeLinecap: "round",
12820
+ strokeLinejoin: "round"
12821
+ }
12822
+ ),
12823
+ /* @__PURE__ */ jsxRuntime.jsx(
12824
+ "rect",
12825
+ {
12826
+ width: "12",
12827
+ height: "3",
12828
+ rx: "1.5",
12829
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12830
+ fill: "#D4D4D8"
12831
+ }
12832
+ ),
12833
+ /* @__PURE__ */ jsxRuntime.jsx(
12834
+ "rect",
12835
+ {
12836
+ x: "0.00428286",
12837
+ y: "-0.742904",
12838
+ width: "33.5",
12839
+ height: "65.5",
12840
+ rx: "6.75",
12841
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12842
+ fill: "#D4D4D8",
12843
+ stroke: "#52525B",
12844
+ strokeWidth: "1.5"
12845
+ }
12846
+ ),
12847
+ /* @__PURE__ */ jsxRuntime.jsx(
12848
+ "rect",
12849
+ {
12850
+ x: "0.00428286",
12851
+ y: "-0.742904",
12852
+ width: "33.5",
12853
+ height: "65.5",
12854
+ rx: "6.75",
12855
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12856
+ fill: "white",
12857
+ stroke: "#52525B",
12858
+ strokeWidth: "1.5"
12859
+ }
12860
+ ),
12861
+ /* @__PURE__ */ jsxRuntime.jsx(
12862
+ "rect",
12863
+ {
12864
+ width: "12",
12865
+ height: "3",
12866
+ rx: "1.5",
12867
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12868
+ fill: "#D4D4D8"
12869
+ }
12870
+ ),
12871
+ /* @__PURE__ */ jsxRuntime.jsx(
12872
+ "rect",
12873
+ {
12874
+ width: "17",
12875
+ height: "3",
12876
+ rx: "1.5",
12877
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12878
+ fill: "#D4D4D8"
12879
+ }
12880
+ ),
12881
+ /* @__PURE__ */ jsxRuntime.jsx(
12882
+ "rect",
12883
+ {
12884
+ width: "12",
12885
+ height: "3",
12886
+ rx: "1.5",
12887
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12888
+ fill: "#D4D4D8"
12889
+ }
12890
+ ),
12891
+ /* @__PURE__ */ jsxRuntime.jsx(
12892
+ "path",
12893
+ {
12894
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12895
+ fill: "#A1A1AA"
12896
+ }
12897
+ ),
12898
+ /* @__PURE__ */ jsxRuntime.jsx(
12899
+ "rect",
12900
+ {
12901
+ width: "17",
12902
+ height: "3",
12903
+ rx: "1.5",
12904
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12905
+ fill: "#A1A1AA"
12906
+ }
12907
+ ),
12908
+ /* @__PURE__ */ jsxRuntime.jsx(
12909
+ "rect",
12910
+ {
12911
+ width: "12",
12912
+ height: "3",
12913
+ rx: "1.5",
12914
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12915
+ fill: "#A1A1AA"
12916
+ }
12917
+ ),
12918
+ /* @__PURE__ */ jsxRuntime.jsx(
12919
+ "path",
12920
+ {
12921
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12922
+ fill: "#52525B"
12923
+ }
12924
+ ),
12925
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12926
+ "path",
12927
+ {
12928
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12929
+ stroke: "#A1A1AA",
12930
+ strokeWidth: "1.5",
12931
+ strokeLinecap: "round",
12932
+ strokeLinejoin: "round"
12933
+ }
12934
+ ) }),
12935
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12936
+ "path",
12937
+ {
12938
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12939
+ stroke: "#A1A1AA",
12940
+ strokeWidth: "1.5",
12941
+ strokeLinecap: "round",
12942
+ strokeLinejoin: "round"
12943
+ }
12944
+ ) }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12946
+ "path",
12903
12947
  {
12904
- id: "promotion-combobox",
12905
- "aria-describedby": "promotion-combobox-hint",
12906
- isFetchingNextPage: comboboxData.isFetchingNextPage,
12907
- fetchNextPage: comboboxData.fetchNextPage,
12908
- options: comboboxData.options,
12909
- onSearchValueChange: comboboxData.onSearchValueChange,
12910
- searchValue: comboboxData.searchValue,
12911
- disabled: comboboxData.disabled || isAddingPromotions,
12912
- onChange: add,
12913
- value: comboboxValue
12948
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12949
+ stroke: "#A1A1AA",
12950
+ strokeWidth: "1.5",
12951
+ strokeLinecap: "round",
12952
+ strokeLinejoin: "round"
12914
12953
  }
12915
- )
12916
- ] }),
12917
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12918
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12919
- PromotionItem,
12920
- {
12921
- promotion,
12922
- orderId: preview.id,
12923
- isLoading: isPending
12924
- },
12925
- promotion.id
12926
- )) })
12927
- ] }) }),
12928
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12929
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12930
- /* @__PURE__ */ jsxRuntime.jsx(
12931
- ui.Button,
12932
- {
12933
- size: "small",
12934
- type: "submit",
12935
- isLoading: isSubmitting || isAddingPromotions,
12936
- children: "Save"
12937
- }
12938
- )
12939
- ] }) })
12940
- ] });
12941
- };
12942
- const PromotionItem = ({
12943
- promotion,
12944
- orderId,
12945
- isLoading
12946
- }) => {
12947
- var _a;
12948
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12949
- const onRemove = async () => {
12950
- removePromotions(
12951
- {
12952
- promo_codes: [promotion.code]
12953
- },
12954
- {
12955
- onError: (e) => {
12956
- ui.toast.error(e.message);
12957
- }
12958
- }
12959
- );
12960
- };
12961
- const displayValue = getDisplayValue(promotion);
12962
- return /* @__PURE__ */ jsxRuntime.jsxs(
12963
- "div",
12964
- {
12965
- className: ui.clx(
12966
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12967
- {
12968
- "animate-pulse": isLoading
12969
- }
12970
- ),
12971
- children: [
12972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12973
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12974
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12975
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12976
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12978
- ] }),
12979
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12980
- ] })
12981
- ] }),
12982
- /* @__PURE__ */ jsxRuntime.jsx(
12983
- ui.IconButton,
12954
+ ) }),
12955
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12956
+ "path",
12984
12957
  {
12985
- size: "small",
12986
- type: "button",
12987
- variant: "transparent",
12988
- onClick: onRemove,
12989
- isLoading: isPending || isLoading,
12990
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12958
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12959
+ stroke: "#A1A1AA",
12960
+ strokeWidth: "1.5",
12961
+ strokeLinecap: "round",
12962
+ strokeLinejoin: "round"
12991
12963
  }
12992
- )
12964
+ ) }),
12965
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12966
+ "path",
12967
+ {
12968
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12969
+ stroke: "#A1A1AA",
12970
+ strokeWidth: "1.5",
12971
+ strokeLinecap: "round",
12972
+ strokeLinejoin: "round"
12973
+ }
12974
+ ) }),
12975
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12976
+ "path",
12977
+ {
12978
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12979
+ stroke: "#A1A1AA",
12980
+ strokeWidth: "1.5",
12981
+ strokeLinecap: "round",
12982
+ strokeLinejoin: "round"
12983
+ }
12984
+ ) }),
12985
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12986
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12987
+ "rect",
12988
+ {
12989
+ width: "12",
12990
+ height: "12",
12991
+ fill: "white",
12992
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12993
+ }
12994
+ ) }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12996
+ "rect",
12997
+ {
12998
+ width: "12",
12999
+ height: "12",
13000
+ fill: "white",
13001
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13002
+ }
13003
+ ) }),
13004
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13005
+ "rect",
13006
+ {
13007
+ width: "12",
13008
+ height: "12",
13009
+ fill: "white",
13010
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13011
+ }
13012
+ ) }),
13013
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13014
+ "rect",
13015
+ {
13016
+ width: "12",
13017
+ height: "12",
13018
+ fill: "white",
13019
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13020
+ }
13021
+ ) }),
13022
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13023
+ "rect",
13024
+ {
13025
+ width: "12",
13026
+ height: "12",
13027
+ fill: "white",
13028
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13029
+ }
13030
+ ) }),
13031
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13032
+ "rect",
13033
+ {
13034
+ width: "12",
13035
+ height: "12",
13036
+ fill: "white",
13037
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13038
+ }
13039
+ ) })
13040
+ ] })
12993
13041
  ]
12994
- },
12995
- promotion.id
13042
+ }
12996
13043
  );
12997
13044
  };
12998
- function getDisplayValue(promotion) {
12999
- var _a, _b, _c, _d;
13000
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
13001
- if (!value) {
13002
- return null;
13003
- }
13004
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
13005
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13006
- if (!currency) {
13007
- return null;
13008
- }
13009
- return getLocaleAmount(value, currency);
13010
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13011
- return formatPercentage(value);
13012
- }
13013
- return null;
13014
- }
13015
- const formatter = new Intl.NumberFormat([], {
13016
- style: "percent",
13017
- minimumFractionDigits: 2
13045
+ const schema = objectType({
13046
+ customer_id: stringType().min(1)
13018
13047
  });
13019
- const formatPercentage = (value, isPercentageValue = false) => {
13020
- let val = value || 0;
13021
- if (!isPercentageValue) {
13022
- val = val / 100;
13023
- }
13024
- return formatter.format(val);
13025
- };
13026
- function getPromotionIds(items, shippingMethods) {
13027
- const promotionIds = /* @__PURE__ */ new Set();
13028
- for (const item of items) {
13029
- if (item.adjustments) {
13030
- for (const adjustment of item.adjustments) {
13031
- if (adjustment.promotion_id) {
13032
- promotionIds.add(adjustment.promotion_id);
13033
- }
13034
- }
13035
- }
13036
- }
13037
- for (const shippingMethod of shippingMethods) {
13038
- if (shippingMethod.adjustments) {
13039
- for (const adjustment of shippingMethod.adjustments) {
13040
- if (adjustment.promotion_id) {
13041
- promotionIds.add(adjustment.promotion_id);
13042
- }
13043
- }
13044
- }
13045
- }
13046
- return Array.from(promotionIds);
13047
- }
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13065,14 +13065,14 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
- {
13069
- Component: BillingAddress,
13070
- path: "/draft-orders/:id/billing-address"
13071
- },
13072
13068
  {
13073
13069
  Component: CustomItems,
13074
13070
  path: "/draft-orders/:id/custom-items"
13075
13071
  },
13072
+ {
13073
+ Component: BillingAddress,
13074
+ path: "/draft-orders/:id/billing-address"
13075
+ },
13076
13076
  {
13077
13077
  Component: Email,
13078
13078
  path: "/draft-orders/:id/email"
@@ -13085,10 +13085,18 @@ const routeModule = {
13085
13085
  Component: Metadata,
13086
13086
  path: "/draft-orders/:id/metadata"
13087
13087
  },
13088
+ {
13089
+ Component: Promotions,
13090
+ path: "/draft-orders/:id/promotions"
13091
+ },
13088
13092
  {
13089
13093
  Component: SalesChannel,
13090
13094
  path: "/draft-orders/:id/sales-channel"
13091
13095
  },
13096
+ {
13097
+ Component: Shipping,
13098
+ path: "/draft-orders/:id/shipping"
13099
+ },
13092
13100
  {
13093
13101
  Component: ShippingAddress,
13094
13102
  path: "/draft-orders/:id/shipping-address"
@@ -13096,14 +13104,6 @@ const routeModule = {
13096
13104
  {
13097
13105
  Component: TransferOwnership,
13098
13106
  path: "/draft-orders/:id/transfer-ownership"
13099
- },
13100
- {
13101
- Component: Shipping,
13102
- path: "/draft-orders/:id/shipping"
13103
- },
13104
- {
13105
- Component: Promotions,
13106
- path: "/draft-orders/:id/promotions"
13107
13107
  }
13108
13108
  ]
13109
13109
  }