@medusajs/draft-order 2.10.4-preview-20250922120207 → 2.10.4-preview-20250922150158

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9573,6 +9573,27 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
+ const CustomItems = () => {
9577
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9579
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9580
+ ] });
9581
+ };
9582
+ const CustomItemsForm = () => {
9583
+ const form = reactHookForm.useForm({
9584
+ resolver: zod.zodResolver(schema$5)
9585
+ });
9586
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9590
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9591
+ ] }) })
9592
+ ] }) });
9593
+ };
9594
+ const schema$5 = objectType({
9595
+ email: stringType().email()
9596
+ });
9576
9597
  const Email = () => {
9577
9598
  const { id } = reactRouterDom.useParams();
9578
9599
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9595,7 +9616,7 @@ const EmailForm = ({ order }) => {
9595
9616
  defaultValues: {
9596
9617
  email: order.email ?? ""
9597
9618
  },
9598
- resolver: zod.zodResolver(schema$5)
9619
+ resolver: zod.zodResolver(schema$4)
9599
9620
  });
9600
9621
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9601
9622
  const { handleSuccess } = useRouteModal();
@@ -9638,27 +9659,6 @@ const EmailForm = ({ order }) => {
9638
9659
  }
9639
9660
  ) });
9640
9661
  };
9641
- const schema$5 = objectType({
9642
- email: stringType().email()
9643
- });
9644
- const CustomItems = () => {
9645
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9646
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9647
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9648
- ] });
9649
- };
9650
- const CustomItemsForm = () => {
9651
- const form = reactHookForm.useForm({
9652
- resolver: zod.zodResolver(schema$4)
9653
- });
9654
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9655
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9656
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9657
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9658
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9659
- ] }) })
9660
- ] }) });
9661
- };
9662
9662
  const schema$4 = objectType({
9663
9663
  email: stringType().email()
9664
9664
  });
@@ -11263,386 +11263,77 @@ function getPromotionIds(items, shippingMethods) {
11263
11263
  }
11264
11264
  return Array.from(promotionIds);
11265
11265
  }
11266
- const SalesChannel = () => {
11266
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11267
+ const Shipping = () => {
11268
+ var _a;
11267
11269
  const { id } = reactRouterDom.useParams();
11268
- const { draft_order, isPending, isError, error } = useDraftOrder(
11269
- id,
11270
- {
11271
- fields: "+sales_channel_id"
11272
- },
11273
- {
11274
- enabled: !!id
11275
- }
11276
- );
11270
+ const { order, isPending, isError, error } = useOrder(id, {
11271
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11272
+ });
11273
+ const {
11274
+ order: preview,
11275
+ isPending: isPreviewPending,
11276
+ isError: isPreviewError,
11277
+ error: previewError
11278
+ } = useOrderPreview(id);
11279
+ useInitiateOrderEdit({ preview });
11280
+ const { onCancel } = useCancelOrderEdit({ preview });
11277
11281
  if (isError) {
11278
11282
  throw error;
11279
11283
  }
11280
- const ISrEADY = !!draft_order && !isPending;
11281
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11282
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11283
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11284
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11285
- ] }),
11286
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11287
- ] });
11284
+ if (isPreviewError) {
11285
+ throw previewError;
11286
+ }
11287
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11288
+ const isReady = preview && !isPreviewPending && order && !isPending;
11289
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11290
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11291
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11292
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11293
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11294
+ ] }) }) }),
11295
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11296
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11297
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11298
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11299
+ ] }) });
11288
11300
  };
