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

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.
@@ -11170,323 +11170,166 @@ function getHasUneditableRows(metadata) {
11170
11170
  (value) => !EDITABLE_TYPES.includes(typeof value)
11171
11171
  );
11172
11172
  }
11173
- const PROMOTION_QUERY_KEY = "promotions";
11174
- const promotionsQueryKeys = {
11175
- list: (query2) => [
11176
- PROMOTION_QUERY_KEY,
11177
- query2 ? query2 : void 0
11178
- ],
11179
- detail: (id, query2) => [
11180
- PROMOTION_QUERY_KEY,
11181
- id,
11182
- query2 ? query2 : void 0
11183
- ]
11184
- };
11185
- const usePromotions = (query2, options) => {
11186
- const { data, ...rest } = useQuery({
11187
- queryKey: promotionsQueryKeys.list(query2),
11188
- queryFn: async () => sdk.admin.promotion.list(query2),
11189
- ...options
11190
- });
11191
- return { ...data, ...rest };
11192
- };
11193
- const Promotions = () => {
11173
+ const SalesChannel = () => {
11194
11174
  const { id } = useParams();
11195
- const {
11196
- order: preview,
11197
- isError: isPreviewError,
11198
- error: previewError
11199
- } = useOrderPreview(id, void 0);
11200
- useInitiateOrderEdit({ preview });
11201
- const { onCancel } = useCancelOrderEdit({ preview });
11202
- if (isPreviewError) {
11203
- throw previewError;
11204
- }
11205
- const isReady = !!preview;
11206
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11207
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11208
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11209
- ] });
11210
- };
11211
- const PromotionForm = ({ preview }) => {
11212
- const { items, shipping_methods } = preview;
11213
- const [isSubmitting, setIsSubmitting] = useState(false);
11214
- const [comboboxValue, setComboboxValue] = useState("");
11215
- const { handleSuccess } = useRouteModal();
11216
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11217
- const promoIds = getPromotionIds(items, shipping_methods);
11218
- const { promotions, isPending, isError, error } = usePromotions(
11175
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11176
+ id,
11219
11177
  {
11220
- id: promoIds
11178
+ fields: "+sales_channel_id"
11221
11179
  },
11222
11180
  {
11223
- enabled: !!promoIds.length
11181
+ enabled: !!id
11224
11182
  }
11225
11183
  );
11226
- const comboboxData = useComboboxData({
11227
- queryKey: ["promotions", "combobox", promoIds],
11228
- queryFn: async (params) => {
11229
- return await sdk.admin.promotion.list({
11230
- ...params,
11231
- id: {
11232
- $nin: promoIds
11233
- }
11234
- });
11184
+ if (isError) {
11185
+ throw error;
11186
+ }
11187
+ const ISrEADY = !!draft_order && !isPending;
11188
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11189
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11190
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11191
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11192
+ ] }),
11193
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11194
+ ] });
11195
+ };
11196
+ const SalesChannelForm = ({ order }) => {
11197
+ const form = useForm({
11198
+ defaultValues: {
11199
+ sales_channel_id: order.sales_channel_id || ""
11235
11200
  },
11236
- getOptions: (data) => {
11237
- return data.promotions.map((promotion) => ({
11238
- label: promotion.code,
11239
- value: promotion.code
11240
- }));
11241
- }
11201
+ resolver: zodResolver(schema$2)
11242
11202
  });
11243
- const add = async (value) => {
11244
- if (!value) {
11245
- return;
11246
- }
11247
- addPromotions(
11203
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11204
+ const { handleSuccess } = useRouteModal();
11205
+ const onSubmit = form.handleSubmit(async (data) => {
11206
+ await mutateAsync(
11248
11207
  {
11249
- promo_codes: [value]
11208
+ sales_channel_id: data.sales_channel_id
11250
11209
  },
11251
11210
  {
11252
- onError: (e) => {
11253
- toast.error(e.message);
11254
- comboboxData.onSearchValueChange("");
11255
- setComboboxValue("");
11256
- },
11257
11211
  onSuccess: () => {
11258
- comboboxData.onSearchValueChange("");
11259
- setComboboxValue("");
11212
+ toast.success("Sales channel updated");
11213
+ handleSuccess();
11214
+ },
11215
+ onError: (error) => {
11216
+ toast.error(error.message);
11260
11217
  }
11261
11218
  }
11262
11219
  );
11263
- };
11264
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11265
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11266
- const onSubmit = async () => {
11267
- setIsSubmitting(true);
11268
- let requestSucceeded = false;
11269
- await requestOrderEdit(void 0, {
11270
- onError: (e) => {
11271
- toast.error(e.message);
11272
- },
11273
- onSuccess: () => {
11274
- requestSucceeded = true;
11275
- }
11276
- });
11277
- if (!requestSucceeded) {
11278
- setIsSubmitting(false);
11279
- return;
11220
+ });
11221
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11222
+ KeyboundForm,
11223
+ {
11224
+ className: "flex flex-1 flex-col overflow-hidden",
11225
+ onSubmit,
11226
+ children: [
11227
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11228
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11229
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11230
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11231
+ ] }) })
11232
+ ]
11280
11233
  }
11281
- await confirmOrderEdit(void 0, {
11282
- onError: (e) => {
11283
- toast.error(e.message);
11284
- },
11285
- onSuccess: () => {
11286
- handleSuccess();
11287
- },
11288
- onSettled: () => {
11289
- setIsSubmitting(false);
11234
+ ) });
11235
+ };
11236
+ const SalesChannelField = ({ control, order }) => {
11237
+ const salesChannels = useComboboxData({
11238
+ queryFn: async (params) => {
11239
+ return await sdk.admin.salesChannel.list(params);
11240
+ },
11241
+ queryKey: ["sales-channels"],
11242
+ getOptions: (data) => {
11243
+ return data.sales_channels.map((salesChannel) => ({
11244
+ label: salesChannel.name,
11245
+ value: salesChannel.id
11246
+ }));
11247
+ },
11248
+ defaultValue: order.sales_channel_id || void 0
11249
+ });
11250
+ return /* @__PURE__ */ jsx(
11251
+ Form$2.Field,
11252
+ {
11253
+ control,
11254
+ name: "sales_channel_id",
11255
+ render: ({ field }) => {
11256
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11257
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11258
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11259
+ Combobox,
11260
+ {
11261
+ options: salesChannels.options,
11262
+ fetchNextPage: salesChannels.fetchNextPage,
11263
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11264
+ searchValue: salesChannels.searchValue,
11265
+ onSearchValueChange: salesChannels.onSearchValueChange,
11266
+ placeholder: "Select sales channel",
11267
+ ...field
11268
+ }
11269
+ ) }),
11270
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11271
+ ] });
11290
11272
  }
11291
- });
11292
- };
11273
+ }
11274
+ );
11275
+ };
11276
+ const schema$2 = objectType({
11277
+ sales_channel_id: stringType().min(1)
11278
+ });
11279
+ const ShippingAddress = () => {
11280
+ const { id } = useParams();
11281
+ const { order, isPending, isError, error } = useOrder(id, {
11282
+ fields: "+shipping_address"
11283
+ });
11293
11284
  if (isError) {
11294
11285
  throw error;
11295
11286
  }
11296
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11297
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11298
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11299
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11300
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11301
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11302
- ] }),
11303
- /* @__PURE__ */ jsx(
11304
- Combobox,
11305
- {
11306
- id: "promotion-combobox",
11307
- "aria-describedby": "promotion-combobox-hint",
11308
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11309
- fetchNextPage: comboboxData.fetchNextPage,
11310
- options: comboboxData.options,
11311
- onSearchValueChange: comboboxData.onSearchValueChange,
11312
- searchValue: comboboxData.searchValue,
11313
- disabled: comboboxData.disabled || isAddingPromotions,
11314
- onChange: add,
11315
- value: comboboxValue
11316
- }
11317
- )
11318
- ] }),
11319
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11320
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11321
- PromotionItem,
11322
- {
11323
- promotion,
11324
- orderId: preview.id,
11325
- isLoading: isPending
11326
- },
11327
- promotion.id
11328
- )) })
11329
- ] }) }),
11330
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11331
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11332
- /* @__PURE__ */ jsx(
11333
- Button,
11334
- {
11335
- size: "small",
11336
- type: "submit",
11337
- isLoading: isSubmitting || isAddingPromotions,
11338
- children: "Save"
11339
- }
11340
- )
11341
- ] }) })
11287
+ const isReady = !isPending && !!order;
11288
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11289
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11290
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11291
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11292
+ ] }),
11293
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11342
11294
  ] });
11343
11295
  };
