@medusajs/draft-order 2.10.4-preview-20251004090150 → 2.10.4-preview-20251004120156

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,6 +9757,95 @@ 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
+ const Email = () => {
9782
+ const { id } = useParams();
9783
+ const { order, isPending, isError, error } = useOrder(id, {
9784
+ fields: "+email"
9785
+ });
9786
+ if (isError) {
9787
+ throw error;
9788
+ }
9789
+ const isReady = !isPending && !!order;
9790
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9791
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9792
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9793
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9794
+ ] }),
9795
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9796
+ ] });
9797
+ };
9798
+ const EmailForm = ({ order }) => {
9799
+ const form = useForm({
9800
+ defaultValues: {
9801
+ email: order.email ?? ""
9802
+ },
9803
+ resolver: zodResolver(schema$3)
9804
+ });
9805
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
+ const { handleSuccess } = useRouteModal();
9807
+ const onSubmit = form.handleSubmit(async (data) => {
9808
+ await mutateAsync(
9809
+ { email: data.email },
9810
+ {
9811
+ onSuccess: () => {
9812
+ handleSuccess();
9813
+ },
9814
+ onError: (error) => {
9815
+ toast.error(error.message);
9816
+ }
9817
+ }
9818
+ );
9819
+ });
9820
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9821
+ KeyboundForm,
9822
+ {
9823
+ className: "flex flex-1 flex-col overflow-hidden",
9824
+ onSubmit,
9825
+ children: [
9826
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9827
+ Form$2.Field,
9828
+ {
9829
+ control: form.control,
9830
+ name: "email",
9831
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9832
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9833
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9834
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9835
+ ] })
9836
+ }
9837
+ ) }),
9838
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9839
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9840
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9841
+ ] }) })
9842
+ ]
9843
+ }
9844
+ ) });
9845
+ };
9846
+ const schema$3 = objectType({
9847
+ email: stringType().email()
9848
+ });
9760
9849
  const NumberInput = forwardRef(
9761
9850
  ({
9762
9851
  value,
@@ -11358,27 +11447,6 @@ function getPromotionIds(items, shippingMethods) {
11358
11447
  }
11359
11448
  return Array.from(promotionIds);
11360
11449
  }
11361
- const CustomItems = () => {
11362
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11363
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
11364
- /* @__PURE__ */ jsx(CustomItemsForm, {})
11365
- ] });
11366
- };
11367
- const CustomItemsForm = () => {
11368
- const form = useForm({
11369
- resolver: zodResolver(schema$4)
11370
- });
11371
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11372
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
11373
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11374
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11375
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
11376
- ] }) })
11377
- ] }) });
11378
- };
11379
- const schema$4 = objectType({
11380
- email: stringType().email()
11381
- });
11382
11450
  const SalesChannel = () => {
11383
11451
  const { id } = useParams();
11384
11452
  const { draft_order, isPending, isError, error } = useDraftOrder(
@@ -11407,7 +11475,7 @@ const SalesChannelForm = ({ order }) => {
11407
11475
  defaultValues: {
11408
11476
  sales_channel_id: order.sales_channel_id || ""
11409
11477
  },
11410
- resolver: zodResolver(schema$3)
11478
+ resolver: zodResolver(schema$2)
11411
11479
  });
11412
11480
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11413
11481
  const { handleSuccess } = useRouteModal();
@@ -11482,7 +11550,7 @@ const SalesChannelField = ({ control, order }) => {
11482
11550
  }
11483
11551
  );
11484
11552
  };
