@medusajs/draft-order 2.10.4-preview-20251007060201 → 2.10.4-preview-20251008000316

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.
@@ -9763,95 +9763,6 @@ const BillingAddressForm = ({ order }) => {
9763
9763
  ) });
9764
9764
  };
9765
9765
  const schema$5 = addressSchema;
9766
- const CustomItems = () => {
9767
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9769
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9770
- ] });
9771
- };
9772
- const CustomItemsForm = () => {
9773
- const form = reactHookForm.useForm({
9774
- resolver: zod.zodResolver(schema$4)
9775
- });
9776
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9778
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9779
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9780
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9781
- ] }) })
9782
- ] }) });
9783
- };
9784
- const schema$4 = objectType({
9785
- email: stringType().email()
9786
- });
9787
- const Email = () => {
9788
- const { id } = reactRouterDom.useParams();
9789
- const { order, isPending, isError, error } = useOrder(id, {
9790
- fields: "+email"
9791
- });
9792
- if (isError) {
9793
- throw error;
9794
- }
9795
- const isReady = !isPending && !!order;
9796
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9797
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9798
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9799
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9800
- ] }),
9801
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9802
- ] });
9803
- };
9804
- const EmailForm = ({ order }) => {
9805
- const form = reactHookForm.useForm({
9806
- defaultValues: {
9807
- email: order.email ?? ""
9808
- },
9809
- resolver: zod.zodResolver(schema$3)
9810
- });
9811
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
- const { handleSuccess } = useRouteModal();
9813
- const onSubmit = form.handleSubmit(async (data) => {
9814
- await mutateAsync(
9815
- { email: data.email },
9816
- {
9817
- onSuccess: () => {
9818
- handleSuccess();
9819
- },
9820
- onError: (error) => {
9821
- ui.toast.error(error.message);
9822
- }
9823
- }
9824
- );
9825
- });
9826
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9827
- KeyboundForm,
9828
- {
9829
- className: "flex flex-1 flex-col overflow-hidden",
9830
- onSubmit,
9831
- children: [
9832
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9833
- Form$2.Field,
9834
- {
9835
- control: form.control,
9836
- name: "email",
9837
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9840
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9841
- ] })
9842
- }
9843
- ) }),
9844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9846
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
- ] }) })
9848
- ]
9849
- }
9850
- ) });
9851
- };
9852
- const schema$3 = objectType({
9853
- email: stringType().email()
9854
- });
9855
9766
  const NumberInput = React.forwardRef(
9856
9767
  ({
9857
9768
  value,
@@ -11453,1016 +11364,1122 @@ function getPromotionIds(items, shippingMethods) {
11453
11364
  }
11454
11365
  return Array.from(promotionIds);
11455
11366
  }
11456
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11457
- const Shipping = () => {
11458
- var _a;
11367
+ const SalesChannel = () => {
11459
11368
  const { id } = reactRouterDom.useParams();
11460
- const { order, isPending, isError, error } = useOrder(id, {
11461
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11462
- });
11463
- const {
11464
- order: preview,
11465
- isPending: isPreviewPending,
11466
- isError: isPreviewError,
11467
- error: previewError
11468
- } = useOrderPreview(id);
11469
- useInitiateOrderEdit({ preview });
11470
- const { onCancel } = useCancelOrderEdit({ preview });
11471
- if (isError) {
11472
- throw error;
11473
- }
11474
- if (isPreviewError) {
11475
- throw previewError;
11476
- }
11477
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11478
- const isReady = preview && !isPreviewPending && order && !isPending;
11479
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11480
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11481
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11482
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11483
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11484
- ] }) }) }),
11485
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11486
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11487
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11488
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11489
- ] }) });
11490
- };
11491
- const ShippingForm = ({ preview, order }) => {
11492
- var _a;
11493
- const { setIsOpen } = useStackedModal();
11494
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11495
- const [data, setData] = React.useState(null);
11496
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11497
- const { shipping_options } = useShippingOptions(
11369
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11370
+ id,
11498
11371
  {
11499
- id: appliedShippingOptionIds,
11500
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11372
+ fields: "+sales_channel_id"
11501
11373
  },
11502
11374
  {
11503
- enabled: appliedShippingOptionIds.length > 0
11375
+ enabled: !!id
11504
11376
  }
11505
11377
  );
11506
- const uniqueShippingProfiles = React.useMemo(() => {
11507
- const profiles = /* @__PURE__ */ new Map();
11508
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11509
- profiles.set(profile.id, profile);
11510
- });
11511
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11512
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11513
- });
11514
- return Array.from(profiles.values());
11515
- }, [order.items, shipping_options]);
11378
+ if (isError) {
11379
+ throw error;
11380
+ }
11381
+ const ISrEADY = !!draft_order && !isPending;
11382
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11383
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11384
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11385
+ /* @__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" }) })
11386
+ ] }),
11387
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11388
+ ] });
11389
+ };
11390
+ const SalesChannelForm = ({ order }) => {
11391
+ const form = reactHookForm.useForm({
11392
+ defaultValues: {
11393
+ sales_channel_id: order.sales_channel_id || ""
11394
+ },
11395
+ resolver: zod.zodResolver(schema$4)
11396
+ });
11397
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11516
11398
  const { handleSuccess } = useRouteModal();
11517
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11518
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11519
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11520
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11521
- const onSubmit = async () => {
11522
- setIsSubmitting(true);
11523
- let requestSucceeded = false;
11524
- await requestOrderEdit(void 0, {
11525
- onError: (e) => {
11526
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11527
- },
11528
- onSuccess: () => {
11529
- requestSucceeded = true;
11530
- }
11531
- });
11532
- if (!requestSucceeded) {
11533
- setIsSubmitting(false);
11534
- return;
11535
- }
11536
- await confirmOrderEdit(void 0, {
11537
- onError: (e) => {
11538
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11539
- },
11540
- onSuccess: () => {
11541
- handleSuccess();
11399
+ const onSubmit = form.handleSubmit(async (data) => {
11400
+ await mutateAsync(
11401
+ {
11402
+ sales_channel_id: data.sales_channel_id
11542
11403
  },
11543
- onSettled: () => {
11544
- setIsSubmitting(false);
11545
- }
11546
- });
11547
- };
11548
- const onKeydown = React.useCallback(
11549
- (e) => {
11550
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11551
- if (data || isSubmitting) {
11552
- return;
11404
+ {
11405
+ onSuccess: () => {
11406
+ ui.toast.success("Sales channel updated");
11407
+ handleSuccess();
11408
+ },
11409
+ onError: (error) => {
11410
+ ui.toast.error(error.message);
11553
11411
  }
11554
- onSubmit();
11555
11412
  }
11413
+ );
11414
+ });
11415
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11416
+ KeyboundForm,
11417
+ {
11418
+ className: "flex flex-1 flex-col overflow-hidden",
11419
+ onSubmit,
11420
+ children: [
11421
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11422
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11423
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11424
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11425
+ ] }) })
11426
+ ]
11427
+ }
11428
+ ) });
11429
+ };
11430
+ const SalesChannelField = ({ control, order }) => {
11431
+ const salesChannels = useComboboxData({
11432
+ queryFn: async (params) => {
11433
+ return await sdk.admin.salesChannel.list(params);
11556
11434
  },
11557
- [data, isSubmitting, onSubmit]
11558
- );
11559
- React.useEffect(() => {
11560
- document.addEventListener("keydown", onKeydown);
11561
- return () => {
11562
- document.removeEventListener("keydown", onKeydown);
11563
- };
11564
- }, [onKeydown]);
11565
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11566
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11567
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11568
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11569
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11570
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11571
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11572
- ] }),
11573
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11574
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11575
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11576
- /* @__PURE__ */ jsxRuntime.jsx(
11577
- ui.Text,
11435
+ queryKey: ["sales-channels"],
11436
+ getOptions: (data) => {
11437
+ return data.sales_channels.map((salesChannel) => ({
11438
+ label: salesChannel.name,
11439
+ value: salesChannel.id
11440
+ }));
11441
+ },
11442
+ defaultValue: order.sales_channel_id || void 0
11443
+ });
11444
+ return /* @__PURE__ */ jsxRuntime.jsx(
11445
+ Form$2.Field,
11446
+ {
11447
+ control,
11448
+ name: "sales_channel_id",
11449
+ render: ({ field }) => {
11450
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11451
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11452
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11453
+ Combobox,
11454
+ {
11455
+ options: salesChannels.options,
11456
+ fetchNextPage: salesChannels.fetchNextPage,
11457
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11458
+ searchValue: salesChannels.searchValue,
11459
+ onSearchValueChange: salesChannels.onSearchValueChange,
11460
+ placeholder: "Select sales channel",
11461
+ ...field
11462
+ }
11463
+ ) }),
11464
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11465
+ ] });
11466
+ }
11467
+ }
11468
+ );
11469
+ };
11470
+ const schema$4 = objectType({
11471
+ sales_channel_id: stringType().min(1)
11472
+ });
11473
+ const ShippingAddress = () => {
11474
+ const { id } = reactRouterDom.useParams();
11475
+ const { order, isPending, isError, error } = useOrder(id, {
11476
+ fields: "+shipping_address"
11477
+ });
11478
+ if (isError) {
11479
+ throw error;
11480
+ }
11481
+ const isReady = !isPending && !!order;
11482
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11483
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11484
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11485
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11486
+ ] }),
11487
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11488
+ ] });
11489
+ };
11490
+ const ShippingAddressForm = ({ order }) => {
11491
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11492
+ const form = reactHookForm.useForm({
11493
+ defaultValues: {
11494
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11495
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11496
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11497
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11498
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11499
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11500
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11501
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11502
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11503
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11504
+ },
11505
+ resolver: zod.zodResolver(schema$3)
11506
+ });
11507
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11508
+ const { handleSuccess } = useRouteModal();
11509
+ const onSubmit = form.handleSubmit(async (data) => {
11510
+ await mutateAsync(
11511
+ {
11512
+ shipping_address: {
11513
+ first_name: data.first_name,
11514
+ last_name: data.last_name,
11515
+ company: data.company,
11516
+ address_1: data.address_1,
11517
+ address_2: data.address_2,
11518
+ city: data.city,
11519
+ province: data.province,
11520
+ country_code: data.country_code,
11521
+ postal_code: data.postal_code,
11522
+ phone: data.phone
11523
+ }
11524
+ },
11525
+ {
11526
+ onSuccess: () => {
11527
+ handleSuccess();
11528
+ },
11529
+ onError: (error) => {
11530
+ ui.toast.error(error.message);
11531
+ }
11532
+ }
11533
+ );
11534
+ });
11535
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11536
+ KeyboundForm,
11537
+ {
11538
+ className: "flex flex-1 flex-col overflow-hidden",
11539
+ onSubmit,
11540
+ children: [
11541
+ /* @__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: [
11542
+ /* @__PURE__ */ jsxRuntime.jsx(
11543
+ Form$2.Field,
11544
+ {
11545
+ control: form.control,
11546
+ name: "country_code",
11547
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11548
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11549
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11550
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11551
+ ] })
11552
+ }
11553
+ ),
11554
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11555
+ /* @__PURE__ */ jsxRuntime.jsx(
11556
+ Form$2.Field,
11578
11557
  {
11579
- size: "xsmall",
11580
- weight: "plus",
11581
- className: "text-ui-fg-muted",
11582
- children: "Shipping profile"
11558
+ control: form.control,
11559
+ name: "first_name",
11560
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11561
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11562
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11563
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11564
+ ] })
11583
11565
  }
