@medusajs/draft-order 2.11.3-preview-20251103113757 → 2.11.3-preview-20251103120146

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.
@@ -11452,112 +11452,6 @@ function getPromotionIds(items, shippingMethods) {
11452
11452
  }
11453
11453
  return Array.from(promotionIds);
11454
11454
  }
11455
- const SalesChannel = () => {
11456
- const { id } = reactRouterDom.useParams();
11457
- const { draft_order, isPending, isError, error } = useDraftOrder(
11458
- id,
11459
- {
11460
- fields: "+sales_channel_id"
11461
- },
11462
- {
11463
- enabled: !!id
11464
- }
11465
- );
11466
- if (isError) {
11467
- throw error;
11468
- }
11469
- const ISrEADY = !!draft_order && !isPending;
11470
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11471
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11472
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11473
- /* @__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" }) })
11474
- ] }),
11475
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11476
- ] });
11477
- };
11478
- const SalesChannelForm = ({ order }) => {
11479
- const form = reactHookForm.useForm({
11480
- defaultValues: {
11481
- sales_channel_id: order.sales_channel_id || ""
11482
- },
11483
- resolver: zod.zodResolver(schema$2)
11484
- });
11485
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11486
- const { handleSuccess } = useRouteModal();
11487
- const onSubmit = form.handleSubmit(async (data) => {
11488
- await mutateAsync(
11489
- {
11490
- sales_channel_id: data.sales_channel_id
11491
- },
11492
- {
11493
- onSuccess: () => {
11494
- ui.toast.success("Sales channel updated");
11495
- handleSuccess();
11496
- },
11497
- onError: (error) => {
11498
- ui.toast.error(error.message);
11499
- }
11500
- }
11501
- );
11502
- });
11503
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11504
- KeyboundForm,
11505
- {
11506
- className: "flex flex-1 flex-col overflow-hidden",
11507
- onSubmit,
11508
- children: [
11509
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11510
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11511
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11512
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11513
- ] }) })
11514
- ]
11515
- }
11516
- ) });
11517
- };
11518
- const SalesChannelField = ({ control, order }) => {
11519
- const salesChannels = useComboboxData({
11520
- queryFn: async (params) => {
11521
- return await sdk.admin.salesChannel.list(params);
11522
- },
11523
- queryKey: ["sales-channels"],
11524
- getOptions: (data) => {
11525
- return data.sales_channels.map((salesChannel) => ({
11526
- label: salesChannel.name,
11527
- value: salesChannel.id
11528
- }));
11529
- },
11530
- defaultValue: order.sales_channel_id || void 0
11531
- });
11532
- return /* @__PURE__ */ jsxRuntime.jsx(
11533
- Form$2.Field,
11534
- {
11535
- control,
11536
- name: "sales_channel_id",
11537
- render: ({ field }) => {
11538
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11539
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11541
- Combobox,
11542
- {
11543
- options: salesChannels.options,
11544
- fetchNextPage: salesChannels.fetchNextPage,
11545
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11546
- searchValue: salesChannels.searchValue,
11547
- onSearchValueChange: salesChannels.onSearchValueChange,
11548
- placeholder: "Select sales channel",
11549
- ...field
11550
- }
11551
- ) }),
11552
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11553
- ] });
11554
- }
11555
- }
11556
- );
11557
- };
11558
- const schema$2 = objectType({
11559
- sales_channel_id: stringType().min(1)
11560
- });
11561
11455
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11562
11456
  const Shipping = () => {
11563
11457
  var _a;
@@ -12365,44 +12259,60 @@ const CustomAmountField = ({
12365
12259
  }
12366
12260
  );
12367
12261
  };
