@medusajs/draft-order 2.12.2-preview-20251204150146 → 2.12.2-preview-20251204210133

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,6 +9755,27 @@ 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
+ });
9758
9779
  const Email = () => {
9759
9780
  const { id } = useParams();
9760
9781
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9777,7 +9798,7 @@ const EmailForm = ({ order }) => {
9777
9798
  defaultValues: {
9778
9799
  email: order.email ?? ""
9779
9800
  },
9780
- resolver: zodResolver(schema$4)
9801
+ resolver: zodResolver(schema$3)
9781
9802
  });
9782
9803
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9783
9804
  const { handleSuccess } = useRouteModal();
@@ -9820,7 +9841,7 @@ const EmailForm = ({ order }) => {
9820
9841
  }
9821
9842
  ) });
9822
9843
  };
9823
- const schema$4 = objectType({
9844
+ const schema$3 = objectType({
9824
9845
  email: stringType().email()
9825
9846
  });
9826
9847
  const NumberInput = forwardRef(
@@ -10797,27 +10818,6 @@ const customItemSchema = objectType({
10797
10818
  quantity: numberType(),
10798
10819
  unit_price: unionType([numberType(), stringType()])
10799
10820
  });
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
- });
10821
10821
  const InlineTip = forwardRef(
10822
10822
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10823
10823
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11445,112 +11445,6 @@ function getPromotionIds(items, shippingMethods) {
11445
11445
  }
11446
11446
  return Array.from(promotionIds);
11447
11447
  }
11448
- const SalesChannel = () => {
11449
- const { id } = useParams();
11450
- const { draft_order, isPending, isError, error } = useDraftOrder(
11451
- id,
11452
- {
11453
- fields: "+sales_channel_id"
11454
- },
11455
- {
11456
- enabled: !!id
11457
- }
11458
- );
11459
- if (isError) {
11460
- throw error;
11461
- }
11462
- const ISrEADY = !!draft_order && !isPending;
11463
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11464
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11465
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11466
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11467
- ] }),
11468
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11469
- ] });
11470
- };
11471
- const SalesChannelForm = ({ order }) => {
11472
- const form = useForm({
11473
- defaultValues: {
11474
- sales_channel_id: order.sales_channel_id || ""
11475
- },
11476
- resolver: zodResolver(schema$2)
11477
- });
11478
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11479
- const { handleSuccess } = useRouteModal();
11480
- const onSubmit = form.handleSubmit(async (data) => {
11481
- await mutateAsync(
11482
- {
11483
- sales_channel_id: data.sales_channel_id
11484
- },
11485
- {
11486
- onSuccess: () => {
11487
- toast.success("Sales channel updated");
11488
- handleSuccess();
11489
- },
11490
- onError: (error) => {
11491
- toast.error(error.message);
11492
- }
11493
- }
11494
- );
11495
- });
11496
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11497
- KeyboundForm,
11498
- {
11499
- className: "flex flex-1 flex-col overflow-hidden",
11500
- onSubmit,
11501
- children: [
11502
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11503
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11504
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11505
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11506
- ] }) })
11507
- ]
11508
- }
11509
- ) });
11510
- };
11511
- const SalesChannelField = ({ control, order }) => {
11512
- const salesChannels = useComboboxData({
11513
- queryFn: async (params) => {
11514
- return await sdk.admin.salesChannel.list(params);
11515
- },
11516
- queryKey: ["sales-channels"],
11517
- getOptions: (data) => {
11518
- return data.sales_channels.map((salesChannel) => ({
11519
- label: salesChannel.name,
11520
- value: salesChannel.id
11521
- }));
11522
- },
11523
- defaultValue: order.sales_channel_id || void 0
11524
- });
11525
- return /* @__PURE__ */ jsx(
11526
- Form$2.Field,
11527
- {
11528
- control,
11529
- name: "sales_channel_id",
11530
- render: ({ field }) => {
11531
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11532
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11533
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11534
- Combobox,
11535
- {
11536
- options: salesChannels.options,
11537
- fetchNextPage: salesChannels.fetchNextPage,
11538
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11539
- searchValue: salesChannels.searchValue,
11540
- onSearchValueChange: salesChannels.onSearchValueChange,
11541
- placeholder: "Select sales channel",
11542
- ...field
11543
- }
11544
- ) }),
11545
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11546
- ] });
11547
- }
11548
- }
11549
- );
11550
- };
11551
- const schema$2 = objectType({
11552
- sales_channel_id: stringType().min(1)
11553
- });
11554
11448
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11555
11449
  const Shipping = () => {
11556
11450
  var _a;
@@ -12358,44 +12252,60 @@ const CustomAmountField = ({
12358
12252
  }
12359
12253
  );
12360
12254
  };
