@medusajs/draft-order 2.11.4-preview-20251121120142 → 2.11.4-preview-20251121150135

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.
@@ -9755,27 +9755,6 @@ const BillingAddressForm = ({ order }) => {
9755
9755
  ) });
9756
9756
  };
9757
9757
  const schema$5 = addressSchema;
9758
- const CustomItems = () => {
9759
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9760
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9761
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9762
- ] });
9763
- };
9764
- const CustomItemsForm = () => {
9765
- const form = useForm({
9766
- resolver: zodResolver(schema$4)
9767
- });
9768
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9769
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9770
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9772
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9773
- ] }) })
9774
- ] }) });
9775
- };
9776
- const schema$4 = objectType({
9777
- email: stringType().email()
9778
- });
9779
9758
  const NumberInput = forwardRef(
9780
9759
  ({
9781
9760
  value,
@@ -10750,6 +10729,95 @@ const customItemSchema = objectType({
10750
10729
  quantity: numberType(),
10751
10730
  unit_price: unionType([numberType(), stringType()])
10752
10731
  });
10732
+ const Email = () => {
10733
+ const { id } = useParams();
10734
+ const { order, isPending, isError, error } = useOrder(id, {
10735
+ fields: "+email"
10736
+ });
10737
+ if (isError) {
10738
+ throw error;
10739
+ }
10740
+ const isReady = !isPending && !!order;
10741
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10742
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10743
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
10744
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10745
+ ] }),
10746
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10747
+ ] });
10748
+ };
10749
+ const EmailForm = ({ order }) => {
10750
+ const form = useForm({
10751
+ defaultValues: {
10752
+ email: order.email ?? ""
10753
+ },
10754
+ resolver: zodResolver(schema$4)
10755
+ });
10756
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10757
+ const { handleSuccess } = useRouteModal();
10758
+ const onSubmit = form.handleSubmit(async (data) => {
10759
+ await mutateAsync(
10760
+ { email: data.email },
10761
+ {
10762
+ onSuccess: () => {
10763
+ handleSuccess();
10764
+ },
10765
+ onError: (error) => {
10766
+ toast.error(error.message);
10767
+ }
10768
+ }
10769
+ );
10770
+ });
10771
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10772
+ KeyboundForm,
10773
+ {
10774
+ className: "flex flex-1 flex-col overflow-hidden",
10775
+ onSubmit,
10776
+ children: [
10777
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
10778
+ Form$2.Field,
10779
+ {
10780
+ control: form.control,
10781
+ name: "email",
10782
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10783
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
10784
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10785
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10786
+ ] })
10787
+ }
10788
+ ) }),
10789
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10790
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10791
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10792
+ ] }) })
10793
+ ]
10794
+ }
10795
+ ) });
10796
+ };
10797
+ const schema$4 = objectType({
10798
+ email: stringType().email()
10799
+ });
10800
+ const CustomItems = () => {
10801
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10802
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
10803
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
10804
+ ] });
10805
+ };
10806
+ const CustomItemsForm = () => {
10807
+ const form = useForm({
10808
+ resolver: zodResolver(schema$3)
10809
+ });
10810
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10811
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
10812
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10813
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10814
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
10815
+ ] }) })
10816
+ ] }) });
10817
+ };
10818
+ const schema$3 = objectType({
10819
+ email: stringType().email()
10820
+ });
10753
10821
  const InlineTip = forwardRef(
10754
10822
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10755
10823
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11405,7 +11473,7 @@ const SalesChannelForm = ({ order }) => {
11405
11473
  defaultValues: {
11406
11474
  sales_channel_id: order.sales_channel_id || ""
11407
11475
  },
11408
- resolver: zodResolver(schema$3)
11476
+ resolver: zodResolver(schema$2)
11409
11477
  });
11410
11478
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11411
11479
  const { handleSuccess } = useRouteModal();
@@ -11480,7 +11548,7 @@ const SalesChannelField = ({ control, order }) => {
11480
11548
  }
11481
11549
  );
11482
11550
  };
