@medusajs/draft-order 2.10.0 → 2.10.1-snapshot-20250828200335

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.
@@ -9554,6 +9554,95 @@ const ID = () => {
9554
9554
  /* @__PURE__ */ jsx(Outlet, {})
9555
9555
  ] });
9556
9556
  };
9557
+ const Email = () => {
9558
+ const { id } = useParams();
9559
+ const { order, isPending, isError, error } = useOrder(id, {
9560
+ fields: "+email"
9561
+ });
9562
+ if (isError) {
9563
+ throw error;
9564
+ }
9565
+ const isReady = !isPending && !!order;
9566
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9567
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9568
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9569
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9570
+ ] }),
9571
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9572
+ ] });
9573
+ };
9574
+ const EmailForm = ({ order }) => {
9575
+ const form = useForm({
9576
+ defaultValues: {
9577
+ email: order.email ?? ""
9578
+ },
9579
+ resolver: zodResolver(schema$5)
9580
+ });
9581
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9582
+ const { handleSuccess } = useRouteModal();
9583
+ const onSubmit = form.handleSubmit(async (data) => {
9584
+ await mutateAsync(
9585
+ { email: data.email },
9586
+ {
9587
+ onSuccess: () => {
9588
+ handleSuccess();
9589
+ },
9590
+ onError: (error) => {
9591
+ toast.error(error.message);
9592
+ }
9593
+ }
9594
+ );
9595
+ });
9596
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9597
+ KeyboundForm,
9598
+ {
9599
+ className: "flex flex-1 flex-col overflow-hidden",
9600
+ onSubmit,
9601
+ children: [
9602
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9603
+ Form$2.Field,
9604
+ {
9605
+ control: form.control,
9606
+ name: "email",
9607
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9608
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9609
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9610
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9611
+ ] })
9612
+ }
9613
+ ) }),
9614
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9615
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9616
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9617
+ ] }) })
9618
+ ]
9619
+ }
9620
+ ) });
9621
+ };
9622
+ const schema$5 = objectType({
9623
+ email: stringType().email()
9624
+ });
9625
+ const CustomItems = () => {
9626
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9627
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9628
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9629
+ ] });
9630
+ };
9631
+ const CustomItemsForm = () => {
9632
+ const form = useForm({
9633
+ resolver: zodResolver(schema$4)
9634
+ });
9635
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9636
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9637
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9638
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9639
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9640
+ ] }) })
9641
+ ] }) });
9642
+ };
9643
+ const schema$4 = objectType({
9644
+ email: stringType().email()
9645
+ });
9557
9646
  const BillingAddress = () => {
9558
9647
  const { id } = useParams();
9559
9648
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9586,7 +9675,7 @@ const BillingAddressForm = ({ order }) => {
9586
9675
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9587
9676
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9588
9677
  },
9589
- resolver: zodResolver(schema$5)
9678
+ resolver: zodResolver(schema$3)
9590
9679
  });
9591
9680
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9592
9681
  const { handleSuccess } = useRouteModal();
@@ -9743,96 +9832,7 @@ const BillingAddressForm = ({ order }) => {
9743
9832
  }
9744
9833
  ) });
9745
9834
  };
9746
- const schema$5 = addressSchema;
9747
- const CustomItems = () => {
9748
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9749
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9750
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9751
- ] });
9752
- };
9753
- const CustomItemsForm = () => {
9754
- const form = useForm({
9755
- resolver: zodResolver(schema$4)
9756
- });
9757
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9758
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9759
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9760
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9761
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9762
- ] }) })
9763
- ] }) });
9764
- };
9765
- const schema$4 = objectType({
9766
- email: stringType().email()
9767
- });
9768
- const Email = () => {
9769
- const { id } = useParams();
9770
- const { order, isPending, isError, error } = useOrder(id, {
9771
- fields: "+email"
9772
- });
9773
- if (isError) {
9774
- throw error;
9775
- }
9776
- const isReady = !isPending && !!order;
9777
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9778
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9779
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9780
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9781
- ] }),
9782
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9783
- ] });
9784
- };
9785
- const EmailForm = ({ order }) => {
9786
- const form = useForm({
9787
- defaultValues: {
9788
- email: order.email ?? ""
9789
- },
9790
- resolver: zodResolver(schema$3)
9791
- });
9792
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9793
- const { handleSuccess } = useRouteModal();
9794
- const onSubmit = form.handleSubmit(async (data) => {
9795
- await mutateAsync(
9796
- { email: data.email },
9797
- {
9798
- onSuccess: () => {
9799
- handleSuccess();
9800
- },
9801
- onError: (error) => {
9802
- toast.error(error.message);
9803
- }
9804
- }
9805
- );
9806
- });
9807
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9808
- KeyboundForm,
9809
- {
9810
- className: "flex flex-1 flex-col overflow-hidden",
9811
- onSubmit,
9812
- children: [
9813
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9814
- Form$2.Field,
9815
- {
9816
- control: form.control,
9817
- name: "email",
9818
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9819
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9820
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9821
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9822
- ] })
9823
- }
9824
- ) }),
9825
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9826
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9827
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9828
- ] }) })
9829
- ]
9830
- }
9831
- ) });
9832
- };
9833
- const schema$3 = objectType({
9834
- email: stringType().email()
9835
- });
9835
+ const schema$3 = addressSchema;
9836
9836
  const InlineTip = forwardRef(
9837
9837
  ({ variant = "tip", label, className, children, ...props }, ref) => {
9838
9838
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -10612,84 +10612,194 @@ const SalesChannelField = ({ control, order }) => {
10612
10612
  const schema$2 = objectType({
10613
10613
  sales_channel_id: stringType().min(1)
10614
10614
  });
10615
- function convertNumber(value) {
10616
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10617
- }
10618
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
10619
- const Shipping = () => {
10620
- var _a;
10621
- const { id } = useParams();
10622
- const { order, isPending, isError, error } = useOrder(id, {
10623
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
10624
- });
10625
- const {
10626
- order: preview,
10627
- isPending: isPreviewPending,
10628
- isError: isPreviewError,
10629
- error: previewError
10630
- } = useOrderPreview(id);
10631
- useInitiateOrderEdit({ preview });
10632
- const { onCancel } = useCancelOrderEdit({ preview });
10633
- if (isError) {
10634
- throw error;
10635
- }
10636
- if (isPreviewError) {
10637
- throw previewError;
10638
- }
10639
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
10640
- const isReady = preview && !isPreviewPending && order && !isPending;
10641
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
10642
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10643
- /* @__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: [
10644
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
10645
- /* @__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." }) })
10646
- ] }) }) }),
10647
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
10648
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
10649
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
10650
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10651
- ] }) });
10652
- };
10653
- const ShippingForm = ({ preview, order }) => {
10654
- var _a;
10655
- const { setIsOpen } = useStackedModal();
10656
- const [isSubmitting, setIsSubmitting] = useState(false);
10657
- const [data, setData] = useState(null);
10658
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
10659
- const { shipping_options } = useShippingOptions(
10660
- {
10661
- id: appliedShippingOptionIds,
10662
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
10663
- },
10664
- {
10665
- enabled: appliedShippingOptionIds.length > 0
10666
- }
10667
- );
10668
- const uniqueShippingProfiles = useMemo(() => {
10669
- const profiles = /* @__PURE__ */ new Map();
10670
- getUniqueShippingProfiles(order.items).forEach((profile) => {
10671
- profiles.set(profile.id, profile);
10672
- });
10673
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
10674
- profiles.set(option.shipping_profile_id, option.shipping_profile);
10675
- });
10676
- return Array.from(profiles.values());
10677
- }, [order.items, shipping_options]);
10678
- const { handleSuccess } = useRouteModal();
10679
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10680
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10681
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
10682
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
10683
- const onSubmit = async () => {
10684
- setIsSubmitting(true);
10685
- let requestSucceeded = false;
10686
- await requestOrderEdit(void 0, {
10687
- onError: (e) => {
10688
- toast.error(`Failed to request order edit: ${e.message}`);
10689
- },
10690
- onSuccess: () => {
10691
- requestSucceeded = true;
10692
- }
10615
+ const NumberInput = forwardRef(
10616
+ ({
10617
+ value,
10618
+ onChange,
10619
+ size = "base",
10620
+ min = 0,
10621
+ max = 100,
10622
+ step = 1,
10623
+ className,
10624
+ disabled,
10625
+ ...props
10626
+ }, ref) => {
10627
+ const handleChange = (event) => {
10628
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10629
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10630
+ onChange(newValue);
10631
+ }
10632
+ };
10633
+ const handleIncrement = () => {
10634
+ const newValue = value + step;
10635
+ if (max === void 0 || newValue <= max) {
10636
+ onChange(newValue);
10637
+ }
10638
+ };
10639
+ const handleDecrement = () => {
10640
+ const newValue = value - step;
10641
+ if (min === void 0 || newValue >= min) {
10642
+ onChange(newValue);
10643
+ }
10644
+ };
10645
+ return /* @__PURE__ */ jsxs(
10646
+ "div",
10647
+ {
10648
+ className: clx(
10649
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10650
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10651
+ {
10652
+ "h-7": size === "small",
10653
+ "h-8": size === "base"
10654
+ },
10655
+ className
10656
+ ),
10657
+ children: [
10658
+ /* @__PURE__ */ jsx(
10659
+ "input",
10660
+ {
10661
+ ref,
10662
+ type: "number",
10663
+ value,
10664
+ onChange: handleChange,
10665
+ min,
10666
+ max,
10667
+ step,
10668
+ className: clx(
10669
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10670
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10671
+ "placeholder:text-ui-fg-muted"
10672
+ ),
10673
+ ...props
10674
+ }
10675
+ ),
10676
+ /* @__PURE__ */ jsxs(
10677
+ "button",
10678
+ {
10679
+ className: clx(
10680
+ "flex items-center justify-center outline-none transition-fg",
10681
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10682
+ "focus:bg-ui-bg-field-component-hover",
10683
+ "hover:bg-ui-bg-field-component-hover",
10684
+ {
10685
+ "size-7": size === "small",
10686
+ "size-8": size === "base"
10687
+ }
10688
+ ),
10689
+ type: "button",
10690
+ onClick: handleDecrement,
10691
+ disabled: min !== void 0 && value <= min || disabled,
10692
+ children: [
10693
+ /* @__PURE__ */ jsx(Minus, {}),
10694
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10695
+ ]
10696
+ }
10697
+ ),
10698
+ /* @__PURE__ */ jsxs(
10699
+ "button",
10700
+ {
10701
+ className: clx(
10702
+ "flex items-center justify-center outline-none transition-fg",
10703
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10704
+ "focus:bg-ui-bg-field-hover",
10705
+ "hover:bg-ui-bg-field-hover",
10706
+ {
10707
+ "size-7": size === "small",
10708
+ "size-8": size === "base"
10709
+ }
10710
+ ),
10711
+ type: "button",
10712
+ onClick: handleIncrement,
10713
+ disabled: max !== void 0 && value >= max || disabled,
10714
+ children: [
10715
+ /* @__PURE__ */ jsx(Plus, {}),
10716
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10717
+ ]
10718
+ }
10719
+ )
10720
+ ]
10721
+ }
10722
+ );
10723
+ }
10724
+ );
10725
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10726
+ const productVariantsQueryKeys = {
10727
+ list: (query2) => [
10728
+ PRODUCT_VARIANTS_QUERY_KEY,
10729
+ query2 ? query2 : void 0
10730
+ ]
10731
+ };
10732
+ const useProductVariants = (query2, options) => {
10733
+ const { data, ...rest } = useQuery({
10734
+ queryKey: productVariantsQueryKeys.list(query2),
10735
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
10736
+ ...options
10737
+ });
10738
+ return { ...data, ...rest };
10739
+ };
10740
+ function convertNumber(value) {
10741
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10742
+ }
10743
+ const STACKED_MODAL_ID = "items_stacked_modal";
10744
+ const Items = () => {
10745
+ const { id } = useParams();
10746
+ const {
10747
+ order: preview,
10748
+ isPending: isPreviewPending,
10749
+ isError: isPreviewError,
10750
+ error: previewError
10751
+ } = useOrderPreview(id, void 0, {
10752
+ placeholderData: keepPreviousData
10753
+ });
10754
+ useInitiateOrderEdit({ preview });
10755
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10756
+ id,
10757
+ {
10758
+ fields: "currency_code"
10759
+ },
10760
+ {
10761
+ enabled: !!id
10762
+ }
10763
+ );
10764
+ const { onCancel } = useCancelOrderEdit({ preview });
10765
+ if (isError) {
10766
+ throw error;
10767
+ }
10768
+ if (isPreviewError) {
10769
+ throw previewError;
10770
+ }
10771
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10772
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10773
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10774
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10775
+ ] }) });
10776
+ };
10777
+ const ItemsForm = ({ preview, currencyCode }) => {
10778
+ var _a;
10779
+ const [isSubmitting, setIsSubmitting] = useState(false);
10780
+ const [modalContent, setModalContent] = useState(
10781
+ null
10782
+ );
10783
+ const { handleSuccess } = useRouteModal();
10784
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10785
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10786
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10787
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10788
+ const matches = useMemo(() => {
10789
+ return matchSorter(preview.items, query2, {
10790
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10791
+ });
10792
+ }, [preview.items, query2]);
10793
+ const onSubmit = async () => {
10794
+ setIsSubmitting(true);
10795
+ let requestSucceeded = false;
10796
+ await requestOrderEdit(void 0, {
10797
+ onError: (e) => {
10798
+ toast.error(`Failed to request order edit: ${e.message}`);
10799
+ },
10800
+ onSuccess: () => {
10801
+ requestSucceeded = true;
10802
+ }
10693
10803
  });
10694
10804
  if (!requestSucceeded) {
10695
10805
  setIsSubmitting(false);
@@ -10707,2324 +10817,2214 @@ const ShippingForm = ({ preview, order }) => {
10707
10817
  }
10708
10818
  });
10709
10819
  };
10710
- const onKeydown = useCallback(
10820
+ const onKeyDown = useCallback(
10711
10821
  (e) => {
10712
10822
  if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10713
- if (data || isSubmitting) {
10823
+ if (modalContent || isSubmitting) {
10714
10824
  return;
10715
10825
  }
10716
10826
  onSubmit();
10717
10827
  }
10718
10828
  },
10719
- [data, isSubmitting, onSubmit]
10829
+ [modalContent, isSubmitting, onSubmit]
10720
10830
  );
10721
10831
  useEffect(() => {
10722
- document.addEventListener("keydown", onKeydown);
10832
+ document.addEventListener("keydown", onKeyDown);
10723
10833
  return () => {
10724
- document.removeEventListener("keydown", onKeydown);
10834
+ document.removeEventListener("keydown", onKeyDown);
10725
10835
  };
10726
- }, [onKeydown]);
10836
+ }, [onKeyDown]);
10727
10837
  return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10728
