@medusajs/draft-order 2.10.0-preview-20250827120157 → 2.10.0-preview-20250827180155

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.
@@ -11440,1598 +11440,1598 @@ function getPromotionCodes(items, shippingMethods) {
11440
11440
  }
11441
11441
  return Array.from(codes);
11442
11442
  }
11443
- const SalesChannel = () => {
11443
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11444
+ const Shipping = () => {
11445
+ var _a;
11444
11446
  const { id } = reactRouterDom.useParams();
11445
- const { draft_order, isPending, isError, error } = useDraftOrder(
11446
- id,
11447
- {
11448
- fields: "+sales_channel_id"
11449
- },
11450
- {
11451
- enabled: !!id
11452
- }
11453
- );
11447
+ const { order, isPending, isError, error } = useOrder(id, {
11448
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11449
+ });
11450
+ const {
11451
+ order: preview,
11452
+ isPending: isPreviewPending,
11453
+ isError: isPreviewError,
11454
+ error: previewError
11455
+ } = useOrderPreview(id);
11456
+ useInitiateOrderEdit({ preview });
11457
+ const { onCancel } = useCancelOrderEdit({ preview });
11454
11458
  if (isError) {
11455
11459
  throw error;
11456
11460
  }
11457
- const ISrEADY = !!draft_order && !isPending;
11458
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11459
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11460
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11461
- /* @__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" }) })
11462
- ] }),
11463
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11464
- ] });
11461
+ if (isPreviewError) {
11462
+ throw previewError;
11463
+ }
11464
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11465
+ const isReady = preview && !isPreviewPending && order && !isPending;
11466
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11467
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11468
+ /* @__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: [
11469
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11470
+ /* @__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." }) })
11471
+ ] }) }) }),
11472
+ /* @__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" }) }) })
11473
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11474
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11475
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11476
+ ] }) });
11465
11477
  };
11466
- const SalesChannelForm = ({ order }) => {
11467
- const form = reactHookForm.useForm({
11468
- defaultValues: {
11469
- sales_channel_id: order.sales_channel_id || ""
11470
- },
11471
- resolver: zod.zodResolver(schema$2)
11472
- });
11473
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11474
- const { handleSuccess } = useRouteModal();
11475
- const onSubmit = form.handleSubmit(async (data) => {
11476
- await mutateAsync(
11477
- {
11478
- sales_channel_id: data.sales_channel_id
11479
- },
11480
- {
11481
- onSuccess: () => {
11482
- ui.toast.success("Sales channel updated");
11483
- handleSuccess();
11484
- },
11485
- onError: (error) => {
11486
- ui.toast.error(error.message);
11487
- }
11488
- }
11489
- );
11490
- });
11491
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11492
- KeyboundForm,
11478
+ const ShippingForm = ({ preview, order }) => {
11479
+ var _a;
11480
+ const { setIsOpen } = useStackedModal();
11481
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11482
+ const [data, setData] = React.useState(null);
11483
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11484
+ const { shipping_options } = useShippingOptions(
11493
11485
  {
11494
- className: "flex flex-1 flex-col overflow-hidden",
11495
- onSubmit,
11496
- children: [
11497
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11498
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11499
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11500
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11501
- ] }) })
11502
- ]
11503
- }
11504
- ) });
11505
- };
11506
- const SalesChannelField = ({ control, order }) => {
11507
- const salesChannels = useComboboxData({
11508
- queryFn: async (params) => {
11509
- return await sdk.admin.salesChannel.list(params);
11510
- },
11511
- queryKey: ["sales-channels"],
11512
- getOptions: (data) => {
11513
- return data.sales_channels.map((salesChannel) => ({
11514
- label: salesChannel.name,
11515
- value: salesChannel.id
11516
- }));
11486
+ id: appliedShippingOptionIds,
11487
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11517
11488
  },
11518
- defaultValue: order.sales_channel_id || void 0
11519
- });
11520
- return /* @__PURE__ */ jsxRuntime.jsx(
11521
- Form$2.Field,
11522
11489
  {
11523
- control,
11524
- name: "sales_channel_id",
11525
- render: ({ field }) => {
11526
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11527
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11528
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11529
- Combobox,
11530
- {
11531
- options: salesChannels.options,
11532
- fetchNextPage: salesChannels.fetchNextPage,
11533
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11534
- searchValue: salesChannels.searchValue,
11535
- onSearchValueChange: salesChannels.onSearchValueChange,
11536
- placeholder: "Select sales channel",
11537
- ...field
11538
- }
11539
- ) }),
11540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11541
- ] });
11542
- }
11490
+ enabled: appliedShippingOptionIds.length > 0
11543
11491
  }
11544
11492
  );
11545
- };
11546
- const schema$2 = objectType({
11547
- sales_channel_id: stringType().min(1)
11548
- });
11549
- const ShippingAddress = () => {
11550
- const { id } = reactRouterDom.useParams();
11551
- const { order, isPending, isError, error } = useOrder(id, {
11552
- fields: "+shipping_address"
11553
- });
11554
- if (isError) {
11555
- throw error;
11556
- }
11557
- const isReady = !isPending && !!order;
11558
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11559
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11560
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11561
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11562
- ] }),
11563
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11564
- ] });
11565
- };
11566
- const ShippingAddressForm = ({ order }) => {
11567
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11568
- const form = reactHookForm.useForm({
11569
- defaultValues: {
11570
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11571
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11572
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11573
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11574
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11575
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11576
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11577
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11578
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11579
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11580
- },
11581
- resolver: zod.zodResolver(schema$1)
11582
- });
11583
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11493
+ const uniqueShippingProfiles = React.useMemo(() => {
11494
+ const profiles = /* @__PURE__ */ new Map();
11495
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11496
+ profiles.set(profile.id, profile);
11497
+ });
11498
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11499
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11500
+ });
11501
+ return Array.from(profiles.values());
11502
+ }, [order.items, shipping_options]);
11584
11503
  const { handleSuccess } = useRouteModal();
11585
- const onSubmit = form.handleSubmit(async (data) => {
11586
- await mutateAsync(
11587
- {
11588
- shipping_address: {
11589
- first_name: data.first_name,
11590
- last_name: data.last_name,
11591
- company: data.company,
11592
- address_1: data.address_1,
11593
- address_2: data.address_2,
11594
- city: data.city,
11595
- province: data.province,
11596
- country_code: data.country_code,
11597
- postal_code: data.postal_code,
11598
- phone: data.phone
11599
- }
11504
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11505
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11506
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11507
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11508
+ const onSubmit = async () => {
11509
+ setIsSubmitting(true);
11510
+ let requestSucceeded = false;
11511
+ await requestOrderEdit(void 0, {
11512
+ onError: (e) => {
11513
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11600
11514
  },
11601
- {
11602
- onSuccess: () => {
11603
- handleSuccess();
11604
- },
11605
- onError: (error) => {
11606
- ui.toast.error(error.message);
11515
+ onSuccess: () => {
11516
+ requestSucceeded = true;
11517
+ }
11518
+ });
11519
+ if (!requestSucceeded) {
11520
+ setIsSubmitting(false);
11521
+ return;
11522
+ }
11523
+ await confirmOrderEdit(void 0, {
11524
+ onError: (e) => {
11525
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11526
+ },
11527
+ onSuccess: () => {
11528
+ handleSuccess();
11529
+ },
11530
+ onSettled: () => {
11531
+ setIsSubmitting(false);
11532
+ }
11533
+ });
11534
+ };
11535
+ const onKeydown = React.useCallback(
11536
+ (e) => {
11537
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11538
+ if (data || isSubmitting) {
11539
+ return;
11607
11540
  }
11541
+ onSubmit();
11608
11542
  }
11609
- );
11610
- });
11611
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11612
- KeyboundForm,
11613
- {
11614
- className: "flex flex-1 flex-col overflow-hidden",
11615
- onSubmit,
11616
- children: [
11617
- /* @__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: [
11618
- /* @__PURE__ */ jsxRuntime.jsx(
11619
- Form$2.Field,
11620
- {
11621
- control: form.control,
11622
- name: "country_code",
11623
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11624
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11625
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11626
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11627
- ] })
11628
- }
11629
- ),
11630
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11543
+ },
11544
+ [data, isSubmitting, onSubmit]
11545
+ );
11546
+ React.useEffect(() => {
11547
+ document.addEventListener("keydown", onKeydown);
11548
+ return () => {
11549
+ document.removeEventListener("keydown", onKeydown);
11550
+ };
11551
+ }, [onKeydown]);
11552
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11553
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11554
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11555
+ /* @__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: [
11556
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11557
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11558
+ /* @__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." }) })
11559
+ ] }),
11560
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11561
+ /* @__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: [
11562
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11631
11563
  /* @__PURE__ */ jsxRuntime.jsx(
11632
- Form$2.Field,
11564
+ ui.Text,
11633
11565
  {
11634
- control: form.control,
11635
- name: "first_name",
11636
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11640
- ] })
11566
+ size: "xsmall",
11567
+ weight: "plus",
11568
+ className: "text-ui-fg-muted",
11569
+ children: "Shipping profile"
11641
11570
  }
11642
11571
  ),
11643
11572
  /* @__PURE__ */ jsxRuntime.jsx(
11644
- Form$2.Field,
11573
+ ui.Text,
11645
11574
  {
11646
- control: form.control,
11647
- name: "last_name",
11648
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11649
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11652
- ] })
11575
+ size: "xsmall",
11576
+ weight: "plus",
11577
+ className: "text-ui-fg-muted",
11578
+ children: "Action"
11653
11579
  }
11654
11580
  )
11655
11581
  ] }),