12368
- const TransferOwnership = () => {
12262
+ const ShippingAddress = () => {
12369
12263
  const { id } = reactRouterDom.useParams();
12370
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12371
- fields: "id,customer_id,customer.*"
12264
+ const { order, isPending, isError, error } = useOrder(id, {
12265
+ fields: "+shipping_address"
12372
12266
  });
12373
12267
  if (isError) {
12374
12268
  throw error;
12375
12269
  }
12376
- const isReady = !isPending && !!draft_order;
12270
+ const isReady = !isPending && !!order;
12377
12271
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12378
12272
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12379
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12380
- /* @__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" }) })
12273
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12274
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12381
12275
  ] }),
12382
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12276
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12383
12277
  ] });
12384
12278
  };
12385
- const TransferOwnershipForm = ({ order }) => {
12386
- var _a, _b;
12279
+ const ShippingAddressForm = ({ order }) => {
12280
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12387
12281
  const form = reactHookForm.useForm({
12388
12282
  defaultValues: {
12389
- customer_id: order.customer_id || ""
12283
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12284
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12285
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12286
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12287
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12288
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12289
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12290
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12291
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12292
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12390
12293
  },
12391
- resolver: zod.zodResolver(schema$1)
12294
+ resolver: zod.zodResolver(schema$2)
12392
12295
  });
12393
12296
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12394
12297
  const { handleSuccess } = useRouteModal();
12395
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12396
- const currentCustomer = order.customer ? {
12397
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12398
- value: order.customer.id
12399
- } : null;
12400
12298
  const onSubmit = form.handleSubmit(async (data) => {
12401
12299
  await mutateAsync(
12402
- { customer_id: data.customer_id },
12300
+ {
12301
+ shipping_address: {
12302
+ first_name: data.first_name,
12303
+ last_name: data.last_name,
12304
+ company: data.company,
12305
+ address_1: data.address_1,
12306
+ address_2: data.address_2,
12307
+ city: data.city,
12308
+ province: data.province,
12309
+ country_code: data.country_code,
12310
+ postal_code: data.postal_code,
12311
+ phone: data.phone
12312
+ }
12313
+ },
12403
12314
  {
12404
12315
  onSuccess: () => {
12405
- ui.toast.success("Customer updated");
12406
12316
  handleSuccess();
12407
12317
  },
12408
12318
  onError: (error) => {
@@ -12417,65 +12327,252 @@ const TransferOwnershipForm = ({ order }) => {
12417
12327
  className: "flex flex-1 flex-col overflow-hidden",
12418
12328
  onSubmit,
12419
12329
  children: [
12420
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12421
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12422
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12423
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12424
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12425
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12426
- ] }),
12427
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12428
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12429
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12430
- ] })
12330
+ /* @__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: [
12331
+ /* @__PURE__ */ jsxRuntime.jsx(
12332
+ Form$2.Field,
12333
+ {
12334
+ control: form.control,
12335
+ name: "country_code",
12336
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12337
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12338
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12339
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12340
+ ] })
12341
+ }
12342
+ ),
12343
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12344
+ /* @__PURE__ */ jsxRuntime.jsx(
12345
+ Form$2.Field,
12346
+ {
12347
+ control: form.control,
12348
+ name: "first_name",
12349
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12350
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12351
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12353
+ ] })
12354
+ }
12355
+ ),
12356
+ /* @__PURE__ */ jsxRuntime.jsx(
12357
+ Form$2.Field,
12358
+ {
12359
+ control: form.control,
12360
+ name: "last_name",
12361
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12362
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12363
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12364
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12365
+ ] })
12366
+ }
12367
+ )
12431
12368
  ] }),
12432
12369
  /* @__PURE__ */ jsxRuntime.jsx(
12433
- CustomerField,
12370
+ Form$2.Field,
12434
12371
  {
12435
12372
  control: form.control,
12436
- currentCustomerId: order.customer_id
12373
+ name: "company",
12374
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12375
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12376
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12377
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12378
+ ] })
12437
12379
  }
