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

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.
@@ -11452,6 +11452,112 @@ function getPromotionIds(items, shippingMethods) {
11452
11452
  }
11453
11453
  return Array.from(promotionIds);
11454
11454
  }
11455
+ const SalesChannel = () => {
11456
+ const { id } = reactRouterDom.useParams();
11457
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11458
+ id,
11459
+ {
11460
+ fields: "+sales_channel_id"
11461
+ },
11462
+ {
11463
+ enabled: !!id
11464
+ }
11465
+ );
11466
+ if (isError) {
11467
+ throw error;
11468
+ }
11469
+ const ISrEADY = !!draft_order && !isPending;
11470
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11471
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11473
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11474
+ ] }),
11475
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11476
+ ] });
11477
+ };
11478
+ const SalesChannelForm = ({ order }) => {
11479
+ const form = reactHookForm.useForm({
11480
+ defaultValues: {
11481
+ sales_channel_id: order.sales_channel_id || ""
11482
+ },
11483
+ resolver: zod.zodResolver(schema$2)
11484
+ });
11485
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11486
+ const { handleSuccess } = useRouteModal();
11487
+ const onSubmit = form.handleSubmit(async (data) => {
11488
+ await mutateAsync(
11489
+ {
11490
+ sales_channel_id: data.sales_channel_id
11491
+ },
11492
+ {
11493
+ onSuccess: () => {
11494
+ ui.toast.success("Sales channel updated");
11495
+ handleSuccess();
11496
+ },
11497
+ onError: (error) => {
11498
+ ui.toast.error(error.message);
11499
+ }
11500
+ }
11501
+ );
11502
+ });
11503
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11504
+ KeyboundForm,
11505
+ {
11506
+ className: "flex flex-1 flex-col overflow-hidden",
11507
+ onSubmit,
11508
+ children: [
11509
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11511
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11512
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11513
+ ] }) })
11514
+ ]
11515
+ }
11516
+ ) });
11517
+ };
11518
+ const SalesChannelField = ({ control, order }) => {
11519
+ const salesChannels = useComboboxData({
11520
+ queryFn: async (params) => {
11521
+ return await sdk.admin.salesChannel.list(params);
11522
+ },
11523
+ queryKey: ["sales-channels"],
11524
+ getOptions: (data) => {
11525
+ return data.sales_channels.map((salesChannel) => ({
11526
+ label: salesChannel.name,
11527
+ value: salesChannel.id
11528
+ }));
11529
+ },
11530
+ defaultValue: order.sales_channel_id || void 0
11531
+ });
11532
+ return /* @__PURE__ */ jsxRuntime.jsx(
11533
+ Form$2.Field,
11534
+ {
11535
+ control,
11536
+ name: "sales_channel_id",
11537
+ render: ({ field }) => {
11538
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11539
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11541
+ Combobox,
11542
+ {
11543
+ options: salesChannels.options,
11544
+ fetchNextPage: salesChannels.fetchNextPage,
11545
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11546
+ searchValue: salesChannels.searchValue,
11547
+ onSearchValueChange: salesChannels.onSearchValueChange,
11548
+ placeholder: "Select sales channel",
11549
+ ...field
11550
+ }
11551
+ ) }),
11552
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11553
+ ] });
11554
+ }
11555
+ }
11556
+ );
11557
+ };
11558
+ const schema$2 = objectType({
11559
+ sales_channel_id: stringType().min(1)
11560
+ });
11455
11561
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11456
11562
  const Shipping = () => {
11457
11563
  var _a;
@@ -12259,60 +12365,44 @@ const CustomAmountField = ({
12259
12365
  }
12260
12366
  );
12261
12367
  };