11656
- /* @__PURE__ */ jsxRuntime.jsx(
11657
- Form$2.Field,
11658
- {
11659
- control: form.control,
11660
- name: "company",
11661
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11665
- ] })
11666
- }
11667
- ),
11668
- /* @__PURE__ */ jsxRuntime.jsx(
11669
- Form$2.Field,
11670
- {
11671
- control: form.control,
11672
- name: "address_1",
11673
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11674
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11677
- ] })
11678
- }
11679
- ),
11680
- /* @__PURE__ */ jsxRuntime.jsx(
11681
- Form$2.Field,
11682
- {
11683
- control: form.control,
11684
- name: "address_2",
11685
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11686
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11689
- ] })
11690
- }
11691
- ),
11692
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11693
- /* @__PURE__ */ jsxRuntime.jsx(
11694
- Form$2.Field,
11695
- {
11696
- control: form.control,
11697
- name: "postal_code",
11698
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11702
- ] })
11703
- }
11704
- ),
11705
- /* @__PURE__ */ jsxRuntime.jsx(
11706
- Form$2.Field,
11582
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11583
+ var _a2, _b, _c, _d, _e, _f, _g;
11584
+ const items = getItemsWithShippingProfile(
11585
+ profile.id,
11586
+ order.items
11587
+ );
11588
+ const hasItems = items.length > 0;
11589
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11590
+ (option) => option.shipping_profile_id === profile.id
11591
+ );
11592
+ const shippingMethod = preview.shipping_methods.find(
11593
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11594
+ );
11595
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11596
+ (action) => action.action === "SHIPPING_ADD"
11597
+ );
11598
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11599
+ radixUi.Accordion.Item,
11707
11600
  {
11708
- control: form.control,
11709
- name: "city",
11710
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11711
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11714
- ] })
11715
- }
11716
- )
11717
- ] }),
11718
- /* @__PURE__ */ jsxRuntime.jsx(
11719
- Form$2.Field,
11720
- {
11721
- control: form.control,
11722
- name: "province",
11723
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11727
- ] })
11728
- }
11729
- ),
11730
- /* @__PURE__ */ jsxRuntime.jsx(
11731
- Form$2.Field,
11732
- {
11733
- control: form.control,
11734
- name: "phone",
11735
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11736
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11739
- ] })
11740
- }
11741
- )
11742
- ] }) }),
11743
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11744
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11745
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11746
- ] }) })
11747
- ]
11748
- }
11749
- ) });
11750
- };
11751
- const schema$1 = addressSchema;
11752
- const TransferOwnership = () => {
11753
- const { id } = reactRouterDom.useParams();
11754
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11755
- fields: "id,customer_id,customer.*"
11756
- });
11757
- if (isError) {
11758
- throw error;
11759
- }
11760
- const isReady = !isPending && !!draft_order;
11761
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11762
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11763
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11764
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11765
- ] }),
11766
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11767
- ] });
11768
- };
11769
- const TransferOwnershipForm = ({ order }) => {
11770
- var _a, _b;
11771
- const form = reactHookForm.useForm({
11772
- defaultValues: {
11773
- customer_id: order.customer_id || ""
11774
- },
11775
- resolver: zod.zodResolver(schema)
11776
- });
11777
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11778
- const { handleSuccess } = useRouteModal();
11779
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11780
- const currentCustomer = order.customer ? {
11781
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11782
- value: order.customer.id
11783
- } : null;
11784
- const onSubmit = form.handleSubmit(async (data) => {
11785
- await mutateAsync(
11786
- { customer_id: data.customer_id },
11787
- {
11788
- onSuccess: () => {
11789
- ui.toast.success("Customer updated");
11790
- handleSuccess();
11791
- },
11792
- onError: (error) => {
11793
- ui.toast.error(error.message);
11794
- }
11795
- }
11796
- );
11797
- });
11798
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11799
- KeyboundForm,
11800
- {
11801
- className: "flex flex-1 flex-col overflow-hidden",
11802
- onSubmit,
11803
- children: [
11804
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11805
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11806
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11807
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11808
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11809
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11810
- ] }),
11811
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11812
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11813
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11814
- ] })
11815
- ] }),
11816
- /* @__PURE__ */ jsxRuntime.jsx(
11817
- CustomerField,
11818
- {
11819
- control: form.control,
11820
- currentCustomerId: order.customer_id
11821
- }
11822
- )
11823
- ] }),
11824
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11825
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11826
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11827
- ] }) })
11828
- ]
11829
- }
11830
- ) });
11831
- };
11832
- const CustomerField = ({ control, currentCustomerId }) => {
11833
- const customers = useComboboxData({
11834
- queryFn: async (params) => {
11835
- return await sdk.admin.customer.list({
11836
- ...params,
11837
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11838
- });
11839
- },
11840
- queryKey: ["customers"],
11841
- getOptions: (data) => {
11842
- return data.customers.map((customer) => {
11843
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11844
- return {
11845
- label: name ? `${name} (${customer.email})` : customer.email,
11846
- value: customer.id
11847
- };
11848
- });
11849
- }
11850
- });
11851
- return /* @__PURE__ */ jsxRuntime.jsx(
11852
- Form$2.Field,
11853
- {
11854
- name: "customer_id",
11855
- control,
11856
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11857
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11858
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11859
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11860
- ] }),
11861
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11862
- Combobox,
11863
- {
11864
- options: customers.options,
11865
- fetchNextPage: customers.fetchNextPage,
11866
- isFetchingNextPage: customers.isFetchingNextPage,
11867
- searchValue: customers.searchValue,
11868
- onSearchValueChange: customers.onSearchValueChange,
11869
- placeholder: "Select customer",
11870
- ...field
11871
- }
11872
- ) }),
11873
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11874
- ] })
11875
- }
11876
- );
11877
- };
11878
- const Illustration = () => {
11879
- return /* @__PURE__ */ jsxRuntime.jsxs(
11880
- "svg",
11881
- {
11882
- width: "280",
11883
- height: "180",
11884
- viewBox: "0 0 280 180",
11885
- fill: "none",
11886
- xmlns: "http://www.w3.org/2000/svg",
11887
- children: [
11888
- /* @__PURE__ */ jsxRuntime.jsx(
11889
- "rect",
11890
- {
11891
- x: "0.00428286",
11892
- y: "-0.742904",
11893
- width: "33.5",
11894
- height: "65.5",
11895
- rx: "6.75",
11896
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11897
- fill: "#D4D4D8",
11898
- stroke: "#52525B",
11899
- strokeWidth: "1.5"
11900
- }
11901
- ),
11902
- /* @__PURE__ */ jsxRuntime.jsx(
11903
- "rect",
11904
- {
11905
- x: "0.00428286",
11906
- y: "-0.742904",
11907
- width: "33.5",
11908
- height: "65.5",
11909
- rx: "6.75",
11910
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11911
- fill: "white",
11912
- stroke: "#52525B",
11913
- strokeWidth: "1.5"
11914
- }
11915
- ),
11916
- /* @__PURE__ */ jsxRuntime.jsx(
11917
- "path",
11918
- {
11919
- d: "M180.579 107.142L179.126 107.959",
11920
- stroke: "#52525B",
11921
- strokeWidth: "1.5",
11922
- strokeLinecap: "round",
11923
- strokeLinejoin: "round"
11924
- }
11925
- ),
11926
- /* @__PURE__ */ jsxRuntime.jsx(
11927
- "path",
11928
- {
11929
- opacity: "0.88",
11930
- d: "M182.305 109.546L180.257 109.534",
11931
- stroke: "#52525B",
11932
- strokeWidth: "1.5",
11933
- strokeLinecap: "round",
11934
- strokeLinejoin: "round"
11935
- }
11936
- ),
11937
- /* @__PURE__ */ jsxRuntime.jsx(
11938
- "path",
11939
- {
11940
- opacity: "0.75",
11941
- d: "M180.551 111.93L179.108 111.096",
11942
- stroke: "#52525B",
11943
- strokeWidth: "1.5",
11944
- strokeLinecap: "round",
11945
- strokeLinejoin: "round"
11946
- }
11947
- ),
11948
- /* @__PURE__ */ jsxRuntime.jsx(
11949
- "path",
11950
- {
11951
- opacity: "0.63",
11952
- d: "M176.347 112.897L176.354 111.73",
11953
- stroke: "#52525B",
11954
- strokeWidth: "1.5",
11955
- strokeLinecap: "round",
11956
- strokeLinejoin: "round"
11957
- }
11958
- ),
11959
- /* @__PURE__ */ jsxRuntime.jsx(
11960
- "path",
11961
- {
11962
- opacity: "0.5",
11963
- d: "M172.153 111.881L173.606 111.064",
11964
- stroke: "#52525B",
11965
- strokeWidth: "1.5",
11966
- strokeLinecap: "round",
11967
- strokeLinejoin: "round"
11968
- }
11969
- ),
11970
- /* @__PURE__ */ jsxRuntime.jsx(
11971
- "path",
11972
- {
11973
- opacity: "0.38",
11974
- d: "M170.428 109.478L172.476 109.489",
11975
- stroke: "#52525B",
11976
- strokeWidth: "1.5",
11977
- strokeLinecap: "round",
11978
- strokeLinejoin: "round"
11979
- }
11980
- ),
11981
- /* @__PURE__ */ jsxRuntime.jsx(
11982
- "path",
11983
- {
11984
- opacity: "0.25",
11985
- d: "M172.181 107.094L173.624 107.928",
11986
- stroke: "#52525B",
11987
- strokeWidth: "1.5",
11988
- strokeLinecap: "round",
11989
- strokeLinejoin: "round"
11990
- }
11991
- ),
11992
- /* @__PURE__ */ jsxRuntime.jsx(
11993
- "path",
11994
- {
11995
- opacity: "0.13",
11996
- d: "M176.386 106.126L176.379 107.294",
11997
- stroke: "#52525B",
11998
- strokeWidth: "1.5",
11999
- strokeLinecap: "round",
12000
- strokeLinejoin: "round"
12001
- }
12002
- ),
12003
- /* @__PURE__ */ jsxRuntime.jsx(
12004
- "rect",
12005
- {
12006
- width: "12",
12007
- height: "3",
12008
- rx: "1.5",
12009
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12010
- fill: "#D4D4D8"
12011
- }
12012
- ),
12013
- /* @__PURE__ */ jsxRuntime.jsx(
12014
- "rect",
12015
- {
12016
- x: "0.00428286",
12017
- y: "-0.742904",
12018
- width: "33.5",
12019
- height: "65.5",
12020
- rx: "6.75",
12021
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12022
- fill: "#D4D4D8",
12023
- stroke: "#52525B",
12024
- strokeWidth: "1.5"
12025
- }
12026
- ),
12027
- /* @__PURE__ */ jsxRuntime.jsx(
12028
- "rect",
12029
- {
12030
- x: "0.00428286",
12031
- y: "-0.742904",
12032
- width: "33.5",
12033
- height: "65.5",
12034
- rx: "6.75",
12035
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12036
- fill: "white",
12037
- stroke: "#52525B",
12038
- strokeWidth: "1.5"
12039
- }
12040
- ),
12041
- /* @__PURE__ */ jsxRuntime.jsx(
12042
- "rect",
12043
- {
12044
- width: "12",
12045
- height: "3",
12046
- rx: "1.5",
12047
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12048
- fill: "#D4D4D8"
12049
- }
12050
- ),
12051
- /* @__PURE__ */ jsxRuntime.jsx(
12052
- "rect",
12053
- {
12054
- width: "17",
12055
- height: "3",
12056
- rx: "1.5",
12057
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12058
- fill: "#D4D4D8"
12059
- }
12060
- ),
12061
- /* @__PURE__ */ jsxRuntime.jsx(
12062
- "rect",
12063
- {
12064
- width: "12",
12065
- height: "3",
12066
- rx: "1.5",
12067
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12068
- fill: "#D4D4D8"
12069
- }
12070
- ),
12071
- /* @__PURE__ */ jsxRuntime.jsx(
12072
- "path",
12073
- {
12074
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12075
- fill: "#A1A1AA"
12076
- }
12077
- ),
12078
- /* @__PURE__ */ jsxRuntime.jsx(
12079
- "rect",
12080
- {
12081
- width: "17",
12082
- height: "3",
12083
- rx: "1.5",
12084
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12085
- fill: "#A1A1AA"
12086
- }
12087
- ),
12088
- /* @__PURE__ */ jsxRuntime.jsx(
12089
- "rect",
12090
- {
12091
- width: "12",
12092
- height: "3",
12093
- rx: "1.5",
12094
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12095
- fill: "#A1A1AA"
12096
- }
12097
- ),
12098
- /* @__PURE__ */ jsxRuntime.jsx(
12099
- "path",
12100
- {
12101
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12102
- fill: "#52525B"
12103
- }
12104
- ),
12105
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12106
- "path",
12107
- {
12108
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12109
- stroke: "#A1A1AA",
12110
- strokeWidth: "1.5",
12111
- strokeLinecap: "round",
12112
- strokeLinejoin: "round"
12113
- }
12114
- ) }),
12115
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12116
- "path",
12117
- {
12118
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12119
- stroke: "#A1A1AA",
12120
- strokeWidth: "1.5",
12121
- strokeLinecap: "round",
12122
- strokeLinejoin: "round"
12123
- }
12124
- ) }),
12125
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12126
- "path",
12127
- {
12128
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12129
- stroke: "#A1A1AA",
12130
- strokeWidth: "1.5",
12131
- strokeLinecap: "round",
12132
- strokeLinejoin: "round"
12133
- }
12134
- ) }),
12135
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12136
- "path",
12137
- {
12138
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12139
- stroke: "#A1A1AA",
12140
- strokeWidth: "1.5",
12141
- strokeLinecap: "round",
12142
- strokeLinejoin: "round"
12143
- }
12144
- ) }),
12145
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12146
- "path",
12147
- {
12148
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12149
- stroke: "#A1A1AA",
12150
- strokeWidth: "1.5",
12151
- strokeLinecap: "round",
12152
- strokeLinejoin: "round"
12153
- }
12154
- ) }),
12155
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12156
- "path",
12157
- {
12158
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12159
- stroke: "#A1A1AA",
12160
- strokeWidth: "1.5",
12161
- strokeLinecap: "round",
12162
- strokeLinejoin: "round"
12163
- }
12164
- ) }),
12165
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12166
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12167
- "rect",
12168
- {
12169
- width: "12",
12170
- height: "12",
12171
- fill: "white",
12172
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11601
+ value: profile.id,
11602
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11603
+ children: [
11604
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11605
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11606
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11607
+ ui.IconButton,
11608
+ {
11609
+ size: "2xsmall",
11610
+ variant: "transparent",
11611
+ className: "group/trigger",
11612
+ disabled: !hasItems,
11613
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11614
+ }
11615
+ ) }),
11616
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11617
+ /* @__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" }) }) }),
11618
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11619
+ /* @__PURE__ */ jsxRuntime.jsx(
11620
+ ui.Text,
11621
+ {
11622
+ size: "small",
11623
+ weight: "plus",
11624
+ leading: "compact",
11625
+ children: profile.name
11626
+ }
11627
+ ),
11628
+ /* @__PURE__ */ jsxRuntime.jsxs(
11629
+ ui.Text,
11630
+ {
11631
+ size: "small",
11632
+ leading: "compact",
11633
+ className: "text-ui-fg-subtle",
11634
+ children: [
11635
+ items.length,
11636
+ " ",
11637
+ pluralize(items.length, "items", "item")
11638
+ ]
11639
+ }
11640
+ )
11641
+ ] })
11642
+ ] }) : /* @__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: [
11643
+ /* @__PURE__ */ jsxRuntime.jsx(
11644
+ ui.Tooltip,
11645
+ {
11646
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11647
+ var _a3, _b2, _c2;
11648
+ return /* @__PURE__ */ jsxRuntime.jsx(
11649
+ "li",
11650
+ {
11651
+ 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})`
11652
+ },
11653
+ item.id
11654
+ );
11655
+ }) }),
11656
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11657
+ ui.Badge,
11658
+ {
11659
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11660
+ size: "xsmall",
11661
+ children: [
11662
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11663
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11664
+ items.reduce(
11665
+ (acc, item) => acc + item.quantity,
11666
+ 0
11667
+ ),
11668
+ "x",
11669
+ " ",
11670
+ pluralize(items.length, "items", "item")
11671
+ ] })
11672
+ ]
11673
+ }
11674
+ )
11675
+ }
11676
+ ),
11677
+ /* @__PURE__ */ jsxRuntime.jsx(
11678
+ ui.Tooltip,
11679
+ {
11680
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11681
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11682
+ ui.Badge,
11683
+ {
11684
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11685
+ size: "xsmall",
11686
+ children: [
11687
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11688
+ /* @__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 })
11689
+ ]
11690
+ }
11691
+ )
11692
+ }
11693
+ ),
11694
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, 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.TruckFast, { className: "shrink-0" }),
11701
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11702
+ ]
11703
+ }
11704
+ ) })
11705
+ ] })
11706
+ ] }),
11707
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11708
+ ActionMenu,
11709
+ {
11710
+ groups: [
11711
+ {
11712
+ actions: [
11713
+ hasItems ? {
11714
+ label: "Edit shipping option",
11715
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11716
+ onClick: () => {
11717
+ setIsOpen(
11718
+ STACKED_FOCUS_MODAL_ID,
11719
+ true
11720
+ );
11721
+ setData({
11722
+ shippingProfileId: profile.id,
11723
+ shippingOption,
11724
+ shippingMethod
11725
+ });
11726
+ }
11727
+ } : void 0,
11728
+ {
11729
+ label: "Remove shipping option",
11730
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11731
+ onClick: () => {
11732
+ if (shippingMethod) {
11733
+ if (addShippingMethodAction) {
11734
+ removeActionShippingMethod(
11735
+ addShippingMethodAction.id
11736
+ );
11737
+ } else {
11738
+ removeShippingMethod(
11739
+ shippingMethod.id
11740
+ );
11741
+ }
11742
+ }
11743
+ }
11744
+ }
11745
+ ].filter(Boolean)
11746
+ }
11747
+ ]
11748
+ }
11749
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
11750
+ StackedModalTrigger,
11751
+ {
11752
+ shippingProfileId: profile.id,
11753
+ shippingOption,
11754
+ shippingMethod,
11755
+ setData,
11756
+ children: "Add shipping option"
11757
+ }
11758
+ )
11759
+ ] }),
11760
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11761
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11762
+ items.map((item, idx) => {
11763
+ var _a3, _b2, _c2, _d2, _e2;
11764
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11765
+ /* @__PURE__ */ jsxRuntime.jsxs(
11766
+ "div",
11767
+ {
11768
+ className: "px-3 flex items-center gap-x-3",
11769
+ children: [
11770
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11771
+ ui.Divider,
11772
+ {
11773
+ variant: "dashed",
11774
+ orientation: "vertical"
11775
+ }
11776
+ ) }),
11777
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11778
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11779
+ ui.Text,
11780
+ {
11781
+ size: "small",
11782
+ leading: "compact",
11783
+ className: "text-ui-fg-subtle",
11784
+ children: [
11785
+ item.quantity,
11786
+ "x"
11787
+ ]
11788
+ }
11789
+ ) }),
11790
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11791
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11792
+ /* @__PURE__ */ jsxRuntime.jsxs(
11793
+ ui.Text,
11794
+ {
11795
+ size: "small",
11796
+ leading: "compact",
11797
+ weight: "plus",
11798
+ children: [
11799
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11800
+ " (",
11801
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
11802
+ ")"
11803
+ ]
11804
+ }
11805
+ ),
11806
+ /* @__PURE__ */ jsxRuntime.jsx(
11807
+ ui.Text,
11808
+ {
11809
+ size: "small",
11810
+ leading: "compact",
11811
+ className: "text-ui-fg-subtle",
11812
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11813
+ }
11814
+ )
11815
+ ] })
11816
+ ] })
11817
+ ]
11818
+ },
11819
+ item.id
11820
+ ),
11821
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11822
+ ] }, item.id);
11823
+ })
11824
+ ] })
11825
+ ]
11826
+ },
11827
+ profile.id
11828
+ );
11829
+ }) })
11830
+ ] }) })
11831
+ ] }) }),
11832
+ /* @__PURE__ */ jsxRuntime.jsx(
11833
+ StackedFocusModal,
11834
+ {
11835
+ id: STACKED_FOCUS_MODAL_ID,
11836
+ onOpenChangeCallback: (open) => {
11837
+ if (!open) {
11838
+ setData(null);
12173
11839
  }
12174
- ) }),
12175
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12176
- "rect",
11840
+ return open;
11841
+ },
11842
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11843
+ }
11844
+ )
11845
+ ] }),
11846
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11847
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11848
+ /* @__PURE__ */ jsxRuntime.jsx(
11849
+ ui.Button,
11850
+ {
11851
+ size: "small",
11852
+ type: "button",
11853
+ isLoading: isSubmitting,
11854
+ onClick: onSubmit,
11855
+ children: "Save"
11856
+ }
11857
+ )
11858
+ ] }) })
11859
+ ] });
11860
+ };
11861
+ const StackedModalTrigger = ({
11862
+ shippingProfileId,
11863
+ shippingOption,
11864
+ shippingMethod,
11865
+ setData,
11866
+ children
11867
+ }) => {
11868
+ const { setIsOpen, getIsOpen } = useStackedModal();
11869
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11870
+ const onToggle = () => {
11871
+ if (isOpen) {
11872
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11873
+ setData(null);
11874
+ } else {
11875
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11876
+ setData({
11877
+ shippingProfileId,
11878
+ shippingOption,
11879
+ shippingMethod
11880
+ });
11881
+ }
11882
+ };
11883
+ return /* @__PURE__ */ jsxRuntime.jsx(
11884
+ ui.Button,
11885
+ {
11886
+ size: "small",
11887
+ variant: "secondary",
11888
+ onClick: onToggle,
11889
+ className: "text-ui-fg-primary shrink-0",
11890
+ children
11891
+ }
11892
+ );
11893
+ };
11894
+ const ShippingProfileForm = ({
11895
+ data,
11896
+ order,
11897
+ preview
11898
+ }) => {
11899
+ var _a, _b, _c, _d, _e, _f;
11900
+ const { setIsOpen } = useStackedModal();
11901
+ const form = reactHookForm.useForm({
11902
+ resolver: zod.zodResolver(shippingMethodSchema),
11903
+ defaultValues: {
11904
+ 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,
11905
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11906
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11907
+ }
11908
+ });
11909
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11910
+ const {
11911
+ mutateAsync: updateShippingMethod,
11912
+ isPending: isUpdatingShippingMethod
11913
+ } = useDraftOrderUpdateShippingMethod(order.id);
11914
+ const onSubmit = form.handleSubmit(async (values) => {
11915
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
11916
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11917
+ return;
11918
+ }
11919
+ if (data.shippingMethod) {
11920
+ await updateShippingMethod(
11921
+ {
11922
+ method_id: data.shippingMethod.id,
11923
+ shipping_option_id: values.shipping_option_id,
11924
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11925
+ },
11926
+ {
11927
+ onError: (e) => {
11928
+ ui.toast.error(e.message);
11929
+ },
11930
+ onSuccess: () => {
11931
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11932
+ }
11933
+ }
11934
+ );
11935
+ return;
11936
+ }
11937
+ await addShippingMethod(
11938
+ {
11939
+ shipping_option_id: values.shipping_option_id,
11940
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11941
+ },
11942
+ {
11943
+ onError: (e) => {
11944
+ ui.toast.error(e.message);
11945
+ },
11946
+ onSuccess: () => {
11947
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11948
+ }
11949
+ }
11950
+ );
11951
+ });
11952
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11953
+ KeyboundForm,
11954
+ {
11955
+ className: "flex h-full flex-col overflow-hidden",
11956
+ onSubmit,
11957
+ children: [
11958
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11959
+ /* @__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: [
11960
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11961
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11962
+ /* @__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." }) })
11963
+ ] }),
11964
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11965
+ /* @__PURE__ */ jsxRuntime.jsx(
11966
+ LocationField,
12177
11967
  {
12178
- width: "12",
12179
- height: "12",
12180
- fill: "white",
12181
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11968
+ control: form.control,
11969
+ setValue: form.setValue
12182
11970
  }
12183
- ) }),
12184
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12185
- "rect",
11971
+ ),
11972
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11973
+ /* @__PURE__ */ jsxRuntime.jsx(
11974
+ ShippingOptionField,
12186
11975
  {
12187
- width: "12",
12188
- height: "12",
12189
- fill: "white",
12190
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11976
+ shippingProfileId: data.shippingProfileId,
11977
+ preview,
11978
+ control: form.control
12191
11979
  }
12192
- ) }),
12193
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12194
- "rect",
11980
+ ),
11981
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11982
+ /* @__PURE__ */ jsxRuntime.jsx(
11983
+ CustomAmountField,
12195
11984
  {
12196
- width: "12",
12197
- height: "12",
12198
- fill: "white",
12199
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
11985
+ control: form.control,
11986
+ currencyCode: order.currency_code
12200
11987
  }
12201
- ) }),
12202
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12203
- "rect",
11988
+ ),
11989
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11990
+ /* @__PURE__ */ jsxRuntime.jsx(
11991
+ ItemsPreview,
12204
11992
  {
12205
- width: "12",
12206
- height: "12",
12207
- fill: "white",
12208
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
11993
+ order,
11994
+ shippingProfileId: data.shippingProfileId
12209
11995
  }
12210
- ) }),
12211
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12212
- "rect",
11996
+ )
11997
+ ] }) }) }),
11998
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11999
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12000
+ /* @__PURE__ */ jsxRuntime.jsx(
12001
+ ui.Button,
12213
12002
  {
12214
- width: "12",
12215
- height: "12",
12216
- fill: "white",
12217
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12003
+ size: "small",
12004
+ type: "submit",
12005
+ isLoading: isPending || isUpdatingShippingMethod,
12006
+ children: data.shippingMethod ? "Update" : "Add"
12218
12007
  }
12219
- ) })
12220
- ] })
12008
+ )
12009
+ ] }) })
12221
12010
  ]
12222
12011
  }
12223
- );
12012
+ ) }) });
12224
12013
  };
12225
- const schema = objectType({
12226
- customer_id: stringType().min(1)
12014
+ const shippingMethodSchema = objectType({
12015
+ location_id: stringType(),
12016
+ shipping_option_id: stringType(),
12017
+ custom_amount: unionType([numberType(), stringType()]).optional()
12227
12018
  });
12228
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12229
- const Shipping = () => {
12230
- var _a;
12231
- const { id } = reactRouterDom.useParams();
12232
- const { order, isPending, isError, error } = useOrder(id, {
12233
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12234
- });
12235
- const {
12236
- order: preview,
12237
- isPending: isPreviewPending,
12238
- isError: isPreviewError,
12239
- error: previewError
12240
- } = useOrderPreview(id);
12241
- useInitiateOrderEdit({ preview });
12242
- const { onCancel } = useCancelOrderEdit({ preview });
12243
- if (isError) {
12244
- throw error;
12245
- }
12246
- if (isPreviewError) {
12247
- throw previewError;
12248
- }
12249
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12250
- const isReady = preview && !isPreviewPending && order && !isPending;
12251
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12252
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12253
- /* @__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: [
12254
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12255
- /* @__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." }) })
12256
- ] }) }) }),
12257
- /* @__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" }) }) })
12258
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12259
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12260
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12261
- ] }) });
12262
- };
12263
- const ShippingForm = ({ preview, order }) => {
12264
- var _a;
12265
- const { setIsOpen } = useStackedModal();
12266
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12267
- const [data, setData] = React.useState(null);
12268
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12269
- const { shipping_options } = useShippingOptions(
12270
- {
12271
- id: appliedShippingOptionIds,
12272
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12273
- },
12274
- {
12275
- enabled: appliedShippingOptionIds.length > 0
12276
- }
12277
- );
12278
- const uniqueShippingProfiles = React.useMemo(() => {
12279
- const profiles = /* @__PURE__ */ new Map();
12280
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12281
- profiles.set(profile.id, profile);
12282
- });
12283
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12284
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12285
- });
12286
- return Array.from(profiles.values());
12287
- }, [order.items, shipping_options]);
12288
- const { handleSuccess } = useRouteModal();
12289
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12290
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12291
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12292
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12293
- const onSubmit = async () => {
12294
- setIsSubmitting(true);
12295
- let requestSucceeded = false;
12296
- await requestOrderEdit(void 0, {
12297
- onError: (e) => {
12298
- ui.toast.error(`Failed to request order edit: ${e.message}`);
12299
- },
12300
- onSuccess: () => {
12301
- requestSucceeded = true;
12302
- }
12303
- });
12304
- if (!requestSucceeded) {
12305
- setIsSubmitting(false);
12306
- return;
12019
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12020
+ const matches = order.items.filter(
12021
+ (item) => {
12022
+ var _a, _b, _c;
12023
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12307
12024
  }
12308
- await confirmOrderEdit(void 0, {
12309
- onError: (e) => {
12310
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12311
- },
12312
- onSuccess: () => {
12313
- handleSuccess();
12314
- },
12315
- onSettled: () => {
12316
- setIsSubmitting(false);
12317
- }
12318
- });
12319
- };
12320
- const onKeydown = React.useCallback(
12321
- (e) => {
12322
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12323
- if (data || isSubmitting) {
12324
- return;
12325
- }
12326
- onSubmit();
12327
- }
12328
- },
12329
- [data, isSubmitting, onSubmit]
12330
12025
  );
12331
- React.useEffect(() => {
12332
- document.addEventListener("keydown", onKeydown);
12333
- return () => {
12334
- document.removeEventListener("keydown", onKeydown);
12335
- };
12336
- }, [onKeydown]);
12337
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12338
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12339
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12340
- /* @__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: [
12341
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12342
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12343
- /* @__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." }) })
12344
- ] }),
12345
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12346
- /* @__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: [
12347
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12348
- /* @__PURE__ */ jsxRuntime.jsx(
12349
- ui.Text,
12350
- {
12351
- size: "xsmall",
12352
- weight: "plus",
12353
- className: "text-ui-fg-muted",
12354
- children: "Shipping profile"
12355
- }
12356
- ),
12357
- /* @__PURE__ */ jsxRuntime.jsx(
12358
- ui.Text,
12359
- {
12360
- size: "xsmall",
12361
- weight: "plus",
12362
- className: "text-ui-fg-muted",
12363
- children: "Action"
12364
- }
12365
- )
12366
- ] }),
12367
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12368
- var _a2, _b, _c, _d, _e, _f, _g;
12369
- const items = getItemsWithShippingProfile(
12370
- profile.id,
12371
- order.items
12372
- );
12373
- const hasItems = items.length > 0;
12374
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12375
- (option) => option.shipping_profile_id === profile.id
12376
- );
12377
- const shippingMethod = preview.shipping_methods.find(
12378
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12379
- );
12380
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
12381
- (action) => action.action === "SHIPPING_ADD"
12382
- );
12383
- return /* @__PURE__ */ jsxRuntime.jsxs(
12384
- radixUi.Accordion.Item,
12026
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12027
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12028
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12029
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12030
+ ] }) }),
12031
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12032
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12033
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12034
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12035
+ ] }),
12036
+ /* @__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(
12037
+ "div",
12038
+ {
12039
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12040
+ children: [
12041
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12042
+ /* @__PURE__ */ jsxRuntime.jsx(
12043
+ Thumbnail,
12044
+ {
12045
+ thumbnail: item.thumbnail,
12046
+ alt: item.product_title ?? void 0
12047
+ }
12048
+ ),
12049
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12050
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12051
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12052
+ /* @__PURE__ */ jsxRuntime.jsxs(
12053
+ ui.Text,
12054
+ {
12055
+ size: "small",
12056
+ leading: "compact",
12057
+ className: "text-ui-fg-subtle",
12058
+ children: [
12059
+ "(",
12060
+ item.variant_title,
12061
+ ")"
12062
+ ]
12063
+ }
12064
+ )
12065
+ ] }),
12066
+ /* @__PURE__ */ jsxRuntime.jsx(
12067
+ ui.Text,
12068
+ {
12069
+ size: "small",
12070
+ leading: "compact",
12071
+ className: "text-ui-fg-subtle",
12072
+ children: item.variant_sku
12073
+ }
12074
+ )
12075
+ ] })
12076
+ ] }),
12077
+ /* @__PURE__ */ jsxRuntime.jsxs(
12078
+ ui.Text,
12385
12079
  {
12386
- value: profile.id,
12387
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12080
+ size: "small",
12081
+ leading: "compact",
12082
+ className: "text-ui-fg-subtle",
12388
12083
  children: [
12389
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
12390
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
12391
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
12392
- ui.IconButton,
12393
- {
12394
- size: "2xsmall",
12395
- variant: "transparent",
12396
- className: "group/trigger",
12397
- disabled: !hasItems,
12398
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
12399
- }
12400
- ) }),
12401
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12402
- /* @__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" }) }) }),
12403
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
12404
- /* @__PURE__ */ jsxRuntime.jsx(
12405
- ui.Text,
12406
- {
12407
- size: "small",
12408
- weight: "plus",
12409
- leading: "compact",
12410
- children: profile.name
12411
- }
12412
- ),
12413
- /* @__PURE__ */ jsxRuntime.jsxs(
12414
- ui.Text,
12415
- {
12416
- size: "small",
12417
- leading: "compact",
12418
- className: "text-ui-fg-subtle",
12419
- children: [
12420
- items.length,
12421
- " ",
12422
- pluralize(items.length, "items", "item")
12423
- ]
12424
- }
12425
- )
12426
- ] })
12427
- ] }) : /* @__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: [
12428
- /* @__PURE__ */ jsxRuntime.jsx(
12429
- ui.Tooltip,
12430
- {
12431
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
12432
- var _a3, _b2, _c2;
12433
- return /* @__PURE__ */ jsxRuntime.jsx(
12434
- "li",
12435
- {
12436
- 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})`
12437
- },
12438
- item.id
12439
- );
12440
- }) }),
12441
- children: /* @__PURE__ */ jsxRuntime.jsxs(
12442
- ui.Badge,
12443
- {
12444
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12445
- size: "xsmall",
12446
- children: [
12447
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
12448
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
12449
- items.reduce(
12450
- (acc, item) => acc + item.quantity,
12451
- 0
12452
- ),
12453
- "x",
12454
- " ",
12455
- pluralize(items.length, "items", "item")
12456
- ] })
12457
- ]
12458
- }
12459
- )
12460
- }
12461
- ),
12462
- /* @__PURE__ */ jsxRuntime.jsx(
12463
- ui.Tooltip,
12464
- {
12465
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12466
- children: /* @__PURE__ */ jsxRuntime.jsxs(
12467
- ui.Badge,
12468
- {
12469
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12470
- size: "xsmall",
12471
- children: [
12472
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12473
- /* @__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 })
12474
- ]
12475
- }
12476
- )
12477
- }
12478
- ),
12479
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12480
- ui.Badge,
12481
- {
12482
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12483
- size: "xsmall",
12484
- children: [
12485
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12486
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12487
- ]
12488
- }
12489
- ) })
12490
- ] })
12491
- ] }),
12492
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12493
- ActionMenu,
12494
- {
12495
- groups: [
12496
- {
12497
- actions: [
12498
- hasItems ? {
12499
- label: "Edit shipping option",
12500
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12501
- onClick: () => {
12502
- setIsOpen(
12503
- STACKED_FOCUS_MODAL_ID,
12504
- true
12505
- );
12506
- setData({
12507
- shippingProfileId: profile.id,
12508
- shippingOption,
12509
- shippingMethod
12510
- });
12511
- }
12512
- } : void 0,
12513
- {
12514
- label: "Remove shipping option",
12515
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12516
- onClick: () => {
12517
- if (shippingMethod) {
12518
- if (addShippingMethodAction) {
12519
- removeActionShippingMethod(
12520
- addShippingMethodAction.id
12521
- );
12522
- } else {
12523
- removeShippingMethod(
12524
- shippingMethod.id
12525
- );
12526
- }
12527
- }
12528
- }
12529
- }
12530
- ].filter(Boolean)
12531
- }
12532
- ]
12533
- }
12534
- ) : /* @__PURE__ */ jsxRuntime.jsx(
12535
- StackedModalTrigger,
12536
- {
12537
- shippingProfileId: profile.id,
12538
- shippingOption,
12539
- shippingMethod,
12540
- setData,
12541
- children: "Add shipping option"
12542
- }
12543
- )
12544
- ] }),
12545
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12546
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12547
- items.map((item, idx) => {
12548
- var _a3, _b2, _c2, _d2, _e2;
12549
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12550
- /* @__PURE__ */ jsxRuntime.jsxs(
12551
- "div",
12552
- {
12553
- className: "px-3 flex items-center gap-x-3",
12554
- children: [
12555
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12556
- ui.Divider,
12557
- {
12558
- variant: "dashed",
12559
- orientation: "vertical"
12560
- }
12561
- ) }),
12562
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12563
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12564
- ui.Text,
12565
- {
12566
- size: "small",
12567
- leading: "compact",
12568
- className: "text-ui-fg-subtle",
12569
- children: [
12570
- item.quantity,
12571
- "x"
12572
- ]
12573
- }
12574
- ) }),
12575
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12576
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12577
- /* @__PURE__ */ jsxRuntime.jsxs(
12578
- ui.Text,
12579
- {
12580
- size: "small",
12581
- leading: "compact",
12582
- weight: "plus",
12583
- children: [
12584
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12585
- " (",
12586
- (_c2 = item.variant) == null ? void 0 : _c2.title,
12587
- ")"
12588
- ]
12589
- }
12590
- ),
12591
- /* @__PURE__ */ jsxRuntime.jsx(
12592
- ui.Text,
12593
- {
12594
- size: "small",
12595
- leading: "compact",
12596
- className: "text-ui-fg-subtle",
12597
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12598
- }
12599
- )
12600
- ] })
12601
- ] })
12602
- ]
12603
- },
12604
- item.id
12605
- ),
12606
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12607
- ] }, item.id);
12608
- })
12609
- ] })
12084
+ item.quantity,
12085
+ "x"
12610
12086
  ]