11485
- const schema$3 = objectType({
11553
+ const schema$2 = objectType({
11486
11554
  sales_channel_id: stringType().min(1)
11487
11555
  });
11488
11556
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12292,44 +12360,60 @@ const CustomAmountField = ({
12292
12360
  }
12293
12361
  );
12294
12362
  };
12295
- const TransferOwnership = () => {
12363
+ const ShippingAddress = () => {
12296
12364
  const { id } = useParams();
12297
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12298
- fields: "id,customer_id,customer.*"
12365
+ const { order, isPending, isError, error } = useOrder(id, {
12366
+ fields: "+shipping_address"
12299
12367
  });
12300
12368
  if (isError) {
12301
12369
  throw error;
12302
12370
  }
12303
- const isReady = !isPending && !!draft_order;
12371
+ const isReady = !isPending && !!order;
12304
12372
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12305
12373
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12306
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12307
- /* @__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" }) })
12374
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12308
12376
  ] }),
12309
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12377
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12310
12378
  ] });
12311
12379
  };
12312
- const TransferOwnershipForm = ({ order }) => {
12313
- var _a, _b;
12380
+ const ShippingAddressForm = ({ order }) => {
12381
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12314
12382
  const form = useForm({
12315
12383
  defaultValues: {
12316
- customer_id: order.customer_id || ""
12384
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12317
12394
  },
12318
- resolver: zodResolver(schema$2)
12395
+ resolver: zodResolver(schema$1)
12319
12396
  });
12320
12397
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12321
12398
  const { handleSuccess } = useRouteModal();
12322
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12323
- const currentCustomer = order.customer ? {
12324
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12325
- value: order.customer.id
12326
- } : null;
12327
12399
  const onSubmit = form.handleSubmit(async (data) => {
12328
12400
  await mutateAsync(
12329
- { customer_id: data.customer_id },
12401
+ {
12402
+ shipping_address: {
12403
+ first_name: data.first_name,
12404
+ last_name: data.last_name,
12405
+ company: data.company,
12406
+ address_1: data.address_1,
12407
+ address_2: data.address_2,
12408
+ city: data.city,
12409
+ province: data.province,
12410
+ country_code: data.country_code,
12411
+ postal_code: data.postal_code,
12412
+ phone: data.phone
12413
+ }
12414
+ },
12330
12415
  {
12331
12416
  onSuccess: () => {
12332
- toast.success("Customer updated");
12333
12417
  handleSuccess();
12334
12418
  },
12335
12419
  onError: (error) => {
@@ -12344,56 +12428,243 @@ const TransferOwnershipForm = ({ order }) => {
12344
12428
  className: "flex flex-1 flex-col overflow-hidden",
12345
12429
  onSubmit,
12346
12430
  children: [
12347
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12348
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12349
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12350
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12351
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12352
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12353
- ] }),
12354
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12355
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12356
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12357
- ] })
12431
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12432
+ /* @__PURE__ */ jsx(
12433
+ Form$2.Field,
12434
+ {
12435
+ control: form.control,
12436
+ name: "country_code",
12437
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
+ ] })
12442
+ }
12443
+ ),
12444
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
+ /* @__PURE__ */ jsx(
12446
+ Form$2.Field,
12447
+ {
12448
+ control: form.control,
12449
+ name: "first_name",
12450
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
+ ] })
12455
+ }
12456
+ ),
12457
+ /* @__PURE__ */ jsx(
12458
+ Form$2.Field,
12459
+ {
12460
+ control: form.control,
12461
+ name: "last_name",
12462
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
+ ] })
12467
+ }
12468
+ )
12358
12469
  ] }),
12359
12470
  /* @__PURE__ */ jsx(
12360
- CustomerField,
12471
+ Form$2.Field,
12361
12472
  {
12362
12473
  control: form.control,
12363
- currentCustomerId: order.customer_id
12474
+ name: "company",
12475
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
+ ] })
12364
12480
  }
