@medusajs/draft-order 2.11.3-preview-20251103120146 → 2.12.0-preview-20251103150145

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.
@@ -11445,6 +11445,315 @@ 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
+ const ShippingAddress = () => {
11555
+ const { id } = useParams();
11556
+ const { order, isPending, isError, error } = useOrder(id, {
11557
+ fields: "+shipping_address"
11558
+ });
11559
+ if (isError) {
11560
+ throw error;
11561
+ }
11562
+ const isReady = !isPending && !!order;
11563
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11564
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11565
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11566
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11567
+ ] }),
11568
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11569
+ ] });
11570
+ };
11571
+ const ShippingAddressForm = ({ order }) => {
11572
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11573
+ const form = useForm({
11574
+ defaultValues: {
11575
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11576
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11577
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11578
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11579
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11580
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11581
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11582
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11583
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11584
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11585
+ },
11586
+ resolver: zodResolver(schema$1)
11587
+ });
11588
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11589
+ const { handleSuccess } = useRouteModal();
11590
+ const onSubmit = form.handleSubmit(async (data) => {
11591
+ await mutateAsync(
11592
+ {
11593
+ shipping_address: {
11594
+ first_name: data.first_name,
11595
+ last_name: data.last_name,
11596
+ company: data.company,
11597
+ address_1: data.address_1,
11598
+ address_2: data.address_2,
11599
+ city: data.city,
11600
+ province: data.province,
11601
+ country_code: data.country_code,
11602
+ postal_code: data.postal_code,
11603
+ phone: data.phone
11604
+ }
11605
+ },
11606
+ {
11607
+ onSuccess: () => {
11608
+ handleSuccess();
11609
+ },
11610
+ onError: (error) => {
11611
+ toast.error(error.message);
11612
+ }
11613
+ }
11614
+ );
11615
+ });
11616
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11617
+ KeyboundForm,
11618
+ {
11619
+ className: "flex flex-1 flex-col overflow-hidden",
11620
+ onSubmit,
11621
+ children: [
11622
+ /* @__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: [
11623
+ /* @__PURE__ */ jsx(
11624
+ Form$2.Field,
11625
+ {
11626
+ control: form.control,
11627
+ name: "country_code",
11628
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11629
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11630
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11631
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11632
+ ] })
11633
+ }
11634
+ ),
11635
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11636
+ /* @__PURE__ */ jsx(
11637
+ Form$2.Field,
11638
+ {
11639
+ control: form.control,
11640
+ name: "first_name",
11641
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11642
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11643
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11644
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11645
+ ] })
11646
+ }
11647
+ ),
11648
+ /* @__PURE__ */ jsx(
11649
+ Form$2.Field,
11650
+ {
11651
+ control: form.control,
11652
+ name: "last_name",
11653
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11654
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11655
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11656
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11657
+ ] })
11658
+ }
11659
+ )
11660
+ ] }),
11661
+ /* @__PURE__ */ jsx(
11662
+ Form$2.Field,
11663
+ {
11664
+ control: form.control,
11665
+ name: "company",
11666
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11667
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11668
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11669
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11670
+ ] })
11671
+ }
11672
+ ),
11673
+ /* @__PURE__ */ jsx(
11674
+ Form$2.Field,
11675
+ {
11676
+ control: form.control,
11677
+ name: "address_1",
11678
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11679
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11680
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11681
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11682
+ ] })
11683
+ }
11684
+ ),
11685
+ /* @__PURE__ */ jsx(
11686
+ Form$2.Field,
11687
+ {
11688
+ control: form.control,
11689
+ name: "address_2",
11690
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11691
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11692
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11693
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11694
+ ] })
11695
+ }
11696
+ ),
11697
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11698
+ /* @__PURE__ */ jsx(
11699
+ Form$2.Field,
11700
+ {
11701
+ control: form.control,
11702
+ name: "postal_code",
11703
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11704
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11705
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11706
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11707
+ ] })
11708
+ }
11709
+ ),
11710
+ /* @__PURE__ */ jsx(
11711
+ Form$2.Field,
11712
+ {
11713
+ control: form.control,
11714
+ name: "city",
11715
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11716
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11717
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11718
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11719
+ ] })
11720
+ }
11721
+ )
11722
+ ] }),
11723
+ /* @__PURE__ */ jsx(
11724
+ Form$2.Field,
11725
+ {
11726
+ control: form.control,
11727
+ name: "province",
11728
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11729
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11730
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11731
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11732
+ ] })
11733
+ }
11734
+ ),
11735
+ /* @__PURE__ */ jsx(
11736
+ Form$2.Field,
11737
+ {
11738
+ control: form.control,
11739
+ name: "phone",
11740
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11741
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11742
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11743
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11744
+ ] })
11745
+ }
11746
+ )
11747
+ ] }) }),
11748
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11749
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11750
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11751
+ ] }) })
11752
+ ]
11753
+ }
11754
+ ) });
11755
+ };
11756
+ const schema$1 = addressSchema;
11448
11757
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11449
11758
  const Shipping = () => {
11450
11759
  var _a;
@@ -12195,266 +12504,63 @@ const ShippingOptionField = ({
12195
12504
  render: ({ field }) => {
12196
12505
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12197
12506
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12198
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12199
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12200
- ] }),
12201
- /* @__PURE__ */ jsx(
12202
- ConditionalTooltip,
12203
- {
12204
- content: tooltipContent,
12205
- showTooltip: !locationId || !shippingProfileId,
12206
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12207
- Combobox,
12208
- {
12209
- options: shippingOptions.options,
12210
- fetchNextPage: shippingOptions.fetchNextPage,
12211
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12212
- searchValue: shippingOptions.searchValue,
12213
- onSearchValueChange: shippingOptions.onSearchValueChange,
12214
- placeholder: "Select shipping option",
12215
- ...field,
12216
- disabled: !locationId || !shippingProfileId
12217
- }
12218
- ) }) })
12219
- }
12220
- )
12221
- ] }) });
12222
- }
12223
- }
12224
- );
12225
- };
12226
- const CustomAmountField = ({
12227
- control,
12228
- currencyCode
12229
- }) => {
12230
- return /* @__PURE__ */ jsx(
12231
- Form$2.Field,
12232
- {
12233
- control,
12234
- name: "custom_amount",
12235
- render: ({ field: { onChange, ...field } }) => {
12236
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12237
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12238
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12239
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12240
- ] }),
12241
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12242
- CurrencyInput,
12243
- {
12244
- ...field,
12245
- onValueChange: (value) => onChange(value),
12246
- symbol: getNativeSymbol(currencyCode),
12247
- code: currencyCode
12248
- }
12249
- ) })
12250
- ] });
12251
- }
12252
- }
12253
- );
12254
- };
12255
- const ShippingAddress = () => {
12256
- const { id } = useParams();
12257
- const { order, isPending, isError, error } = useOrder(id, {
12258
- fields: "+shipping_address"
12259
- });
12260
- if (isError) {
12261
- throw error;
12262
- }
12263
- const isReady = !isPending && !!order;
12264
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12265
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
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" }) })
12268
- ] }),
12269
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12270
- ] });
12271
- };
12272
- const ShippingAddressForm = ({ order }) => {
12273
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12274
- const form = useForm({
12275
- defaultValues: {
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) ?? ""
12286
- },
12287
- resolver: zodResolver(schema$2)
12288
- });
12289
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12290
- const { handleSuccess } = useRouteModal();
12291
- const onSubmit = form.handleSubmit(async (data) => {
12292
- await mutateAsync(
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
- },
12307
- {
12308
- onSuccess: () => {
12309
- handleSuccess();
12310
- },
12311
- onError: (error) => {
12312
- toast.error(error.message);
12313
- }
12314
- }
12315
- );
12316
- });
12317
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12318
- KeyboundForm,
12319
- {
12320
- className: "flex flex-1 flex-col overflow-hidden",
12321
- onSubmit,
12322
- children: [
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: [
12324
- /* @__PURE__ */ jsx(
12325
- Form$2.Field,
12326
- {
12327
- control: form.control,
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
- ] })
12334
- }
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
- )
12507
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12508
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12361
12509
  ] }),