11289
- const SalesChannelForm = ({ order }) => {
11290
- const form = reactHookForm.useForm({
11291
- defaultValues: {
11292
- sales_channel_id: order.sales_channel_id || ""
11293
- },
11294
- resolver: zod.zodResolver(schema$3)
11295
- });
11296
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11297
- const { handleSuccess } = useRouteModal();
11298
- const onSubmit = form.handleSubmit(async (data) => {
11299
- await mutateAsync(
11300
- {
11301
- sales_channel_id: data.sales_channel_id
11302
- },
11303
- {
11304
- onSuccess: () => {
11305
- ui.toast.success("Sales channel updated");
11306
- handleSuccess();
11307
- },
11308
- onError: (error) => {
11309
- ui.toast.error(error.message);
11310
- }
11311
- }
11312
- );
11313
- });
11314
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11315
- KeyboundForm,
11301
+ const ShippingForm = ({ preview, order }) => {
11302
+ var _a;
11303
+ const { setIsOpen } = useStackedModal();
11304
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11305
+ const [data, setData] = React.useState(null);
11306
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11307
+ const { shipping_options } = useShippingOptions(
11316
11308
  {
11317
- className: "flex flex-1 flex-col overflow-hidden",
11318
- onSubmit,
11319
- children: [
11320
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11321
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11322
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11323
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11324
- ] }) })
11325
- ]
11326
- }
11327
- ) });
11328
- };
11329
- const SalesChannelField = ({ control, order }) => {
11330
- const salesChannels = useComboboxData({
11331
- queryFn: async (params) => {
11332
- return await sdk.admin.salesChannel.list(params);
11333
- },
11334
- queryKey: ["sales-channels"],
11335
- getOptions: (data) => {
11336
- return data.sales_channels.map((salesChannel) => ({
11337
- label: salesChannel.name,
11338
- value: salesChannel.id
11339
- }));
11309
+ id: appliedShippingOptionIds,
11310
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11340
11311
  },
11341
- defaultValue: order.sales_channel_id || void 0
11342
- });
11343
- return /* @__PURE__ */ jsxRuntime.jsx(
11344
- Form$2.Field,
11345
11312
  {
11346
- control,
11347
- name: "sales_channel_id",
11348
- render: ({ field }) => {
11349
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11352
- Combobox,
11353
- {
11354
- options: salesChannels.options,
11355
- fetchNextPage: salesChannels.fetchNextPage,
11356
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11357
- searchValue: salesChannels.searchValue,
11358
- onSearchValueChange: salesChannels.onSearchValueChange,
11359
- placeholder: "Select sales channel",
11360
- ...field
11361
- }
11362
- ) }),
11363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11364
- ] });
11365
- }
11313
+ enabled: appliedShippingOptionIds.length > 0
11366
11314
  }
11367
11315
  );
11368
- };
11369
- const schema$3 = objectType({
11370
- sales_channel_id: stringType().min(1)
11371
- });
11372
- const ShippingAddress = () => {
11373
- const { id } = reactRouterDom.useParams();
11374
- const { order, isPending, isError, error } = useOrder(id, {
11375
- fields: "+shipping_address"
11376
- });
11377
- if (isError) {
11378
- throw error;
11379
- }
11380
- const isReady = !isPending && !!order;
11381
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11382
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11383
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11384
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11385
- ] }),
11386
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11387
- ] });
11388
- };
11389
- const ShippingAddressForm = ({ order }) => {
11390
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11391
- const form = reactHookForm.useForm({
11392
- defaultValues: {
11393
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11394
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11395
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11396
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11397
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11398
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11399
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11400
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11401
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11402
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11403
- },
11404
- resolver: zod.zodResolver(schema$2)
11405
- });
11406
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11316
+ const uniqueShippingProfiles = React.useMemo(() => {
11317
+ const profiles = /* @__PURE__ */ new Map();
11318
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11319
+ profiles.set(profile.id, profile);
11320
+ });
11321
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11322
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11323
+ });
11324
+ return Array.from(profiles.values());
11325
+ }, [order.items, shipping_options]);
11407
11326
  const { handleSuccess } = useRouteModal();
