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 (