11584
11566
  ),
11585
11567
  /* @__PURE__ */ jsxRuntime.jsx(
11586
- ui.Text,
11568
+ Form$2.Field,
11587
11569
  {
11588
- size: "xsmall",
11589
- weight: "plus",
11590
- className: "text-ui-fg-muted",
11591
- children: "Action"
11570
+ control: form.control,
11571
+ name: "last_name",
11572
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11573
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11574
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11575
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11576
+ ] })
11592
11577
  }
11593
11578
  )
11594
11579
  ] }),
11595
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11596
- var _a2, _b, _c, _d, _e, _f, _g;
11597
- const items = getItemsWithShippingProfile(
11598
- profile.id,
11599
- order.items
11600
- );
11601
- const hasItems = items.length > 0;
11602
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11603
- (option) => option.shipping_profile_id === profile.id
11604
- );
11605
- const shippingMethod = preview.shipping_methods.find(
11606
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11607
- );
11608
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11609
- (action) => action.action === "SHIPPING_ADD"
11610
- );
11611
- return /* @__PURE__ */ jsxRuntime.jsxs(
11612
- radixUi.Accordion.Item,
11580
+ /* @__PURE__ */ jsxRuntime.jsx(
11581
+ Form$2.Field,
11582
+ {
11583
+ control: form.control,
11584
+ name: "company",
11585
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11586
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11587
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11588
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11589
+ ] })
11590
+ }
11591
+ ),
11592
+ /* @__PURE__ */ jsxRuntime.jsx(
11593
+ Form$2.Field,
11594
+ {
11595
+ control: form.control,
11596
+ name: "address_1",
11597
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11598
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11599
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11600
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11601
+ ] })
11602
+ }
11603
+ ),
11604
+ /* @__PURE__ */ jsxRuntime.jsx(
11605
+ Form$2.Field,
11606
+ {
11607
+ control: form.control,
11608
+ name: "address_2",
11609
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11610
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11611
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11612
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11613
+ ] })
11614
+ }
11615
+ ),
11616
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11617
+ /* @__PURE__ */ jsxRuntime.jsx(
11618
+ Form$2.Field,
11613
11619
  {
11614
- value: profile.id,
11615
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11616
- children: [
11617
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11618
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11619
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11620
- ui.IconButton,
11621
- {
11622
- size: "2xsmall",
11623
- variant: "transparent",
11624
- className: "group/trigger",
11625
- disabled: !hasItems,
11626
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11627
- }
11628
- ) }),
11629
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11630
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11631
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11632
- /* @__PURE__ */ jsxRuntime.jsx(
11633
- ui.Text,
11634
- {
11635
- size: "small",
11636
- weight: "plus",
11637
- leading: "compact",
11638
- children: profile.name
11639
- }
11640
- ),
11641
- /* @__PURE__ */ jsxRuntime.jsxs(
11642
- ui.Text,
11643
- {
11644
- size: "small",
11645
- leading: "compact",
11646
- className: "text-ui-fg-subtle",
11647
- children: [
11648
- items.length,
11649
- " ",
11650
- pluralize(items.length, "items", "item")
11651
- ]
11652
- }
11653
- )
11654
- ] })
11655
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11656
- /* @__PURE__ */ jsxRuntime.jsx(
11657
- ui.Tooltip,
11658
- {
11659
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11660
- var _a3, _b2, _c2;
11661
- return /* @__PURE__ */ jsxRuntime.jsx(
11662
- "li",
11663
- {
11664
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11665
- },
11666
- item.id
11667
- );
11668
- }) }),
11669
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11670
- ui.Badge,
11671
- {
11672
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11673
- size: "xsmall",
11674
- children: [
11675
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11676
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11677
- items.reduce(
11678
- (acc, item) => acc + item.quantity,
11679
- 0
11680
- ),
11681
- "x",
11682
- " ",
11683
- pluralize(items.length, "items", "item")
11684
- ] })
11685
- ]
11686
- }
11687
- )
11688
- }
11689
- ),
11690
- /* @__PURE__ */ jsxRuntime.jsx(
11691
- ui.Tooltip,
11692
- {
11693
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11694
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11695
- ui.Badge,
11696
- {
11697
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11698
- size: "xsmall",
11699
- children: [
11700
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11701
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11702
- ]
11703
- }
11704
- )
11705
- }
11706
- ),
11707
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11708
- ui.Badge,
11709
- {
11710
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11711
- size: "xsmall",
11712
- children: [
11713
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11714
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11715
- ]
11716
- }
11717
- ) })
11718
- ] })
11719
- ] }),
11720
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11721
- ActionMenu,
11722
- {
11723
- groups: [
11724
- {
11725
- actions: [
11726
- hasItems ? {
11727
- label: "Edit shipping option",
11728
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11729
- onClick: () => {
11730
- setIsOpen(
11731
- STACKED_FOCUS_MODAL_ID,
11732
- true
11733
- );
11734
- setData({
11735
- shippingProfileId: profile.id,
11736
- shippingOption,
11737
- shippingMethod
11738
- });
11739
- }
11740
- } : void 0,
11741
- {
11742
- label: "Remove shipping option",
11743
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11744
- onClick: () => {
11745
- if (shippingMethod) {
11746
- if (addShippingMethodAction) {
11747
- removeActionShippingMethod(
11748
- addShippingMethodAction.id
11749
- );
11750
- } else {
11751
- removeShippingMethod(
11752
- shippingMethod.id
11753
- );
11754
- }
11755
- }
11756
- }
11757
- }
11758
- ].filter(Boolean)
11759
- }
11760
- ]
11761
- }
11762
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11763
- StackedModalTrigger,
11764
- {
11765
- shippingProfileId: profile.id,
11766
- shippingOption,
11767
- shippingMethod,
11768
- setData,
11769
- children: "Add shipping option"
11770
- }
11771
- )
11772
- ] }),
11773
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11774
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11775
- items.map((item, idx) => {
11776
- var _a3, _b2, _c2, _d2, _e2;
11777
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11778
- /* @__PURE__ */ jsxRuntime.jsxs(
11779
- "div",
11780
- {
11781
- className: "px-3 flex items-center gap-x-3",
11782
- children: [
11783
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11784
- ui.Divider,
11785
- {
11786
- variant: "dashed",
11787
- orientation: "vertical"
11788
- }
11789
- ) }),
11790
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11791
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11792
- ui.Text,
11793
- {
11794
- size: "small",
11795
- leading: "compact",
11796
- className: "text-ui-fg-subtle",
11797
- children: [
11798
- item.quantity,
11799
- "x"
11800
- ]
11801
- }
11802
- ) }),
11803
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11804
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11805
- /* @__PURE__ */ jsxRuntime.jsxs(
11806
- ui.Text,
11807
- {
11808
- size: "small",
11809
- leading: "compact",
11810
- weight: "plus",
11811
- children: [
11812
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11813
- " (",
11814
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11815
- ")"
11816
- ]
11817
- }
11818
- ),
11819
- /* @__PURE__ */ jsxRuntime.jsx(
11820
- ui.Text,
11821
- {
11822
- size: "small",
11823
- leading: "compact",
11824
- className: "text-ui-fg-subtle",
11825
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11826
- }
11827
- )
11828
- ] })
11829
- ] })
11830
- ]
11831
- },
11832
- item.id
11833
- ),
11834
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11835
- ] }, item.id);
11836
- })
11837
- ] })
11838
- ]
11839
- },
11840
- profile.id
11841
- );
11842
- }) })
11843
- ] }) })
11844
- ] }) }),
11845
- /* @__PURE__ */ jsxRuntime.jsx(
11846
- StackedFocusModal,
11847
- {
11848
- id: STACKED_FOCUS_MODAL_ID,
11849
- onOpenChangeCallback: (open) => {
11850
- if (!open) {
11851
- setData(null);
11852
- }
11853
- return open;
11854
- },
11855
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11856
- }
11857
- )
11858
- ] }),
11859
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11860
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11861
- /* @__PURE__ */ jsxRuntime.jsx(
11862
- ui.Button,
11863
- {
11864
- size: "small",
11865
- type: "button",
11866
- isLoading: isSubmitting,
11867
- onClick: onSubmit,
11868
- children: "Save"
11869
- }
11870
- )
11871
- ] }) })
11872
- ] });
11873
- };
11874
- const StackedModalTrigger = ({
11875
- shippingProfileId,
11876
- shippingOption,
11877
- shippingMethod,
11878
- setData,
11879
- children
11880
- }) => {
11881
- const { setIsOpen, getIsOpen } = useStackedModal();
11882
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11883
- const onToggle = () => {
11884
- if (isOpen) {
11885
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11886
- setData(null);
11887
- } else {
11888
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11889
- setData({
11890
- shippingProfileId,
11891
- shippingOption,
11892
- shippingMethod
11893
- });
11894
- }
11895
- };
11896
- return /* @__PURE__ */ jsxRuntime.jsx(
11897
- ui.Button,
11898
- {
11899
- size: "small",
11900
- variant: "secondary",
11901
- onClick: onToggle,
11902
- className: "text-ui-fg-primary shrink-0",
11903
- children
11904
- }
11905
- );
11906
- };
11907
- const ShippingProfileForm = ({
11908
- data,
11909
- order,
11910
- preview
11911
- }) => {
11912
- var _a, _b, _c, _d, _e, _f;
11913
- const { setIsOpen } = useStackedModal();
11914
- const form = reactHookForm.useForm({
11915
- resolver: zod.zodResolver(shippingMethodSchema),
11916
- defaultValues: {
11917
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
11918
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11919
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11920
- }
11921
- });
11922
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11923
- const {
11924
- mutateAsync: updateShippingMethod,
11925
- isPending: isUpdatingShippingMethod
11926
- } = useDraftOrderUpdateShippingMethod(order.id);
11927
- const onSubmit = form.handleSubmit(async (values) => {
11928
- if (lodash.isEqual(values, form.formState.defaultValues)) {
11929
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11930
- return;
11931
- }
11932
- if (data.shippingMethod) {
11933
- await updateShippingMethod(
11934
- {
11935
- method_id: data.shippingMethod.id,
11936
- shipping_option_id: values.shipping_option_id,
11937
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11938
- },
11939
- {
11940
- onError: (e) => {
11941
- ui.toast.error(e.message);
11942
- },
11943
- onSuccess: () => {
11944
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11945
- }
11946
- }
11947
- );
11948
- return;
11949
- }
11950
- await addShippingMethod(
11951
- {
11952
- shipping_option_id: values.shipping_option_id,
11953
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11954
- },
11955
- {
11956
- onError: (e) => {
11957
- ui.toast.error(e.message);
11958
- },
11959
- onSuccess: () => {
11960
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11961
- }
11962
- }
11963
- );
11964
- });
11965
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11966
- KeyboundForm,
11967
- {
11968
- className: "flex h-full flex-col overflow-hidden",
11969
- onSubmit,
11970
- children: [
11971
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11972
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11973
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11974
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11975
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11620
+ control: form.control,
11621
+ name: "postal_code",
11622
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11623
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11624
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11625
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11626
+ ] })
11627
+ }
11628
+ ),
11629
+ /* @__PURE__ */ jsxRuntime.jsx(
11630
+ Form$2.Field,
11631
+ {
11632
+ control: form.control,
11633
+ name: "city",
11634
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11635
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11636
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11638
+ ] })
11639
+ }
11640
+ )
11976
11641
  ] }),