10838
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10729
- /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
10730
- /* @__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: [
10731
- /* @__PURE__ */ jsxs("div", { children: [
10732
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
10733
- /* @__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." }) })
10734
- ] }),
10735
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10736
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
10737
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
10738
- /* @__PURE__ */ jsx(
10739
- Text,
10740
- {
10741
- size: "xsmall",
10742
- weight: "plus",
10743
- className: "text-ui-fg-muted",
10744
- children: "Shipping profile"
10745
- }
10746
- ),
10747
- /* @__PURE__ */ jsx(
10748
- Text,
10749
- {
10750
- size: "xsmall",
10751
- weight: "plus",
10752
- className: "text-ui-fg-muted",
10753
- children: "Action"
10754
- }
10755
- )
10756
- ] }),
10757
- /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
10758
- var _a2, _b, _c, _d, _e, _f, _g;
10759
- const items = getItemsWithShippingProfile(
10760
- profile.id,
10761
- order.items
10762
- );
10763
- const hasItems = items.length > 0;
10764
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
10765
- (option) => option.shipping_profile_id === profile.id
10766
- );
10767
- const shippingMethod = preview.shipping_methods.find(
10768
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
10769
- );
10770
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
10771
- (action) => action.action === "SHIPPING_ADD"
10772
- );
10773
- return /* @__PURE__ */ jsxs(
10774
- Accordion.Item,
10775
- {
10776
- value: profile.id,
10777
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
10778
- children: [
10779
- /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
10780
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
10781
- /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
10782
- IconButton,
10783
- {
10784
- size: "2xsmall",
10785
- variant: "transparent",
10786
- className: "group/trigger",
10787
- disabled: !hasItems,
10788
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
10839
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10840
+ StackedFocusModal,
10841
+ {
10842
+ id: STACKED_MODAL_ID,
10843
+ onOpenChangeCallback: (open) => {
10844
+ if (!open) {
10845
+ setModalContent(null);
10846
+ }
10847
+ },
10848
+ children: [
10849
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10850
+ /* @__PURE__ */ jsxs("div", { children: [
10851
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10852
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
10853
+ ] }),
10854
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10855
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10856
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10857
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10858
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10859
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10860
+ ] }),
10861
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10862
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10863
+ Input,
10864
+ {
10865
+ type: "search",
10866
+ placeholder: "Search items",
10867
+ value: searchValue,
10868
+ onChange: (e) => onSearchValueChange(e.target.value)
10869
+ }
10870
+ ) }),
10871
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10872
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10873
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10874
+ /* @__PURE__ */ jsx(
10875
+ StackedModalTrigger$1,
10876
+ {
10877
+ type: "add-items",
10878
+ setModalContent
10789
10879
  }
10790
- ) }),
10791
- !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10792
- /* @__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" }) }) }),
10793
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
10794
- /* @__PURE__ */ jsx(
10795
- Text,
10796
- {
10797
- size: "small",
10798
- weight: "plus",
10799
- leading: "compact",
10800
- children: profile.name
10801
- }
10802
- ),
10803
- /* @__PURE__ */ jsxs(
10804
- Text,
10805
- {
10806
- size: "small",
10807
- leading: "compact",
10808
- className: "text-ui-fg-subtle",
10809
- children: [
10810
- items.length,
10811
- " ",
10812
- pluralize(items.length, "items", "item")
10813
- ]
10814
- }
10815
- )
10816
- ] })
10817
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
10818
- /* @__PURE__ */ jsx(
10819
- Tooltip,
10820
- {
10821
- content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
10822
- var _a3, _b2, _c2;
10823
- return /* @__PURE__ */ jsx(
10824
- "li",
10825
- {
10826
- 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})`
10827
- },
10828
- item.id
10829
- );
10830
- }) }),
10831
- children: /* @__PURE__ */ jsxs(
10832
- Badge,
10833
- {
10834
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
10835
- size: "xsmall",
10836
- children: [
10837
- /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
10838
- /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
10839
- items.reduce(
10840
- (acc, item) => acc + item.quantity,
10841
- 0
10842
- ),
10843
- "x",
10844
- " ",
10845
- pluralize(items.length, "items", "item")
10846
- ] })
10847
- ]
10848
- }
10849
- )
10850
- }
10851
- ),
10852
- /* @__PURE__ */ jsx(
10853
- Tooltip,
10854
- {
10855
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
10856
- children: /* @__PURE__ */ jsxs(
10857
- Badge,
10858
- {
10859
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
10860
- size: "xsmall",
10861
- children: [
10862
- /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
10863
- /* @__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 })
10864
- ]
10865
- }
10866
- )
10867
- }
10868
- ),
10869
- /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
10870
- Badge,
10871
- {
10872
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
10873
- size: "xsmall",
10874
- children: [
10875
- /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
10876
- /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
10877
- ]
10878
- }
10879
- ) })
10880
- ] })
10881
- ] }),
10882
- shippingOption ? /* @__PURE__ */ jsx(
10883
- ActionMenu,
10884
- {
10885
- groups: [
10886
- {
10887
- actions: [
10888
- hasItems ? {
10889
- label: "Edit shipping option",
10890
- icon: /* @__PURE__ */ jsx(Channels, {}),
10891
- onClick: () => {
10892
- setIsOpen(
10893
- STACKED_FOCUS_MODAL_ID,
10894
- true
10895
- );
10896
- setData({
10897
- shippingProfileId: profile.id,
10898
- shippingOption,
10899
- shippingMethod
10900
- });
10901
- }
10902
- } : void 0,
10903
- {
10904
- label: "Remove shipping option",
10905
- icon: /* @__PURE__ */ jsx(Trash, {}),
10906
- onClick: () => {
10907
- if (shippingMethod) {
10908
- if (addShippingMethodAction) {
10909
- removeActionShippingMethod(
10910
- addShippingMethodAction.id
10911
- );
10912
- } else {
10913
- removeShippingMethod(
10914
- shippingMethod.id
10915
- );
10916
- }
10917
- }
10918
- }
10919
- }
10920
- ].filter(Boolean)
10921
- }
10922
- ]
10923
- }
10924
- ) : /* @__PURE__ */ jsx(
10925
- StackedModalTrigger$1,
10926
- {
10927
- shippingProfileId: profile.id,
10928
- shippingOption,
10929
- shippingMethod,
10930
- setData,
10931
- children: "Add shipping option"
10932
- }
10933
- )
10934
- ] }),
10935
- /* @__PURE__ */ jsxs(Accordion.Content, { children: [
10936
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10937
- items.map((item, idx) => {
10938
- var _a3, _b2, _c2, _d2, _e2;
10939
- return /* @__PURE__ */ jsxs("div", { children: [
10940
- /* @__PURE__ */ jsxs(
10941
- "div",
10942
- {
10943
- className: "px-3 flex items-center gap-x-3",
10944
- children: [
10945
- /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
10946
- Divider,
10947
- {
10948
- variant: "dashed",
10949
- orientation: "vertical"
10950
- }
10951
- ) }),
10952
- /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
10953
- /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
10954
- Text,
10955
- {
10956
- size: "small",
10957
- leading: "compact",
10958
- className: "text-ui-fg-subtle",
10959
- children: [
10960
- item.quantity,
10961
- "x"
10962
- ]
10963
- }
10964
- ) }),
10965
- /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
10966
- /* @__PURE__ */ jsxs("div", { children: [
10967
- /* @__PURE__ */ jsxs(
10968
- Text,
10969
- {
10970
- size: "small",
10971
- leading: "compact",
10972
- weight: "plus",
10973
- children: [
10974
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
10975
- " (",
10976
- (_c2 = item.variant) == null ? void 0 : _c2.title,
10977
- ")"
10978
- ]
10979
- }
10980
- ),
10981
- /* @__PURE__ */ jsx(
10982
- Text,
10983
- {
10984
- size: "small",
10985
- leading: "compact",
10986
- className: "text-ui-fg-subtle",
10987
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
10988
- }
10989
- )
10990
- ] })
10991
- ] })
10992
- ]
10993
- },
10994
- item.id
10995
- ),
10996
- idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
10997
- ] }, item.id);
10998
- })
10999
- ] })
11000
- ]
11001
- },
11002
- profile.id
11003
- );
11004
- }) })
11005
- ] }) })
11006
- ] }) }),
11007
- /* @__PURE__ */ jsx(
11008
- StackedFocusModal,
11009
- {
11010
- id: STACKED_FOCUS_MODAL_ID,
11011
- onOpenChangeCallback: (open) => {
11012
- if (!open) {
11013
- setData(null);
10880
+ ),
10881
+ /* @__PURE__ */ jsx(
10882
+ StackedModalTrigger$1,
10883
+ {
10884
+ type: "add-custom-item",
10885
+ setModalContent
10886
+ }
10887
+ )
10888
+ ] })
10889
+ ] })
10890
+ ] })
10891
+ ] }),
10892
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10893
+ /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
10894
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10895
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10896
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10897
+ /* @__PURE__ */ jsx("div", {})
10898
+ ] }) }),
10899
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__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: [
10900
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10901
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10902
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10903
+ Item,
10904
+ {
10905
+ item,
10906
+ preview,
10907
+ currencyCode
10908
+ },
10909
+ item.id
10910
+ )) : /* @__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: [
10911
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10912
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10913
+ 'No items found for "',
10914
+ query2,
10915
+ '".'
10916
+ ] })
10917
+ ] }) })
10918
+ ] })
10919
+ ] }),
10920
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10921
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10922
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10923
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10924
+ Text,
10925
+ {
10926
+ size: "small",
10927
+ leading: "compact",
10928
+ className: "text-ui-fg-subtle",
10929
+ children: [
10930
+ itemCount,
10931
+ " ",
10932
+ itemCount === 1 ? "item" : "items"
10933
+ ]
10934
+ }
10935
+ ) }),
10936
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10937
+ ] })
10938
+ ] }) }),
10939
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10940
+ CustomItemForm,
10941
+ {
10942
+ orderId: preview.id,
10943
+ currencyCode
11014
10944
  }
11015
- return open;
11016
- },
11017
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11018
- }
11019
- )
11020
- ] }),
11021
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
10945
+ ) : null)
10946
+ ]
10947
+ }
10948
+ ) }),
10949
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
11022
10950
  /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11023
10951
  /* @__PURE__ */ jsx(
11024
10952
  Button,
11025
10953
  {
11026
10954
  size: "small",
11027
10955
  type: "button",
11028
- isLoading: isSubmitting,
11029
10956
  onClick: onSubmit,
10957
+ isLoading: isSubmitting,
11030
10958
  children: "Save"
11031
10959
  }
11032
10960
  )
11033
10961
  ] }) })
11034
10962
  ] });
11035
10963
  };
11036
- const StackedModalTrigger$1 = ({
11037
- shippingProfileId,
11038
- shippingOption,
11039
- shippingMethod,
11040
- setData,
11041
- children
11042
- }) => {
11043
- const { setIsOpen, getIsOpen } = useStackedModal();
11044
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11045
- const onToggle = () => {
11046
- if (isOpen) {
11047
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11048
- setData(null);
11049
- } else {
11050
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11051
- setData({
11052
- shippingProfileId,
11053
- shippingOption,
11054
- shippingMethod
11055
- });
11056
- }
11057
- };
11058
- return /* @__PURE__ */ jsx(
11059
- Button,
11060
- {
11061
- size: "small",
11062
- variant: "secondary",
11063
- onClick: onToggle,
11064
- className: "text-ui-fg-primary shrink-0",
11065
- children
11066
- }
11067
- );
10964
+ const Item = ({ item, preview, currencyCode }) => {
10965
+ if (item.variant_id) {
10966
+ return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10967
+ }
10968
+ return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
11068
10969
  };
11069
- const ShippingProfileForm = ({
11070
- data,
11071
- order,
11072
- preview
11073
- }) => {
11074
- var _a, _b, _c, _d, _e, _f;
11075
- const { setIsOpen } = useStackedModal();
10970
+ const VariantItem = ({ item, preview, currencyCode }) => {
10971
+ const [editing, setEditing] = useState(false);
11076
10972
  const form = useForm({
11077
- resolver: zodResolver(shippingMethodSchema),
11078
10973
  defaultValues: {
11079
- 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,
11080
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11081
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11082
- }
10974
+ quantity: item.quantity,
10975
+ unit_price: item.unit_price
10976
+ },
10977
+ resolver: zodResolver(variantItemSchema)
11083
10978
  });
11084
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11085
- const {
11086
- mutateAsync: updateShippingMethod,
11087
- isPending: isUpdatingShippingMethod
11088
- } = useDraftOrderUpdateShippingMethod(order.id);
11089
- const onSubmit = form.handleSubmit(async (values) => {
11090
- if (isEqual(values, form.formState.defaultValues)) {
11091
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
10979
+ const actionId = useMemo(() => {
10980
+ var _a, _b;
10981
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10982
+ }, [item]);
10983
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10984
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10985
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10986
+ const onSubmit = form.handleSubmit(async (data) => {
10987
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10988
+ setEditing(false);
11092
10989
  return;
11093
10990
  }
11094
- if (data.shippingMethod) {
11095
- await updateShippingMethod(
10991
+ if (!actionId) {
10992
+ await updateOriginalItem(
11096
10993
  {
11097
- method_id: data.shippingMethod.id,
11098
- shipping_option_id: values.shipping_option_id,
11099
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
10994
+ item_id: item.id,
10995
+ quantity: data.quantity,
10996
+ unit_price: convertNumber(data.unit_price)
11100
10997
  },
11101
10998
  {
10999
+ onSuccess: () => {
11000
+ setEditing(false);
11001
+ },
11102
11002
  onError: (e) => {
11103
11003
  toast.error(e.message);
11104
- },
11105
- onSuccess: () => {
11106
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11107
11004
  }
11108
11005
  }
11109
11006
  );
11110
11007
  return;
11111
11008
  }
11112
- await addShippingMethod(
11009
+ await updateActionItem(
11113
11010
  {
11114
- shipping_option_id: values.shipping_option_id,
11115
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11011
+ action_id: actionId,
11012
+ quantity: data.quantity,
11013
+ unit_price: convertNumber(data.unit_price)
11116
11014
  },
11117
11015
  {
11016
+ onSuccess: () => {
11017
+ setEditing(false);
11018
+ },
11118
11019
  onError: (e) => {
11119
11020
  toast.error(e.message);
11120
- },
11121
- onSuccess: () => {
11122
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11123
11021
  }
11124
11022
  }
11125
11023
  );
11126
11024
  });
11127
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
11128
- KeyboundForm,
11129
- {
11130
- className: "flex h-full flex-col overflow-hidden",
11131
- onSubmit,
11132
- children: [
11133
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11134
- /* @__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: [
11135
- /* @__PURE__ */ jsxs("div", { children: [
11136
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11137
- /* @__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." }) })
11138
- ] }),
11139
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11140
- /* @__PURE__ */ jsx(
11141
- LocationField,
11142
- {
11143
- control: form.control,
11144
- setValue: form.setValue
11145
- }
11146
- ),
11147
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11148
- /* @__PURE__ */ jsx(
11149
- ShippingOptionField,
11150
- {
11151
- shippingProfileId: data.shippingProfileId,
11152
- preview,
11153
- control: form.control
11154
- }
11155
- ),
11156
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11157
- /* @__PURE__ */ jsx(
11158
- CustomAmountField,
11159
- {
11160
- control: form.control,
11161
- currencyCode: order.currency_code
11162
- }
11163
- ),
11164
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11165
- /* @__PURE__ */ jsx(
11166
- ItemsPreview,
11025
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
11026
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
11027
+ /* @__PURE__ */ jsx(
11028
+ Thumbnail,
11029
+ {
11030
+ thumbnail: item.thumbnail,
11031
+ alt: item.product_title ?? void 0
11032
+ }
11033
+ ),
11034
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11035
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
11036
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11037
+ /* @__PURE__ */ jsxs(
11038
+ Text,
11167
11039
  {
11168
- order,
11169
- shippingProfileId: data.shippingProfileId
11040
+ size: "small",
11041
+ leading: "compact",
11042
+ className: "text-ui-fg-subtle",
11043
+ children: [
11044
+ "(",
11045
+ item.variant_title,
11046
+ ")"
11047
+ ]
11170
11048
  }
11171
11049
  )
11172
- ] }) }) }),
11173
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11174
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11175
- /* @__PURE__ */ jsx(
11176
- Button,
11050
+ ] }),
11051
+ /* @__PURE__ */ jsx(
11052
+ Text,
11053
+ {
11054
+ size: "small",
11055
+ leading: "compact",
11056
+ className: "text-ui-fg-subtle",
11057
+ children: item.variant_sku
11058
+ }
11059
+ )
11060
+ ] })
11061
+ ] }),
11062
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
11063
+ Form$2.Field,
11064
+ {
11065
+ control: form.control,
11066
+ name: "quantity",
11067
+ render: ({ field }) => {
11068
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
11069
+ }
11070
+ }
11071
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
11072
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
11073
+ Form$2.Field,
11074
+ {
11075
+ control: form.control,
11076
+ name: "unit_price",
11077
+ render: ({ field: { onChange, ...field } }) => {
11078
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11079
+ CurrencyInput,
11177
11080
  {
11178
- size: "small",
11179
- type: "submit",
11180
- isLoading: isPending || isUpdatingShippingMethod,
11181
- children: data.shippingMethod ? "Update" : "Add"
11081
+ ...field,
11082
+ symbol: getNativeSymbol(currencyCode),
11083
+ code: currencyCode,
11084
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11182
11085
  }
11183
- )
11184
- ] }) })
11185
- ]
11186
- }
11187
- ) }) });
11086
+ ) }) });
11087
+ }
11088
+ }
11089
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11090
+ /* @__PURE__ */ jsx(
11091
+ IconButton,
11092
+ {
11093
+ type: "button",
11094
+ size: "small",
11095
+ onClick: editing ? onSubmit : () => {
11096
+ setEditing(true);
11097
+ },
11098
+ disabled: isPending,
11099
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
11100
+ }
11101
+ )
11102
+ ] }) }) });
11188
11103
  };
11189
- const shippingMethodSchema = objectType({
11190
- location_id: stringType(),
11191
- shipping_option_id: stringType(),
11192
- custom_amount: unionType([numberType(), stringType()]).optional()
11104
+ const variantItemSchema = objectType({
11105
+ quantity: numberType(),
11106
+ unit_price: unionType([numberType(), stringType()])
11193
11107
  });
11194
- const ItemsPreview = ({ order, shippingProfileId }) => {
11195
- const matches = order.items.filter(
11196
- (item) => {
11197
- var _a, _b, _c;
11198
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11108
+ const CustomItem = ({ item, preview, currencyCode }) => {
11109
+ const [editing, setEditing] = useState(false);
11110
+ const { quantity, unit_price, title } = item;
11111
+ const form = useForm({
11112
+ defaultValues: {
11113
+ title,
11114
+ quantity,
11115
+ unit_price
11116
+ },
11117
+ resolver: zodResolver(customItemSchema)
11118
+ });
11119
+ useEffect(() => {
11120
+ form.reset({
11121
+ title,
11122
+ quantity,
11123
+ unit_price
11124
+ });
11125
+ }, [form, title, quantity, unit_price]);
11126
+ const actionId = useMemo(() => {
11127
+ var _a, _b;
11128
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
11129
+ }, [item]);
11130
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
11131
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
11132
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
11133
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
11134
+ const onSubmit = form.handleSubmit(async (data) => {
11135
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
11136
+ setEditing(false);
11137
+ return;
11199
11138
  }
11200
- );
11201
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
11202
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11203
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11204
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11205
- ] }) }),
11206
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11207
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11208
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
11209
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
11210
- ] }),
11211
- /* @__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(
11212
- "div",
11139
+ if (!actionId) {
11140
+ await updateOriginalItem(
11213
11141
  {
11214
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11215
- children: [
11216
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11217
- /* @__PURE__ */ jsx(
11218
- Thumbnail,
11219
- {
11220
- thumbnail: item.thumbnail,
11221
- alt: item.product_title ?? void 0
11222
- }
11223
- ),
11224
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11225
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
11226
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11227
- /* @__PURE__ */ jsxs(
11228
- Text,
11229
- {
11230
- size: "small",
11231
- leading: "compact",
11232
- className: "text-ui-fg-subtle",
11233
- children: [
11234
- "(",
11235
- item.variant_title,
11236
- ")"
11237
- ]
11238
- }
11239
- )
11240
- ] }),
11241
- /* @__PURE__ */ jsx(
11242
- Text,
11243
- {
11244
- size: "small",
11245
- leading: "compact",
11246
- className: "text-ui-fg-subtle",
11247
- children: item.variant_sku
11248
- }
11249
- )
11250
- ] })
11251
- ] }),
11252
- /* @__PURE__ */ jsxs(
11253
- Text,
11254
- {
11255
- size: "small",
11256
- leading: "compact",
11257
- className: "text-ui-fg-subtle",
11258
- children: [
11259
- item.quantity,
11260
- "x"
11261
- ]
11262
- }
11263
- )
11264
- ]
11142
+ item_id: item.id,
11143
+ quantity: data.quantity,
11144
+ unit_price: convertNumber(data.unit_price)
11265
11145
  },
11266
- item.id
11267
- )) : /* @__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: [
11268
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11269
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
11270
- 'No items found for "',
11271
- query,
11272
- '".'
11273
- ] })
11274
- ] }) })
11275
- ] })
11276
- ] });
11277
- };
11278
- const LocationField = ({ control, setValue }) => {
11279
- const locations = useComboboxData({
11280
- queryKey: ["locations"],
11281
- queryFn: async (params) => {
11282
- return await sdk.admin.stockLocation.list(params);
11283
- },
11284
- getOptions: (data) => {
11285
- return data.stock_locations.map((location) => ({
11286
- label: location.name,
11287
- value: location.id
11288
- }));
11146
+ {
11147
+ onSuccess: () => {
11148
+ setEditing(false);
11149
+ },
11150
+ onError: (e) => {
11151
+ toast.error(e.message);
11152
+ }
11153
+ }
11154
+ );
11155
+ return;
11289
11156
  }
11290
- });
11291
- return /* @__PURE__ */ jsx(
11292
- Form$2.Field,
11293
- {
11294
- control,
11295
- name: "location_id",
11296
- render: ({ field: { onChange, ...field } }) => {
11297
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11298
- /* @__PURE__ */ jsxs("div", { children: [
11299
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
11300
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11301
- ] }),
11302
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11303
- Combobox,
11304
- {
11305
- options: locations.options,
11306
- fetchNextPage: locations.fetchNextPage,
11307
- isFetchingNextPage: locations.isFetchingNextPage,
11308
- searchValue: locations.searchValue,
11309
- onSearchValueChange: locations.onSearchValueChange,
11310
- placeholder: "Select location",
11311
- onChange: (value) => {
11312
- setValue("shipping_option_id", "", {
11313
- shouldDirty: true,
11314
- shouldTouch: true
11315
- });
11316
- onChange(value);
11317
- },
11318
- ...field
11319
- }
11320
- ) })
11321
- ] }) });
11322
- }
11157
+ if (data.quantity === 0) {
11158
+ await removeActionItem(actionId, {
11159
+ onSuccess: () => {
11160
+ setEditing(false);
11161
+ },
11162
+ onError: (e) => {
11163
+ toast.error(e.message);
11164
+ }
11165
+ });
11166
+ return;
11323
11167
  }
11324
- );
11325
- };
11326
- const ShippingOptionField = ({
11327
- shippingProfileId,
11328
- preview,
11329
- control
11330
- }) => {
11331
- var _a;
11332
- const locationId = useWatch({ control, name: "location_id" });
11333
- const shippingOptions = useComboboxData({
11334
- queryKey: ["shipping_options", locationId, shippingProfileId],
11335
- queryFn: async (params) => {
11336
- return await sdk.admin.shippingOption.list({
11337
- ...params,
11338
- stock_location_id: locationId,
11339
- shipping_profile_id: shippingProfileId
11340
- });
11341
- },
11342
- getOptions: (data) => {
11343
- return data.shipping_options.map((option) => {
11344
- var _a2;
11345
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
11346
- (r) => r.attribute === "is_return" && r.value === "true"
11347
- )) {
11348
- return void 0;
11168
+ await updateActionItem(
11169
+ {
11170
+ action_id: actionId,
11171
+ quantity: data.quantity,
11172
+ unit_price: convertNumber(data.unit_price)
11173
+ },
11174
+ {
11175
+ onSuccess: () => {
11176
+ setEditing(false);
11177
+ },
11178
+ onError: (e) => {
11179
+ toast.error(e.message);
11349
11180
  }
11350
- return {
11351
- label: option.name,
11352
- value: option.id
11353
- };
11354
- }).filter(Boolean);
11355
- },
11356
- enabled: !!locationId && !!shippingProfileId,
11357
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11181
+ }
11182
+ );
11358
11183
  });
11359
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
11360
- return /* @__PURE__ */ jsx(
11361
- Form$2.Field,
11362
- {
11363
- control,
11364
- name: "shipping_option_id",
11365
- render: ({ field }) => {
11366
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11367
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11368
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
11369
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
11370
- ] }),
11371
- /* @__PURE__ */ jsx(
11372
- ConditionalTooltip,
11373
- {
11374
- content: tooltipContent,
11375
- showTooltip: !locationId || !shippingProfileId,
11376
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11377
- Combobox,
11378
- {
11379
- options: shippingOptions.options,
11380
- fetchNextPage: shippingOptions.fetchNextPage,
11381
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
11382
- searchValue: shippingOptions.searchValue,
11383
- onSearchValueChange: shippingOptions.onSearchValueChange,
11384
- placeholder: "Select shipping option",
11385
- ...field,
11386
- disabled: !locationId || !shippingProfileId
11387
- }
11388
- ) }) })
11389
- }
11390
- )
11391
- ] }) });
11184
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
11185
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11186
+ /* @__PURE__ */ jsx(
11187
+ Thumbnail,
11188
+ {
11189
+ thumbnail: item.thumbnail,
11190
+ alt: item.title ?? void 0
11191
+ }
11192
+ ),
11193
+ editing ? /* @__PURE__ */ jsx(
11194
+ Form$2.Field,
11195
+ {
11196
+ control: form.control,
11197
+ name: "title",
11198
+ render: ({ field }) => {
11199
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
11200
+ }
11201
+ }
11202
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
11203
+ ] }),
11204
+ editing ? /* @__PURE__ */ jsx(
11205
+ Form$2.Field,
11206
+ {
11207
+ control: form.control,
11208
+ name: "quantity",
11209
+ render: ({ field }) => {
11210
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
11211
+ }
11392
11212
  }
11393
- }
11394
- );
11395
- };
11396
- const CustomAmountField = ({
11397
- control,
11398
- currencyCode
11399
- }) => {
11400
- return /* @__PURE__ */ jsx(
11401
- Form$2.Field,
11402
- {
11403
- control,
11404
- name: "custom_amount",
11405
- render: ({ field: { onChange, ...field } }) => {
11406
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11407
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11408
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
11409
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
11410
- ] }),
11411
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11213
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
11214
+ editing ? /* @__PURE__ */ jsx(
11215
+ Form$2.Field,
11216
+ {
11217
+ control: form.control,
11218
+ name: "unit_price",
11219
+ render: ({ field: { onChange, ...field } }) => {
11220
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11412
11221
  CurrencyInput,
11413
11222
  {
11414
11223
  ...field,
11415
- onValueChange: (value) => onChange(value),
11416
11224
  symbol: getNativeSymbol(currencyCode),
11417
- code: currencyCode
11225
+ code: currencyCode,
11226
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11418
11227
  }
11419
- ) })
11420
- ] });
11228
+ ) }) });
11229
+ }
11421
11230
  }
11422
- }
11423
- );
11231
+ ) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11232
+ /* @__PURE__ */ jsx(
11233
+ IconButton,
11234
+ {
11235
+ type: "button",
11236
+ size: "small",
11237
+ onClick: editing ? onSubmit : () => {
11238
+ setEditing(true);
11239
+ },
11240
+ disabled: isPending,
11241
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
11242
+ }
11243
+ )
11244
+ ] }) }) });
11424
11245
  };
11425
- const TransferOwnership = () => {
11426
- const { id } = useParams();
11427
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11428
- fields: "id,customer_id,customer.*"
11429
- });
11430
- if (isError) {
11431
- throw error;
11432
- }
11433
- const isReady = !isPending && !!draft_order;
11434
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11435
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11436
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11437
- /* @__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" }) })
11438
- ] }),
11439
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11440
- ] });
11246
+ const StackedModalTrigger$1 = ({
11247
+ type,
11248
+ setModalContent
11249
+ }) => {
11250
+ const { setIsOpen } = useStackedModal();
11251
+ const onClick = useCallback(() => {
11252
+ setModalContent(type);
11253
+ setIsOpen(STACKED_MODAL_ID, true);
11254
+ }, [setModalContent, setIsOpen, type]);
11255
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
11441
11256
  };
11442
- const TransferOwnershipForm = ({ order }) => {
11443
- var _a, _b;
11444
- const form = useForm({
11445
- defaultValues: {
11446
- customer_id: order.customer_id || ""
11257
+ const VARIANT_PREFIX = "items";
11258
+ const LIMIT = 50;
11259
+ const ExistingItemsForm = ({ orderId, items }) => {
11260
+ const { setIsOpen } = useStackedModal();
11261
+ const [rowSelection, setRowSelection] = useState(
11262
+ items.reduce((acc, item) => {
11263
+ acc[item.variant_id] = true;
11264
+ return acc;
11265
+ }, {})
11266
+ );
11267
+ useEffect(() => {
11268
+ setRowSelection(
11269
+ items.reduce((acc, item) => {
11270
+ if (item.variant_id) {
11271
+ acc[item.variant_id] = true;
11272
+ }
11273
+ return acc;
11274
+ }, {})
11275
+ );
11276
+ }, [items]);
11277
+ const { q, order, offset } = useQueryParams(
11278
+ ["q", "order", "offset"],
11279
+ VARIANT_PREFIX
11280
+ );
11281
+ const { variants, count, isPending, isError, error } = useProductVariants(
11282
+ {
11283
+ q,
11284
+ order,
11285
+ offset: offset ? parseInt(offset) : void 0,
11286
+ limit: LIMIT
11447
11287
  },
11448
- resolver: zodResolver(schema$1)
11449
- });
11450
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11451
- const { handleSuccess } = useRouteModal();
11452
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11453
- const currentCustomer = order.customer ? {
11454
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11455
- value: order.customer.id
11456
- } : null;
11457
- const onSubmit = form.handleSubmit(async (data) => {
11288
+ {
11289
+ placeholderData: keepPreviousData
11290
+ }
11291
+ );
11292
+ const columns = useColumns();
11293
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
11294
+ const onSubmit = async () => {
11295
+ const ids = Object.keys(rowSelection).filter(
11296
+ (id) => !items.find((i) => i.variant_id === id)
11297
+ );
11458
11298
  await mutateAsync(
11459
- { customer_id: data.customer_id },
11299
+ {
11300
+ items: ids.map((id) => ({
11301
+ variant_id: id,
11302
+ quantity: 1
11303
+ }))
11304
+ },
11460
11305
  {
11461
11306
  onSuccess: () => {
11462
- toast.success("Customer updated");
11463
- handleSuccess();
11307
+ setRowSelection({});
11308
+ setIsOpen(STACKED_MODAL_ID, false);
11464
11309
  },
11465
- onError: (error) => {
11466
- toast.error(error.message);
11310
+ onError: (e) => {
11311
+ toast.error(e.message);
11467
11312
  }
11468
11313
  }
11469
11314
  );
11470
- });
11471
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11472
- KeyboundForm,
11473
- {
11474
- className: "flex flex-1 flex-col overflow-hidden",
11475
- onSubmit,
11476
- children: [
11477
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11478
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11479
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11480
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11481
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11482
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11483
- ] }),
11484
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11485
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11486
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11487
- ] })
11488
- ] }),
11489
- /* @__PURE__ */ jsx(
11490
- CustomerField,
11491
- {
11492
- control: form.control,
11493
- currentCustomerId: order.customer_id
11494
- }
11495
- )
11496
- ] }),
11497
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11498
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11499
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11500
- ] }) })
11501
- ]
11502
- }
11503
- ) });
11504
- };
11505
- const CustomerField = ({ control, currentCustomerId }) => {
11506
- const customers = useComboboxData({
11507
- queryFn: async (params) => {
11508
- return await sdk.admin.customer.list({
11509
- ...params,
11510
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11511
- });
11512
- },
11513
- queryKey: ["customers"],
11514
- getOptions: (data) => {
11515
- return data.customers.map((customer) => {
11516
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11517
- return {
11518
- label: name ? `${name} (${customer.email})` : customer.email,
11519
- value: customer.id
11520
- };
11521
- });
11522
- }
11523
- });
11524
- return /* @__PURE__ */ jsx(
11525
- Form$2.Field,
11315
+ };
11316
+ if (isError) {
11317
+ throw error;
11318
+ }
11319
+ return /* @__PURE__ */ jsxs(
11320
+ StackedFocusModal.Content,
11526
11321
  {
11527
- name: "customer_id",
11528
- control,
11529
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11530
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11531
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11532
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11322
+ onOpenAutoFocus: (e) => {
11323
+ e.preventDefault();
11324
+ const searchInput = document.querySelector(
11325
+ "[data-modal-id='modal-search-input']"
11326
+ );
11327
+ if (searchInput) {
11328
+ searchInput.focus();
11329
+ }
11330
+ },
11331
+ children: [
11332
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
11333
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
11334
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
11533
11335
  ] }),
11534
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11535
- Combobox,
11336
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
11337
+ DataTable,
11536
11338
  {
11537
- options: customers.options,
11538
- fetchNextPage: customers.fetchNextPage,
11539
- isFetchingNextPage: customers.isFetchingNextPage,
11540
- searchValue: customers.searchValue,
11541
- onSearchValueChange: customers.onSearchValueChange,
11542
- placeholder: "Select customer",
11543
- ...field
11339
+ data: variants,
11340
+ columns,
11341
+ isLoading: isPending,
11342
+ getRowId: (row) => row.id,
11343
+ rowCount: count,
11344
+ prefix: VARIANT_PREFIX,
11345
+ layout: "fill",
11346
+ rowSelection: {
11347
+ state: rowSelection,
11348
+ onRowSelectionChange: setRowSelection,
11349
+ enableRowSelection: (row) => {
11350
+ return !items.find((i) => i.variant_id === row.original.id);
11351
+ }
11352
+ },
11353
+ autoFocusSearch: true
11544
11354
  }
11545
11355
  ) }),
11546
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11547
- ] })
11356
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
11357
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11358
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
11359
+ ] }) })
11360
+ ]
11548
11361
  }
11549
11362
  );
11550
11363
  };
11551
- const Illustration = () => {
11552
- return /* @__PURE__ */ jsxs(
11553
- "svg",
11554
- {
11555
- width: "280",
11556
- height: "180",
11557
- viewBox: "0 0 280 180",
11558
- fill: "none",
11559
- xmlns: "http://www.w3.org/2000/svg",
11560
- children: [
11561
- /* @__PURE__ */ jsx(
11562
- "rect",
11563
- {
11564
- x: "0.00428286",
11565
- y: "-0.742904",
11566
- width: "33.5",
11567
- height: "65.5",
11568
- rx: "6.75",
11569
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11570
- fill: "#D4D4D8",
11571
- stroke: "#52525B",
11572
- strokeWidth: "1.5"
11573
- }
11574
- ),
11575
- /* @__PURE__ */ jsx(
11576
- "rect",
11577
- {
11578
- x: "0.00428286",
11579
- y: "-0.742904",
11580
- width: "33.5",
11581
- height: "65.5",
11582
- rx: "6.75",
11583
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11584
- fill: "white",
11585
- stroke: "#52525B",
11586
- strokeWidth: "1.5"
11587
- }
11588
- ),
11589
- /* @__PURE__ */ jsx(
11590
- "path",
11591
- {
11592
- d: "M180.579 107.142L179.126 107.959",
11593
- stroke: "#52525B",
11594
- strokeWidth: "1.5",
11595
- strokeLinecap: "round",
11596
- strokeLinejoin: "round"
11597
- }
11598
- ),
11599
- /* @__PURE__ */ jsx(
11600
- "path",
11364
+ const columnHelper = createDataTableColumnHelper();
11365
+ const useColumns = () => {
11366
+ return useMemo(() => {
11367
+ return [
11368
+ columnHelper.select(),
11369
+ columnHelper.accessor("product.title", {
11370
+ header: "Product",
11371
+ cell: ({ row }) => {
11372
+ var _a, _b, _c;
11373
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
11374
+ /* @__PURE__ */ jsx(
11375
+ Thumbnail,
11376
+ {
11377
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11378
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
11379
+ }
11380
+ ),
11381
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11382
+ ] });
11383
+ },
11384
+ enableSorting: true
11385
+ }),
11386
+ columnHelper.accessor("title", {
11387
+ header: "Variant",
11388
+ enableSorting: true
11389
+ }),
11390
+ columnHelper.accessor("sku", {
11391
+ header: "SKU",
11392
+ cell: ({ getValue }) => {
11393
+ return getValue() ?? "-";
11394
+ },
11395
+ enableSorting: true
11396
+ }),
11397
+ columnHelper.accessor("updated_at", {
11398
+ header: "Updated",
11399
+ cell: ({ getValue }) => {
11400
+ return /* @__PURE__ */ jsx(
11401
+ Tooltip,
11402
+ {
11403
+ content: getFullDate({ date: getValue(), includeTime: true }),
11404
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11405
+ }
11406
+ );
11407
+ },
11408
+ enableSorting: true,
11409
+ sortAscLabel: "Oldest first",
11410
+ sortDescLabel: "Newest first"
11411
+ }),
11412
+ columnHelper.accessor("created_at", {
11413
+ header: "Created",
11414
+ cell: ({ getValue }) => {
11415
+ return /* @__PURE__ */ jsx(
11416
+ Tooltip,
11417
+ {
11418
+ content: getFullDate({ date: getValue(), includeTime: true }),
11419
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11420
+ }
11421
+ );
11422
+ },
11423
+ enableSorting: true,
11424
+ sortAscLabel: "Oldest first",
11425
+ sortDescLabel: "Newest first"
11426
+ })
11427
+ ];
11428
+ }, []);
11429
+ };
11430
+ const CustomItemForm = ({ orderId, currencyCode }) => {
11431
+ const { setIsOpen } = useStackedModal();
11432
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11433
+ const form = useForm({
11434
+ defaultValues: {
11435
+ title: "",
11436
+ quantity: 1,
11437
+ unit_price: ""
11438
+ },
11439
+ resolver: zodResolver(customItemSchema)
11440
+ });
11441
+ const onSubmit = form.handleSubmit(async (data) => {
11442
+ await addItems(
11443
+ {
11444
+ items: [
11601
11445
  {
11602
- opacity: "0.88",
11603
- d: "M182.305 109.546L180.257 109.534",
11604
- stroke: "#52525B",
11605
- strokeWidth: "1.5",
11606
- strokeLinecap: "round",
11607
- strokeLinejoin: "round"
11446
+ title: data.title,
11447
+ quantity: data.quantity,
11448
+ unit_price: convertNumber(data.unit_price)
11608
11449
  }
11609
- ),
11610
- /* @__PURE__ */ jsx(
11611
- "path",
11612
- {
11613
- opacity: "0.75",
11614
- d: "M180.551 111.93L179.108 111.096",
11615
- stroke: "#52525B",
11616
- strokeWidth: "1.5",
11617
- strokeLinecap: "round",
11618
- strokeLinejoin: "round"
11619
- }
11620
- ),
11621
- /* @__PURE__ */ jsx(
11622
- "path",
11623
- {
11624
- opacity: "0.63",
11625
- d: "M176.347 112.897L176.354 111.73",
11626
- stroke: "#52525B",
11627
- strokeWidth: "1.5",
11628
- strokeLinecap: "round",
11629
- strokeLinejoin: "round"
11630
- }
11631
- ),
11632
- /* @__PURE__ */ jsx(
11633
- "path",
11634
- {
11635
- opacity: "0.5",
11636
- d: "M172.153 111.881L173.606 111.064",
11637
- stroke: "#52525B",
11638
- strokeWidth: "1.5",
11639
- strokeLinecap: "round",
11640
- strokeLinejoin: "round"
11641
- }
11642
- ),
11643
- /* @__PURE__ */ jsx(
11644
- "path",
11645
- {
11646
- opacity: "0.38",
11647
- d: "M170.428 109.478L172.476 109.489",
11648
- stroke: "#52525B",
11649
- strokeWidth: "1.5",
11650
- strokeLinecap: "round",
11651
- strokeLinejoin: "round"
11652
- }
11653
- ),
11654
- /* @__PURE__ */ jsx(
11655
- "path",
11656
- {
11657
- opacity: "0.25",
11658
- d: "M172.181 107.094L173.624 107.928",
11659
- stroke: "#52525B",
11660
- strokeWidth: "1.5",
11661
- strokeLinecap: "round",
11662
- strokeLinejoin: "round"
11663
- }
11664
- ),
11665
- /* @__PURE__ */ jsx(
11666
- "path",
11667
- {
11668
- opacity: "0.13",
11669
- d: "M176.386 106.126L176.379 107.294",
11670
- stroke: "#52525B",
11671
- strokeWidth: "1.5",
11672
- strokeLinecap: "round",
11673
- strokeLinejoin: "round"
11674
- }
11675
- ),
11676
- /* @__PURE__ */ jsx(
11677
- "rect",
11678
- {
11679
- width: "12",
11680
- height: "3",
11681
- rx: "1.5",
11682
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11683
- fill: "#D4D4D8"
11684
- }
11685
- ),
11686
- /* @__PURE__ */ jsx(
11687
- "rect",
11688
- {
11689
- x: "0.00428286",
11690
- y: "-0.742904",
11691
- width: "33.5",
11692
- height: "65.5",
11693
- rx: "6.75",
11694
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11695
- fill: "#D4D4D8",
11696
- stroke: "#52525B",
11697
- strokeWidth: "1.5"
11698
- }
11699
- ),
11700
- /* @__PURE__ */ jsx(
11701
- "rect",
11702
- {
11703
- x: "0.00428286",
11704
- y: "-0.742904",
11705
- width: "33.5",
11706
- height: "65.5",
11707
- rx: "6.75",
11708
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11709
- fill: "white",
11710
- stroke: "#52525B",
11711
- strokeWidth: "1.5"
11712
- }
11713
- ),
11714
- /* @__PURE__ */ jsx(
11715
- "rect",
11716
- {
11717
- width: "12",
11718
- height: "3",
11719
- rx: "1.5",
11720
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11721
- fill: "#D4D4D8"
11722
- }
11723
- ),
11724
- /* @__PURE__ */ jsx(
11725
- "rect",
11726
- {
11727
- width: "17",
11728
- height: "3",
11729
- rx: "1.5",
11730
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11731
- fill: "#D4D4D8"
11732
- }
11733
- ),
11734
- /* @__PURE__ */ jsx(
11735
- "rect",
11736
- {
11737
- width: "12",
11738
- height: "3",
11739
- rx: "1.5",
11740
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11741
- fill: "#D4D4D8"
11742
- }
11743
- ),
11744
- /* @__PURE__ */ jsx(
11745
- "path",
11746
- {
11747
- 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",
11748
- fill: "#A1A1AA"
11749
- }
11750
- ),
11751
- /* @__PURE__ */ jsx(
11752
- "rect",
11753
- {
11754
- width: "17",
11755
- height: "3",
11756
- rx: "1.5",
11757
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11758
- fill: "#A1A1AA"
11759
- }
11760
- ),
11761
- /* @__PURE__ */ jsx(
11762
- "rect",
11763
- {
11764
- width: "12",
11765
- height: "3",
11766
- rx: "1.5",
11767
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11768
- fill: "#A1A1AA"
11769
- }
11770
- ),
11771
- /* @__PURE__ */ jsx(
11772
- "path",
11773
- {
11774
- 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",
11775
- fill: "#52525B"
11776
- }
11777
- ),
11778
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
11779
- "path",
11780
- {
11781
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11782
- stroke: "#A1A1AA",
11783
- strokeWidth: "1.5",
11784
- strokeLinecap: "round",
11785
- strokeLinejoin: "round"
11786
- }
11787
- ) }),
11788
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
11789
- "path",
11790
- {
11791
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11792
- stroke: "#A1A1AA",
11793
- strokeWidth: "1.5",
11794
- strokeLinecap: "round",
11795
- strokeLinejoin: "round"
11796
- }
11797
- ) }),
11798
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
11799
- "path",
11800
- {
11801
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11802
- stroke: "#A1A1AA",
11803
- strokeWidth: "1.5",
11804
- strokeLinecap: "round",
11805
- strokeLinejoin: "round"
11806
- }
11807
- ) }),
11808
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
11809
- "path",
11810
- {
11811
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11812
- stroke: "#A1A1AA",
11813
- strokeWidth: "1.5",
11814
- strokeLinecap: "round",
11815
- strokeLinejoin: "round"
11816
- }
11817
- ) }),
11818
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
11819
- "path",
11820
- {
11821
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11822
- stroke: "#A1A1AA",
11823
- strokeWidth: "1.5",
11824
- strokeLinecap: "round",
11825
- strokeLinejoin: "round"
11826
- }
11827
- ) }),
11828
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
11829
- "path",
11830
- {
11831
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11832
- stroke: "#A1A1AA",
11833
- strokeWidth: "1.5",
11834
- strokeLinecap: "round",
11835
- strokeLinejoin: "round"
11836
- }
11837
- ) }),
11838
- /* @__PURE__ */ jsxs("defs", { children: [
11839
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
11840
- "rect",
11841
- {
11842
- width: "12",
11843
- height: "12",
11844
- fill: "white",
11845
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11846
- }
11847
- ) }),
11848
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
11849
- "rect",
11850
- {
11851
- width: "12",
11852
- height: "12",
11853
- fill: "white",
11854
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11855
- }
11856
- ) }),
11857
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
11858
- "rect",
11859
- {
11860
- width: "12",
11861
- height: "12",
11862
- fill: "white",
11863
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11864
- }
11865
- ) }),
11866
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
11867
- "rect",
11868
- {
11869
- width: "12",
11870
- height: "12",
11871
- fill: "white",
11872
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
11873
- }
11874
- ) }),
11875
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
11876
- "rect",
11877
- {
11878
- width: "12",
11879
- height: "12",
11880
- fill: "white",
11881
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
11882
- }
11883
- ) }),
11884
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
11885
- "rect",
11886
- {
11887
- width: "12",
11888
- height: "12",
11889
- fill: "white",
11890
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
11891
- }
11892
- ) })
11893
- ] })
11894
- ]
11895
- }
11896
- );
11450
+ ]
11451
+ },
11452
+ {
11453
+ onSuccess: () => {
11454
+ setIsOpen(STACKED_MODAL_ID, false);
11455
+ },
11456
+ onError: (e) => {
11457
+ toast.error(e.message);
11458
+ }
11459
+ }
11460
+ );
11461
+ });
11462
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
11463
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11464
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
11465
+ /* @__PURE__ */ jsxs("div", { children: [
11466
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
11467
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
11468
+ ] }),
11469
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11470
+ /* @__PURE__ */ jsx(
11471
+ Form$2.Field,
11472
+ {
11473
+ control: form.control,
11474
+ name: "title",
11475
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11476
+ /* @__PURE__ */ jsxs("div", { children: [
11477
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
11478
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
11479
+ ] }),
11480
+ /* @__PURE__ */ jsxs("div", { children: [
11481
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11482
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11483
+ ] })
11484
+ ] }) })
11485
+ }
11486
+ ),
11487
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11488
+ /* @__PURE__ */ jsx(
11489
+ Form$2.Field,
11490
+ {
11491
+ control: form.control,
11492
+ name: "unit_price",
11493
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11494
+ /* @__PURE__ */ jsxs("div", { children: [
11495
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
11496
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11497
+ ] }),
11498
+ /* @__PURE__ */ jsxs("div", { children: [
11499
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11500
+ CurrencyInput,
11501
+ {
11502
+ symbol: getNativeSymbol(currencyCode),
11503
+ code: currencyCode,
11504
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11505
+ ...field
11506
+ }
11507
+ ) }),
11508
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11509
+ ] })
11510
+ ] }) })
11511
+ }
11512
+ ),
11513
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11514
+ /* @__PURE__ */ jsx(
11515
+ Form$2.Field,
11516
+ {
11517
+ control: form.control,
11518
+ name: "quantity",
11519
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11520
+ /* @__PURE__ */ jsxs("div", { children: [
11521
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
11522
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11523
+ ] }),
11524
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
11525
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
11526
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11527
+ ] })
11528
+ ] }) })
11529
+ }
11530
+ )
11531
+ ] }) }) }),
11532
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
11533
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11534
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11535
+ ] }) })
11536
+ ] }) }) });
11897
11537
  };
11898
- const schema$1 = objectType({
11899
- customer_id: stringType().min(1)
11538
+ const customItemSchema = objectType({
11539
+ title: stringType().min(1),
11540
+ quantity: numberType(),
11541
+ unit_price: unionType([numberType(), stringType()])
11900
11542
  });
11901
- const ShippingAddress = () => {
11543
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11544
+ const Shipping = () => {
11545
+ var _a;
11902
11546
  const { id } = useParams();
11903
11547
  const { order, isPending, isError, error } = useOrder(id, {
11904
- fields: "+shipping_address"
11548
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11905
11549
  });
11550
+ const {
11551
+ order: preview,
11552
+ isPending: isPreviewPending,
11553
+ isError: isPreviewError,
11554
+ error: previewError
11555
+ } = useOrderPreview(id);
11556
+ useInitiateOrderEdit({ preview });
11557
+ const { onCancel } = useCancelOrderEdit({ preview });
11906
11558
  if (isError) {
11907
11559
  throw error;
11908
11560
  }
11909
- const isReady = !isPending && !!order;
11910
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11911
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11912
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11913
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11561
+ if (isPreviewError) {
11562
+ throw previewError;
11563
+ }
11564
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11565
+ const isReady = preview && !isPreviewPending && order && !isPending;
11566
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11567
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11568
+ /* @__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: [
11569
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11570
+ /* @__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." }) })
11571
+ ] }) }) }),
11572
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11573
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11574
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11575
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11576
+ ] }) });
11577
+ };
11578
+ const ShippingForm = ({ preview, order }) => {
11579
+ var _a;
11580
+ const { setIsOpen } = useStackedModal();
11581
+ const [isSubmitting, setIsSubmitting] = useState(false);
11582
+ const [data, setData] = useState(null);
11583
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11584
+ const { shipping_options } = useShippingOptions(
11585
+ {
11586
+ id: appliedShippingOptionIds,
11587
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11588
+ },
11589
+ {
11590
+ enabled: appliedShippingOptionIds.length > 0
11591
+ }
11592
+ );
11593
+ const uniqueShippingProfiles = useMemo(() => {
11594
+ const profiles = /* @__PURE__ */ new Map();
11595
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11596
+ profiles.set(profile.id, profile);
11597
+ });
11598
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11599
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11600
+ });
11601
+ return Array.from(profiles.values());
11602
+ }, [order.items, shipping_options]);
11603
+ const { handleSuccess } = useRouteModal();
11604
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11605
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11606
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11607
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11608
+ const onSubmit = async () => {
11609
+ setIsSubmitting(true);
11610
+ let requestSucceeded = false;
11611
+ await requestOrderEdit(void 0, {
11612
+ onError: (e) => {
11613
+ toast.error(`Failed to request order edit: ${e.message}`);
11614
+ },
11615
+ onSuccess: () => {
11616
+ requestSucceeded = true;
11617
+ }
11618
+ });
11619
+ if (!requestSucceeded) {
11620
+ setIsSubmitting(false);
11621
+ return;
11622
+ }
11623
+ await confirmOrderEdit(void 0, {
11624
+ onError: (e) => {
11625
+ toast.error(`Failed to confirm order edit: ${e.message}`);
11626
+ },
11627
+ onSuccess: () => {
11628
+ handleSuccess();
11629
+ },
11630
+ onSettled: () => {
11631
+ setIsSubmitting(false);
11632
+ }
11633
+ });
11634
+ };
11635
+ const onKeydown = useCallback(
11636
+ (e) => {
11637
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11638
+ if (data || isSubmitting) {
11639
+ return;
11640
+ }
11641
+ onSubmit();
11642
+ }
11643
+ },
11644
+ [data, isSubmitting, onSubmit]
11645
+ );
11646
+ useEffect(() => {
11647
+ document.addEventListener("keydown", onKeydown);
11648
+ return () => {
11649
+ document.removeEventListener("keydown", onKeydown);
11650
+ };
11651
+ }, [onKeydown]);
11652
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11653
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11654
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11655
+ /* @__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: [
11656
+ /* @__PURE__ */ jsxs("div", { children: [
11657
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11658
+ /* @__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." }) })
11659
+ ] }),
11660
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11661
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11662
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11663
+ /* @__PURE__ */ jsx(
11664
+ Text,
11665
+ {
11666
+ size: "xsmall",
11667
+ weight: "plus",
11668
+ className: "text-ui-fg-muted",
11669
+ children: "Shipping profile"
11670
+ }
11671
+ ),
11672
+ /* @__PURE__ */ jsx(
11673
+ Text,
11674
+ {
11675
+ size: "xsmall",
11676
+ weight: "plus",
11677
+ className: "text-ui-fg-muted",
11678
+ children: "Action"
11679
+ }
11680
+ )
11681
+ ] }),
11682
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11683
+ var _a2, _b, _c, _d, _e, _f, _g;
11684
+ const items = getItemsWithShippingProfile(
11685
+ profile.id,
11686
+ order.items
11687
+ );
11688
+ const hasItems = items.length > 0;
11689
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11690
+ (option) => option.shipping_profile_id === profile.id
11691
+ );
11692
+ const shippingMethod = preview.shipping_methods.find(
11693
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11694
+ );
11695
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11696
+ (action) => action.action === "SHIPPING_ADD"
11697
+ );
11698
+ return /* @__PURE__ */ jsxs(
11699
+ Accordion.Item,
11700
+ {
11701
+ value: profile.id,
11702
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11703
+ children: [
11704
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11705
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11706
+ /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11707
+ IconButton,
11708
+ {
11709
+ size: "2xsmall",
11710
+ variant: "transparent",
11711
+ className: "group/trigger",
11712
+ disabled: !hasItems,
11713
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11714
+ }
11715
+ ) }),
11716
+ !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11717
+ /* @__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" }) }) }),
11718
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11719
+ /* @__PURE__ */ jsx(
11720
+ Text,
11721
+ {
11722
+ size: "small",
11723
+ weight: "plus",
11724
+ leading: "compact",
11725
+ children: profile.name
11726
+ }
11727
+ ),
11728
+ /* @__PURE__ */ jsxs(
11729
+ Text,
11730
+ {
11731
+ size: "small",
11732
+ leading: "compact",
11733
+ className: "text-ui-fg-subtle",
11734
+ children: [
11735
+ items.length,
11736
+ " ",
11737
+ pluralize(items.length, "items", "item")
11738
+ ]
11739
+ }
11740
+ )
11741
+ ] })
11742
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11743
+ /* @__PURE__ */ jsx(
11744
+ Tooltip,
11745
+ {
11746
+ content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11747
+ var _a3, _b2, _c2;
11748
+ return /* @__PURE__ */ jsx(
11749
+ "li",
11750
+ {
11751
+ 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})`
11752
+ },
11753
+ item.id
11754
+ );
11755
+ }) }),
11756
+ children: /* @__PURE__ */ jsxs(
11757
+ Badge,
11758
+ {
11759
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11760
+ size: "xsmall",
11761
+ children: [
11762
+ /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11763
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11764
+ items.reduce(
11765
+ (acc, item) => acc + item.quantity,
11766
+ 0
11767
+ ),
11768
+ "x",
11769
+ " ",
11770
+ pluralize(items.length, "items", "item")
11771
+ ] })
11772
+ ]
11773
+ }
11774
+ )
11775
+ }
11776
+ ),
11777
+ /* @__PURE__ */ jsx(
11778
+ Tooltip,
11779
+ {
11780
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11781
+ children: /* @__PURE__ */ jsxs(
11782
+ Badge,
11783
+ {
11784
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11785
+ size: "xsmall",
11786
+ children: [
11787
+ /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
11788
+ /* @__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 })
11789
+ ]
11790
+ }
11791
+ )
11792
+ }
11793
+ ),
11794
+ /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11795
+ Badge,
11796
+ {
11797
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11798
+ size: "xsmall",
11799
+ children: [
11800
+ /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11801
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11802
+ ]
11803
+ }
11804
+ ) })
11805
+ ] })
11806
+ ] }),
11807
+ shippingOption ? /* @__PURE__ */ jsx(
11808
+ ActionMenu,
11809
+ {
11810
+ groups: [
11811
+ {
11812
+ actions: [
11813
+ hasItems ? {
11814
+ label: "Edit shipping option",
11815
+ icon: /* @__PURE__ */ jsx(Channels, {}),
11816
+ onClick: () => {
11817
+ setIsOpen(
11818
+ STACKED_FOCUS_MODAL_ID,
11819
+ true
11820
+ );
11821
+ setData({
11822
+ shippingProfileId: profile.id,
11823
+ shippingOption,
11824
+ shippingMethod
11825
+ });
11826
+ }
11827
+ } : void 0,
11828
+ {
11829
+ label: "Remove shipping option",
11830
+ icon: /* @__PURE__ */ jsx(Trash, {}),
11831
+ onClick: () => {
11832
+ if (shippingMethod) {
11833
+ if (addShippingMethodAction) {
11834
+ removeActionShippingMethod(
11835
+ addShippingMethodAction.id
11836
+ );
11837
+ } else {
11838
+ removeShippingMethod(
11839
+ shippingMethod.id
11840
+ );
11841
+ }
11842
+ }
11843
+ }
11844
+ }
11845
+ ].filter(Boolean)
11846
+ }
11847
+ ]
11848
+ }
11849
+ ) : /* @__PURE__ */ jsx(
11850
+ StackedModalTrigger,
11851
+ {
11852
+ shippingProfileId: profile.id,
11853
+ shippingOption,
11854
+ shippingMethod,
11855
+ setData,
11856
+ children: "Add shipping option"
11857
+ }
11858
+ )
11859
+ ] }),
11860
+ /* @__PURE__ */ jsxs(Accordion.Content, { children: [
11861
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11862
+ items.map((item, idx) => {
11863
+ var _a3, _b2, _c2, _d2, _e2;
11864
+ return /* @__PURE__ */ jsxs("div", { children: [
11865
+ /* @__PURE__ */ jsxs(
11866
+ "div",
11867
+ {
11868
+ className: "px-3 flex items-center gap-x-3",
11869
+ children: [
11870
+ /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11871
+ Divider,
11872
+ {
11873
+ variant: "dashed",
11874
+ orientation: "vertical"
11875
+ }
11876
+ ) }),
11877
+ /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11878
+ /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11879
+ Text,
11880
+ {
11881
+ size: "small",
11882
+ leading: "compact",
11883
+ className: "text-ui-fg-subtle",
11884
+ children: [
11885
+ item.quantity,
11886
+ "x"
11887
+ ]
11888
+ }
11889
+ ) }),
11890
+ /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
11891
+ /* @__PURE__ */ jsxs("div", { children: [
11892
+ /* @__PURE__ */ jsxs(
11893
+ Text,
11894
+ {
11895
+ size: "small",
11896
+ leading: "compact",
11897
+ weight: "plus",
11898
+ children: [
11899
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11900
+ " (",
11901
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
11902
+ ")"
11903
+ ]
11904
+ }
11905
+ ),
11906
+ /* @__PURE__ */ jsx(
11907
+ Text,
11908
+ {
11909
+ size: "small",
11910
+ leading: "compact",
11911
+ className: "text-ui-fg-subtle",
11912
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11913
+ }
11914
+ )
11915
+ ] })
11916
+ ] })
11917
+ ]
11918
+ },
11919
+ item.id
11920
+ ),
11921
+ idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11922
+ ] }, item.id);
11923
+ })
11924
+ ] })
11925
+ ]
11926
+ },
11927
+ profile.id
11928
+ );
11929
+ }) })
11930
+ ] }) })
11931
+ ] }) }),
11932
+ /* @__PURE__ */ jsx(
11933
+ StackedFocusModal,
11934
+ {
11935
+ id: STACKED_FOCUS_MODAL_ID,
11936
+ onOpenChangeCallback: (open) => {
11937
+ if (!open) {
11938
+ setData(null);
11939
+ }
11940
+ return open;
11941
+ },
11942
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11943
+ }
11944
+ )
11914
11945
  ] }),
