@medusajs/draft-order 2.10.0-preview-20250828031543 → 2.10.0-preview-20250828090201

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.
@@ -9765,74 +9765,6 @@ const CustomItemsForm = () => {
9765
9765
  const schema$4 = objectType({
9766
9766
  email: stringType().email()
9767
9767
  });
9768
- const Email = () => {
9769
- const { id } = useParams();
9770
- const { order, isPending, isError, error } = useOrder(id, {
9771
- fields: "+email"
9772
- });
9773
- if (isError) {
9774
- throw error;
9775
- }
9776
- const isReady = !isPending && !!order;
9777
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9778
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9779
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9780
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9781
- ] }),
9782
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9783
- ] });
9784
- };
9785
- const EmailForm = ({ order }) => {
9786
- const form = useForm({
9787
- defaultValues: {
9788
- email: order.email ?? ""
9789
- },
9790
- resolver: zodResolver(schema$3)
9791
- });
9792
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9793
- const { handleSuccess } = useRouteModal();
9794
- const onSubmit = form.handleSubmit(async (data) => {
9795
- await mutateAsync(
9796
- { email: data.email },
9797
- {
9798
- onSuccess: () => {
9799
- handleSuccess();
9800
- },
9801
- onError: (error) => {
9802
- toast.error(error.message);
9803
- }
9804
- }
9805
- );
9806
- });
9807
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9808
- KeyboundForm,
9809
- {
9810
- className: "flex flex-1 flex-col overflow-hidden",
9811
- onSubmit,
9812
- children: [
9813
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9814
- Form$2.Field,
9815
- {
9816
- control: form.control,
9817
- name: "email",
9818
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9819
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9820
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9821
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9822
- ] })
9823
- }
9824
- ) }),
9825
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9826
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9827
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9828
- ] }) })
9829
- ]
9830
- }
9831
- ) });
9832
- };
9833
- const schema$3 = objectType({
9834
- email: stringType().email()
9835
- });
9836
9768
  const NumberInput = forwardRef(
9837
9769
  ({
9838
9770
  value,
@@ -10807,6 +10739,74 @@ const customItemSchema = objectType({
10807
10739
  quantity: numberType(),
10808
10740
  unit_price: unionType([numberType(), stringType()])
10809
10741
  });
10742
+ const Email = () => {
10743
+ const { id } = useParams();
10744
+ const { order, isPending, isError, error } = useOrder(id, {
10745
+ fields: "+email"
10746
+ });
10747
+ if (isError) {
10748
+ throw error;
10749
+ }
10750
+ const isReady = !isPending && !!order;
10751
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10752
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10753
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
10754
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10755
+ ] }),
10756
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10757
+ ] });
10758
+ };
10759
+ const EmailForm = ({ order }) => {
10760
+ const form = useForm({
10761
+ defaultValues: {
10762
+ email: order.email ?? ""
10763
+ },
10764
+ resolver: zodResolver(schema$3)
10765
+ });
10766
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10767
+ const { handleSuccess } = useRouteModal();
10768
+ const onSubmit = form.handleSubmit(async (data) => {
10769
+ await mutateAsync(
10770
+ { email: data.email },
10771
+ {
10772
+ onSuccess: () => {
10773
+ handleSuccess();
10774
+ },
10775
+ onError: (error) => {
10776
+ toast.error(error.message);
10777
+ }
10778
+ }
10779
+ );
10780
+ });
10781
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10782
+ KeyboundForm,
10783
+ {
10784
+ className: "flex flex-1 flex-col overflow-hidden",
10785
+ onSubmit,
10786
+ children: [
10787
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
10788
+ Form$2.Field,
10789
+ {
10790
+ control: form.control,
10791
+ name: "email",
10792
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10793
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
10794
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10795
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10796
+ ] })
10797
+ }
10798
+ ) }),
10799
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10800
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10801
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10802
+ ] }) })
10803
+ ]
10804
+ }
10805
+ ) });
10806
+ };
10807
+ const schema$3 = objectType({
10808
+ email: stringType().email()
10809
+ });
10810
10810
  const InlineTip = forwardRef(
10811
10811
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10812
10812
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -12347,44 +12347,60 @@ const CustomAmountField = ({
12347
12347
  }
12348
12348
  );
12349
12349
  };
