diff --git a/src/Admin/Components/Components/DataCard.js b/src/Admin/Components/Components/DataCard.js index 86d41b93ef8db1180cee02f24a42fd55bb70f869..9f5c565d6374808b1a0abc830cdfaba9e805881a 100644 --- a/src/Admin/Components/Components/DataCard.js +++ b/src/Admin/Components/Components/DataCard.js @@ -29,106 +29,112 @@ import { useStyles } from "../Styles/DataCard"; import EditRoundedIcon from "@material-ui/icons/EditRounded"; import ArrowBackIosIcon from "@material-ui/icons/ArrowBackIos"; -const DataCard = (props) => { - const classes = useStyles(); - const [edit, setEdit] = useState(false); +const DataCard = (params) => { + console.log(params) + return( + <div> + {params.data} + </div> + ) + // const classes = useStyles(); + // const [edit, setEdit] = useState(false); - const buttonArr = [ - { - label: "Listar", - icon: <ListRoundedIcon />, - }, - edit - ? { - label: "Voltar", - icon: <ArrowBackIosIcon />, - } - : { - label: "Editar", - icon: <EditRoundedIcon />, - }, - ]; + // const buttonArr = [ + // { + // label: "Listar", + // icon: <ListRoundedIcon />, + // }, + // edit + // ? { + // label: "Voltar", + // icon: <ArrowBackIosIcon />, + // } + // : { + // label: "Editar", + // icon: <EditRoundedIcon />, + // }, + // ]; - //Change state of the var edit - const EditHandler = () => { - setEdit(!edit); - }; + // //Change state of the var edit + // const EditHandler = () => { + // setEdit(!edit); + // }; - // it stores an function that will be called when a button is clicked - const functionArr = [props.viewData, EditHandler]; + // // it stores an function that will be called when a button is clicked + // const functionArr = [props.viewData, EditHandler]; - return ( - edit ? - <Card className={classes.root} variant="outlined"> - <CardContent> - <div className={classes.displayRow}> - <Typography - className={classes.title} - color="inherit" - gutterBottom - > - {props.data[1].prop} - </Typography> - <ButtonGroup - color="primary" - aria-label="outlined primary button group" - > - {buttonArr.map((button, index) => ( - <Button onClick={functionArr[index]}> - <div className={classes.displayRow}> - {button.icon} - {button.label} - </div> - </Button> - ))} - </ButtonGroup> - </div> + // return ( + // edit ? + // <Card className={classes.root} variant="outlined"> + // <CardContent> + // <div className={classes.displayRow}> + // <Typography + // className={classes.title} + // color="inherit" + // gutterBottom + // > + // {props.data[1].prop} + // </Typography> + // <ButtonGroup + // color="primary" + // aria-label="outlined primary button group" + // > + // {buttonArr.map((button, index) => ( + // <Button onClick={functionArr[index]}> + // <div className={classes.displayRow}> + // {button.icon} + // {button.label} + // </div> + // </Button> + // ))} + // </ButtonGroup> + // </div> - {/* Display the edit area */} - {props.component} + // {/* Display the edit area */} + // {props.component} - </CardContent> - </Card> - : - <Card className={classes.root} variant="outlined"> - <CardContent> - <div className={classes.displayRow}> - <Typography - className={classes.title} - color="inherit" - gutterBottom - > - {props.data[1].prop} - </Typography> - <ButtonGroup - color="primary" - aria-label="outlined primary button group" - > - {buttonArr.map((button, index) => ( - <Button onClick={functionArr[index]}> - <div className={classes.displayRow}> - {button.icon} - {button.label} - </div> - </Button> - ))} - </ButtonGroup> - </div> - {props.data.map((info , index) => ( - <div className={classes.displayColumn} key={index}> - <Typography color="initial" className={classes.subTitle}> - {info.subTitle} - </Typography> - <Typography color='textSecondary'> - { - info.prop === null ? 'Sem dados' : info.prop - } - </Typography> - </div> - ))} - </CardContent> - </Card> - ); + // </CardContent> + // </Card> + // : + // <Card className={classes.root} variant="outlined"> + // <CardContent> + // <div className={classes.displayRow}> + // <Typography + // className={classes.title} + // color="inherit" + // gutterBottom + // > + // {props.data[1].prop} + // </Typography> + // <ButtonGroup + // color="primary" + // aria-label="outlined primary button group" + // > + // {buttonArr.map((button, index) => ( + // <Button onClick={functionArr[index]}> + // <div className={classes.displayRow}> + // {button.icon} + // {button.label} + // </div> + // </Button> + // ))} + // </ButtonGroup> + // </div> + // {props.data.map((info , index) => ( + // <div className={classes.displayColumn} key={index}> + // <Typography color="initial" className={classes.subTitle}> + // {info.subTitle} + // </Typography> + // <Typography color='textSecondary'> + // { + // info.prop === null ? 'Sem dados' : info.prop + // } + // </Typography> + // </div> + // ))} + // </CardContent> + // </Card> + // ); } export default DataCard; diff --git a/src/Admin/Components/Components/Inputs/CreateInstitution.js b/src/Admin/Components/Components/Inputs/CreateInstitution.js index e2543ca5a61d74d52c2b0a91c438a49898401df5..4c51d9759abe31cbd986c840dd775c6c5f795841 100644 --- a/src/Admin/Components/Components/Inputs/CreateInstitution.js +++ b/src/Admin/Components/Components/Inputs/CreateInstitution.js @@ -31,6 +31,8 @@ import SnackBar from '../../../../Components/SnackbarComponent'; //imports services import { Create } from '../../../Services'; import { Url } from '../../../Filters'; +//router +import {Link} from 'react-router-dom'; const CreateInstitution = (props) => { const [name, setName] = useState('Nova Instituição'); @@ -203,17 +205,19 @@ const CreateInstitution = (props) => { <Typography variant='h4'> {name} </Typography> - <Button - onClick={props.BackToList} - startIcon={<ListRoundedIcon />} - variant='outlined' - color='primary' - > - Listar + <Link to={'/admin/intitutions'}> + <Button + onClick={props.BackToList} + startIcon={<ListRoundedIcon />} + variant='outlined' + color='primary' + > + Listar </Button> + </Link> </Grid> - <div style={{height : '1em'}}></div> + <div style={{ height: '1em' }}></div> <form style={{ display: 'flex', flexDirection: 'column' }}> {fields.map((field, index) => ( @@ -235,8 +239,7 @@ const CreateInstitution = (props) => { <CardAction> <Button onClick={() => { - onSubmit(); - setTimeout(function(){props.UpdateList(Url('institutions', '', '0', 'DESC'))}, 3000) + onSubmit(); }} variant="contained" color="primary" diff --git a/src/Admin/Components/Components/Inputs/IntitutionsInputs.js b/src/Admin/Components/Components/Inputs/IntitutionsInputs.js index b1f13cab0ceec8d245776d5ac7fc21f846133f7e..a6d30a8b101a4f64d68696738e03bffec27d043b 100644 --- a/src/Admin/Components/Components/Inputs/IntitutionsInputs.js +++ b/src/Admin/Components/Components/Inputs/IntitutionsInputs.js @@ -16,23 +16,34 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; //imports material ui components import { TextField, Button } from '@material-ui/core'; import CircularProgress from '@material-ui/core/CircularProgress'; import SaveIcon from '@material-ui/icons/Save'; +import Card from "@material-ui/core/Card"; +import CardContent from "@material-ui/core/CardContent"; +import Typography from "@material-ui/core/Typography"; +import ListRoundedIcon from "@material-ui/icons/ListRounded"; //imports local files import SnackBar from '../../../../Components/SnackbarComponent'; //imports services import { Edit } from '../../../Services'; -import { EditFilter , Url } from '../../../Filters'; -const EditInstitution = (props) => { - const id = props.editInfo.id - const [name, setName] = useState(props.editInfo.name); - const [description, setDescription] = useState(props.editInfo.description); - const [adress, setAdress] = useState(props.editInfo.adress); - const [city, setCity] = useState(props.editInfo.city); - const [country, setCountry] = useState(props.editInfo.country); +import { EditFilter, GetAData } from '../../../Filters'; +//Routers +import {Link} from 'react-router-dom'; + +let id; + +const EditInstitution = ({ match }) => { + 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 [name, setName] = useState(); + const [description, setDescription] = useState(); + const [adress, setAdress] = useState(); + const [city, setCity] = useState(); + const [country, setCountry] = useState(); //Used to display circle progress indicator when user click to save const [isLoading, setIsLoading] = useState(false); @@ -98,10 +109,10 @@ const EditInstitution = (props) => { } //Handle submit - async function onSubmit() { + async function onSubmit() { setIsLoading(true) if (!isEmpty(name) && !isEmpty(country)) { - const api = EditFilter('institutions' , id) + const api = EditFilter('institutions', id) const body = { "institution": { 'name': name, @@ -117,7 +128,7 @@ const EditInstitution = (props) => { HandleSnack('A instituição foi alterada com sucesso', true, 'success', '#228B22') } else { HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') - } + } setIsLoading(false) }) @@ -179,56 +190,107 @@ const EditInstitution = (props) => { } ] - return ( - <div> - <SnackBar - severity={snackInfo.icon} - text={snackInfo.message} - snackbarOpen={snackInfo.open} - color={snackInfo.color} - handleClose={() => setSnackInfo({ - message: '', - icon: '', - open: false, - color: '' - })} - /> - <div> - <form style={{ display: 'flex', flexDirection: 'column' }}> - {fields.map((field, index) => ( - <TextField - key={index} - required={field.required} - error={field.error} - helperText={field.error ? field.errorMessage : ''} - style={{ width: '250px', marginBottom: '1em' }} - label={field.label} - value={field.value} - onChange={field.onChange} - type="search" - multiline={true} - /> - ))} - </form> - </div> - <div> - <Button - onClick={() => { - onSubmit(); - setTimeout(function(){props.UpdateList(Url('institutions', '', '0', 'DESC'))}, 3000) - }} - variant="contained" - color="primary" - disabled={isLoading} - startIcon={ isLoading ? null : <SaveIcon />} - > - { - isLoading ? <CircularProgress size={24} /> : 'Salvar' - } - </Button> - </div> - </div> - ); + useEffect(() => { + fetch(GetAData("institutions", match.params.id)) + .then((res) => res.json()) + .then( + (result) => { + setIsLoaded(true); + setName(result.name) + setDescription(result.description) + setAdress(result.adress) + setCity(result.city) + setCountry(result.country) + id = result.id + }, + (error) => { + setIsLoaded(true); + setError(error); + } + ); + }, []); + + if (error) { + return <div> Erro... </div> + } else if (!isLoaded) { + return <div> Loading... </div> + } else { + return ( + <Card variant="outlined"> + <SnackBar + severity={snackInfo.icon} + text={snackInfo.message} + snackbarOpen={snackInfo.open} + color={snackInfo.color} + handleClose={() => setSnackInfo({ + message: '', + icon: '', + open: false, + color: '' + })} + /> + <CardContent> + <div style={{ display: 'flex', justifyContent: 'space-between' }}> + <Typography + variant='h4' + color="inherit" + gutterBottom + > + {name} + </Typography> + + <Link to={`/admin/intitutions`}> + <Button + startIcon={<ListRoundedIcon />} + color="primary" + variant="outlined" + > + Listar + </Button> + </Link> + </div> + + <div> + <div> + <form style={{ display: 'flex', flexDirection: 'column' }}> + {fields.map((field, index) => ( + <TextField + key={index} + required={field.required} + error={field.error} + helperText={field.error ? field.errorMessage : ''} + style={{ width: '250px', marginBottom: '1em' }} + label={field.label} + value={field.value} + onChange={field.onChange} + type="search" + multiline={true} + /> + ))} + </form> + </div> + <div> + <Button + onClick={() => { + onSubmit(); + }} + variant="contained" + color="primary" + disabled={isLoading} + startIcon={isLoading ? null : <SaveIcon />} + > + { + isLoading ? <CircularProgress size={24} /> : 'Salvar' + } + </Button> + </div> + </div> + + </CardContent> + </Card> + + ); + } } export default EditInstitution; \ No newline at end of file diff --git a/src/Admin/Pages/Pages/Admin.js b/src/Admin/Pages/Pages/Admin.js index 9d7a35455c4dee4737e3805883d008e49fb17f72..e6bfcead089dde749c7486ae148cbcc7e099ddb5 100644 --- a/src/Admin/Pages/Pages/Admin.js +++ b/src/Admin/Pages/Pages/Admin.js @@ -40,6 +40,10 @@ import Institution from './SubPages/Institutions'; import SendEmail from './SubPages/SendEmail'; import Inframe from './SubPages/Inframe'; import Languages from './SubPages/Languages'; +import Activity from './SubPages/Activity'; +import InstitutionCard from '../../Components/Components/DataCards/InstitutionsCard'; +import InstitutionsInput from '../../Components/Components/Inputs/IntitutionsInputs'; +import CreateInstitution from '../../Components/Components/Inputs/CreateInstitution'; const useStyles = makeStyles({ list: { @@ -111,11 +115,18 @@ export default function Admin() { <Switch> <div style={{ paddingTop: '2em', paddingLeft: '2em', paddingRight: '2em', paddingBottom: '2em', backgroundColor: ' #D3D3D3' }}> <Route path='/admin/home' component={Welcome} /> - <Route path='/admin/intitution' component={Institution} /> + + <Route path='/admin/intitutions' component={Institution} /> + <Route path='/admin/intitution/:id' component={InstitutionCard}/> + <Route path='/admin/intitutionEdit/:id' component={InstitutionsInput}/> + <Route path='/admin/InstitutionCreate' component={CreateInstitution}/> + <Route path='/admin/sendEmail' component={SendEmail} /> <Route path='/admin/inframe' component={Inframe} /> <Route path='/admin/noteVar' component={NoteVariables} /> - <Route path='/admin/languages' component={Languages}/> + <Route path='/admin/languages' component={Languages} /> + <Route path='/admin/activity' component={Activity} /> + </div> </Switch> diff --git a/src/Admin/Pages/Pages/SubPages/Institutions.js b/src/Admin/Pages/Pages/SubPages/Institutions.js index a7c61efd1dd5422396f03f8af30856bafefc47a0..ea358988e625fe31b373edec9bc38bd4a1cdd269 100644 --- a/src/Admin/Pages/Pages/SubPages/Institutions.js +++ b/src/Admin/Pages/Pages/SubPages/Institutions.js @@ -17,12 +17,8 @@ You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ import React, { useState, useEffect } from "react"; -import { apiUrl } from "../../../../env"; // Imports from local files import TableData from "../../../Components/Components/Table"; -import DataCard from "../../../Components/Components/DataCard"; -import InstitutionsInputs from "../../../Components/Components/Inputs/IntitutionsInputs"; -import CreateInstitution from "../../../Components/Components/Inputs/CreateInstitution"; import SnackBar from "../../../../Components/SnackbarComponent"; import AlertDialog from "../../../Components/Components/AlertDialog"; // Imports about icon @@ -48,6 +44,8 @@ import TextField from "@material-ui/core/TextField"; import { Delete, GetFullList } from "../../../Services"; //Filters import { Url, GetOneOfAllUrl, EditFilter } from "../../../Filters"; +//router +import { Link } from 'react-router-dom'; let currPage = 0; let transformListToAsc = false @@ -97,13 +95,6 @@ const Institutions = () => { const [isLoadingToDelete, setIsLoadingToDelete] = useState(null); const [isUpdating, setIsUpdating] = useState(false); const [isLoadingMoreItems, setIsLoadingMoreItems] = useState(false); - // const [isFiltering , setIsFiltering] = 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 - const [viewData, setViewData] = useState(false); //Controlls the state, if someone wants to see the data - - const [createNewInstitution, setCreateNewInstitution] = useState(false); const [openAlertDialog, setOpenAlertDialog] = useState(false); @@ -195,13 +186,6 @@ const Institutions = () => { }; // **************** About the PopOverMenu **************** - //Controlls the state of the create institution sections - const CreateInstitutionHandler = () => { - transformListToAsc = false - currPage = 0; - setCreateNewInstitution(!createNewInstitution); - }; - //Controlls the state of the Alert Dialog const HandleStateAlertDialog = (i) => { const obj = { ...items[i] }; @@ -360,51 +344,6 @@ const Institutions = () => { "Deletar", ]; - // i = index of the array of the table - const viewDataHandler = (i) => { - currPage = 0; - const item = { ...items[i] }; - const infoArr = [ - { - subTitle: "ID", - prop: item.id, - }, - { - subTitle: "Nome", - prop: item.name, - }, - { - subTitle: "Descrição", - prop: item.description, - }, - { - subTitle: "Endereço", - prop: item.address, - }, - { - subTitle: "Cidade", - prop: item.city, - }, - { - subTitle: "PaÃs", - prop: item.country, - }, - ]; - - const objEdit = { - id: item.id, - name: item.name, - adress: item.address, - city: item.city, - country: item.country, - description: item.description, - }; - - setData(infoArr); - setEditInfo(objEdit); - setViewData(!viewData); - }; - //Buttons from PopOverMenu const flatButtonsFromPopOverMenu = [ { @@ -457,244 +396,236 @@ const Institutions = () => { }, ]; - return !viewData ? ( - createNewInstitution ? ( - <CreateInstitution - BackToList={CreateInstitutionHandler} - UpdateList={UpdtateListData} + return ( + <div> + <SnackBar + severity={snackInfo.icon} + text={snackInfo.message} + snackbarOpen={snackInfo.open} + color={snackInfo.color} + handleClose={() => + setSnackInfo({ + message: "", + icon: "", + open: false, + color: "", + }) + } /> - ) : ( - <div> - <SnackBar - severity={snackInfo.icon} - text={snackInfo.message} - snackbarOpen={snackInfo.open} - color={snackInfo.color} - handleClose={() => - setSnackInfo({ - message: "", - icon: "", - open: false, - color: "", - }) - } - /> - {/************** Start of the header **************/} - <Paper style={{ padding: "1em" }}> - <Grid container spacing={3} direction="row" alignItems="center"> - <Grid item xs={6}> - <Typography className={classes.paper} variant="h4"> - Lista de Instituições - </Typography> - </Grid> - <Grid - item - xs={6} - alignItems="center" - justify="center" - direction="row" - > - <Grid container justify="flex-end" spacing={3}> - <Grid item> + {/************** Start of the header **************/} + <Paper style={{ padding: "1em" }}> + <Grid container spacing={3} direction="row" alignItems="center"> + <Grid item xs={6}> + <Typography className={classes.paper} variant="h4"> + Lista de Instituições + </Typography> + </Grid> + <Grid + item + xs={6} + alignItems="center" + justify="center" + direction="row" + > + <Grid container justify="flex-end" spacing={3}> + <Grid item> + <Button + aria-describedby={id} + variant="contained" + color="secondary" + className={classes.button} + onClick={handleClick} + startIcon={ + <FilterListRoundedIcon style={{ fill: "white" }} /> + } + > + Filtrar + </Button> + <Popover + id={id} + open={open} + anchorEl={anchorEl} + onClose={handleClose} + anchorOrigin={{ + vertical: "bottom", + horizontal: "center", + }} + transformOrigin={{ + vertical: "top", + horizontal: "center", + }} + > + {flatButtonsFromPopOverMenu.map((flat, index) => ( <Button - aria-describedby={id} - variant="contained" - color="secondary" - className={classes.button} - onClick={handleClick} - startIcon={ - <FilterListRoundedIcon style={{ fill: "white" }} /> - } + key={index} + onClick={flat.onClick} + color={flat.color} > - Filtrar + {flat.label} </Button> - <Popover - id={id} - open={open} - anchorEl={anchorEl} - onClose={handleClose} - anchorOrigin={{ - vertical: "bottom", - horizontal: "center", - }} - transformOrigin={{ - vertical: "top", - horizontal: "center", - }} - > - {flatButtonsFromPopOverMenu.map((flat, index) => ( - <Button - key={index} - onClick={flat.onClick} - color={flat.color} - > - {flat.label} - </Button> - ))} - </Popover> - </Grid> - - <Grid item> - <Button - variant="contained" - color="secondary" - className={classes.button} - startIcon={<AddRoundedIcon style={{ fill: "white" }} />} - onClick={CreateInstitutionHandler} - > - Novo - </Button> - </Grid> + ))} + </Popover> + </Grid> - <Grid item> - <Button - variant="contained" - color="secondary" - className={classes.button} - startIcon={<UpdateRoundedIcon />} - disabled={isUpdating} - onClick={() => { - currPage = 0; - transformListToAsc = false - setIsUpdating(true); - UpdtateListData( - Url("institutions", "", `${currPage}`, "DESC") - ); - }} - > - {isUpdating ? <CircularProgress /> : "Atualizar"} - </Button> - </Grid> - </Grid> + <Grid item> + <Link to={'/admin/InstitutionCreate'}> + <Button + variant="contained" + color="secondary" + className={classes.button} + startIcon={<AddRoundedIcon style={{ fill: "white" }} />} + onClick={() => { + currPage = 0 + transformListToAsc = false + }} + > + Novo + </Button> + </Link> </Grid> - </Grid> - <Grid item xs={12}> - <Grid container justify="space-between" spacing={3}> - {TextFieldOfTheFilter.map((field, index) => ( - <Grid item> - {field.show ? ( - <div> - <TextField - id={index} - label={field.label} - type="search" - onChange={field.onChange} - /> - <IconButton - size="small" - color="primary" - onClick={field.hide} - > - <CancelRoundedIcon /> - </IconButton> - </div> - ) : null} - </Grid> - ))} + + <Grid item> + <Button + variant="contained" + color="secondary" + className={classes.button} + startIcon={<UpdateRoundedIcon />} + disabled={isUpdating} + onClick={() => { + currPage = 0; + transformListToAsc = false + setIsUpdating(true); + UpdtateListData( + Url("institutions", "", `${currPage}`, "DESC") + ); + }} + > + {isUpdating ? <CircularProgress /> : "Atualizar"} + </Button> </Grid> </Grid> - </Paper> - {/************** End of the header **************/} - - <div style={{ height: "2em" }}></div> - - {/************** Start of display data in table **************/} - <TableData top={topTable} onIconPressed={InvertList}> - <TableBody> - {items.map((row, index) => - index === items.length - 1 ? ( - <div style={{ padding: "1em" }}> - {/* Button to load more data */} - <Button + </Grid> + </Grid> + <Grid item xs={12}> + <Grid container justify="space-between" spacing={3}> + {TextFieldOfTheFilter.map((field, index) => ( + <Grid item> + {field.show ? ( + <div> + <TextField + id={index} + label={field.label} + type="search" + onChange={field.onChange} + /> + <IconButton + size="small" color="primary" - variant="text" - startIcon={<AddRoundedIcon />} - disabled={ - isLoadingMoreItems || - isFilteringByCity || - isFilteringByCounty || - isFilteringByDesc || - isFilteringByName - } - onClick={() => { - currPage++ - if (transformListToAsc) { - LoadMoreItens(Url('institutions', '', `${currPage}`, 'ASC')) - } else { - LoadMoreItens(Url('institutions', '', `${currPage}`, 'DESC')) - } - }} + onClick={field.hide} > - {isLoadingMoreItems ? ( - <CircularProgress /> - ) : ( - "Carregar mais itens" - )} - </Button> + <CancelRoundedIcon /> + </IconButton> </div> - ) : ( - <StyledTableRow key={index}> - <StyledTableCell component="th" scope="row"> - {row.id} - </StyledTableCell> - <StyledTableCell align="right">{row.name}</StyledTableCell> - <StyledTableCell align="right"> - {row.description} - </StyledTableCell> - <StyledTableCell align="right">{row.city}</StyledTableCell> - <StyledTableCell align="right"> - {row.country} - </StyledTableCell> - <StyledTableCell align="right"> - <IconButton onClick={() => viewDataHandler(index)}> - <VisibilityIcon style={{ fill: "#8A2BE2" }} /> + ) : null} + </Grid> + ))} + </Grid> + </Grid> + </Paper> + {/************** End of the header **************/} + + <div style={{ height: "2em" }}></div> + + {/************** Start of display data in table **************/} + <TableData top={topTable} onIconPressed={InvertList}> + <TableBody> + {items.map((row, index) => + index === items.length - 1 ? ( + <div style={{ padding: "1em" }}> + {/* Button to load more data */} + <Button + color="primary" + variant="text" + startIcon={<AddRoundedIcon />} + disabled={ + isLoadingMoreItems || + isFilteringByCity || + isFilteringByCounty || + isFilteringByDesc || + isFilteringByName + } + onClick={() => { + currPage++ + if (transformListToAsc) { + LoadMoreItens(Url('institutions', '', `${currPage}`, 'ASC')) + } else { + LoadMoreItens(Url('institutions', '', `${currPage}`, 'DESC')) + } + }} + > + {isLoadingMoreItems ? ( + <CircularProgress /> + ) : ( + "Carregar mais itens" + )} + </Button> + </div> + ) : ( + <StyledTableRow key={index}> + <StyledTableCell component="th" scope="row"> + {row.id} + </StyledTableCell> + <StyledTableCell align="right">{row.name}</StyledTableCell> + <StyledTableCell align="right"> + {row.description} + </StyledTableCell> + <StyledTableCell align="right">{row.city}</StyledTableCell> + <StyledTableCell align="right"> + {row.country} + </StyledTableCell> + <StyledTableCell align="right"> + <Link to={`/admin/intitution/${row.id}`}> + <IconButton onClick={() => { + currPage = 0 + transformListToAsc = false + }}> + <VisibilityIcon style={{ fill: "#00bcd4" }} /> + </IconButton> + </Link> + </StyledTableCell> + <StyledTableCell align="right"> + {isLoadingToDelete === index ? ( + <CircularProgress size={24} color="primary" /> + ) : ( + <IconButton + onClick={() => { + HandleStateAlertDialog(index); + HandleStateCircularProgress(index); + }} + > + <DeleteIcon style={{ fill: "#FF0000" }} /> </IconButton> - </StyledTableCell> - <StyledTableCell align="right"> - {isLoadingToDelete === index ? ( - <CircularProgress size={24} color="primary" /> - ) : ( - <IconButton - onClick={() => { - HandleStateAlertDialog(index); - HandleStateCircularProgress(index); - }} - > - <DeleteIcon style={{ fill: "#FF0000" }} /> - </IconButton> - )} - </StyledTableCell> - </StyledTableRow> - ) - )} - </TableBody> - </TableData> - {/************** End of display data in table **************/} - - {/* This alert will be displayed if the user click to delete an institution */} - <AlertDialog - open={openAlertDialog} - OnDelete={DeleteHandler} - deleteItem={deleteItem} - HandleClose={() => { - setOpenAlertDialog(false); - HandleStateCircularProgress(null); - }} - /> - </div> - ) - ) : ( - <DataCard - data={data} - component={ - <InstitutionsInputs - editInfo={editInfo} - UpdateList={UpdtateListData} - /> - } - viewData={() => setViewData(!viewData)} + )} + </StyledTableCell> + </StyledTableRow> + ) + )} + </TableBody> + </TableData> + {/************** End of display data in table **************/} + + {/* This alert will be displayed if the user click to delete an institution */} + <AlertDialog + open={openAlertDialog} + OnDelete={DeleteHandler} + deleteItem={deleteItem} + HandleClose={() => { + setOpenAlertDialog(false); + HandleStateCircularProgress(null); + }} /> - ); + </div> + ) } };