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