11977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11978
11642
  /* @__PURE__ */ jsxRuntime.jsx(
11979
- LocationField,
11980
- {
11981
- control: form.control,
11982
- setValue: form.setValue
11983
- }
11984
- ),
11985
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11986
- /* @__PURE__ */ jsxRuntime.jsx(
11987
- ShippingOptionField,
11988
- {
11989
- shippingProfileId: data.shippingProfileId,
11990
- preview,
11991
- control: form.control
11992
- }
11993
- ),
11994
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11995
- /* @__PURE__ */ jsxRuntime.jsx(
11996
- CustomAmountField,
11643
+ Form$2.Field,
11997
11644
  {
11998
11645
  control: form.control,
11999
- currencyCode: order.currency_code
12000
- }
12001
- ),
12002
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12003
- /* @__PURE__ */ jsxRuntime.jsx(
12004
- ItemsPreview,
12005
- {
12006
- order,
12007
- shippingProfileId: data.shippingProfileId
11646
+ name: "province",
11647
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11651
+ ] })
12008
11652
  }
12009
- )
12010
- ] }) }) }),
12011
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12012
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11653
+ ),
12013
11654
  /* @__PURE__ */ jsxRuntime.jsx(
12014
- ui.Button,
11655
+ Form$2.Field,
12015
11656
  {
12016
- size: "small",
12017
- type: "submit",
12018
- isLoading: isPending || isUpdatingShippingMethod,
12019
- children: data.shippingMethod ? "Update" : "Add"
11657
+ control: form.control,
11658
+ name: "phone",
11659
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11660
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11661
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11663
+ ] })
12020
11664
  }
