import { Controller } from "react-hook-form" import { useTranslation } from "react-i18next" import { Option } from "../../types/shared" import FormValidator from "../../utils/form-validator" import { nestedForm, NestedForm } from "../../utils/nested-form" import MetadataForm, { MetadataFormType } from "../forms/general/metadata-form" import Input from "../molecules/input" import { NextSelect } from "../molecules/select/next-select" export type AddressPayload = { first_name: string last_name: string company: string | null address_1: string address_2: string | null city: string province: string | null country_code: Option postal_code: string phone: string | null metadata: MetadataFormType } export enum AddressType { SHIPPING = "shipping", BILLING = "billing", LOCATION = "location", } type AddressFormProps = { form: NestedForm countryOptions: Option[] type: AddressType required?: boolean noTitle?: boolean } const AddressForm = ({ form, countryOptions, type, required = true, noTitle = false, }: AddressFormProps) => { const { register, path, control, formState: { errors }, } = form const { t } = useTranslation() return (
{(type === AddressType.SHIPPING || type === AddressType.BILLING) && ( <> {t("templates-general", "General")}
)} {!noTitle && ( {`${ type === AddressType.BILLING ? t("templates-billing-address", "Billing Address") : type === AddressType.SHIPPING ? t("templates-shipping-address", "Shipping Address") : t("templates-address", "Address") }`} )}
{ return ( ) }} />
{t("templates-metadata", "Metadata")}
) } export default AddressForm