11483
- const schema$3 = objectType({
11551
+ const schema$2 = objectType({
11484
11552
  sales_channel_id: stringType().min(1)
11485
11553
  });
11486
11554
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12290,44 +12358,60 @@ const CustomAmountField = ({
12290
12358
  }
12291
12359
  );
12292
12360
  };
12293
- const TransferOwnership = () => {
12361
+ const ShippingAddress = () => {
12294
12362
  const { id } = useParams();
12295
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12296
- fields: "id,customer_id,customer.*"
12363
+ const { order, isPending, isError, error } = useOrder(id, {
12364
+ fields: "+shipping_address"
12297
12365
  });
12298
12366
  if (isError) {
12299
12367
  throw error;
12300
12368
  }
12301
- const isReady = !isPending && !!draft_order;
12369
+ const isReady = !isPending && !!order;
12302
12370
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12303
12371
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12304
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12305
- /* @__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" }) })
12372
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12373
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12306
12374
  ] }),
12307
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12375
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12308
12376
  ] });
12309
12377
  };
12310
- const TransferOwnershipForm = ({ order }) => {
12311
- var _a, _b;
12378
+ const ShippingAddressForm = ({ order }) => {
12379
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12312
12380
  const form = useForm({
12313
12381
  defaultValues: {
12314
- customer_id: order.customer_id || ""
12382
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12383
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12384
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12385
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12386
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12387
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12388
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12389
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12390
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12391
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12315
12392
  },
12316
- resolver: zodResolver(schema$2)
12393
+ resolver: zodResolver(schema$1)
12317
12394
  });
12318
12395
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12319
12396
  const { handleSuccess } = useRouteModal();
12320
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12321
- const currentCustomer = order.customer ? {
12322
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12323
- value: order.customer.id
12324
- } : null;
12325
12397
  const onSubmit = form.handleSubmit(async (data) => {
12326
12398
  await mutateAsync(
12327
- { customer_id: data.customer_id },
12399
+ {
12400
+ shipping_address: {
12401
+ first_name: data.first_name,
12402
+ last_name: data.last_name,
12403
+ company: data.company,
12404
+ address_1: data.address_1,
12405
+ address_2: data.address_2,
12406
+ city: data.city,
12407
+ province: data.province,
12408
+ country_code: data.country_code,
12409
+ postal_code: data.postal_code,
12410
+ phone: data.phone
12411
+ }
12412
+ },
12328
12413
  {
12329
12414
  onSuccess: () => {
12330
- toast.success("Customer updated");
12331
12415
  handleSuccess();
12332
12416
  },
12333
12417
  onError: (error) => {
@@ -12342,56 +12426,243 @@ const TransferOwnershipForm = ({ order }) => {
12342
12426
  className: "flex flex-1 flex-col overflow-hidden",
12343
12427
  onSubmit,
12344
12428
  children: [
12345
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12346
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12347
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12348
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12349
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12350
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12351
- ] }),
12352
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12353
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12354
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12355
- ] })
12429
+ /* @__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: [
12430
+ /* @__PURE__ */ jsx(
12431
+ Form$2.Field,
12432
+ {
12433
+ control: form.control,
12434
+ name: "country_code",
12435
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12436
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12437
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12438
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12439
+ ] })
12440
+ }
12441
+ ),
12442
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12443
+ /* @__PURE__ */ jsx(
12444
+ Form$2.Field,
12445
+ {
12446
+ control: form.control,
12447
+ name: "first_name",
12448
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12449
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12450
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12451
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12452
+ ] })
12453
+ }
12454
+ ),
12455
+ /* @__PURE__ */ jsx(
12456
+ Form$2.Field,
12457
+ {
12458
+ control: form.control,
12459
+ name: "last_name",
12460
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12461
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12462
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12463
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12464
+ ] })
12465
+ }
12466
+ )
12356
12467
  ] }),
12357
12468
  /* @__PURE__ */ jsx(
12358
- CustomerField,
12469
+ Form$2.Field,
12359
12470
  {
12360
12471
  control: form.control,
12361
- currentCustomerId: order.customer_id
12472
+ name: "company",
12473
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12474
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12475
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12476
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12477
+ ] })
12362
12478
  }