12021
11665
  )
11666
+ ] }) }),
11667
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11668
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11669
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12022
11670
  ] }) })
12023
11671
  ]
12024
11672
  }
12025
- ) }) });
11673
+ ) });
12026
11674
  };
12027
- const shippingMethodSchema = objectType({
12028
- location_id: stringType(),
12029
- shipping_option_id: stringType(),
12030
- custom_amount: unionType([numberType(), stringType()]).optional()
12031
- });
12032
- const ItemsPreview = ({ order, shippingProfileId }) => {
12033
- const matches = order.items.filter(
12034
- (item) => {
12035
- var _a, _b, _c;
12036
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11675
+ const schema$3 = addressSchema;
11676
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11677
+ const Shipping = () => {
11678
+ var _a;
11679
+ const { id } = reactRouterDom.useParams();
11680
+ const { order, isPending, isError, error } = useOrder(id, {
11681
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11682
+ });
11683
+ const {
11684
+ order: preview,
11685
+ isPending: isPreviewPending,
11686
+ isError: isPreviewError,
11687
+ error: previewError
11688
+ } = useOrderPreview(id);
11689
+ useInitiateOrderEdit({ preview });
11690
+ const { onCancel } = useCancelOrderEdit({ preview });
11691
+ if (isError) {
11692
+ throw error;
11693
+ }
11694
+ if (isPreviewError) {
11695
+ throw previewError;
11696
+ }
11697
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11698
+ const isReady = preview && !isPreviewPending && order && !isPending;
11699
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11700
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11701
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11702
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11703
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11704
+ ] }) }) }),
11705
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11706
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11707
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11708
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11709
+ ] }) });
11710
+ };
11711
+ const ShippingForm = ({ preview, order }) => {
11712
+ var _a;
11713
+ const { setIsOpen } = useStackedModal();
11714
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11715
+ const [data, setData] = React.useState(null);
11716
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11717
+ const { shipping_options } = useShippingOptions(
11718
+ {
11719
+ id: appliedShippingOptionIds,
11720
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11721
+ },
11722
+ {
11723
+ enabled: appliedShippingOptionIds.length > 0
12037
11724
  }
12038
11725
  );
12039
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12040
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12041
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12042
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12043
- ] }) }),
12044
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12045
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12046
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12047
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12048
- ] }),
12049
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12050
- "div",
12051
- {
12052
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12053
- children: [
12054
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12055
- /* @__PURE__ */ jsxRuntime.jsx(
12056
- Thumbnail,
12057
- {
12058
- thumbnail: item.thumbnail,
12059
- alt: item.product_title ?? void 0
12060
- }
12061
- ),
12062
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12063
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12064
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12065
- /* @__PURE__ */ jsxRuntime.jsxs(
12066
- ui.Text,
12067
- {
12068
- size: "small",
12069
- leading: "compact",
12070
- className: "text-ui-fg-subtle",
12071
- children: [
12072
- "(",
12073
- item.variant_title,
12074
- ")"
12075
- ]
12076
- }
12077
- )
12078
- ] }),
12079
- /* @__PURE__ */ jsxRuntime.jsx(
12080
- ui.Text,
12081
- {
12082
- size: "small",
12083
- leading: "compact",
12084
- className: "text-ui-fg-subtle",
12085
- children: item.variant_sku
12086
- }
12087
- )
12088
- ] })
12089
- ] }),
12090
- /* @__PURE__ */ jsxRuntime.jsxs(
11726
+ const uniqueShippingProfiles = React.useMemo(() => {
11727
+ const profiles = /* @__PURE__ */ new Map();
11728
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11729
+ profiles.set(profile.id, profile);
11730
+ });
11731
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11732
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11733
+ });
11734
+ return Array.from(profiles.values());
11735
+ }, [order.items, shipping_options]);
11736
+ const { handleSuccess } = useRouteModal();
11737
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11738
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11739
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11740
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11741
+ const onSubmit = async () => {
11742
+ setIsSubmitting(true);
11743
+ let requestSucceeded = false;
11744
+ await requestOrderEdit(void 0, {
11745
+ onError: (e) => {
11746
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11747
+ },
11748
+ onSuccess: () => {
11749
+ requestSucceeded = true;
11750
+ }
11751
+ });
11752
+ if (!requestSucceeded) {
11753
+ setIsSubmitting(false);
11754
+ return;
11755
+ }
11756
+ await confirmOrderEdit(void 0, {
11757
+ onError: (e) => {
11758
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11759
+ },
11760
+ onSuccess: () => {
11761
+ handleSuccess();
11762
+ },
11763
+ onSettled: () => {
11764
+ setIsSubmitting(false);
11765
+ }
11766
+ });
11767
+ };
11768
+ const onKeydown = React.useCallback(
11769
+ (e) => {
11770
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11771
+ if (data || isSubmitting) {
11772
+ return;
11773
+ }
11774
+ onSubmit();
11775
+ }
11776
+ },
11777
+ [data, isSubmitting, onSubmit]
11778
+ );
11779
+ React.useEffect(() => {
11780
+ document.addEventListener("keydown", onKeydown);
11781
+ return () => {
11782
+ document.removeEventListener("keydown", onKeydown);
11783
+ };
11784
+ }, [onKeydown]);
11785
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11786
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11787
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11788
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11789
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11790
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11791
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11792
+ ] }),
11793
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11794
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11795
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11796
+ /* @__PURE__ */ jsxRuntime.jsx(
12091
11797
  ui.Text,
12092
11798
  {
12093
- size: "small",
12094
- leading: "compact",
12095
- className: "text-ui-fg-subtle",
12096
- children: [
12097
- item.quantity,
12098
- "x"
12099
- ]
11799
+ size: "xsmall",
11800
+ weight: "plus",
11801
+ className: "text-ui-fg-muted",
11802
+ children: "Shipping profile"
12100
11803
  }
12101
- )
12102
- ]
12103
- },
12104
- item.id
12105
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12106
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12107
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12108
- 'No items found for "',
12109
- query,
12110
- '".'
12111
- ] })
12112
- ] }) })
12113
- ] })
12114
- ] });
12115
- };
12116
- const LocationField = ({ control, setValue }) => {
12117
- const locations = useComboboxData({
12118
- queryKey: ["locations"],
12119
- queryFn: async (params) => {
12120
- return await sdk.admin.stockLocation.list(params);
12121
- },
12122
- getOptions: (data) => {
12123
- return data.stock_locations.map((location) => ({
12124
- label: location.name,
12125
- value: location.id
12126
- }));
12127
- }
12128
- });
12129
- return /* @__PURE__ */ jsxRuntime.jsx(
12130
- Form$2.Field,
12131
- {
12132
- control,
12133
- name: "location_id",
12134
- render: ({ field: { onChange, ...field } }) => {
12135
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12136
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12137
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12138
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11804
+ ),
11805
+ /* @__PURE__ */ jsxRuntime.jsx(
11806
+ ui.Text,
11807
+ {
11808
+ size: "xsmall",
11809
+ weight: "plus",
11810
+ className: "text-ui-fg-muted",
11811
+ children: "Action"
11812
+ }
11813
+ )
12139
11814
  ] }),