11915
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11946
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11947
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11948
+ /* @__PURE__ */ jsx(
11949
+ Button,
11950
+ {
11951
+ size: "small",
11952
+ type: "button",
11953
+ isLoading: isSubmitting,
11954
+ onClick: onSubmit,
11955
+ children: "Save"
11956
+ }
11957
+ )
11958
+ ] }) })
11916
11959
  ] });
11917
11960
  };
11918
- const ShippingAddressForm = ({ order }) => {
11919
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11961
+ const StackedModalTrigger = ({
11962
+ shippingProfileId,
11963
+ shippingOption,
11964
+ shippingMethod,
11965
+ setData,
11966
+ children
11967
+ }) => {
11968
+ const { setIsOpen, getIsOpen } = useStackedModal();
11969
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11970
+ const onToggle = () => {
11971
+ if (isOpen) {
11972
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11973
+ setData(null);
11974
+ } else {
11975
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11976
+ setData({
11977
+ shippingProfileId,
11978
+ shippingOption,
11979
+ shippingMethod
11980
+ });
11981
+ }
11982
+ };
11983
+ return /* @__PURE__ */ jsx(
11984
+ Button,
11985
+ {
11986
+ size: "small",
11987
+ variant: "secondary",
11988
+ onClick: onToggle,
11989
+ className: "text-ui-fg-primary shrink-0",
11990
+ children
11991
+ }
11992
+ );
11993
+ };
11994
+ const ShippingProfileForm = ({
11995
+ data,
11996
+ order,
11997
+ preview
11998
+ }) => {
11999
+ var _a, _b, _c, _d, _e, _f;
12000
+ const { setIsOpen } = useStackedModal();
11920
12001
  const form = useForm({
12002
+ resolver: zodResolver(shippingMethodSchema),
11921
12003
  defaultValues: {
11922
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11923
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11924
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11925
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11926
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11927
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11928
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11929
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11930
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11931
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11932
- },
11933
- resolver: zodResolver(schema)
12004
+ 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,
12005
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12006
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12007
+ }
11934
12008
  });
11935
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11936
- const { handleSuccess } = useRouteModal();
11937
- const onSubmit = form.handleSubmit(async (data) => {
11938
- await mutateAsync(
11939
- {
11940
- shipping_address: {
11941
- first_name: data.first_name,
11942
- last_name: data.last_name,
11943
- company: data.company,
11944
- address_1: data.address_1,
11945
- address_2: data.address_2,
11946
- city: data.city,
11947
- province: data.province,
11948
- country_code: data.country_code,
11949
- postal_code: data.postal_code,
11950
- phone: data.phone
12009
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12010
+ const {
12011
+ mutateAsync: updateShippingMethod,
12012
+ isPending: isUpdatingShippingMethod
12013
+ } = useDraftOrderUpdateShippingMethod(order.id);
12014
+ const onSubmit = form.handleSubmit(async (values) => {
12015
+ if (isEqual(values, form.formState.defaultValues)) {
12016
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12017
+ return;
12018
+ }
12019
+ if (data.shippingMethod) {
12020
+ await updateShippingMethod(
12021
+ {
12022
+ method_id: data.shippingMethod.id,
12023
+ shipping_option_id: values.shipping_option_id,
12024
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12025
+ },
12026
+ {
12027
+ onError: (e) => {
12028
+ toast.error(e.message);
12029
+ },
12030
+ onSuccess: () => {
12031
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12032
+ }
11951
12033
  }
12034
+ );
12035
+ return;
12036
+ }
12037
+ await addShippingMethod(
12038
+ {
12039
+ shipping_option_id: values.shipping_option_id,
12040
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11952
12041
  },
11953
12042
  {
11954
- onSuccess: () => {
11955
- handleSuccess();
12043
+ onError: (e) => {
12044
+ toast.error(e.message);
11956
12045
  },
11957
- onError: (error) => {
11958
- toast.error(error.message);
12046
+ onSuccess: () => {
12047
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11959
12048
  }
11960
12049
  }
11961
12050
  );
11962
12051
  });
11963
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12052
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
11964
12053
  KeyboundForm,
11965
12054
  {
11966
- className: "flex flex-1 flex-col overflow-hidden",
12055
+ className: "flex h-full flex-col overflow-hidden",
11967
12056
  onSubmit,
11968
12057
  children: [
11969
- /* @__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: [
11970
- /* @__PURE__ */ jsx(
11971
- Form$2.Field,
11972
- {
11973
- control: form.control,
11974
- name: "country_code",
11975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11976
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11979
- ] })
11980
- }
11981
- ),
11982
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11983
- /* @__PURE__ */ jsx(
11984
- Form$2.Field,
11985
- {
11986
- control: form.control,
11987
- name: "first_name",
11988
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11989
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11990
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11991
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11992
- ] })
11993
- }
11994
- ),
11995
- /* @__PURE__ */ jsx(
11996
- Form$2.Field,
11997
- {
11998
- control: form.control,
11999
- name: "last_name",
12000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12001
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12004
- ] })
12005
- }
12006
- )
12058
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12059
+ /* @__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: [
12060
+ /* @__PURE__ */ jsxs("div", { children: [
12061
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12062
+ /* @__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." }) })
12007
12063
  ] }),
12064
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12008
12065
  /* @__PURE__ */ jsx(
12009
- Form$2.Field,
12010
- {
12011
- control: form.control,
12012
- name: "company",
12013
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12014
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12015
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12016
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12017
- ] })
12018
- }
12019
- ),
12020
- /* @__PURE__ */ jsx(
12021
- Form$2.Field,
12022
- {
12023
- control: form.control,
12024
- name: "address_1",
12025
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12026
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12027
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12028
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12029
- ] })
12030
- }
12031
- ),
12032
- /* @__PURE__ */ jsx(
12033
- Form$2.Field,
12066
+ LocationField,
12034
12067
  {
12035
12068
  control: form.control,
12036
- name: "address_2",
12037
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12038
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12039
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12040
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12041
- ] })
12069
+ setValue: form.setValue
12042
12070
  }
