From cf0b5c2d27bff98dd38514bca61ad14b8b110043 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 25 Jul 2022 16:08:00 -0600 Subject: [PATCH] add validaciones en blanco en inputs --- .../components/AdministradoresComunidad.js | 153 +++++++++++++----- 1 file changed, 114 insertions(+), 39 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index 84120372..7a203a1e 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -14,22 +14,10 @@ import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; import { faHomeAlt } from '@fortawesome/free-solid-svg-icons'; import { Dropdown } from 'primereact/dropdown'; - +import classNames from 'classnames'; const AdministradoresComunidad = () => { - const [listaAdmins, setListaAdmins] = useState([]); - const [listaAdminComunidad, setListaAdminComunidad] = useState([]); - const [adminCommunity, setAdminCommunity] = useState(emptyAdminCommunity); - const [selectedAdminsCommunities, setSelectedAdminsCommunities] = useState(null); - const [globalFilter, setGlobalFilter] = useState(null); - const [deleteAdminCommunityDialog, setDeleteAdminCommunityDialog] = useState(false); - const [deleteAdminsCommunitiesDialog, setDeleteAdminsCommunitiesDialog] = useState(false); - const toast = useRef(null); - const dt = useRef(null); - const [communitiesList, setCommunitiesList] = useState([]); - const [communityId, setCommunityId] = useState([]); - let emptyAdminCommunity = { _id: null, @@ -39,24 +27,27 @@ const AdministradoresComunidad = () => { email: '', phone: '', password: '', + confirmPassword: '', community_id: '', community_name: '', user_type: '2', status: '1' }; - async function getCommunites() { - let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' }); - let resList = await response.json(); - let list = await resList.message; - console.log(list); + const [listaAdmins, setListaAdmins] = useState([]); + const [listaAdminComunidad, setListaAdminComunidad] = useState([]); + const [adminCommunity, setAdminCommunity] = useState(emptyAdminCommunity); + const [selectedAdminsCommunities, setSelectedAdminsCommunities] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteAdminCommunityDialog, setDeleteAdminCommunityDialog] = useState(false); + const [deleteAdminsCommunitiesDialog, setDeleteAdminsCommunitiesDialog] = useState(false); + const [communitiesList, setCommunitiesList] = useState([]); + const [communityId, setCommunityId] = useState(null); + const [submitted, setSubmitted] = useState(false); + const toast = useRef(null); + const dt = useRef(null); - setCommunitiesList(await list); - } - useEffect(() => { - getCommunites(); - }, []) async function listaAdmin() { @@ -83,11 +74,25 @@ const AdministradoresComunidad = () => { }, []) + + async function getCommunites() { + let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' }); + let resList = await response.json(); + let list = await resList.message; + console.log(list); + + setCommunitiesList(await list); + } + + useEffect(() => { + getCommunites(); + }, []) + const cList = communitiesList.map((item) => ({ label: item.name, value: item.id, })) - + const deleteAdminCommunity = () => { /* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { @@ -147,8 +152,16 @@ const AdministradoresComunidad = () => { } - const saveCommunityAdmin = () => { + const saveAdminCommunity = () => { + if (adminCommunity.password !== adminCommunity.confirmPassword) { + setSubmitted(true); + } else if (adminCommunity.name && adminCommunity.dni && adminCommunity.last_name && adminCommunity.email && adminCommunity.password && adminCommunity.phone) { + toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Administrador de Comunidad de vivienda Creada', life: 3000 }); + } else { + setSubmitted(true); + + } } const hideDeleteAdminCommunityDialog = () => { @@ -264,6 +277,18 @@ const AdministradoresComunidad = () => { ) + const onInputChange = (e, name) => { + const val = (e.target && e.target.value) || ''; + let _adminCommunity = { ...adminCommunity }; + _adminCommunity[`${name}`] = val; + + setAdminCommunity(_adminCommunity); + } + + const handleCommunities = (event) => { + const getCommunity = event.target.value; + setCommunityId(getCommunity); + } return (
@@ -305,30 +330,80 @@ const AdministradoresComunidad = () => {
Registro de un administrador de una comunidad de viviendas
- - + +
+
+ + + + onInputChange(e, 'name')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.name === '' })} /> +
+ {submitted && adminCommunity.name === '' && Nombre es requirido.} +
- - + +
+
+ + + + onInputChange(e, 'last_name')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.last_name === '' })} /> +
+ {submitted && adminCommunity.last_name === '' && Apellidos es requirido.} +
- - + +
+
+ + + + onInputChange(e, 'email')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.email === '' })} /> +
+ {submitted && adminCommunity.email === '' && Correo electrónico + es requirido.} +
- - + +
+
+ + + + onInputChange(e, 'dni')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.dni === '' })} /> +
+ {submitted && adminCommunity.email === '' && Identificación es requirida.} +
-
- - +
+ +
+
+ + + + onInputChange(e, 'phone')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.phone === '' })} /> +
+ {submitted && adminCommunity.phone === '' && Número de teléfono es requirida.} +
-
+
- +
+
+ + + + +
+ {submitted && !communityId && Comunidad es requirida.} +
-