12140
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12141
- Combobox,
12142
- {
12143
- options: locations.options,
12144
- fetchNextPage: locations.fetchNextPage,
12145
- isFetchingNextPage: locations.isFetchingNextPage,
12146
- searchValue: locations.searchValue,
12147
- onSearchValueChange: locations.onSearchValueChange,
12148
- placeholder: "Select location",
12149
- onChange: (value) => {
12150
- setValue("shipping_option_id", "", {
12151
- shouldDirty: true,
12152
- shouldTouch: true
12153
- });
12154
- onChange(value);
11815
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11816
+ var _a2, _b, _c, _d, _e, _f, _g;
11817
+ const items = getItemsWithShippingProfile(
11818
+ profile.id,
11819
+ order.items
11820
+ );
11821
+ const hasItems = items.length > 0;
11822
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11823
+ (option) => option.shipping_profile_id === profile.id
11824
+ );
11825
+ const shippingMethod = preview.shipping_methods.find(
11826
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11827
+ );
11828
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11829
+ (action) => action.action === "SHIPPING_ADD"
11830
+ );
11831
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11832
+ radixUi.Accordion.Item,
11833
+ {
11834
+ value: profile.id,
11835
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11836
+ children: [
11837
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11838
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11839
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11840
+ ui.IconButton,
11841
+ {
11842
+ size: "2xsmall",
11843
+ variant: "transparent",
11844
+ className: "group/trigger",
11845
+ disabled: !hasItems,
11846
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11847
+ }
11848
+ ) }),
11849
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11850
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11851
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11852
+ /* @__PURE__ */ jsxRuntime.jsx(
11853
+ ui.Text,
11854
+ {
11855
+ size: "small",
11856
+ weight: "plus",
11857
+ leading: "compact",
11858
+ children: profile.name
11859
+ }
11860
+ ),
11861
+ /* @__PURE__ */ jsxRuntime.jsxs(
11862
+ ui.Text,
11863
+ {
11864
+ size: "small",
11865
+ leading: "compact",
11866
+ className: "text-ui-fg-subtle",
11867
+ children: [
11868
+ items.length,
11869
+ " ",
11870
+ pluralize(items.length, "items", "item")
11871
+ ]
11872
+ }
11873
+ )
11874
+ ] })
11875
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11876
+ /* @__PURE__ */ jsxRuntime.jsx(
11877
+ ui.Tooltip,
11878
+ {
11879
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11880
+ var _a3, _b2, _c2;
11881
+ return /* @__PURE__ */ jsxRuntime.jsx(
11882
+ "li",
11883
+ {
11884
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11885
+ },
11886
+ item.id
11887
+ );
11888
+ }) }),
11889
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11890
+ ui.Badge,
11891
+ {
11892
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11893
+ size: "xsmall",
11894
+ children: [
11895
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11896
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11897
+ items.reduce(
11898
+ (acc, item) => acc + item.quantity,
11899
+ 0
11900
+ ),
11901
+ "x",
11902
+ " ",
11903
+ pluralize(items.length, "items", "item")
11904
+ ] })
11905
+ ]
11906
+ }
11907
+ )
11908
+ }
11909
+ ),
11910
+ /* @__PURE__ */ jsxRuntime.jsx(
11911
+ ui.Tooltip,
11912
+ {
11913
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11914
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11915
+ ui.Badge,
11916
+ {
11917
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11918
+ size: "xsmall",
11919
+ children: [
11920
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11921
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11922
+ ]
11923
+ }
11924
+ )
11925
+ }
11926
+ ),
11927
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11928
+ ui.Badge,
11929
+ {
11930
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11931
+ size: "xsmall",
11932
+ children: [
11933
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11934
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11935
+ ]
11936
+ }
11937
+ ) })
11938
+ ] })
11939
+ ] }),
11940
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11941
+ ActionMenu,
11942
+ {
11943
+ groups: [
11944
+ {
11945
+ actions: [
11946
+ hasItems ? {
11947
+ label: "Edit shipping option",
11948
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11949
+ onClick: () => {
11950
+ setIsOpen(
11951
+ STACKED_FOCUS_MODAL_ID,
11952
+ true
11953
+ );
11954
+ setData({
11955
+ shippingProfileId: profile.id,
11956
+ shippingOption,
11957
+ shippingMethod
11958
+ });
11959
+ }
11960
+ } : void 0,
11961
+ {
11962
+ label: "Remove shipping option",
11963
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11964
+ onClick: () => {
11965
+ if (shippingMethod) {
11966
+ if (addShippingMethodAction) {
11967
+ removeActionShippingMethod(
11968
+ addShippingMethodAction.id
11969
+ );
11970
+ } else {
11971
+ removeShippingMethod(
11972
+ shippingMethod.id
11973
+ );
11974
+ }
11975
+ }
11976
+ }
11977
+ }
11978
+ ].filter(Boolean)
11979
+ }
11980
+ ]
11981
+ }
11982
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
11983
+ StackedModalTrigger,
11984
+ {
11985
+ shippingProfileId: profile.id,
11986
+ shippingOption,
11987
+ shippingMethod,
11988
+ setData,
11989
+ children: "Add shipping option"
11990
+ }
11991
+ )
11992
+ ] }),
11993
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11994
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11995
+ items.map((item, idx) => {
11996
+ var _a3, _b2, _c2, _d2, _e2;
11997
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11998
+ /* @__PURE__ */ jsxRuntime.jsxs(
11999
+ "div",
12000
+ {
12001
+ className: "px-3 flex items-center gap-x-3",
12002
+ children: [
12003
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12004
+ ui.Divider,
12005
+ {
12006
+ variant: "dashed",
12007
+ orientation: "vertical"
12008
+ }
12009
+ ) }),
12010
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12011
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12012
+ ui.Text,
12013
+ {
12014
+ size: "small",
12015
+ leading: "compact",
12016
+ className: "text-ui-fg-subtle",
12017
+ children: [
12018
+ item.quantity,
12019
+ "x"
12020
+ ]
12021
+ }
12022
+ ) }),
12023
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12024
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12025
+ /* @__PURE__ */ jsxRuntime.jsxs(
12026
+ ui.Text,
12027
+ {
12028
+ size: "small",
12029
+ leading: "compact",
12030
+ weight: "plus",
12031
+ children: [
12032
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12033
+ " (",
12034
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12035
+ ")"
12036
+ ]
12037
+ }
12038
+ ),
12039
+ /* @__PURE__ */ jsxRuntime.jsx(
12040
+ ui.Text,
12041
+ {
12042
+ size: "small",
12043
+ leading: "compact",
12044
+ className: "text-ui-fg-subtle",
12045
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12046
+ }
12047
+ )
12048
+ ] })
12049
+ ] })
12050
+ ]
12051
+ },
12052
+ item.id
12053
+ ),
12054
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12055
+ ] }, item.id);
12056
+ })
12057
+ ] })
12058
+ ]
12155
12059
  },
12156
- ...field
12060
+ profile.id
12061
+ );
12062
+ }) })
12063
+ ] }) })
12064
+ ] }) }),
12065
+ /* @__PURE__ */ jsxRuntime.jsx(
12066
+ StackedFocusModal,
12067
+ {
12068
+ id: STACKED_FOCUS_MODAL_ID,
12069
+ onOpenChangeCallback: (open) => {
12070
+ if (!open) {
12071
+ setData(null);
12157
12072
  }
12158
- ) })
12159
- ] }) });
12160
- }
12161
- }
12162
- );
12073
+ return open;
12074
+ },
12075
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12076
+ }
12077
+ )
12078
+ ] }),
12079
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12080
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12081
+ /* @__PURE__ */ jsxRuntime.jsx(
12082
+ ui.Button,
12083
+ {
12084
+ size: "small",
12085
+ type: "button",
12086
+ isLoading: isSubmitting,
12087
+ onClick: onSubmit,
12088
+ children: "Save"
12089
+ }
12090
+ )
12091
+ ] }) })
12092
+ ] });
12163
12093
  };