12362
12510
  /* @__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,
12511
+ ConditionalTooltip,
12388
12512
  {
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
- ] })
12513
+ content: tooltipContent,
12514
+ showTooltip: !locationId || !shippingProfileId,
12515
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12516
+ Combobox,
12517
+ {
12518
+ options: shippingOptions.options,
12519
+ fetchNextPage: shippingOptions.fetchNextPage,
12520
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12521
+ searchValue: shippingOptions.searchValue,
12522
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12523
+ placeholder: "Select shipping option",
12524
+ ...field,
12525
+ disabled: !locationId || !shippingProfileId
12526
+ }
12527
+ ) }) })
12396
12528
  }
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
- )
12529
+ )
12530
+ ] }) });
12531
+ }
12532
+ }
12533
+ );
12534
+ };
12535
+ const CustomAmountField = ({
12536
+ control,
12537
+ currencyCode
12538
+ }) => {
12539
+ return /* @__PURE__ */ jsx(
12540
+ Form$2.Field,
12541
+ {
12542
+ control,
12543
+ name: "custom_amount",
12544
+ render: ({ field: { onChange, ...field } }) => {
12545
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12546
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12547
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12548
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12423
12549
  ] }),
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,
12550
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12551
+ CurrencyInput,
12438
12552
  {
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
- ] })
12553
+ ...field,
12554
+ onValueChange: (value) => onChange(value),
12555
+ symbol: getNativeSymbol(currencyCode),
12556
+ code: currencyCode
12446
12557
  }
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
- ]
12558
+ ) })
12559
+ ] });
12560
+ }
12454
12561
  }
12455
- ) });
12562
+ );
12456
12563
  };
