add button

This commit is contained in:
Eduardo Quiros 2022-09-01 10:01:10 -06:00
parent f6ab828ed4
commit 22dff4fe07
No known key found for this signature in database
GPG Key ID: B77F36C3F12720B4
1 changed files with 25 additions and 8 deletions

View File

@ -41,6 +41,7 @@ const Communities = () => {
const [districtId, setDistrictId] = useState(null); const [districtId, setDistrictId] = useState(null);
const [codeHouses, setCodeHouses] = useState(''); const [codeHouses, setCodeHouses] = useState('');
const [submitted, setSubmitted] = useState(false); const [submitted, setSubmitted] = useState(false);
const [saveButtonLabel, setSaveButtonLabel] = useState('Registrar')
const [selectedCommunities, setSelectedCommunities] = useState(null); const [selectedCommunities, setSelectedCommunities] = useState(null);
const [globalFilter, setGlobalFilter] = useState(null); const [globalFilter, setGlobalFilter] = useState(null);
const [deleteCommunityDialog, setDeleteCommunityDialog] = useState(false); const [deleteCommunityDialog, setDeleteCommunityDialog] = useState(false);
@ -97,7 +98,7 @@ const Communities = () => {
async function fillCantons() { async function fillCantons() {
const resJson = await getCantons(); const resJson = await getCantons();
const cantones = await resJson.filter(function (i, n) { const cantones = await resJson.filter(function(i, n) {
return i.parentCode === provinciaId; return i.parentCode === provinciaId;
}); });
setCantonsList(await cantones); setCantonsList(await cantones);
@ -112,7 +113,7 @@ const Communities = () => {
async function fillDistricts() { async function fillDistricts() {
const resJson = await getDistricts(); const resJson = await getDistricts();
const districts = await resJson.filter(function (i, n) { const districts = await resJson.filter(function(i, n) {
return i.parentCode === cantonId; return i.parentCode === cantonId;
}); });
setDistrictsList(await districts); setDistrictsList(await districts);
@ -232,7 +233,7 @@ const Communities = () => {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
}) })
.then(function (response) { .then(function(response) {
if (response.status != 201) if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status); console.log('Ocurrió un error con el servicio: ' + response.status);
else return response.json(); else return response.json();
@ -357,7 +358,7 @@ const Communities = () => {
} }
}) })
.then( .then(
function (response) { function(response) {
if (response.status != 201) if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status); console.log('Ocurrió un error con el servicio: ' + response.status);
else else
@ -365,7 +366,7 @@ const Communities = () => {
} }
) )
.then( .then(
function (response) { function(response) {
setEditCommunityDialog(false); setEditCommunityDialog(false);
toast.current.show({ toast.current.show({
severity: 'success', severity: 'success',
@ -389,7 +390,7 @@ const Communities = () => {
} }
}) })
.then( .then(
function (response) { function(response) {
if (response.status != 201) if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status); console.log('Ocurrió un error con el servicio: ' + response.status);
else else
@ -397,7 +398,7 @@ const Communities = () => {
} }
) )
.then( .then(
function (response) { function(response) {
let _community = communitiesList.filter(val => val._id !== community._id); let _community = communitiesList.filter(val => val._id !== community._id);
setCommunitiesList(_community); setCommunitiesList(_community);
@ -454,6 +455,16 @@ const Communities = () => {
}); });
}; };
const updateCommunity = (community) => {
console.log(community);
setCommunity(community);
setSaveButtonLabel('Actualizar');
setHousesList(community.houses);
setProvinciaId(community.provincia);
setCantonId(community.canton);
setDistrictId(community.district);
}
const actionsCommunity = (rowData) => { const actionsCommunity = (rowData) => {
let icono = ''; let icono = '';
@ -465,6 +476,12 @@ const Communities = () => {
return ( return (
<div className="actions"> <div className="actions">
<Button
icon="pi pi-pencil"
className="p-button-rounded p-button-success mt-2 mx-2"
onClick={() => updateCommunity(rowData)}
title="Editar"
/>
<Button <Button
icon="pi pi-exclamation-circle" icon="pi pi-exclamation-circle"
className="p-button-rounded p-button-info mt-2 mx-2" className="p-button-rounded p-button-info mt-2 mx-2"
@ -1169,7 +1186,7 @@ const Communities = () => {
</div> </div>
<div className="col-12 md:col-12 py-2"> <div className="col-12 md:col-12 py-2">
<Button <Button
label="Registrar" label={saveButtonLabel}
icon="pi pi-check" icon="pi pi-check"
onClick={saveCommunity} onClick={saveCommunity}
></Button> ></Button>