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