12363
- )
12364
- ] }),
12365
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12366
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12367
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12368
- ] }) })
12369
- ]
12370
- }
12371
- ) });
12372
- };
12373
- const CustomerField = ({ control, currentCustomerId }) => {
12374
- const customers = useComboboxData({
12375
- queryFn: async (params) => {
12376
- return await sdk.admin.customer.list({
12377
- ...params,
12378
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12379
- });
12380
- },
12381
- queryKey: ["customers"],
12382
- getOptions: (data) => {
12383
- return data.customers.map((customer) => {
12384
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12385
- return {
12386
- label: name ? `${name} (${customer.email})` : customer.email,
12387
- value: customer.id
12388
- };
12389
- });
12390
- }
12391
- });
12392
- return /* @__PURE__ */ jsx(
12393
- Form$2.Field,
12394
- {
12479
+ ),
12480
+ /* @__PURE__ */ jsx(
12481
+ Form$2.Field,
12482
+ {
12483
+ control: form.control,
12484
+ name: "address_1",
12485
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12486
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12487
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12488
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12489
+ ] })
12490
+ }
12491
+ ),
12492
+ /* @__PURE__ */ jsx(
12493
+ Form$2.Field,
12494
+ {
12495
+ control: form.control,
12496
+ name: "address_2",
12497
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12498
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12499
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12500
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12501
+ ] })
12502
+ }
12503
+ ),
12504
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12505
+ /* @__PURE__ */ jsx(
12506
+ Form$2.Field,
12507
+ {
12508
+ control: form.control,
12509
+ name: "postal_code",
12510
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12511
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12512
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12513
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12514
+ ] })
12515
+ }
12516
+ ),
12517
+ /* @__PURE__ */ jsx(
12518
+ Form$2.Field,
12519
+ {
12520
+ control: form.control,
12521
+ name: "city",
12522
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12523
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12524
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12525
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12526
+ ] })
12527
+ }
12528
+ )
12529
+ ] }),
12530
+ /* @__PURE__ */ jsx(
12531
+ Form$2.Field,
12532
+ {
12533
+ control: form.control,
12534
+ name: "province",
12535
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12536
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12537
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12538
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12539
+ ] })
12540
+ }
12541
+ ),
12542
+ /* @__PURE__ */ jsx(
12543
+ Form$2.Field,
12544
+ {
12545
+ control: form.control,
12546
+ name: "phone",
12547
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12548
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12549
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12550
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12551
+ ] })
12552
+ }
12553
+ )
12554
+ ] }) }),
12555
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12556
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12557
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12558
+ ] }) })
12559
+ ]
12560
+ }
12561
+ ) });
12562
+ };
12563
+ const schema$1 = addressSchema;
12564
+ const TransferOwnership = () => {
12565
+ const { id } = useParams();
12566
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12567
+ fields: "id,customer_id,customer.*"
12568
+ });
12569
+ if (isError) {
12570
+ throw error;
12571
+ }
12572
+ const isReady = !isPending && !!draft_order;
12573
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12574
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12575
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12576
+ /* @__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" }) })
12577
+ ] }),
12578
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12579
+ ] });
12580
+ };
12581
+ const TransferOwnershipForm = ({ order }) => {
12582
+ var _a, _b;
12583
+ const form = useForm({
12584
+ defaultValues: {
12585
+ customer_id: order.customer_id || ""
12586
+ },
12587
+ resolver: zodResolver(schema)
12588
+ });
12589
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
+ const { handleSuccess } = useRouteModal();
12591
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12592
+ const currentCustomer = order.customer ? {
12593
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12594
+ value: order.customer.id
12595
+ } : null;
12596
+ const onSubmit = form.handleSubmit(async (data) => {
12597
+ await mutateAsync(
12598
+ { customer_id: data.customer_id },
12599
+ {
12600
+ onSuccess: () => {
12601
+ toast.success("Customer updated");
12602
+ handleSuccess();
12603
+ },
12604
+ onError: (error) => {
12605
+ toast.error(error.message);
12606
+ }
12607
+ }
12608
+ );
12609
+ });
12610
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12611
+ KeyboundForm,
12612
+ {
12613
+ className: "flex flex-1 flex-col overflow-hidden",
12614
+ onSubmit,
12615
+ children: [
12616
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12617
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12618
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12619
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12620
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12621
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12622
+ ] }),
12623
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12624
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12625
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12626
+ ] })
12627
+ ] }),
12628
+ /* @__PURE__ */ jsx(
12629
+ CustomerField,
12630
+ {
12631
+ control: form.control,
12632
+ currentCustomerId: order.customer_id
12633
+ }
12634
+ )
12635
+ ] }),
12636
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12637
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12638
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12639
+ ] }) })
12640
+ ]
12641
+ }
12642
+ ) });
12643
+ };
12644
+ const CustomerField = ({ control, currentCustomerId }) => {
12645
+ const customers = useComboboxData({
12646
+ queryFn: async (params) => {
12647
+ return await sdk.admin.customer.list({
12648
+ ...params,
12649
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12650
+ });
12651
+ },
12652
+ queryKey: ["customers"],
12653
+ getOptions: (data) => {
12654
+ return data.customers.map((customer) => {
12655
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12656
+ return {
12657
+ label: name ? `${name} (${customer.email})` : customer.email,
12658
+ value: customer.id
12659
+ };
12660
+ });
12661
+ }
12662
+ });
12663
+ return /* @__PURE__ */ jsx(
12664
+ Form$2.Field,
12665
+ {
12395
12666
  name: "customer_id",
12396
12667
  control,
12397
12668
  render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
@@ -12763,279 +13034,8 @@ const Illustration = () => {
12763
13034
  }
12764
13035
  );
12765
13036
  };
12766
- const schema$2 = objectType({
12767
- customer_id: stringType().min(1)
12768
- });
12769
- const ShippingAddress = () => {
12770
- const { id } = useParams();
12771
- const { order, isPending, isError, error } = useOrder(id, {
12772
- fields: "+shipping_address"
12773
- });
12774
- if (isError) {
12775
- throw error;
12776
- }
12777
- const isReady = !isPending && !!order;
12778
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12779
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12780
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12781
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12782
- ] }),
12783
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12784
- ] });
12785
- };
12786
- const ShippingAddressForm = ({ order }) => {
12787
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12788
- const form = useForm({
12789
- defaultValues: {
12790
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12791
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12792
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12793
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12794
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12795
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12796
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12797
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12798
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12799
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12800
- },
12801
- resolver: zodResolver(schema$1)
12802
- });
12803
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12804
- const { handleSuccess } = useRouteModal();
12805
- const onSubmit = form.handleSubmit(async (data) => {
12806
- await mutateAsync(
12807
- {
12808
- shipping_address: {
12809
- first_name: data.first_name,
12810
- last_name: data.last_name,
12811
- company: data.company,
12812
- address_1: data.address_1,
12813
- address_2: data.address_2,
12814
- city: data.city,
12815
- province: data.province,
12816
- country_code: data.country_code,
12817
- postal_code: data.postal_code,
12818
- phone: data.phone
12819
- }
12820
- },
12821
- {
12822
- onSuccess: () => {
12823
- handleSuccess();
12824
- },
12825
- onError: (error) => {
12826
- toast.error(error.message);
12827
- }
12828
- }
12829
- );
12830
- });
12831
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12832
- KeyboundForm,
12833
- {
12834
- className: "flex flex-1 flex-col overflow-hidden",
12835
- onSubmit,
12836
- children: [
12837
- /* @__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: [
12838
- /* @__PURE__ */ jsx(
12839
- Form$2.Field,
12840
- {
12841
- control: form.control,
12842
- name: "country_code",
12843
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12844
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12845
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12846
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12847
- ] })
12848
- }
12849
- ),
12850
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12851
- /* @__PURE__ */ jsx(
12852
- Form$2.Field,
12853
- {
12854
- control: form.control,
12855
- name: "first_name",
12856
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12857
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12858
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12859
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12860
- ] })
12861
- }
12862
- ),
12863
- /* @__PURE__ */ jsx(
12864
- Form$2.Field,
12865
- {
12866
- control: form.control,
12867
- name: "last_name",
12868
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12869
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12870
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12871
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12872
- ] })
12873
- }
12874
- )
12875
- ] }),
12876
- /* @__PURE__ */ jsx(
12877
- Form$2.Field,
12878
- {
12879
- control: form.control,
12880
- name: "company",
12881
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12882
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12883
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12884
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12885
- ] })
12886
- }
12887
- ),
12888
- /* @__PURE__ */ jsx(
12889
- Form$2.Field,
12890
- {
12891
- control: form.control,
12892
- name: "address_1",
12893
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12894
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12895
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12896
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12897
- ] })
12898
- }
12899
- ),
12900
- /* @__PURE__ */ jsx(
12901
- Form$2.Field,
12902
- {
12903
- control: form.control,
12904
- name: "address_2",
12905
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12906
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12907
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12908
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12909
- ] })
12910
- }
12911
- ),
12912
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12913
- /* @__PURE__ */ jsx(
12914
- Form$2.Field,
12915
- {
12916
- control: form.control,
12917
- name: "postal_code",
12918
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12919
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12920
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12921
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12922
- ] })
12923
- }
12924
- ),
12925
- /* @__PURE__ */ jsx(
12926
- Form$2.Field,
12927
- {
12928
- control: form.control,
12929
- name: "city",
12930
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12931
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12932
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12933
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12934
- ] })
12935
- }
12936
- )
12937
- ] }),
12938
- /* @__PURE__ */ jsx(
12939
- Form$2.Field,
12940
- {
12941
- control: form.control,
12942
- name: "province",
12943
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12944
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12945
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12946
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12947
- ] })
12948
- }
12949
- ),
12950
- /* @__PURE__ */ jsx(
12951
- Form$2.Field,
12952
- {
12953
- control: form.control,
12954
- name: "phone",
12955
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12956
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12957
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12958
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12959
- ] })
12960
- }
12961
- )
12962
- ] }) }),
12963
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12964
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12965
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12966
- ] }) })
12967
- ]
12968
- }
12969
- ) });
12970
- };
12971
- const schema$1 = addressSchema;
12972
- const Email = () => {
12973
- const { id } = useParams();
12974
- const { order, isPending, isError, error } = useOrder(id, {
12975
- fields: "+email"
12976
- });
12977
- if (isError) {
12978
- throw error;
12979
- }
12980
- const isReady = !isPending && !!order;
12981
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12982
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12983
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12984
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12985
- ] }),
12986
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12987
- ] });
12988
- };
12989
- const EmailForm = ({ order }) => {
12990
- const form = useForm({
12991
- defaultValues: {
12992
- email: order.email ?? ""
12993
- },
12994
- resolver: zodResolver(schema)
12995
- });
12996
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12997
- const { handleSuccess } = useRouteModal();
12998
- const onSubmit = form.handleSubmit(async (data) => {
12999
- await mutateAsync(
13000
- { email: data.email },
13001
- {
13002
- onSuccess: () => {
13003
- handleSuccess();
13004
- },
13005
- onError: (error) => {
13006
- toast.error(error.message);
13007
- }
13008
- }
13009
- );
13010
- });
13011
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
13012
- KeyboundForm,
13013
- {
13014
- className: "flex flex-1 flex-col overflow-hidden",
13015
- onSubmit,
13016
- children: [
13017
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
13018
- Form$2.Field,
13019
- {
13020
- control: form.control,
13021
- name: "email",
13022
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13023
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
13024
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13025
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13026
- ] })
13027
- }
13028
- ) }),
13029
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13030
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13031
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13032
- ] }) })
13033
- ]
13034
- }
13035
- ) });
13036
- };
13037
13037
  const schema = objectType({
13038
- email: stringType().email()
13038
+ customer_id: stringType().min(1)
13039
13039
  });
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
@@ -13061,14 +13061,18 @@ const routeModule = {
13061
13061
  Component: BillingAddress,
13062
13062
  path: "/draft-orders/:id/billing-address"
13063
13063
  },
