@medusajs/draft-order 2.11.4-preview-20251108180137 → 2.11.4-preview-20251108210131

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.
@@ -9772,6 +9772,74 @@ const CustomItemsForm = () => {
9772
9772
  const schema$4 = objectType({
9773
9773
  email: stringType().email()
9774
9774
  });
9775
+ const Email = () => {
9776
+ const { id } = useParams();
9777
+ const { order, isPending, isError, error } = useOrder(id, {
9778
+ fields: "+email"
9779
+ });
9780
+ if (isError) {
9781
+ throw error;
9782
+ }
9783
+ const isReady = !isPending && !!order;
9784
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9785
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9786
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9787
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9788
+ ] }),
9789
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9790
+ ] });
9791
+ };
9792
+ const EmailForm = ({ order }) => {
9793
+ const form = useForm({
9794
+ defaultValues: {
9795
+ email: order.email ?? ""
9796
+ },
9797
+ resolver: zodResolver(schema$3)
9798
+ });
9799
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9800
+ const { handleSuccess } = useRouteModal();
9801
+ const onSubmit = form.handleSubmit(async (data) => {
9802
+ await mutateAsync(
9803
+ { email: data.email },
9804
+ {
9805
+ onSuccess: () => {
9806
+ handleSuccess();
9807
+ },
9808
+ onError: (error) => {
9809
+ toast.error(error.message);
9810
+ }
9811
+ }
9812
+ );
9813
+ });
9814
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9815
+ KeyboundForm,
9816
+ {
9817
+ className: "flex flex-1 flex-col overflow-hidden",
9818
+ onSubmit,
9819
+ children: [
9820
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9821
+ Form$2.Field,
9822
+ {
9823
+ control: form.control,
9824
+ name: "email",
9825
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9826
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9827
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9828
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9829
+ ] })
9830
+ }
9831
+ ) }),
9832
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9833
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9834
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9835
+ ] }) })
9836
+ ]
9837
+ }
9838
+ ) });
9839
+ };
9840
+ const schema$3 = objectType({
9841
+ email: stringType().email()
9842
+ });
9775
9843
  const NumberInput = forwardRef(
9776
9844
  ({
9777
9845
  value,
@@ -11096,74 +11164,6 @@ function getHasUneditableRows(metadata) {
11096
11164
  (value) => !EDITABLE_TYPES.includes(typeof value)
11097
11165
  );
11098
11166
  }
11099
- const Email = () => {
11100
- const { id } = useParams();
11101
- const { order, isPending, isError, error } = useOrder(id, {
11102
- fields: "+email"
11103
- });
11104
- if (isError) {
11105
- throw error;
11106
- }
11107
- const isReady = !isPending && !!order;
11108
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11109
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11110
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
11111
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
11112
- ] }),
11113
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
11114
- ] });
11115
- };
11116
- const EmailForm = ({ order }) => {
11117
- const form = useForm({
11118
- defaultValues: {
11119
- email: order.email ?? ""
11120
- },
11121
- resolver: zodResolver(schema$3)
11122
- });
11123
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11124
- const { handleSuccess } = useRouteModal();
11125
- const onSubmit = form.handleSubmit(async (data) => {
11126
- await mutateAsync(
11127
- { email: data.email },
11128
- {
11129
- onSuccess: () => {
11130
- handleSuccess();
11131
- },
11132
- onError: (error) => {
11133
- toast.error(error.message);
11134
- }
11135
- }
11136
- );
11137
- });
11138
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11139
- KeyboundForm,
11140
- {
11141
- className: "flex flex-1 flex-col overflow-hidden",
11142
- onSubmit,
11143
- children: [
11144
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
11145
- Form$2.Field,
11146
- {
11147
- control: form.control,
11148
- name: "email",
11149
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11150
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
11151
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11152
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11153
- ] })
11154
- }
11155
- ) }),
11156
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11157
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11158
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11159
- ] }) })
11160
- ]
11161
- }
11162
- ) });
11163
- };
11164
- const schema$3 = objectType({
11165
- email: stringType().email()
11166
- });
11167
11167
  const PROMOTION_QUERY_KEY = "promotions";