12262
- const ShippingAddress = () => {
12368
+ const TransferOwnership = () => {
12263
12369
  const { id } = reactRouterDom.useParams();
12264
- const { order, isPending, isError, error } = useOrder(id, {
12265
- fields: "+shipping_address"
12370
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12371
+ fields: "id,customer_id,customer.*"
12266
12372
  });
12267
12373
  if (isError) {
12268
12374
  throw error;
12269
12375
  }
12270
- const isReady = !isPending && !!order;
12376
+ const isReady = !isPending && !!draft_order;
12271
12377
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12272
12378
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12273
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12274
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12379
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12380
+ /* @__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" }) })
12275
12381
  ] }),
12276
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12382
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12277
12383
  ] });
12278
12384
  };
12279
- const ShippingAddressForm = ({ order }) => {
12280
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12385
+ const TransferOwnershipForm = ({ order }) => {
12386
+ var _a, _b;
12281
12387
  const form = reactHookForm.useForm({
12282
12388
  defaultValues: {
12283
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12284
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12285
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12286
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12287
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12288
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12289
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12290
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12291
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12292
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12389
+ customer_id: order.customer_id || ""
12293
12390
  },
12294
- resolver: zod.zodResolver(schema$2)
12391
+ resolver: zod.zodResolver(schema$1)
12295
12392
  });
12296
12393
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12297
12394
  const { handleSuccess } = useRouteModal();
12395
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12396
+ const currentCustomer = order.customer ? {
12397
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12398
+ value: order.customer.id
12399
+ } : null;
12298
12400
  const onSubmit = form.handleSubmit(async (data) => {
12299
12401
  await mutateAsync(
12300
- {
12301
- shipping_address: {
12302
- first_name: data.first_name,
12303
- last_name: data.last_name,
12304
- company: data.company,
12305
- address_1: data.address_1,
12306
- address_2: data.address_2,
12307
- city: data.city,
12308
- province: data.province,
12309
- country_code: data.country_code,
12310
- postal_code: data.postal_code,
12311
- phone: data.phone
12312
- }
12313
- },
12402
+ { customer_id: data.customer_id },
12314
12403
  {
12315
12404
  onSuccess: () => {
12405
+ ui.toast.success("Customer updated");
12316
12406
  handleSuccess();
12317
12407
  },
12318
12408
  onError: (error) => {
@@ -12327,316 +12417,23 @@ const ShippingAddressForm = ({ order }) => {
12327
12417
  className: "flex flex-1 flex-col overflow-hidden",
12328
12418
  onSubmit,
12329
12419
  children: [
12330
- /* @__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: [
12331
- /* @__PURE__ */ jsxRuntime.jsx(
12332
- Form$2.Field,
12333
- {
12334
- control: form.control,
12335
- name: "country_code",
12336
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12337
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12338
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12339
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12340
- ] })
12341
- }
12342
- ),
12343
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12344
- /* @__PURE__ */ jsxRuntime.jsx(
12345
- Form$2.Field,
12346
- {
12347
- control: form.control,
12348
- name: "first_name",
12349
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12353
- ] })
12354
- }
12355
- ),
12356
- /* @__PURE__ */ jsxRuntime.jsx(
12357
- Form$2.Field,
12358
- {
12359
- control: form.control,
12360
- name: "last_name",
12361
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12362
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12364
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12365
- ] })
12366
- }
12367
- )
12420
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12421
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12422
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12423
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12424
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12425
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12426
+ ] }),
12427
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12428
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12429
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12430
+ ] })
12368
12431
  ] }),