12043
12071
  ),
12044
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12045
- /* @__PURE__ */ jsx(
12046
- Form$2.Field,
12047
- {
12048
- control: form.control,
12049
- name: "postal_code",
12050
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12051
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12052
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12053
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12054
- ] })
12055
- }
12056
- ),
12057
- /* @__PURE__ */ jsx(
12058
- Form$2.Field,
12059
- {
12060
- control: form.control,
12061
- name: "city",
12062
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12063
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12064
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12065
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12066
- ] })
12067
- }
12068
- )
12069
- ] }),
12072
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12070
12073
  /* @__PURE__ */ jsx(
12071
- Form$2.Field,
12074
+ ShippingOptionField,
12072
12075
  {
12073
- control: form.control,
12074
- name: "province",
12075
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12076
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12077
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12078
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12079
- ] })
12076
+ shippingProfileId: data.shippingProfileId,
12077
+ preview,
12078
+ control: form.control
12080
12079
  }
12081
12080
  ),
12081
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12082
12082
  /* @__PURE__ */ jsx(
12083
- Form$2.Field,
12083
+ CustomAmountField,
12084
12084
  {
12085
12085
  control: form.control,
12086
- name: "phone",
12087
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12088
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12089
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12090
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12091
- ] })
12086
+ currencyCode: order.currency_code
12087
+ }
12088
+ ),
12089
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12090
+ /* @__PURE__ */ jsx(
12091
+ ItemsPreview,
12092
+ {
12093
+ order,
12094
+ shippingProfileId: data.shippingProfileId
12095
+ }
12096
+ )
12097
+ ] }) }) }),
12098
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12099
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12100
+ /* @__PURE__ */ jsx(
12101
+ Button,
12102
+ {
12103
+ size: "small",
12104
+ type: "submit",
12105
+ isLoading: isPending || isUpdatingShippingMethod,
12106
+ children: data.shippingMethod ? "Update" : "Add"
12092
12107
  }
12093
12108
  )