11344
- const PromotionItem = ({
11345
- promotion,
11346
- orderId,
11347
- isLoading
11348
- }) => {
11349
- var _a;
11350
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11351
- const onRemove = async () => {
11352
- removePromotions(
11353
- {
11354
- promo_codes: [promotion.code]
11355
- },
11356
- {
11357
- onError: (e) => {
11358
- toast.error(e.message);
11359
- }
11360
- }
11361
- );
11362
- };
11363
- const displayValue = getDisplayValue(promotion);
11364
- return /* @__PURE__ */ jsxs(
11365
- "div",
11366
- {
11367
- className: clx(
11368
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11369
- {
11370
- "animate-pulse": isLoading
11371
- }
11372
- ),
11373
- children: [
11374
- /* @__PURE__ */ jsxs("div", { children: [
11375
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11376
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11377
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11378
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11379
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11380
- ] }),
11381
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11382
- ] })
11383
- ] }),
11384
- /* @__PURE__ */ jsx(
11385
- IconButton,
11386
- {
11387
- size: "small",
11388
- type: "button",
11389
- variant: "transparent",
11390
- onClick: onRemove,
11391
- isLoading: isPending || isLoading,
11392
- children: /* @__PURE__ */ jsx(XMark, {})
11393
- }
11394
- )
11395
- ]
11396
- },
11397
- promotion.id
11398
- );
11399
- };
11400
- function getDisplayValue(promotion) {
11401
- var _a, _b, _c, _d;
11402
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11403
- if (!value) {
11404
- return null;
11405
- }
11406
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11407
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11408
- if (!currency) {
11409
- return null;
11410
- }
11411
- return getLocaleAmount(value, currency);
11412
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11413
- return formatPercentage(value);
11414
- }
11415
- return null;
11416
- }
11417
- const formatter = new Intl.NumberFormat([], {
11418
- style: "percent",
11419
- minimumFractionDigits: 2
11420
- });
11421
- const formatPercentage = (value, isPercentageValue = false) => {
11422
- let val = value || 0;
11423
- if (!isPercentageValue) {
11424
- val = val / 100;
11425
- }
11426
- return formatter.format(val);
11427
- };
11428
- function getPromotionIds(items, shippingMethods) {
11429
- const promotionIds = /* @__PURE__ */ new Set();
11430
- for (const item of items) {
11431
- if (item.adjustments) {
11432
- for (const adjustment of item.adjustments) {
11433
- if (adjustment.promotion_id) {
11434
- promotionIds.add(adjustment.promotion_id);
11435
- }
11436
- }
11437
- }
11438
- }
11439
- for (const shippingMethod of shippingMethods) {
11440
- if (shippingMethod.adjustments) {
11441
- for (const adjustment of shippingMethod.adjustments) {
11442
- if (adjustment.promotion_id) {
11443
- promotionIds.add(adjustment.promotion_id);
11444
- }
11445
- }
11446
- }
11447
- }
11448
- return Array.from(promotionIds);
11449
- }
11450
- const SalesChannel = () => {
11451
- const { id } = useParams();
11452
- const { draft_order, isPending, isError, error } = useDraftOrder(
11453
- id,
11454
- {
11455
- fields: "+sales_channel_id"
11456
- },
11457
- {
11458
- enabled: !!id
11459
- }
11460
- );
11461
- if (isError) {
11462
- throw error;
11463
- }
11464
- const ISrEADY = !!draft_order && !isPending;
11465
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11467
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11468
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11469
- ] }),
11470
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11471
- ] });
11472
- };
11473
- const SalesChannelForm = ({ order }) => {
11296
+ const ShippingAddressForm = ({ order }) => {
11297
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11474
11298
  const form = useForm({
11475
11299
  defaultValues: {
11476
- sales_channel_id: order.sales_channel_id || ""
11300
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11301
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11302
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11303
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11304
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11305
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11306
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11307
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11308
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11309
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11477
11310
  },
11478
- resolver: zodResolver(schema$2)
11311
+ resolver: zodResolver(schema$1)
11479
11312
  });
11480
11313
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
11314
  const { handleSuccess } = useRouteModal();
11482
11315
  const onSubmit = form.handleSubmit(async (data) => {
11483
11316
  await mutateAsync(
11484
11317
  {
11485
- sales_channel_id: data.sales_channel_id
11318
+ shipping_address: {
11319
+ first_name: data.first_name,
11320
+ last_name: data.last_name,
11321
+ company: data.company,
11322
+ address_1: data.address_1,
11323
+ address_2: data.address_2,
11324
+ city: data.city,
11325
+ province: data.province,
11326
+ country_code: data.country_code,
11327
+ postal_code: data.postal_code,
11328
+ phone: data.phone
11329
+ }
11486
11330
  },
11487
11331
  {
11488
11332
  onSuccess: () => {
11489
- toast.success("Sales channel updated");
11490
11333
  handleSuccess();
11491
11334
  },
11492
11335
  onError: (error) => {
@@ -11501,1203 +11344,276 @@ const SalesChannelForm = ({ order }) => {
11501
11344
  className: "flex flex-1 flex-col overflow-hidden",
11502
11345
  onSubmit,
11503
11346
  children: [
11504
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11505
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11506
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11507
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
- ] }) })
11509
- ]
11510
- }
11511
- ) });
11512
- };
11513
- const SalesChannelField = ({ control, order }) => {
11514
- const salesChannels = useComboboxData({
11515
- queryFn: async (params) => {
11516
- return await sdk.admin.salesChannel.list(params);
11517
- },
11518
- queryKey: ["sales-channels"],
11519
- getOptions: (data) => {
11520
- return data.sales_channels.map((salesChannel) => ({
11521
- label: salesChannel.name,
11522
- value: salesChannel.id
11523
- }));
11524
- },
11525
- defaultValue: order.sales_channel_id || void 0
11526
- });
11527
- return /* @__PURE__ */ jsx(
11528
- Form$2.Field,
11529
- {
11530
- control,
11531
- name: "sales_channel_id",
11532
- render: ({ field }) => {
11533
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
- Combobox,
11347
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11348
+ /* @__PURE__ */ jsx(
11349
+ Form$2.Field,
11537
11350
  {
11538
- options: salesChannels.options,
11539
- fetchNextPage: salesChannels.fetchNextPage,
11540
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
- searchValue: salesChannels.searchValue,
11542
- onSearchValueChange: salesChannels.onSearchValueChange,
11543
- placeholder: "Select sales channel",
11544
- ...field
11351
+ control: form.control,
11352
+ name: "country_code",
11353
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11354
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11355
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11356
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11357
+ ] })
11545
11358
  }
11546
- ) }),
11547
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
- ] });
11549
- }
11550
- }
11551
- );
11552
- };
11553
- const schema$2 = objectType({
11554
- sales_channel_id: stringType().min(1)
11555
- });
11556
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
- const Shipping = () => {
11558
- var _a;
11559
- const { id } = useParams();
11560
- const { order, isPending, isError, error } = useOrder(id, {
11561
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11562
- });
11563
- const {
11564
- order: preview,
11565
- isPending: isPreviewPending,
11566
- isError: isPreviewError,
11567
- error: previewError
11568
- } = useOrderPreview(id);
11569
- useInitiateOrderEdit({ preview });
11570
- const { onCancel } = useCancelOrderEdit({ preview });
11571
- if (isError) {
11572
- throw error;
11573
- }
11574
- if (isPreviewError) {
11575
- throw previewError;
11576
- }
11577
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11578
- const isReady = preview && !isPreviewPending && order && !isPending;
11579
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11580
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11581
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11582
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11583
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11584
- ] }) }) }),
11585
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11586
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11587
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11588
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11589
- ] }) });
11590
- };
11591
- const ShippingForm = ({ preview, order }) => {
11592
- var _a;
11593
- const { setIsOpen } = useStackedModal();
11594
- const [isSubmitting, setIsSubmitting] = useState(false);
11595
- const [data, setData] = useState(null);
11596
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11597
- const { shipping_options } = useShippingOptions(
11598
- {
11599
- id: appliedShippingOptionIds,
11600
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11601
- },
11602
- {
11603
- enabled: appliedShippingOptionIds.length > 0
11604
- }
11605
- );
11606
- const uniqueShippingProfiles = useMemo(() => {
11607
- const profiles = /* @__PURE__ */ new Map();
11608
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11609
- profiles.set(profile.id, profile);
11610
- });
11611
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11612
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11613
- });
11614
- return Array.from(profiles.values());
11615
- }, [order.items, shipping_options]);
11616
- const { handleSuccess } = useRouteModal();
11617
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11618
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11619
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11620
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11621
- const onSubmit = async () => {
11622
- setIsSubmitting(true);
11623
- let requestSucceeded = false;
11624
- await requestOrderEdit(void 0, {
11625
- onError: (e) => {
11626
- toast.error(`Failed to request order edit: ${e.message}`);
11627
- },
11628
- onSuccess: () => {
11629
- requestSucceeded = true;
11630
- }
11631
- });
11632
- if (!requestSucceeded) {
11633
- setIsSubmitting(false);
11634
- return;
11635
- }
11636
- await confirmOrderEdit(void 0, {
11637
- onError: (e) => {
11638
- toast.error(`Failed to confirm order edit: ${e.message}`);
11639
- },
11640
- onSuccess: () => {
11641
- handleSuccess();
11642
- },
11643
- onSettled: () => {
11644
- setIsSubmitting(false);
11645
- }
11646
- });
11647
- };
11648
- const onKeydown = useCallback(
11649
- (e) => {
11650
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11651
- if (data || isSubmitting) {
11652
- return;
11653
- }
11654
- onSubmit();
11655
- }
11656
- },
11657
- [data, isSubmitting, onSubmit]
11658
- );
11659
- useEffect(() => {
11660
- document.addEventListener("keydown", onKeydown);
11661
- return () => {
11662
- document.removeEventListener("keydown", onKeydown);
11663
- };
11664
- }, [onKeydown]);
11665
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11666
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11667
- /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11668
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11669
- /* @__PURE__ */ jsxs("div", { children: [
11670
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11671
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11672
- ] }),
11673
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11674
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11675
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11359
+ ),
11360
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11676
11361
  /* @__PURE__ */ jsx(
11677
- Text,
11362
+ Form$2.Field,
11678
11363
  {
11679
- size: "xsmall",
11680
- weight: "plus",
11681
- className: "text-ui-fg-muted",
11682
- children: "Shipping profile"
11364
+ control: form.control,
11365
+ name: "first_name",
11366
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11367
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11368
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11369
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11370
+ ] })
11683
11371
  }
11684
11372
  ),
11685
11373
  /* @__PURE__ */ jsx(
11686
- Text,
11374
+ Form$2.Field,
11687
11375
  {
11688
- size: "xsmall",
11689
- weight: "plus",
11690
- className: "text-ui-fg-muted",
11691
- children: "Action"
11376
+ control: form.control,
11377
+ name: "last_name",
11378
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11379
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11380
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11381
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11382
+ ] })
11692
11383
  }
11693
11384
  )
11694
11385
  ] }),
