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

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