11408
- const onSubmit = form.handleSubmit(async (data) => {
11409
- await mutateAsync(
11410
- {
11411
- shipping_address: {
11412
- first_name: data.first_name,
11413
- last_name: data.last_name,
11414
- company: data.company,
11415
- address_1: data.address_1,
11416
- address_2: data.address_2,
11417
- city: data.city,
11418
- province: data.province,
11419
- country_code: data.country_code,
11420
- postal_code: data.postal_code,
11421
- phone: data.phone
11422
- }
11423
- },
11424
- {
11425
- onSuccess: () => {
11426
- handleSuccess();
11427
- },
11428
- onError: (error) => {
11429
- ui.toast.error(error.message);
11430
- }
11431
- }
11432
- );
11433
- });
11434
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11435
- KeyboundForm,
11436
- {
11437
- className: "flex flex-1 flex-col overflow-hidden",
11438
- onSubmit,
11439
- children: [
11440
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11441
- /* @__PURE__ */ jsxRuntime.jsx(
11442
- Form$2.Field,
11443
- {
11444
- control: form.control,
11445
- name: "country_code",
11446
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11447
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11448
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11450
- ] })
11451
- }
11452
- ),
11453
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11454
- /* @__PURE__ */ jsxRuntime.jsx(
11455
- Form$2.Field,
11456
- {
11457
- control: form.control,
11458
- name: "first_name",
11459
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11460
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11461
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11462
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11463
- ] })
11464
- }
11465
- ),
11466
- /* @__PURE__ */ jsxRuntime.jsx(
11467
- Form$2.Field,
11468
- {
11469
- control: form.control,
11470
- name: "last_name",
11471
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11472
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11473
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11474
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11475
- ] })
11476
- }
11477
- )
11478
- ] }),
11479
- /* @__PURE__ */ jsxRuntime.jsx(
11480
- Form$2.Field,
11481
- {
11482
- control: form.control,
11483
- name: "company",
11484
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11485
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11486
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11487
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11488
- ] })
11489
- }
11490
- ),
11491
- /* @__PURE__ */ jsxRuntime.jsx(
11492
- Form$2.Field,
11493
- {
11494
- control: form.control,
11495
- name: "address_1",
11496
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11497
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11498
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11499
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11500
- ] })
11501
- }
11502
- ),
11503
- /* @__PURE__ */ jsxRuntime.jsx(
11504
- Form$2.Field,
11505
- {
11506
- control: form.control,
11507
- name: "address_2",
11508
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11509
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11510
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11511
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11512
- ] })
11513
- }
11514
- ),
11515
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11516
- /* @__PURE__ */ jsxRuntime.jsx(
11517
- Form$2.Field,
11518
- {
11519
- control: form.control,
11520
- name: "postal_code",
11521
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11522
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11523
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11524
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11525
- ] })
11526
- }
11527
- ),
11528
- /* @__PURE__ */ jsxRuntime.jsx(
11529
- Form$2.Field,
11530
- {
11531
- control: form.control,
11532
- name: "city",
11533
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11534
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11535
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11536
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11537
- ] })
11538
- }
11539
- )
11540
- ] }),
11541
- /* @__PURE__ */ jsxRuntime.jsx(
11542
- Form$2.Field,
11543
- {
11544
- control: form.control,
11545
- name: "province",
11546
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11547
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11548
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11549
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11550
- ] })
11551
- }
11552
- ),
11553
- /* @__PURE__ */ jsxRuntime.jsx(
11554
- Form$2.Field,
11555
- {
11556
- control: form.control,
11557
- name: "phone",
11558
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11559
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11560
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11561
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11562
- ] })
11563
- }
11564
- )
11565
- ] }) }),
11566
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11567
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11568
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11569
- ] }) })
11570
- ]
11571
- }
11572
- ) });
11573
- };
11574
- const schema$2 = addressSchema;
11575
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11576
- const Shipping = () => {
11577
- var _a;
11578
- const { id } = reactRouterDom.useParams();
11579
- const { order, isPending, isError, error } = useOrder(id, {
11580
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11581
- });
11582
- const {
11583
- order: preview,
11584
- isPending: isPreviewPending,
11585
- isError: isPreviewError,
11586
- error: previewError
11587
- } = useOrderPreview(id);
11588
- useInitiateOrderEdit({ preview });
11589
- const { onCancel } = useCancelOrderEdit({ preview });
11590
- if (isError) {
11591
- throw error;
11592
- }
11593
- if (isPreviewError) {
11594
- throw previewError;
11595
- }
11596
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11597
- const isReady = preview && !isPreviewPending && order && !isPending;
11598
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11599
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11600
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11601
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11602
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11603
- ] }) }) }),
11604
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11605
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11606
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11607
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11608
- ] }) });
11609
- };
11610
- const ShippingForm = ({ preview, order }) => {
11611
- var _a;
11612
- const { setIsOpen } = useStackedModal();
11613
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11614
- const [data, setData] = React.useState(null);
11615
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11616
- const { shipping_options } = useShippingOptions(
11617
- {
11618
- id: appliedShippingOptionIds,
11619
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11620
- },
11621
- {
11622
- enabled: appliedShippingOptionIds.length > 0
11623
- }
11624
- );
11625
- const uniqueShippingProfiles = React.useMemo(() => {
11626
- const profiles = /* @__PURE__ */ new Map();
11627
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11628
- profiles.set(profile.id, profile);
11629
- });
11630
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11631
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11632
- });
11633
- return Array.from(profiles.values());
11634
- }, [order.items, shipping_options]);
11635
- const { handleSuccess } = useRouteModal();
11636
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11637
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11638
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11639
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11640
- const onSubmit = async () => {
11641
- setIsSubmitting(true);
11642
- let requestSucceeded = false;
11643
- await requestOrderEdit(void 0, {
11644
- onError: (e) => {
11645
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11327
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11328
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11329
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11330
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11331
+ const onSubmit = async () => {
11332
+ setIsSubmitting(true);
11333
+ let requestSucceeded = false;
11334
+ await requestOrderEdit(void 0, {
11335
+ onError: (e) => {
11336
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11646
11337
  },
11647
11338
  onSuccess: () => {
11648
11339
  requestSucceeded = true;
@@ -12379,46 +12070,249 @@ const CustomAmountField = ({
12379
12070
  }
12380
12071
  );
12381
12072
  };
12382
- const TransferOwnership = () => {
12073
+ const ShippingAddress = () => {
12383
12074
  const { id } = reactRouterDom.useParams();
12384
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12385
- fields: "id,customer_id,customer.*"
12075
+ const { order, isPending, isError, error } = useOrder(id, {
12076
+ fields: "+shipping_address"
12386
12077
  });
12387
12078
  if (isError) {
12388
12079
  throw error;
12389
12080
  }
12390
- const isReady = !isPending && !!draft_order;
12081
+ const isReady = !isPending && !!order;
12391
12082
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12392
12083
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12393
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12394
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12084
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12085
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12395
12086
  ] }),
12396
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12087
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12397
12088
  ] });
12398
12089
  };
12399
- const TransferOwnershipForm = ({ order }) => {
12400
- var _a, _b;
12090
+ const ShippingAddressForm = ({ order }) => {
12091
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12401
12092
  const form = reactHookForm.useForm({
12402
12093
  defaultValues: {
12403
- customer_id: order.customer_id || ""
12094
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12095
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12096
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12097
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12098
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12099
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12100
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12101
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12102
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12103
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12404
12104
  },
12405
- resolver: zod.zodResolver(schema$1)
12105
+ resolver: zod.zodResolver(schema$3)
12406
12106
  });
12407
12107
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12408
12108
  const { handleSuccess } = useRouteModal();
12409
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12410
- const currentCustomer = order.customer ? {
12411
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12412
- value: order.customer.id
12413
- } : null;
12414
12109
  const onSubmit = form.handleSubmit(async (data) => {
12415
12110
  await mutateAsync(
12416
- { customer_id: data.customer_id },
12417
12111
  {
12418
- onSuccess: () => {
12419
- ui.toast.success("Customer updated");
12420
- handleSuccess();
12421
- },
12112
+ shipping_address: {
12113
+ first_name: data.first_name,
12114
+ last_name: data.last_name,
12115
+ company: data.company,
12116
+ address_1: data.address_1,
12117
+ address_2: data.address_2,
12118
+ city: data.city,
12119
+ province: data.province,
12120
+ country_code: data.country_code,
12121
+ postal_code: data.postal_code,
12122
+ phone: data.phone
12123
+ }
12124
+ },
12125
+ {
12126
+ onSuccess: () => {
12127
+ handleSuccess();
12128
+ },
12129
+ onError: (error) => {
12130
+ ui.toast.error(error.message);
12131
+ }
12132
+ }
12133
+ );
12134
+ });
12135
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12136
+ KeyboundForm,
12137
+ {
12138
+ className: "flex flex-1 flex-col overflow-hidden",
12139
+ onSubmit,
12140
+ children: [
12141
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12142
+ /* @__PURE__ */ jsxRuntime.jsx(
12143
+ Form$2.Field,
12144
+ {
12145
+ control: form.control,
12146
+ name: "country_code",
12147
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12148
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12149
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12150
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12151
+ ] })
12152
+ }
12153
+ ),
12154
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12155
+ /* @__PURE__ */ jsxRuntime.jsx(
12156
+ Form$2.Field,
12157
+ {
12158
+ control: form.control,
12159
+ name: "first_name",
12160
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12161
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12162
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12163
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12164
+ ] })
12165
+ }
12166
+ ),
12167
+ /* @__PURE__ */ jsxRuntime.jsx(
12168
+ Form$2.Field,
12169
+ {
12170
+ control: form.control,
12171
+ name: "last_name",
12172
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12173
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12174
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12175
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12176
+ ] })
12177
+ }
12178
+ )
12179
+ ] }),
12180
+ /* @__PURE__ */ jsxRuntime.jsx(
12181
+ Form$2.Field,
12182
+ {
12183
+ control: form.control,
12184
+ name: "company",
12185
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12186
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12187
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12188
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12189
+ ] })
12190
+ }
12191
+ ),
12192
+ /* @__PURE__ */ jsxRuntime.jsx(
12193
+ Form$2.Field,
12194
+ {
12195
+ control: form.control,
12196
+ name: "address_1",
12197
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12198
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12199
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12200
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12201
+ ] })
12202
+ }
12203
+ ),
12204
+ /* @__PURE__ */ jsxRuntime.jsx(
12205
+ Form$2.Field,
12206
+ {
12207
+ control: form.control,
12208
+ name: "address_2",
12209
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12210
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12211
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12212
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12213
+ ] })
12214
+ }
12215
+ ),
12216
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12217
+ /* @__PURE__ */ jsxRuntime.jsx(
12218
+ Form$2.Field,
12219
+ {
12220
+ control: form.control,
12221
+ name: "postal_code",
12222
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12223
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12224
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12225
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12226
+ ] })
12227
+ }
12228
+ ),
12229
+ /* @__PURE__ */ jsxRuntime.jsx(
12230
+ Form$2.Field,
12231
+ {
12232
+ control: form.control,
12233
+ name: "city",
12234
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12235
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12236
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12237
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12238
+ ] })
12239
+ }
12240
+ )
12241
+ ] }),
12242
+ /* @__PURE__ */ jsxRuntime.jsx(
12243
+ Form$2.Field,
12244
+ {
12245
+ control: form.control,
12246
+ name: "province",
12247
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12248
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12249
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12250
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12251
+ ] })
12252
+ }
12253
+ ),
12254
+ /* @__PURE__ */ jsxRuntime.jsx(
12255
+ Form$2.Field,
12256
+ {
12257
+ control: form.control,
12258
+ name: "phone",
12259
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12260
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12261
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12262
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12263
+ ] })
12264
+ }
12265
+ )
12266
+ ] }) }),
12267
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12268
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12269
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12270
+ ] }) })
12271
+ ]
12272
+ }
12273
+ ) });
12274
+ };
12275
+ const schema$3 = addressSchema;
12276
+ const TransferOwnership = () => {
12277
+ const { id } = reactRouterDom.useParams();
12278
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12279
+ fields: "id,customer_id,customer.*"
12280
+ });
12281
+ if (isError) {
12282
+ throw error;
12283
+ }
12284
+ const isReady = !isPending && !!draft_order;
12285
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12286
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12287
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12288
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12289
+ ] }),
12290
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12291
+ ] });
12292
+ };
12293
+ const TransferOwnershipForm = ({ order }) => {
12294
+ var _a, _b;
12295
+ const form = reactHookForm.useForm({
12296
+ defaultValues: {
12297
+ customer_id: order.customer_id || ""
12298
+ },
12299
+ resolver: zod.zodResolver(schema$2)
12300
+ });
12301
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12302
+ const { handleSuccess } = useRouteModal();
12303
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12304
+ const currentCustomer = order.customer ? {
12305
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12306
+ value: order.customer.id
12307
+ } : null;
12308
+ const onSubmit = form.handleSubmit(async (data) => {
12309
+ await mutateAsync(
12310
+ { customer_id: data.customer_id },
12311
+ {
12312
+ onSuccess: () => {
12313
+ ui.toast.success("Customer updated");
12314
+ handleSuccess();
12315
+ },
12422
12316
  onError: (error) => {
12423
12317
  ui.toast.error(error.message);
12424
12318
  }
@@ -12852,7 +12746,7 @@ const Illustration = () => {
12852
12746
  }
12853
12747
  );
12854
12748
  };
12855
- const schema$1 = objectType({
12749
+ const schema$2 = objectType({
12856
12750
  customer_id: stringType().min(1)
12857
12751
  });
12858
12752
  const BillingAddress = () => {
@@ -12887,7 +12781,7 @@ const BillingAddressForm = ({ order }) => {
12887
12781
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12888
12782
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12889
12783
  },
12890
- resolver: zod.zodResolver(schema)
12784
+ resolver: zod.zodResolver(schema$1)
12891
12785
  });
12892
12786
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12893
12787
  const { handleSuccess } = useRouteModal();
@@ -13044,7 +12938,113 @@ const BillingAddressForm = ({ order }) => {
13044
12938
  }
13045
12939
  ) });
13046
12940
  };