12164
- const ShippingOptionField = ({
12094
+ const StackedModalTrigger = ({
12165
12095
  shippingProfileId,
12166
- preview,
12167
- control
12096
+ shippingOption,
12097
+ shippingMethod,
12098
+ setData,
12099
+ children
12168
12100
  }) => {
12169
- var _a;
12170
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12171
- const shippingOptions = useComboboxData({
12172
- queryKey: ["shipping_options", locationId, shippingProfileId],
12173
- queryFn: async (params) => {
12174
- return await sdk.admin.shippingOption.list({
12175
- ...params,
12176
- stock_location_id: locationId,
12177
- shipping_profile_id: shippingProfileId
12101
+ const { setIsOpen, getIsOpen } = useStackedModal();
12102
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12103
+ const onToggle = () => {
12104
+ if (isOpen) {
12105
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12106
+ setData(null);
12107
+ } else {
12108
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12109
+ setData({
12110
+ shippingProfileId,
12111
+ shippingOption,
12112
+ shippingMethod
12178
12113
  });
12179
- },
12180
- getOptions: (data) => {
12181
- return data.shipping_options.map((option) => {
12182
- var _a2;
12183
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12184
- (r) => r.attribute === "is_return" && r.value === "true"
12185
- )) {
12186
- return void 0;
12187
- }
12188
- return {
12189
- label: option.name,
12190
- value: option.id
12191
- };
12192
- }).filter(Boolean);
12193
- },
12194
- enabled: !!locationId && !!shippingProfileId,
12195
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12196
- });
12197
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12198
- return /* @__PURE__ */ jsxRuntime.jsx(
12199
- Form$2.Field,
12200
- {
12201
- control,
12202
- name: "shipping_option_id",
12203
- render: ({ field }) => {
12204
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12205
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12206
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12207
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12208
- ] }),
12209
- /* @__PURE__ */ jsxRuntime.jsx(
12210
- ConditionalTooltip,
12211
- {
12212
- content: tooltipContent,
12213
- showTooltip: !locationId || !shippingProfileId,
12214
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12215
- Combobox,
12216
- {
12217
- options: shippingOptions.options,
12218
- fetchNextPage: shippingOptions.fetchNextPage,
12219
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12220
- searchValue: shippingOptions.searchValue,
12221
- onSearchValueChange: shippingOptions.onSearchValueChange,
12222
- placeholder: "Select shipping option",
12223
- ...field,
12224
- disabled: !locationId || !shippingProfileId
12225
- }
12226
- ) }) })
12227
- }
12228
- )
12229
- ] }) });
12230
- }
12231
12114
  }
12232
- );
12233
- };
12234
- const CustomAmountField = ({
12235
- control,
12236
- currencyCode
12237
- }) => {
12115
+ };
12238
12116
  return /* @__PURE__ */ jsxRuntime.jsx(
12239
- Form$2.Field,
12117
+ ui.Button,
12240
12118
  {
12241
- control,
12242
- name: "custom_amount",
12243
- render: ({ field: { onChange, ...field } }) => {
12244
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12245
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12246
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12247
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12248
- ] }),
12249
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12250
- ui.CurrencyInput,
12251
- {
12252
- ...field,
12253
- onValueChange: (value) => onChange(value),
12254
- symbol: getNativeSymbol(currencyCode),
12255
- code: currencyCode
12256
- }
12257
- ) })
12258
- ] });
12259
- }
12119
+ size: "small",
12120
+ variant: "secondary",
12121
+ onClick: onToggle,
12122
+ className: "text-ui-fg-primary shrink-0",
12123
+ children
12260
12124
  }
12261
12125
  );
12262
12126
  };
12263
- const ShippingAddress = () => {
12264
- const { id } = reactRouterDom.useParams();
12265
- const { order, isPending, isError, error } = useOrder(id, {
12266
- fields: "+shipping_address"
12267
- });
12268
- if (isError) {
12269
- throw error;
12270
- }
12271
- const isReady = !isPending && !!order;
12272
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12273
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12274
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12275
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12276
- ] }),
12277
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12278
- ] });
12279
- };
12280
- const ShippingAddressForm = ({ order }) => {
12281
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12127
+ const ShippingProfileForm = ({
12128
+ data,
12129
+ order,
12130
+ preview
12131
+ }) => {
12132
+ var _a, _b, _c, _d, _e, _f;
12133
+ const { setIsOpen } = useStackedModal();
12282
12134
  const form = reactHookForm.useForm({
12135
+ resolver: zod.zodResolver(shippingMethodSchema),
12283
12136
  defaultValues: {
12284
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12285
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12286
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12287
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12288
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12289
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12290
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12291
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12292
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12293
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12294
- },
12295
- resolver: zod.zodResolver(schema$2)
12137
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12138
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12139
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12140
+ }
12296
12141
  });
12297
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12298
- const { handleSuccess } = useRouteModal();
12299
- const onSubmit = form.handleSubmit(async (data) => {
12300
- await mutateAsync(
12301
- {
12302
- shipping_address: {
12303
- first_name: data.first_name,
12304
- last_name: data.last_name,
12305
- company: data.company,
12306
- address_1: data.address_1,
12307
- address_2: data.address_2,
12308
- city: data.city,
12309
- province: data.province,
12310
- country_code: data.country_code,
12311
- postal_code: data.postal_code,
12312
- phone: data.phone
12142
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12143
+ const {
12144
+ mutateAsync: updateShippingMethod,
12145
+ isPending: isUpdatingShippingMethod
12146
+ } = useDraftOrderUpdateShippingMethod(order.id);
12147
+ const onSubmit = form.handleSubmit(async (values) => {
12148
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12149
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12150
+ return;
12151
+ }
12152
+ if (data.shippingMethod) {
12153
+ await updateShippingMethod(
12154
+ {
12155
+ method_id: data.shippingMethod.id,
12156
+ shipping_option_id: values.shipping_option_id,
12157
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12158
+ },
12159
+ {
12160
+ onError: (e) => {
12161
+ ui.toast.error(e.message);
12162
+ },
12163
+ onSuccess: () => {
12164
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12165
+ }
12313
12166
  }
12167
+ );
12168
+ return;
12169
+ }
12170
+ await addShippingMethod(
12171
+ {
12172
+ shipping_option_id: values.shipping_option_id,
12173
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12314
12174
  },
12315
12175
  {
12316
- onSuccess: () => {
12317
- handleSuccess();
12176
+ onError: (e) => {
12177
+ ui.toast.error(e.message);
12318
12178
  },
12319
- onError: (error) => {
12320
- ui.toast.error(error.message);
12179
+ onSuccess: () => {
12180
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12321
12181
  }
12322
12182
  }
12323
12183
  );
12324
12184
  });
12325
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12185
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12326
12186
  KeyboundForm,
12327
12187
  {
12328
- className: "flex flex-1 flex-col overflow-hidden",
12188
+ className: "flex h-full flex-col overflow-hidden",
12329
12189
  onSubmit,
12330
12190
  children: [
12331
- /* @__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: [
12191
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12192
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12193
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12194
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12195
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12196
+ ] }),
12197
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12332
12198
  /* @__PURE__ */ jsxRuntime.jsx(
12333
- Form$2.Field,
12199
+ LocationField,
12334
12200
  {
12335
12201
  control: form.control,
12336
- name: "country_code",
12337
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12338
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12339
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12341
- ] })
12202
+ setValue: form.setValue
12342
12203
  }
12343
12204
  ),
12344
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12345
- /* @__PURE__ */ jsxRuntime.jsx(
12346
- Form$2.Field,
12347
- {
12348
- control: form.control,
12349
- name: "first_name",
12350
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12354
- ] })
12355
- }
12356
- ),
12357
- /* @__PURE__ */ jsxRuntime.jsx(
12358
- Form$2.Field,
12359
- {
12360
- control: form.control,
12361
- name: "last_name",
12362
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12364
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12366
- ] })
12367
- }
12368
- )
12369
- ] }),
12205
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12370
12206
  /* @__PURE__ */ jsxRuntime.jsx(
12371
- Form$2.Field,
12207
+ ShippingOptionField,
12372
12208
  {
12373
- control: form.control,
12374
- name: "company",
12375
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12376
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12377
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12378
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12379
- ] })
12209
+ shippingProfileId: data.shippingProfileId,
12210
+ preview,
12211
+ control: form.control
12380
12212
  }
12381
12213
  ),
