From 44a016256717b871ada858d5dc064d9d0e06425e Mon Sep 17 00:00:00 2001
From: HombreLaser <sebastian-440@live.com>
Date: Thu, 18 May 2023 22:04:52 -0600
Subject: Añade creación de direcciones
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/components/forms/address_form.tsx | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

(limited to 'src/components/forms/address_form.tsx')

diff --git a/src/components/forms/address_form.tsx b/src/components/forms/address_form.tsx
index 11b0191..53822bb 100644
--- a/src/components/forms/address_form.tsx
+++ b/src/components/forms/address_form.tsx
@@ -1,72 +1,72 @@
 import { Form } from "react-router-dom";
-import { formHasErrors } from "../../lib/form_utils";
 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) {
+function getFieldProperties(address?: any) {
   const fields: Array<FieldProperties> = [
     {
       id: "street-field",
       type: "text",
       name: "street",
       label: "Calle",
-      placeholder: address.street
+      placeholder: address?.street
     },
     {
       id: "number-field",
       type: "number",
       name: "number",
       label: "Número",
-      placeholder: address.number
+      placeholder: address?.number
     },
     {
       id: "zip-code-field",
       type: "number",
       name: "zip_code",
       label: "Código postal",
-      placeholder: address.zip_code
+      placeholder: address?.zip_code
     },
     {
       id: "city-field",
       type: "text",
       name: "city",
       label: "Ciudad",
-      placeholder: address.city
+      placeholder: address?.city
     }
   ];
 
-  for(const field of fields) {
-    if(sessionStorage.getItem(field.name)) {
-      field.error_message = sessionStorage.getItem(field.name);
-    }
-  }
-
   return fields;
 }
 
 function getCountrySelectOptions(address: any, country_code: string) {
-  if(country_code == address.country)
+  if(address && country_code == address.country)
     return (<option key={ country_code } value={ country_code } selected>{ countryList().getLabel(country_code) }</option>);
   else
     return (<option key={ country_code } value={ country_code }>{ countryList().getLabel(country_code) }</option>);
 }
 
-export default function AddressForm({ address }) {
+
+export default function AddressForm({ address = null, errors = null }) {
+  let field_properties = getFieldProperties(address);
   const select_field_properties: FieldProperties = {
     id: "country-field",
     type: "select",
-    name: "city",
+    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 = getFieldProperties(address).map(field_properties =>
-    <Field properties={field_properties}/>
+  const fields = field_properties.map(field_property =>
+    <Field properties={field_property}/>
   );
 
   return(
-- 
cgit v1.2.3