12365
- )
12366
- ] }),
12367
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12368
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12369
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12370
- ] }) })
12371
- ]
12372
- }
12373
- ) });
12374
- };
12375
- const CustomerField = ({ control, currentCustomerId }) => {
12376
- const customers = useComboboxData({
12377
- queryFn: async (params) => {
12378
- return await sdk.admin.customer.list({
12379
- ...params,
12380
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12381
- });
12382
- },
12383
- queryKey: ["customers"],
12384
- getOptions: (data) => {
12385
- return data.customers.map((customer) => {
12386
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12387
- return {
12388
- label: name ? `${name} (${customer.email})` : customer.email,
12389
- value: customer.id
12390
- };
12391
- });
12392
- }
12393
- });
12394
- return /* @__PURE__ */ jsx(
12395
- Form$2.Field,
12396
- {
12481
+ ),
12482
+ /* @__PURE__ */ jsx(
12483
+ Form$2.Field,
12484
+ {
12485
+ control: form.control,
12486
+ name: "address_1",
12487
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
+ ] })
12492
+ }
12493
+ ),
12494
+ /* @__PURE__ */ jsx(
12495
+ Form$2.Field,
12496
+ {
12497
+ control: form.control,
12498
+ name: "address_2",
12499
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
+ ] })
12504
+ }
12505
+ ),
12506
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
+ /* @__PURE__ */ jsx(
12508
+ Form$2.Field,
12509
+ {
12510
+ control: form.control,
12511
+ name: "postal_code",
12512
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
+ ] })
12517
+ }
12518
+ ),
12519
+ /* @__PURE__ */ jsx(
12520
+ Form$2.Field,
12521
+ {
12522
+ control: form.control,
12523
+ name: "city",
12524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
+ ] })
12529
+ }
12530
+ )
12531
+ ] }),
12532
+ /* @__PURE__ */ jsx(
12533
+ Form$2.Field,
12534
+ {
12535
+ control: form.control,
12536
+ name: "province",
12537
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
+ ] })
12542
+ }
12543
+ ),
12544
+ /* @__PURE__ */ jsx(
12545
+ Form$2.Field,
12546
+ {
12547
+ control: form.control,
12548
+ name: "phone",
12549
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
+ ] })
12554
+ }
12555
+ )
12556
+ ] }) }),
12557
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12558
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12559
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12560
+ ] }) })
12561
+ ]
12562
+ }
12563
+ ) });
12564
+ };
12565
+ const schema$1 = addressSchema;
12566
+ const TransferOwnership = () => {
12567
+ const { id } = useParams();
12568
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12569
+ fields: "id,customer_id,customer.*"
12570
+ });
12571
+ if (isError) {
12572
+ throw error;
12573
+ }
12574
+ const isReady = !isPending && !!draft_order;
12575
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12576
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12577
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12578
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12579
+ ] }),
12580
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12581
+ ] });
12582
+ };
12583
+ const TransferOwnershipForm = ({ order }) => {
12584
+ var _a, _b;
12585
+ const form = useForm({
12586
+ defaultValues: {
12587
+ customer_id: order.customer_id || ""
12588
+ },
12589
+ resolver: zodResolver(schema)
12590
+ });
12591
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
+ const { handleSuccess } = useRouteModal();
12593
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12594
+ const currentCustomer = order.customer ? {
12595
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12596
+ value: order.customer.id
12597
+ } : null;
12598
+ const onSubmit = form.handleSubmit(async (data) => {
12599
+ await mutateAsync(
12600
+ { customer_id: data.customer_id },
12601
+ {
12602
+ onSuccess: () => {
12603
+ toast.success("Customer updated");
12604
+ handleSuccess();
12605
+ },
12606
+ onError: (error) => {
12607
+ toast.error(error.message);
12608
+ }
12609
+ }
12610
+ );
12611
+ });
12612
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12613
+ KeyboundForm,
12614
+ {
12615
+ className: "flex flex-1 flex-col overflow-hidden",
12616
+ onSubmit,
12617
+ children: [
12618
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12619
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12620
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12621
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12622
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12623
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12624
+ ] }),
12625
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12626
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12627
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12628
+ ] })
12629
+ ] }),
12630
+ /* @__PURE__ */ jsx(
12631
+ CustomerField,
12632
+ {
12633
+ control: form.control,
12634
+ currentCustomerId: order.customer_id
12635
+ }
12636
+ )
12637
+ ] }),
12638
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12639
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12640
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12641
+ ] }) })
12642
+ ]
12643
+ }
12644
+ ) });
12645
+ };
12646
+ const CustomerField = ({ control, currentCustomerId }) => {
12647
+ const customers = useComboboxData({
12648
+ queryFn: async (params) => {
12649
+ return await sdk.admin.customer.list({
12650
+ ...params,
12651
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12652
+ });
12653
+ },
12654
+ queryKey: ["customers"],
12655
+ getOptions: (data) => {
12656
+ return data.customers.map((customer) => {
12657
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12658
+ return {
12659
+ label: name ? `${name} (${customer.email})` : customer.email,
12660
+ value: customer.id
12661
+ };
12662
+ });
12663
+ }
12664
+ });
12665
+ return /* @__PURE__ */ jsx(
12666
+ Form$2.Field,
12667
+ {
12397
12668
  name: "customer_id",
12398
12669
  control,
12399
12670
  render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
@@ -12765,279 +13036,8 @@ const Illustration = () => {
12765
13036
  }
12766
13037
  );
12767
13038
  };
12768
- const schema$2 = objectType({
12769
- customer_id: stringType().min(1)
12770
- });
12771
- const ShippingAddress = () => {
12772
- const { id } = useParams();
12773
- const { order, isPending, isError, error } = useOrder(id, {
12774
- fields: "+shipping_address"
12775
- });
12776
- if (isError) {
12777
- throw error;
12778
- }
12779
- const isReady = !isPending && !!order;
12780
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12781
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12782
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12783
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12784
- ] }),
12785
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12786
- ] });
12787
- };
12788
- const ShippingAddressForm = ({ order }) => {
12789
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12790
- const form = useForm({
12791
- defaultValues: {
12792
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12793
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12794
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12795
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12796
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12797
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12798
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12799
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12800
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12801
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12802
- },
12803
- resolver: zodResolver(schema$1)
12804
- });
12805
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12806
- const { handleSuccess } = useRouteModal();
12807
- const onSubmit = form.handleSubmit(async (data) => {
12808
- await mutateAsync(
12809
- {
12810
- shipping_address: {
12811
- first_name: data.first_name,
12812
- last_name: data.last_name,
12813
- company: data.company,
12814
- address_1: data.address_1,
12815
- address_2: data.address_2,
12816
- city: data.city,
12817
- province: data.province,
12818
- country_code: data.country_code,
12819
- postal_code: data.postal_code,
12820
- phone: data.phone
12821
- }
12822
- },
12823
- {
12824
- onSuccess: () => {
12825
- handleSuccess();
12826
- },
12827
- onError: (error) => {
12828
- toast.error(error.message);
12829
- }
12830
- }
12831
- );
12832
- });
12833
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12834
- KeyboundForm,
12835
- {
12836
- className: "flex flex-1 flex-col overflow-hidden",
12837
- onSubmit,
12838
- children: [
12839
- /* @__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: [
12840
- /* @__PURE__ */ jsx(
12841
- Form$2.Field,
12842
- {
12843
- control: form.control,
12844
- name: "country_code",
12845
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12846
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12847
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12848
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12849
- ] })
12850
- }
12851
- ),
12852
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12853
- /* @__PURE__ */ jsx(
12854
- Form$2.Field,
12855
- {
12856
- control: form.control,
12857
- name: "first_name",
12858
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12859
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12860
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12861
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12862
- ] })
12863
- }
12864
- ),
12865
- /* @__PURE__ */ jsx(
12866
- Form$2.Field,
12867
- {
12868
- control: form.control,
12869
- name: "last_name",
12870
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12871
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12872
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12873
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12874
- ] })
12875
- }
12876
- )
12877
- ] }),
12878
- /* @__PURE__ */ jsx(
12879
- Form$2.Field,
12880
- {
12881
- control: form.control,
12882
- name: "company",
12883
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12884
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12885
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12886
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12887
- ] })
12888
- }
12889
- ),
12890
- /* @__PURE__ */ jsx(
12891
- Form$2.Field,
12892
- {
12893
- control: form.control,
12894
- name: "address_1",
12895
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12896
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12897
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12898
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12899
- ] })
12900
- }
12901
- ),
12902
- /* @__PURE__ */ jsx(
12903
- Form$2.Field,
12904
- {
12905
- control: form.control,
12906
- name: "address_2",
12907
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12908
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12909
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12910
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12911
- ] })
12912
- }
12913
- ),
12914
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12915
- /* @__PURE__ */ jsx(
12916
- Form$2.Field,
12917
- {
12918
- control: form.control,
12919
- name: "postal_code",
12920
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12921
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12922
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12923
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12924
- ] })
12925
- }
12926
- ),
12927
- /* @__PURE__ */ jsx(
12928
- Form$2.Field,
12929
- {
12930
- control: form.control,
12931
- name: "city",
12932
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12933
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12934
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12935
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12936
- ] })
12937
- }
12938
- )
12939
- ] }),
12940
- /* @__PURE__ */ jsx(
12941
- Form$2.Field,
12942
- {
12943
- control: form.control,
12944
- name: "province",
12945
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12946
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12947
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12948
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12949
- ] })
12950
- }
12951
- ),
12952
- /* @__PURE__ */ jsx(
12953
- Form$2.Field,
12954
- {
12955
- control: form.control,
12956
- name: "phone",
12957
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12958
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12959
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12960
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12961
- ] })
12962
- }
12963
- )
12964
- ] }) }),
12965
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12966
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12967
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12968
- ] }) })
12969
- ]
12970
- }
12971
- ) });
12972
- };
12973
- const schema$1 = addressSchema;
12974
- const Email = () => {
12975
- const { id } = useParams();
12976
- const { order, isPending, isError, error } = useOrder(id, {
12977
- fields: "+email"
12978
- });
12979
- if (isError) {
12980
- throw error;
12981
- }
12982
- const isReady = !isPending && !!order;
12983
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12984
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12985
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12986
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12987
- ] }),
12988
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12989
- ] });
12990
- };
12991
- const EmailForm = ({ order }) => {
12992
- const form = useForm({
12993
- defaultValues: {
12994
- email: order.email ?? ""
12995
- },
12996
- resolver: zodResolver(schema)
12997
- });
12998
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12999
- const { handleSuccess } = useRouteModal();
13000
- const onSubmit = form.handleSubmit(async (data) => {
13001
- await mutateAsync(
13002
- { email: data.email },
13003
- {
13004
- onSuccess: () => {
13005
- handleSuccess();
13006
- },
13007
- onError: (error) => {
13008
- toast.error(error.message);
13009
- }
13010
- }
13011
- );
13012
- });
13013
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
13014
- KeyboundForm,
13015
- {
13016
- className: "flex flex-1 flex-col overflow-hidden",
13017
- onSubmit,
13018
- children: [
13019
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
13020
- Form$2.Field,
13021
- {
13022
- control: form.control,
13023
- name: "email",
13024
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13025
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
13026
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13027
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13028
- ] })
13029
- }
13030
- ) }),
13031
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13032
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13033
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13034
- ] }) })
13035
- ]
13036
- }
13037
- ) });
13038
- };
13039
13039
  const schema = objectType({
13040
- email: stringType().email()
13040
+ customer_id: stringType().min(1)
13041
13041
  });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
