fix repetidos entre usuarios de comunidad

This commit is contained in:
Mariela 2022-08-22 23:10:43 -06:00
parent d2c2b8739c
commit 8e63bcae3c
2 changed files with 24 additions and 33 deletions

View File

@ -228,20 +228,20 @@ const AdministradoresComunidad = () => {
const findIndexById = (id) => { const findIndexById = (id) => {
let index = -1; let index = -1;
for (let i = 0; i < listaAdmins.length; i++) { for (let i = 0; i < listaAdmins.length; i++) {
if (listaAdmins[i]._id === id) { if (listaAdmins[i]._id === id) {
index = i; index = i;
break; break;
} }
} }
return index; return index;
} }
const findRepeated = (name, value) => { const findRepeated = (name, value) => {
let _administrators = [...listaAdmins]; let _administrators = [...listaAdmins];
let value_filtered = _administrators.filter(item => item[`${name}`] === value); let value_filtered = _administrators.filter(item => item[`${name}`] === value);
return value_filtered.length return value_filtered.length
} }
const saveAdminCommunity = () => { const saveAdminCommunity = () => {
let _administrators = [...listaAdmins]; let _administrators = [...listaAdmins];
@ -647,10 +647,16 @@ const AdministradoresComunidad = () => {
<span className="p-inputgroup-addon p-button p-icon-input-khaki"> <span className="p-inputgroup-addon p-button p-icon-input-khaki">
<i className="pi pi-at"></i> <i className="pi pi-at"></i>
</span> </span>
<InputText id="email" value={adminCommunity.email} onChange={(e) => onInputChange(e, 'email')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.email === '' })} /> <InputText id="email" value={adminCommunity.email}
onChange={(e) => onInputChange(e, 'email')} required autoFocus
className={classNames({ 'p-invalid': submitted &&
(adminCommunity.email === '' || findRepeated('email', adminCommunity.email) > 0) })} />
</div> </div>
{submitted && adminCommunity.email === '' && <small className="p-invalid">Correo electrónico {submitted && adminCommunity.email === '' && <small className="p-invalid">Correo electrónico
es requirido.</small>} es requirido.</small>}
{submitted && findRepeated('email', adminCommunity.email) > 0 &&
<small className="p-invalid">Correo electrónico se encuentra repetido.</small>
}
</div> </div>
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
@ -660,9 +666,15 @@ const AdministradoresComunidad = () => {
<span className="p-inputgroup-addon p-button p-icon-input-khaki"> <span className="p-inputgroup-addon p-button p-icon-input-khaki">
<i className="pi pi-id-card"></i> <i className="pi pi-id-card"></i>
</span> </span>
<InputText id="dni" value={adminCommunity.dni} onChange={(e) => onInputChange(e, 'dni')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.dni === '' })} /> <InputText id="dni" value={adminCommunity.dni}
onChange={(e) => onInputChange(e, 'dni')} required autoFocus
className={classNames({ 'p-invalid': submitted
&& (adminCommunity.dni === '' || findRepeated('dni', adminCommunity.dni) > 0)})} />
</div> </div>
{submitted && adminCommunity.email === '' && <small className="p-invalid">Identificación es requirida.</small>} {submitted && adminCommunity.dni === '' && <small className="p-invalid">Identificación es requirida.</small>}
{submitted && findRepeated('dni', adminCommunity.dni) > 0 &&
<small className="p-invalid">Identificación se encuentra repetida.</small>
}
</div> </div>
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">

View File

@ -107,9 +107,6 @@ const AdministradoresSistema = () => {
} else { } else {
if (_admin._id) { if (_admin._id) {
fetch('http://localhost:4000/user/updateAdminSystem/', { fetch('http://localhost:4000/user/updateAdminSystem/', {
cache: 'no-cache', cache: 'no-cache',
method: 'POST', method: 'POST',
@ -145,15 +142,7 @@ const AdministradoresSistema = () => {
.catch( .catch(
err => console.log('Ocurrió un error con el fetch', err) err => console.log('Ocurrió un error con el fetch', err)
); );
} else { } else {
fetch('http://localhost:4000/user/createAdminSystem/', { fetch('http://localhost:4000/user/createAdminSystem/', {
cache: 'no-cache', cache: 'no-cache',
method: 'POST', method: 'POST',
@ -181,15 +170,8 @@ const AdministradoresSistema = () => {
); );
} }
} }
} else { } else {
setSubmitted(true); setSubmitted(true);
} }
} }
@ -268,16 +250,13 @@ const AdministradoresSistema = () => {
setSubmitted(false); setSubmitted(false);
setAdminDialog(false); setAdminDialog(false);
setSysAdmin(emptySysAdmin); setSysAdmin(emptySysAdmin);
}; };
const infoAdmin = (sysadmin) => { const infoAdmin = (sysadmin) => {
setSysAdmin({ ...sysadmin }); setSysAdmin({ ...sysadmin });
setAdminDialog(true); setAdminDialog(true);
}; };
const cancelEdit = () => { const cancelEdit = () => {
setSaveButtonTitle('Registrar'); setSaveButtonTitle('Registrar');
setSubmitted(false); setSubmitted(false);