12087
+ }
12088
+ )
12089
+ ]
12090
+ },
12091
+ item.id
12092
+ )) : /* @__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: [
12093
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12094
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12095
+ 'No items found for "',
12096
+ query,
12097
+ '".'
12098
+ ] })
12099
+ ] }) })
12100
+ ] })
12101
+ ] });
12102
+ };
12103
+ const LocationField = ({ control, setValue }) => {
12104
+ const locations = useComboboxData({
12105
+ queryKey: ["locations"],
12106
+ queryFn: async (params) => {
12107
+ return await sdk.admin.stockLocation.list(params);
12108
+ },
12109
+ getOptions: (data) => {
12110
+ return data.stock_locations.map((location) => ({
12111
+ label: location.name,
12112
+ value: location.id
12113
+ }));
12114
+ }
12115
+ });
12116
+ return /* @__PURE__ */ jsxRuntime.jsx(
12117
+ Form$2.Field,
12118
+ {
12119
+ control,
12120
+ name: "location_id",
12121
+ render: ({ field: { onChange, ...field } }) => {
12122
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12123
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12124
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12125
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12126
+ ] }),
12127
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12128
+ Combobox,
12129
+ {
12130
+ options: locations.options,
12131
+ fetchNextPage: locations.fetchNextPage,
12132
+ isFetchingNextPage: locations.isFetchingNextPage,
12133
+ searchValue: locations.searchValue,
12134
+ onSearchValueChange: locations.onSearchValueChange,
12135
+ placeholder: "Select location",
12136
+ onChange: (value) => {
12137
+ setValue("shipping_option_id", "", {
12138
+ shouldDirty: true,
12139
+ shouldTouch: true
12140
+ });
12141
+ onChange(value);
12611
12142
  },
12612
- profile.id
12613
- );
12614
- }) })
12615
- ] }) })
12616
- ] }) }),
12617
- /* @__PURE__ */ jsxRuntime.jsx(
12618
- StackedFocusModal,
12619
- {
12620
- id: STACKED_FOCUS_MODAL_ID,
12621
- onOpenChangeCallback: (open) => {
12622
- if (!open) {
12623
- setData(null);
12143
+ ...field
12144
+ }
12145
+ ) })
12146
+ ] }) });
12147
+ }
12148
+ }
12149
+ );
12150
+ };
12151
+ const ShippingOptionField = ({
12152
+ shippingProfileId,
12153
+ preview,
12154
+ control
12155
+ }) => {
12156
+ var _a;
12157
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12158
+ const shippingOptions = useComboboxData({
12159
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12160
+ queryFn: async (params) => {
12161
+ return await sdk.admin.shippingOption.list({
12162
+ ...params,
12163
+ stock_location_id: locationId,
12164
+ shipping_profile_id: shippingProfileId
12165
+ });
12166
+ },
12167
+ getOptions: (data) => {
12168
+ return data.shipping_options.map((option) => {
12169
+ var _a2;
12170
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12171
+ (r) => r.attribute === "is_return" && r.value === "true"
12172
+ )) {
12173
+ return void 0;
12174
+ }
12175
+ return {
12176
+ label: option.name,
12177
+ value: option.id
12178
+ };
12179
+ }).filter(Boolean);
12180
+ },
12181
+ enabled: !!locationId && !!shippingProfileId,
12182
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12183
+ });
12184
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12185
+ return /* @__PURE__ */ jsxRuntime.jsx(
12186
+ Form$2.Field,
12187
+ {
12188
+ control,
12189
+ name: "shipping_option_id",
12190
+ render: ({ field }) => {
12191
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12192
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12193
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12194
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12195
+ ] }),
12196
+ /* @__PURE__ */ jsxRuntime.jsx(
12197
+ ConditionalTooltip,
12198
+ {
12199
+ content: tooltipContent,
12200
+ showTooltip: !locationId || !shippingProfileId,
12201
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12202
+ Combobox,
12203
+ {
12204
+ options: shippingOptions.options,
12205
+ fetchNextPage: shippingOptions.fetchNextPage,
12206
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12207
+ searchValue: shippingOptions.searchValue,
12208
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12209
+ placeholder: "Select shipping option",
12210
+ ...field,
12211
+ disabled: !locationId || !shippingProfileId
12212
+ }
12213
+ ) }) })
12214
+ }
12215
+ )
12216
+ ] }) });
12217
+ }
12218
+ }
12219
+ );
12220
+ };
12221
+ const CustomAmountField = ({
12222
+ control,
12223
+ currencyCode
12224
+ }) => {
12225
+ return /* @__PURE__ */ jsxRuntime.jsx(
12226
+ Form$2.Field,
12227
+ {
12228
+ control,
12229
+ name: "custom_amount",
12230
+ render: ({ field: { onChange, ...field } }) => {
12231
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12232
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12233
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12234
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12235
+ ] }),
12236
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12237
+ ui.CurrencyInput,
12238
+ {
12239
+ ...field,
12240
+ onValueChange: (value) => onChange(value),
12241
+ symbol: getNativeSymbol(currencyCode),
12242
+ code: currencyCode
12243
+ }
12244
+ ) })
12245
+ ] });
12246
+ }
12247
+ }
12248
+ );
12249
+ };
12250
+ const ShippingAddress = () => {
12251
+ const { id } = reactRouterDom.useParams();
12252
+ const { order, isPending, isError, error } = useOrder(id, {
12253
+ fields: "+shipping_address"
12254
+ });
12255
+ if (isError) {
12256
+ throw error;
12257
+ }
12258
+ const isReady = !isPending && !!order;
12259
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12260
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12261
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12262
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12263
+ ] }),
12264
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12265
+ ] });
12266
+ };
12267
+ const ShippingAddressForm = ({ order }) => {
12268
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12269
+ const form = reactHookForm.useForm({
12270
+ defaultValues: {
12271
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12272
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12273
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12274
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12275
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12276
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12277
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12278
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12279
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12280
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12281
+ },
12282
+ resolver: zod.zodResolver(schema$2)
12283
+ });
12284
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12285
+ const { handleSuccess } = useRouteModal();
12286
+ const onSubmit = form.handleSubmit(async (data) => {
12287
+ await mutateAsync(
12288
+ {
12289
+ shipping_address: {
12290
+ first_name: data.first_name,
12291
+ last_name: data.last_name,
12292
+ company: data.company,
12293
+ address_1: data.address_1,
12294
+ address_2: data.address_2,
12295
+ city: data.city,
12296
+ province: data.province,
12297
+ country_code: data.country_code,
12298
+ postal_code: data.postal_code,
12299
+ phone: data.phone
12300
+ }
12301
+ },
12302
+ {
12303
+ onSuccess: () => {
12304
+ handleSuccess();
12305
+ },
12306
+ onError: (error) => {
12307
+ ui.toast.error(error.message);
12308
+ }
12309
+ }
12310
+ );
12311
+ });
12312
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12313
+ KeyboundForm,
12314
+ {
12315
+ className: "flex flex-1 flex-col overflow-hidden",
12316
+ onSubmit,
12317
+ children: [
12318
+ /* @__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: [
12319
+ /* @__PURE__ */ jsxRuntime.jsx(
12320
+ Form$2.Field,
12321
+ {
12322
+ control: form.control,
12323
+ name: "country_code",
12324
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12325
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12326
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12327
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12328
+ ] })
12329
+ }
12330
+ ),
12331
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12332
+ /* @__PURE__ */ jsxRuntime.jsx(
12333
+ Form$2.Field,
12334
+ {
12335
+ control: form.control,
12336
+ name: "first_name",
12337
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12338
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12339
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12340
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12341
+ ] })
12342
+ }
12343
+ ),
12344
+ /* @__PURE__ */ jsxRuntime.jsx(
12345
+ Form$2.Field,
12346
+ {
12347
+ control: form.control,
12348
+ name: "last_name",
12349
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12350
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12351
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12353
+ ] })
12354
+ }
12355
+ )
12356
+ ] }),
12357
+ /* @__PURE__ */ jsxRuntime.jsx(
12358
+ Form$2.Field,
12359
+ {
12360
+ control: form.control,
12361
+ name: "company",
12362
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12363
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12364
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12365
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12366
+ ] })
12624
12367
  }