11695
- /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11696
- var _a2, _b, _c, _d, _e, _f, _g;
11697
- const items = getItemsWithShippingProfile(
11698
- profile.id,
11699
- order.items
11700
- );
11701
- const hasItems = items.length > 0;
11702
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11703
- (option) => option.shipping_profile_id === profile.id
11704
- );
11705
- const shippingMethod = preview.shipping_methods.find(
11706
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11707
- );
11708
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11709
- (action) => action.action === "SHIPPING_ADD"
11710
- );
11711
- return /* @__PURE__ */ jsxs(
11712
- Accordion.Item,
11386
+ /* @__PURE__ */ jsx(
11387
+ Form$2.Field,
11388
+ {
11389
+ control: form.control,
11390
+ name: "company",
11391
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11392
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11393
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11394
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11395
+ ] })
11396
+ }
11397
+ ),
11398
+ /* @__PURE__ */ jsx(
11399
+ Form$2.Field,
11400
+ {
11401
+ control: form.control,
11402
+ name: "address_1",
11403
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11404
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11405
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11406
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11407
+ ] })
11408
+ }
11409
+ ),
11410
+ /* @__PURE__ */ jsx(
11411
+ Form$2.Field,
11412
+ {
11413
+ control: form.control,
11414
+ name: "address_2",
11415
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11416
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11417
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11418
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11419
+ ] })
11420
+ }
11421
+ ),
11422
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11423
+ /* @__PURE__ */ jsx(
11424
+ Form$2.Field,
11713
11425
  {
11714
- value: profile.id,
11715
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11716
- children: [
11717
- /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11718
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11719
- /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11720
- IconButton,
11721
- {
11722
- size: "2xsmall",
11723
- variant: "transparent",
11724
- className: "group/trigger",
11725
- disabled: !hasItems,
11726
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11727
- }
11728
- ) }),
11729
- !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11730
- /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11731
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11732
- /* @__PURE__ */ jsx(
11733
- Text,
11734
- {
11735
- size: "small",
11736
- weight: "plus",
11737
- leading: "compact",
11738
- children: profile.name
11739
- }
11740
- ),
11741
- /* @__PURE__ */ jsxs(
11742
- Text,
11743
- {
11744
- size: "small",
11745
- leading: "compact",
11746
- className: "text-ui-fg-subtle",
11747
- children: [
11748
- items.length,
11749
- " ",
11750
- pluralize(items.length, "items", "item")
11751
- ]
11752
- }
11753
- )
11754
- ] })
11755
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11756
- /* @__PURE__ */ jsx(
11757
- Tooltip,
11758
- {
11759
- content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11760
- var _a3, _b2, _c2;
11761
- return /* @__PURE__ */ jsx(
11762
- "li",
11763
- {
11764
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11765
- },
11766
- item.id
11767
- );
11768
- }) }),
11769
- children: /* @__PURE__ */ jsxs(
11770
- Badge,
11771
- {
11772
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11773
- size: "xsmall",
11774
- children: [
11775
- /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11776
- /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11777
- items.reduce(
11778
- (acc, item) => acc + item.quantity,
11779
- 0
11780
- ),
11781
- "x",
11782
- " ",
11783
- pluralize(items.length, "items", "item")
11784
- ] })
11785
- ]
11786
- }
11787
- )
11788
- }
11789
- ),
11790
- /* @__PURE__ */ jsx(
11791
- Tooltip,
11792
- {
11793
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11794
- children: /* @__PURE__ */ jsxs(
11795
- Badge,
11796
- {
11797
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11798
- size: "xsmall",
11799
- children: [
11800
- /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
11801
- /* @__PURE__ */ jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11802
- ]
11803
- }
11804
- )
11805
- }
11806
- ),
11807
- /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11808
- Badge,
11809
- {
11810
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11811
- size: "xsmall",
11812
- children: [
11813
- /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11814
- /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11815
- ]
11816
- }
11817
- ) })
11818
- ] })
11819
- ] }),
11820
- shippingOption ? /* @__PURE__ */ jsx(
11821
- ActionMenu,
11822
- {
11823
- groups: [
11824
- {
11825
- actions: [
11826
- hasItems ? {
11827
- label: "Edit shipping option",
11828
- icon: /* @__PURE__ */ jsx(Channels, {}),
11829
- onClick: () => {
11830
- setIsOpen(
11831
- STACKED_FOCUS_MODAL_ID,
11832
- true
11833
- );
11834
- setData({
11835
- shippingProfileId: profile.id,
11836
- shippingOption,
11837
- shippingMethod
11838
- });
11839
- }
11840
- } : void 0,
11841
- {
11842
- label: "Remove shipping option",
11843
- icon: /* @__PURE__ */ jsx(Trash, {}),
11844
- onClick: () => {
11845
- if (shippingMethod) {
11846
- if (addShippingMethodAction) {
11847
- removeActionShippingMethod(
11848
- addShippingMethodAction.id
11849
- );
11850
- } else {
11851
- removeShippingMethod(
11852
- shippingMethod.id
11853
- );
11854
- }
11855
- }
11856
- }
11857
- }
11858
- ].filter(Boolean)
11859
- }
11860
- ]
11861
- }
11862
- ) : /* @__PURE__ */ jsx(
11863
- StackedModalTrigger,
11864
- {
11865
- shippingProfileId: profile.id,
11866
- shippingOption,
11867
- shippingMethod,
11868
- setData,
11869
- children: "Add shipping option"
11870
- }
11871
- )
11872
- ] }),
11873
- /* @__PURE__ */ jsxs(Accordion.Content, { children: [
11874
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11875
- items.map((item, idx) => {
11876
- var _a3, _b2, _c2, _d2, _e2;
11877
- return /* @__PURE__ */ jsxs("div", { children: [
11878
- /* @__PURE__ */ jsxs(
11879
- "div",
11880
- {
11881
- className: "px-3 flex items-center gap-x-3",
11882
- children: [
11883
- /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11884
- Divider,
11885
- {
11886
- variant: "dashed",
11887
- orientation: "vertical"
11888
- }
11889
- ) }),
11890
- /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11891
- /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11892
- Text,
11893
- {
11894
- size: "small",
11895
- leading: "compact",
11896
- className: "text-ui-fg-subtle",
11897
- children: [
11898
- item.quantity,
11899
- "x"
11900
- ]
11901
- }
11902
- ) }),
11903
- /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
11904
- /* @__PURE__ */ jsxs("div", { children: [
11905
- /* @__PURE__ */ jsxs(
11906
- Text,
11907
- {
11908
- size: "small",
11909
- leading: "compact",
11910
- weight: "plus",
11911
- children: [
11912
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11913
- " (",
11914
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11915
- ")"
11916
- ]
11917
- }
11918
- ),
11919
- /* @__PURE__ */ jsx(
11920
- Text,
11921
- {
11922
- size: "small",
11923
- leading: "compact",
11924
- className: "text-ui-fg-subtle",
11925
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11926
- }
11927
- )
11928
- ] })
11929
- ] })
11930
- ]
11931
- },
11932
- item.id
11933
- ),
11934
- idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11935
- ] }, item.id);
11936
- })
11937
- ] })
11938
- ]
11939
- },
11940
- profile.id
11941
- );
11942
- }) })
11943
- ] }) })
11944
- ] }) }),
11945
- /* @__PURE__ */ jsx(
11946
- StackedFocusModal,
11947
- {
11948
- id: STACKED_FOCUS_MODAL_ID,
11949
- onOpenChangeCallback: (open) => {
11950
- if (!open) {
11951
- setData(null);
11426
+ control: form.control,
11427
+ name: "postal_code",
11428
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11429
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11430
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11431
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11432
+ ] })
11433
+ }
11434
+ ),
11435
+ /* @__PURE__ */ jsx(
11436
+ Form$2.Field,
11437
+ {
11438
+ control: form.control,
11439
+ name: "city",
11440
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11441
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11442
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11443
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11444
+ ] })
11445
+ }
11446
+ )
11447
+ ] }),
11448
+ /* @__PURE__ */ jsx(
11449
+ Form$2.Field,
11450
+ {
11451
+ control: form.control,
11452
+ name: "province",
11453
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11454
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11455
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11456
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11457
+ ] })
11952
11458
  }
11953
- return open;
11954
- },
11955
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11956
- }
11957
- )
11459
+ ),
11460
+ /* @__PURE__ */ jsx(
11461
+ Form$2.Field,
11462
+ {
11463
+ control: form.control,
11464
+ name: "phone",
11465
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11466
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11467
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11468
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11469
+ ] })
11470
+ }
11471
+ )
11472
+ ] }) }),
11473
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11474
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11475
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11476
+ ] }) })
11477
+ ]
11478
+ }
11479
+ ) });
11480
+ };
11481
+ const schema$1 = addressSchema;
11482
+ const TransferOwnership = () => {
11483
+ const { id } = useParams();
11484
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11485
+ fields: "id,customer_id,customer.*"
11486
+ });
11487
+ if (isError) {
11488
+ throw error;
11489
+ }
11490
+ const isReady = !isPending && !!draft_order;
11491
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11492
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11493
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11494
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11958
11495
  ] }),
11959
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11960
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11961
- /* @__PURE__ */ jsx(
11962
- Button,
11963
- {
11964
- size: "small",
11965
- type: "button",
11966
- isLoading: isSubmitting,
11967
- onClick: onSubmit,
11968
- children: "Save"
11969
- }
11970
- )
11971
- ] }) })
11496
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11972
11497
  ] });
11973
11498
  };
11974
- const StackedModalTrigger = ({
11975
- shippingProfileId,
11976
- shippingOption,
11977
- shippingMethod,
11978
- setData,
11979
- children
11980
- }) => {
11981
- const { setIsOpen, getIsOpen } = useStackedModal();
11982
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11983
- const onToggle = () => {
11984
- if (isOpen) {
11985
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11986
- setData(null);
11987
- } else {
11988
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11989
- setData({
11990
- shippingProfileId,
11991
- shippingOption,
11992
- shippingMethod
11993
- });
11994
- }
11995
- };
11996
- return /* @__PURE__ */ jsx(
11997
- Button,
11998
- {
11999
- size: "small",
12000
- variant: "secondary",
12001
- onClick: onToggle,
12002
- className: "text-ui-fg-primary shrink-0",
12003
- children
12004
- }
12005
- );
12006
- };
12007
- const ShippingProfileForm = ({
12008
- data,
12009
- order,
12010
- preview
12011
- }) => {
12012
- var _a, _b, _c, _d, _e, _f;
12013
- const { setIsOpen } = useStackedModal();
11499
+ const TransferOwnershipForm = ({ order }) => {
11500
+ var _a, _b;
12014
11501
  const form = useForm({
12015
- resolver: zodResolver(shippingMethodSchema),
12016
11502
  defaultValues: {
12017
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12018
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12019
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12020
- }
11503
+ customer_id: order.customer_id || ""
11504
+ },
11505
+ resolver: zodResolver(schema)
12021
11506
  });
12022
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12023
- const {
12024
- mutateAsync: updateShippingMethod,
12025
- isPending: isUpdatingShippingMethod
12026
- } = useDraftOrderUpdateShippingMethod(order.id);
12027
- const onSubmit = form.handleSubmit(async (values) => {
12028
- if (isEqual(values, form.formState.defaultValues)) {
12029
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12030
- return;
12031
- }
12032
- if (data.shippingMethod) {
12033
- await updateShippingMethod(
12034
- {
12035
- method_id: data.shippingMethod.id,
12036
- shipping_option_id: values.shipping_option_id,
12037
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12038
- },
12039
- {
12040
- onError: (e) => {
12041
- toast.error(e.message);
12042
- },
12043
- onSuccess: () => {
12044
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12045
- }
12046
- }
12047
- );
12048
- return;
12049
- }
12050
- await addShippingMethod(
12051
- {
12052
- shipping_option_id: values.shipping_option_id,
12053
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12054
- },
11507
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11508
+ const { handleSuccess } = useRouteModal();
11509
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11510
+ const currentCustomer = order.customer ? {
11511
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11512
+ value: order.customer.id
11513
+ } : null;
11514
+ const onSubmit = form.handleSubmit(async (data) => {
11515
+ await mutateAsync(
11516
+ { customer_id: data.customer_id },
12055
11517
  {
12056
- onError: (e) => {
12057
- toast.error(e.message);
12058
- },
12059
11518
  onSuccess: () => {
12060
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11519
+ toast.success("Customer updated");
11520
+ handleSuccess();
11521
+ },
11522
+ onError: (error) => {
11523
+ toast.error(error.message);
12061
11524
  }
12062
11525
  }
12063
11526
  );
12064
11527
  });
12065
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
11528
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12066
11529
  KeyboundForm,
12067
11530
  {
12068
- className: "flex h-full flex-col overflow-hidden",
11531
+ className: "flex flex-1 flex-col overflow-hidden",
12069
11532
  onSubmit,
12070
11533
  children: [
12071
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12072
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12073
- /* @__PURE__ */ jsxs("div", { children: [
12074
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12075
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11534
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11535
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11536
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11537
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11538
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11539
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11540
+ ] }),
11541
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11542
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11543
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11544
+ ] })
12076
11545
  ] }),