12369
12432
  /* @__PURE__ */ jsxRuntime.jsx(
12370
- Form$2.Field,
12371
- {
12372
- control: form.control,
12373
- name: "company",
12374
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12375
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12376
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12377
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12378
- ] })
12379
- }
12380
- ),
12381
- /* @__PURE__ */ jsxRuntime.jsx(
12382
- Form$2.Field,
12383
- {
12384
- control: form.control,
12385
- name: "address_1",
12386
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12387
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12388
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12389
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12390
- ] })
12391
- }
12392
- ),
12393
- /* @__PURE__ */ jsxRuntime.jsx(
12394
- Form$2.Field,
12433
+ CustomerField,
12395
12434
  {
12396
12435
  control: form.control,
12397
- name: "address_2",
12398
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12399
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12400
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12401
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12402
- ] })
12403
- }
12404
- ),
12405
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12406
- /* @__PURE__ */ jsxRuntime.jsx(
12407
- Form$2.Field,
12408
- {
12409
- control: form.control,
12410
- name: "postal_code",
12411
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12412
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12413
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12414
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12415
- ] })
12416
- }
12417
- ),
12418
- /* @__PURE__ */ jsxRuntime.jsx(
12419
- Form$2.Field,
12420
- {
12421
- control: form.control,
12422
- name: "city",
12423
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12424
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12425
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12426
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12427
- ] })
12428
- }
12429
- )
12430
- ] }),
12431
- /* @__PURE__ */ jsxRuntime.jsx(
12432
- Form$2.Field,
12433
- {
12434
- control: form.control,
12435
- name: "province",
12436
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12437
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12438
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12439
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12440
- ] })
12441
- }
12442
- ),
12443
- /* @__PURE__ */ jsxRuntime.jsx(
12444
- Form$2.Field,
12445
- {
12446
- control: form.control,
12447
- name: "phone",
12448
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12450
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12451
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12452
- ] })
12453
- }
12454
- )
12455
- ] }) }),
12456
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12457
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12458
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12459
- ] }) })
12460
- ]
12461
- }
12462
- ) });
12463
- };
12464
- const schema$2 = addressSchema;
12465
- const SalesChannel = () => {
12466
- const { id } = reactRouterDom.useParams();
12467
- const { draft_order, isPending, isError, error } = useDraftOrder(
12468
- id,
12469
- {
12470
- fields: "+sales_channel_id"
12471
- },
12472
- {
12473
- enabled: !!id
12474
- }
12475
- );
12476
- if (isError) {
12477
- throw error;
12478
- }
12479
- const ISrEADY = !!draft_order && !isPending;
12480
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12481
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12482
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12483
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12484
- ] }),
12485
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12486
- ] });
12487
- };
12488
- const SalesChannelForm = ({ order }) => {
12489
- const form = reactHookForm.useForm({
12490
- defaultValues: {
12491
- sales_channel_id: order.sales_channel_id || ""
12492
- },
12493
- resolver: zod.zodResolver(schema$1)
12494
- });
12495
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12496
- const { handleSuccess } = useRouteModal();
12497
- const onSubmit = form.handleSubmit(async (data) => {
12498
- await mutateAsync(
12499
- {
12500
- sales_channel_id: data.sales_channel_id
12501
- },
12502
- {
12503
- onSuccess: () => {
12504
- ui.toast.success("Sales channel updated");
12505
- handleSuccess();
12506
- },
12507
- onError: (error) => {
12508
- ui.toast.error(error.message);
12509
- }
12510
- }
12511
- );
12512
- });
12513
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12514
- KeyboundForm,
12515
- {
12516
- className: "flex flex-1 flex-col overflow-hidden",
12517
- onSubmit,
12518
- children: [
12519
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12520
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12521
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12522
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12523
- ] }) })
12524
- ]
12525
- }
12526
- ) });
12527
- };
12528
- const SalesChannelField = ({ control, order }) => {
12529
- const salesChannels = useComboboxData({
12530
- queryFn: async (params) => {
12531
- return await sdk.admin.salesChannel.list(params);
12532
- },
12533
- queryKey: ["sales-channels"],
12534
- getOptions: (data) => {
12535
- return data.sales_channels.map((salesChannel) => ({
12536
- label: salesChannel.name,
12537
- value: salesChannel.id
12538
- }));
12539
- },
12540
- defaultValue: order.sales_channel_id || void 0
12541
- });
12542
- return /* @__PURE__ */ jsxRuntime.jsx(
12543
- Form$2.Field,
12544
- {
12545
- control,
12546
- name: "sales_channel_id",
12547
- render: ({ field }) => {
12548
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12549
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12550
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12551
- Combobox,
12552
- {
12553
- options: salesChannels.options,
12554
- fetchNextPage: salesChannels.fetchNextPage,
12555
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12556
- searchValue: salesChannels.searchValue,
12557
- onSearchValueChange: salesChannels.onSearchValueChange,
12558
- placeholder: "Select sales channel",
12559
- ...field
12560
- }
12561
- ) }),
12562
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12563
- ] });
12564
- }
12565
- }
12566
- );
12567
- };
12568
- const schema$1 = objectType({
12569
- sales_channel_id: stringType().min(1)
12570
- });
12571
- const TransferOwnership = () => {
12572
- const { id } = reactRouterDom.useParams();
12573
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12574
- fields: "id,customer_id,customer.*"
12575
- });
12576
- if (isError) {
12577
- throw error;
12578
- }
12579
- const isReady = !isPending && !!draft_order;
12580
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12581
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12582
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12583
- /* @__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" }) })
12584
- ] }),
12585
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12586
- ] });
12587
- };
12588
- const TransferOwnershipForm = ({ order }) => {
12589
- var _a, _b;
12590
- const form = reactHookForm.useForm({
12591
- defaultValues: {
12592
- customer_id: order.customer_id || ""
12593
- },
12594
- resolver: zod.zodResolver(schema)
12595
- });
12596
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12597
- const { handleSuccess } = useRouteModal();
12598
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12599
- const currentCustomer = order.customer ? {
12600
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12601
- value: order.customer.id
12602
- } : null;
12603
- const onSubmit = form.handleSubmit(async (data) => {
12604
- await mutateAsync(
12605
- { customer_id: data.customer_id },
12606
- {
12607
- onSuccess: () => {
12608
- ui.toast.success("Customer updated");
12609
- handleSuccess();
12610
- },
12611
- onError: (error) => {
12612
- ui.toast.error(error.message);
12613
- }
12614
- }
12615
- );
12616
- });
12617
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12618
- KeyboundForm,
12619
- {
12620
- className: "flex flex-1 flex-col overflow-hidden",
12621
- onSubmit,
12622
- children: [
12623
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12624
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12625
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12626
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12627
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12628
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12629
- ] }),
12630
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12631
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12632
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12633
- ] })
12634
- ] }),
12635
- /* @__PURE__ */ jsxRuntime.jsx(
12636
- CustomerField,
12637
- {
12638
- control: form.control,
12639
- currentCustomerId: order.customer_id
12436
+ currentCustomerId: order.customer_id
12640
12437
  }
12641
12438
  )
