@medusajs/draft-order 2.10.4-preview-20251014031441 → 2.10.4-preview-20251014060203

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