12457
- const schema$2 = addressSchema;
12458
12564
  const TransferOwnership = () => {
12459
12565
  const { id } = useParams();
12460
12566
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12478,7 +12584,7 @@ const TransferOwnershipForm = ({ order }) => {
12478
12584
  defaultValues: {
12479
12585
  customer_id: order.customer_id || ""
12480
12586
  },
12481
- resolver: zodResolver(schema$1)
12587
+ resolver: zodResolver(schema)
12482
12588
  });
12483
12589
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12484
12590
  const { handleSuccess } = useRouteModal();
@@ -12928,114 +13034,8 @@ const Illustration = () => {
12928
13034
  }
12929
13035
  );
12930
13036
  };
12931
- const schema$1 = objectType({
12932
- customer_id: stringType().min(1)
12933
- });
12934
- const SalesChannel = () => {
12935
- const { id } = useParams();
12936
- const { draft_order, isPending, isError, error } = useDraftOrder(
12937
- id,
12938
- {
12939
- fields: "+sales_channel_id"
12940
- },
12941
- {
12942
- enabled: !!id
12943
- }
12944
- );
12945
- if (isError) {
12946
- throw error;
12947
- }
12948
- const ISrEADY = !!draft_order && !isPending;
12949
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12950
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12951
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12952
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12953
- ] }),
12954
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12955
- ] });
12956
- };
12957
- const SalesChannelForm = ({ order }) => {
12958
- const form = useForm({
12959
- defaultValues: {
12960
- sales_channel_id: order.sales_channel_id || ""
12961
- },
12962
- resolver: zodResolver(schema)
12963
- });
12964
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12965
- const { handleSuccess } = useRouteModal();
12966
- const onSubmit = form.handleSubmit(async (data) => {
12967
- await mutateAsync(
12968
- {
12969
- sales_channel_id: data.sales_channel_id
12970
- },
12971
- {
12972
- onSuccess: () => {
12973
- toast.success("Sales channel updated");
12974
- handleSuccess();
12975
- },
12976
- onError: (error) => {
12977
- toast.error(error.message);
12978
- }
12979
- }
12980
- );
12981
- });
12982
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12983
- KeyboundForm,
12984
- {
12985
- className: "flex flex-1 flex-col overflow-hidden",
12986
- onSubmit,
12987
- children: [
12988
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12989
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12990
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12991
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12992
- ] }) })
12993
- ]
12994
- }
12995
- ) });
12996
- };
12997
- const SalesChannelField = ({ control, order }) => {
12998
- const salesChannels = useComboboxData({
12999
- queryFn: async (params) => {
13000
- return await sdk.admin.salesChannel.list(params);
13001
- },
13002
- queryKey: ["sales-channels"],
13003
- getOptions: (data) => {
13004
- return data.sales_channels.map((salesChannel) => ({
13005
- label: salesChannel.name,
13006
- value: salesChannel.id
13007
- }));
13008
- },
13009
- defaultValue: order.sales_channel_id || void 0
13010
- });
13011
- return /* @__PURE__ */ jsx(
13012
- Form$2.Field,
13013
- {
13014
- control,
13015
- name: "sales_channel_id",
13016
- render: ({ field }) => {
13017
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13018
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13019
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13020
- Combobox,
13021
- {
13022
- options: salesChannels.options,
13023
- fetchNextPage: salesChannels.fetchNextPage,
13024
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13025
- searchValue: salesChannels.searchValue,
13026
- onSearchValueChange: salesChannels.onSearchValueChange,
13027
- placeholder: "Select sales channel",
13028
- ...field
13029
- }
13030
- ) }),
13031
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13032
- ] });
13033
- }
13034
- }
13035
- );
13036
- };
13037
13037
  const schema = objectType({
13038
- sales_channel_id: stringType().min(1)
13038
+ customer_id: stringType().min(1)
13039
13039
  });
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
@@ -13082,20 +13082,20 @@ const routeModule = {
13082
13082
  path: "/draft-orders/:id/promotions"
13083
13083
  },
13084
13084
  {
13085
- Component: Shipping,
13086
- path: "/draft-orders/:id/shipping"
13085
+ Component: SalesChannel,
13086
+ path: "/draft-orders/:id/sales-channel"
13087
13087
  },
13088
13088
  {
13089
13089
  Component: ShippingAddress,
13090
13090
  path: "/draft-orders/:id/shipping-address"
13091
13091
  },
13092
13092
  {
13093
- Component: TransferOwnership,
13094
- path: "/draft-orders/:id/transfer-ownership"
13093
+ Component: Shipping,
13094
+ path: "/draft-orders/:id/shipping"
13095
13095
  },
13096
13096
  {
13097
- Component: SalesChannel,
13098
- path: "/draft-orders/:id/sales-channel"
13097
+ Component: TransferOwnership,
13098
+ path: "/draft-orders/:id/transfer-ownership"
13099
13099
  }
13100
13100
  ]
13101
13101
  }