12625
- return open;
12626
- },
12627
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12628
- }
12629
- )
12368
+ ),
12369
+ /* @__PURE__ */ jsxRuntime.jsx(
12370
+ Form$2.Field,
12371
+ {
12372
+ control: form.control,
12373
+ name: "address_1",
12374
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12375
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12376
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12377
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12378
+ ] })
12379
+ }
12380
+ ),
12381
+ /* @__PURE__ */ jsxRuntime.jsx(
12382
+ Form$2.Field,
12383
+ {
12384
+ control: form.control,
12385
+ name: "address_2",
12386
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12387
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12388
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12389
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12390
+ ] })
12391
+ }
12392
+ ),
12393
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12394
+ /* @__PURE__ */ jsxRuntime.jsx(
12395
+ Form$2.Field,
12396
+ {
12397
+ control: form.control,
12398
+ name: "postal_code",
12399
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12400
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12401
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12402
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12403
+ ] })
12404
+ }
12405
+ ),
12406
+ /* @__PURE__ */ jsxRuntime.jsx(
12407
+ Form$2.Field,
12408
+ {
12409
+ control: form.control,
12410
+ name: "city",
12411
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12412
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12413
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12414
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12415
+ ] })
12416
+ }
12417
+ )
12418
+ ] }),
12419
+ /* @__PURE__ */ jsxRuntime.jsx(
12420
+ Form$2.Field,
12421
+ {
12422
+ control: form.control,
12423
+ name: "province",
12424
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12425
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12426
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12427
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12428
+ ] })
12429
+ }
12430
+ ),
12431
+ /* @__PURE__ */ jsxRuntime.jsx(
12432
+ Form$2.Field,
12433
+ {
12434
+ control: form.control,
12435
+ name: "phone",
12436
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12437
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12438
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12439
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12440
+ ] })
12441
+ }
12442
+ )
12443
+ ] }) }),
12444
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12445
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12446
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12447
+ ] }) })
12448
+ ]
12449
+ }
12450
+ ) });
12451
+ };
12452
+ const schema$2 = addressSchema;
12453
+ const TransferOwnership = () => {
12454
+ const { id } = reactRouterDom.useParams();
12455
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12456
+ fields: "id,customer_id,customer.*"
12457
+ });
12458
+ if (isError) {
12459
+ throw error;
12460
+ }
12461
+ const isReady = !isPending && !!draft_order;
12462
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12463
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12464
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12465
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12630
12466
  ] }),