13047
- const schema = addressSchema;
12941
+ const schema$1 = addressSchema;
12942
+ const SalesChannel = () => {
12943
+ const { id } = reactRouterDom.useParams();
12944
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12945
+ id,
12946
+ {
12947
+ fields: "+sales_channel_id"
12948
+ },
12949
+ {
12950
+ enabled: !!id
12951
+ }
12952
+ );
12953
+ if (isError) {
12954
+ throw error;
12955
+ }
12956
+ const ISrEADY = !!draft_order && !isPending;
12957
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12959
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12960
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12961
+ ] }),
12962
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12963
+ ] });
12964
+ };
12965
+ const SalesChannelForm = ({ order }) => {
12966
+ const form = reactHookForm.useForm({
12967
+ defaultValues: {
12968
+ sales_channel_id: order.sales_channel_id || ""
12969
+ },
12970
+ resolver: zod.zodResolver(schema)
12971
+ });
12972
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12973
+ const { handleSuccess } = useRouteModal();
12974
+ const onSubmit = form.handleSubmit(async (data) => {
12975
+ await mutateAsync(
12976
+ {
12977
+ sales_channel_id: data.sales_channel_id
12978
+ },
12979
+ {
12980
+ onSuccess: () => {
12981
+ ui.toast.success("Sales channel updated");
12982
+ handleSuccess();
12983
+ },
12984
+ onError: (error) => {
12985
+ ui.toast.error(error.message);
12986
+ }
12987
+ }
12988
+ );
12989
+ });
12990
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12991
+ KeyboundForm,
12992
+ {
12993
+ className: "flex flex-1 flex-col overflow-hidden",
12994
+ onSubmit,
12995
+ children: [
12996
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12998
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12999
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13000
+ ] }) })
13001
+ ]
13002
+ }
13003
+ ) });
13004
+ };
13005
+ const SalesChannelField = ({ control, order }) => {
13006
+ const salesChannels = useComboboxData({
13007
+ queryFn: async (params) => {
13008
+ return await sdk.admin.salesChannel.list(params);
13009
+ },
13010
+ queryKey: ["sales-channels"],
13011
+ getOptions: (data) => {
13012
+ return data.sales_channels.map((salesChannel) => ({
13013
+ label: salesChannel.name,
13014
+ value: salesChannel.id
13015
+ }));
13016
+ },
13017
+ defaultValue: order.sales_channel_id || void 0
13018
+ });
13019
+ return /* @__PURE__ */ jsxRuntime.jsx(
13020
+ Form$2.Field,
13021
+ {
13022
+ control,
13023
+ name: "sales_channel_id",
13024
+ render: ({ field }) => {
13025
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13026
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13027
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13028
+ Combobox,
13029
+ {
13030
+ options: salesChannels.options,
13031
+ fetchNextPage: salesChannels.fetchNextPage,
13032
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13033
+ searchValue: salesChannels.searchValue,
13034
+ onSearchValueChange: salesChannels.onSearchValueChange,
13035
+ placeholder: "Select sales channel",
13036
+ ...field
13037
+ }
13038
+ ) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13040
+ ] });
13041
+ }
13042
+ }
13043
+ );
13044
+ };
13045
+ const schema = objectType({
13046
+ sales_channel_id: stringType().min(1)
13047
+ });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13065,14 +13065,14 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
- {
13069
- Component: Email,
13070
- path: "/draft-orders/:id/email"
13071
- },
13072
13068
  {
13073
13069
  Component: CustomItems,
13074
13070
  path: "/draft-orders/:id/custom-items"
13075
13071
  },