12438
- )
12439
- ] }),
12440
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12441
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12442
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12443
- ] }) })
12444
- ]
12445
- }
12446
- ) });
12447
- };
12448
- const CustomerField = ({ control, currentCustomerId }) => {
12449
- const customers = useComboboxData({
12450
- queryFn: async (params) => {
12451
- return await sdk.admin.customer.list({
12452
- ...params,
12453
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12454
- });
12455
- },
12456
- queryKey: ["customers"],
12457
- getOptions: (data) => {
12458
- return data.customers.map((customer) => {
12459
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12460
- return {
12461
- label: name ? `${name} (${customer.email})` : customer.email,
12462
- value: customer.id
12463
- };
12464
- });
12465
- }
12466
- });
12467
- return /* @__PURE__ */ jsxRuntime.jsx(
12468
- Form$2.Field,
12469
- {
12470
- name: "customer_id",
12471
- control,
12472
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12473
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12474
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12475
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12476
- ] }),
12477
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12478
- Combobox,
12380
+ ),
12381
+ /* @__PURE__ */ jsxRuntime.jsx(
12382
+ Form$2.Field,
12383
+ {
12384
+ control: form.control,
12385
+ name: "address_1",
12386
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12387
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12388
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12389
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12390
+ ] })
12391
+ }
12392
+ ),
12393
+ /* @__PURE__ */ jsxRuntime.jsx(
12394
+ Form$2.Field,
12395
+ {
12396
+ control: form.control,
12397
+ name: "address_2",
12398
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12399
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12400
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12401
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12402
+ ] })
12403
+ }
12404
+ ),
12405
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12406
+ /* @__PURE__ */ jsxRuntime.jsx(
12407
+ Form$2.Field,
12408
+ {
12409
+ control: form.control,
12410
+ name: "postal_code",
12411
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12412
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12413
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12414
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12415
+ ] })
12416
+ }
12417
+ ),
12418
+ /* @__PURE__ */ jsxRuntime.jsx(
12419
+ Form$2.Field,
12420
+ {
12421
+ control: form.control,
12422
+ name: "city",
12423
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12424
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12425
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12426
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12427
+ ] })
12428
+ }
12429
+ )
12430
+ ] }),
12431
+ /* @__PURE__ */ jsxRuntime.jsx(
12432
+ Form$2.Field,
12433
+ {
12434
+ control: form.control,
12435
+ name: "province",
12436
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12437
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12438
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12439
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12440
+ ] })
12441
+ }
12442
+ ),
12443
+ /* @__PURE__ */ jsxRuntime.jsx(
12444
+ Form$2.Field,
12445
+ {
12446
+ control: form.control,
12447
+ name: "phone",
12448
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12449
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12450
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12451
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12452
+ ] })
12453
+ }
12454
+ )
12455
+ ] }) }),
12456
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12457
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12458
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12459
+ ] }) })
12460
+ ]
12461
+ }
12462
+ ) });
12463
+ };
12464
+ const schema$2 = addressSchema;
12465
+ const TransferOwnership = () => {
12466
+ const { id } = reactRouterDom.useParams();
12467
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12468
+ fields: "id,customer_id,customer.*"
12469
+ });
12470
+ if (isError) {
12471
+ throw error;
12472
+ }
12473
+ const isReady = !isPending && !!draft_order;
12474
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12475
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12476
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12477
+ /* @__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" }) })
12478
+ ] }),
12479
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12480
+ ] });
12481
+ };
12482
+ const TransferOwnershipForm = ({ order }) => {
12483
+ var _a, _b;
12484
+ const form = reactHookForm.useForm({
12485
+ defaultValues: {
12486
+ customer_id: order.customer_id || ""
12487
+ },
12488
+ resolver: zod.zodResolver(schema$1)
12489
+ });
12490
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12491
+ const { handleSuccess } = useRouteModal();
12492
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12493
+ const currentCustomer = order.customer ? {
12494
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12495
+ value: order.customer.id
12496
+ } : null;
12497
+ const onSubmit = form.handleSubmit(async (data) => {
12498
+ await mutateAsync(
12499
+ { customer_id: data.customer_id },
12500
+ {
12501
+ onSuccess: () => {
12502
+ ui.toast.success("Customer updated");
12503
+ handleSuccess();
12504
+ },
12505
+ onError: (error) => {
12506
+ ui.toast.error(error.message);
12507
+ }
12508
+ }
12509
+ );
12510
+ });
12511
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12512
+ KeyboundForm,
12513
+ {
12514
+ className: "flex flex-1 flex-col overflow-hidden",
12515
+ onSubmit,
12516
+ children: [
12517
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12518
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12519
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12520
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12521
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12522
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12523
+ ] }),
12524
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12525
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12526
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12527
+ ] })
12528
+ ] }),
12529
+ /* @__PURE__ */ jsxRuntime.jsx(
12530
+ CustomerField,
12531
+ {
12532
+ control: form.control,
12533
+ currentCustomerId: order.customer_id
12534
+ }
12535
+ )
12536
+ ] }),
12537
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12538
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12539
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12540
+ ] }) })
12541
+ ]
12542
+ }
12543
+ ) });
12544
+ };
12545
+ const CustomerField = ({ control, currentCustomerId }) => {
12546
+ const customers = useComboboxData({
12547
+ queryFn: async (params) => {
12548
+ return await sdk.admin.customer.list({
12549
+ ...params,
12550
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12551
+ });
12552
+ },
12553
+ queryKey: ["customers"],
12554
+ getOptions: (data) => {
12555
+ return data.customers.map((customer) => {
12556
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12557
+ return {
12558
+ label: name ? `${name} (${customer.email})` : customer.email,
12559
+ value: customer.id
12560
+ };
12561
+ });
12562
+ }
12563
+ });
12564
+ return /* @__PURE__ */ jsxRuntime.jsx(
12565
+ Form$2.Field,
12566
+ {
12567
+ name: "customer_id",
12568
+ control,
12569
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12570
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12571
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12572
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12573
+ ] }),
12574
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12575
+ Combobox,
12479
12576
  {
12480
12577
  options: customers.options,
12481
12578
  fetchNextPage: customers.fetchNextPage,
@@ -12841,37 +12938,33 @@ const Illustration = () => {
12841
12938
  const schema$1 = objectType({
12842
12939
  customer_id: stringType().min(1)
12843
12940
  });
12844
- const ShippingAddress = () => {
12941
+ const SalesChannel = () => {
12845
12942
  const { id } = reactRouterDom.useParams();
12846
- const { order, isPending, isError, error } = useOrder(id, {
12847
- fields: "+shipping_address"
12848
- });
12943
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12944
+ id,
12945
+ {
12946
+ fields: "+sales_channel_id"
12947
+ },
12948
+ {
12949
+ enabled: !!id
12950
+ }
12951
+ );
12849
12952
  if (isError) {
12850
12953
  throw error;
12851
12954
  }
12852
- const isReady = !isPending && !!order;
12955
+ const ISrEADY = !!draft_order && !isPending;
12853
12956
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12854
12957
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12855
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12856
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12958
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12959
+ /* @__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" }) })
12857
12960
  ] }),
12858
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12961
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12859
12962
  ] });
12860
12963
  };
12861
- const ShippingAddressForm = ({ order }) => {
12862
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12964
+ const SalesChannelForm = ({ order }) => {
12863
12965
  const form = reactHookForm.useForm({
12864
12966
  defaultValues: {
12865
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12866
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12867
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12868
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12869
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12870
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12871
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12872
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12873
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12874
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12967
+ sales_channel_id: order.sales_channel_id || ""
12875
12968
  },
12876
12969
  resolver: zod.zodResolver(schema)
12877
12970
  });
@@ -12880,21 +12973,11 @@ const ShippingAddressForm = ({ order }) => {
12880
12973
  const onSubmit = form.handleSubmit(async (data) => {
12881
12974
  await mutateAsync(
12882
12975
  {
12883
- shipping_address: {
12884
- first_name: data.first_name,
12885
- last_name: data.last_name,
12886
- company: data.company,
12887
- address_1: data.address_1,
12888
- address_2: data.address_2,
12889
- city: data.city,
12890
- province: data.province,
12891
- country_code: data.country_code,
12892
- postal_code: data.postal_code,
12893
- phone: data.phone
12894
- }
12976
+ sales_channel_id: data.sales_channel_id
12895
12977
  },
12896
12978
  {
12897
12979
  onSuccess: () => {
12980
+ ui.toast.success("Sales channel updated");
12898
12981
  handleSuccess();
12899
12982
  },
12900
12983
  onError: (error) => {
@@ -12909,132 +12992,7 @@ const ShippingAddressForm = ({ order }) => {
12909
12992
  className: "flex flex-1 flex-col overflow-hidden",
12910
12993
  onSubmit,
12911
12994
  children: [
12912
- /* @__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: [
12913
- /* @__PURE__ */ jsxRuntime.jsx(
12914
- Form$2.Field,
12915
- {
12916
- control: form.control,
12917
- name: "country_code",
12918
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12919
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12920
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12921
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12922
- ] })
12923
- }
12924
- ),
12925
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12926
- /* @__PURE__ */ jsxRuntime.jsx(
12927
- Form$2.Field,
12928
- {
12929
- control: form.control,
12930
- name: "first_name",
12931
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12933
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
- ] })
12936
- }
12937
- ),
12938
- /* @__PURE__ */ jsxRuntime.jsx(
12939
- Form$2.Field,
12940
- {
12941
- control: form.control,
12942
- name: "last_name",
12943
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12944
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12946
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12947
- ] })
12948
- }
12949
- )
12950
- ] }),
12951
- /* @__PURE__ */ jsxRuntime.jsx(
12952
- Form$2.Field,
12953
- {
12954
- control: form.control,
12955
- name: "company",
12956
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
- ] })
12961
- }
12962
- ),
12963
- /* @__PURE__ */ jsxRuntime.jsx(
12964
- Form$2.Field,
12965
- {
12966
- control: form.control,
12967
- name: "address_1",
12968
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
- ] })
12973
- }
12974
- ),
12975
- /* @__PURE__ */ jsxRuntime.jsx(
12976
- Form$2.Field,
12977
- {
12978
- control: form.control,
12979
- name: "address_2",
12980
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12981
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12982
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12983
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12984
- ] })
12985
- }
12986
- ),
12987
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12988
- /* @__PURE__ */ jsxRuntime.jsx(
12989
- Form$2.Field,
12990
- {
12991
- control: form.control,
12992
- name: "postal_code",
12993
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12995
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
- ] })
12998
- }
12999
- ),
13000
- /* @__PURE__ */ jsxRuntime.jsx(
13001
- Form$2.Field,
13002
- {
13003
- control: form.control,
13004
- name: "city",
13005
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13006
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13008
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13009
- ] })
13010
- }
13011
- )
13012
- ] }),
13013
- /* @__PURE__ */ jsxRuntime.jsx(
13014
- Form$2.Field,
13015
- {
13016
- control: form.control,
13017
- name: "province",
13018
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
- ] })
13023
- }
13024
- ),
13025
- /* @__PURE__ */ jsxRuntime.jsx(
13026
- Form$2.Field,
13027
- {
13028
- control: form.control,
13029
- name: "phone",
13030
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13033
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13034
- ] })
13035
- }
13036
- )
13037
- ] }) }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
13038
12996
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13039
12997
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13040
12998
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13043,7 +13001,49 @@ const ShippingAddressForm = ({ order }) => {
13043
13001
  }