11168
11168
  const promotionsQueryKeys = {
11169
11169
  list: (query2) => [
@@ -12354,44 +12354,60 @@ const CustomAmountField = ({
12354
12354
  }
12355
12355
  );
12356
12356
  };
12357
- const TransferOwnership = () => {
12357
+ const ShippingAddress = () => {
12358
12358
  const { id } = useParams();
12359
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12360
- fields: "id,customer_id,customer.*"
12359
+ const { order, isPending, isError, error } = useOrder(id, {
12360
+ fields: "+shipping_address"
12361
12361
  });
12362
12362
  if (isError) {
12363
12363
  throw error;
12364
12364
  }
12365
- const isReady = !isPending && !!draft_order;
12365
+ const isReady = !isPending && !!order;
12366
12366
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12367
12367
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12368
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12369
- /* @__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" }) })
12368
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12369
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12370
12370
  ] }),
12371
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12371
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12372
12372
  ] });
12373
12373
  };
12374
- const TransferOwnershipForm = ({ order }) => {
12375
- var _a, _b;
12374
+ const ShippingAddressForm = ({ order }) => {
12375
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12376
12376
  const form = useForm({
12377
12377
  defaultValues: {
12378
- customer_id: order.customer_id || ""
12378
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12379
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12380
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12381
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12382
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12383
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12384
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12385
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12386
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12387
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12379
12388
  },
12380
12389
  resolver: zodResolver(schema$1)
12381
12390
  });
12382
12391
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12383
12392
  const { handleSuccess } = useRouteModal();
12384
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12385
- const currentCustomer = order.customer ? {
12386
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12387
- value: order.customer.id
12388
- } : null;
12389
12393
  const onSubmit = form.handleSubmit(async (data) => {
12390
12394
  await mutateAsync(
12391
- { customer_id: data.customer_id },
12395
+ {
12396
+ shipping_address: {
12397
+ first_name: data.first_name,
12398
+ last_name: data.last_name,
12399
+ company: data.company,
12400
+ address_1: data.address_1,
12401
+ address_2: data.address_2,
12402
+ city: data.city,
12403
+ province: data.province,
12404
+ country_code: data.country_code,
12405
+ postal_code: data.postal_code,
12406
+ phone: data.phone
12407
+ }
12408
+ },
12392
12409
  {
12393
12410
  onSuccess: () => {
12394
- toast.success("Customer updated");
12395
12411
  handleSuccess();
12396
12412
  },
12397
12413
  onError: (error) => {
@@ -12406,36 +12422,223 @@ const TransferOwnershipForm = ({ order }) => {
12406
12422
  className: "flex flex-1 flex-col overflow-hidden",
12407
12423
  onSubmit,
12408
12424
  children: [
12409
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12410
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12411
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12412
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12413
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12414
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12415
- ] }),
12416
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12417
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12418
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12419
- ] })
12425
+ /* @__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: [
12426
+ /* @__PURE__ */ jsx(
12427
+ Form$2.Field,
12428
+ {
12429
+ control: form.control,
12430
+ name: "country_code",
12431
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12432
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12433
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12434
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12435
+ ] })
12436
+ }
12437
+ ),
12438
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12439
+ /* @__PURE__ */ jsx(
12440
+ Form$2.Field,
12441
+ {
12442
+ control: form.control,
12443
+ name: "first_name",
12444
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12445
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12446
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12447
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12448
+ ] })
12449
+ }
12450
+ ),
12451
+ /* @__PURE__ */ jsx(
12452
+ Form$2.Field,
12453
+ {
12454
+ control: form.control,
12455
+ name: "last_name",
12456
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12457
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12458
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12459
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12460
+ ] })
12461
+ }
12462
+ )
12420
12463
  ] }),
12421
12464
  /* @__PURE__ */ jsx(
12422
- CustomerField,
12465
+ Form$2.Field,
12423
12466
  {
12424
12467
  control: form.control,
12425
- currentCustomerId: order.customer_id
12468
+ name: "company",
12469
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12470
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12471
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12472
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12473
+ ] })
12426
12474
  }