12094
- ] }) }),
12095
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12096
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12097
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12098
12109
  ] }) })
12099
12110
  ]
12100
12111
  }
12101
- ) });
12112
+ ) }) });
12102
12113
  };
12103
- const schema = addressSchema;
12104
- const NumberInput = forwardRef(
12105
- ({
12106
- value,
12107
- onChange,
12108
- size = "base",
12109
- min = 0,
12110
- max = 100,
12111
- step = 1,
12112
- className,
12113
- disabled,
12114
- ...props
12115
- }, ref) => {
12116
- const handleChange = (event) => {
12117
- const newValue = event.target.value === "" ? min : Number(event.target.value);
12118
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
12119
- onChange(newValue);
12120
- }
12121
- };
12122
- const handleIncrement = () => {
12123
- const newValue = value + step;
12124
- if (max === void 0 || newValue <= max) {
12125
- onChange(newValue);
12126
- }
12127
- };
12128
- const handleDecrement = () => {
12129
- const newValue = value - step;
12130
- if (min === void 0 || newValue >= min) {
12131
- onChange(newValue);
12132
- }
12133
- };
12134
- return /* @__PURE__ */ jsxs(
12135
- "div",
12136
- {
12137
- className: clx(
12138
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
12139
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
12140
- {
12141
- "h-7": size === "small",
12142
- "h-8": size === "base"
12143
- },
12144
- className
12145
- ),
12146
- children: [
12147
- /* @__PURE__ */ jsx(
12148
- "input",
12149
- {
12150
- ref,
12151
- type: "number",
12152
- value,
12153
- onChange: handleChange,
12154
- min,
12155
- max,
12156
- step,
12157
- className: clx(
12158
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
12159
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
12160
- "placeholder:text-ui-fg-muted"
12161
- ),
12162
- ...props
12163
- }
12164
- ),
12165
- /* @__PURE__ */ jsxs(
12166
- "button",
12167
- {
12168
- className: clx(
12169
- "flex items-center justify-center outline-none transition-fg",
12170
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12171
- "focus:bg-ui-bg-field-component-hover",
12172
- "hover:bg-ui-bg-field-component-hover",
12114
+ const shippingMethodSchema = objectType({
12115
+ location_id: stringType(),
12116
+ shipping_option_id: stringType(),
12117
+ custom_amount: unionType([numberType(), stringType()]).optional()
12118
+ });
12119
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12120
+ const matches = order.items.filter(
12121
+ (item) => {
12122
+ var _a, _b, _c;
12123
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12124
+ }
12125
+ );
12126
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12127
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12128
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12129
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12130
+ ] }) }),
12131
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12132
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12133
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12134
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12135
+ ] }),
12136
+ /* @__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(
12137
+ "div",
12138
+ {
12139
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12140
+ children: [
12141
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12142
+ /* @__PURE__ */ jsx(
12143
+ Thumbnail,
12173
12144
  {
12174
- "size-7": size === "small",
12175
- "size-8": size === "base"
12145
+ thumbnail: item.thumbnail,
12146
+ alt: item.product_title ?? void 0
12176
12147
  }
12177
12148
  ),