13064
- {
13065
- Component: CustomItems,
13066
- path: "/draft-orders/:id/custom-items"
13067
- },
13068
13064
  {
13069
13065
  Component: Items,
13070
13066
  path: "/draft-orders/:id/items"
13071
13067
  },
13068
+ {
13069
+ Component: Email,
13070
+ path: "/draft-orders/:id/email"
13071
+ },
13072
+ {
13073
+ Component: CustomItems,
13074
+ path: "/draft-orders/:id/custom-items"
13075
+ },
13072
13076
  {
13073
13077
  Component: Metadata,
13074
13078
  path: "/draft-orders/:id/metadata"
@@ -13085,17 +13089,13 @@ const routeModule = {
13085
13089
  Component: Shipping,
13086
13090
  path: "/draft-orders/:id/shipping"
13087
13091
  },
13088
- {
13089
- Component: TransferOwnership,
13090
- path: "/draft-orders/:id/transfer-ownership"
13091
- },
13092
13092
  {
13093
13093
  Component: ShippingAddress,
13094
13094
  path: "/draft-orders/:id/shipping-address"
13095
13095
  },
13096
13096
  {
13097
- Component: Email,
13098
- path: "/draft-orders/:id/email"
13097
+ Component: TransferOwnership,
13098
+ path: "/draft-orders/:id/transfer-ownership"
13099
13099
  }
13100
13100
  ]
13101
13101
  }