diff --git a/src/Admin/Pages/Pages/SubPages/Institutions.js b/src/Admin/Pages/Pages/SubPages/Institutions.js index 6446b62ffb02463011865e84ae0d31aa62371da0..e11933775468fc7d42f7e61d44b6466785d15f50 100644 --- a/src/Admin/Pages/Pages/SubPages/Institutions.js +++ b/src/Admin/Pages/Pages/SubPages/Institutions.js @@ -47,7 +47,7 @@ import TextField from "@material-ui/core/TextField"; // services import { Delete, GetFullList } from "../../../Services"; //Filters -import { BuildFilter } from '../../../Filters'; +import { Url } from '../../../Filters'; const StyledTableCell = withStyles((theme) => ({ head: { @@ -87,11 +87,11 @@ const Institutions = () => { const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data - const [api , setApi] = useState(apiUrl + "/institutions") - // const api = apiUrl + "/institutions"; //Api + const [api, setApi] = useState(apiUrl + "/institutions") const [deleteItem, setDeleteItem] = useState({}); //Delete Item const [isLoadingToDelete, setIsLoadingToDelete] = useState(null); + const [isUpdating, setIsUpdating] = useState(false); const [data, setData] = useState([]); // Data that will be used to display the content of the row in full screen, when its clicked const [editInfo, setEditInfo] = useState({}); //Informations to be displayed in the edit section @@ -121,27 +121,23 @@ const Institutions = () => { const [description, setDescription] = useState(""); const CityHandler = () => { - setShowCityField(!showCityField); - setApi(apiUrl + "/institutions") - UpdtateListData(api) + setShowCityField(!showCityField); + UpdtateListData(Url('institutions', '', '0', '')) }; const CountryHandler = () => { setShowCountryField(!showContryField); - setApi(apiUrl + "/institutions") - UpdtateListData(api) + UpdtateListData(Url('institutions', '', '0', '')) }; const DescHandler = () => { setShowDescriptionField(!showDescriptionField); - setApi(apiUrl + "/institutions") - UpdtateListData(api) + UpdtateListData(Url('institutions', '', '0', '')) }; const StandartHandler = () => { setShowStandarSearchField(!showStandadSearch); - setApi(apiUrl + "/institutions") - UpdtateListData(api) + UpdtateListData(Url('institutions', '', '0', '')) }; const handleClick = (event) => { @@ -158,9 +154,9 @@ const Institutions = () => { const OnChangeSearchHandler = (e) => { setSeacrh(e.target.value); if (search.length === 0) { - UpdtateListData(api) + UpdtateListData(Url('institutions', '', '0', '')) } else { - setApi(BuildFilter('name', 'institutions', search)) + setApi(Url('institutions', `"name" : "${search}"`, '0' , '')) UpdtateListData(api) } }; @@ -168,19 +164,20 @@ const Institutions = () => { const onChangeCityHandler = (e) => { setCity(e.target.value); if (city.length === 0) { - UpdtateListData(`${apiUrl}/institutions`) + UpdtateListData(Url('institutions', '', '0', '')) + } else { - setApi(BuildFilter('city', 'institutions', city)) + setApi(Url('institutions', `"city" : "${city}"`, '0' , '')) UpdtateListData(api) - } + } }; const onChangeCountryHandler = (e) => { setCountry(e.target.value); if (country.length === 0) { - UpdtateListData(api) + UpdtateListData(Url('institutions', '', '0', '')) } else { - setApi(BuildFilter('country', 'institutions', country)) + setApi(Url('institutions', `"country" : "${country}"`, '0' , '')) UpdtateListData(api) } }; @@ -188,9 +185,9 @@ const Institutions = () => { const onChangeDescriptionHandler = (e) => { setDescription(e.target.value); if (description.length === 0) { - UpdtateListData(api) + UpdtateListData(Url('institutions', '', '0', '')) } else { - setApi(BuildFilter('description', 'institutions', description)) + setApi(Url('institutions', `"description" : "${description}"`, '0', '')) UpdtateListData(api) } }; @@ -231,6 +228,7 @@ const Institutions = () => { } else { setError(true); } + setIsUpdating(false) }); }; @@ -246,7 +244,7 @@ const Institutions = () => { "success", "#228B22" ); - UpdtateListData(api); + UpdtateListData(Url('institutions', '', '0', '')) } else { HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); } @@ -255,7 +253,7 @@ const Institutions = () => { } useEffect(() => { - fetch(api) + fetch(Url('institutions', '', '0', '')) .then((res) => res.json()) .then( (result) => { @@ -406,7 +404,7 @@ const Institutions = () => { } /> {/************** Start of the header **************/} - <Paper style={{ width: "100%", backgroundColor: "white" }}> + <Paper style={{ padding: '1em' }}> <Grid container spacing={3} direction="row" alignItems="center"> <Grid item xs={6}> <Typography className={classes.paper} variant="h4"> @@ -478,8 +476,15 @@ const Institutions = () => { color="secondary" className={classes.button} startIcon={<UpdateRoundedIcon />} + disabled={isUpdating} + onClick={() => { + setIsUpdating(true) + UpdtateListData(Url('institutions', '', '0', '')) + }} > - Atualizar + { + isUpdating ? <CircularProgress /> : 'Atualizar' + } </Button> </Grid> </Grid> @@ -519,7 +524,7 @@ const Institutions = () => { <TableData top={topTable}> <TableBody> {items.map((row, index) => ( - + <StyledTableRow key={index}> <StyledTableCell component="th" scope="row"> {row.id}