12214
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12382
12215
  /* @__PURE__ */ jsxRuntime.jsx(
12383
- Form$2.Field,
12216
+ CustomAmountField,
12384
12217
  {
12385
12218
  control: form.control,
12386
- name: "address_1",
12387
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12388
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12389
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12390
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12391
- ] })
12219
+ currencyCode: order.currency_code
12392
12220
  }
12393
12221
  ),
12222
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12394
12223
  /* @__PURE__ */ jsxRuntime.jsx(
12395
- Form$2.Field,
12224
+ ItemsPreview,
12396
12225
  {
12397
- control: form.control,
12398
- name: "address_2",
12399
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12400
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12401
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12402
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12403
- ] })
12226
+ order,
12227
+ shippingProfileId: data.shippingProfileId
12404
12228
  }
12405
- ),
12406
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12407
- /* @__PURE__ */ jsxRuntime.jsx(
12408
- Form$2.Field,
12409
- {
12410
- control: form.control,
12411
- name: "postal_code",
12412
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12413
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12414
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12415
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12416
- ] })
12417
- }
12418
- ),
12419
- /* @__PURE__ */ jsxRuntime.jsx(
12420
- Form$2.Field,
12229
+ )
12230
+ ] }) }) }),
12231
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12232
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12233
+ /* @__PURE__ */ jsxRuntime.jsx(
12234
+ ui.Button,
12235
+ {
12236
+ size: "small",
12237
+ type: "submit",
12238
+ isLoading: isPending || isUpdatingShippingMethod,
12239
+ children: data.shippingMethod ? "Update" : "Add"
12240
+ }
12241
+ )
12242
+ ] }) })
12243
+ ]
12244
+ }
12245
+ ) }) });
12246
+ };
12247
+ const shippingMethodSchema = objectType({
12248
+ location_id: stringType(),
12249
+ shipping_option_id: stringType(),
12250
+ custom_amount: unionType([numberType(), stringType()]).optional()
12251
+ });
12252
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12253
+ const matches = order.items.filter(
12254
+ (item) => {
12255
+ var _a, _b, _c;
12256
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12257
+ }
12258
+ );
12259
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12260
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12261
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12262
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12263
+ ] }) }),
12264
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12265
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12266
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12267
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12268
+ ] }),
12269
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12270
+ "div",
12271
+ {
12272
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12273
+ children: [
12274
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12275
+ /* @__PURE__ */ jsxRuntime.jsx(
12276
+ Thumbnail,
12277
+ {
12278
+ thumbnail: item.thumbnail,
12279
+ alt: item.product_title ?? void 0
12280
+ }
12281
+ ),
12282
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12283
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12284
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12285
+ /* @__PURE__ */ jsxRuntime.jsxs(
12286
+ ui.Text,
12287
+ {
12288
+ size: "small",
12289
+ leading: "compact",
12290
+ className: "text-ui-fg-subtle",
12291
+ children: [
12292
+ "(",
12293
+ item.variant_title,
12294
+ ")"
12295
+ ]
12296
+ }
12297
+ )
12298
+ ] }),
12299
+ /* @__PURE__ */ jsxRuntime.jsx(
12300
+ ui.Text,
12301
+ {
12302
+ size: "small",
12303
+ leading: "compact",
12304
+ className: "text-ui-fg-subtle",
12305
+ children: item.variant_sku
12306
+ }
12307
+ )
12308
+ ] })
12309
+ ] }),
12310
+ /* @__PURE__ */ jsxRuntime.jsxs(
12311
+ ui.Text,
12421
12312
  {
12422
- control: form.control,
12423
- name: "city",
12424
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12425
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12426
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12427
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12428
- ] })
12313
+ size: "small",
12314
+ leading: "compact",
12315
+ className: "text-ui-fg-subtle",
12316
+ children: [
12317
+ item.quantity,
12318
+ "x"
12319
+ ]
12429
12320
  }
12430
12321
  )
12322
+ ]
12323
+ },
12324
+ item.id
12325
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12326
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12327
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12328
+ 'No items found for "',
12329
+ query,
12330
+ '".'
12331
+ ] })
12332
+ ] }) })
12333
+ ] })
12334
+ ] });
12335
+ };
12336
+ const LocationField = ({ control, setValue }) => {
12337
+ const locations = useComboboxData({
12338
+ queryKey: ["locations"],
12339
+ queryFn: async (params) => {
12340
+ return await sdk.admin.stockLocation.list(params);
12341
+ },
12342
+ getOptions: (data) => {
12343
+ return data.stock_locations.map((location) => ({
12344
+ label: location.name,
12345
+ value: location.id
12346
+ }));
12347
+ }
12348
+ });
12349
+ return /* @__PURE__ */ jsxRuntime.jsx(
12350
+ Form$2.Field,
12351
+ {
12352
+ control,
12353
+ name: "location_id",
12354
+ render: ({ field: { onChange, ...field } }) => {
12355
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12356
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12357
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12358
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12359
+ ] }),
12360
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12361
+ Combobox,
12362
+ {
12363
+ options: locations.options,
12364
+ fetchNextPage: locations.fetchNextPage,
12365
+ isFetchingNextPage: locations.isFetchingNextPage,
12366
+ searchValue: locations.searchValue,
12367
+ onSearchValueChange: locations.onSearchValueChange,
12368
+ placeholder: "Select location",
12369
+ onChange: (value) => {
12370
+ setValue("shipping_option_id", "", {
12371
+ shouldDirty: true,
12372
+ shouldTouch: true
12373
+ });
12374
+ onChange(value);
12375
+ },
12376
+ ...field
12377
+ }
12378
+ ) })
12379
+ ] }) });
12380
+ }
12381
+ }
12382
+ );
12383
+ };
12384
+ const ShippingOptionField = ({
12385
+ shippingProfileId,
12386
+ preview,
12387
+ control
12388
+ }) => {
12389
+ var _a;
12390
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12391
+ const shippingOptions = useComboboxData({
12392
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12393
+ queryFn: async (params) => {
12394
+ return await sdk.admin.shippingOption.list({
12395
+ ...params,
12396
+ stock_location_id: locationId,
12397
+ shipping_profile_id: shippingProfileId
12398
+ });
12399
+ },
12400
+ getOptions: (data) => {
12401
+ return data.shipping_options.map((option) => {
12402
+ var _a2;
12403
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12404
+ (r) => r.attribute === "is_return" && r.value === "true"
12405
+ )) {
12406
+ return void 0;
12407
+ }
12408
+ return {
12409
+ label: option.name,
12410
+ value: option.id
12411
+ };
12412
+ }).filter(Boolean);
12413
+ },
12414
+ enabled: !!locationId && !!shippingProfileId,
12415
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12416
+ });
12417
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12418
+ return /* @__PURE__ */ jsxRuntime.jsx(
12419
+ Form$2.Field,
12420
+ {
12421
+ control,
12422
+ name: "shipping_option_id",
12423
+ render: ({ field }) => {
12424
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12425
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12426
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12427
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12431
12428
  ] }),
12432
12429
  /* @__PURE__ */ jsxRuntime.jsx(
12433
- Form$2.Field,
12430
+ ConditionalTooltip,
12434
12431
  {
12435
- control: form.control,
12436
- name: "province",
12437
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12438
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12439
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12440
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12441
- ] })
12432
+ content: tooltipContent,
12433
+ showTooltip: !locationId || !shippingProfileId,
12434
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12435
+ Combobox,
12436
+ {
12437
+ options: shippingOptions.options,
12438
+ fetchNextPage: shippingOptions.fetchNextPage,
12439
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12440
+ searchValue: shippingOptions.searchValue,
12441
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12442
+ placeholder: "Select shipping option",
12443
+ ...field,
12444
+ disabled: !locationId || !shippingProfileId
12445
+ }
12446
+ ) }) })
12442
12447
  }