12077
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12078
- /* @__PURE__ */ jsx(
12079
- LocationField,
12080
- {
12081
- control: form.control,
12082
- setValue: form.setValue
12083
- }
12084
- ),
12085
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12086
- /* @__PURE__ */ jsx(
12087
- ShippingOptionField,
12088
- {
12089
- shippingProfileId: data.shippingProfileId,
12090
- preview,
12091
- control: form.control
12092
- }
12093
- ),
12094
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12095
11546
  /* @__PURE__ */ jsx(
12096
- CustomAmountField,
11547
+ CustomerField,
12097
11548
  {
12098
11549
  control: form.control,
12099
- currencyCode: order.currency_code
12100
- }
12101
- ),
12102
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12103
- /* @__PURE__ */ jsx(
12104
- ItemsPreview,
12105
- {
12106
- order,
12107
- shippingProfileId: data.shippingProfileId
12108
- }
12109
- )
12110
- ] }) }) }),
12111
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12112
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12113
- /* @__PURE__ */ jsx(
12114
- Button,
12115
- {
12116
- size: "small",
12117
- type: "submit",
12118
- isLoading: isPending || isUpdatingShippingMethod,
12119
- children: data.shippingMethod ? "Update" : "Add"
11550
+ currentCustomerId: order.customer_id
12120
11551
  }
12121
11552
  )
11553
+ ] }),
11554
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11555
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11556
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12122
11557
  ] }) })
12123
11558
  ]
12124
11559
  }
12125
- ) }) });
12126
- };
12127
- const shippingMethodSchema = objectType({
12128
- location_id: stringType(),
12129
- shipping_option_id: stringType(),
12130
- custom_amount: unionType([numberType(), stringType()]).optional()
12131
- });
12132
- const ItemsPreview = ({ order, shippingProfileId }) => {
12133
- const matches = order.items.filter(
12134
- (item) => {
12135
- var _a, _b, _c;
12136
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12137
- }
12138
- );
12139
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12140
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12141
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12142
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12143
- ] }) }),
12144
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12145
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12146
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12147
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12148
- ] }),
12149
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12150
- "div",
12151
- {
12152
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12153
- children: [
12154
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12155
- /* @__PURE__ */ jsx(
12156
- Thumbnail,
12157
- {
12158
- thumbnail: item.thumbnail,
12159
- alt: item.product_title ?? void 0
12160
- }
12161
- ),
12162
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12163
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12164
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12165
- /* @__PURE__ */ jsxs(
12166
- Text,
12167
- {
12168
- size: "small",
12169
- leading: "compact",
12170
- className: "text-ui-fg-subtle",
12171
- children: [
12172
- "(",
12173
- item.variant_title,
12174
- ")"
12175
- ]
12176
- }
12177
- )
12178
- ] }),
12179
- /* @__PURE__ */ jsx(
12180
- Text,
12181
- {
12182
- size: "small",
12183
- leading: "compact",
12184
- className: "text-ui-fg-subtle",
12185
- children: item.variant_sku
12186
- }
12187
- )
12188
- ] })
12189
- ] }),
12190
- /* @__PURE__ */ jsxs(
12191
- Text,
12192
- {
12193
- size: "small",
12194
- leading: "compact",
12195
- className: "text-ui-fg-subtle",
12196
- children: [
12197
- item.quantity,
12198
- "x"
12199
- ]
12200
- }
12201
- )
12202
- ]
12203
- },
12204
- item.id
12205
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12206
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12207
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12208
- 'No items found for "',
12209
- query,
12210
- '".'
12211
- ] })
12212
- ] }) })
12213
- ] })
12214
- ] });
11560
+ ) });
12215
11561
  };
12216
- const LocationField = ({ control, setValue }) => {
12217
- const locations = useComboboxData({
12218
- queryKey: ["locations"],
11562
+ const CustomerField = ({ control, currentCustomerId }) => {
11563
+ const customers = useComboboxData({
12219
11564
  queryFn: async (params) => {
12220
- return await sdk.admin.stockLocation.list(params);
11565
+ return await sdk.admin.customer.list({
11566
+ ...params,
11567
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11568
+ });
12221
11569
  },
11570
+ queryKey: ["customers"],
12222
11571
  getOptions: (data) => {
12223
- return data.stock_locations.map((location) => ({
12224
- label: location.name,
12225
- value: location.id
12226
- }));
11572
+ return data.customers.map((customer) => {
11573
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11574
+ return {
11575
+ label: name ? `${name} (${customer.email})` : customer.email,
11576
+ value: customer.id
11577
+ };
11578
+ });
12227
11579
  }
12228
11580
  });
12229
11581
  return /* @__PURE__ */ jsx(
12230
11582
  Form$2.Field,
12231
11583
  {
11584
+ name: "customer_id",
12232
11585
  control,
12233
- name: "location_id",
12234
- render: ({ field: { onChange, ...field } }) => {
12235
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12236
- /* @__PURE__ */ jsxs("div", { children: [
12237
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12238
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12239
- ] }),
12240
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12241
- Combobox,
12242
- {
12243
- options: locations.options,
12244
- fetchNextPage: locations.fetchNextPage,
12245
- isFetchingNextPage: locations.isFetchingNextPage,
12246
- searchValue: locations.searchValue,
12247
- onSearchValueChange: locations.onSearchValueChange,
12248
- placeholder: "Select location",
12249
- onChange: (value) => {
12250
- setValue("shipping_option_id", "", {
12251
- shouldDirty: true,
12252
- shouldTouch: true
12253
- });
12254
- onChange(value);
12255
- },
12256
- ...field
12257
- }
12258
- ) })
12259
- ] }) });
12260
- }
12261
- }
12262
- );
12263
- };
12264
- const ShippingOptionField = ({
12265
- shippingProfileId,
12266
- preview,
12267
- control
12268
- }) => {
12269
- var _a;
12270
- const locationId = useWatch({ control, name: "location_id" });
12271
- const shippingOptions = useComboboxData({
12272
- queryKey: ["shipping_options", locationId, shippingProfileId],
12273
- queryFn: async (params) => {
12274
- return await sdk.admin.shippingOption.list({
12275
- ...params,
12276
- stock_location_id: locationId,
12277
- shipping_profile_id: shippingProfileId
12278
- });
12279
- },
12280
- getOptions: (data) => {
12281
- return data.shipping_options.map((option) => {
12282
- var _a2;
12283
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12284
- (r) => r.attribute === "is_return" && r.value === "true"
12285
- )) {
12286
- return void 0;
12287
- }
12288
- return {
12289
- label: option.name,
12290
- value: option.id
12291
- };
12292
- }).filter(Boolean);
12293
- },
12294
- enabled: !!locationId && !!shippingProfileId,
12295
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12296
- });
12297
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12298
- return /* @__PURE__ */ jsx(
12299
- Form$2.Field,
12300
- {
12301
- control,
12302
- name: "shipping_option_id",
12303
- render: ({ field }) => {
12304
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12305
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12306
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12307
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12308
- ] }),
12309
- /* @__PURE__ */ jsx(
12310
- ConditionalTooltip,
12311
- {
12312
- content: tooltipContent,
12313
- showTooltip: !locationId || !shippingProfileId,
12314
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12315
- Combobox,
12316
- {
12317
- options: shippingOptions.options,
12318
- fetchNextPage: shippingOptions.fetchNextPage,
12319
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12320
- searchValue: shippingOptions.searchValue,
12321
- onSearchValueChange: shippingOptions.onSearchValueChange,
12322
- placeholder: "Select shipping option",
12323
- ...field,
12324
- disabled: !locationId || !shippingProfileId
12325
- }
12326
- ) }) })
12327
- }
12328
- )
12329
- ] }) });
12330
- }
12331
- }
12332
- );
12333
- };
12334
- const CustomAmountField = ({
12335
- control,
12336
- currencyCode
12337
- }) => {
12338
- return /* @__PURE__ */ jsx(
12339
- Form$2.Field,
12340
- {
12341
- control,
12342
- name: "custom_amount",
12343
- render: ({ field: { onChange, ...field } }) => {
12344
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12345
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12346
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12347
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12348
- ] }),
12349
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
- CurrencyInput,
12351
- {
12352
- ...field,
12353
- onValueChange: (value) => onChange(value),
12354
- symbol: getNativeSymbol(currencyCode),
12355
- code: currencyCode
12356
- }
12357
- ) })
12358
- ] });
12359
- }
11586
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11587
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11588
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11589
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11590
+ ] }),
11591
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11592
+ Combobox,
11593
+ {
11594
+ options: customers.options,
11595
+ fetchNextPage: customers.fetchNextPage,
11596
+ isFetchingNextPage: customers.isFetchingNextPage,
11597
+ searchValue: customers.searchValue,
11598
+ onSearchValueChange: customers.onSearchValueChange,
11599
+ placeholder: "Select customer",
11600
+ ...field
11601
+ }
11602
+ ) }),
11603
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11604
+ ] })
12360
11605
  }
12361
11606
  );
12362
11607
  };
