agregar funcion actualizar
This commit is contained in:
parent
81cb378a1a
commit
f8909acc54
|
@ -227,19 +227,19 @@ const AdministradoresComunidad = () => {
|
||||||
|
|
||||||
const saveAdminCommunity = () => {
|
const saveAdminCommunity = () => {
|
||||||
let _administrators = [...listaAdmins];
|
let _administrators = [...listaAdmins];
|
||||||
|
let _admin = { ...adminCommunity };
|
||||||
|
_admin.community_id = communityId;
|
||||||
|
|
||||||
if (adminCommunity._id) {
|
if (adminCommunity._id === null) {
|
||||||
if (adminCommunity.name && adminCommunity.dni &&
|
if (adminCommunity.name && adminCommunity.dni &&
|
||||||
adminCommunity.last_name && adminCommunity.email &&
|
adminCommunity.last_name && adminCommunity.email &&
|
||||||
adminCommunity.phone) {
|
adminCommunity.phone) {
|
||||||
|
|
||||||
let _adminCommunity = { ...adminCommunity };
|
|
||||||
_adminCommunity.community_id = communityId;
|
|
||||||
|
|
||||||
fetch('http://localhost:4000/user/createAdminCommunity', {
|
fetch('http://localhost:4000/user/createAdminCommunity', {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(_adminCommunity),
|
body: JSON.stringify(_admin),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ const AdministradoresComunidad = () => {
|
||||||
|
|
||||||
// _adminCommunity.community_id = communitiesList.find(c => c._id === _adminCommunity.community_id).name
|
// _adminCommunity.community_id = communitiesList.find(c => c._id === _adminCommunity.community_id).name
|
||||||
|
|
||||||
_administrators.push(_adminCommunity);
|
_administrators.push(_admin);
|
||||||
toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Administrador de Comunidad de vivienda Creada', life: 3000 });
|
toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Administrador de Comunidad de vivienda Creada', life: 3000 });
|
||||||
|
|
||||||
setListaAdmins(_administrators);
|
setListaAdmins(_administrators);
|
||||||
|
@ -273,8 +273,10 @@ const AdministradoresComunidad = () => {
|
||||||
setSubmitted(true);
|
setSubmitted(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let _admin = { ...adminCommunity };
|
|
||||||
console.log(`Actualizando admnistrador de comunidad: ${_admin}`)
|
console.log(`Actualizando admnistrador de comunidad: ${_admin}`)
|
||||||
|
_admin.community_id = communityId;
|
||||||
|
console.log(`Actualizando admnistrador de comunidad: ${_admin}`)
|
||||||
|
|
||||||
fetch(`http://localhost:4000/user/updateAdminCommunity/${_admin._id}`, {
|
fetch(`http://localhost:4000/user/updateAdminCommunity/${_admin._id}`, {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
@ -290,7 +292,7 @@ const AdministradoresComunidad = () => {
|
||||||
toast.current.show({
|
toast.current.show({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
summary: 'Éxito',
|
summary: 'Éxito',
|
||||||
detail: 'Inquilino editado',
|
detail: 'Administrador de comunidad actualizado',
|
||||||
life: 3000,
|
life: 3000,
|
||||||
})
|
})
|
||||||
_administrators.push(_admin);
|
_administrators.push(_admin);
|
||||||
|
@ -334,11 +336,12 @@ const AdministradoresComunidad = () => {
|
||||||
setAdminCommunity(admin);
|
setAdminCommunity(admin);
|
||||||
console.log(admin);
|
console.log(admin);
|
||||||
setSaveButtonTitle('Actualizar');
|
setSaveButtonTitle('Actualizar');
|
||||||
|
setCommunityId(admin.community_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const cancelEdit = () => {
|
const cancelEdit = () => {
|
||||||
setAdminCommunity(adminCommunity);
|
setAdminCommunity(emptyAdminCommunity);
|
||||||
setSaveButtonTitle('Registrar');
|
setSaveButtonTitle('Registrar');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue