diff --git a/src/Admin/Components/Components/DataCards/CollectionCard.js b/src/Admin/Components/Components/DataCards/CollectionCard.js index e558eb752782189870a0fa8ccf0c1345ff645864..79773d75017ce2eb1f5084677f6e7b0df2675791 100644 --- a/src/Admin/Components/Components/DataCards/CollectionCard.js +++ b/src/Admin/Components/Components/DataCards/CollectionCard.js @@ -29,19 +29,27 @@ import { useStyles } from "../../Styles/DataCard"; import Grid from '@material-ui/core/Grid'; // Icons import EditRoundedIcon from "@material-ui/icons/EditRounded"; +import DeleteRoundedIcon from "@material-ui/icons/DeleteRounded"; //imports from local files -import { GetAData } from "../../../Filters"; -import { Link } from 'react-router-dom' +import { GetAData, DeleteFilter } from "../../../Filters"; +import { Link, useHistory } from 'react-router-dom' import LoadingSpinner from '../../../../Components/LoadingSpinner'; -import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig'; +import SnackBar from '../../../../Components/SnackbarComponent'; +import { getRequest, deleteRequest } from '../../../../Components/HelperFunctions/getAxiosConfig'; const CollectionCard = ({ match }) => { - console.log(match); + let history = useHistory() const classes = useStyles(); 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 [item, setItem] = useState({}); //Necessary to consult the API, data + const [snackInfo, setSnackInfo] = useState({ + message: "", + icon: "", + open: false, + color: "", + }); const DisplayDate = (date) => { const convertedData = moment.utc(date); @@ -50,6 +58,40 @@ const CollectionCard = ({ match }) => { .toString(); }; + const HandleSnack = (message, state, icon, color) => { + setSnackInfo({ + message: message, + icon: icon, + open: state, + color: color, + }); + }; + + + //Called when user want to delete one institution + async function DeleteHandler() { + const id = match.params.id + deleteRequest( + DeleteFilter("collections", id), + (data) => { + if (data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else { + HandleSnack( + "A Coleção foi deletada com sucesso", + true, + "success", + "#228B22" + ); + history.goBack() + } + }, + (error) => { + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + } + ); + } + useEffect(() => { getRequest( GetAData("collections", match.params.id), @@ -107,6 +149,18 @@ const CollectionCard = ({ match }) => { return ( <Card> + <SnackBar + severity={snackInfo.icon} + text={snackInfo.message} + snackbarOpen={snackInfo.open} + color={snackInfo.color} + handleClose={() => setSnackInfo({ + message: '', + icon: '', + open: false, + color: '' + })} + /> <CardContent> <Grid xs={12} justify="space-between" alignItems="center" container> <Grid item> @@ -138,6 +192,15 @@ const CollectionCard = ({ match }) => { Editar </Button> </Link> + + <Button + startIcon={<DeleteRoundedIcon />} + color="secondary" + variant="outlined" + onClick={DeleteHandler} + > + Deletar + </Button> </ButtonGroup> </Grid> </Grid> diff --git a/src/Admin/Components/Components/DataCards/EducationalObjectsCard.js b/src/Admin/Components/Components/DataCards/EducationalObjectsCard.js index de37dc845cc7c9e5dd4b61dab06d16e596dd611d..8f78633dd111ab871b73152746ea09cca842b646 100644 --- a/src/Admin/Components/Components/DataCards/EducationalObjectsCard.js +++ b/src/Admin/Components/Components/DataCards/EducationalObjectsCard.js @@ -29,16 +29,19 @@ import VisibilityIcon from "@material-ui/icons/Visibility"; import EditRoundedIcon from '@material-ui/icons/EditRounded'; import ButtonGroup from "@material-ui/core/ButtonGroup"; import { useStyles } from "../../Styles/DataCard"; +import DeleteRoundedIcon from "@material-ui/icons/DeleteRounded"; //imports from local files -import { GetAData } from "../../../Filters"; -import { Link } from "react-router-dom"; +import { GetAData, DeleteFilter } from "../../../Filters"; +import { Link, useHistory } from "react-router-dom"; import { apiUrl, apiDomain } from "../../../../env"; import { Grid } from "@material-ui/core"; import LoadingSpinner from '../../../../Components/LoadingSpinner'; -import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' +import { getRequest, deleteRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' +import SnackBar from '../../../../Components/SnackbarComponent'; const CommunityQuestions = ({ match }) => { const classes = useStyles(); + let history = useHistory() 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 @@ -51,6 +54,45 @@ const CommunityQuestions = ({ match }) => { .toString(); }; + const HandleSnack = (message, state, icon, color) => { + setSnackInfo({ + message: message, + icon: icon, + open: state, + color: color, + }); + }; + + const [snackInfo, setSnackInfo] = useState({ + message: "", + icon: "", + open: false, + color: "", + }); + + async function DeleteHandler() { + const id = match.params.id + deleteRequest( + DeleteFilter("learning_objects", id), + (data) => { + if (data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else { + HandleSnack( + "O objeto educacional foi deletada com sucesso", + true, + "success", + "#228B22" + ); + history.goBack() + } + }, + (error) => { + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + } + ); + } + useEffect(() => { getRequest( GetAData("learning_objects", match.params.id), @@ -69,7 +111,7 @@ const CommunityQuestions = ({ match }) => { if (error) { return <div>Houve um erro</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> + return <LoadingSpinner text="Carregando..." /> } else { console.log(item); const DATA = [ @@ -163,6 +205,18 @@ const CommunityQuestions = ({ match }) => { 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> <Grid container @@ -224,6 +278,14 @@ const CommunityQuestions = ({ match }) => { Editar </Button> </Link> + <Button + startIcon={<DeleteRoundedIcon />} + color="secondary" + variant="outlined" + onClick={DeleteHandler} + > + Deletar + </Button> </ButtonGroup> </Grid> </Grid> diff --git a/src/Admin/Components/Components/DataCards/InstitutionsCard.js b/src/Admin/Components/Components/DataCards/InstitutionsCard.js index 1c2e1b7deb680d3e404cb50cae594a6b5d623da8..520bd316e9445f732b48bf77e769474ed8366190 100644 --- a/src/Admin/Components/Components/DataCards/InstitutionsCard.js +++ b/src/Admin/Components/Components/DataCards/InstitutionsCard.js @@ -29,16 +29,17 @@ import { useStyles } from "../../Styles/DataCard"; import Grid from '@material-ui/core/Grid'; // Icons import EditRoundedIcon from "@material-ui/icons/EditRounded"; +import DeleteRoundedIcon from "@material-ui/icons/DeleteRounded"; //imports from local files -import { GetAData } from "../../../Filters"; -import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' -import { Store } from '../../../../Store'; -import { Link } from 'react-router-dom'; +import { GetAData, DeleteFilter } from "../../../Filters"; +import { getRequest, deleteRequest } from '../../../../Components/HelperFunctions/getAxiosConfig'; +import { Link, useHistory } from 'react-router-dom'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; +import SnackBar from '../../../../Components/SnackbarComponent'; const InstitutionCard = ({ match }) => { const classes = useStyles(); - + let history = useHistory() 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 @@ -51,6 +52,45 @@ const InstitutionCard = ({ match }) => { .toString(); }; + const HandleSnack = (message, state, icon, color) => { + setSnackInfo({ + message: message, + icon: icon, + open: state, + color: color, + }); + }; + + const [snackInfo, setSnackInfo] = useState({ + message: "", + icon: "", + open: false, + color: "", + }); + + async function DeleteHandler() { + const id = match.params.id + deleteRequest( + DeleteFilter("institutions", id), + (data) => { + if (data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else { + HandleSnack( + "A instituição foi deletada com sucesso", + true, + "success", + "#228B22" + ); + history.goBack() + } + }, + (error) => { + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + } + ); + } + useEffect(() => { getRequest( GetAData('institutions', match.params.id), @@ -107,6 +147,18 @@ const InstitutionCard = ({ match }) => { return ( <Card> + <SnackBar + severity={snackInfo.icon} + text={snackInfo.message} + snackbarOpen={snackInfo.open} + color={snackInfo.color} + handleClose={() => setSnackInfo({ + message: '', + icon: '', + open: false, + color: '' + })} + /> <CardContent> <Grid container xs={12} justify="space-between" alignItems="center" alignContent="center"> <Grid item> @@ -138,6 +190,15 @@ const InstitutionCard = ({ match }) => { Editar </Button> </Link> + + <Button + startIcon={<DeleteRoundedIcon />} + color="secondary" + variant="outlined" + onClick={DeleteHandler} + > + Deletar + </Button> </ButtonGroup> </Grid> </Grid> diff --git a/src/Admin/Components/Components/DataCards/RatingCard.js b/src/Admin/Components/Components/DataCards/RatingCard.js index ee1f89645bee26cb2852cba9b413be365940eaf0..82585c189a8f5d15d53729b7d33bd87996ccacd4 100644 --- a/src/Admin/Components/Components/DataCards/RatingCard.js +++ b/src/Admin/Components/Components/DataCards/RatingCard.js @@ -29,18 +29,27 @@ import Grid from "@material-ui/core/Grid"; import { useStyles } from "../../Styles/DataCard"; // Icons import EditRoundedIcon from "@material-ui/icons/EditRounded"; +import DeleteRoundedIcon from "@material-ui/icons/DeleteRounded"; //imports from local files -import { GetAData } from "../../../Filters"; -import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' -import { Link } from 'react-router-dom'; -import LoadingSpinner from '../../../../Components/LoadingSpinner';; +import { GetAData, DeleteFilter } from "../../../Filters"; +import { getRequest, deleteRequest } from '../../../../Components/HelperFunctions/getAxiosConfig'; +import { Link, useHistory } from 'react-router-dom'; +import LoadingSpinner from '../../../../Components/LoadingSpinner'; +import SnackBar from '../../../../Components/SnackbarComponent'; const RatingCard = ({ match }) => { const classes = useStyles(); + let history = useHistory() 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 [item, setItem] = useState({}); //Necessary to consult the API, data + const [snackInfo, setSnackInfo] = useState({ + message: "", + icon: "", + open: false, + color: "", + }); const DisplayDate = (date) => { const convertedData = moment.utc(date); @@ -49,6 +58,40 @@ const RatingCard = ({ match }) => { .toString(); }; + + const HandleSnack = (message, state, icon, color) => { + setSnackInfo({ + message: message, + icon: icon, + open: state, + color: color, + }); + }; + + async function DeleteHandler() { + const id = match.params.id + deleteRequest( + DeleteFilter("ratings", id), + (data) => { + if (data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else { + HandleSnack( + "O rating foi deletada com sucesso", + true, + "success", + "#228B22" + ); + history.goBack() + } + }, + (error) => { + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + } + ); + } + + useEffect(() => { getRequest( GetAData('ratings', match.params.id), @@ -93,6 +136,18 @@ const RatingCard = ({ match }) => { 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> <Grid container xs={12} justify="space-between" alignItems="center" alignContent="center"> <Grid item> @@ -124,6 +179,15 @@ const RatingCard = ({ match }) => { Editar </Button> </Link> + + <Button + startIcon={<DeleteRoundedIcon />} + color="secondary" + variant="outlined" + onClick={DeleteHandler} + > + Deletar + </Button> </ButtonGroup> </Grid> </Grid> diff --git a/src/Admin/Components/Components/Inputs/EditLanguage.js b/src/Admin/Components/Components/Inputs/EditLanguage.js index 431b156c78e73bd3fd68a7322eb0c05dce7839de..a099bf35cd7bf6fda69bebdc4d6c2f92d3ac0501 100644 --- a/src/Admin/Components/Components/Inputs/EditLanguage.js +++ b/src/Admin/Components/Components/Inputs/EditLanguage.js @@ -18,7 +18,7 @@ along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/> import React, { useState, useEffect, useContext } from 'react'; //imports material ui components -import { Typography, TextField, Button, Grid } from '@material-ui/core'; +import { Typography, TextField, Button, Grid, ButtonGroup } from '@material-ui/core'; import CircularProgress from '@material-ui/core/CircularProgress'; import Card from "@material-ui/core/Card"; import CardContent from "@material-ui/core/CardContent"; @@ -30,14 +30,16 @@ import SnackBar from '../../../../Components/SnackbarComponent'; import { Store } from '../../../../Store'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; //imports services -import { getRequest, putRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' -import { EditFilter, GetAData } from '../../../Filters'; +import { getRequest, putRequest, deleteRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' +import { EditFilter, GetAData, DeleteFilter } from '../../../Filters'; +import DeleteRoundedIcon from "@material-ui/icons/DeleteRounded"; //routers -import { Link } from 'react-router-dom'; +import { Link, useHistory } from 'react-router-dom'; import Unauthorized from '../Unauthorized'; const EditLanguage = ({ match }) => { const { state, dispatch } = useContext(Store); + let history = useHistory() 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 @@ -64,6 +66,29 @@ const EditLanguage = ({ match }) => { color: '', }) + async function DeleteHandler() { + const id = match.params.id + deleteRequest( + DeleteFilter("languages", id), + (data) => { + if (data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else { + HandleSnack( + "A lÃngua foi deletada com sucesso", + true, + "success", + "#228B22" + ); + history.push("/admin/languages") + } + }, + (error) => { + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + } + ); + } + const NameHandler = (e) => { if (errorInName.error) { setErrorInName({ @@ -230,15 +255,25 @@ const EditLanguage = ({ match }) => { <Typography variant='h4'> {name} </Typography> - <Link style={{ textDecoration: 'none' }} to={'/admin/languages'}> + <ButtonGroup> + <Link style={{ textDecoration: 'none' }} to={'/admin/languages'}> + <Button + startIcon={<ListRoundedIcon />} + variant='outlined' + color='primary' + > + Listar + </Button> + </Link> <Button - startIcon={<ListRoundedIcon />} - variant='outlined' - color='primary' + startIcon={<DeleteRoundedIcon />} + color="secondary" + variant="outlined" + onClick={DeleteHandler} > - Listar - </Button> - </Link> + Deletar + </Button> + </ButtonGroup> </Grid> <div style={{ height: '1em' }}></div> diff --git a/src/Admin/Components/Components/Inputs/EditRoles.js b/src/Admin/Components/Components/Inputs/EditRoles.js index 55e4aa00cb7fc030b291ef40ec7d7c51568d19ec..68dc00133f86b99b983d86ed8c1f2b8bd22181f8 100644 --- a/src/Admin/Components/Components/Inputs/EditRoles.js +++ b/src/Admin/Components/Components/Inputs/EditRoles.js @@ -25,19 +25,22 @@ import CardContent from "@material-ui/core/CardContent"; import CardAction from '@material-ui/core/CardActions'; import ListRoundedIcon from '@material-ui/icons/ListRounded'; import SaveIcon from '@material-ui/icons/Save'; +import ButtonGroup from "@material-ui/core/ButtonGroup"; +import DeleteRoundedIcon from "@material-ui/icons/DeleteRounded"; //imports local files import SnackBar from '../../../../Components/SnackbarComponent'; import { Store } from '../../../../Store'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; //imports services -import { getRequest, putRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' -import { EditFilter, GetAData } from '../../../Filters'; +import { getRequest, putRequest, deleteRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' +import { EditFilter, GetAData, DeleteFilter } from '../../../Filters'; //routers -import { Link } from 'react-router-dom'; +import { Link, useHistory } from 'react-router-dom'; import Unauthorized from '../Unauthorized'; const EditLanguage = ({ match }) => { const { state, dispatch } = useContext(Store); + let history = useHistory() 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 @@ -46,6 +49,22 @@ const EditLanguage = ({ match }) => { const id = match.params.id const [name, setName] = useState() const [desc, setDesc] = useState() + const [snackInfo, setSnackInfo] = useState({ + message: "", + icon: "", + open: false, + color: "", + }); + + + const HandleSnack = (message, state, icon, color) => { + setSnackInfo({ + message: message, + icon: icon, + open: state, + color: color, + }); + }; const [errorInName, setErrorInName] = useState({ error: false, @@ -57,13 +76,6 @@ const EditLanguage = ({ match }) => { message: '' }) - const [snackInfo, setSnackInfo] = useState({ - message: '', - icon: '', - open: false, - color: '', - }) - const NameHandler = (e) => { if (errorInName.error) { setErrorInName({ @@ -118,16 +130,6 @@ const EditLanguage = ({ match }) => { }, ] - // Handle snack infos - const HandleSnack = (message, state, icon, color) => { - setSnackInfo({ - message: message, - icon: icon, - open: state, - color: color - }) - } - const CheckUserPermission = () => { let canUserEdit = false; @@ -182,6 +184,29 @@ const EditLanguage = ({ match }) => { ) } + async function DeleteHandler() { + const id = match.params.id + deleteRequest( + DeleteFilter("roles", id), + (data) => { + if (data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else { + HandleSnack( + "A permissão foi deletada com sucesso", + true, + "success", + "#228B22" + ); + history.goBack() + } + }, + (error) => { + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + } + ); + } + useEffect(() => { getRequest( GetAData("roles", match.params.id), @@ -221,15 +246,25 @@ const EditLanguage = ({ match }) => { <Typography variant='h4'> {name} </Typography> - <Link style={{ textDecoration: 'none' }} to={'/admin/permissions'}> + <ButtonGroup> + <Link style={{ textDecoration: 'none' }} to={'/admin/permissions'}> + <Button + startIcon={<ListRoundedIcon />} + variant='outlined' + color='primary' + > + Listar + </Button> + </Link> <Button - startIcon={<ListRoundedIcon />} - variant='outlined' - color='primary' + startIcon={<DeleteRoundedIcon />} + color="secondary" + variant="outlined" + onClick={DeleteHandler} > - Listar + Deletar </Button> - </Link> + </ButtonGroup> </Grid> <div style={{ height: '1em' }}></div> diff --git a/src/Admin/Components/Components/Inputs/EmailInputs.js b/src/Admin/Components/Components/Inputs/EmailInputs.js index 646bdbebca9bfda683e335f478fba4c4b501d7ec..8790e927f9ff46fb0ebaf4a84e805a5c15319d0f 100644 --- a/src/Admin/Components/Components/Inputs/EmailInputs.js +++ b/src/Admin/Components/Components/Inputs/EmailInputs.js @@ -168,7 +168,7 @@ const EmailInputs = (props) => { const EmailsHandler = (e) => { if (errorInEmails.error) - setErrorInSubject({ + setErrorInEmail({ error: false, message: "", }); @@ -193,11 +193,6 @@ const EmailInputs = (props) => { arr.push(emails); setEmails(""); setEmailsAdress(arr); - setErrorInEmail({ - error: false, - message: "", - arroba: false, - }); } else { setErrorInEmail({ error: true, @@ -373,7 +368,7 @@ const EmailInputs = (props) => { <li key={index} style={{ listStyleType: "none", marginBottom: "0.5em" }}> <Chip label={email} - onDelete={HandleDelete} + onDelete={() => HandleDelete(index)} classes={classes.chip} /> </li>