12363
- const ShippingAddress = () => {
12364
- const { id } = useParams();
12365
- const { order, isPending, isError, error } = useOrder(id, {
12366
- fields: "+shipping_address"
12367
- });
12368
- if (isError) {
12369
- throw error;
12370
- }
12371
- const isReady = !isPending && !!order;
12372
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12373
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12374
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12376
- ] }),
12377
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12378
- ] });
12379
- };
12380
- const ShippingAddressForm = ({ order }) => {
12381
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12382
- const form = useForm({
12383
- defaultValues: {
12384
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12394
- },
12395
- resolver: zodResolver(schema$1)
12396
- });
12397
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12398
- const { handleSuccess } = useRouteModal();
12399
- const onSubmit = form.handleSubmit(async (data) => {
12400
- await mutateAsync(
12401
- {
12402
- shipping_address: {
12403
- first_name: data.first_name,
12404
- last_name: data.last_name,
12405
- company: data.company,
12406
- address_1: data.address_1,
12407
- address_2: data.address_2,
12408
- city: data.city,
12409
- province: data.province,
12410
- country_code: data.country_code,
12411
- postal_code: data.postal_code,
12412
- phone: data.phone
12413
- }
12414
- },
12415
- {
12416
- onSuccess: () => {
12417
- handleSuccess();
12418
- },
12419
- onError: (error) => {
12420
- toast.error(error.message);
12421
- }
12422
- }
12423
- );
12424
- });
12425
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12426
- KeyboundForm,
11608
+ const Illustration = () => {
11609
+ return /* @__PURE__ */ jsxs(
11610
+ "svg",
12427
11611
  {
12428
- className: "flex flex-1 flex-col overflow-hidden",
12429
- onSubmit,
12430
- children: [
12431
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12432
- /* @__PURE__ */ jsx(
12433
- Form$2.Field,
12434
- {
12435
- control: form.control,
12436
- name: "country_code",
12437
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
- ] })
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
- /* @__PURE__ */ jsx(
12446
- Form$2.Field,
12447
- {
12448
- control: form.control,
12449
- name: "first_name",
12450
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
- ] })
12455
- }
12456
- ),
12457
- /* @__PURE__ */ jsx(
12458
- Form$2.Field,
12459
- {
12460
- control: form.control,
12461
- name: "last_name",
12462
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
- ] })
12467
- }
12468
- )
12469
- ] }),
12470
- /* @__PURE__ */ jsx(
12471
- Form$2.Field,
12472
- {
12473
- control: form.control,
12474
- name: "company",
12475
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
- ] })
12480
- }
12481
- ),
12482
- /* @__PURE__ */ jsx(
12483
- Form$2.Field,
12484
- {
12485
- control: form.control,
12486
- name: "address_1",
12487
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
- ] })
12492
- }
12493
- ),
12494
- /* @__PURE__ */ jsx(
12495
- Form$2.Field,
12496
- {
12497
- control: form.control,
12498
- name: "address_2",
12499
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
- ] })
12504
- }
12505
- ),
12506
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
- /* @__PURE__ */ jsx(
12508
- Form$2.Field,
12509
- {
12510
- control: form.control,
12511
- name: "postal_code",
12512
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
- ] })
12517
- }
12518
- ),
12519
- /* @__PURE__ */ jsx(
12520
- Form$2.Field,
12521
- {
12522
- control: form.control,
12523
- name: "city",
12524
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
- ] })
12529
- }
12530
- )
12531
- ] }),
12532
- /* @__PURE__ */ jsx(
12533
- Form$2.Field,
12534
- {
12535
- control: form.control,
12536
- name: "province",
12537
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
- ] })
12542
- }
12543
- ),
12544
- /* @__PURE__ */ jsx(
12545
- Form$2.Field,
12546
- {
12547
- control: form.control,
12548
- name: "phone",
12549
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
- ] })
12554
- }
12555
- )
12556
- ] }) }),
12557
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12558
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12559
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12560
- ] }) })
12561
- ]
12562
- }
12563
- ) });
12564
- };
12565
- const schema$1 = addressSchema;
12566
- const TransferOwnership = () => {
12567
- const { id } = useParams();
12568
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12569
- fields: "id,customer_id,customer.*"
12570
- });
12571
- if (isError) {
12572
- throw error;
12573
- }
12574
- const isReady = !isPending && !!draft_order;
12575
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12576
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12577
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12578
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12579
- ] }),
12580
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12581
- ] });
12582
- };
12583
- const TransferOwnershipForm = ({ order }) => {
12584
- var _a, _b;
12585
- const form = useForm({
12586
- defaultValues: {
12587
- customer_id: order.customer_id || ""
12588
- },
12589
- resolver: zodResolver(schema)
12590
- });
12591
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
- const { handleSuccess } = useRouteModal();
12593
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12594
- const currentCustomer = order.customer ? {
12595
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12596
- value: order.customer.id
12597
- } : null;
12598
- const onSubmit = form.handleSubmit(async (data) => {
12599
- await mutateAsync(
12600
- { customer_id: data.customer_id },
12601
- {
12602
- onSuccess: () => {
12603
- toast.success("Customer updated");
12604
- handleSuccess();
12605
- },
12606
- onError: (error) => {
12607
- toast.error(error.message);
12608
- }
12609
- }
12610
- );
12611
- });
12612
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12613
- KeyboundForm,
12614
- {
12615
- className: "flex flex-1 flex-col overflow-hidden",
12616
- onSubmit,
12617
- children: [
12618
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12619
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12620
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12621
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12622
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12623
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12624
- ] }),
12625
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12626
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12627
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12628
- ] })
12629
- ] }),
12630
- /* @__PURE__ */ jsx(
12631
- CustomerField,
12632
- {
12633
- control: form.control,
12634
- currentCustomerId: order.customer_id
12635
- }
12636
- )
12637
- ] }),
12638
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12639
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12640
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12641
- ] }) })
12642
- ]
12643
- }
12644
- ) });
12645
- };
12646
- const CustomerField = ({ control, currentCustomerId }) => {
12647
- const customers = useComboboxData({
12648
- queryFn: async (params) => {
12649
- return await sdk.admin.customer.list({
12650
- ...params,
12651
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12652
- });
12653
- },
12654
- queryKey: ["customers"],
12655
- getOptions: (data) => {
12656
- return data.customers.map((customer) => {
12657
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12658
- return {
12659
- label: name ? `${name} (${customer.email})` : customer.email,
12660
- value: customer.id
12661
- };
12662
- });
12663
- }
12664
- });
12665
- return /* @__PURE__ */ jsx(
12666
- Form$2.Field,
12667
- {
12668
- name: "customer_id",
12669
- control,
12670
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12671
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12672
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12673
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12674
- ] }),
12675
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12676
- Combobox,
12677
- {
12678
- options: customers.options,
12679
- fetchNextPage: customers.fetchNextPage,
12680
- isFetchingNextPage: customers.isFetchingNextPage,
12681
- searchValue: customers.searchValue,
12682
- onSearchValueChange: customers.onSearchValueChange,
12683
- placeholder: "Select customer",
12684
- ...field
12685
- }
12686
- ) }),
12687
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12688
- ] })
12689
- }
12690
- );
12691
- };
12692
- const Illustration = () => {
12693
- return /* @__PURE__ */ jsxs(
12694
- "svg",
12695
- {
12696
- width: "280",
12697
- height: "180",
12698
- viewBox: "0 0 280 180",
12699
- fill: "none",
12700
- xmlns: "http://www.w3.org/2000/svg",
11612
+ width: "280",
11613
+ height: "180",
11614
+ viewBox: "0 0 280 180",
11615
+ fill: "none",
11616
+ xmlns: "http://www.w3.org/2000/svg",
12701
11617
  children: [
12702
11618
  /* @__PURE__ */ jsx(
12703
11619
  "rect",
@@ -12959,86 +11875,1170 @@ const Illustration = () => {
12959
11875
  /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12960
11876
  "path",
12961
11877
  {
12962
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12963
- stroke: "#A1A1AA",
12964
- strokeWidth: "1.5",
12965
- strokeLinecap: "round",
12966
- strokeLinejoin: "round"
11878
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11879
+ stroke: "#A1A1AA",
11880
+ strokeWidth: "1.5",
11881
+ strokeLinecap: "round",
11882
+ strokeLinejoin: "round"
11883
+ }
11884
+ ) }),
11885
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
11886
+ "path",
11887
+ {
11888
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11889
+ stroke: "#A1A1AA",
11890
+ strokeWidth: "1.5",
11891
+ strokeLinecap: "round",
11892
+ strokeLinejoin: "round"
11893
+ }
11894
+ ) }),
11895
+ /* @__PURE__ */ jsxs("defs", { children: [
11896
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
11897
+ "rect",
11898
+ {
11899
+ width: "12",
11900
+ height: "12",
11901
+ fill: "white",
11902
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11903
+ }
11904
+ ) }),
11905
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
11906
+ "rect",
11907
+ {
11908
+ width: "12",
11909
+ height: "12",
11910
+ fill: "white",
11911
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11912
+ }
11913
+ ) }),
11914
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
11915
+ "rect",
11916
+ {
11917
+ width: "12",
11918
+ height: "12",
11919
+ fill: "white",
11920
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11921
+ }
11922
+ ) }),
11923
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
11924
+ "rect",
11925
+ {
11926
+ width: "12",
11927
+ height: "12",
11928
+ fill: "white",
11929
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
11930
+ }
11931
+ ) }),
11932
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
11933
+ "rect",
11934
+ {
11935
+ width: "12",
11936
+ height: "12",
11937
+ fill: "white",
11938
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
11939
+ }
11940
+ ) }),
11941
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
11942
+ "rect",
11943
+ {
11944
+ width: "12",
11945
+ height: "12",
11946
+ fill: "white",
11947
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
11948
+ }
11949
+ ) })
11950
+ ] })
11951
+ ]
11952
+ }
11953
+ );
11954
+ };
11955
+ const schema = objectType({
11956
+ customer_id: stringType().min(1)
11957
+ });
11958
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11959
+ const Shipping = () => {
11960
+ var _a;
11961
+ const { id } = useParams();
11962
+ const { order, isPending, isError, error } = useOrder(id, {
11963
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11964
+ });
11965
+ const {
11966
+ order: preview,
11967
+ isPending: isPreviewPending,
11968
+ isError: isPreviewError,
11969
+ error: previewError
11970
+ } = useOrderPreview(id);
11971
+ useInitiateOrderEdit({ preview });
11972
+ const { onCancel } = useCancelOrderEdit({ preview });
11973
+ if (isError) {
11974
+ throw error;
11975
+ }
11976
+ if (isPreviewError) {
11977
+ throw previewError;
11978
+ }
11979
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11980
+ const isReady = preview && !isPreviewPending && order && !isPending;
11981
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11982
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11983
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11984
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11985
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11986
+ ] }) }) }),
11987
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11988
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11989
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11990
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11991
+ ] }) });
11992
+ };
11993
+ const ShippingForm = ({ preview, order }) => {
11994
+ var _a;
11995
+ const { setIsOpen } = useStackedModal();
11996
+ const [isSubmitting, setIsSubmitting] = useState(false);
11997
+ const [data, setData] = useState(null);
11998
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11999
+ const { shipping_options } = useShippingOptions(
12000
+ {
12001
+ id: appliedShippingOptionIds,
12002
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12003
+ },
12004
+ {
12005
+ enabled: appliedShippingOptionIds.length > 0
12006
+ }
12007
+ );
12008
+ const uniqueShippingProfiles = useMemo(() => {
12009
+ const profiles = /* @__PURE__ */ new Map();
12010
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
12011
+ profiles.set(profile.id, profile);
12012
+ });
12013
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12014
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
12015
+ });
12016
+ return Array.from(profiles.values());
12017
+ }, [order.items, shipping_options]);
12018
+ const { handleSuccess } = useRouteModal();
12019
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12020
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12021
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12022
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12023
+ const onSubmit = async () => {
12024
+ setIsSubmitting(true);
12025
+ let requestSucceeded = false;
12026
+ await requestOrderEdit(void 0, {
12027
+ onError: (e) => {
12028
+ toast.error(`Failed to request order edit: ${e.message}`);
12029
+ },
12030
+ onSuccess: () => {
12031
+ requestSucceeded = true;
12032
+ }
12033
+ });
12034
+ if (!requestSucceeded) {
12035
+ setIsSubmitting(false);
12036
+ return;
12037
+ }
12038
+ await confirmOrderEdit(void 0, {
12039
+ onError: (e) => {
12040
+ toast.error(`Failed to confirm order edit: ${e.message}`);
12041
+ },
12042
+ onSuccess: () => {
12043
+ handleSuccess();
12044
+ },
12045
+ onSettled: () => {
12046
+ setIsSubmitting(false);
12047
+ }
12048
+ });
12049
+ };
12050
+ const onKeydown = useCallback(
12051
+ (e) => {
12052
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12053
+ if (data || isSubmitting) {
12054
+ return;
12055
+ }
12056
+ onSubmit();
12057
+ }
12058
+ },
12059
+ [data, isSubmitting, onSubmit]
12060
+ );
12061
+ useEffect(() => {
12062
+ document.addEventListener("keydown", onKeydown);
12063
+ return () => {
12064
+ document.removeEventListener("keydown", onKeydown);
12065
+ };
12066
+ }, [onKeydown]);
12067
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12068
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12069
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12070
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12071
+ /* @__PURE__ */ jsxs("div", { children: [
12072
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12073
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
12074
+ ] }),
12075
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12076
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
12077
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12078
+ /* @__PURE__ */ jsx(
12079
+ Text,
12080
+ {
12081
+ size: "xsmall",
12082
+ weight: "plus",
12083
+ className: "text-ui-fg-muted",
12084
+ children: "Shipping profile"
12085
+ }
12086
+ ),
12087
+ /* @__PURE__ */ jsx(
12088
+ Text,
12089
+ {
12090
+ size: "xsmall",
12091
+ weight: "plus",
12092
+ className: "text-ui-fg-muted",
12093
+ children: "Action"
12094
+ }
12095
+ )
12096
+ ] }),
12097
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12098
+ var _a2, _b, _c, _d, _e, _f, _g;
12099
+ const items = getItemsWithShippingProfile(
12100
+ profile.id,
12101
+ order.items
12102
+ );
12103
+ const hasItems = items.length > 0;
12104
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12105
+ (option) => option.shipping_profile_id === profile.id
12106
+ );
12107
+ const shippingMethod = preview.shipping_methods.find(
12108
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12109
+ );
12110
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
12111
+ (action) => action.action === "SHIPPING_ADD"
12112
+ );
12113
+ return /* @__PURE__ */ jsxs(
12114
+ Accordion.Item,
12115
+ {
12116
+ value: profile.id,
12117
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12118
+ children: [
12119
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
12120
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
12121
+ /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
12122
+ IconButton,
12123
+ {
12124
+ size: "2xsmall",
12125
+ variant: "transparent",
12126
+ className: "group/trigger",
12127
+ disabled: !hasItems,
12128
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
12129
+ }
12130
+ ) }),
12131
+ !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12132
+ /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
12133
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
12134
+ /* @__PURE__ */ jsx(
12135
+ Text,
12136
+ {
12137
+ size: "small",
12138
+ weight: "plus",
12139
+ leading: "compact",
12140
+ children: profile.name
12141
+ }
12142
+ ),
12143
+ /* @__PURE__ */ jsxs(
12144
+ Text,
12145
+ {
12146
+ size: "small",
12147
+ leading: "compact",
12148
+ className: "text-ui-fg-subtle",
12149
+ children: [
12150
+ items.length,
12151
+ " ",
12152
+ pluralize(items.length, "items", "item")
12153
+ ]
12154
+ }
12155
+ )
12156
+ ] })
12157
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
12158
+ /* @__PURE__ */ jsx(
12159
+ Tooltip,
12160
+ {
12161
+ content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
12162
+ var _a3, _b2, _c2;
12163
+ return /* @__PURE__ */ jsx(
12164
+ "li",
12165
+ {
12166
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
12167
+ },
12168
+ item.id
12169
+ );
12170
+ }) }),
12171
+ children: /* @__PURE__ */ jsxs(
12172
+ Badge,
12173
+ {
12174
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12175
+ size: "xsmall",
12176
+ children: [
12177
+ /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
12178
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
12179
+ items.reduce(
12180
+ (acc, item) => acc + item.quantity,
12181
+ 0
12182
+ ),
12183
+ "x",
12184
+ " ",
12185
+ pluralize(items.length, "items", "item")
12186
+ ] })
12187
+ ]
12188
+ }
12189
+ )
12190
+ }
12191
+ ),
12192
+ /* @__PURE__ */ jsx(
12193
+ Tooltip,
12194
+ {
12195
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12196
+ children: /* @__PURE__ */ jsxs(
12197
+ Badge,
12198
+ {
12199
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12200
+ size: "xsmall",
12201
+ children: [
12202
+ /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
12203
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12204
+ ]
12205
+ }
12206
+ )
12207
+ }
12208
+ ),
12209
+ /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
12210
+ Badge,
12211
+ {
12212
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12213
+ size: "xsmall",
12214
+ children: [
12215
+ /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
12216
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
12217
+ ]
12218
+ }
12219
+ ) })
12220
+ ] })
12221
+ ] }),
12222
+ shippingOption ? /* @__PURE__ */ jsx(
12223
+ ActionMenu,
12224
+ {
12225
+ groups: [
12226
+ {
12227
+ actions: [
12228
+ hasItems ? {
12229
+ label: "Edit shipping option",
12230
+ icon: /* @__PURE__ */ jsx(Channels, {}),
12231
+ onClick: () => {
12232
+ setIsOpen(
12233
+ STACKED_FOCUS_MODAL_ID,
12234
+ true
12235
+ );
12236
+ setData({
12237
+ shippingProfileId: profile.id,
12238
+ shippingOption,
12239
+ shippingMethod
12240
+ });
12241
+ }
12242
+ } : void 0,
12243
+ {
12244
+ label: "Remove shipping option",
12245
+ icon: /* @__PURE__ */ jsx(Trash, {}),
12246
+ onClick: () => {
12247
+ if (shippingMethod) {
12248
+ if (addShippingMethodAction) {
12249
+ removeActionShippingMethod(
12250
+ addShippingMethodAction.id
12251
+ );
12252
+ } else {
12253
+ removeShippingMethod(
12254
+ shippingMethod.id
12255
+ );
12256
+ }
12257
+ }
12258
+ }
12259
+ }
12260
+ ].filter(Boolean)
12261
+ }
12262
+ ]
12263
+ }
12264
+ ) : /* @__PURE__ */ jsx(
12265
+ StackedModalTrigger,
12266
+ {
12267
+ shippingProfileId: profile.id,
12268
+ shippingOption,
12269
+ shippingMethod,
12270
+ setData,
12271
+ children: "Add shipping option"
12272
+ }
12273
+ )
12274
+ ] }),
12275
+ /* @__PURE__ */ jsxs(Accordion.Content, { children: [
12276
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12277
+ items.map((item, idx) => {
12278
+ var _a3, _b2, _c2, _d2, _e2;
12279
+ return /* @__PURE__ */ jsxs("div", { children: [
12280
+ /* @__PURE__ */ jsxs(
12281
+ "div",
12282
+ {
12283
+ className: "px-3 flex items-center gap-x-3",
12284
+ children: [
12285
+ /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
12286
+ Divider,
12287
+ {
12288
+ variant: "dashed",
12289
+ orientation: "vertical"
12290
+ }
12291
+ ) }),
12292
+ /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12293
+ /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
12294
+ Text,
12295
+ {
12296
+ size: "small",
12297
+ leading: "compact",
12298
+ className: "text-ui-fg-subtle",
12299
+ children: [
12300
+ item.quantity,
12301
+ "x"
12302
+ ]
12303
+ }
12304
+ ) }),
12305
+ /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
12306
+ /* @__PURE__ */ jsxs("div", { children: [
12307
+ /* @__PURE__ */ jsxs(
12308
+ Text,
12309
+ {
12310
+ size: "small",
12311
+ leading: "compact",
12312
+ weight: "plus",
12313
+ children: [
12314
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12315
+ " (",
12316
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12317
+ ")"
12318
+ ]
12319
+ }
12320
+ ),
12321
+ /* @__PURE__ */ jsx(
12322
+ Text,
12323
+ {
12324
+ size: "small",
12325
+ leading: "compact",
12326
+ className: "text-ui-fg-subtle",
12327
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12328
+ }
12329
+ )
12330
+ ] })
12331
+ ] })
12332
+ ]
12333
+ },
12334
+ item.id
12335
+ ),
12336
+ idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
12337
+ ] }, item.id);
12338
+ })
12339
+ ] })
12340
+ ]
12341
+ },
12342
+ profile.id
12343
+ );
12344
+ }) })
12345
+ ] }) })
12346
+ ] }) }),
12347
+ /* @__PURE__ */ jsx(
12348
+ StackedFocusModal,
12349
+ {
12350
+ id: STACKED_FOCUS_MODAL_ID,
12351
+ onOpenChangeCallback: (open) => {
12352
+ if (!open) {
12353
+ setData(null);
12354
+ }
12355
+ return open;
12356
+ },
12357
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
12358
+ }
12359
+ )
12360
+ ] }),
12361
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12362
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12363
+ /* @__PURE__ */ jsx(
12364
+ Button,
12365
+ {
12366
+ size: "small",
12367
+ type: "button",
12368
+ isLoading: isSubmitting,
12369
+ onClick: onSubmit,
12370
+ children: "Save"
12371
+ }
12372
+ )
12373
+ ] }) })
12374
+ ] });
12375
+ };
12376
+ const StackedModalTrigger = ({
12377
+ shippingProfileId,
12378
+ shippingOption,
12379
+ shippingMethod,
12380
+ setData,
12381
+ children
12382
+ }) => {
12383
+ const { setIsOpen, getIsOpen } = useStackedModal();
12384
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12385
+ const onToggle = () => {
12386
+ if (isOpen) {
12387
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12388
+ setData(null);
12389
+ } else {
12390
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12391
+ setData({
12392
+ shippingProfileId,
12393
+ shippingOption,
12394
+ shippingMethod
12395
+ });
12396
+ }
12397
+ };
12398
+ return /* @__PURE__ */ jsx(
12399
+ Button,
12400
+ {
12401
+ size: "small",
12402
+ variant: "secondary",
12403
+ onClick: onToggle,
12404
+ className: "text-ui-fg-primary shrink-0",
12405
+ children
12406
+ }
12407
+ );
12408
+ };
12409
+ const ShippingProfileForm = ({
12410
+ data,
12411
+ order,
12412
+ preview
12413
+ }) => {
12414
+ var _a, _b, _c, _d, _e, _f;
12415
+ const { setIsOpen } = useStackedModal();
12416
+ const form = useForm({
12417
+ resolver: zodResolver(shippingMethodSchema),
12418
+ defaultValues: {
12419
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12420
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12421
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12422
+ }
12423
+ });
12424
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12425
+ const {
12426
+ mutateAsync: updateShippingMethod,
12427
+ isPending: isUpdatingShippingMethod
12428
+ } = useDraftOrderUpdateShippingMethod(order.id);
12429
+ const onSubmit = form.handleSubmit(async (values) => {
12430
+ if (isEqual(values, form.formState.defaultValues)) {
12431
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12432
+ return;
12433
+ }
12434
+ if (data.shippingMethod) {
12435
+ await updateShippingMethod(
12436
+ {
12437
+ method_id: data.shippingMethod.id,
12438
+ shipping_option_id: values.shipping_option_id,
12439
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12440
+ },
12441
+ {
12442
+ onError: (e) => {
12443
+ toast.error(e.message);
12444
+ },
12445
+ onSuccess: () => {
12446
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12447
+ }
12448
+ }
12449
+ );
12450
+ return;
12451
+ }
12452
+ await addShippingMethod(
12453
+ {
12454
+ shipping_option_id: values.shipping_option_id,
12455
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12456
+ },
12457
+ {
12458
+ onError: (e) => {
12459
+ toast.error(e.message);
12460
+ },
12461
+ onSuccess: () => {
12462
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12463
+ }
12464
+ }
12465
+ );
12466
+ });
12467
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12468
+ KeyboundForm,
12469
+ {
12470
+ className: "flex h-full flex-col overflow-hidden",
12471
+ onSubmit,
12472
+ children: [
12473
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12474
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12475
+ /* @__PURE__ */ jsxs("div", { children: [
12476
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12477
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12478
+ ] }),
12479
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12480
+ /* @__PURE__ */ jsx(
12481
+ LocationField,
12482
+ {
12483
+ control: form.control,
12484
+ setValue: form.setValue
12485
+ }
12486
+ ),
12487
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12488
+ /* @__PURE__ */ jsx(
12489
+ ShippingOptionField,
12490
+ {
12491
+ shippingProfileId: data.shippingProfileId,
12492
+ preview,
12493
+ control: form.control
12494
+ }
12495
+ ),
12496
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12497
+ /* @__PURE__ */ jsx(
12498
+ CustomAmountField,
12499
+ {
12500
+ control: form.control,
12501
+ currencyCode: order.currency_code
12502
+ }
12503
+ ),
12504
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12505
+ /* @__PURE__ */ jsx(
12506
+ ItemsPreview,
12507
+ {
12508
+ order,
12509
+ shippingProfileId: data.shippingProfileId
12510
+ }
12511
+ )
12512
+ ] }) }) }),
12513
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12514
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12515
+ /* @__PURE__ */ jsx(
12516
+ Button,
12517
+ {
12518
+ size: "small",
12519
+ type: "submit",
12520
+ isLoading: isPending || isUpdatingShippingMethod,
12521
+ children: data.shippingMethod ? "Update" : "Add"
12522
+ }
12523
+ )
12524
+ ] }) })
12525
+ ]
12526
+ }
12527
+ ) }) });
12528
+ };
12529
+ const shippingMethodSchema = objectType({
12530
+ location_id: stringType(),
12531
+ shipping_option_id: stringType(),
12532
+ custom_amount: unionType([numberType(), stringType()]).optional()
12533
+ });
12534
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12535
+ const matches = order.items.filter(
12536
+ (item) => {
12537
+ var _a, _b, _c;
12538
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12539
+ }
12540
+ );
12541
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12542
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12543
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12544
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12545
+ ] }) }),
12546
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12547
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12548
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12549
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12550
+ ] }),
12551
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12552
+ "div",
12553
+ {
12554
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12555
+ children: [
12556
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12557
+ /* @__PURE__ */ jsx(
12558
+ Thumbnail,
12559
+ {
12560
+ thumbnail: item.thumbnail,
12561
+ alt: item.product_title ?? void 0
12562
+ }
12563
+ ),
12564
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12565
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12566
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12567
+ /* @__PURE__ */ jsxs(
12568
+ Text,
12569
+ {
12570
+ size: "small",
12571
+ leading: "compact",
12572
+ className: "text-ui-fg-subtle",
12573
+ children: [
12574
+ "(",
12575
+ item.variant_title,
12576
+ ")"
12577
+ ]
12578
+ }
12579
+ )
12580
+ ] }),
12581
+ /* @__PURE__ */ jsx(
12582
+ Text,
12583
+ {
12584
+ size: "small",
12585
+ leading: "compact",
12586
+ className: "text-ui-fg-subtle",
12587
+ children: item.variant_sku
12588
+ }
12589
+ )
12590
+ ] })
12591
+ ] }),
12592
+ /* @__PURE__ */ jsxs(
12593
+ Text,
12594
+ {
12595
+ size: "small",
12596
+ leading: "compact",
12597
+ className: "text-ui-fg-subtle",
12598
+ children: [
12599
+ item.quantity,
12600
+ "x"
12601
+ ]
12602
+ }
12603
+ )
12604
+ ]
12605
+ },
12606
+ item.id
12607
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12608
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12609
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12610
+ 'No items found for "',
12611
+ query,
12612
+ '".'
12613
+ ] })
12614
+ ] }) })
12615
+ ] })
12616
+ ] });
12617
+ };
12618
+ const LocationField = ({ control, setValue }) => {
12619
+ const locations = useComboboxData({
12620
+ queryKey: ["locations"],
12621
+ queryFn: async (params) => {
12622
+ return await sdk.admin.stockLocation.list(params);
12623
+ },
12624
+ getOptions: (data) => {
12625
+ return data.stock_locations.map((location) => ({
12626
+ label: location.name,
12627
+ value: location.id
12628
+ }));
12629
+ }
12630
+ });
12631
+ return /* @__PURE__ */ jsx(
12632
+ Form$2.Field,
12633
+ {
12634
+ control,
12635
+ name: "location_id",
12636
+ render: ({ field: { onChange, ...field } }) => {
12637
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12638
+ /* @__PURE__ */ jsxs("div", { children: [
12639
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12640
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12641
+ ] }),
12642
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12643
+ Combobox,
12644
+ {
12645
+ options: locations.options,
12646
+ fetchNextPage: locations.fetchNextPage,
12647
+ isFetchingNextPage: locations.isFetchingNextPage,
12648
+ searchValue: locations.searchValue,
12649
+ onSearchValueChange: locations.onSearchValueChange,
12650
+ placeholder: "Select location",
12651
+ onChange: (value) => {
12652
+ setValue("shipping_option_id", "", {
12653
+ shouldDirty: true,
12654
+ shouldTouch: true
12655
+ });
12656
+ onChange(value);
12657
+ },
12658
+ ...field
12659
+ }
12660
+ ) })
12661
+ ] }) });
12662
+ }
12663
+ }
12664
+ );
12665
+ };
12666
+ const ShippingOptionField = ({
12667
+ shippingProfileId,
12668
+ preview,
12669
+ control
12670
+ }) => {
12671
+ var _a;
12672
+ const locationId = useWatch({ control, name: "location_id" });
12673
+ const shippingOptions = useComboboxData({
12674
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12675
+ queryFn: async (params) => {
12676
+ return await sdk.admin.shippingOption.list({
12677
+ ...params,
12678
+ stock_location_id: locationId,
12679
+ shipping_profile_id: shippingProfileId
12680
+ });
12681
+ },
12682
+ getOptions: (data) => {
12683
+ return data.shipping_options.map((option) => {
12684
+ var _a2;
12685
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12686
+ (r) => r.attribute === "is_return" && r.value === "true"
12687
+ )) {
12688
+ return void 0;
12689
+ }
12690
+ return {
12691
+ label: option.name,
12692
+ value: option.id
12693
+ };
12694
+ }).filter(Boolean);
12695
+ },
12696
+ enabled: !!locationId && !!shippingProfileId,
12697
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12698
+ });
12699
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12700
+ return /* @__PURE__ */ jsx(
12701
+ Form$2.Field,
12702
+ {
12703
+ control,
12704
+ name: "shipping_option_id",
12705
+ render: ({ field }) => {
12706
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12707
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12708
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12709
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12710
+ ] }),
12711
+ /* @__PURE__ */ jsx(
12712
+ ConditionalTooltip,
12713
+ {
12714
+ content: tooltipContent,
12715
+ showTooltip: !locationId || !shippingProfileId,
12716
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12717
+ Combobox,
12718
+ {
12719
+ options: shippingOptions.options,
12720
+ fetchNextPage: shippingOptions.fetchNextPage,
12721
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12722
+ searchValue: shippingOptions.searchValue,
12723
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12724
+ placeholder: "Select shipping option",
12725
+ ...field,
12726
+ disabled: !locationId || !shippingProfileId
12727
+ }
12728
+ ) }) })
12729
+ }
12730
+ )
12731
+ ] }) });
12732
+ }
12733
+ }
12734
+ );
12735
+ };
12736
+ const CustomAmountField = ({
12737
+ control,
12738
+ currencyCode
12739
+ }) => {
12740
+ return /* @__PURE__ */ jsx(
12741
+ Form$2.Field,
12742
+ {
12743
+ control,
12744
+ name: "custom_amount",
12745
+ render: ({ field: { onChange, ...field } }) => {
12746
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12747
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12748
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12749
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12750
+ ] }),
12751
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12752
+ CurrencyInput,
12753
+ {
12754
+ ...field,
12755
+ onValueChange: (value) => onChange(value),
12756
+ symbol: getNativeSymbol(currencyCode),
12757
+ code: currencyCode
12758
+ }
12759
+ ) })
12760
+ ] });
12761
+ }
12762
+ }
12763
+ );
12764
+ };
12765
+ const PROMOTION_QUERY_KEY = "promotions";
12766
+ const promotionsQueryKeys = {
12767
+ list: (query2) => [
12768
+ PROMOTION_QUERY_KEY,
12769
+ query2 ? query2 : void 0
12770
+ ],
12771
+ detail: (id, query2) => [
12772
+ PROMOTION_QUERY_KEY,
12773
+ id,
12774
+ query2 ? query2 : void 0
12775
+ ]
12776
+ };
12777
+ const usePromotions = (query2, options) => {
12778
+ const { data, ...rest } = useQuery({
12779
+ queryKey: promotionsQueryKeys.list(query2),
12780
+ queryFn: async () => sdk.admin.promotion.list(query2),
12781
+ ...options
12782
+ });
12783
+ return { ...data, ...rest };
12784
+ };
12785
+ const Promotions = () => {
12786
+ const { id } = useParams();
12787
+ const {
12788
+ order: preview,
12789
+ isError: isPreviewError,
12790
+ error: previewError
12791
+ } = useOrderPreview(id, void 0);
12792
+ useInitiateOrderEdit({ preview });
12793
+ const { onCancel } = useCancelOrderEdit({ preview });
12794
+ if (isPreviewError) {
12795
+ throw previewError;
12796
+ }
12797
+ const isReady = !!preview;
12798
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
12799
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
12800
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
12801
+ ] });
12802
+ };
12803
+ const PromotionForm = ({ preview }) => {
12804
+ const { items, shipping_methods } = preview;
12805
+ const [isSubmitting, setIsSubmitting] = useState(false);
12806
+ const [comboboxValue, setComboboxValue] = useState("");
12807
+ const { handleSuccess } = useRouteModal();
12808
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12809
+ const promoIds = getPromotionIds(items, shipping_methods);
12810
+ const { promotions, isPending, isError, error } = usePromotions(
12811
+ {
12812
+ id: promoIds
12813
+ },
12814
+ {
12815
+ enabled: !!promoIds.length
12816
+ }
12817
+ );
12818
+ const comboboxData = useComboboxData({
12819
+ queryKey: ["promotions", "combobox", promoIds],
12820
+ queryFn: async (params) => {
12821
+ return await sdk.admin.promotion.list({
12822
+ ...params,
12823
+ id: {
12824
+ $nin: promoIds
12825
+ }
12826
+ });
12827
+ },
12828
+ getOptions: (data) => {
12829
+ return data.promotions.map((promotion) => ({
12830
+ label: promotion.code,
12831
+ value: promotion.code
12832
+ }));
12833
+ }
12834
+ });
12835
+ const add = async (value) => {
12836
+ if (!value) {
12837
+ return;
12838
+ }
12839
+ addPromotions(
12840
+ {
12841
+ promo_codes: [value]
12842
+ },
12843
+ {
12844
+ onError: (e) => {
12845
+ toast.error(e.message);
12846
+ comboboxData.onSearchValueChange("");
12847
+ setComboboxValue("");
12848
+ },
12849
+ onSuccess: () => {
12850
+ comboboxData.onSearchValueChange("");
12851
+ setComboboxValue("");
12852
+ }
12853
+ }
12854
+ );
12855
+ };
12856
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12857
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12858
+ const onSubmit = async () => {
12859
+ setIsSubmitting(true);
12860
+ let requestSucceeded = false;
12861
+ await requestOrderEdit(void 0, {
12862
+ onError: (e) => {
12863
+ toast.error(e.message);
12864
+ },
12865
+ onSuccess: () => {
12866
+ requestSucceeded = true;
12867
+ }
12868
+ });
12869
+ if (!requestSucceeded) {
12870
+ setIsSubmitting(false);
12871
+ return;
12872
+ }
12873
+ await confirmOrderEdit(void 0, {
12874
+ onError: (e) => {
12875
+ toast.error(e.message);
12876
+ },
12877
+ onSuccess: () => {
12878
+ handleSuccess();
12879
+ },
12880
+ onSettled: () => {
12881
+ setIsSubmitting(false);
12882
+ }
12883
+ });
12884
+ };
12885
+ if (isError) {
12886
+ throw error;
12887
+ }
12888
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12889
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
12890
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
12891
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12892
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12893
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12894
+ ] }),
12895
+ /* @__PURE__ */ jsx(
12896
+ Combobox,
12897
+ {
12898
+ id: "promotion-combobox",
12899
+ "aria-describedby": "promotion-combobox-hint",
12900
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12901
+ fetchNextPage: comboboxData.fetchNextPage,
12902
+ options: comboboxData.options,
12903
+ onSearchValueChange: comboboxData.onSearchValueChange,
12904
+ searchValue: comboboxData.searchValue,
12905
+ disabled: comboboxData.disabled || isAddingPromotions,
12906
+ onChange: add,
12907
+ value: comboboxValue
12967
12908
  }
12968
- ) }),
12969
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12970
- "path",
12909
+ )
12910
+ ] }),
12911
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12912
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
12913
+ PromotionItem,
12914
+ {
12915
+ promotion,
12916
+ orderId: preview.id,
12917
+ isLoading: isPending
12918
+ },
12919
+ promotion.id
12920
+ )) })
12921
+ ] }) }),
12922
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12923
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12924
+ /* @__PURE__ */ jsx(
12925
+ Button,
12926
+ {
12927
+ size: "small",
12928
+ type: "submit",
12929
+ isLoading: isSubmitting || isAddingPromotions,
12930
+ children: "Save"
12931
+ }
12932
+ )
12933
+ ] }) })
12934
+ ] });
12935
+ };
12936
+ const PromotionItem = ({
12937
+ promotion,
12938
+ orderId,
12939
+ isLoading
12940
+ }) => {
12941
+ var _a;
12942
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12943
+ const onRemove = async () => {
12944
+ removePromotions(
12945
+ {
12946
+ promo_codes: [promotion.code]
12947
+ },
12948
+ {
12949
+ onError: (e) => {
12950
+ toast.error(e.message);
12951
+ }
12952
+ }
12953
+ );
12954
+ };
12955
+ const displayValue = getDisplayValue(promotion);
12956
+ return /* @__PURE__ */ jsxs(
12957
+ "div",
12958
+ {
12959
+ className: clx(
12960
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12961
+ {
12962
+ "animate-pulse": isLoading
12963
+ }
12964
+ ),
12965
+ children: [
12966
+ /* @__PURE__ */ jsxs("div", { children: [
12967
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12968
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12969
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
12970
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
12971
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
12972
+ ] }),
12973
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12974
+ ] })
12975
+ ] }),
12976
+ /* @__PURE__ */ jsx(
12977
+ IconButton,
12971
12978
  {
12972
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
- stroke: "#A1A1AA",
12974
- strokeWidth: "1.5",
12975
- strokeLinecap: "round",
12976
- strokeLinejoin: "round"
12979
+ size: "small",
12980
+ type: "button",
12981
+ variant: "transparent",
12982
+ onClick: onRemove,
12983
+ isLoading: isPending || isLoading,
12984
+ children: /* @__PURE__ */ jsx(XMark, {})
12977
12985
  }
12978
- ) }),
12979
- /* @__PURE__ */ jsxs("defs", { children: [
12980
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
- "rect",
12982
- {
12983
- width: "12",
12984
- height: "12",
12985
- fill: "white",
12986
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12987
- }
12988
- ) }),
12989
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
- "rect",
12991
- {
12992
- width: "12",
12993
- height: "12",
12994
- fill: "white",
12995
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12996
- }
12997
- ) }),
12998
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
- "rect",
13000
- {
13001
- width: "12",
13002
- height: "12",
13003
- fill: "white",
13004
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13005
- }
13006
- ) }),
13007
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
- "rect",
13009
- {
13010
- width: "12",
13011
- height: "12",
13012
- fill: "white",
13013
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13014
- }
13015
- ) }),
13016
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
- "rect",
13018
- {
13019
- width: "12",
13020
- height: "12",
13021
- fill: "white",
13022
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13023
- }
13024
- ) }),
13025
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
- "rect",
13027
- {
13028
- width: "12",
13029
- height: "12",
13030
- fill: "white",
13031
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13032
- }
13033
- ) })
13034
- ] })
12986
+ )
13035
12987
  ]