12443
- ),
12444
- /* @__PURE__ */ jsxRuntime.jsx(
12445
- Form$2.Field,
12448
+ )
12449
+ ] }) });
12450
+ }
12451
+ }
12452
+ );
12453
+ };
12454
+ const CustomAmountField = ({
12455
+ control,
12456
+ currencyCode
12457
+ }) => {
12458
+ return /* @__PURE__ */ jsxRuntime.jsx(
12459
+ Form$2.Field,
12460
+ {
12461
+ control,
12462
+ name: "custom_amount",
12463
+ render: ({ field: { onChange, ...field } }) => {
12464
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12465
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12466
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12467
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12468
+ ] }),
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12470
+ ui.CurrencyInput,
12446
12471
  {
12447
- control: form.control,
12448
- name: "phone",
12449
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12450
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12451
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12452
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12453
- ] })
12472
+ ...field,
12473
+ onValueChange: (value) => onChange(value),
12474
+ symbol: getNativeSymbol(currencyCode),
12475
+ code: currencyCode
12454
12476
  }
12455
- )
12456
- ] }) }),
12457
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12458
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12459
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12460
- ] }) })
12461
- ]
12477
+ ) })
12478
+ ] });
12479
+ }
12462
12480
  }
12463
- ) });
12481
+ );
12464
12482
  };
12465
- const schema$2 = addressSchema;
12466
12483
  const TransferOwnership = () => {
12467
12484
  const { id } = reactRouterDom.useParams();
12468
12485
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12486,7 +12503,7 @@ const TransferOwnershipForm = ({ order }) => {
12486
12503
  defaultValues: {
12487
12504
  customer_id: order.customer_id || ""
12488
12505
  },
12489
- resolver: zod.zodResolver(schema$1)
12506
+ resolver: zod.zodResolver(schema$2)
12490
12507
  });
12491
12508
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12492
12509
  const { handleSuccess } = useRouteModal();
@@ -12936,49 +12953,40 @@ const Illustration = () => {
12936
12953
  }
12937
12954
  );
12938
12955
  };
12939
- const schema$1 = objectType({
12956
+ const schema$2 = objectType({
12940
12957
  customer_id: stringType().min(1)
12941
12958
  });
12942
- const SalesChannel = () => {
12959
+ const Email = () => {
12943
12960
  const { id } = reactRouterDom.useParams();
12944
- const { draft_order, isPending, isError, error } = useDraftOrder(
12945
- id,
12946
- {
12947
- fields: "+sales_channel_id"
12948
- },
12949
- {
12950
- enabled: !!id
12951
- }
12952
- );
12961
+ const { order, isPending, isError, error } = useOrder(id, {
12962
+ fields: "+email"
12963
+ });
12953
12964
  if (isError) {
12954
12965
  throw error;
12955
12966
  }
12956
- const ISrEADY = !!draft_order && !isPending;
12967
+ const isReady = !isPending && !!order;
12957
12968
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12958
12969
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12959
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12960
- /* @__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" }) })
12970
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12961
12972
  ] }),
12962
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12973
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12963
12974
  ] });
12964
12975
  };
12965
- const SalesChannelForm = ({ order }) => {
12976
+ const EmailForm = ({ order }) => {
12966
12977
  const form = reactHookForm.useForm({
12967
12978
  defaultValues: {
12968
- sales_channel_id: order.sales_channel_id || ""
12979
+ email: order.email ?? ""
12969
12980
  },
12970
- resolver: zod.zodResolver(schema)
12981
+ resolver: zod.zodResolver(schema$1)
12971
12982
  });
12972
12983
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12973
12984
  const { handleSuccess } = useRouteModal();
12974
12985
  const onSubmit = form.handleSubmit(async (data) => {
12975
12986
  await mutateAsync(
12976
- {
12977
- sales_channel_id: data.sales_channel_id
12978
- },
12987
+ { email: data.email },
12979
12988
  {
12980
12989
  onSuccess: () => {
12981
- ui.toast.success("Sales channel updated");
12982
12990
  handleSuccess();
12983
12991
  },
12984
12992
  onError: (error) => {
@@ -12993,7 +13001,18 @@ const SalesChannelForm = ({ order }) => {
12993
13001
  className: "flex flex-1 flex-col overflow-hidden",
12994
13002
  onSubmit,
12995
13003
  children: [
12996
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
13004
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13005
+ Form$2.Field,
13006
+ {
13007
+ control: form.control,
13008
+ name: "email",
13009
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13010
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13011
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13012
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13013
+ ] })
13014
+ }
13015
+ ) }),
12997
13016
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12998
13017
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12999
13018
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13002,48 +13021,29 @@ const SalesChannelForm = ({ order }) => {
13002
13021
  }
13003
13022
  ) });
13004
13023
  };
13005
- const SalesChannelField = ({ control, order }) => {
13006
- const salesChannels = useComboboxData({
13007
- queryFn: async (params) => {
13008
- return await sdk.admin.salesChannel.list(params);
13009
- },
13010
- queryKey: ["sales-channels"],
13011
- getOptions: (data) => {
13012
- return data.sales_channels.map((salesChannel) => ({
13013
- label: salesChannel.name,
13014
- value: salesChannel.id
13015
- }));
13016
- },
13017
- defaultValue: order.sales_channel_id || void 0
13024
+ const schema$1 = objectType({
13025
+ email: stringType().email()
13026
+ });
13027
+ const CustomItems = () => {
13028
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
13029
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
13030
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
13031
+ ] });
13032
+ };
13033
+ const CustomItemsForm = () => {
13034
+ const form = reactHookForm.useForm({
13035
+ resolver: zod.zodResolver(schema)
13018
13036
  });
13019
- return /* @__PURE__ */ jsxRuntime.jsx(
13020
- Form$2.Field,
13021
- {
13022
- control,
13023
- name: "sales_channel_id",
13024
- render: ({ field }) => {
13025
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13027
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13028
- Combobox,
13029
- {
13030
- options: salesChannels.options,
13031
- fetchNextPage: salesChannels.fetchNextPage,
13032
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13033
- searchValue: salesChannels.searchValue,
13034
- onSearchValueChange: salesChannels.onSearchValueChange,
13035
- placeholder: "Select sales channel",
13036
- ...field
13037
- }
13038
- ) }),
13039
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13040
- ] });
13041
- }
13042
- }
13043
- );
13037
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
13042
+ ] }) })
13043
+ ] }) });
13044
13044
  };
13045
13045
  const schema = objectType({
13046
- sales_channel_id: stringType().min(1)
13046
+ email: stringType().email()
13047
13047
  });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
@@ -13069,14 +13069,6 @@ const routeModule = {
13069
13069
  Component: BillingAddress,
13070
13070
  path: "/draft-orders/:id/billing-address"
13071
13071
  },
13072
- {
13073
- Component: CustomItems,
13074
- path: "/draft-orders/:id/custom-items"
13075
- },
13076
- {
13077
- Component: Email,
13078
- path: "/draft-orders/:id/email"
13079
- },
13080
13072
  {
13081
13073
  Component: Items,
13082
13074
  path: "/draft-orders/:id/items"
@@ -13090,20 +13082,28 @@ const routeModule = {
13090
13082
  path: "/draft-orders/:id/promotions"
13091
13083
  },
13092
13084
  {
13093
- Component: Shipping,
13094
- path: "/draft-orders/:id/shipping"
13085
+ Component: SalesChannel,
13086
+ path: "/draft-orders/:id/sales-channel"
13095
13087
  },
13096
13088
  {
13097
13089
  Component: ShippingAddress,
13098
13090
  path: "/draft-orders/:id/shipping-address"
13099
13091
  },
13092
+ {
13093
+ Component: Shipping,
13094
+ path: "/draft-orders/:id/shipping"
13095
+ },
13100
13096
  {
13101
13097
  Component: TransferOwnership,
13102
13098
  path: "/draft-orders/:id/transfer-ownership"
13103
13099
  },
13104
13100
  {
13105
- Component: SalesChannel,
13106
- path: "/draft-orders/:id/sales-channel"
13101
+ Component: Email,
13102
+ path: "/draft-orders/:id/email"
13103
+ },
13104
+ {
13105
+ Component: CustomItems,
13106
+ path: "/draft-orders/:id/custom-items"
13107
13107
  }
13108
13108
  ]
13109
13109
  }