diff --git a/.env b/.env new file mode 100644 index 0000000..c3b2839 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VITE_API_URL = http://localhost:3000/clientes \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index af1fa84..bf53bcf 100644 --- a/.prettierrc +++ b/.prettierrc @@ -4,5 +4,6 @@ "arrowParens": "avoid", "jsxSingleQuote": true, "jsxIgnoreLineBreak": true, - "singleAttributePerLine": true + "singleAttributePerLine": true, + "bracketSpacing": true } \ No newline at end of file diff --git a/db.json b/db.json new file mode 100644 index 0000000..fb60a04 --- /dev/null +++ b/db.json @@ -0,0 +1,39 @@ +{ + "clientes": [ + { + "id": 1, + "nombre": "Juan", + "telefono": 102013313, + "email": "juan@juan.com", + "empresa": "Codigo Con Juan" + }, + { + "id": 2, + "nombre": "Karen", + "telefono": 138198313, + "email": "karen@juan.com", + "empresa": "Codigo Con Juan" + }, + { + "id": 3, + "nombre": "Josue", + "telefono": 31983913, + "email": "josue@juan.com", + "empresa": "Codigo Con Juan" + }, + { + "id": 4, + "nombre": "Miguel", + "telefono": 6193978127, + "email": "miguel@juan.com", + "empresa": "Codigo Con Juan" + }, + { + "id": 5, + "nombre": "Pedro", + "telefono": 1398198938, + "email": "pedro@juan.com", + "empresa": "Codigo Con Juan" + } + ] +} \ No newline at end of file diff --git a/index.html b/index.html index 79c4701..e81ae12 100644 --- a/index.html +++ b/index.html @@ -4,9 +4,9 @@ -
{nombre}
+{empresa}
++ {' '} + Email: + {email} + Tel: + {telefono} +
+Administra Tus Clientes
+ {clients.length ? ( +Clients | +Contact | +Actions | +
---|
No Hay Clientes Aun
+ )} + > + ) +} + +export default Index diff --git a/src/pages/NewClient.jsx b/src/pages/NewClient.jsx new file mode 100644 index 0000000..26269da --- /dev/null +++ b/src/pages/NewClient.jsx @@ -0,0 +1,71 @@ +import { useNavigate, Form, useActionData } from 'react-router-dom' +import Formulario from '../components/Formulario' +import Error from '../components/Error' + +export async function action({ request }) { + const formData = await request.formData() + const datos = Object.fromEntries(formData) + const email = datos.email + console.log(email) + // Validacion de Datos + const errores = [] + if (Object.values(datos).includes('')) { + errores.push('Todos los campos son obligatorios') + } + + let regex = new RegExp( + "([!#-'*+/-9=?A-Z^-~-]+(.[!#-'*+/-9=?A-Z^-~-]+)*|\"([]!#-[^-~ \t]|(\\[\t -~]))+\")@([!#-'*+/-9=?A-Z^-~-]+(.[!#-'*+/-9=?A-Z^-~-]+)*|[[\t -Z^-~]*])" + ) + + if (!regex.test(email)) { + errores.push('Email no es válido') + } + + //return datos si hay errores + if (Object.keys(errores).length) { + console.log('si hay errores') + return errores + } +} + +function NewClient() { + const navigate = useNavigate() + const errores = useActionData() + + console.log(errores) + return ( + <> ++ Llena todos los campos para registrar un nuevo cliente +
+ +