@medusajs/draft-order 2.11.4-preview-20251106210130 → 2.11.4-preview-20251107032027

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