12178
- type: "button",
12179
- onClick: handleDecrement,
12180
- disabled: min !== void 0 && value <= min || disabled,
12181
- children: [
12182
- /* @__PURE__ */ jsx(Minus, {}),
12183
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
12184
- ]
12149
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12150
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12151
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12152
+ /* @__PURE__ */ jsxs(
12153
+ Text,
12154
+ {
12155
+ size: "small",
12156
+ leading: "compact",
12157
+ className: "text-ui-fg-subtle",
12158
+ children: [
12159
+ "(",
12160
+ item.variant_title,
12161
+ ")"
12162
+ ]
12163
+ }
12164
+ )
12165
+ ] }),
12166
+ /* @__PURE__ */ jsx(
12167
+ Text,
12168
+ {
12169
+ size: "small",
12170
+ leading: "compact",
12171
+ className: "text-ui-fg-subtle",
12172
+ children: item.variant_sku
12173
+ }
12174
+ )
12175
+ ] })
12176
+ ] }),
12177
+ /* @__PURE__ */ jsxs(
12178
+ Text,
12179
+ {
12180
+ size: "small",
12181
+ leading: "compact",
12182
+ className: "text-ui-fg-subtle",
12183
+ children: [
12184
+ item.quantity,
12185
+ "x"
12186
+ ]
12187
+ }
12188
+ )
12189
+ ]
12190
+ },
12191
+ item.id
12192
+ )) : /* @__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: [
12193
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12194
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12195
+ 'No items found for "',
12196
+ query,
12197
+ '".'
12198
+ ] })
12199
+ ] }) })
12200
+ ] })
12201
+ ] });
12202
+ };
12203
+ const LocationField = ({ control, setValue }) => {
12204
+ const locations = useComboboxData({
12205
+ queryKey: ["locations"],
12206
+ queryFn: async (params) => {
12207
+ return await sdk.admin.stockLocation.list(params);
12208
+ },
12209
+ getOptions: (data) => {
12210
+ return data.stock_locations.map((location) => ({
12211
+ label: location.name,
12212
+ value: location.id
12213
+ }));
12214
+ }
12215
+ });
12216
+ return /* @__PURE__ */ jsx(
12217
+ Form$2.Field,
12218
+ {
12219
+ control,
12220
+ name: "location_id",
12221
+ render: ({ field: { onChange, ...field } }) => {
12222
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12223
+ /* @__PURE__ */ jsxs("div", { children: [
12224
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12225
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12226
+ ] }),
12227
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12228
+ Combobox,
12229
+ {
12230
+ options: locations.options,
12231
+ fetchNextPage: locations.fetchNextPage,
12232
+ isFetchingNextPage: locations.isFetchingNextPage,
12233
+ searchValue: locations.searchValue,
12234
+ onSearchValueChange: locations.onSearchValueChange,
12235
+ placeholder: "Select location",
12236
+ onChange: (value) => {
12237
+ setValue("shipping_option_id", "", {
12238
+ shouldDirty: true,
12239
+ shouldTouch: true
12240
+ });
12241
+ onChange(value);
12242
+ },
12243
+ ...field
12185
12244
  }
12186
- ),
12187
- /* @__PURE__ */ jsxs(
12188
- "button",
12245
+ ) })
12246
+ ] }) });
12247
+ }
12248
+ }
12249
+ );
12250
+ };
12251
+ const ShippingOptionField = ({
12252
+ shippingProfileId,
12253
+ preview,
12254
+ control
12255
+ }) => {
12256
+ var _a;
12257
+ const locationId = useWatch({ control, name: "location_id" });
12258
+ const shippingOptions = useComboboxData({
12259
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12260
+ queryFn: async (params) => {
12261
+ return await sdk.admin.shippingOption.list({
12262
+ ...params,
12263
+ stock_location_id: locationId,
12264
+ shipping_profile_id: shippingProfileId
12265
+ });
12266
+ },
12267
+ getOptions: (data) => {
12268
+ return data.shipping_options.map((option) => {
12269
+ var _a2;
12270
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12271
+ (r) => r.attribute === "is_return" && r.value === "true"
12272
+ )) {
12273
+ return void 0;
12274
+ }
12275
+ return {
12276
+ label: option.name,
12277
+ value: option.id
12278
+ };
12279
+ }).filter(Boolean);
12280
+ },
12281
+ enabled: !!locationId && !!shippingProfileId,
12282
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12283
+ });
12284
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12285
+ return /* @__PURE__ */ jsx(
12286
+ Form$2.Field,
12287
+ {
12288
+ control,
12289
+ name: "shipping_option_id",
12290
+ render: ({ field }) => {
12291
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12292
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12293
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12294
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12295
+ ] }),
12296
+ /* @__PURE__ */ jsx(
12297
+ ConditionalTooltip,
12189
12298
  {
12190
- className: clx(
12191
- "flex items-center justify-center outline-none transition-fg",
12192
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12193
- "focus:bg-ui-bg-field-hover",
12194
- "hover:bg-ui-bg-field-hover",
12299
+ content: tooltipContent,
12300
+ showTooltip: !locationId || !shippingProfileId,
12301
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12302
+ Combobox,
12195
12303
  {
12196
- "size-7": size === "small",
12197
- "size-8": size === "base"
12304
+ options: shippingOptions.options,
12305
+ fetchNextPage: shippingOptions.fetchNextPage,
12306
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12307
+ searchValue: shippingOptions.searchValue,
12308
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12309
+ placeholder: "Select shipping option",
12310
+ ...field,
12311
+ disabled: !locationId || !shippingProfileId
12198
12312
  }
12199
- ),
12200
- type: "button",
12201
- onClick: handleIncrement,
12202
- disabled: max !== void 0 && value >= max || disabled,
12203
- children: [
12204
- /* @__PURE__ */ jsx(Plus, {}),
12205
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
12206
- ]
12313
+ ) }) })
12207
12314
  }
12208
12315
  )
12209
- ]
12316
+ ] }) });
12210
12317
  }
12211
- );
12212
- }
12213
- );
12214
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
12215
- const productVariantsQueryKeys = {
12216
- list: (query2) => [
12217
- PRODUCT_VARIANTS_QUERY_KEY,
12218
- query2 ? query2 : void 0
12219
- ]
12220
- };
12221
- const useProductVariants = (query2, options) => {
12222
- const { data, ...rest } = useQuery({
12223
- queryKey: productVariantsQueryKeys.list(query2),
12224
- queryFn: async () => await sdk.admin.productVariant.list(query2),
12225
- ...options
12226
- });
12227
- return { ...data, ...rest };
12318
+ }
12319
+ );
12228
12320
  };
12229
- const STACKED_MODAL_ID = "items_stacked_modal";
12230
- const Items = () => {
12231
- const { id } = useParams();
12232
- const {
12233
- order: preview,
12234
- isPending: isPreviewPending,
12235
- isError: isPreviewError,
12236
- error: previewError
12237
- } = useOrderPreview(id, void 0, {
12238
- placeholderData: keepPreviousData
12239
- });
12240
- useInitiateOrderEdit({ preview });
12241
- const { draft_order, isPending, isError, error } = useDraftOrder(
12242
- id,
12243
- {
12244
- fields: "currency_code"
12245
- },
12321
+ const CustomAmountField = ({
12322
+ control,
12323
+ currencyCode
12324
+ }) => {
12325
+ return /* @__PURE__ */ jsx(
12326
+ Form$2.Field,
12246
12327
  {
12247
- enabled: !!id
12328
+ control,
12329
+ name: "custom_amount",
12330
+ render: ({ field: { onChange, ...field } }) => {
12331
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12332
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12333
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12334
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12335
+ ] }),
12336
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12337
+ CurrencyInput,
12338
+ {
12339
+ ...field,
12340
+ onValueChange: (value) => onChange(value),
12341
+ symbol: getNativeSymbol(currencyCode),
12342
+ code: currencyCode
12343
+ }
12344
+ ) })
12345
+ ] });
12346
+ }
12248
12347
  }
12249
12348
  );
12250
- const { onCancel } = useCancelOrderEdit({ preview });
12349
+ };
12350
+ const ShippingAddress = () => {
12351
+ const { id } = useParams();
12352
+ const { order, isPending, isError, error } = useOrder(id, {
12353
+ fields: "+shipping_address"
12354
+ });
12251
12355
  if (isError) {
12252
12356
  throw error;
12253
12357
  }
12254
- if (isPreviewError) {
12255
- throw previewError;
12256
- }
12257
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
12258
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
12259
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
12260
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12261
- ] }) });
12358
+ const isReady = !isPending && !!order;
12359
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12360
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12361
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12362
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12363
+ ] }),
12364
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12365
+ ] });
12262
12366
  };
12263
- const ItemsForm = ({ preview, currencyCode }) => {
12264
- var _a;
12265
- const [isSubmitting, setIsSubmitting] = useState(false);
12266
- const [modalContent, setModalContent] = useState(
12267
- null
12268
- );
12367
+ const ShippingAddressForm = ({ order }) => {
12368
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12369
+ const form = useForm({
12370
+ defaultValues: {
12371
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12372
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12373
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12374
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12375
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12376
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12377
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12378
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12379
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12380
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12381
+ },
12382
+ resolver: zodResolver(schema$1)
12383
+ });
12384
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12269
12385
  const { handleSuccess } = useRouteModal();
12270
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
12271
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12272
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12273
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
12274
- const matches = useMemo(() => {
12275
- return matchSorter(preview.items, query2, {
12276
- keys: ["product_title", "variant_title", "variant_sku", "title"]
12277
- });
12278
- }, [preview.items, query2]);
12279
- const onSubmit = async () => {
12280
- setIsSubmitting(true);
12281
- let requestSucceeded = false;
12282
- await requestOrderEdit(void 0, {
12283
- onError: (e) => {
12284
- toast.error(`Failed to request order edit: ${e.message}`);
12285
- },
12286
- onSuccess: () => {
12287
- requestSucceeded = true;
12288
- }
12289
- });
12290
- if (!requestSucceeded) {
12291
- setIsSubmitting(false);
12292
- return;
12293
- }
12294
- await confirmOrderEdit(void 0, {
12295
- onError: (e) => {
12296
- toast.error(`Failed to confirm order edit: ${e.message}`);
12297
- },
12298
- onSuccess: () => {
12299
- handleSuccess();
12300
- },
12301
- onSettled: () => {
12302
- setIsSubmitting(false);
12303
- }
12304
- });
12305
- };
12306
- const onKeyDown = useCallback(
12307
- (e) => {
12308
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12309
- if (modalContent || isSubmitting) {
12310
- return;
12386
+ const onSubmit = form.handleSubmit(async (data) => {
12387
+ await mutateAsync(
12388
+ {
12389
+ shipping_address: {
12390
+ first_name: data.first_name,
12391
+ last_name: data.last_name,
12392
+ company: data.company,
12393
+ address_1: data.address_1,
12394
+ address_2: data.address_2,
12395
+ city: data.city,
12396
+ province: data.province,
12397
+ country_code: data.country_code,
12398
+ postal_code: data.postal_code,
12399
+ phone: data.phone
12311
12400
  }
12312
- onSubmit();
12313
- }
12314
- },
12315
- [modalContent, isSubmitting, onSubmit]
12316
- );
12317
- useEffect(() => {
12318
- document.addEventListener("keydown", onKeyDown);
12319
- return () => {
12320
- document.removeEventListener("keydown", onKeyDown);
12321
- };
12322
- }, [onKeyDown]);
12323
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12324
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12325
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
12326
- StackedFocusModal,
12401
+ },
12327
12402
  {
12328
- id: STACKED_MODAL_ID,
12329
- onOpenChangeCallback: (open) => {
12330
- if (!open) {
12331
- setModalContent(null);
12332
- }
12403
+ onSuccess: () => {
12404
+ handleSuccess();
12333
12405
  },
12334
- children: [
12335
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12336
- /* @__PURE__ */ jsxs("div", { children: [
12337
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
12338
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
12339
- ] }),
12340
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12341
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12342
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
12343
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
12345
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
12346
- ] }),
12347
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
12348
- /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
12349
- Input,
12350
- {
12351
- type: "search",
12352
- placeholder: "Search items",
12353
- value: searchValue,
12354
- onChange: (e) => onSearchValueChange(e.target.value)
12355
- }
12356
- ) }),
12357
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
12358
- /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
12359
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
12360
- /* @__PURE__ */ jsx(
12361
- StackedModalTrigger,
12362
- {
12363
- type: "add-items",
12364
- setModalContent
12365
- }
12366
- ),
12367
- /* @__PURE__ */ jsx(
12368
- StackedModalTrigger,
12369
- {
12370
- type: "add-custom-item",
12371
- setModalContent
12372
- }
12373
- )
12374
- ] })
12375
- ] })
12406
+ onError: (error) => {
12407
+ toast.error(error.message);
12408
+ }
12409
+ }
12410
+ );
12411
+ });
12412
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12413
+ KeyboundForm,
12414
+ {
12415
+ className: "flex flex-1 flex-col overflow-hidden",
12416
+ onSubmit,
12417
+ children: [
12418
+ /* @__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: [
12419
+ /* @__PURE__ */ jsx(
12420
+ Form$2.Field,
12421
+ {
12422
+ control: form.control,
12423
+ name: "country_code",
12424
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12425
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12426
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12427
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12428
+ ] })
12429
+ }
12430
+ ),
12431
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12432
+ /* @__PURE__ */ jsx(
12433
+ Form$2.Field,
12434
+ {
12435
+ control: form.control,
12436
+ name: "first_name",
12437
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12439
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12440
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12376
12441
  ] })
12377
- ] }),
12378
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12379
- /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
12380
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12381
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
12382
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
12383
- /* @__PURE__ */ jsx("div", {})
12384
- ] }) }),
12385
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__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: [
12386
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
12387
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
12388
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
12389
- Item,
12390
- {
12391
- item,
12392
- preview,
12393
- currencyCode
12394
- },
12395
- item.id
12396
- )) : /* @__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: [
12397
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12398
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12399
- 'No items found for "',
12400
- query2,
12401
- '".'
12402
- ] })
12403
- ] }) })
12442
+ }
12443
+ ),
12444
+ /* @__PURE__ */ jsx(
12445
+ Form$2.Field,
12446
+ {
12447
+ control: form.control,
12448
+ name: "last_name",
12449
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12450
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12451
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12452
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12453
+ ] })
12454
+ }
12455
+ )
12456
+ ] }),
12457
+ /* @__PURE__ */ jsx(
12458
+ Form$2.Field,
12459
+ {
12460
+ control: form.control,
12461
+ name: "company",
12462
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12464
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12404
12466
  ] })