13036
- }
12988
+ },
12989
+ promotion.id
13037
12990
  );
13038
12991
  };
13039
- const schema = objectType({
13040
- customer_id: stringType().min(1)
12992
+ function getDisplayValue(promotion) {
12993
+ var _a, _b, _c, _d;
12994
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12995
+ if (!value) {
12996
+ return null;
12997
+ }
12998
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12999
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13000
+ if (!currency) {
13001
+ return null;
13002
+ }
13003
+ return getLocaleAmount(value, currency);
13004
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13005
+ return formatPercentage(value);
13006
+ }
13007
+ return null;
13008
+ }
13009
+ const formatter = new Intl.NumberFormat([], {
13010
+ style: "percent",
13011
+ minimumFractionDigits: 2
13041
13012
  });
13013
+ const formatPercentage = (value, isPercentageValue = false) => {
13014
+ let val = value || 0;
13015
+ if (!isPercentageValue) {
13016
+ val = val / 100;
13017
+ }
13018
+ return formatter.format(val);
13019
+ };
13020
+ function getPromotionIds(items, shippingMethods) {
13021
+ const promotionIds = /* @__PURE__ */ new Set();
13022
+ for (const item of items) {
13023
+ if (item.adjustments) {
13024
+ for (const adjustment of item.adjustments) {
13025
+ if (adjustment.promotion_id) {
13026
+ promotionIds.add(adjustment.promotion_id);
13027
+ }
13028
+ }
13029
+ }
13030
+ }
13031
+ for (const shippingMethod of shippingMethods) {
13032
+ if (shippingMethod.adjustments) {
13033
+ for (const adjustment of shippingMethod.adjustments) {
13034
+ if (adjustment.promotion_id) {
13035
+ promotionIds.add(adjustment.promotion_id);
13036
+ }
13037
+ }
13038
+ }
13039
+ }
13040
+ return Array.from(promotionIds);
13041
+ }
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13079,18 +13079,10 @@ const routeModule = {
13079
13079
  Component: Metadata,
13080
13080
  path: "/draft-orders/:id/metadata"
13081
13081
  },
13082
- {
13083
- Component: Promotions,
13084
- path: "/draft-orders/:id/promotions"
13085
- },
13086
13082
  {
13087
13083
  Component: SalesChannel,
13088
13084
  path: "/draft-orders/:id/sales-channel"
13089
13085
  },
13090
- {
13091
- Component: Shipping,
13092
- path: "/draft-orders/:id/shipping"
13093
- },
13094
13086
  {
13095
13087
  Component: ShippingAddress,
13096
13088
  path: "/draft-orders/:id/shipping-address"
@@ -13098,6 +13090,14 @@ const routeModule = {
13098
13090
  {
13099
13091
  Component: TransferOwnership,
13100
13092
  path: "/draft-orders/:id/transfer-ownership"
13093
+ },
13094
+ {
13095
+ Component: Shipping,
13096
+ path: "/draft-orders/:id/shipping"
13097
+ },
13098
+ {
13099
+ Component: Promotions,
13100
+ path: "/draft-orders/:id/promotions"
13101
13101
  }
13102
13102
  ]
13103
13103
  }