12350
- const TransferOwnership = () => {
12350
+ const ShippingAddress = () => {
12351
12351
  const { id } = useParams();
12352
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12353
- fields: "id,customer_id,customer.*"
12352
+ const { order, isPending, isError, error } = useOrder(id, {
12353
+ fields: "+shipping_address"
12354
12354
  });
12355
12355
  if (isError) {
12356
12356
  throw error;
12357
12357
  }
12358
- const isReady = !isPending && !!draft_order;
12358
+ const isReady = !isPending && !!order;
12359
12359
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12360
12360
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12361
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12362
- /* @__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" }) })
12361
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12362
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12363
12363
  ] }),
12364
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12364
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12365
12365
  ] });
12366
12366
  };
12367
- const TransferOwnershipForm = ({ order }) => {
12368
- var _a, _b;
12367
+ const ShippingAddressForm = ({ order }) => {
12368
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12369
12369
  const form = useForm({
12370
12370
  defaultValues: {
12371
- customer_id: order.customer_id || ""
12371
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12372
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12373
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12374
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12375
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12376
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12377
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12378
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12379
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12380
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12372
12381
  },
12373
12382
  resolver: zodResolver(schema$1)
12374
12383
  });
12375
12384
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12376
12385
  const { handleSuccess } = useRouteModal();
12377
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12378
- const currentCustomer = order.customer ? {
12379
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12380
- value: order.customer.id
12381
- } : null;
12382
12386
  const onSubmit = form.handleSubmit(async (data) => {
12383
12387
  await mutateAsync(
12384
- { customer_id: data.customer_id },
12388
+ {
12389
+ shipping_address: {
12390
+ first_name: data.first_name,
12391
+ last_name: data.last_name,
12392
+ company: data.company,
12393
+ address_1: data.address_1,
12394
+ address_2: data.address_2,
12395
+ city: data.city,
12396
+ province: data.province,
12397
+ country_code: data.country_code,
12398
+ postal_code: data.postal_code,
12399
+ phone: data.phone
12400
+ }
12401
+ },
12385
12402
  {
12386
12403
  onSuccess: () => {
12387
- toast.success("Customer updated");
12388
12404
  handleSuccess();
12389
12405
  },
12390
12406
  onError: (error) => {
@@ -12399,36 +12415,223 @@ const TransferOwnershipForm = ({ order }) => {
12399
12415
  className: "flex flex-1 flex-col overflow-hidden",
12400
12416
  onSubmit,
12401
12417
  children: [
12402
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12403
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12404
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12405
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12406
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12407
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12408
- ] }),
12409
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12410
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12411
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12412
- ] })
12418
+ /* @__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: [
12419
+ /* @__PURE__ */ jsx(
12420
+ Form$2.Field,
12421
+ {
12422
+ control: form.control,
12423
+ name: "country_code",
12424
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12425
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12426
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12427
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12428
+ ] })
12429
+ }
12430
+ ),
12431
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12432
+ /* @__PURE__ */ jsx(
12433
+ Form$2.Field,
12434
+ {
12435
+ control: form.control,
12436
+ name: "first_name",
12437
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12439
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12440
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
+ ] })
12442
+ }
12443
+ ),
12444
+ /* @__PURE__ */ jsx(
12445
+ Form$2.Field,
12446
+ {
12447
+ control: form.control,
12448
+ name: "last_name",
12449
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12450
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12451
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12452
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12453
+ ] })
12454
+ }
12455
+ )
12413
12456
  ] }),
12414
12457
  /* @__PURE__ */ jsx(
12415
- CustomerField,
12458
+ Form$2.Field,
12416
12459
  {
12417
12460
  control: form.control,
12418
- currentCustomerId: order.customer_id
12461
+ name: "company",
12462
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12464
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
+ ] })
12419
12467
  }