12405
- ] }),
12406
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12407
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
12408
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
12409
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
12410
- Text,
12411
- {
12412
- size: "small",
12413
- leading: "compact",
12414
- className: "text-ui-fg-subtle",
12415
- children: [
12416
- itemCount,
12417
- " ",
12418
- itemCount === 1 ? "item" : "items"
12419
- ]
12420
- }
12421
- ) }),
12422
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
12423
- ] })
12424
- ] }) }),
12425
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
12426
- CustomItemForm,
12467
+ }
12468
+ ),
12469
+ /* @__PURE__ */ jsx(
12470
+ Form$2.Field,
12427
12471
  {
12428
- orderId: preview.id,
12429
- currencyCode
12472
+ control: form.control,
12473
+ name: "address_1",
12474
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12475
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12476
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12477
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12478
+ ] })
12430
12479
  }
12431
- ) : null)
12432
- ]
12433
- }
12434
- ) }),
12435
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12436
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12437
- /* @__PURE__ */ jsx(
12438
- Button,
12439
- {
12440
- size: "small",
12441
- type: "button",
12442
- onClick: onSubmit,
12443
- isLoading: isSubmitting,
12444
- children: "Save"
12445
- }
12446
- )
12447
- ] }) })
12448
- ] });
12480
+ ),
12481
+ /* @__PURE__ */ jsx(
12482
+ Form$2.Field,
12483
+ {
12484
+ control: form.control,
12485
+ name: "address_2",
12486
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12487
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12488
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12489
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12490
+ ] })
12491
+ }
12492
+ ),
12493
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12494
+ /* @__PURE__ */ jsx(
12495
+ Form$2.Field,
12496
+ {
12497
+ control: form.control,
12498
+ name: "postal_code",
12499
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12501
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
+ ] })
12504
+ }
12505
+ ),
12506
+ /* @__PURE__ */ jsx(
12507
+ Form$2.Field,
12508
+ {
12509
+ control: form.control,
12510
+ name: "city",
12511
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12512
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12513
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12514
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12515
+ ] })
12516
+ }
12517
+ )
12518
+ ] }),
12519
+ /* @__PURE__ */ jsx(
12520
+ Form$2.Field,
12521
+ {
12522
+ control: form.control,
12523
+ name: "province",
12524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
+ ] })
12529
+ }
12530
+ ),
12531
+ /* @__PURE__ */ jsx(
12532
+ Form$2.Field,
12533
+ {
12534
+ control: form.control,
12535
+ name: "phone",
12536
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12537
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12538
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12539
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12540
+ ] })
12541
+ }
12542
+ )
12543
+ ] }) }),
12544
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12545
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12546
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12547
+ ] }) })
12548
+ ]
12549
+ }
12550
+ ) });
12449
12551
  };
12450
- const Item = ({ item, preview, currencyCode }) => {
12451
- if (item.variant_id) {
12452
- return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
12552
+ const schema$1 = addressSchema;
12553
+ const TransferOwnership = () => {
12554
+ const { id } = useParams();
12555
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12556
+ fields: "id,customer_id,customer.*"
12557
+ });
12558
+ if (isError) {
12559
+ throw error;
12453
12560
  }
12454
- return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
12561
+ const isReady = !isPending && !!draft_order;
12562
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12563
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12564
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12565
+ /* @__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" }) })
12566
+ ] }),
12567
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12568
+ ] });
12455
12569
  };
12456
- const VariantItem = ({ item, preview, currencyCode }) => {
12457
- const [editing, setEditing] = useState(false);
12570
+ const TransferOwnershipForm = ({ order }) => {
12571
+ var _a, _b;
12458
12572
  const form = useForm({
12459
12573
  defaultValues: {
12460
- quantity: item.quantity,
12461
- unit_price: item.unit_price
12574
+ customer_id: order.customer_id || ""
12462
12575
  },
12463
- resolver: zodResolver(variantItemSchema)
12576
+ resolver: zodResolver(schema)
12464
12577
  });
12465
- const actionId = useMemo(() => {
12466
- var _a, _b;
12467
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12468
- }, [item]);
12469
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12470
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12471
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12578
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12579
+ const { handleSuccess } = useRouteModal();
12580
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12581
+ const currentCustomer = order.customer ? {
12582
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12583
+ value: order.customer.id
12584
+ } : null;
12472
12585
  const onSubmit = form.handleSubmit(async (data) => {
12473
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
12474
- setEditing(false);
12475
- return;
12476
- }
12477
- if (!actionId) {
12478
- await updateOriginalItem(
12479
- {
12480
- item_id: item.id,
12481
- quantity: data.quantity,
12482
- unit_price: convertNumber(data.unit_price)
12586
+ await mutateAsync(
12587
+ { customer_id: data.customer_id },
12588
+ {
12589
+ onSuccess: () => {
12590
+ toast.success("Customer updated");
12591
+ handleSuccess();
12483
12592
  },
12484
- {
12485
- onSuccess: () => {
12486
- setEditing(false);
12487
- },
12488
- onError: (e) => {
12489
- toast.error(e.message);
12593
+ onError: (error) => {
12594
+ toast.error(error.message);
12595
+ }
12596
+ }
12597
+ );
12598
+ });
12599
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12600
+ KeyboundForm,
12601
+ {
12602
+ className: "flex flex-1 flex-col overflow-hidden",
12603
+ onSubmit,
12604
+ children: [
12605
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12606
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12607
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12608
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12609
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12610
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12611
+ ] }),
12612
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12613
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12614
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12615
+ ] })
12616
+ ] }),
12617
+ /* @__PURE__ */ jsx(
12618
+ CustomerField,
12619
+ {
12620
+ control: form.control,
12621
+ currentCustomerId: order.customer_id
12622
+ }
12623
+ )
12624
+ ] }),
12625
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12626
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12627
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12628
+ ] }) })
12629
+ ]
12630
+ }
12631
+ ) });
12632
+ };
12633
+ const CustomerField = ({ control, currentCustomerId }) => {
12634
+ const customers = useComboboxData({
12635
+ queryFn: async (params) => {
12636
+ return await sdk.admin.customer.list({
12637
+ ...params,
12638
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12639
+ });
12640
+ },
12641
+ queryKey: ["customers"],
12642
+ getOptions: (data) => {
12643
+ return data.customers.map((customer) => {
12644
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12645
+ return {
12646
+ label: name ? `${name} (${customer.email})` : customer.email,
12647
+ value: customer.id
12648
+ };
12649
+ });
12650
+ }
12651
+ });
12652
+ return /* @__PURE__ */ jsx(
12653
+ Form$2.Field,
12654
+ {
12655
+ name: "customer_id",
12656
+ control,
12657
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12658
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12659
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12660
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12661
+ ] }),
12662
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12663
+ Combobox,
12664
+ {
12665
+ options: customers.options,
12666
+ fetchNextPage: customers.fetchNextPage,
12667
+ isFetchingNextPage: customers.isFetchingNextPage,
12668
+ searchValue: customers.searchValue,
12669
+ onSearchValueChange: customers.onSearchValueChange,
12670
+ placeholder: "Select customer",
12671
+ ...field
12672
+ }
12673
+ ) }),
12674
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12675
+ ] })
12676
+ }
12677
+ );
12678
+ };
12679
+ const Illustration = () => {
12680
+ return /* @__PURE__ */ jsxs(
12681
+ "svg",
12682
+ {
12683
+ width: "280",
12684
+ height: "180",
12685
+ viewBox: "0 0 280 180",
12686
+ fill: "none",
12687
+ xmlns: "http://www.w3.org/2000/svg",
12688
+ children: [
12689
+ /* @__PURE__ */ jsx(
12690
+ "rect",
12691
+ {
12692
+ x: "0.00428286",
12693
+ y: "-0.742904",
12694
+ width: "33.5",
12695
+ height: "65.5",
12696
+ rx: "6.75",
12697
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12698
+ fill: "#D4D4D8",
12699
+ stroke: "#52525B",
12700
+ strokeWidth: "1.5"
12701
+ }
12702
+ ),
12703
+ /* @__PURE__ */ jsx(
12704
+ "rect",
12705
+ {
12706
+ x: "0.00428286",
12707
+ y: "-0.742904",
12708
+ width: "33.5",
12709
+ height: "65.5",
12710
+ rx: "6.75",
12711
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12712
+ fill: "white",
12713
+ stroke: "#52525B",
12714
+ strokeWidth: "1.5"
12715
+ }
12716
+ ),
12717
+ /* @__PURE__ */ jsx(
12718
+ "path",
12719
+ {
12720
+ d: "M180.579 107.142L179.126 107.959",
12721
+ stroke: "#52525B",
12722
+ strokeWidth: "1.5",
12723
+ strokeLinecap: "round",
12724
+ strokeLinejoin: "round"
12725
+ }
12726
+ ),
12727
+ /* @__PURE__ */ jsx(
12728
+ "path",
12729
+ {
12730
+ opacity: "0.88",
12731
+ d: "M182.305 109.546L180.257 109.534",
12732
+ stroke: "#52525B",
12733
+ strokeWidth: "1.5",
12734
+ strokeLinecap: "round",
12735
+ strokeLinejoin: "round"
12736
+ }
12737
+ ),
12738
+ /* @__PURE__ */ jsx(
12739
+ "path",
12740
+ {
12741
+ opacity: "0.75",
12742
+ d: "M180.551 111.93L179.108 111.096",
12743
+ stroke: "#52525B",
12744
+ strokeWidth: "1.5",
12745
+ strokeLinecap: "round",
12746
+ strokeLinejoin: "round"
12747
+ }
12748
+ ),
12749
+ /* @__PURE__ */ jsx(
12750
+ "path",
12751
+ {
12752
+ opacity: "0.63",
12753
+ d: "M176.347 112.897L176.354 111.73",
12754
+ stroke: "#52525B",
12755
+ strokeWidth: "1.5",
12756
+ strokeLinecap: "round",
12757
+ strokeLinejoin: "round"
12758
+ }
12759
+ ),
12760
+ /* @__PURE__ */ jsx(
12761
+ "path",
12762
+ {
12763
+ opacity: "0.5",
12764
+ d: "M172.153 111.881L173.606 111.064",
12765
+ stroke: "#52525B",
12766
+ strokeWidth: "1.5",
12767
+ strokeLinecap: "round",
12768
+ strokeLinejoin: "round"
12769
+ }
12770
+ ),
12771
+ /* @__PURE__ */ jsx(
12772
+ "path",
12773
+ {
12774
+ opacity: "0.38",
12775
+ d: "M170.428 109.478L172.476 109.489",
12776
+ stroke: "#52525B",
12777
+ strokeWidth: "1.5",
12778
+ strokeLinecap: "round",
12779
+ strokeLinejoin: "round"
12780
+ }
12781
+ ),
12782
+ /* @__PURE__ */ jsx(
12783
+ "path",
12784
+ {
12785
+ opacity: "0.25",
12786
+ d: "M172.181 107.094L173.624 107.928",
12787
+ stroke: "#52525B",
12788
+ strokeWidth: "1.5",
12789
+ strokeLinecap: "round",
12790
+ strokeLinejoin: "round"
12490
12791
  }
12491
- }
12492
- );
12493
- return;
12494
- }
12495
- await updateActionItem(
12496
- {
12497
- action_id: actionId,
12498
- quantity: data.quantity,
12499
- unit_price: convertNumber(data.unit_price)
12500
- },
12501
- {
12502
- onSuccess: () => {
12503
- setEditing(false);
12504
- },
12505
- onError: (e) => {
12506
- toast.error(e.message);
12507
- }
12508
- }
12509
- );
12510
- });
12511
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12512
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
12513
- /* @__PURE__ */ jsx(
12514
- Thumbnail,
12515
- {
12516
- thumbnail: item.thumbnail,
12517
- alt: item.product_title ?? void 0
12518
- }
12519
- ),
12520
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12521
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12522
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12523
- /* @__PURE__ */ jsxs(
12524
- Text,
12525
- {
12526
- size: "small",
12527
- leading: "compact",
12528
- className: "text-ui-fg-subtle",
12529
- children: [
12530
- "(",
12531
- item.variant_title,
12532
- ")"
12533
- ]
12534
- }
12535
- )
12536
- ] }),
12792
+ ),
12537
12793
  /* @__PURE__ */ jsx(
12538
- Text,
12794
+ "path",
12539
12795
  {
12540
- size: "small",
12541
- leading: "compact",
12542
- className: "text-ui-fg-subtle",
12543
- children: item.variant_sku
12796
+ opacity: "0.13",
12797
+ d: "M176.386 106.126L176.379 107.294",
12798
+ stroke: "#52525B",
12799
+ strokeWidth: "1.5",
12800
+ strokeLinecap: "round",
12801
+ strokeLinejoin: "round"
12544
12802
  }
12545
- )
12546
- ] })
12547
- ] }),
12548
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
12549
- Form$2.Field,
12550
- {
12551
- control: form.control,
12552
- name: "quantity",
12553
- render: ({ field }) => {
12554
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12555
- }
12556
- }
12557
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
12558
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
12559
- Form$2.Field,
12560
- {
12561
- control: form.control,
12562
- name: "unit_price",
12563
- render: ({ field: { onChange, ...field } }) => {
12564
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12565
- CurrencyInput,
12566
- {
12567
- ...field,
12568
- symbol: getNativeSymbol(currencyCode),
12569
- code: currencyCode,
12570
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12571
- }
12572
- ) }) });
12573
- }
12574
- }
12575
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12576
- /* @__PURE__ */ jsx(
12577
- IconButton,
12578
- {
12579
- type: "button",
12580
- size: "small",
12581
- onClick: editing ? onSubmit : () => {
12582
- setEditing(true);
12583
- },
12584
- disabled: isPending,
12585
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12586
- }
12587
- )
12588
- ] }) }) });
12589
- };
12590
- const variantItemSchema = objectType({
12591
- quantity: numberType(),
12592
- unit_price: unionType([numberType(), stringType()])
12593
- });
12594
- const CustomItem = ({ item, preview, currencyCode }) => {
12595
- const [editing, setEditing] = useState(false);
12596
- const { quantity, unit_price, title } = item;
12597
- const form = useForm({
12598
- defaultValues: {
12599
- title,
12600
- quantity,
12601
- unit_price
12602
- },
12603
- resolver: zodResolver(customItemSchema)
12604
- });
12605
- useEffect(() => {
12606
- form.reset({
12607
- title,
12608
- quantity,
12609
- unit_price
12610
- });
12611
- }, [form, title, quantity, unit_price]);
12612
- const actionId = useMemo(() => {
12613
- var _a, _b;
12614
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12615
- }, [item]);
12616
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12617
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12618
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12619
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12620
- const onSubmit = form.handleSubmit(async (data) => {
12621
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12622
- setEditing(false);
12623
- return;
12624
- }
12625
- if (!actionId) {
12626
- await updateOriginalItem(
12627
- {
12628
- item_id: item.id,
12629
- quantity: data.quantity,
12630
- unit_price: convertNumber(data.unit_price)
12631
- },
12632
- {
12633
- onSuccess: () => {
12634
- setEditing(false);
12635
- },
12636
- onError: (e) => {
12637
- toast.error(e.message);
12803
+ ),
12804
+ /* @__PURE__ */ jsx(
12805
+ "rect",
12806
+ {
12807
+ width: "12",
12808
+ height: "3",
12809
+ rx: "1.5",
12810
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12811
+ fill: "#D4D4D8"
12638
12812
  }
12639
- }
12640
- );
12641
- return;
12642
- }
12643
- if (data.quantity === 0) {
12644
- await removeActionItem(actionId, {
12645
- onSuccess: () => {
12646
- setEditing(false);
12647
- },
12648
- onError: (e) => {
12649
- toast.error(e.message);
12650
- }
12651
- });
12652
- return;
12653
- }
12654
- await updateActionItem(
12655
- {
12656
- action_id: actionId,
12657
- quantity: data.quantity,
12658
- unit_price: convertNumber(data.unit_price)
12659
- },
12660
- {
12661
- onSuccess: () => {
12662
- setEditing(false);
12663
- },
12664
- onError: (e) => {
12665
- toast.error(e.message);
12666
- }
12667
- }
12668
- );
12669
- });
12670
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12671
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12672
- /* @__PURE__ */ jsx(
12673
- Thumbnail,
12674
- {
12675
- thumbnail: item.thumbnail,
12676
- alt: item.title ?? void 0
12677
- }
12678
- ),
12679
- editing ? /* @__PURE__ */ jsx(
12680
- Form$2.Field,
12681
- {
12682
- control: form.control,
12683
- name: "title",
12684
- render: ({ field }) => {
12685
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
12813
+ ),
12814
+ /* @__PURE__ */ jsx(
12815
+ "rect",
12816
+ {
12817
+ x: "0.00428286",
12818
+ y: "-0.742904",
12819
+ width: "33.5",
12820
+ height: "65.5",
12821
+ rx: "6.75",
12822
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12823
+ fill: "#D4D4D8",
12824
+ stroke: "#52525B",
12825
+ strokeWidth: "1.5"
12826
+ }
12827
+ ),
12828
+ /* @__PURE__ */ jsx(
12829
+ "rect",
12830
+ {
12831
+ x: "0.00428286",
12832
+ y: "-0.742904",
12833
+ width: "33.5",
12834
+ height: "65.5",
12835
+ rx: "6.75",
12836
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12837
+ fill: "white",
12838
+ stroke: "#52525B",
12839
+ strokeWidth: "1.5"
12840
+ }
12841
+ ),
12842
+ /* @__PURE__ */ jsx(
12843
+ "rect",
12844
+ {
12845
+ width: "12",
12846
+ height: "3",
12847
+ rx: "1.5",
12848
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12849
+ fill: "#D4D4D8"
12850
+ }
12851
+ ),
12852
+ /* @__PURE__ */ jsx(
12853
+ "rect",
12854
+ {
12855
+ width: "17",
12856
+ height: "3",
12857
+ rx: "1.5",
12858
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12859
+ fill: "#D4D4D8"
12686
12860
  }
12687
- }
12688
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
12689
- ] }),
12690
- editing ? /* @__PURE__ */ jsx(
12691
- Form$2.Field,
12692
- {
12693
- control: form.control,
12694
- name: "quantity",
12695
- render: ({ field }) => {
12696
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12697
- }
12698
- }
12699
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
12700
- editing ? /* @__PURE__ */ jsx(
12701
- Form$2.Field,
12702
- {
12703
- control: form.control,
12704
- name: "unit_price",
12705
- render: ({ field: { onChange, ...field } }) => {
12706
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12707
- CurrencyInput,
12708
- {
12709
- ...field,
12710
- symbol: getNativeSymbol(currencyCode),
12711
- code: currencyCode,
12712
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12713
- }
12714
- ) }) });
12715
- }
12716
- }
12717
- ) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12718
- /* @__PURE__ */ jsx(
12719
- IconButton,
12720
- {
12721
- type: "button",
12722
- size: "small",
12723
- onClick: editing ? onSubmit : () => {
12724
- setEditing(true);
12725
- },
12726
- disabled: isPending,
12727
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12728
- }
12729
- )
12730
- ] }) }) });
12731
- };
12732
- const StackedModalTrigger = ({
12733
- type,
12734
- setModalContent
12735
- }) => {
12736
- const { setIsOpen } = useStackedModal();
12737
- const onClick = useCallback(() => {
12738
- setModalContent(type);
12739
- setIsOpen(STACKED_MODAL_ID, true);
12740
- }, [setModalContent, setIsOpen, type]);
12741
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12742
- };
12743
- const VARIANT_PREFIX = "items";
12744
- const LIMIT = 50;
12745
- const ExistingItemsForm = ({ orderId, items }) => {
12746
- const { setIsOpen } = useStackedModal();
12747
- const [rowSelection, setRowSelection] = useState(
12748
- items.reduce((acc, item) => {
12749
- acc[item.variant_id] = true;
12750
- return acc;
12751
- }, {})
12752
- );
12753
- useEffect(() => {
12754
- setRowSelection(
12755
- items.reduce((acc, item) => {
12756
- if (item.variant_id) {
12757
- acc[item.variant_id] = true;
12758
- }
12759
- return acc;
12760
- }, {})
12761
- );
12762
- }, [items]);
12763
- const { q, order, offset } = useQueryParams(
12764
- ["q", "order", "offset"],
12765
- VARIANT_PREFIX
12766
- );
12767
- const { variants, count, isPending, isError, error } = useProductVariants(
12768
- {
12769
- q,
12770
- order,
12771
- offset: offset ? parseInt(offset) : void 0,
12772
- limit: LIMIT
12773
- },
12774
- {
12775
- placeholderData: keepPreviousData
12776
- }
12777
- );
12778
- const columns = useColumns();
12779
- const { mutateAsync } = useDraftOrderAddItems(orderId);
12780
- const onSubmit = async () => {
12781
- const ids = Object.keys(rowSelection).filter(
12782
- (id) => !items.find((i) => i.variant_id === id)
12783
- );
12784
- await mutateAsync(
12785
- {
12786
- items: ids.map((id) => ({
12787
- variant_id: id,
12788
- quantity: 1
12789
- }))
12790
- },
12791
- {
12792
- onSuccess: () => {
12793
- setRowSelection({});
12794
- setIsOpen(STACKED_MODAL_ID, false);
12795
- },
12796
- onError: (e) => {
12797
- toast.error(e.message);
12798
- }
12799
- }
12800
- );
12801
- };
12802
- if (isError) {
12803
- throw error;
12804
- }
12805
- return /* @__PURE__ */ jsxs(
12806
- StackedFocusModal.Content,
12807
- {
12808
- onOpenAutoFocus: (e) => {
12809
- e.preventDefault();
12810
- const searchInput = document.querySelector(
12811
- "[data-modal-id='modal-search-input']"
12812
- );
12813
- if (searchInput) {
12814
- searchInput.focus();
12815
- }
12816
- },
12817
- children: [
12818
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
12819
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12820
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12821
- ] }),
12822
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
12823
- DataTable,
12861
+ ),
12862
+ /* @__PURE__ */ jsx(
12863
+ "rect",
12824
12864
  {
12825
- data: variants,
12826
- columns,
12827
- isLoading: isPending,
12828
- getRowId: (row) => row.id,
12829
- rowCount: count,
12830
- prefix: VARIANT_PREFIX,
12831
- layout: "fill",
12832
- rowSelection: {
12833
- state: rowSelection,
12834
- onRowSelectionChange: setRowSelection,
12835
- enableRowSelection: (row) => {
12836
- return !items.find((i) => i.variant_id === row.original.id);
12837
- }
12838
- },
12839
- autoFocusSearch: true
12865
+ width: "12",
12866
+ height: "3",
12867
+ rx: "1.5",
12868
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12869
+ fill: "#D4D4D8"
12870
+ }
12871
+ ),
12872
+ /* @__PURE__ */ jsx(
12873
+ "path",
12874
+ {
12875
+ 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",
12876
+ fill: "#A1A1AA"
12877
+ }
12878
+ ),
12879
+ /* @__PURE__ */ jsx(
12880
+ "rect",
12881
+ {
12882
+ width: "17",
12883
+ height: "3",
12884
+ rx: "1.5",
12885
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12886
+ fill: "#A1A1AA"
12887
+ }
12888
+ ),
12889
+ /* @__PURE__ */ jsx(
12890
+ "rect",
12891
+ {
12892
+ width: "12",
12893
+ height: "3",
12894
+ rx: "1.5",
12895
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12896
+ fill: "#A1A1AA"
12897
+ }
12898
+ ),
12899
+ /* @__PURE__ */ jsx(
12900
+ "path",
12901
+ {
12902
+ 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",
12903
+ fill: "#52525B"
12904
+ }
12905
+ ),
12906
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12907
+ "path",
12908
+ {
12909
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12910
+ stroke: "#A1A1AA",
12911
+ strokeWidth: "1.5",
12912
+ strokeLinecap: "round",
12913
+ strokeLinejoin: "round"
12840
12914
  }