13044
13002
  ) });
13045
13003
  };
13046
- const schema = addressSchema;
13004
+ const SalesChannelField = ({ control, order }) => {
13005
+ const salesChannels = useComboboxData({
13006
+ queryFn: async (params) => {
13007
+ return await sdk.admin.salesChannel.list(params);
13008
+ },
13009
+ queryKey: ["sales-channels"],
13010
+ getOptions: (data) => {
13011
+ return data.sales_channels.map((salesChannel) => ({
13012
+ label: salesChannel.name,
13013
+ value: salesChannel.id
13014
+ }));
13015
+ },
13016
+ defaultValue: order.sales_channel_id || void 0
13017
+ });
13018
+ return /* @__PURE__ */ jsxRuntime.jsx(
13019
+ Form$2.Field,
13020
+ {
13021
+ control,
13022
+ name: "sales_channel_id",
13023
+ render: ({ field }) => {
13024
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13025
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13027
+ Combobox,
13028
+ {
13029
+ options: salesChannels.options,
13030
+ fetchNextPage: salesChannels.fetchNextPage,
13031
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13032
+ searchValue: salesChannels.searchValue,
13033
+ onSearchValueChange: salesChannels.onSearchValueChange,
13034
+ placeholder: "Select sales channel",
13035
+ ...field
13036
+ }
13037
+ ) }),
13038
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13039
+ ] });
13040
+ }
13041
+ }
13042
+ );
13043
+ };
13044
+ const schema = objectType({
13045
+ sales_channel_id: stringType().min(1)
13046
+ });
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
13049
13049
  routes: [
@@ -13088,21 +13088,21 @@ const routeModule = {
13088
13088
  Component: Promotions,
13089
13089
  path: "/draft-orders/:id/promotions"
13090
13090
  },
13091
- {
13092
- Component: SalesChannel,
13093
- path: "/draft-orders/:id/sales-channel"
13094
- },
13095
13091
  {
13096
13092
  Component: Shipping,
13097
13093
  path: "/draft-orders/:id/shipping"
13098
13094
  },
13095
+ {
13096
+ Component: ShippingAddress,
13097
+ path: "/draft-orders/:id/shipping-address"
13098
+ },
13099
13099
  {
13100
13100
  Component: TransferOwnership,
13101
13101
  path: "/draft-orders/:id/transfer-ownership"
13102
13102
  },
13103
13103
  {
13104
- Component: ShippingAddress,
13105
- path: "/draft-orders/:id/shipping-address"
13104
+ Component: SalesChannel,
13105
+ path: "/draft-orders/:id/sales-channel"
13106
13106
  }
13107
13107
  ]
13108
13108
  }