12420
- )
12421
- ] }),
12422
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12423
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12424
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12425
- ] }) })
12426
- ]
12427
- }
12428
- ) });
12429
- };
12430
- const CustomerField = ({ control, currentCustomerId }) => {
12431
- const customers = useComboboxData({
12468
+ ),
12469
+ /* @__PURE__ */ jsx(
12470
+ Form$2.Field,
12471
+ {
12472
+ control: form.control,
12473
+ name: "address_1",
12474
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12475
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12476
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12477
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12478
+ ] })
12479
+ }
12480
+ ),
12481
+ /* @__PURE__ */ jsx(
12482
+ Form$2.Field,
12483
+ {
12484
+ control: form.control,
12485
+ name: "address_2",
12486
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12487
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12488
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12489
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12490
+ ] })
12491
+ }
12492
+ ),
12493
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12494
+ /* @__PURE__ */ jsx(
12495
+ Form$2.Field,
12496
+ {
12497
+ control: form.control,
12498
+ name: "postal_code",
12499
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12501
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
+ ] })
12504
+ }
12505
+ ),
12506
+ /* @__PURE__ */ jsx(
12507
+ Form$2.Field,
12508
+ {
12509
+ control: form.control,
12510
+ name: "city",
12511
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12512
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12513
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12514
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12515
+ ] })
12516
+ }
12517
+ )
12518
+ ] }),
12519
+ /* @__PURE__ */ jsx(
12520
+ Form$2.Field,
12521
+ {
12522
+ control: form.control,
12523
+ name: "province",
12524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
+ ] })
12529
+ }
12530
+ ),
12531
+ /* @__PURE__ */ jsx(
12532
+ Form$2.Field,
12533
+ {
12534
+ control: form.control,
12535
+ name: "phone",
12536
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12537
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12538
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12539
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12540
+ ] })
12541
+ }
12542
+ )
12543
+ ] }) }),
12544
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12545
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12546
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12547
+ ] }) })
12548
+ ]
12549
+ }
12550
+ ) });
12551
+ };
12552
+ const schema$1 = addressSchema;
12553
+ const TransferOwnership = () => {
12554
+ const { id } = useParams();
12555
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12556
+ fields: "id,customer_id,customer.*"
12557
+ });
12558
+ if (isError) {
12559
+ throw error;
12560
+ }
12561
+ const isReady = !isPending && !!draft_order;
12562
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12563
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12564
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12565
+ /* @__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" }) })
12566
+ ] }),
12567
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12568
+ ] });
12569
+ };
12570
+ const TransferOwnershipForm = ({ order }) => {
12571
+ var _a, _b;
12572
+ const form = useForm({
12573
+ defaultValues: {
12574
+ customer_id: order.customer_id || ""
12575
+ },
12576
+ resolver: zodResolver(schema)
12577
+ });
12578
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12579
+ const { handleSuccess } = useRouteModal();
12580
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12581
+ const currentCustomer = order.customer ? {
12582
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12583
+ value: order.customer.id
12584
+ } : null;
12585
+ const onSubmit = form.handleSubmit(async (data) => {
12586
+ await mutateAsync(
12587
+ { customer_id: data.customer_id },
12588
+ {
12589
+ onSuccess: () => {
12590
+ toast.success("Customer updated");
12591
+ handleSuccess();
12592
+ },
12593
+ onError: (error) => {
12594
+ toast.error(error.message);
12595
+ }
12596
+ }
12597
+ );
12598
+ });
12599
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12600
+ KeyboundForm,
12601
+ {
12602
+ className: "flex flex-1 flex-col overflow-hidden",
12603
+ onSubmit,
12604
+ children: [
12605
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12606
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12607
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12608
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12609
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12610
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12611
+ ] }),
12612
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12613
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12614
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12615
+ ] })
12616
+ ] }),
12617
+ /* @__PURE__ */ jsx(
12618
+ CustomerField,
12619
+ {
12620
+ control: form.control,
12621
+ currentCustomerId: order.customer_id
12622
+ }
12623
+ )
12624
+ ] }),
12625
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12626
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12627
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12628
+ ] }) })
12629
+ ]
12630
+ }
12631
+ ) });
12632
+ };
12633
+ const CustomerField = ({ control, currentCustomerId }) => {
12634
+ const customers = useComboboxData({
12432
12635
  queryFn: async (params) => {
12433
12636
  return await sdk.admin.customer.list({
12434
12637
  ...params,
@@ -12820,212 +13023,9 @@ const Illustration = () => {
12820
13023
  }
12821
13024
  );
12822
13025
  };
12823
- const schema$1 = objectType({
13026
+ const schema = objectType({
12824
13027
  customer_id: stringType().min(1)
12825
13028
  });
12826
- const ShippingAddress = () => {
12827
- const { id } = useParams();
12828
- const { order, isPending, isError, error } = useOrder(id, {
12829
- fields: "+shipping_address"
12830
- });
12831
- if (isError) {
12832
- throw error;
12833
- }
12834
- const isReady = !isPending && !!order;
12835
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12836
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12837
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12838
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12839
- ] }),
12840
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12841
- ] });
12842
- };
12843
- const ShippingAddressForm = ({ order }) => {
12844
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12845
- const form = useForm({
12846
- defaultValues: {
12847
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12848
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12849
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12850
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12851
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12852
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12853
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12854
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12855
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12856
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12857
- },
12858
- resolver: zodResolver(schema)
12859
- });
12860
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12861
- const { handleSuccess } = useRouteModal();
12862
- const onSubmit = form.handleSubmit(async (data) => {
12863
- await mutateAsync(
12864
- {
12865
- shipping_address: {
12866
- first_name: data.first_name,
12867
- last_name: data.last_name,
12868
- company: data.company,
12869
- address_1: data.address_1,
12870
- address_2: data.address_2,
12871
- city: data.city,
12872
- province: data.province,
12873
- country_code: data.country_code,
12874
- postal_code: data.postal_code,
12875
- phone: data.phone
12876
- }
12877
- },
12878
- {
12879
- onSuccess: () => {
12880
- handleSuccess();
12881
- },
12882
- onError: (error) => {
12883
- toast.error(error.message);
12884
- }
12885
- }
12886
- );
12887
- });
12888
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12889
- KeyboundForm,
12890
- {
12891
- className: "flex flex-1 flex-col overflow-hidden",
12892
- onSubmit,
12893
- children: [
12894
- /* @__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: [
12895
- /* @__PURE__ */ jsx(
12896
- Form$2.Field,
12897
- {
12898
- control: form.control,
12899
- name: "country_code",
12900
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12901
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12902
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12903
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12904
- ] })
12905
- }
12906
- ),
12907
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12908
- /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12910
- {
12911
- control: form.control,
12912
- name: "first_name",
12913
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12915
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12916
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
- ] })
12918
- }
12919
- ),
12920
- /* @__PURE__ */ jsx(
12921
- Form$2.Field,
12922
- {
12923
- control: form.control,
12924
- name: "last_name",
12925
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12926
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12927
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12928
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12929
- ] })
12930
- }
12931
- )
12932
- ] }),
12933
- /* @__PURE__ */ jsx(
12934
- Form$2.Field,
12935
- {
12936
- control: form.control,
12937
- name: "company",
12938
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
- ] })
12943
- }
12944
- ),
12945
- /* @__PURE__ */ jsx(
12946
- Form$2.Field,
12947
- {
12948
- control: form.control,
12949
- name: "address_1",
12950
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12951
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12952
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12953
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12954
- ] })
12955
- }
12956
- ),
12957
- /* @__PURE__ */ jsx(
12958
- Form$2.Field,
12959
- {
12960
- control: form.control,
12961
- name: "address_2",
12962
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12963
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12964
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12965
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12966
- ] })
12967
- }
12968
- ),
12969
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
12972
- {
12973
- control: form.control,
12974
- name: "postal_code",
12975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
- ] })
12980
- }
12981
- ),
12982
- /* @__PURE__ */ jsx(
12983
- Form$2.Field,
12984
- {
12985
- control: form.control,
12986
- name: "city",
12987
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12988
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12989
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12990
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12991
- ] })
12992
- }
12993
- )
12994
- ] }),
12995
- /* @__PURE__ */ jsx(
12996
- Form$2.Field,
12997
- {
12998
- control: form.control,
12999
- name: "province",
13000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
- ] })
13005
- }
13006
- ),
13007
- /* @__PURE__ */ jsx(
13008
- Form$2.Field,
13009
- {
13010
- control: form.control,
13011
- name: "phone",
13012
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13013
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13014
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13015
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13016
- ] })
13017
- }
13018
- )
13019
- ] }) }),
13020
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13021
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13022
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13023
- ] }) })
13024
- ]
13025
- }
13026
- ) });
13027
- };
13028
- const schema = addressSchema;
13029
13029
  const widgetModule = { widgets: [] };