12631
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12632
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12633
- /* @__PURE__ */ jsxRuntime.jsx(
12634
- ui.Button,
12635
- {
12636
- size: "small",
12637
- type: "button",
12638
- isLoading: isSubmitting,
12639
- onClick: onSubmit,
12640
- children: "Save"
12641
- }
12642
- )
12643
- ] }) })
12467
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12644
12468
  ] });
12645
12469
  };
12646
- const StackedModalTrigger = ({
12647
- shippingProfileId,
12648
- shippingOption,
12649
- shippingMethod,
12650
- setData,
12651
- children
12652
- }) => {
12653
- const { setIsOpen, getIsOpen } = useStackedModal();
12654
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12655
- const onToggle = () => {
12656
- if (isOpen) {
12657
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12658
- setData(null);
12659
- } else {
12660
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12661
- setData({
12662
- shippingProfileId,
12663
- shippingOption,
12664
- shippingMethod
12665
- });
12666
- }
12667
- };
12668
- return /* @__PURE__ */ jsxRuntime.jsx(
12669
- ui.Button,
12470
+ const TransferOwnershipForm = ({ order }) => {
12471
+ var _a, _b;
12472
+ const form = reactHookForm.useForm({
12473
+ defaultValues: {
12474
+ customer_id: order.customer_id || ""
12475
+ },
12476
+ resolver: zod.zodResolver(schema$1)
12477
+ });
12478
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12479
+ const { handleSuccess } = useRouteModal();
12480
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12481
+ const currentCustomer = order.customer ? {
12482
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12483
+ value: order.customer.id
12484
+ } : null;
12485
+ const onSubmit = form.handleSubmit(async (data) => {
12486
+ await mutateAsync(
12487
+ { customer_id: data.customer_id },
12488
+ {
12489
+ onSuccess: () => {
12490
+ ui.toast.success("Customer updated");
12491
+ handleSuccess();
12492
+ },
12493
+ onError: (error) => {
12494
+ ui.toast.error(error.message);
12495
+ }
12496
+ }
12497
+ );
12498
+ });
12499
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12500
+ KeyboundForm,
12670
12501
  {
12671
- size: "small",
12672
- variant: "secondary",
12673
- onClick: onToggle,
12674
- className: "text-ui-fg-primary shrink-0",
12675
- children
12502
+ className: "flex flex-1 flex-col overflow-hidden",
12503
+ onSubmit,
12504
+ children: [
12505
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12506
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12507
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12508
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12509
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12510
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12511
+ ] }),
12512
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12513
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12514
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12515
+ ] })
12516
+ ] }),
12517
+ /* @__PURE__ */ jsxRuntime.jsx(
12518
+ CustomerField,
12519
+ {
12520
+ control: form.control,
12521
+ currentCustomerId: order.customer_id
12522
+ }
12523
+ )
12524
+ ] }),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12526
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12527
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12528
+ ] }) })
12529
+ ]
12676
12530
  }
