import clsx from "clsx" import { useWatch } from "react-hook-form" import { useTranslation } from "react-i18next" import CheckIcon from "../../../../components/fundamentals/icons/check-icon" import AddressForm, { AddressType, } from "../../../../components/templates/address-form" import isNullishObject from "../../../../utils/is-nullish-object" import { nestedForm } from "../../../../utils/nested-form" import { useNewOrderForm } from "../form" const Billing = () => { const { t } = useTranslation() const { context: { validCountries }, form, } = useNewOrderForm() const shippingAddress = useWatch({ control: form.control, name: "shipping_address", }) const shippingAddressId = useWatch({ control: form.control, name: "shipping_address_id", }) const sameAsShipping = useWatch({ control: form.control, name: "same_as_shipping", }) const updateSameAsShipping = () => { if (!sameAsShipping) { form.setValue("billing_address", shippingAddress) form.setValue("billing_address_id", shippingAddressId) } else { form.resetField("billing_address") form.resetField("billing_address_id") } form.setValue("same_as_shipping", !sameAsShipping) } return (
{t("components-billing-address", "Billing Address")} {!isNullishObject(shippingAddress) || shippingAddressId ? (
{sameAsShipping && }
{t("components-use-same-as-shipping", "Use same as shipping")}
) : null}
) } export default Billing