12642
12439
  ] }),
@@ -13041,9 +12838,212 @@ const Illustration = () => {
13041
12838
  }
13042
12839
  );
13043
12840
  };
13044
- const schema = objectType({
12841
+ const schema$1 = objectType({
13045
12842
  customer_id: stringType().min(1)
13046
12843
  });
12844
+ const ShippingAddress = () => {
12845
+ const { id } = reactRouterDom.useParams();
12846
+ const { order, isPending, isError, error } = useOrder(id, {
12847
+ fields: "+shipping_address"
12848
+ });
12849
+ if (isError) {
12850
+ throw error;
12851
+ }
12852
+ const isReady = !isPending && !!order;
12853
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12854
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12855
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12856
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12857
+ ] }),
12858
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12859
+ ] });
12860
+ };
12861
+ const ShippingAddressForm = ({ order }) => {
12862
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12863
+ const form = reactHookForm.useForm({
12864
+ defaultValues: {
12865
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12866
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12867
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12868
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12869
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12870
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12871
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12872
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12873
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12874
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12875
+ },
12876
+ resolver: zod.zodResolver(schema)
12877
+ });
12878
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12879
+ const { handleSuccess } = useRouteModal();
12880
+ const onSubmit = form.handleSubmit(async (data) => {
12881
+ await mutateAsync(
12882
+ {
12883
+ shipping_address: {
12884
+ first_name: data.first_name,
12885
+ last_name: data.last_name,
12886
+ company: data.company,
12887
+ address_1: data.address_1,
12888
+ address_2: data.address_2,
12889
+ city: data.city,
12890
+ province: data.province,
12891
+ country_code: data.country_code,
12892
+ postal_code: data.postal_code,
12893
+ phone: data.phone
12894
+ }
12895
+ },
12896
+ {
12897
+ onSuccess: () => {
12898
+ handleSuccess();
12899
+ },
12900
+ onError: (error) => {
12901
+ ui.toast.error(error.message);
12902
+ }
12903
+ }
12904
+ );
12905
+ });
12906
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12907
+ KeyboundForm,
12908
+ {
12909
+ className: "flex flex-1 flex-col overflow-hidden",
12910
+ onSubmit,
12911
+ children: [
12912
+ /* @__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: [
12913
+ /* @__PURE__ */ jsxRuntime.jsx(
12914
+ Form$2.Field,
12915
+ {
12916
+ control: form.control,
12917
+ name: "country_code",
12918
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12919
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12922
+ ] })
12923
+ }
12924
+ ),
12925
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12926
+ /* @__PURE__ */ jsxRuntime.jsx(
12927
+ Form$2.Field,
12928
+ {
12929
+ control: form.control,
12930
+ name: "first_name",
12931
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
+ ] })
12936
+ }
12937
+ ),
12938
+ /* @__PURE__ */ jsxRuntime.jsx(
12939
+ Form$2.Field,
12940
+ {
12941
+ control: form.control,
12942
+ name: "last_name",
12943
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12944
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12947
+ ] })
12948
+ }
12949
+ )
12950
+ ] }),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(
12952
+ Form$2.Field,
12953
+ {
12954
+ control: form.control,
12955
+ name: "company",
12956
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
+ ] })
12961
+ }
12962
+ ),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(
12964
+ Form$2.Field,
12965
+ {
12966
+ control: form.control,
12967
+ name: "address_1",
12968
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
+ ] })
12973
+ }
12974
+ ),
12975
+ /* @__PURE__ */ jsxRuntime.jsx(
12976
+ Form$2.Field,
12977
+ {
12978
+ control: form.control,
12979
+ name: "address_2",
12980
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12981
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12984
+ ] })
12985
+ }
12986
+ ),
12987
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12988
+ /* @__PURE__ */ jsxRuntime.jsx(
12989
+ Form$2.Field,
12990
+ {
12991
+ control: form.control,
12992
+ name: "postal_code",
12993
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
+ ] })
12998
+ }
12999
+ ),
13000
+ /* @__PURE__ */ jsxRuntime.jsx(
13001
+ Form$2.Field,
13002
+ {
13003
+ control: form.control,
13004
+ name: "city",
13005
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13006
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13009
+ ] })
13010
+ }
13011
+ )
13012
+ ] }),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(
13014
+ Form$2.Field,
13015
+ {
13016
+ control: form.control,
13017
+ name: "province",
13018
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
+ ] })
13023
+ }
13024
+ ),
13025
+ /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Form$2.Field,
13027
+ {
13028
+ control: form.control,
13029
+ name: "phone",
13030
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13034
+ ] })
13035
+ }
13036
+ )
13037
+ ] }) }),
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13040
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13041
+ ] }) })
13042
+ ]
13043
+ }
13044
+ ) });
13045
+ };
13046
+ const schema = addressSchema;
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
13049
13049
  routes: [
@@ -13088,21 +13088,21 @@ const routeModule = {
13088
13088
  Component: Promotions,
13089
13089
  path: "/draft-orders/:id/promotions"
13090
13090
  },
13091
- {
13092
- Component: Shipping,
13093
- path: "/draft-orders/:id/shipping"
13094
- },
13095
- {
13096
- Component: ShippingAddress,
13097
- path: "/draft-orders/:id/shipping-address"
13098
- },
13099
13091
  {
13100
13092
  Component: SalesChannel,
13101
13093
  path: "/draft-orders/:id/sales-channel"
13102
13094
  },
13095
+ {
13096
+ Component: Shipping,
13097
+ path: "/draft-orders/:id/shipping"
13098
+ },
13103
13099
  {
13104
13100
  Component: TransferOwnership,
13105
13101
  path: "/draft-orders/:id/transfer-ownership"
13102
+ },
13103
+ {
13104
+ Component: ShippingAddress,
13105
+ path: "/draft-orders/:id/shipping-address"
13106
13106
  }
13107
13107
  ]
13108
13108
  }