12677
- );
12531
+ ) });
12678
12532
  };
12679
- const ShippingProfileForm = ({
12680
- data,
12681
- order,
12682
- preview
12683
- }) => {
12684
- var _a, _b, _c, _d, _e, _f;
12685
- const { setIsOpen } = useStackedModal();
12686
- const form = reactHookForm.useForm({
12687
- resolver: zod.zodResolver(shippingMethodSchema),
12688
- defaultValues: {
12689
- 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,
12690
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12691
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12533
+ const CustomerField = ({ control, currentCustomerId }) => {
12534
+ const customers = useComboboxData({
12535
+ queryFn: async (params) => {
12536
+ return await sdk.admin.customer.list({
12537
+ ...params,
12538
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12539
+ });
12540
+ },
12541
+ queryKey: ["customers"],
12542
+ getOptions: (data) => {
12543
+ return data.customers.map((customer) => {
12544
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12545
+ return {
12546
+ label: name ? `${name} (${customer.email})` : customer.email,
12547
+ value: customer.id
12548
+ };
12549
+ });
12692
12550
  }
12693
12551
  });
12694
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12695
- const {
12696
- mutateAsync: updateShippingMethod,
12697
- isPending: isUpdatingShippingMethod
12698
- } = useDraftOrderUpdateShippingMethod(order.id);
12699
- const onSubmit = form.handleSubmit(async (values) => {
12700
- if (lodash.isEqual(values, form.formState.defaultValues)) {
12701
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12702
- return;
12552
+ return /* @__PURE__ */ jsxRuntime.jsx(
12553
+ Form$2.Field,
12554
+ {
12555
+ name: "customer_id",
12556
+ control,
12557
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12558
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12559
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12560
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12561
+ ] }),
12562
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12563
+ Combobox,
12564
+ {
12565
+ options: customers.options,
12566
+ fetchNextPage: customers.fetchNextPage,
12567
+ isFetchingNextPage: customers.isFetchingNextPage,
12568
+ searchValue: customers.searchValue,
12569
+ onSearchValueChange: customers.onSearchValueChange,
12570
+ placeholder: "Select customer",
12571
+ ...field
12572
+ }
12573
+ ) }),
12574
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12575
+ ] })
12703
12576
  }