12427
- )
12428
- ] }),
12429
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12430
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12431
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12432
- ] }) })
12433
- ]
12434
- }
12435
- ) });
12436
- };
12437
- const CustomerField = ({ control, currentCustomerId }) => {
12438
- const customers = useComboboxData({
12475
+ ),
12476
+ /* @__PURE__ */ jsx(
12477
+ Form$2.Field,
12478
+ {
12479
+ control: form.control,
12480
+ name: "address_1",
12481
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12482
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12483
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12484
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12485
+ ] })
12486
+ }
12487
+ ),
12488
+ /* @__PURE__ */ jsx(
12489
+ Form$2.Field,
12490
+ {
12491
+ control: form.control,
12492
+ name: "address_2",
12493
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12494
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12495
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12496
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12497
+ ] })
12498
+ }
12499
+ ),
12500
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12501
+ /* @__PURE__ */ jsx(
12502
+ Form$2.Field,
12503
+ {
12504
+ control: form.control,
12505
+ name: "postal_code",
12506
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12507
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12508
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12509
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12510
+ ] })
12511
+ }
12512
+ ),
12513
+ /* @__PURE__ */ jsx(
12514
+ Form$2.Field,
12515
+ {
12516
+ control: form.control,
12517
+ name: "city",
12518
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12519
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12520
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12521
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12522
+ ] })
12523
+ }
12524
+ )
12525
+ ] }),
12526
+ /* @__PURE__ */ jsx(
12527
+ Form$2.Field,
12528
+ {
12529
+ control: form.control,
12530
+ name: "province",
12531
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12532
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12533
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12534
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12535
+ ] })
12536
+ }
12537
+ ),
12538
+ /* @__PURE__ */ jsx(
12539
+ Form$2.Field,
12540
+ {
12541
+ control: form.control,
12542
+ name: "phone",
12543
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12544
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12545
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12546
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12547
+ ] })
12548
+ }
12549
+ )
12550
+ ] }) }),
12551
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12552
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12553
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12554
+ ] }) })
12555
+ ]
12556
+ }
12557
+ ) });
12558
+ };
12559
+ const schema$1 = addressSchema;
12560
+ const TransferOwnership = () => {
12561
+ const { id } = useParams();
12562
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12563
+ fields: "id,customer_id,customer.*"
12564
+ });
12565
+ if (isError) {
12566
+ throw error;
12567
+ }
12568
+ const isReady = !isPending && !!draft_order;
12569
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12570
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12571
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12572
+ /* @__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" }) })
12573
+ ] }),
12574
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12575
+ ] });
12576
+ };
12577
+ const TransferOwnershipForm = ({ order }) => {
12578
+ var _a, _b;
12579
+ const form = useForm({
12580
+ defaultValues: {
12581
+ customer_id: order.customer_id || ""
12582
+ },
12583
+ resolver: zodResolver(schema)
12584
+ });
12585
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12586
+ const { handleSuccess } = useRouteModal();
12587
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12588
+ const currentCustomer = order.customer ? {
12589
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12590
+ value: order.customer.id
12591
+ } : null;
12592
+ const onSubmit = form.handleSubmit(async (data) => {
12593
+ await mutateAsync(
12594
+ { customer_id: data.customer_id },
12595
+ {
12596
+ onSuccess: () => {
12597
+ toast.success("Customer updated");
12598
+ handleSuccess();
12599
+ },
12600
+ onError: (error) => {
12601
+ toast.error(error.message);
12602
+ }
12603
+ }
12604
+ );
12605
+ });
12606
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12607
+ KeyboundForm,
12608
+ {
12609
+ className: "flex flex-1 flex-col overflow-hidden",
12610
+ onSubmit,
12611
+ children: [
12612
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12613
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12614
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12615
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12616
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12617
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12618
+ ] }),
12619
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12620
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12621
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12622
+ ] })
12623
+ ] }),
12624
+ /* @__PURE__ */ jsx(
12625
+ CustomerField,
12626
+ {
12627
+ control: form.control,
12628
+ currentCustomerId: order.customer_id
12629
+ }
12630
+ )
12631
+ ] }),
12632
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12633
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12634
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12635
+ ] }) })
12636
+ ]
12637
+ }
12638
+ ) });
12639
+ };
12640
+ const CustomerField = ({ control, currentCustomerId }) => {
12641
+ const customers = useComboboxData({
12439
12642
  queryFn: async (params) => {
12440
12643
  return await sdk.admin.customer.list({
12441
12644
  ...params,
@@ -12827,212 +13030,9 @@ const Illustration = () => {
12827
13030
  }
12828
13031
  );
12829
13032
  };
12830
- const schema$1 = objectType({
13033
+ const schema = objectType({
12831
13034
  customer_id: stringType().min(1)
12832
13035
  });
12833
- const ShippingAddress = () => {
12834
- const { id } = useParams();
12835
- const { order, isPending, isError, error } = useOrder(id, {
12836
- fields: "+shipping_address"
12837
- });
12838
- if (isError) {
12839
- throw error;
12840
- }
12841
- const isReady = !isPending && !!order;
12842
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12843
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12844
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12845
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12846
- ] }),
12847
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12848
- ] });
12849
- };
12850
- const ShippingAddressForm = ({ order }) => {
12851
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12852
- const form = useForm({
12853
- defaultValues: {
12854
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12855
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12856
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12857
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12858
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12859
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12860
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12861
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12862
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12863
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12864
- },
12865
- resolver: zodResolver(schema)
12866
- });
12867
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12868
- const { handleSuccess } = useRouteModal();
12869
- const onSubmit = form.handleSubmit(async (data) => {
12870
- await mutateAsync(
12871
- {
12872
- shipping_address: {
12873
- first_name: data.first_name,
12874
- last_name: data.last_name,
12875
- company: data.company,
12876
- address_1: data.address_1,
12877
- address_2: data.address_2,
12878
- city: data.city,
12879
- province: data.province,
12880
- country_code: data.country_code,
12881
- postal_code: data.postal_code,
12882
- phone: data.phone
12883
- }
12884
- },
12885
- {
12886
- onSuccess: () => {
12887
- handleSuccess();
12888
- },
12889
- onError: (error) => {
12890
- toast.error(error.message);
12891
- }
12892
- }
12893
- );
12894
- });
12895
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12896
- KeyboundForm,
12897
- {
12898
- className: "flex flex-1 flex-col overflow-hidden",
12899
- onSubmit,
12900
- children: [
12901
- /* @__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: [
12902
- /* @__PURE__ */ jsx(
12903
- Form$2.Field,
12904
- {
12905
- control: form.control,
12906
- name: "country_code",
12907
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12908
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12909
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...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: "first_name",
12920
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12921
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
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: "last_name",
12932
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12933
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
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: "company",
12945
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12946
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
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: "address_1",
12957
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12958
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12959
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12960
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12961
- ] })
12962
- }
12963
- ),
12964
- /* @__PURE__ */ jsx(
12965
- Form$2.Field,
12966
- {
12967
- control: form.control,
12968
- name: "address_2",
12969
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12970
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12971
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12972
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12973
- ] })
12974
- }
12975
- ),
12976
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12977
- /* @__PURE__ */ jsx(
12978
- Form$2.Field,
12979
- {
12980
- control: form.control,
12981
- name: "postal_code",
12982
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12983
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12984
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12985
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12986
- ] })
12987
- }
12988
- ),
12989
- /* @__PURE__ */ jsx(
12990
- Form$2.Field,
12991
- {
12992
- control: form.control,
12993
- name: "city",
12994
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12995
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12996
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12997
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12998
- ] })
12999
- }
13000
- )
13001
- ] }),
13002
- /* @__PURE__ */ jsx(
13003
- Form$2.Field,
13004
- {
13005
- control: form.control,
13006
- name: "province",
13007
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13008
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13009
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13010
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13011
- ] })
13012
- }
13013
- ),
13014
- /* @__PURE__ */ jsx(
13015
- Form$2.Field,
13016
- {
13017
- control: form.control,
13018
- name: "phone",
13019
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13020
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13021
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13022
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13023
- ] })
13024
- }
13025
- )
13026
- ] }) }),
13027
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13028
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13029
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13030
- ] }) })
13031
- ]
13032
- }
13033
- ) });
13034
- };
13035
- const schema = addressSchema;
13036
13036
  const widgetModule = { widgets: [] };
