import { useContext, useEffect, useState } from "react" import { Controller, useWatch } from "react-hook-form" import { useTranslation } from "react-i18next" import Spinner from "../../../../components/atoms/spinner" import Button from "../../../../components/fundamentals/button" import AlertIcon from "../../../../components/fundamentals/icons/alert-icon" import TrashIcon from "../../../../components/fundamentals/icons/trash-icon" import { SteppedContext } from "../../../../components/molecules/modal/stepped-modal" import Select from "../../../../components/molecules/select" import CurrencyInput from "../../../../components/organisms/currency-input" import { extractOptionPrice } from "../../../../utils/prices" import { useNewOrderForm } from "../form" const SelectShippingMethod = () => { const { t } = useTranslation() const { disableNextPage, enableNextPage } = useContext(SteppedContext) const [showCustomPrice, setShowCustomPrice] = useState(false) const { context: { region, shippingOptions }, form: { control, setValue }, } = useNewOrderForm() const currentCustomPrice = useWatch({ control, name: "custom_shipping_price", }) useEffect(() => { if (!showCustomPrice && currentCustomPrice) { setShowCustomPrice(true) } }, [currentCustomPrice]) const selectedShippingOption = useWatch({ control, name: "shipping_option", }) const removeCustomPrice = () => { setShowCustomPrice(false) setValue("custom_shipping_price", undefined) } useEffect(() => { if (!selectedShippingOption) { disableNextPage() } if (selectedShippingOption) { enableNextPage() } }, [selectedShippingOption]) return (