12361
- const TransferOwnership = () => {
12255
+ const ShippingAddress = () => {
12362
12256
  const { id } = useParams();
12363
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12364
- fields: "id,customer_id,customer.*"
12257
+ const { order, isPending, isError, error } = useOrder(id, {
12258
+ fields: "+shipping_address"
12365
12259
  });
12366
12260
  if (isError) {
12367
12261
  throw error;
12368
12262
  }
12369
- const isReady = !isPending && !!draft_order;
12263
+ const isReady = !isPending && !!order;
12370
12264
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12371
12265
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12372
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12373
- /* @__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" }) })
12266
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12267
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12374
12268
  ] }),
12375
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12269
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12376
12270
  ] });
12377
12271
  };
12378
- const TransferOwnershipForm = ({ order }) => {
12379
- var _a, _b;
12272
+ const ShippingAddressForm = ({ order }) => {
12273
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12380
12274
  const form = useForm({
12381
12275
  defaultValues: {
12382
- customer_id: order.customer_id || ""
12276
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12277
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12278
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12279
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12280
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12281
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12282
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12283
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12284
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12285
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12383
12286
  },
12384
- resolver: zodResolver(schema$1)
12287
+ resolver: zodResolver(schema$2)
12385
12288
  });
12386
12289
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12387
12290
  const { handleSuccess } = useRouteModal();
12388
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12389
- const currentCustomer = order.customer ? {
12390
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12391
- value: order.customer.id
12392
- } : null;
12393
12291
  const onSubmit = form.handleSubmit(async (data) => {
12394
12292
  await mutateAsync(
12395
- { customer_id: data.customer_id },
12293
+ {
12294
+ shipping_address: {
12295
+ first_name: data.first_name,
12296
+ last_name: data.last_name,
12297
+ company: data.company,
12298
+ address_1: data.address_1,
12299
+ address_2: data.address_2,
12300
+ city: data.city,
12301
+ province: data.province,
12302
+ country_code: data.country_code,
12303
+ postal_code: data.postal_code,
12304
+ phone: data.phone
12305
+ }
12306
+ },
12396
12307
  {
12397
12308
  onSuccess: () => {
12398
- toast.success("Customer updated");
12399
12309
  handleSuccess();
12400
12310
  },
12401
12311
  onError: (error) => {
@@ -12410,55 +12320,348 @@ const TransferOwnershipForm = ({ order }) => {
12410
12320
  className: "flex flex-1 flex-col overflow-hidden",
12411
12321
  onSubmit,
12412
12322
  children: [
12413
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12414
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12415
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12416
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12417
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12418
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12419
- ] }),
12420
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12421
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12422
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12423
- ] })
12424
- ] }),
12323
+ /* @__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: [
12425
12324
  /* @__PURE__ */ jsx(
12426
- CustomerField,
12325
+ Form$2.Field,
12427
12326
  {
12428
12327
  control: form.control,
12429
- currentCustomerId: order.customer_id
12328
+ name: "country_code",
12329
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12330
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12331
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12332
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12333
+ ] })
12430
12334
  }