12704
- if (data.shippingMethod) {
12705
- await updateShippingMethod(
12706
- {
12707
- method_id: data.shippingMethod.id,
12708
- shipping_option_id: values.shipping_option_id,
12709
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12710
- },
12711
- {
12712
- onError: (e) => {
12713
- ui.toast.error(e.message);
12714
- },
12715
- onSuccess: () => {
12716
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12577
+ );
12578
+ };
12579
+ const Illustration = () => {
12580
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12581
+ "svg",
12582
+ {
12583
+ width: "280",
12584
+ height: "180",
12585
+ viewBox: "0 0 280 180",
12586
+ fill: "none",
12587
+ xmlns: "http://www.w3.org/2000/svg",
12588
+ children: [
12589
+ /* @__PURE__ */ jsxRuntime.jsx(
12590
+ "rect",
12591
+ {
12592
+ x: "0.00428286",
12593
+ y: "-0.742904",
12594
+ width: "33.5",
12595
+ height: "65.5",
12596
+ rx: "6.75",
12597
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12598
+ fill: "#D4D4D8",
12599
+ stroke: "#52525B",
12600
+ strokeWidth: "1.5"
12601
+ }
12602
+ ),
12603
+ /* @__PURE__ */ jsxRuntime.jsx(
12604
+ "rect",
12605
+ {
12606
+ x: "0.00428286",
12607
+ y: "-0.742904",
12608
+ width: "33.5",
12609
+ height: "65.5",
12610
+ rx: "6.75",
12611
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12612
+ fill: "white",
12613
+ stroke: "#52525B",
12614
+ strokeWidth: "1.5"
12615
+ }
12616
+ ),
12617
+ /* @__PURE__ */ jsxRuntime.jsx(
12618
+ "path",
12619
+ {
12620
+ d: "M180.579 107.142L179.126 107.959",
12621
+ stroke: "#52525B",
12622
+ strokeWidth: "1.5",
12623
+ strokeLinecap: "round",
12624
+ strokeLinejoin: "round"
12625
+ }
12626
+ ),
12627
+ /* @__PURE__ */ jsxRuntime.jsx(
12628
+ "path",
12629
+ {
12630
+ opacity: "0.88",
12631
+ d: "M182.305 109.546L180.257 109.534",
12632
+ stroke: "#52525B",
12633
+ strokeWidth: "1.5",
12634
+ strokeLinecap: "round",
12635
+ strokeLinejoin: "round"
12636
+ }
12637
+ ),
12638
+ /* @__PURE__ */ jsxRuntime.jsx(
12639
+ "path",
12640
+ {
12641
+ opacity: "0.75",
12642
+ d: "M180.551 111.93L179.108 111.096",
12643
+ stroke: "#52525B",
12644
+ strokeWidth: "1.5",
12645
+ strokeLinecap: "round",
12646
+ strokeLinejoin: "round"
12647
+ }
12648
+ ),
12649
+ /* @__PURE__ */ jsxRuntime.jsx(
12650
+ "path",
12651
+ {
12652
+ opacity: "0.63",
12653
+ d: "M176.347 112.897L176.354 111.73",
12654
+ stroke: "#52525B",
12655
+ strokeWidth: "1.5",
12656
+ strokeLinecap: "round",
12657
+ strokeLinejoin: "round"
12658
+ }
12659
+ ),
12660
+ /* @__PURE__ */ jsxRuntime.jsx(
12661
+ "path",
12662
+ {
12663
+ opacity: "0.5",
12664
+ d: "M172.153 111.881L173.606 111.064",
12665
+ stroke: "#52525B",
12666
+ strokeWidth: "1.5",
12667
+ strokeLinecap: "round",
12668
+ strokeLinejoin: "round"
12669
+ }
12670
+ ),
12671
+ /* @__PURE__ */ jsxRuntime.jsx(
12672
+ "path",
12673
+ {
12674
+ opacity: "0.38",
12675
+ d: "M170.428 109.478L172.476 109.489",
12676
+ stroke: "#52525B",
12677
+ strokeWidth: "1.5",
12678
+ strokeLinecap: "round",
12679
+ strokeLinejoin: "round"
12680
+ }
12681
+ ),
12682
+ /* @__PURE__ */ jsxRuntime.jsx(
12683
+ "path",
12684
+ {
12685
+ opacity: "0.25",
12686
+ d: "M172.181 107.094L173.624 107.928",
12687
+ stroke: "#52525B",
12688
+ strokeWidth: "1.5",
12689
+ strokeLinecap: "round",
12690
+ strokeLinejoin: "round"
12691
+ }
12692
+ ),
12693
+ /* @__PURE__ */ jsxRuntime.jsx(
12694
+ "path",
12695
+ {
12696
+ opacity: "0.13",
12697
+ d: "M176.386 106.126L176.379 107.294",
12698
+ stroke: "#52525B",
12699
+ strokeWidth: "1.5",
12700
+ strokeLinecap: "round",
12701
+ strokeLinejoin: "round"
12702
+ }
12703
+ ),
12704
+ /* @__PURE__ */ jsxRuntime.jsx(
12705
+ "rect",
12706
+ {
12707
+ width: "12",
12708
+ height: "3",
12709
+ rx: "1.5",
12710
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12711
+ fill: "#D4D4D8"
12712
+ }
12713
+ ),
12714
+ /* @__PURE__ */ jsxRuntime.jsx(
12715
+ "rect",
12716
+ {
12717
+ x: "0.00428286",
12718
+ y: "-0.742904",
12719
+ width: "33.5",
12720
+ height: "65.5",
12721
+ rx: "6.75",
12722
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12723
+ fill: "#D4D4D8",
12724
+ stroke: "#52525B",
12725
+ strokeWidth: "1.5"
12726
+ }
12727
+ ),
12728
+ /* @__PURE__ */ jsxRuntime.jsx(
12729
+ "rect",
12730
+ {
12731
+ x: "0.00428286",
12732
+ y: "-0.742904",
12733
+ width: "33.5",
12734
+ height: "65.5",
12735
+ rx: "6.75",
12736
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12737
+ fill: "white",
12738
+ stroke: "#52525B",
12739
+ strokeWidth: "1.5"
12740
+ }
12741
+ ),
12742
+ /* @__PURE__ */ jsxRuntime.jsx(
12743
+ "rect",
12744
+ {
12745
+ width: "12",
12746
+ height: "3",
12747
+ rx: "1.5",
12748
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12749
+ fill: "#D4D4D8"
12750
+ }
12751
+ ),
12752
+ /* @__PURE__ */ jsxRuntime.jsx(
12753
+ "rect",
12754
+ {
12755
+ width: "17",
12756
+ height: "3",
12757
+ rx: "1.5",
12758
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12759
+ fill: "#D4D4D8"
12760
+ }
12761
+ ),
12762
+ /* @__PURE__ */ jsxRuntime.jsx(
12763
+ "rect",
12764
+ {
12765
+ width: "12",
12766
+ height: "3",
12767
+ rx: "1.5",
12768
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12769
+ fill: "#D4D4D8"
12770
+ }
12771
+ ),
12772
+ /* @__PURE__ */ jsxRuntime.jsx(
12773
+ "path",
12774
+ {
12775
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12776
+ fill: "#A1A1AA"
12777
+ }
12778
+ ),
12779
+ /* @__PURE__ */ jsxRuntime.jsx(
12780
+ "rect",
12781
+ {
12782
+ width: "17",
12783
+ height: "3",
12784
+ rx: "1.5",
12785
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12786
+ fill: "#A1A1AA"
12717
12787
  }
12718
- }
12719
- );
12720
- return;
12721
- }
12722
- await addShippingMethod(
12723
- {
12724
- shipping_option_id: values.shipping_option_id,
12725
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12726
- },
12727
- {
12728
- onError: (e) => {
12729
- ui.toast.error(e.message);
12730
- },
12731
- onSuccess: () => {
12732
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12733
- }
12734
- }
12735
- );
12736
- });
12737
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12738
- KeyboundForm,
12739
- {
12740
- className: "flex h-full flex-col overflow-hidden",
12741
- onSubmit,
12742
- children: [
12743
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12744
- /* @__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: [
12745
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12746
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12747
- /* @__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." }) })
12748
- ] }),
12749
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12750
- /* @__PURE__ */ jsxRuntime.jsx(
12751
- LocationField,
12752
- {
12753
- control: form.control,
12754
- setValue: form.setValue
12755
- }
12756
- ),
12757
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12758
- /* @__PURE__ */ jsxRuntime.jsx(
12759
- ShippingOptionField,
12760
- {
12761
- shippingProfileId: data.shippingProfileId,
12762
- preview,
12763
- control: form.control
12764
- }
12765
- ),
12766
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12767
- /* @__PURE__ */ jsxRuntime.jsx(
12768
- CustomAmountField,
12769
- {
12770
- control: form.control,
12771
- currencyCode: order.currency_code
12772
- }
12773
- ),
12774
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12775
- /* @__PURE__ */ jsxRuntime.jsx(
12776
- ItemsPreview,
12788
+ ),
12789
+ /* @__PURE__ */ jsxRuntime.jsx(
12790
+ "rect",
12791
+ {
12792
+ width: "12",
12793
+ height: "3",
12794
+ rx: "1.5",
12795
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12796
+ fill: "#A1A1AA"
12797
+ }
12798
+ ),
12799
+ /* @__PURE__ */ jsxRuntime.jsx(
12800
+ "path",
12801
+ {
12802
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12803
+ fill: "#52525B"
12804
+ }
12805
+ ),
12806
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12807
+ "path",
12808
+ {
12809
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12810
+ stroke: "#A1A1AA",
12811
+ strokeWidth: "1.5",
12812
+ strokeLinecap: "round",
12813
+ strokeLinejoin: "round"
12814
+ }
12815
+ ) }),
12816
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12817
+ "path",
12818
+ {
12819
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12820
+ stroke: "#A1A1AA",
12821
+ strokeWidth: "1.5",
12822
+ strokeLinecap: "round",
12823
+ strokeLinejoin: "round"
12824
+ }
12825
+ ) }),
12826
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12827
+ "path",
12828
+ {
12829
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12830
+ stroke: "#A1A1AA",
12831
+ strokeWidth: "1.5",
12832
+ strokeLinecap: "round",
12833
+ strokeLinejoin: "round"
12834
+ }
12835
+ ) }),
12836
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12837
+ "path",
12838
+ {
12839
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12840
+ stroke: "#A1A1AA",
12841
+ strokeWidth: "1.5",
12842
+ strokeLinecap: "round",
12843
+ strokeLinejoin: "round"
12844
+ }
12845
+ ) }),
12846
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12847
+ "path",
12848
+ {
12849
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12850
+ stroke: "#A1A1AA",
12851
+ strokeWidth: "1.5",
12852
+ strokeLinecap: "round",
12853
+ strokeLinejoin: "round"
12854
+ }
12855
+ ) }),
12856
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12857
+ "path",
12858
+ {
12859
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12860
+ stroke: "#A1A1AA",
12861
+ strokeWidth: "1.5",
12862
+ strokeLinecap: "round",
12863
+ strokeLinejoin: "round"
12864
+ }
12865
+ ) }),
12866
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12867
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12868
+ "rect",
12777
12869
  {
12778
- order,
12779
- shippingProfileId: data.shippingProfileId
12870
+ width: "12",
12871
+ height: "12",
12872
+ fill: "white",
12873
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12780
12874
  }
12781
- )
12782
- ] }) }) }),
12783
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12784
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12785
- /* @__PURE__ */ jsxRuntime.jsx(
12786
- ui.Button,
12875
+ ) }),
12876
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12877
+ "rect",
12787
12878
  {
12788
- size: "small",
12789
- type: "submit",
12790
- isLoading: isPending || isUpdatingShippingMethod,
12791
- children: data.shippingMethod ? "Update" : "Add"
12879
+ width: "12",
12880
+ height: "12",
12881
+ fill: "white",
12882
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12792
12883
  }