12841
12915
  ) }),
12842
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12843
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12844
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12845
- ] }) })
12846
- ]
12847
- }
12848
- );
12849
- };
12850
- const columnHelper = createDataTableColumnHelper();
12851
- const useColumns = () => {
12852
- return useMemo(() => {
12853
- return [
12854
- columnHelper.select(),
12855
- columnHelper.accessor("product.title", {
12856
- header: "Product",
12857
- cell: ({ row }) => {
12858
- var _a, _b, _c;
12859
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
12860
- /* @__PURE__ */ jsx(
12861
- Thumbnail,
12862
- {
12863
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12864
- alt: (_b = row.original.product) == null ? void 0 : _b.title
12865
- }
12866
- ),
12867
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12868
- ] });
12869
- },
12870
- enableSorting: true
12871
- }),
12872
- columnHelper.accessor("title", {
12873
- header: "Variant",
12874
- enableSorting: true
12875
- }),
12876
- columnHelper.accessor("sku", {
12877
- header: "SKU",
12878
- cell: ({ getValue }) => {
12879
- return getValue() ?? "-";
12880
- },
12881
- enableSorting: true
12882
- }),
12883
- columnHelper.accessor("updated_at", {
12884
- header: "Updated",
12885
- cell: ({ getValue }) => {
12886
- return /* @__PURE__ */ jsx(
12887
- Tooltip,
12916
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12917
+ "path",
12918
+ {
12919
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12920
+ stroke: "#A1A1AA",
12921
+ strokeWidth: "1.5",
12922
+ strokeLinecap: "round",
12923
+ strokeLinejoin: "round"
12924
+ }
12925
+ ) }),
12926
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12927
+ "path",
12928
+ {
12929
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12930
+ stroke: "#A1A1AA",
12931
+ strokeWidth: "1.5",
12932
+ strokeLinecap: "round",
12933
+ strokeLinejoin: "round"
12934
+ }
12935
+ ) }),
12936
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12937
+ "path",
12938
+ {
12939
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12940
+ stroke: "#A1A1AA",
12941
+ strokeWidth: "1.5",
12942
+ strokeLinecap: "round",
12943
+ strokeLinejoin: "round"
12944
+ }
12945
+ ) }),
12946
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12947
+ "path",
12948
+ {
12949
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12950
+ stroke: "#A1A1AA",
12951
+ strokeWidth: "1.5",
12952
+ strokeLinecap: "round",
12953
+ strokeLinejoin: "round"
12954
+ }
12955
+ ) }),
12956
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12957
+ "path",
12958
+ {
12959
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12960
+ stroke: "#A1A1AA",
12961
+ strokeWidth: "1.5",
12962
+ strokeLinecap: "round",
12963
+ strokeLinejoin: "round"
12964
+ }
12965
+ ) }),
12966
+ /* @__PURE__ */ jsxs("defs", { children: [
12967
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12968
+ "rect",
12888
12969
  {
12889
- content: getFullDate({ date: getValue(), includeTime: true }),
12890
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
12970
+ width: "12",
12971
+ height: "12",
12972
+ fill: "white",
12973
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12891
12974
  }
12892
- );
12893
- },
12894
- enableSorting: true,
12895
- sortAscLabel: "Oldest first",
12896
- sortDescLabel: "Newest first"
12897
- }),
12898
- columnHelper.accessor("created_at", {
12899
- header: "Created",
12900
- cell: ({ getValue }) => {
12901
- return /* @__PURE__ */ jsx(
12902
- Tooltip,
12975
+ ) }),
12976
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12977
+ "rect",
12903
12978
  {
12904
- content: getFullDate({ date: getValue(), includeTime: true }),
12905
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
12979
+ width: "12",
12980
+ height: "12",
12981
+ fill: "white",
12982
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12906
12983
  }
12907
- );
12908
- },
12909
- enableSorting: true,
12910
- sortAscLabel: "Oldest first",
12911
- sortDescLabel: "Newest first"
12912
- })
12913
- ];
12914
- }, []);
12915
- };
12916
- const CustomItemForm = ({ orderId, currencyCode }) => {
12917
- const { setIsOpen } = useStackedModal();
12918
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12919
- const form = useForm({
12920
- defaultValues: {
12921
- title: "",
12922
- quantity: 1,
12923
- unit_price: ""
12924
- },
12925
- resolver: zodResolver(customItemSchema)
12926
- });
12927
- const onSubmit = form.handleSubmit(async (data) => {
12928
- await addItems(
12929
- {
12930
- items: [
12931
- {
12932
- title: data.title,
12933
- quantity: data.quantity,
12934
- unit_price: convertNumber(data.unit_price)
12935
- }
12936
- ]
12937
- },
12938
- {
12939
- onSuccess: () => {
12940
- setIsOpen(STACKED_MODAL_ID, false);
12941
- },
12942
- onError: (e) => {
12943
- toast.error(e.message);
12944
- }
12945
- }
12946
- );
12947
- });
12948
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
12949
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12950
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
12951
- /* @__PURE__ */ jsxs("div", { children: [
12952
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
12953
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
12954
- ] }),
12955
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12956
- /* @__PURE__ */ jsx(
12957
- Form$2.Field,
12958
- {
12959
- control: form.control,
12960
- name: "title",
12961
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12962
- /* @__PURE__ */ jsxs("div", { children: [
12963
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
12964
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
12965
- ] }),
12966
- /* @__PURE__ */ jsxs("div", { children: [
12967
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12968
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12969
- ] })
12970
- ] }) })
12971
- }
12972
- ),
12973
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12974
- /* @__PURE__ */ jsx(
12975
- Form$2.Field,
12976
- {
12977
- control: form.control,
12978
- name: "unit_price",
12979
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12980
- /* @__PURE__ */ jsxs("div", { children: [
12981
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
12982
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12983
- ] }),
12984
- /* @__PURE__ */ jsxs("div", { children: [
12985
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12986
- CurrencyInput,
12987
- {
12988
- symbol: getNativeSymbol(currencyCode),
12989
- code: currencyCode,
12990
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12991
- ...field
12992
- }
12993
- ) }),
12994
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12995
- ] })
12996
- ] }) })
12997
- }
12998
- ),
12999
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
13000
- /* @__PURE__ */ jsx(
13001
- Form$2.Field,
13002
- {
13003
- control: form.control,
13004
- name: "quantity",
13005
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13006
- /* @__PURE__ */ jsxs("div", { children: [
13007
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
13008
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
13009
- ] }),
13010
- /* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
13011
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
13012
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13013
- ] })
13014
- ] }) })
13015
- }
13016
- )
13017
- ] }) }) }),
13018
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
13019
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13020
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
13021
- ] }) })
13022
- ] }) }) });
12984
+ ) }),
12985
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12986
+ "rect",
12987
+ {
12988
+ width: "12",
12989
+ height: "12",
12990
+ fill: "white",
12991
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12992
+ }
12993
+ ) }),
12994
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12995
+ "rect",
12996
+ {
12997
+ width: "12",
12998
+ height: "12",
12999
+ fill: "white",
13000
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13001
+ }
13002
+ ) }),
13003
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13004
+ "rect",
13005
+ {
13006
+ width: "12",
13007
+ height: "12",
13008
+ fill: "white",
13009
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13010
+ }
13011
+ ) }),
13012
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13013
+ "rect",
13014
+ {
13015
+ width: "12",
13016
+ height: "12",
13017
+ fill: "white",
13018
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13019
+ }
13020
+ ) })
13021
+ ] })
13022
+ ]
13023
+ }
13024
+ );
13023
13025
  };
13024
- const customItemSchema = objectType({
13025
- title: stringType().min(1),
13026
- quantity: numberType(),
13027
- unit_price: unionType([numberType(), stringType()])
13026
+ const schema = objectType({
13027
+ customer_id: stringType().min(1)
13028
13028
  });
13029
13029
  const widgetModule = { widgets: [] };
13030
13030
  const routeModule = {
@@ -13047,16 +13047,16 @@ const routeModule = {
13047
13047
  loader,
13048
13048
  children: [
13049
13049
  {
13050
- Component: BillingAddress,
13051
- path: "/draft-orders/:id/billing-address"
13050
+ Component: Email,
13051
+ path: "/draft-orders/:id/email"
13052
13052
  },
13053
13053
  {
13054
13054
  Component: CustomItems,
13055
13055
  path: "/draft-orders/:id/custom-items"
13056
13056
  },
13057
13057
  {
13058
- Component: Email,
13059
- path: "/draft-orders/:id/email"
13058
+ Component: BillingAddress,
13059
+ path: "/draft-orders/:id/billing-address"
13060
13060
  },
13061
13061
  {
13062
13062
  Component: Metadata,
@@ -13071,20 +13071,20 @@ const routeModule = {
13071
13071
  path: "/draft-orders/:id/sales-channel"
13072
13072
  },
13073
13073
  {
13074
- Component: Shipping,
13075
- path: "/draft-orders/:id/shipping"
13074
+ Component: Items,
13075
+ path: "/draft-orders/:id/items"
13076
13076
  },
13077
13077
  {
13078
- Component: TransferOwnership,
13079
- path: "/draft-orders/:id/transfer-ownership"
13078
+ Component: Shipping,
13079
+ path: "/draft-orders/:id/shipping"
13080
13080
  },
13081
13081
  {
13082
13082
  Component: ShippingAddress,
13083
13083
  path: "/draft-orders/:id/shipping-address"
13084
13084
  },
13085
13085
  {
13086
- Component: Items,
13087
- path: "/draft-orders/:id/items"
13086
+ Component: TransferOwnership,
13087
+ path: "/draft-orders/:id/transfer-ownership"
13088
13088
  }
13089
13089
  ]
13090
13090
  }