12431
- )
12432
- ] }),
12433
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12434
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12435
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12436
- ] }) })
12437
- ]
12438
- }
12439
- ) });
12440
- };
12441
- const CustomerField = ({ control, currentCustomerId }) => {
12442
- const customers = useComboboxData({
12443
- queryFn: async (params) => {
12444
- return await sdk.admin.customer.list({
12445
- ...params,
12446
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12447
- });
12448
- },
12449
- queryKey: ["customers"],
12450
- getOptions: (data) => {
12451
- return data.customers.map((customer) => {
12452
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12453
- return {
12454
- label: name ? `${name} (${customer.email})` : customer.email,
12455
- value: customer.id
12456
- };
12457
- });
12458
- }
12459
- });
12460
- return /* @__PURE__ */ jsx(
12461
- Form$2.Field,
12335
+ ),
12336
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12337
+ /* @__PURE__ */ jsx(
12338
+ Form$2.Field,
12339
+ {
12340
+ control: form.control,
12341
+ name: "first_name",
12342
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12343
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12344
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12345
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12346
+ ] })
12347
+ }
12348
+ ),
12349
+ /* @__PURE__ */ jsx(
12350
+ Form$2.Field,
12351
+ {
12352
+ control: form.control,
12353
+ name: "last_name",
12354
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12355
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12356
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12357
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12358
+ ] })
12359
+ }
12360
+ )
12361
+ ] }),
12362
+ /* @__PURE__ */ jsx(
12363
+ Form$2.Field,
12364
+ {
12365
+ control: form.control,
12366
+ name: "company",
12367
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12368
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12369
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12370
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12371
+ ] })
12372
+ }
12373
+ ),
12374
+ /* @__PURE__ */ jsx(
12375
+ Form$2.Field,
12376
+ {
12377
+ control: form.control,
12378
+ name: "address_1",
12379
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12380
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12381
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12382
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12383
+ ] })
12384
+ }
12385
+ ),
12386
+ /* @__PURE__ */ jsx(
12387
+ Form$2.Field,
12388
+ {
12389
+ control: form.control,
12390
+ name: "address_2",
12391
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12392
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12393
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12394
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12395
+ ] })
12396
+ }
12397
+ ),
12398
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12399
+ /* @__PURE__ */ jsx(
12400
+ Form$2.Field,
12401
+ {
12402
+ control: form.control,
12403
+ name: "postal_code",
12404
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12405
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12406
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12407
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12408
+ ] })
12409
+ }
12410
+ ),
12411
+ /* @__PURE__ */ jsx(
12412
+ Form$2.Field,
12413
+ {
12414
+ control: form.control,
12415
+ name: "city",
12416
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12417
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12418
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12419
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12420
+ ] })
12421
+ }
12422
+ )
12423
+ ] }),
12424
+ /* @__PURE__ */ jsx(
12425
+ Form$2.Field,
12426
+ {
12427
+ control: form.control,
12428
+ name: "province",
12429
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12430
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12431
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12432
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12433
+ ] })
12434
+ }
12435
+ ),
12436
+ /* @__PURE__ */ jsx(
12437
+ Form$2.Field,
12438
+ {
12439
+ control: form.control,
12440
+ name: "phone",
12441
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12442
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12443
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12444
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12445
+ ] })
12446
+ }
12447
+ )
12448
+ ] }) }),
12449
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12450
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12451
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12452
+ ] }) })
12453
+ ]
12454
+ }
12455
+ ) });
12456
+ };
12457
+ const schema$2 = addressSchema;
12458
+ const SalesChannel = () => {
12459
+ const { id } = useParams();
12460
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12461
+ id,
12462
+ {
12463
+ fields: "+sales_channel_id"
12464
+ },
12465
+ {
12466
+ enabled: !!id
12467
+ }
12468
+ );
12469
+ if (isError) {
12470
+ throw error;
12471
+ }
12472
+ const ISrEADY = !!draft_order && !isPending;
12473
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12474
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12475
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12476
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12477
+ ] }),
12478
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12479
+ ] });
12480
+ };
12481
+ const SalesChannelForm = ({ order }) => {
12482
+ const form = useForm({
12483
+ defaultValues: {
12484
+ sales_channel_id: order.sales_channel_id || ""
12485
+ },
12486
+ resolver: zodResolver(schema$1)
12487
+ });
12488
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12489
+ const { handleSuccess } = useRouteModal();
12490
+ const onSubmit = form.handleSubmit(async (data) => {
12491
+ await mutateAsync(
12492
+ {
12493
+ sales_channel_id: data.sales_channel_id
12494
+ },
12495
+ {
12496
+ onSuccess: () => {
12497
+ toast.success("Sales channel updated");
12498
+ handleSuccess();
12499
+ },
12500
+ onError: (error) => {
12501
+ toast.error(error.message);
12502
+ }
12503
+ }
12504
+ );
12505
+ });
12506
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12507
+ KeyboundForm,
12508
+ {
12509
+ className: "flex flex-1 flex-col overflow-hidden",
12510
+ onSubmit,
12511
+ children: [
12512
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12513
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12514
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12515
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12516
+ ] }) })
12517
+ ]
12518
+ }
12519
+ ) });
12520
+ };
12521
+ const SalesChannelField = ({ control, order }) => {
12522
+ const salesChannels = useComboboxData({
12523
+ queryFn: async (params) => {
12524
+ return await sdk.admin.salesChannel.list(params);
12525
+ },
12526
+ queryKey: ["sales-channels"],
12527
+ getOptions: (data) => {
12528
+ return data.sales_channels.map((salesChannel) => ({
12529
+ label: salesChannel.name,
12530
+ value: salesChannel.id
12531
+ }));
12532
+ },
12533
+ defaultValue: order.sales_channel_id || void 0
12534
+ });
12535
+ return /* @__PURE__ */ jsx(
12536
+ Form$2.Field,
12537
+ {
12538
+ control,
12539
+ name: "sales_channel_id",
12540
+ render: ({ field }) => {
12541
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12542
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12543
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12544
+ Combobox,
12545
+ {
12546
+ options: salesChannels.options,
12547
+ fetchNextPage: salesChannels.fetchNextPage,
12548
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12549
+ searchValue: salesChannels.searchValue,
12550
+ onSearchValueChange: salesChannels.onSearchValueChange,
12551
+ placeholder: "Select sales channel",
12552
+ ...field
12553
+ }
12554
+ ) }),
12555
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12556
+ ] });
12557
+ }
12558
+ }
12559
+ );
12560
+ };
12561
+ const schema$1 = objectType({
12562
+ sales_channel_id: stringType().min(1)
12563
+ });
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,
12462
12665
  {
12463
12666
  name: "customer_id",
12464
12667
  control,
@@ -12831,212 +13034,9 @@ const Illustration = () => {
12831
13034
  }
12832
13035
  );