12793
- )
12794
- ] }) })
12795
- ]
12796
- }
12797
- ) }) });
12798
- };
12799
- const shippingMethodSchema = objectType({
12800
- location_id: stringType(),
12801
- shipping_option_id: stringType(),
12802
- custom_amount: unionType([numberType(), stringType()]).optional()
12803
- });
12804
- const ItemsPreview = ({ order, shippingProfileId }) => {
12805
- const matches = order.items.filter(
12806
- (item) => {
12807
- var _a, _b, _c;
12808
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12809
- }
12810
- );
12811
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12812
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12813
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12814
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12815
- ] }) }),
12816
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12817
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12818
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12819
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12820
- ] }),
12821
- /* @__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(
12822
- "div",
12823
- {
12824
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12825
- children: [
12826
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12827
- /* @__PURE__ */ jsxRuntime.jsx(
12828
- Thumbnail,
12829
- {
12830
- thumbnail: item.thumbnail,
12831
- alt: item.product_title ?? void 0
12832
- }
12833
- ),
12834
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12835
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12836
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12837
- /* @__PURE__ */ jsxRuntime.jsxs(
12838
- ui.Text,
12839
- {
12840
- size: "small",
12841
- leading: "compact",
12842
- className: "text-ui-fg-subtle",
12843
- children: [
12844
- "(",
12845
- item.variant_title,
12846
- ")"
12847
- ]
12848
- }
12849
- )
12850
- ] }),
12851
- /* @__PURE__ */ jsxRuntime.jsx(
12852
- ui.Text,
12853
- {
12854
- size: "small",
12855
- leading: "compact",
12856
- className: "text-ui-fg-subtle",
12857
- children: item.variant_sku
12858
- }
12859
- )
12860
- ] })
12861
- ] }),
12862
- /* @__PURE__ */ jsxRuntime.jsxs(
12863
- ui.Text,
12864
- {
12865
- size: "small",
12866
- leading: "compact",
12867
- className: "text-ui-fg-subtle",
12868
- children: [
12869
- item.quantity,
12870
- "x"
12871
- ]
12872
- }
12873
- )
12874
- ]
12875
- },
12876
- item.id
12877
- )) : /* @__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: [
12878
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12879
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12880
- 'No items found for "',
12881
- query,
12882
- '".'
12884
+ ) }),
12885
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12886
+ "rect",
12887
+ {
12888
+ width: "12",
12889
+ height: "12",
12890
+ fill: "white",
12891
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12892
+ }
12893
+ ) }),
12894
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12895
+ "rect",
12896
+ {
12897
+ width: "12",
12898
+ height: "12",
12899
+ fill: "white",
12900
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12901
+ }
12902
+ ) }),
12903
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12904
+ "rect",
12905
+ {
12906
+ width: "12",
12907
+ height: "12",
12908
+ fill: "white",
12909
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12910
+ }
12911
+ ) }),
12912
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12913
+ "rect",
12914
+ {
12915
+ width: "12",
12916
+ height: "12",
12917
+ fill: "white",
12918
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12919
+ }
12920
+ ) })
12883
12921
  ] })
12884
- ] }) })
12885
- ] })
12886
- ] });
12922
+ ]
12923
+ }
12924
+ );
12887
12925
  };
12888
- const LocationField = ({ control, setValue }) => {
12889
- const locations = useComboboxData({
12890
- queryKey: ["locations"],
12891
- queryFn: async (params) => {
12892
- return await sdk.admin.stockLocation.list(params);
12926
+ const schema$1 = objectType({
12927
+ customer_id: stringType().min(1)
12928
+ });
12929
+ const SalesChannel = () => {
12930
+ const { id } = reactRouterDom.useParams();
12931
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12932
+ id,
12933
+ {
12934
+ fields: "+sales_channel_id"
12893
12935
  },
12894
- getOptions: (data) => {
12895
- return data.stock_locations.map((location) => ({
12896
- label: location.name,
12897
- value: location.id
12898
- }));
12936
+ {
12937
+ enabled: !!id
12899
12938
  }
12939
+ );
12940
+ if (isError) {
12941
+ throw error;
12942
+ }
12943
+ const ISrEADY = !!draft_order && !isPending;
12944
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12946
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12947
+ /* @__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" }) })
12948
+ ] }),
12949
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12950
+ ] });
12951
+ };
12952
+ const SalesChannelForm = ({ order }) => {
12953
+ const form = reactHookForm.useForm({
12954
+ defaultValues: {
12955
+ sales_channel_id: order.sales_channel_id || ""
12956
+ },
12957
+ resolver: zod.zodResolver(schema)
12900
12958
  });
12901
- return /* @__PURE__ */ jsxRuntime.jsx(
12902
- Form$2.Field,
12903
- {
12904
- control,
12905
- name: "location_id",
12906
- render: ({ field: { onChange, ...field } }) => {
12907
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12908
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12909
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12910
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12911
- ] }),
12912
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12913
- Combobox,
12914
- {
12915
- options: locations.options,
12916
- fetchNextPage: locations.fetchNextPage,
12917
- isFetchingNextPage: locations.isFetchingNextPage,
12918
- searchValue: locations.searchValue,
12919
- onSearchValueChange: locations.onSearchValueChange,
12920
- placeholder: "Select location",
12921
- onChange: (value) => {
12922
- setValue("shipping_option_id", "", {
12923
- shouldDirty: true,
12924
- shouldTouch: true
12925
- });
12926
- onChange(value);
12927
- },
12928
- ...field
12929
- }
12930
- ) })
12931
- ] }) });
12959
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12960
+ const { handleSuccess } = useRouteModal();
12961
+ const onSubmit = form.handleSubmit(async (data) => {
12962
+ await mutateAsync(
12963
+ {
12964
+ sales_channel_id: data.sales_channel_id
12965
+ },
12966
+ {
12967
+ onSuccess: () => {
12968
+ ui.toast.success("Sales channel updated");
12969
+ handleSuccess();
12970
+ },
12971
+ onError: (error) => {
12972
+ ui.toast.error(error.message);
12973
+ }
12932
12974
  }
12975
+ );
12976
+ });
12977
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12978
+ KeyboundForm,
12979
+ {
12980
+ className: "flex flex-1 flex-col overflow-hidden",
12981
+ onSubmit,
12982
+ children: [
12983
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12985
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12986
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12987
+ ] }) })
12988
+ ]
12933
12989
  }
12934
- );
12990
+ ) });
12935
12991
  };
12936
- const ShippingOptionField = ({
12937
- shippingProfileId,
12938
- preview,
12939
- control
12940
- }) => {
12941
- var _a;
12942
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12943
- const shippingOptions = useComboboxData({
12944
- queryKey: ["shipping_options", locationId, shippingProfileId],
12992
+ const SalesChannelField = ({ control, order }) => {
12993
+ const salesChannels = useComboboxData({
12945
12994
  queryFn: async (params) => {
12946
- return await sdk.admin.shippingOption.list({
12947
- ...params,
12948
- stock_location_id: locationId,
12949
- shipping_profile_id: shippingProfileId
12950
- });
12995
+ return await sdk.admin.salesChannel.list(params);
12951
12996
  },
12997
+ queryKey: ["sales-channels"],
12952
12998
  getOptions: (data) => {
12953
- return data.shipping_options.map((option) => {
12954
- var _a2;
12955
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12956
- (r) => r.attribute === "is_return" && r.value === "true"
12957
- )) {
12958
- return void 0;
12959
- }
12960
- return {
12961
- label: option.name,
12962
- value: option.id
12963
- };
12964
- }).filter(Boolean);
12999
+ return data.sales_channels.map((salesChannel) => ({
13000
+ label: salesChannel.name,
13001
+ value: salesChannel.id
13002
+ }));
12965
13003
  },
12966
- enabled: !!locationId && !!shippingProfileId,
12967
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
13004
+ defaultValue: order.sales_channel_id || void 0
12968
13005
  });
12969
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12970
13006
  return /* @__PURE__ */ jsxRuntime.jsx(
12971
13007
  Form$2.Field,
12972
13008
  {
12973
13009
  control,
12974
- name: "shipping_option_id",
13010
+ name: "sales_channel_id",
12975
13011
  render: ({ field }) => {
12976
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12977
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12978
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12979
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12980
- ] }),
12981
- /* @__PURE__ */ jsxRuntime.jsx(
12982
- ConditionalTooltip,
12983
- {
12984
- content: tooltipContent,
12985
- showTooltip: !locationId || !shippingProfileId,
12986
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12987
- Combobox,
12988
- {
12989
- options: shippingOptions.options,
12990
- fetchNextPage: shippingOptions.fetchNextPage,
12991
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12992
- searchValue: shippingOptions.searchValue,
12993
- onSearchValueChange: shippingOptions.onSearchValueChange,
12994
- placeholder: "Select shipping option",
12995
- ...field,
12996
- disabled: !locationId || !shippingProfileId
12997
- }
12998
- ) }) })
12999
- }
13000
- )
13001
- ] }) });
13002
- }
13003
- }
13004
- );
13005
- };
13006
- const CustomAmountField = ({
13007
- control,
13008
- currencyCode
13009
- }) => {
13010
- return /* @__PURE__ */ jsxRuntime.jsx(
13011
- Form$2.Field,
13012
- {
13013
- control,
13014
- name: "custom_amount",
13015
- render: ({ field: { onChange, ...field } }) => {
13016
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13017
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13018
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
13020
- ] }),
13012
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13013
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13021
13014
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13022
- ui.CurrencyInput,
13015
+ Combobox,
13023
13016
  {
13024
- ...field,
13025
- onValueChange: (value) => onChange(value),
13026
- symbol: getNativeSymbol(currencyCode),
13027
- code: currencyCode
13017
+ options: salesChannels.options,
13018
+ fetchNextPage: salesChannels.fetchNextPage,
13019
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13020
+ searchValue: salesChannels.searchValue,
13021
+ onSearchValueChange: salesChannels.onSearchValueChange,
13022
+ placeholder: "Select sales channel",
13023
+ ...field
13028
13024
  }
13029
- ) })
13025
+ ) }),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13030
13027
  ] });
13031
13028
  }
13032
13029
  }
13033
13030
  );
13034
13031
  };
13032
+ const schema = objectType({
13033
+ sales_channel_id: stringType().min(1)
13034
+ });
13035
13035
  const widgetModule = { widgets: [] };
13036
13036
  const routeModule = {
13037
13037
  routes: [
@@ -13077,8 +13077,8 @@ const routeModule = {
13077
13077
  path: "/draft-orders/:id/promotions"
13078
13078
  },
13079
13079
  {
13080
- Component: SalesChannel,
13081
- path: "/draft-orders/:id/sales-channel"
13080
+ Component: Shipping,
13081
+ path: "/draft-orders/:id/shipping"
13082
13082
  },
13083
13083
  {
13084
13084
  Component: ShippingAddress,
@@ -13089,8 +13089,8 @@ const routeModule = {
13089
13089
  path: "/draft-orders/:id/transfer-ownership"
13090
13090
  },
13091
13091
  {
13092
- Component: Shipping,
13093
- path: "/draft-orders/:id/shipping"
13092
+ Component: SalesChannel,
13093
+ path: "/draft-orders/:id/sales-channel"
13094
13094
  }
13095
13095
  ]
13096
13096
  }