Merge pull request #118 from DeimosPr4/UH-registroComunidadVivienda

fix visualización "sin administrador" en tabla
This commit is contained in:
Eduardo Quiros 2022-07-22 01:11:20 -06:00 committed by GitHub
commit 1c4f93b60f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 63 additions and 59 deletions

View File

@ -33,7 +33,7 @@ const Communities = () => {
const [cantonId, setCantonId] = useState(null);
const [districtsList, setDistrictsList] = useState([]);
const [districtId, setDistrictId] = useState(null);
const [codeHouses, setCodeHouses] = useState(null);
const [codeHouses, setCodeHouses] = useState('');
const [submitted, setSubmitted] = useState(false);
const toast = useRef(null);
const dt = useRef(null);
@ -142,21 +142,21 @@ const Communities = () => {
item.province = pList.find(p => p.code === item.province).name
item.canton = cList.find(p => p.code === item.canton).name
item.district = dList.find(p => p.code === item.district).name
if (!item.id_admin) {
item.name_admin = "Sin Administrador"
}
})
setCommunitiesList(await resJson.message);
}
useEffect(() => {
getCommunites();
}, [])
const saveCommunity = () => {
setSubmitted(true);
if (community.name.trim()) {
if (community.name && community.num_houses > 0 && provinciaId && cantonId && districtId && community.phone ) {
let _communities = [...communitiesList];
let _community = { ...community };
_community.province = provinciaId;
@ -205,12 +205,16 @@ const Communities = () => {
setCodeHouses('');
setCommunity(emptyCommunity);
})
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
} else {
setSubmitted(true);
}
}
@ -230,13 +234,13 @@ const Communities = () => {
<h5>Comunidades de Viviendas</h5>
<DataTable value={communitiesList} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="province" header="Provincia" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="canton" header="Cantón" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="district" header="Distrito" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
<Column field="num_houses" header="Número de viviendas" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
<Column field="name_admin" header="Administrador" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
<Column field="name" header="🏘️ Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="province" header="📍 Provincia" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="canton" header="📍 Cantón" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="district" header="📍 Distrito" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="phone" header="☎️ Telefóno" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
<Column field="num_houses" header="#️⃣ Número de viviendas" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
<Column field="name_admin" header="👩🏻‍💼👨🏻‍💼 Administrador" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
</DataTable>
</div>
</div>
@ -253,7 +257,7 @@ const Communities = () => {
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
<i className="pi pi-home"></i>
</span>
<InputText id="name" value={community.name} onChange={(e) => onInputChange(e, 'name')} required autoFocus className={classNames( submitted && community.name==='' ? 'p-invalid' : '' )} />
<InputText id="name" value={community.name} onChange={(e) => onInputChange(e, 'name')} required autoFocus className={classNames({'p-invalid' : submitted && community.name === ''})} />
</div>
{submitted && community.name === '' && <small className="p-invalid">Nombre es requirido.</small>}
</div>
@ -325,9 +329,9 @@ const Communities = () => {
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
<i className="pi pi-hashtag"></i>
</span>
<InputText id="code_houses" value={codeHouses} onChange={handleCodeHouses} required autoFocus className={classNames({ 'p-invalid': submitted && !codeHouses } )} />
<InputText id="code_houses" value={codeHouses} onChange={handleCodeHouses} autoFocus className={classNames({ 'p-invalid': submitted && codeHouses === '' })} />
</div>
{submitted && !codeHouses && <small className="p-invalid">El código para las viviendas es requirido.</small>}
{submitted && codeHouses === '' && <small className="p-invalid">El código para las viviendas es requirido.</small>}
</div>
</div>
<div className="col-12 md:col-12 py-2">