12833
13036
  };
12834
- const schema$1 = objectType({
13037
+ const schema = objectType({
12835
13038
  customer_id: stringType().min(1)
12836
13039
  });
12837
- const ShippingAddress = () => {
12838
- const { id } = useParams();
12839
- const { order, isPending, isError, error } = useOrder(id, {
12840
- fields: "+shipping_address"
12841
- });
12842
- if (isError) {
12843
- throw error;
12844
- }
12845
- const isReady = !isPending && !!order;
12846
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12847
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12848
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12849
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12850
- ] }),
12851
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12852
- ] });
12853
- };
12854
- const ShippingAddressForm = ({ order }) => {
12855
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12856
- const form = useForm({
12857
- defaultValues: {
12858
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12859
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12860
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12861
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12862
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12863
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12864
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12865
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12866
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12867
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12868
- },
12869
- resolver: zodResolver(schema)
12870
- });
12871
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12872
- const { handleSuccess } = useRouteModal();
12873
- const onSubmit = form.handleSubmit(async (data) => {
12874
- await mutateAsync(
12875
- {
12876
- shipping_address: {
12877
- first_name: data.first_name,
12878
- last_name: data.last_name,
12879
- company: data.company,
12880
- address_1: data.address_1,
12881
- address_2: data.address_2,
12882
- city: data.city,
12883
- province: data.province,
12884
- country_code: data.country_code,
12885
- postal_code: data.postal_code,
12886
- phone: data.phone
12887
- }
12888
- },
12889
- {
12890
- onSuccess: () => {
12891
- handleSuccess();
12892
- },
12893
- onError: (error) => {
12894
- toast.error(error.message);
12895
- }
12896
- }
12897
- );
12898
- });
12899
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12900
- KeyboundForm,
12901
- {
12902
- className: "flex flex-1 flex-col overflow-hidden",
12903
- onSubmit,
12904
- children: [
12905
- /* @__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: [
12906
- /* @__PURE__ */ jsx(
12907
- Form$2.Field,
12908
- {
12909
- control: form.control,
12910
- name: "country_code",
12911
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12912
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12913
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12914
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12915
- ] })
12916
- }
12917
- ),
12918
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12919
- /* @__PURE__ */ jsx(
12920
- Form$2.Field,
12921
- {
12922
- control: form.control,
12923
- name: "first_name",
12924
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12925
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12926
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12927
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12928
- ] })
12929
- }
12930
- ),
12931
- /* @__PURE__ */ jsx(
12932
- Form$2.Field,
12933
- {
12934
- control: form.control,
12935
- name: "last_name",
12936
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12937
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12938
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12939
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12940
- ] })
12941
- }
12942
- )
12943
- ] }),
12944
- /* @__PURE__ */ jsx(
12945
- Form$2.Field,
12946
- {
12947
- control: form.control,
12948
- name: "company",
12949
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12950
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12951
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12952
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12953
- ] })
12954
- }
12955
- ),
12956
- /* @__PURE__ */ jsx(
12957
- Form$2.Field,
12958
- {
12959
- control: form.control,
12960
- name: "address_1",
12961
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12962
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12963
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12964
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12965
- ] })
12966
- }
12967
- ),
12968
- /* @__PURE__ */ jsx(
12969
- Form$2.Field,
12970
- {
12971
- control: form.control,
12972
- name: "address_2",
12973
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12974
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12975
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12976
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12977
- ] })
12978
- }
12979
- ),
12980
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12981
- /* @__PURE__ */ jsx(
12982
- Form$2.Field,
12983
- {
12984
- control: form.control,
12985
- name: "postal_code",
12986
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12987
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12988
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12989
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12990
- ] })
12991
- }
12992
- ),
12993
- /* @__PURE__ */ jsx(
12994
- Form$2.Field,
12995
- {
12996
- control: form.control,
12997
- name: "city",
12998
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12999
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13000
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13001
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13002
- ] })
13003
- }
13004
- )
13005
- ] }),
13006
- /* @__PURE__ */ jsx(
13007
- Form$2.Field,
13008
- {
13009
- control: form.control,
13010
- name: "province",
13011
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13012
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13013
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13014
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13015
- ] })
13016
- }
13017
- ),
13018
- /* @__PURE__ */ jsx(
13019
- Form$2.Field,
13020
- {
13021
- control: form.control,
13022
- name: "phone",
13023
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13024
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13025
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13026
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13027
- ] })
13028
- }
13029
- )
13030
- ] }) }),
13031
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13032
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13033
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13034
- ] }) })
13035
- ]
13036
- }
13037
- ) });
13038
- };
13039
- const schema = addressSchema;
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13061,6 +13061,10 @@ 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
+ },
13064
13068
  {
13065
13069
  Component: Email,
13066
13070
  path: "/draft-orders/:id/email"
@@ -13069,10 +13073,6 @@ const routeModule = {
13069
13073
  Component: Items,
13070
13074
  path: "/draft-orders/:id/items"
13071
13075
  },
13072
- {
13073
- Component: CustomItems,
13074
- path: "/draft-orders/:id/custom-items"
13075
- },
13076
13076
  {
13077
13077
  Component: Metadata,
13078
13078
  path: "/draft-orders/:id/metadata"
@@ -13081,21 +13081,21 @@ const routeModule = {
13081
13081
  Component: Promotions,
13082
13082
  path: "/draft-orders/:id/promotions"
13083
13083
  },
13084
- {
13085
- Component: SalesChannel,
13086
- path: "/draft-orders/:id/sales-channel"
13087
- },
13088
13084
  {
13089
13085
  Component: Shipping,
13090
13086
  path: "/draft-orders/:id/shipping"
13091
13087
  },
13092
- {
13093
- Component: TransferOwnership,
13094
- path: "/draft-orders/:id/transfer-ownership"
13095
- },
13096
13088
  {
13097
13089
  Component: ShippingAddress,
13098
13090
  path: "/draft-orders/:id/shipping-address"
13091
+ },
13092
+ {
13093
+ Component: SalesChannel,
13094
+ path: "/draft-orders/:id/sales-channel"
13095
+ },
13096
+ {
13097
+ Component: TransferOwnership,
13098
+ path: "/draft-orders/:id/transfer-ownership"
13099
13099
  }
13100
13100
  ]
13101
13101
  }