13030
13030
  const routeModule = {
13031
13031
  routes: [
@@ -13054,14 +13054,14 @@ const routeModule = {
13054
13054
  Component: CustomItems,
13055
13055
  path: "/draft-orders/:id/custom-items"
13056
13056
  },
13057
- {
13058
- Component: Email,
13059
- path: "/draft-orders/:id/email"
13060
- },
13061
13057
  {
13062
13058
  Component: Items,
13063
13059
  path: "/draft-orders/:id/items"
13064
13060
  },
13061
+ {
13062
+ Component: Email,
13063
+ path: "/draft-orders/:id/email"
13064
+ },
13065
13065
  {
13066
13066
  Component: Metadata,
13067
13067
  path: "/draft-orders/:id/metadata"
@@ -13078,13 +13078,13 @@ const routeModule = {
13078
13078
  Component: Shipping,
13079
13079
  path: "/draft-orders/:id/shipping"
13080
13080
  },
13081
- {
13082
- Component: TransferOwnership,
13083
- path: "/draft-orders/:id/transfer-ownership"
13084
- },
13085
13081
  {
13086
13082
  Component: ShippingAddress,
13087
13083
  path: "/draft-orders/:id/shipping-address"
13084
+ },
13085
+ {
13086
+ Component: TransferOwnership,
13087
+ path: "/draft-orders/:id/transfer-ownership"
13088
13088
  }
13089
13089
  ]
13090
13090
  }