13037
13037
  const routeModule = {
13038
13038
  routes: [
@@ -13061,6 +13061,10 @@ const routeModule = {
13061
13061
  Component: CustomItems,
13062
13062
  path: "/draft-orders/:id/custom-items"
13063
13063
  },
13064
+ {
13065
+ Component: Email,
13066
+ path: "/draft-orders/:id/email"
13067
+ },
13064
13068
  {
13065
13069
  Component: Items,
13066
13070
  path: "/draft-orders/:id/items"
@@ -13069,10 +13073,6 @@ const routeModule = {
13069
13073
  Component: Metadata,
13070
13074
  path: "/draft-orders/:id/metadata"
13071
13075
  },
13072
- {
13073
- Component: Email,
13074
- path: "/draft-orders/:id/email"
13075
- },
13076
13076
  {
13077
13077
  Component: Promotions,
13078
13078
  path: "/draft-orders/:id/promotions"
@@ -13085,13 +13085,13 @@ const routeModule = {
13085
13085
  Component: Shipping,
13086
13086
  path: "/draft-orders/:id/shipping"
13087
13087
  },
13088
- {
13089
- Component: TransferOwnership,
13090
- path: "/draft-orders/:id/transfer-ownership"
13091
- },
13092
13088
  {
13093
13089
  Component: ShippingAddress,
13094
13090
  path: "/draft-orders/:id/shipping-address"
13091
+ },
13092
+ {
13093
+ Component: TransferOwnership,
13094
+ path: "/draft-orders/:id/transfer-ownership"
13095
13095
  }
13096
13096
  ]
13097
13097
  }