import { Form } from "react-router-dom"; import countryList from "react-select-country-list"; import FieldProperties from "./fields/field_properties"; import Field from "./fields/field"; import SelectField from "./fields/select_field"; import { useEffect } from "react"; import { setFieldErrorMessages } from "../../lib/form_utils"; function getFieldProperties(address?: any) { const fields: Array = [ { id: "street-field", type: "text", name: "street", label: "Calle", placeholder: address?.street }, { id: "number-field", type: "number", name: "number", label: "Número", placeholder: address?.number }, { id: "zip-code-field", type: "number", name: "zip_code", label: "Código postal", placeholder: address?.zip_code }, { id: "city-field", type: "text", name: "city", label: "Ciudad", placeholder: address?.city } ]; return fields; } function getCountrySelectOptions(address: any, country_code: string) { if(address && country_code == address.country) return (); else return (); } export default function AddressForm({ address = null, errors = null }) { let field_properties = getFieldProperties(address); const select_field_properties: FieldProperties = { id: "country-field", type: "select", name: "country", label: "Ciudad" } if(errors) field_properties = setFieldErrorMessages(field_properties, errors); const options = countryList().getValues().map(country_code => getCountrySelectOptions(address, country_code) ); const fields = field_properties.map(field_property => ); return(
{fields} ); }