diff --git a/src/Admin/Pages/Pages/SubPages/Activity.js b/src/Admin/Pages/Pages/SubPages/Activity.js index 21308bd036ff937cb72617def822903626aaafab..d01a5c573e97794762b4692b393b37e10734f32a 100644 --- a/src/Admin/Pages/Pages/SubPages/Activity.js +++ b/src/Admin/Pages/Pages/SubPages/Activity.js @@ -258,10 +258,6 @@ const Activity = () => { variant="contained" color="secondary" onClick={() => { - currPage = 0; - UpdateHandler( - Url("activities", "", `${currPage}`, "DESC") - ); setShowFilter(!showFilter); }} startIcon={<FilterListRoundedIcon />} diff --git a/src/Admin/Pages/Pages/SubPages/AproveTeacher.js b/src/Admin/Pages/Pages/SubPages/AproveTeacher.js index 45c88dcb9b5902175158598a0b34fb640227c600..29d6988a36bcda9735524140dec70d41cdead60f 100644 --- a/src/Admin/Pages/Pages/SubPages/AproveTeacher.js +++ b/src/Admin/Pages/Pages/SubPages/AproveTeacher.js @@ -24,7 +24,10 @@ import SnackBar from "../../../../Components/SnackbarComponent"; import { Url } from "../../../Filters"; import { Store } from "../../../../Store"; import LoadingSpinner from "../../../../Components/LoadingSpinner"; -import { getRequest, postRequest } from "../../../../Components/HelperFunctions/getAxiosConfig"; +import { + getRequest, + postRequest, +} from "../../../../Components/HelperFunctions/getAxiosConfig"; //imports from material ui import { withStyles } from "@material-ui/core/styles"; import TableBody from "@material-ui/core/TableBody"; @@ -46,9 +49,9 @@ import { Link } from "react-router-dom"; import Unauthorized from "../../../Components/Components/Unauthorized"; let currPage = 0; -let currContentState = "requested"; -let currContentName = ""; -let currContentEmail = ""; +let currStateFilter = "requested"; +let currNameFilter = ""; +let currEmailFilter = ""; const StyledTableCell = withStyles((theme) => ({ head: { @@ -91,7 +94,7 @@ const AproveTeacher = () => { const [showFilter, setShowFilter] = useState(false); - const [option, setOption] = useState("Pendente"); + const [option, setOption] = useState("requested"); const [name, setName] = useState(""); const [email, setEmail] = useState(""); @@ -187,17 +190,16 @@ const AproveTeacher = () => { const handleChange = (e, type) => { const value = e.target.value; - console.log(e); setOption(value); }; const ApplyFilter = (id, type) => { + currStateFilter = id; currPage = 0; - currContentState = id; getRequest( Url( "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, + `"submitter_request":"${currStateFilter}","name":"${currNameFilter}","email":"${email}"`, `${currPage}`, "DESC" ), @@ -216,11 +218,12 @@ const AproveTeacher = () => { const NameHandler = (e) => { currPage = 0; - currContentName = e.target.value; + currNameFilter = e.target.value + setName(currNameFilter); getRequest( Url( "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, + `"submitter_request":"${currStateFilter}","name":"${currNameFilter}","email":"${email}"`, `${currPage}`, "DESC" ), @@ -239,11 +242,12 @@ const AproveTeacher = () => { const EmailHandler = (e) => { currPage = 0; - currContentEmail = e.target.value; + currEmailFilter = e.target.value + setEmail(currEmailFilter); getRequest( Url( "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, + `"submitter_request":"${currStateFilter}","name":"${currNameFilter}","email":"${currEmailFilter}"`, `${currPage}`, "DESC" ), @@ -317,7 +321,7 @@ const AproveTeacher = () => { > Não requisitado </Paper> - ) + ); } }; @@ -329,72 +333,79 @@ const AproveTeacher = () => { }; const handleAprove = (userId, userName) => { - const url = `/users/${userId}/add_teacher` + const url = `/users/${userId}/add_teacher`; const body = { - "approves": true - } + approves: true, + }; postRequest( url, body, (data) => { - if (data.errors) - HandleSnack("Erro!", true, "warning", "#FA8072"); + if (data.errors) HandleSnack("Erro!", true, "warning", "#FA8072"); else { - HandleSnack(`${userName} aceito como professor!`, true, "success", "#228B22"); + HandleSnack( + `${userName} aceito como professor!`, + true, + "success", + "#228B22" + ); currPage = 0; UpdateHandler( Url( "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, + `"submitter_request":"${currStateFilter}","name":"${currNameFilter}","email":"${currEmailFilter}"`, `${currPage}`, "DESC" - ), + ) ); } }, (error) => { HandleSnack("Erro!", true, "warning", "#FA8072"); } - ) - } + ); + }; const handleReject = (userId, userName) => { - const url = `/users/${userId}/add_teacher` + const url = `/users/${userId}/add_teacher`; const body = { - "approves": false - } + approves: false, + }; postRequest( url, body, (data) => { - if (data.errors) - HandleSnack("Erro!", true, "warning", "#FA8072"); - else - { - HandleSnack(`${userName} rejeitado como professor!`, true, "success", "#228B22"); + if (data.errors) HandleSnack("Erro!", true, "warning", "#FA8072"); + else { + HandleSnack( + `${userName} rejeitado como professor!`, + true, + "success", + "#228B22" + ); currPage = 0; UpdateHandler( Url( "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, + `"submitter_request":"${currStateFilter}","name":"${currNameFilter}","email":"${currEmailFilter}"`, `${currPage}`, "DESC" - ), + ) ); } }, (error) => { HandleSnack("Erro!", true, "warning", "#FA8072"); } - ) - } + ); + }; //getting data from server useEffect(() => { getRequest( Url( "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, + `"submitter_request":"${currStateFilter}","name":"${currNameFilter}","email":"${currEmailFilter}"`, `${currPage}`, "DESC" ), @@ -454,10 +465,10 @@ const AproveTeacher = () => { UpdateHandler( Url( "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, + `"submitter_request":"${currStateFilter}","name":"${currNameFilter}","email":"${currEmailFilter}"`, `${currPage}`, "DESC" - ), + ) ); }} startIcon={<UpdateRoundedIcon />} @@ -470,15 +481,6 @@ const AproveTeacher = () => { variant="contained" color="secondary" onClick={() => { - currPage = 0; - UpdateHandler( - Url( - "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, - `${currPage}`, - "DESC" - ), - ); setShowFilter(!showFilter); }} startIcon={<FilterListRoundedIcon />} @@ -523,10 +525,14 @@ const AproveTeacher = () => { </TextField> </Grid> <Grid item> - <TextField label="Nome" onBlur={NameHandler} value={name} onChange={(e) => { setName(e.target.value) }} /> + <TextField label="Nome" onChange={NameHandler} value={name} /> </Grid> <Grid item> - <TextField label="Email" onBlur={EmailHandler} value={email} onChange={(e) => { setEmail(e.target.value) }} /> + <TextField + label="Email" + onChange={EmailHandler} + value={email} + /> </Grid> </Grid> ) : null} @@ -553,11 +559,11 @@ const AproveTeacher = () => { LoadMoreItens( Url( "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, + `"submitter_request":"${currStateFilter}","name":"${currNameFilter}","email":"${currEmailFilter}"`, `${currPage}`, "DESC" - ), - ) + ) + ); }} > {isLoadingMoreItems ? ( @@ -587,6 +593,8 @@ const AproveTeacher = () => { <IconButton onClick={() => { currPage = 0; + currNameFilter = "" + currEmailFilter = "" }} > <VisibilityIcon style={{ fill: "#00bcd4" }} /> @@ -604,7 +612,9 @@ const AproveTeacher = () => { startIcon={ <CloseRoundedIcon style={{ fill: "#FFFAFA" }} /> } - onClick={() => { handleReject(row.id, row.name) }} + onClick={() => { + handleReject(row.id, row.name); + }} > Recusar </Button> @@ -619,7 +629,9 @@ const AproveTeacher = () => { startIcon={ <CheckRoundedIcon style={{ fill: "#FFFAFA" }} /> } - onClick={() => { handleAprove(row.id, row.name) }} + onClick={() => { + handleAprove(row.id, row.name); + }} > Aceitar </Button> diff --git a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js index 06f0f96defc4d9d738ad82d36d49d99038951350..86b10055cafc7a5ebbba84e03badb9e66ae17145 100644 --- a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js +++ b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js @@ -38,7 +38,7 @@ import TableData from '../../../Components/Components/Table'; import SnackBar from '../../../../Components/SnackbarComponent'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; //Services -import { getRequest, postRequest, putRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' +import { getRequest, putRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' import { Url } from '../../../Filters'; //routers import { Link } from 'react-router-dom'; @@ -462,7 +462,7 @@ const BlockedUsers = () => { </Button> <Link to={`/admin/user/${row.id}`}> <Button - onClick={() => { currPage = 0; transformListToAsc = false }} + onClick={() => { currPage = 0; transformListToAsc = false; currContentFilter = 1}} style={{ width: "100%" }} variant="contained" color="primary" diff --git a/src/Admin/Pages/Pages/SubPages/Collections.js b/src/Admin/Pages/Pages/SubPages/Collections.js index 4acb169bb479fcb42de78075b7629f267dc0a9cf..0950588baedb6be69c2c3fea0d54f5c5acd6ed6f 100644 --- a/src/Admin/Pages/Pages/SubPages/Collections.js +++ b/src/Admin/Pages/Pages/SubPages/Collections.js @@ -17,13 +17,13 @@ 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, { useEffect, useState } from "react"; -import moment from 'moment'; +import moment from "moment"; //imports from local files import TableData from "../../../Components/Components/Table"; import SnackBar from "../../../../Components/SnackbarComponent"; import { Url, DeleteFilter } from "../../../Filters"; import AlertDialog from "../../../Components/Components/AlertDialog"; -import LoadingSpinner from '../../../../Components/LoadingSpinner'; +import LoadingSpinner from "../../../../Components/LoadingSpinner"; //imports from material ui import { withStyles } from "@material-ui/core/styles"; import TableBody from "@material-ui/core/TableBody"; @@ -39,11 +39,16 @@ import UpdateRoundedIcon from "@material-ui/icons/UpdateRounded"; import FilterListRoundedIcon from "@material-ui/icons/FilterListRounded"; import VisibilityIcon from "@material-ui/icons/Visibility"; import DeleteIcon from "@material-ui/icons/Delete"; -import { deleteRequest, getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig'; +import { + deleteRequest, + getRequest, +} from "../../../../Components/HelperFunctions/getAxiosConfig"; //routers -import { Link } from 'react-router-dom'; +import { Link } from "react-router-dom"; let currPage = 0; +let currPrivacyFilter = ""; +let currNameFilter = ""; const StyledTableCell = withStyles((theme) => ({ head: { @@ -73,7 +78,7 @@ const Collections = () => { "ATUALIZAÇÃO", "PRIVACIDADE", "VISUALIZAR", - "DELETAR" + "DELETAR", ]; //Labels from Table const [error, setError] = useState(null); //Necessary to consult the API, catch errors @@ -84,7 +89,7 @@ const Collections = () => { const [isUpdating, setIsUpdating] = useState(false); //controlls the state of updating data const [showFilter, setShowFilter] = useState(false); - const [search, setSearch] = useState(''); + const [search, setSearch] = useState(""); const [openAlertDialog, setOpenAlertDialog] = useState(false); const [deleteItem, setDeleteItem] = useState({}); //Delete Item @@ -123,7 +128,8 @@ const Collections = () => { //handle load more items const LoadMoreItens = async (api) => { setIsLoadingMoreItems(true); - getRequest(api, + getRequest( + api, (data, header) => { const arrData = [...data]; if (arrData.length === 0) { @@ -145,7 +151,7 @@ const Collections = () => { HandleSnack("Erro ao carregar os dados", true, "warning", "#FA8072"); setIsLoadingMoreItems(false); } - ) + ); }; //Defines which row must show the circular progress @@ -156,7 +162,8 @@ const Collections = () => { // handle update list data const UpdateHandler = async (api) => { setIsUpdating(true); - getRequest(api, + getRequest( + api, (data, header) => { HandleSnack( "A lista de dados foi atualizada", @@ -172,14 +179,15 @@ const Collections = () => { HandleSnack("Erro ao carregar os dados", true, "warning", "#FA8072"); setIsUpdating(false); } - ) + ); }; //Called when user want to delete one institution async function DeleteHandler() { const id = deleteItem.id; HandleStateAlertDialog(null); - deleteRequest(DeleteFilter("collections", id), + deleteRequest( + DeleteFilter("collections", id), (data) => { if (data.errors) HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); @@ -199,7 +207,7 @@ const Collections = () => { HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); HandleStateCircularProgress(null); } - ) + ); } //Controlls the state of the Alert Dialog @@ -209,15 +217,17 @@ const Collections = () => { setOpenAlertDialog(!openAlertDialog); }; - - // handle change of privacy - const handleChange = (e) => { - const value = e.target.value; - console.log(value); + const ApplyFilter = (value) => { + currPrivacyFilter = value currPage = 0; - setIsLoaded(false) - setOption(value); - getRequest(Url("collections", `"privacy" : "${value}"`, `${currPage}`, "DESC"), + setIsLoaded(false); + getRequest( + Url( + "collections", + `"privacy" : "${currPrivacyFilter}" , "name" : "${currNameFilter}"`, + `${currPage}`, + "DESC" + ), (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -228,14 +238,25 @@ const Collections = () => { HandleSnack("Erro ao carregar os dados", true, "warning", "#FA8072"); setIsLoaded(true); } - ) + ); + } + + // handle change of privacy + const handleChange = (e) => { + setOption(e.target.value); }; //Handle the search filter const HandleSearch = (event) => { - setSearch(event.target.value) + currNameFilter = event.target.value + setSearch(currNameFilter); getRequest( - Url("collections", `"name" : "${search}"`, `${currPage}`, "DESC"), + Url( + "collections", + `"privacy" : "${currPrivacyFilter}" , "name" : "${currNameFilter}"`, + `${currPage}`, + "DESC" + ), (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -245,8 +266,8 @@ const Collections = () => { HandleSnack("Erro ao carregar os dados", true, "warning", "#FA8072"); setIsLoaded(true); } - ) - } + ); + }; const DisplayDate = (date) => { const convertedData = moment.utc(date); @@ -258,7 +279,12 @@ const Collections = () => { //getting data from server useEffect(() => { getRequest( - Url("collections", "", `${currPage}`, "DESC"), + Url( + "collections", + `"privacy" : "${currPrivacyFilter}" , "name" : "${currNameFilter}"`, + `${currPage}`, + "DESC" + ), (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -270,218 +296,215 @@ const Collections = () => { setIsLoaded(false); setError(true); } - ) + ); }, []); if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..." /> + return <LoadingSpinner text="Carregando..." />; } else { - - return <> - <SnackBar - severity={snackInfo.icon} - text={snackInfo.message} - snackbarOpen={snackInfo.open} - color={snackInfo.color} - handleClose={() => - setSnackInfo({ - message: "", - icon: "", - open: false, - color: "", - }) - } - /> - - <Paper style={{ padding: "1em" }}> - <Grid container spacing={3} direction="row" alignItems="center"> - <Grid item xs={6}> - <Typography variant="h4">Coleções</Typography> - </Grid> - <Grid - item - xs={6} - > - <Grid container justify="flex-end" spacing={3}> - <Grid item> - <Button - variant="contained" - color="secondary" - disabled={isUpdating} - onClick={() => { - currPage = 0; - UpdateHandler( - Url("collections", "", `${currPage}`, "DESC") - ); - }} - startIcon={<UpdateRoundedIcon />} - > - {isUpdating ? <CircularProgress size={24} /> : "Atualizar"} - </Button> - </Grid> - <Grid item> - <Button - variant="contained" - color="secondary" - onClick={() => { - currPage = 0; - UpdateHandler( - Url("collections", "", `${currPage}`, "DESC") - ); - setShowFilter(!showFilter); - }} - startIcon={<FilterListRoundedIcon />} - > - Filtrar - </Button> + return ( + <> + <SnackBar + severity={snackInfo.icon} + text={snackInfo.message} + snackbarOpen={snackInfo.open} + color={snackInfo.color} + handleClose={() => + setSnackInfo({ + message: "", + icon: "", + open: false, + color: "", + }) + } + /> + + <Paper style={{ padding: "1em" }}> + <Grid container spacing={3} direction="row" alignItems="center"> + <Grid item xs={6}> + <Typography variant="h4">Coleções</Typography> + </Grid> + <Grid item xs={6}> + <Grid container justify="flex-end" spacing={3}> + <Grid item> + <Button + variant="contained" + color="secondary" + disabled={isUpdating} + onClick={() => { + currPage = 0; + UpdateHandler( + Url( + "collections", + `"privacy" : "${currPrivacyFilter}" , "name" : "${currNameFilter}"`, + `${currPage}`, + "DESC" + ) + ); + }} + startIcon={<UpdateRoundedIcon />} + > + {isUpdating ? <CircularProgress size={24} /> : "Atualizar"} + </Button> + </Grid> + <Grid item> + <Button + variant="contained" + color="secondary" + onClick={() => { + setShowFilter(!showFilter); + }} + startIcon={<FilterListRoundedIcon />} + > + Filtrar + </Button> + </Grid> </Grid> </Grid> </Grid> - </Grid> - - {showFilter ? ( - <> - <div style={{ height: "1em" }}></div> - - <Grid container alignItems="center" alignContent="center" xs={12} direction="row" justify="space-between"> - <Grid item> - <TextField - select - label="Filtro" - value={option ? option : ""} - onChange={handleChange} - helperText="Por favor, selecione uma das opções" - > - {options.map((option, index) => ( - <MenuItem - key={index} - value={option.value} - > - {option.label} - </MenuItem> - ))} - </TextField> + + {showFilter ? ( + <> + <div style={{ height: "1em" }}></div> + + <Grid + container + alignItems="center" + alignContent="center" + xs={12} + direction="row" + justify="space-between" + > + <Grid item> + <TextField + select + label="Filtro" + value={option ? option : ""} + onChange={handleChange} + helperText="Por favor, selecione uma das opções" + > + {options.map((option, index) => ( + <MenuItem key={index} value={option.value} onClick={() => { ApplyFilter(option.value) }}> + {option.label} + </MenuItem> + ))} + </TextField> + </Grid> + + <Grid item> + <TextField + label="Pesquisa" + value={search} + onChange={(event) => HandleSearch(event)} + ></TextField> + </Grid> </Grid> + </> + ) : null} + </Paper> - <Grid item> - <TextField - label="Pesquisa" - onChange={(event) => HandleSearch(event)} - > + <div style={{ height: "2em" }}></div> - </TextField> - </Grid> - </Grid> - </> - ) : null} - </Paper> - - <div style={{ height: "2em" }}></div> - - <TableData top={TOP_LABELS}> - <TableBody> - {items.map((row, index) => - index === items.length - 1 ? ( - <StyledTableRow key={index}> - <StyledTableCell> - <Button - key={index} - color="primary" - variant="text" - // disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - disabled={isLoadingMoreItems} - onClick={() => { - currPage++; - if (showFilter) { - if (search) { - LoadMoreItens( - Url("collections", `"name" : "${search}"`, `${currPage}`, "DESC") - ); - } - else { - LoadMoreItens( - Url("collections", `"privacy" : "${option}"`, `${currPage}`, "DESC") - ); - } - } else { + <TableData top={TOP_LABELS}> + <TableBody> + {items.map((row, index) => + index === items.length - 1 ? ( + <StyledTableRow key={index}> + <StyledTableCell> + <Button + key={index} + color="primary" + variant="text" + // disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + disabled={isLoadingMoreItems} + onClick={() => { + currPage++; LoadMoreItens( - Url("collections", "", `${currPage}`, "DESC") + Url( + "collections", + `"privacy" : "${currPrivacyFilter}" , "name" : "${currNameFilter}"`, + `${currPage}`, + "DESC" + ) ); - } - }} - > - {isLoadingMoreItems ? ( - <CircularProgress size={24} /> - ) : ( - "Carregar mais itens" - )} - </Button> - </StyledTableCell> - </StyledTableRow> - ) : ( - <StyledTableRow key={index}> - <StyledTableCell component="th" scope="row"> - {row.name} - </StyledTableCell> - <StyledTableCell align="right"> - <div dangerouslySetInnerHTML={{ __html: row.description }}> - </div> - </StyledTableCell> - <StyledTableCell align="right"> - { - row.owner === null ? '' : row.owner.name - } - </StyledTableCell> - <StyledTableCell align="right"> - {DisplayDate(row.created_at)} - </StyledTableCell> - <StyledTableCell align="right"> - {DisplayDate(row.updated_at)} - </StyledTableCell> - <StyledTableCell align="right"> - {row.privacy} - </StyledTableCell> - <StyledTableCell align="right"> - <Link to={`/admin/Collection/${row.id}`}> - <IconButton onClick={() => { currPage = 0 }}> - <VisibilityIcon style={{ fill: "#00bcd4" }} /> - </IconButton> - </Link> + }} + > + {isLoadingMoreItems ? ( + <CircularProgress size={24} /> + ) : ( + "Carregar mais itens" + )} + </Button> </StyledTableCell> - <StyledTableCell align="right"> - {isLoadingToDelete === index ? ( - <CircularProgress size={24} color="primary" /> - ) : ( + </StyledTableRow> + ) : ( + <StyledTableRow key={index}> + <StyledTableCell component="th" scope="row"> + {row.name} + </StyledTableCell> + <StyledTableCell align="right"> + <div + dangerouslySetInnerHTML={{ __html: row.description }} + ></div> + </StyledTableCell> + <StyledTableCell align="right"> + {row.owner === null ? "" : row.owner.name} + </StyledTableCell> + <StyledTableCell align="right"> + {DisplayDate(row.created_at)} + </StyledTableCell> + <StyledTableCell align="right"> + {DisplayDate(row.updated_at)} + </StyledTableCell> + <StyledTableCell align="right">{row.privacy}</StyledTableCell> + <StyledTableCell align="right"> + <Link to={`/admin/Collection/${row.id}`}> <IconButton onClick={() => { - HandleStateAlertDialog(index); - HandleStateCircularProgress(index); + currPage = 0; + currPrivacyFilter = ""; + currNameFilter = ""; }} > - <DeleteIcon style={{ fill: "#FF0000" }} /> + <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> - )} - </StyledTableCell> - </StyledTableRow> - ) - )} - </TableBody> - </TableData> - - {/* 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); - }} - /> - </> + </Link> + </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> + + {/* 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); + }} + /> + </> + ); } }; export default Collections; diff --git a/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js b/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js index d38242b3a290b673467fcb8364956ff4c9f782e4..6b346b7559cab49d528347e6da95fafe1d00dfa5 100644 --- a/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js +++ b/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js @@ -91,9 +91,9 @@ const CommunityQuestion = () => { const [showMessageFilter, setShowMessageFilter] = useState(false); const [showEmailFilter, setShowEmailFilter] = useState(false); const [showNameFilter, setShowNameFilter] = useState(false); - const [message, setMessage] = useState(''); - const [email, setEmail] = useState(''); - const [name, setName] = useState(''); + const [message, setMessage] = useState(""); + const [email, setEmail] = useState(""); + const [name, setName] = useState(""); const [snackInfo, setSnackInfo] = useState({ message: "", @@ -103,10 +103,10 @@ const CommunityQuestion = () => { }); //handle with the message filter - const MessageFilterHandler = async (e) => { + const MessageFilterHandler = (e) => { setMessage(e.target.value) getRequest( - Url("contacts", `"message" : "${message}"`, currPage, 'DESC'), + Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : "${name}"`, currPage, 'DESC'), (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -121,7 +121,7 @@ const CommunityQuestion = () => { const EmailFilterHandler = (e) => { setEmail(e.target.value) getRequest( - Url("contacts", `"email" : "${email}"`, currPage, 'DESC'), + Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : "${name}"`, currPage, 'DESC'), (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -136,7 +136,7 @@ const CommunityQuestion = () => { const NameFilterHandler = (e) => { setName(e.target.value) getRequest( - Url("contacts", `"name" : "${name}"`, currPage, 'DESC'), + Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : "${name}"`, currPage, 'DESC'), (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -169,7 +169,7 @@ const CommunityQuestion = () => { const id = open ? 'simple-popover' : undefined; //handle load more items - const LoadMoreItens = async (api) => { + const LoadMoreItens = (api) => { setIsLoadingMoreItems(true) getRequest( api, @@ -198,7 +198,7 @@ const CommunityQuestion = () => { }; // handle update list data - const UpdateHandler = async (api) => { + const UpdateHandler = (api) => { setIsUpdating(true); getRequest( api, @@ -246,7 +246,7 @@ const CommunityQuestion = () => { //getting data from server useEffect(() => { getRequest( - Url("contacts", "", `${currPage}`, "DESC"), + Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : "${name}"`, `${currPage}`, "DESC"), (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -300,7 +300,7 @@ const CommunityQuestion = () => { onClick={() => { currPage = 0; UpdateHandler( - Url("contacts", "", `${currPage}`, "DESC") + Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : "${name}"`, `${currPage}`, "DESC") ); }} startIcon={<UpdateRoundedIcon />} @@ -313,10 +313,6 @@ const CommunityQuestion = () => { variant="contained" color="secondary" onClick={(e) => { - currPage = 0; - UpdateHandler( - Url("contacts", "", `${currPage}`, "DESC") - ); handleClick(e); }} startIcon={<FilterListRoundedIcon />} @@ -372,7 +368,7 @@ const CommunityQuestion = () => { <Grid container justify="space-between" spacing={3}> { showMessageFilter ? - <Grid item> + <Grid item > <TextField label='Mensagem' type="search" @@ -383,8 +379,9 @@ const CommunityQuestion = () => { color="primary" onClick={() => { currPage = 0; + setMessage("") UpdateHandler( - Url("contacts", "", `${currPage}`, "DESC") + Url("contacts", `"message" : "", "email" : "${email}", "name" : "${name}"`, `${currPage}`, "DESC") ); setShowMessageFilter(false) }} @@ -406,8 +403,9 @@ const CommunityQuestion = () => { color="primary" onClick={() => { currPage = 0; + setEmail("") UpdateHandler( - Url("contacts", "", `${currPage}`, "DESC") + Url("contacts", `"message" : "${message}", "email" : "", "name" : "${name}"`, `${currPage}`, "DESC") ); setShowEmailFilter(false) }} @@ -429,8 +427,9 @@ const CommunityQuestion = () => { color="primary" onClick={() => { currPage = 0; + setName("") UpdateHandler( - Url("contacts", "", `${currPage}`, "DESC") + Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : ""`, `${currPage}`, "DESC") ); setShowNameFilter(false) }} @@ -459,23 +458,9 @@ const CommunityQuestion = () => { disabled={isLoadingMoreItems} onClick={() => { currPage++; - if (showMessageFilter) { - LoadMoreItens( - Url("contacts", `"message" : "${message}"`, `${currPage}`, "DESC") - ); - } else if (showEmailFilter) { - LoadMoreItens( - Url("contacts", `"email" : "${email}"`, `${currPage}`, "DESC") - ); - } else if (showNameFilter) { - LoadMoreItens( - Url("contacts", `"name" : "${name}"`, `${currPage}`, "DESC") - ); - } else { - LoadMoreItens( - Url("contacts", "", `${currPage}`, "DESC") - ); - } + LoadMoreItens( + Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : "${name}"`, `${currPage}`, "DESC") + ); }} > {isLoadingMoreItems ? ( @@ -511,12 +496,12 @@ const CommunityQuestion = () => { </Link> : null } </StyledTableCell> - <StyledTableCell align="right"> + <StyledTableCell align="right"> {row.message} </StyledTableCell> <StyledTableCell align="right"> <Link to={`/admin/CommunityQuestion/${row.id}`}> - <IconButton onClick={() => {currPage = 0}}> + <IconButton onClick={() => { currPage = 0 }}> <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> </Link> diff --git a/src/Admin/Pages/Pages/SubPages/Complaints.js b/src/Admin/Pages/Pages/SubPages/Complaints.js index 2375b739e418dc5fa1f24be5a95f4d07ebb05e58..a99d2b8b560e6b9a7b0c888d120f0b81cbf5de51 100644 --- a/src/Admin/Pages/Pages/SubPages/Complaints.js +++ b/src/Admin/Pages/Pages/SubPages/Complaints.js @@ -45,8 +45,9 @@ import { Link } from "react-router-dom"; import Unauthorized from "../../../Components/Components/Unauthorized"; let currPage = 0; -let currIdFilter; -let currTypeFilter; +let currStateFilter = "0" +let currComplainReasonId; +let currDescriptionFilter = ""; const StyledTableCell = withStyles((theme) => ({ head: { @@ -92,7 +93,9 @@ const Complaints = () => { const [showFilter, setShowFilter] = useState(false); - const [option, setOption] = useState("Todos os usuários"); //labels of the text field 'to' + const [stateOption, setStateOption] = useState("Pendente"); + const [complainOption, setComplainOption] = useState(""); + const [description, setDescription] = useState(""); const [snackInfo, setSnackInfo] = useState({ message: "", @@ -195,18 +198,69 @@ const Complaints = () => { ) }; - const handleChange = (e, type) => { + const handleChangeState = (e, type) => { const value = e.target.value; - console.log(e); - setOption(value); + setStateOption(value); }; - const ApplyFilter = (id, type) => { + const handleChangeComplain = (e, type) => { + const value = e.target.value; + setComplainOption(value); + }; + + const ApplyFilterState = (id, type) => { currPage = 0; - currIdFilter = id; - currTypeFilter = type; + currStateFilter = id; + let url; + if (currComplainReasonId) { + url = Url("complaints", + `"state" : "${currStateFilter}", "complaint_reason_id" : "${currComplainReasonId}", "description" : "${currDescriptionFilter}"`, + `${currPage}`, + "DESC" + ) + } + else { + url = Url("complaints", + `"state" : "${currStateFilter}", "description" : "${currDescriptionFilter}"`, + `${currPage}`, + "DESC" + ) + } getRequest( - Url("complaints", `"${currTypeFilter}" : "${currIdFilter}"`, `${currPage}`, "DESC"), + url, + (data, header) => { + const arrData = [...data]; + setItems(arrData.concat(ADD_ONE_LENGHT)); + HandleSnack("Filtro aplicado com sucesso", true, "success", "#228B22"); + setIsLoaded(true); + }, + (error) => { + HandleSnack("Erro ao carregar os dados", true, "warning", "#FA8072"); + setIsLoaded(true); + } + ) + }; + + const ApplyFilterComplainReason = (id, type) => { + currPage = 0; + currComplainReasonId = id; + let url; + if (currComplainReasonId) { + url = Url("complaints", + `"state" : "${currStateFilter}", "complaint_reason_id" : "${currComplainReasonId}", "description" : "${currDescriptionFilter}"`, + `${currPage}`, + "DESC" + ) + } + else { + url = Url("complaints", + `"state" : "${currStateFilter}", "description" : "${currDescriptionFilter}"`, + `${currPage}`, + "DESC" + ) + } + getRequest( + url, (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -222,10 +276,25 @@ const Complaints = () => { const DescriptionHandler = (e) => { currPage = 0; - currTypeFilter = "description"; - currIdFilter = e.target.value; + currDescriptionFilter = e.target.value; + setDescription(currDescriptionFilter) + let url; + if (currComplainReasonId) { + url = Url("complaints", + `"state" : "${currStateFilter}", "complaint_reason_id" : "${currComplainReasonId}", "description" : "${currDescriptionFilter}"`, + `${currPage}`, + "DESC" + ) + } + else { + url = Url("complaints", + `"state" : "${currStateFilter}", "description" : "${currDescriptionFilter}"`, + `${currPage}`, + "DESC" + ) + } getRequest( - Url("complaints", `"${currTypeFilter}" : "${currIdFilter}"`, `${currPage}`, "DESC"), + url, (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -311,7 +380,7 @@ const Complaints = () => { //getting data from server useEffect(() => { getRequest( - Url("complaints", "", `${currPage}`, "DESC"), + Url("complaints", `"state" : "${currStateFilter}"`, `${currPage}`, "DESC"), (data, header) => { const arrData = [...data]; setItems(arrData.concat(ADD_ONE_LENGHT)); @@ -366,9 +435,24 @@ const Complaints = () => { disabled={isUpdating} onClick={() => { currPage = 0; - UpdateHandler( - Url("complaints", "", `${currPage}`, "DESC") - ); + if (currComplainReasonId) { + UpdateHandler( + Url("complaints", + `"state" : "${currStateFilter}", "complaint_reason_id" : "${currComplainReasonId}", "description" : "${currDescriptionFilter}"`, + `${currPage}`, + "DESC" + ) + ); + } + else { + UpdateHandler( + Url("complaints", + `"state" : "${currStateFilter}", "description" : "${currDescriptionFilter}"`, + `${currPage}`, + "DESC" + ) + ); + } }} startIcon={<UpdateRoundedIcon />} > @@ -380,10 +464,6 @@ const Complaints = () => { variant="contained" color="secondary" onClick={() => { - currPage = 0; - UpdateHandler( - Url("complaints", "", `${currPage}`, "DESC") - ); setShowFilter(!showFilter); }} startIcon={<FilterListRoundedIcon />} @@ -409,8 +489,8 @@ const Complaints = () => { <TextField select label="Motivo" - value={option ? option : ""} - onChange={handleChange} + value={complainOption} + onChange={handleChangeComplain} helperText="Por favor, selecione uma das opções" > {ComplaintReasons.map((option, index) => ( @@ -419,7 +499,7 @@ const Complaints = () => { value={option.name} name={option.id} onClick={() => - ApplyFilter(option.id, "complaint_reason_id") + ApplyFilterComplainReason(option.id, "complaint_reason_id") } > {option.name} @@ -431,8 +511,8 @@ const Complaints = () => { <TextField select label="Estado" - value={option ? option : ""} - onChange={handleChange} + value={stateOption} + onChange={handleChangeState} helperText="Por favor, selecione uma das opções" > {StateOptions.map((option, index) => ( @@ -440,7 +520,7 @@ const Complaints = () => { key={option.id} value={option.name} name={option.id} - onClick={() => ApplyFilter(option.id, "state")} + onClick={() => ApplyFilterState(option.id, "state")} > {option.name} </MenuItem> @@ -448,7 +528,7 @@ const Complaints = () => { </TextField> </Grid> <Grid item> - <TextField label="Descrição" onBlur={DescriptionHandler} /> + <TextField label="Descrição" onChange={DescriptionHandler} value={description} /> </Grid> </Grid> ) : null} @@ -472,18 +552,22 @@ const Complaints = () => { disabled={isLoadingMoreItems} onClick={() => { currPage++; - if (showFilter) { + if (currComplainReasonId) { LoadMoreItens( - Url( - "complaints", - `"${currTypeFilter}" : "${currIdFilter}"`, + Url("complaints", + `"state" : "${currStateFilter}", "complaint_reason_id" : "${currComplainReasonId}", "description" : "${currDescriptionFilter}"`, `${currPage}`, "DESC" ) ); - } else { + } + else { LoadMoreItens( - Url("complaints", "", `${currPage}`, "DESC") + Url("complaints", + `"state" : "${currStateFilter}", "description" : "${currDescriptionFilter}"`, + `${currPage}`, + "DESC" + ) ); } }} @@ -520,7 +604,12 @@ const Complaints = () => { <StyledTableCell align="right"> <Link to={`/admin/complaint/${row.id}`}> <IconButton - onClick={() => { currPage = 0 }} + onClick={() => { + currPage = 0 + currStateFilter = "0" + currDescriptionFilter = "" + currComplainReasonId = null; + }} > <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js index 3dab65449433f0d10c02a803cd0dbd4742bf039c..e22a367f10e7fb4be02d42e3be5752714c78d915 100644 --- a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js +++ b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js @@ -114,18 +114,36 @@ const EducationalObjects = () => { const [search, setSeacrh] = useState(""); const [author, setAuthor] = useState(""); - const [description, setDescription] = useState(""); + const [description, setDescription] = useState(null); const AuthorHandler = () => { + setAuthor("") setShowAuthorField(!showAuthorField); + let url; + if (description) + url = Url("learning_objects", `"name" : "${search}", "author" : "", "description" : "${description}"`, currPage, "DESC") + else + url = Url("learning_objects", `"name" : "${search}", "author" : ""`, currPage, "DESC") + Filter(url); }; const DescHandler = () => { + setDescription(null) setShowDescriptionField(!showDescriptionField); + let url; + url = Url("learning_objects", `"name" : "${search}", "author" : "${author}"`, currPage, "DESC") + Filter(url); }; const StandartHandler = () => { + setSeacrh("") setShowStandarSearchField(!showStandadSearch); + let url; + if (description) + url = Url("learning_objects", `"name" : "", "author" : "${author}", "description" : "${description}"`, currPage, "DESC") + else + url = Url("learning_objects", `"name" : "", "author" : "${author}"`, currPage, "DESC") + Filter(url); }; const handleClick = (event) => { @@ -141,17 +159,32 @@ const EducationalObjects = () => { const OnChangeSearchHandler = (e) => { setSeacrh(e.target.value); - Filter(Url("learning_objects", `"name" : "${search}"`, currPage, "DESC")); + let url; + if (description) + url = Url("learning_objects", `"name" : "${search}", "author" : "${author}", "description" : "${description}"`, currPage, "DESC") + else + url = Url("learning_objects", `"name" : "${search}", "author" : "${author}"`, currPage, "DESC") + Filter(url); }; const onChangeAuthorHandler = (e) => { setAuthor(e.target.value); - Filter(Url("learning_objects", `"author" : "${author}"`, currPage, "DESC")); + let url; + if (description) + url = Url("learning_objects", `"name" : "${search}", "author" : "${author}", "description" : "${description}"`, currPage, "DESC") + else + url = Url("learning_objects", `"name" : "${search}", "author" : "${author}"`, currPage, "DESC") + Filter(url); }; const onChangeDescriptionHandler = (e) => { setDescription(e.target.value); - Filter(Url("learning_objects", `"description" : "${description}"`, currPage, "DESC")); + let url; + if (description) + url = Url("learning_objects", `"name" : "${search}", "author" : "${author}", "description" : "${description}"`, currPage, "DESC") + else + url = Url("learning_objects", `"name" : "${search}", "author" : "${author}"`, currPage, "DESC") + Filter(url); }; // **************** About the PopOverMenu **************** @@ -277,7 +310,7 @@ const EducationalObjects = () => { useEffect(() => { getRequest( - Url("learning_objects", "", `${currPage}`, "DESC"), + Url("learning_objects", `"name" : "${search}", "author" : "${author}"`, `${currPage}`, "DESC"), (data, header) => { setIsLoaded(true); setItems(data.concat(addOndeLenght)); @@ -383,8 +416,6 @@ const EducationalObjects = () => { color="secondary" className={classes.button} onClick={(event) => { - currPage = 0; - UpdtateListData(Url("learning_objects", "", `${currPage}`, "DESC")); handleClick(event) }} startIcon={ @@ -429,9 +460,10 @@ const EducationalObjects = () => { onClick={() => { currPage = 0; setIsUpdating(true); - UpdtateListData( - Url("learning_objects", "", `${currPage}`, "DESC") - ); + if (description) + UpdtateListData(Url("learning_objects", `"name" : "${search}", "author" : "${author}", "description" : "${description}"`, currPage, "DESC")) + else + UpdtateListData(Url("learning_objects", `"name" : "${search}", "author" : "${author}"`, currPage, "DESC")) }} > {isUpdating ? <CircularProgress size={24} /> : "Atualizar"} @@ -487,10 +519,10 @@ const EducationalObjects = () => { } onClick={() => { currPage++ - if (showAuthorField) LoadMoreItens(Url("learning_objects", `"author" : "${author}"`, currPage, "DESC")) - else if (showDescriptionField) LoadMoreItens(Url("learning_objects", `"description" : "${description}"`, currPage, "DESC")) - else if (showStandadSearch) LoadMoreItens(Url("learning_objects", `"name" : "${search}"`, currPage, "DESC")) - else LoadMoreItens(Url('learning_objects', '', `${currPage}`, 'DESC')) + if (description) + LoadMoreItens(Url("learning_objects", `"name" : "${search}", "author" : "${author}", "description" : "${description}"`, currPage, "DESC")) + else + LoadMoreItens(Url("learning_objects", `"name" : "${search}", "author" : "${author}"`, currPage, "DESC")) }} > {isLoadingMoreItems ? ( @@ -522,6 +554,7 @@ const EducationalObjects = () => { <Link to={`/admin/learningObject/${row.id}`}> <IconButton onClick={() => { currPage = 0 + }}> <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/Users.js b/src/Admin/Pages/Pages/SubPages/Users.js index 9846c5efe682aeb2b2238993ebcfac0efce536c2..a02851e02f956ea3e93ed6e6bd62736acfa40211 100644 --- a/src/Admin/Pages/Pages/SubPages/Users.js +++ b/src/Admin/Pages/Pages/SubPages/Users.js @@ -424,7 +424,14 @@ const Users = () => { </StyledTableCell> <StyledTableCell align="right"> <Link to={`/admin/user/${row.id}`}> - <IconButton onClick={() => { currPage = 0; transformListToAsc = false }}> + <IconButton onClick={() => + { + currPage = 0; + transformListToAsc = false + nameFilter = "" + emailFilter = "" + } + }> <VisibilityIcon style={{ fill: '#00bcd4' }} /> </IconButton> </Link>