13072
+ {
13073
+ Component: Email,
13074
+ path: "/draft-orders/:id/email"
13075
+ },
13076
13076
  {
13077
13077
  Component: Items,
13078
13078
  path: "/draft-orders/:id/items"
@@ -13086,17 +13086,13 @@ const routeModule = {
13086
13086
  path: "/draft-orders/:id/promotions"
13087
13087
  },
13088
13088
  {
13089
- Component: SalesChannel,
13090
- path: "/draft-orders/:id/sales-channel"
13089
+ Component: Shipping,
13090
+ path: "/draft-orders/:id/shipping"
13091
13091
  },
13092
13092
  {
13093
13093
  Component: ShippingAddress,
13094
13094
  path: "/draft-orders/:id/shipping-address"
13095
13095
  },
13096
- {
13097
- Component: Shipping,
13098
- path: "/draft-orders/:id/shipping"
13099
- },
13100
13096
  {
13101
13097
  Component: TransferOwnership,
13102
13098
  path: "/draft-orders/:id/transfer-ownership"
@@ -13104,6 +13100,10 @@ const routeModule = {
13104
13100
  {
13105
13101
  Component: BillingAddress,
13106
13102
  path: "/draft-orders/:id/billing-address"
13103
+ },
13104
+ {
13105
+ Component: SalesChannel,
13106
+ path: "/draft-orders/:id/sales-channel"
13107
13107
  }
13108
13108
  ]
13109
13109
  }