@@ -13063,6 +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
+ {
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13073
+ },
13066
13074
  {
13067
13075
  Component: Items,
13068
13076
  path: "/draft-orders/:id/items"
@@ -13075,10 +13083,6 @@ const routeModule = {
13075
13083
  Component: Promotions,
13076
13084
  path: "/draft-orders/:id/promotions"
13077
13085
  },
13078
- {
13079
- Component: CustomItems,
13080
- path: "/draft-orders/:id/custom-items"
13081
- },
13082
13086
  {
13083
13087
  Component: SalesChannel,
13084
13088
  path: "/draft-orders/:id/sales-channel"
@@ -13087,17 +13091,13 @@ const routeModule = {
13087
13091
  Component: Shipping,
13088
13092
  path: "/draft-orders/:id/shipping"
13089
13093
  },
13090
- {
13091
- Component: TransferOwnership,
13092
- path: "/draft-orders/:id/transfer-ownership"
13093
- },
13094
13094
  {
13095
13095
  Component: ShippingAddress,
13096
13096
  path: "/draft-orders/:id/shipping-address"
13097
13097
  },
13098
13098
  {
13099
- Component: Email,
13100
- path: "/draft-orders/:id/email"
13099
+ Component: TransferOwnership,
13100
+ path: "/draft-orders/:id/transfer-ownership"
13101
13101
  }
13102
13102
  ]
13103
13103
  }