diff --git a/src/Admin/Components/Components/DataCards/ComplaintsCard.js b/src/Admin/Components/Components/DataCards/ComplaintsCard.js index 428284cfd08c5b563a19576d9989c68c422d5b1b..d079c8148176da7d432259a2aa95c16ed2bb437b 100644 --- a/src/Admin/Components/Components/DataCards/ComplaintsCard.js +++ b/src/Admin/Components/Components/DataCards/ComplaintsCard.js @@ -37,6 +37,7 @@ import DialogActions from '@material-ui/core/DialogActions'; import DialogContent from '@material-ui/core/DialogContent'; import DialogContentText from '@material-ui/core/DialogContentText'; import DialogTitle from '@material-ui/core/DialogTitle'; +import VisibilityIcon from "@material-ui/icons/Visibility"; import CircularProgress from '@material-ui/core/CircularProgress'; //imports from local files import { GetAData, MethodsToComplain } from "../../../Filters"; @@ -45,7 +46,7 @@ import { CardActions } from "@material-ui/core"; import { apiDomain } from '../../../../env'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; import SnackBar from '../../../../Components/SnackbarComponent'; -import { getRequest, postRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' +import { getRequest, postRequest, putRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' //styles const PORTAL_MEC = "https://plataformaintegrada.mec.gov.br/"; @@ -108,7 +109,7 @@ const CollectionCard = ({ match }) => { (data, header) => { HandleContentModal(data); setComplainedObject(data) - setLoadingObject(false); + setLoadingObject(false); }, (error) => { HandleContentModal(); @@ -121,7 +122,7 @@ const CollectionCard = ({ match }) => { } }; - const ComplaintStatus = (status) => { + const ComplaintStatus = (status, type) => { switch (status) { case "accepted": return ( @@ -135,7 +136,9 @@ const CollectionCard = ({ match }) => { color: "#FFFAFA", }} > - REMOVIDO + { + type === "User" ? "BLOQUEADO" : "REMOVIDO" + } </Paper> ); case "complained": @@ -173,92 +176,257 @@ const CollectionCard = ({ match }) => { } }; - const Actions = (status) => { + const reloadData = () => { + setIsLoaded(false) + getRequest( + GetAData("complaints", match.params.id), + (data, header) => { + setItem(data) + setIsLoaded(true); + setError(false); + }, + (error) => { + setError(true); + } + ) + } + + const HandleComplainUser = (option) => { + const body = { + "option": option ? option : null, + "complaints": [ + { + "id": item.id, + "state": option ? "accept" : "reject" + } + + ] + } + postRequest( + `/complaints/${item.complainable_id}/treat_related`, + body, + (data) => { + if (data.errors) + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + else { + HandleSnack('Alteração feito com sucesso!', true, 'success', '#228B22') + reloadData() + } + }, + (error) => { + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + } + ) + } + + const Actions = (status, type) => { switch (status) { - case "accepted": - return ( - "Este recurso já foi avaliado" - ); case "complained": return ( - <> - <Grid - container - className={classes.marginTop} - direction="row" - justify="space-between" - alignItems="center" - > - <Grid item> - <Typography - color="initial" - className={classes.subTitle} - variant="h6" + type === "User" ? + <Grid container spacing={2}> + <Grid item xs={12} spacing={2}> + <Button + style={{ + width: "100%", + color: "#FFFAFA", + backgroundColor: "#FFA07A", + fontWeight: "500", + }} + variant="contained" + onClick={() => { + HandleComplainUser() + }} > - Remover o recurso e notificar o autor - </Typography> + Recusar + </Button> </Grid> - <Grid item> + <Grid item xs={12}> <Button style={{ + width: "100%", color: "#FFFAFA", backgroundColor: "#FA8072", fontWeight: "500", }} variant="contained" - onClick={() => HandleComplainSubmmit("accept")} - startIcon={ - <RemoveRoundedIcon style={{ fill: "#FFFAFA" }} /> - } + onClick={() => { + HandleComplainUser("blocked") + }} > - Remover + Bloqueio semanal </Button> </Grid> - </Grid> - - <Divider className={classes.marginTop} /> - - <Grid - container - className={classes.marginTop} - direction="row" - justify="space-between" - alignItems="center" - > - <Grid item> - <Typography - color="initial" - className={classes.subTitle} - variant="h6" - > - Reativar o recurso na plataforma - </Typography> - </Grid> - <Grid item> + <Grid item xs={12}> <Button style={{ + width: "100%", color: "#FFFAFA", - backgroundColor: "#228B22", + backgroundColor: "red", fontWeight: "500", }} variant="contained" - onClick={() => HandleComplainSubmmit("reject")} - startIcon={ - <RestoreRoundedIcon style={{ fill: "#FFFAFA" }} /> - } + onClick={() => { + HandleComplainUser("banished") + }} > - Ativar + Bloqueio permanente </Button> </Grid> </Grid> - </> + : + <> + <Grid + container + className={classes.marginTop} + direction="row" + justify="space-between" + alignItems="center" + > + <Grid item> + <Typography + color="initial" + className={classes.subTitle} + variant="h6" + > + Remover o recurso e notificar o autor + </Typography> + </Grid> + <Grid item> + <Button + style={{ + color: "#FFFAFA", + backgroundColor: "#FA8072", + fontWeight: "500", + }} + variant="contained" + onClick={() => HandleComplainObj("accept")} + startIcon={ + <RemoveRoundedIcon style={{ fill: "#FFFAFA" }} /> + } + > + Remover + </Button> + </Grid> + </Grid> + + <Divider className={classes.marginTop} /> + + <Grid + container + className={classes.marginTop} + direction="row" + justify="space-between" + alignItems="center" + > + <Grid item> + <Typography + color="initial" + className={classes.subTitle} + variant="h6" + > + Reativar o recurso na plataforma + </Typography> + </Grid> + <Grid item> + <Button + style={{ + color: "#FFFAFA", + backgroundColor: "#228B22", + fontWeight: "500", + }} + variant="contained" + onClick={() => HandleComplainObj("reject")} + startIcon={ + <RestoreRoundedIcon style={{ fill: "#FFFAFA" }} /> + } + > + Ativar + </Button> + </Grid> + </Grid> + </> ); - case "rejected": + default: + return "Essa denúncia já foi avaliado!"; + } + } + + const DisplayButtonsArea = (type) => { + switch (type) { + case "User": return ( - "Este recurso já foi avaliado" - ); + <CardActions> + <Link to={`/admin/user/${item.complainable_id}`}> + <Button + variant="contained" + color="primary" + startIcon={<VisibilityIcon />} + > + Visualizar usuário + </Button> + </Link> + <Button + style={{ + fontWeight: "500", + backgroundColor: "#FA8072" + }} + variant="contained" + startIcon={<LaunchRoundedIcon style={{ fill: "#FFFAFA" }} />} + > + <a + style={{ textDecoration: "none", color: "#FFFAFA" }} + target="_blank" + href={ + PORTAL_MEC + + convertToLink( + item.complainable_type, + item.complainable_id + ) + } + > + MEC RED + </a> + </Button> + </CardActions> + ) + break; default: - return "NOTHING"; + return ( + <CardActions> + <Button + variant="contained" + color="primary" + startIcon={<GetAppRoundedIcon />} + onClick={handleClickOpen('paper')} + > + Veja o recurso + </Button> + <Button + style={{ + fontWeight: "500", + backgroundColor: "#FA8072" + }} + variant="contained" + startIcon={<LaunchRoundedIcon style={{ fill: "#FFFAFA" }} />} + > + <a + style={{ textDecoration: "none", color: "#FFFAFA" }} + target="_blank" + href={ + PORTAL_MEC + + convertToLink( + item.complainable_type, + item.complainable_id + ) + } + > + MEC RED + </a> + </Button> + </CardActions> + ) + break; } } @@ -396,12 +564,18 @@ const CollectionCard = ({ match }) => { return moment(convertedData).format("LLL").toString(); } - const HandleComplainSubmmit = async (method) => { + const HandleComplainObj = async (method) => { postRequest( MethodsToComplain("complaints", match.params.id, method), {}, (data) => { - HandleSnack('Alteração feito com sucesso', true, 'success', '#228B22') + if (data.errors) + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + else + { + HandleSnack('Alteração feito com sucesso', true, 'success', '#228B22') + reloadData() + } }, (error) => { HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') @@ -430,13 +604,13 @@ const CollectionCard = ({ match }) => { (error) => { setError(true); } - ) + ) }, []); if (error) { return <div>Houve um erro</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> + return <LoadingSpinner text="Carregando..." /> } else { const DATA = [ { @@ -490,7 +664,7 @@ const CollectionCard = ({ match }) => { /> <Grid item - sm={8} + md={6} xs={12} > <Card> @@ -539,45 +713,15 @@ const CollectionCard = ({ match }) => { </div> ))} </CardContent> - <CardActions> - <Button - variant="contained" - color="primary" - startIcon={<GetAppRoundedIcon />} - onClick={handleClickOpen('paper')} - > - Veja o recurso - </Button> - - <Button - style={{ - fontWeight: "500", - backgroundColor: "#FA8072" - }} - variant="contained" - startIcon={<LaunchRoundedIcon style={{ fill: "#FFFAFA" }} />} - > - <a - style={{ textDecoration: "none", color: "#FFFAFA" }} - target="_blank" - href={ - PORTAL_MEC + - convertToLink( - item.complainable_type, - item.complainable_id - ) - } - > - MEC RED - </a> - </Button> - </CardActions> + { + DisplayButtonsArea(item.complainable_type) + } </Card> </Grid> <Grid item - sm={4} + md={6} xs={12} > <Grid item> @@ -587,7 +731,7 @@ const CollectionCard = ({ match }) => { Denúncia #{item.id} </Typography> - {ComplaintStatus(item.state)} + {ComplaintStatus(item.state, item.complainable_type)} <Grid container className={classes.marginTop}> <Grid item> @@ -616,7 +760,9 @@ const CollectionCard = ({ match }) => { > Data </Typography> - <Typography color="initial">{item.created_at}</Typography> + <Typography color="initial"> + {DisplayDate(item.created_at)} + </Typography> </Grid> <Grid item> @@ -672,7 +818,7 @@ const CollectionCard = ({ match }) => { Ações </Typography> { - Actions(item.state) + Actions(item.state, item.complainable_type) } </CardContent> </Card> diff --git a/src/Admin/Components/Components/DataCards/UserCard.js b/src/Admin/Components/Components/DataCards/UserCard.js index 23d8abeafb36e115047606821ae0890661b8bc8d..d4e82906c3470fdaac4fbbbfd0308d5bd7baf0e3 100644 --- a/src/Admin/Components/Components/DataCards/UserCard.js +++ b/src/Admin/Components/Components/DataCards/UserCard.js @@ -25,6 +25,7 @@ import Typography from "@material-ui/core/Typography"; import Button from "@material-ui/core/Button"; import Paper from "@material-ui/core/Paper"; import Grid from "@material-ui/core/Grid"; +import RemoveCircleOutlineRoundedIcon from '@material-ui/icons/RemoveCircleOutlineRounded'; import ListRoundedIcon from "@material-ui/icons/ListRounded"; import Chip from '@material-ui/core/Chip'; import { useStyles } from "../../Styles/DataCard"; @@ -34,20 +35,18 @@ import DeleteRoundedIcon from '@material-ui/icons/DeleteRounded'; import CheckRoundedIcon from "@material-ui/icons/CheckRounded"; import CloseRoundedIcon from "@material-ui/icons/CloseRounded"; //imports from local files -import { GetAData, DeleteFilter } from "../../../Filters"; +import { GetAData } from "../../../Filters"; import { apiDomain } from '../../../../env'; import noAvatar from "../../../../img/default_profile.png"; -import { Link } from "react-router-dom"; +import { Link, useHistory } from "react-router-dom"; import LoadingSpinner from '../../../../Components/LoadingSpinner'; import SnackBar from '../../../../Components/SnackbarComponent'; -import { getRequest, postRequest, deleteRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' -import { useHistory } from "react-router-dom"; +import { getRequest, postRequest, deleteRequest, putRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' //styles import styled from 'styled-components'; const CollectionCard = ({ match }, props) => { - console.log(match); - console.log(props); + 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 @@ -60,7 +59,7 @@ const CollectionCard = ({ match }, props) => { color: '', }) - const ComplaintStatus = (status) => { + const stateTeacherRequest = (status) => { switch (status) { case "accepted": return ( @@ -115,7 +114,7 @@ const CollectionCard = ({ match }, props) => { color: "#FFFAFA", }} > - Não requisitado + Não requisitado solicitação de professor </Paper> ) } @@ -137,6 +136,7 @@ const CollectionCard = ({ match }, props) => { } const reloadData = () => { + setIsLoaded(false) getRequest( GetAData("users", match.params.id), (data, header) => { @@ -159,8 +159,13 @@ const CollectionCard = ({ match }, props) => { url, body, (data) => { - HandleSnack(`${userName} aceito como professor!`, true, "success", "#228B22"); - reloadData() + if(data.errors) + HandleSnack("Erro!", true, "warning", "#FA8072"); + else + { + HandleSnack(`${userName} aceito como professor!`, true, "success", "#228B22"); + reloadData() + } }, (error) => { HandleSnack("Erro!", true, "warning", "#FA8072"); @@ -177,8 +182,13 @@ const CollectionCard = ({ match }, props) => { url, body, (data) => { - HandleSnack(`${userName} rejeitado como professor!`, true, "success", "#228B22"); - reloadData() + if(data.errors) + HandleSnack("Erro!", true, "warning", "#FA8072"); + else + { + HandleSnack(`${userName} rejeitado como professor!`, true, "success", "#228B22"); + reloadData() + } }, (error) => { HandleSnack("Erro!", true, "warning", "#FA8072"); @@ -190,12 +200,113 @@ const CollectionCard = ({ match }, props) => { deleteRequest( `/users/${userId}`, (data) => { - console.log(data); - HandleSnack(`${item.name} deletado com sucesso!`, true, "success", "#228B22"); + if(data.errors) + HandleSnack("Erro!", true, "warning", "#FA8072") + else + { + HandleSnack(`${item.name} deletado com sucesso!`, true, "success", "#228B22"); + history.goBack() + } }, (error) => { - HandleSnack("Erro!", true, "warning", "#FA8072"); - console.log(error); + HandleSnack("Erro!", true, "warning", "#FA8072") + } + ) + } + + const isBlocked = (state) => { + if (state === "blocked" || state === "banished") + return <Paper + style={{ + textAlign: "center", + padding: "0.5em", + backgroundColor: "red", + fontWeight: "500", + color: "#FFFAFA", + }} + > + Bloqueado + </Paper> + } + + const actionsForBlockedUser = (state) => { + if (state === "blocked" || state === "banished") { + return ( + <Button + style={{ width: "100%", marginBottom: "0.5em" }} + variant="contained" + color="secondary" + startIcon={<RemoveCircleOutlineRoundedIcon />} + onClick={() => ReactiveUser()} + > + Desbloquear + </Button> + ) + } + return <Typography color="textSecondary"> + Usuário não bloqueado + </Typography> + } + + const actionsForStateTeacherRequest = (state) => { + if (state === "requested") { + return ( + <Grid container direction="row" spacing={1}> + <Grid item> + <Button + variant="contained" + color="secondary" + style={{ width: "100%" }} + disabled={ + item.submitter_request === "requested" ? false : true + } + startIcon={ + <CloseRoundedIcon style={{ fill: "#FFFAFA" }} /> + } + onClick={() => { handleReject(item.id, item.name) }} + > + Recusar + </Button> + </Grid> + <Grid item> + <Button + variant="contained" + color="primary" + style={{ width: "100%" }} + disabled={ + item.submitter_request === "requested" ? false : true + } + startIcon={ + <CheckRoundedIcon style={{ fill: "#FFFAFA" }} /> + } + onClick={() => { handleAprove(item.id, item.name) }} + > + Aceitar + </Button> + </Grid> + </Grid> + ) + } + return <Typography color="textSecondary"> + Usuário não requisitou conta de professor + </Typography> + } + + const ReactiveUser = () => { + putRequest( + `/users/${match.params.id}/reactivate_user`, + {}, + (data) => { + if(data.errors) + HandleSnack('Erro ao tentar reativar usuário!', true, 'warning', '#FA8072') + else + { + HandleSnack('Usuário foi reativado com sucesso!', true, 'success', '#228B22') + reloadData() + } + }, + (error) => { + HandleSnack('Erro ao tentar reativar usuário!', true, 'warning', '#FA8072') } ) } @@ -385,7 +496,9 @@ const CollectionCard = ({ match }, props) => { Informações do perfil </Typography> - {ComplaintStatus(item.submitter_request)} + {stateTeacherRequest(item.submitter_request)} + <SizedBox /> + {isBlocked(item.state)} <SizedBox /> @@ -505,44 +618,22 @@ const CollectionCard = ({ match }, props) => { <Grid container direction="column"> <Grid item> <Typography variant="h5" component="h2"> - Ações + Ações para solicitação de professor </Typography> </Grid> <SizedBox /> - <Grid container direction="row" spacing={1}> - <Grid item> - <Button - variant="contained" - color="secondary" - style={{ width: "100%" }} - disabled={ - item.submitter_request === "requested" ? false : true - } - startIcon={ - <CloseRoundedIcon style={{ fill: "#FFFAFA" }} /> - } - onClick={() => { handleReject(item.id, item.name) }} - > - Recusar - </Button> - </Grid> - <Grid item> - <Button - variant="contained" - color="primary" - style={{ width: "100%" }} - disabled={ - item.submitter_request === "requested" ? false : true - } - startIcon={ - <CheckRoundedIcon style={{ fill: "#FFFAFA" }} /> - } - onClick={() => { handleAprove(item.id, item.name) }} - > - Aceitar - </Button> - </Grid> + {actionsForStateTeacherRequest(item.submitter_request)} + </Grid> + <StyledDivider> + </StyledDivider> + <Grid container direction="column"> + <Grid item> + <Typography variant="h5" component="h2"> + Ações para usuário bloqueado + </Typography> </Grid> + <SizedBox /> + {actionsForBlockedUser(item.state)} </Grid> </Grid> </CardContent> @@ -572,6 +663,7 @@ const SizedBox = styled.div` const StyledDivider = styled.div` width : 100%; border-radius : 100%; + margin-top : 0.6em; margin-bottom : 0.6em; border : 0.5px solid #d4d4d4; ` \ No newline at end of file diff --git a/src/Admin/Components/Components/Inputs/CreateInstitution.js b/src/Admin/Components/Components/Inputs/CreateInstitution.js index 303b403aab5ae1bbefcd0dffb52b0b539949b174..3b527cbaee24c249fa3c5f2b8a0420993df1b9ac 100644 --- a/src/Admin/Components/Components/Inputs/CreateInstitution.js +++ b/src/Admin/Components/Components/Inputs/CreateInstitution.js @@ -91,11 +91,6 @@ const CreateInstitution = (props) => { setCountry(e.target.value) } - // verify if the given text is empty - const isEmpty = (text) => { - return text.length === 0 ? true : false; - } - // Handle snack infos const HandleSnack = (message, state, icon, color) => { setSnackInfo({ @@ -126,46 +121,41 @@ const CreateInstitution = (props) => { //Handle submit async function onSubmit() { setIsLoading(true) - if (!isEmpty(name) && !isEmpty(country)) { - const api = '/institutions' - const body = { - "institution": { - 'name': name, - 'description': description, - 'address': adress, - 'city': city, - 'country': country, - } + const api = '/institutions' + const body = { + "institution": { + 'name': name, + 'description': description, + 'address': adress, + 'city': city, + 'country': country, } - postRequest( - api, - body, - (data) => { + } + postRequest( + api, + body, + (data) => { + if (data.id) HandleSnack('A instituição foi criada com sucesso', true, 'success', '#228B22') - setIsLoading(false) - }, - (error) => { - HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') - setIsLoading(false) + else { + if (data.name) { + let nameError = ""; + data.name.map((msg) => ( + nameError = nameError + msg + " e " + )) + setErrorInName({ + error: true, + message: nameError + }) + } } - ) - } else { - HandleSnack('Você precisa preencher algumas informações obrigatórias', true, 'warning', '#FFC125') - if (isEmpty(name)) { - setErrorInName({ - error: true, - message: 'Esse campo está vazio' - }) - } - if (isEmpty(country)) { - setErrorInCountry({ - error: true, - message: 'Esse campo está vazio' - }) + setIsLoading(false) + }, + (error) => { + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + setIsLoading(false) } - setIsLoading(false) - } - + ) } // Fields @@ -201,7 +191,7 @@ const CreateInstitution = (props) => { { label: 'PaÃs', value: country, - required: true, + required: false, error: errorInCountry.error, errorMessage: errorInCountry.message, onChange: (event) => CountryHandler(event) diff --git a/src/Admin/Components/Components/Inputs/CreateLanguage.js b/src/Admin/Components/Components/Inputs/CreateLanguage.js index 95a5906303402146d80b53b2d50227518ca8a0e4..89176dfb9d49e98f799c9dfe988ffa57b2315a51 100644 --- a/src/Admin/Components/Components/Inputs/CreateLanguage.js +++ b/src/Admin/Components/Components/Inputs/CreateLanguage.js @@ -111,46 +111,51 @@ const CreateLanguage = (props) => { return canUserEdit; } - //Handle submit async function onSubmit() { setIsLoading(true) - if (!isEmpty(name) && !isEmpty(code)) { - const api = '/languages' - const body = { - "language": { - 'name': name, - 'code': code, - } + const api = '/languages' + const body = { + "language": { + 'name': name, + 'code': code, } - postRequest( - api, - body, - (data) => { + } + postRequest( + api, + body, + (data) => { + if (data.id) HandleSnack('A linguagem foi criada com sucesso', true, 'success', '#228B22') - setIsLoading(false) - }, - (error) => { - HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') - setIsLoading(false) + else { + if (data.name) { + let nameError = ""; + data.name.map((msg) => ( + nameError = nameError + msg + " e " + )) + setErrorInName({ + error: true, + message: nameError + }) + } + if (data.code) { + let codeError = ""; + data.code.map((msg) => ( + codeError = codeError + msg + " e " + )) + setErrorInCode({ + error: true, + message: codeError + }) + } } - ) - } else { - HandleSnack('Você precisa preencher algumas informações obrigatórias', true, 'warning', '#FFC125') - if (isEmpty(name)) { - setErrorInName({ - error: true, - message: 'Esse campo está vazio' - }) + setIsLoading(false) + }, + (error) => { + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + setIsLoading(false) } - if (isEmpty(code)) { - setErrorInCode({ - error: true, - message: 'Esse campo está vazio' - }) - } - setIsLoading(false) - } + ) } // Fields diff --git a/src/Admin/Components/Components/Inputs/CreateQuestion.js b/src/Admin/Components/Components/Inputs/CreateQuestion.js index 70714f7fac42da6425ee07300604ec0a8bd2813d..1f532891768d45bb4279d692c34757f8bbbec391 100644 --- a/src/Admin/Components/Components/Inputs/CreateQuestion.js +++ b/src/Admin/Components/Components/Inputs/CreateQuestion.js @@ -87,26 +87,26 @@ const CreateQuestion = (props) => { } const CheckUserPermission = () => { - let canUserEdit = false; + let canUserEdit = false; if (state.userIsLoggedIn) { const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin') - canUserEdit = true; + canUserEdit = true; } else { canUserEdit = false; - } + } - return canUserEdit; + return canUserEdit; } //Handle submit async function onSubmit() { - setIsLoading(true) - if (!isEmpty(status) && !isEmpty(description)) { + if (!isEmpty(description)) { + setIsLoading(true) const api = '/questions' const body = { "question": { @@ -118,7 +118,10 @@ const CreateQuestion = (props) => { api, body, (data) => { - HandleSnack('A pergunta foi criada com sucesso', true, 'success', '#228B22') + if(data.errors) + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + else + HandleSnack('A pergunta foi criada com sucesso', true, 'success', '#228B22') setIsLoading(false) }, (error) => { @@ -126,21 +129,15 @@ const CreateQuestion = (props) => { setIsLoading(false) } ) - } else { - HandleSnack('Você precisa preencher algumas informações obrigatórias', true, 'warning', '#FFC125') - if (isEmpty(status)) { - setErrorInStatus({ - error: true, - message: 'Esse campo está vazio' - }) - } - if (isEmpty(description)) { - setErrorInDescription({ - error: true, - message: 'Esse campo está vazio' - }) - } - setIsLoading(false) + } + else + { + setErrorInDescription( + { + error : true, + message : "Você precisa preencher este campo!" + } + ) } } @@ -175,7 +172,7 @@ const CreateQuestion = (props) => { }, ]; - if(CheckUserPermission()) { + if (CheckUserPermission()) { return ( <Card> <SnackBar @@ -210,9 +207,9 @@ const CreateQuestion = (props) => { </Link> </Grid> </Grid> - + <div style={{ height: '1em' }}></div> - + <form style={{ display: 'flex', flexDirection: 'column' }}> <> <TextField @@ -270,7 +267,7 @@ const CreateQuestion = (props) => { </CardAction> </Card> ); - } else return <Unauthorized/> + } else return <Unauthorized /> } export default CreateQuestion; \ No newline at end of file diff --git a/src/Admin/Components/Components/Inputs/CreateRating.js b/src/Admin/Components/Components/Inputs/CreateRating.js index 58c2bca1aae5589613d93db5c0e7ed8f43630de3..ef12cd2766b68187906f94c61f284e3af10c1766 100644 --- a/src/Admin/Components/Components/Inputs/CreateRating.js +++ b/src/Admin/Components/Components/Inputs/CreateRating.js @@ -127,7 +127,10 @@ const CreateRating = (props) => { api, body, (data) => { - HandleSnack('O rating foi criada com sucesso', true, 'success', '#228B22') + if(data.errors) + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + else + HandleSnack('O rating foi criada com sucesso', true, 'success', '#228B22') setIsLoading(false) }, (error) => { diff --git a/src/Admin/Components/Components/Inputs/CreateRole.js b/src/Admin/Components/Components/Inputs/CreateRole.js index 7f8349de07438e026d6173d93e147ecf79780496..050203e0c267c85b6ac69106e60637ff4b0d4bed 100644 --- a/src/Admin/Components/Components/Inputs/CreateRole.js +++ b/src/Admin/Components/Components/Inputs/CreateRole.js @@ -80,11 +80,6 @@ const CreateRole = (props) => { setDesc(e.target.value) } - // verify if the given text is empty - const isEmpty = (text) => { - return text.length === 0 ? true : false; - } - // Handle snack infos const HandleSnack = (message, state, icon, color) => { setSnackInfo({ diff --git a/src/Admin/Components/Components/Inputs/EditLanguage.js b/src/Admin/Components/Components/Inputs/EditLanguage.js index 5162858f0fa07ca95328f77306bd87af4e1d38d8..431b156c78e73bd3fd68a7322eb0c05dce7839de 100644 --- a/src/Admin/Components/Components/Inputs/EditLanguage.js +++ b/src/Admin/Components/Components/Inputs/EditLanguage.js @@ -147,43 +147,48 @@ const EditLanguage = ({ match }) => { const onSubmit = async () => { setIsLoading(true) - if (!isEmpty(name) && !isEmpty(code)) { - const api = EditFilter('languages', id) - const body = { - "language": { - 'name': name, - 'code': code, - } + const api = EditFilter('languages', id) + const body = { + "language": { + 'name': name, + 'code': code, } - putRequest( - api, - body, - (data) => { - HandleSnack('A linguagem foi alterada com sucesso', true, 'success', '#228B22') - setIsLoading(false) - }, - (error) => { - HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') - setIsLoading(false) - } - ) } - else { - HandleSnack('Você precisa preencher algumas informações obrigatórias', true, 'warning', '#FFC125') - if (isEmpty(name)) { - setErrorInName({ - error: true, - message: 'Este campo precisa ser preenchido' - }) - } - if (isEmpty(code)) { - setErrorInCode({ - error: true, - message: 'Este campo precisa ser preenchido' - }) + putRequest( + api, + body, + (data) => { + if (data.id) + HandleSnack('A linguagem foi alterada com sucesso!', true, 'success', '#228B22') + else { + if (data.name) { + let errorName = ""; + data.name.map((err) => ( + errorName = errorName + err + " e " + )) + setErrorInName({ + error: true, + message: errorName + }) + } + if (data.code) { + let errorcode = ""; + data.code.map((err) => ( + errorcode = errorcode + err + " e " + )) + setErrorInCode({ + error: true, + message: errorcode + }) + } + } + setIsLoading(false) + }, + (error) => { + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + setIsLoading(false) } - setIsLoading(false) - } + ) } useEffect(() => { diff --git a/src/Admin/Components/Components/Inputs/EditRating.js b/src/Admin/Components/Components/Inputs/EditRating.js index d9467ebef8bf4607d81ec4eab173dd72194f9e61..2229d02f9664b008a7aab833c0222d93128c4c33 100644 --- a/src/Admin/Components/Components/Inputs/EditRating.js +++ b/src/Admin/Components/Components/Inputs/EditRating.js @@ -161,7 +161,10 @@ const EditRating = ({ match }) => { api, body, (data, header) => { - HandleSnack('O rating foi alterada com sucesso', true, 'success', '#228B22') + if(data.errors) + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + else + HandleSnack('O rating foi alterada com sucesso', true, 'success', '#228B22') setIsLoading(false) }, (error) => { diff --git a/src/Admin/Components/Components/Inputs/EditUser.js b/src/Admin/Components/Components/Inputs/EditUser.js index 49118cd580a067bffa47486830b3e6a04916266b..5152ff93438f3c0b3513028dd4fde0fdf3a3790f 100644 --- a/src/Admin/Components/Components/Inputs/EditUser.js +++ b/src/Admin/Components/Components/Inputs/EditUser.js @@ -38,11 +38,10 @@ import { Store } from '../../../../Store'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; //imports services import { getRequest, putRequest, deleteRequest, postRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' -import { EditFilter, GetAData, DeleteFilter } from '../../../Filters'; +import { EditFilter, GetAData } from '../../../Filters'; //routers -import { Link } from 'react-router-dom'; +import { Link, useHistory } from 'react-router-dom'; import Unauthorized from '../Unauthorized'; -import styled from 'styled-components'; const useStyles = makeStyles((theme) => ({ root: { @@ -60,6 +59,7 @@ const useStyles = makeStyles((theme) => ({ const EditUser = ({ match }) => { const classes = useStyles(); + let history = useHistory(); const { state, dispatch } = useContext(Store) const id = match.params.id @@ -196,11 +196,6 @@ const EditUser = ({ match }) => { setConfirmPass(e.target.value) } - //Verify if the string is empty - const isEmpty = (text) => { - return text.length === 0 ? true : false; - } - // Fields const fields = [ { @@ -296,7 +291,13 @@ const EditUser = ({ match }) => { deleteRequest( `/users/${userId}`, (data) => { - HandleSnack(`${name} deletado com sucesso!`, true, "success", "#228B22"); + if(data.errors) + HandleSnack("Erro!", true, "warning", "#FA8072"); + else + { + HandleSnack(`${name} deletado com sucesso!`, true, "success", "#228B22"); + history.push("/admin/usersList") + } }, (error) => { HandleSnack("Erro!", true, "warning", "#FA8072"); @@ -378,7 +379,10 @@ const EditUser = ({ match }) => { (data) => { setIsLoading(false) if (data.id) + { HandleSnack(`O usuário: ${name} foi criado`, true, 'success', '#228B22') + history.push("/admin/usersList") + } else { if (data.password) { let passError = ""; diff --git a/src/Admin/Components/Components/Inputs/IntitutionsInputs.js b/src/Admin/Components/Components/Inputs/IntitutionsInputs.js index 17d85fcc6402985c04e2db48db227ee44c845801..10761cc4b2776b2fb8485848eb309687e18a79e1 100644 --- a/src/Admin/Components/Components/Inputs/IntitutionsInputs.js +++ b/src/Admin/Components/Components/Inputs/IntitutionsInputs.js @@ -44,7 +44,6 @@ 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 [isAuthorized, setIsAuthorized] = useState(); const [name, setName] = useState(); const [description, setDescription] = useState(); @@ -134,45 +133,41 @@ const EditInstitution = ({ match }) => { //Handle submit async function onSubmit() { setIsLoading(true) - if (!isEmpty(name) && !isEmpty(country)) { - const api = EditFilter('institutions', id) - const body = { - "institution": { - 'name': name, - 'description': description, - 'address': adress, - 'city': city, - 'country': country, - } + const api = EditFilter('institutions', id) + const body = { + "institution": { + 'name': name, + 'description': description, + 'address': adress, + 'city': city, + 'country': country, } - putRequest( - api, - body, - (data) => { - HandleSnack('A instituição foi alterada com sucesso', true, 'success', '#228B22') - setIsLoading(false) - }, - (error) => { - HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') - setIsLoading(false) + } + putRequest( + api, + body, + (data) => { + if (data.id) + HandleSnack('A instituição foi criada com sucesso!', true, 'success', '#228B22') + else { + if (data.name) { + let errorName = ""; + data.name.map((err) => ( + errorName = errorName + err + " e " + )) + setErrorInName({ + error: true, + message: errorName + }) + } } - ) - } else { - HandleSnack('Você precisa preencher algumas informações obrigatórias', true, 'warning', '#FFC125') - if (isEmpty(name)) { - setErrorInName({ - error: true, - message: 'Esse campo está vazio' - }) - } - if (isEmpty(country)) { - setErrorInCountry({ - error: true, - message: 'Esse campo está vazio' - }) + setIsLoading(false) + }, + (error) => { + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + setIsLoading(false) } - setIsLoading(false) - } + ) } // Fields diff --git a/src/Admin/Components/Components/Inputs/NoteVarInputs.js b/src/Admin/Components/Components/Inputs/NoteVarInputs.js index f3c3c10dea51f9d694993634157ab6bc8841e795..3043cd68252bdfd1ce0f6ab6eaf3bfdd07d0b8ae 100644 --- a/src/Admin/Components/Components/Inputs/NoteVarInputs.js +++ b/src/Admin/Components/Components/Inputs/NoteVarInputs.js @@ -114,6 +114,15 @@ const NoteVarInputs = ({ match }) => { default: true, type: 'text' }, + { + label: 'Código', + value: code, + error: errorInCode.error, + errorMessage: errorInCode.message, + onChange: (event) => CodeHandler(event), + default: true, + type: 'text' + }, { label: 'Nome', value: name, @@ -123,15 +132,6 @@ const NoteVarInputs = ({ match }) => { default: false, type: 'text', }, - { - label: 'Código', - value: code, - error: errorInCode.error, - errorMessage: errorInCode.message, - onChange: (event) => CodeHandler(event), - default: false, - type: 'text' - }, { label: 'Peso', value: weight, @@ -155,50 +155,49 @@ const NoteVarInputs = ({ match }) => { const onSubmit = async () => { setIsLoading(true) - if (!isEmpty(name) && !isEmpty(code) && !isEmpty(weight)) { - const api = EditFilter('scores', id) - const body = { - "score": { - 'name': name, - 'code': code, - 'weight': weight - } + const api = EditFilter('scores', id) + const body = { + "score": { + 'name': name, + 'code': code, + 'weight': weight } - putRequest( - api, - body, - (data) => { - HandleSnack('A variável de nota foi alterada com sucesso', true, 'success', '#228B22') - setIsLoading(false) - }, - (error) => { - HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') - setIsLoading(false) - } - ) } - else { - HandleSnack('Você precisa preencher algumas informações obrigatórias', true, 'warning', '#FFC125') - if (isEmpty(name)) { - setErrorInName({ - error: true, - message: 'Este campo precisa ser preenchido' - }) - } - if (isEmpty(code)) { - setErrorInCode({ - error: true, - message: 'Este campo precisa ser preenchido' - }) - } - if (isEmpty(weight)) { - setErrorInWeight({ - error: true, - message: 'Este campo precisa ser preenchido' - }) + putRequest( + api, + body, + (data) => { + if (data.id) + HandleSnack('A variável de nota foi atualizada com sucesso!', true, 'success', '#228B22') + else { + if (data.name) { + let errorName = ""; + data.name.map((err) => ( + errorName = errorName + err + " e " + )) + setErrorInName({ + error: true, + message: errorName + }) + } + if(data.weight){ + let weightError = ""; + data.weight.map((err) => ( + weightError = weightError + err + " e " + )) + setErrorInWeight({ + error: true, + message : weightError + }) + } + } + setIsLoading(false) + }, + (error) => { + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + setIsLoading(false) } - setIsLoading(false) - } + ) } const CheckUserPermission = () => { @@ -237,8 +236,8 @@ const NoteVarInputs = ({ match }) => { if (error) { return <div>Houve um erro...</div> } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> - } else if(CheckUserPermission()){ + return <LoadingSpinner text="Carregando..." /> + } else if (CheckUserPermission()) { return ( <Card> <SnackBar @@ -315,7 +314,7 @@ const NoteVarInputs = ({ match }) => { </CardContent> </Card> ) - } else return <Unauthorized/> + } else return <Unauthorized /> } export default NoteVarInputs; \ No newline at end of file diff --git a/src/Admin/Pages/AdminLabelTabs/LabelTabs.js b/src/Admin/Pages/AdminLabelTabs/LabelTabs.js index ebf6b27edc979c4cc64fc7332a6a4305c9109bca..8209b2de8381f09f107fe14e3e421a17c3272afd 100644 --- a/src/Admin/Pages/AdminLabelTabs/LabelTabs.js +++ b/src/Admin/Pages/AdminLabelTabs/LabelTabs.js @@ -87,12 +87,6 @@ const TabsItens = [ label: "Métricas", href:'/admin/inframe', }, - { - label: "Configurações", - }, - { - label: "Sair", - }, ]; export { TabsItens }; diff --git a/src/Admin/Pages/Pages/SubPages/AproveTeacher.js b/src/Admin/Pages/Pages/SubPages/AproveTeacher.js index 22a91c0ff4a621cac9dcc92cca0587b760bc1c7b..45c88dcb9b5902175158598a0b34fb640227c600 100644 --- a/src/Admin/Pages/Pages/SubPages/AproveTeacher.js +++ b/src/Admin/Pages/Pages/SubPages/AproveTeacher.js @@ -337,16 +337,20 @@ const AproveTeacher = () => { url, body, (data) => { - HandleSnack(`${userName} aceito como professor!`, true, "success", "#228B22"); - currPage = 0; - UpdateHandler( - Url( - "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, - `${currPage}`, - "DESC" - ), - ); + if (data.errors) + HandleSnack("Erro!", true, "warning", "#FA8072"); + else { + HandleSnack(`${userName} aceito como professor!`, true, "success", "#228B22"); + currPage = 0; + UpdateHandler( + Url( + "users", + `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, + `${currPage}`, + "DESC" + ), + ); + } }, (error) => { HandleSnack("Erro!", true, "warning", "#FA8072"); @@ -363,16 +367,21 @@ const AproveTeacher = () => { url, body, (data) => { - HandleSnack(`${userName} rejeitado como professor!`, true, "success", "#228B22"); - currPage = 0; - UpdateHandler( - Url( - "users", - `"submitter_request":"${currContentState}","name":"${currContentName}","email":"${currContentEmail}"`, - `${currPage}`, - "DESC" - ), - ); + 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}"`, + `${currPage}`, + "DESC" + ), + ); + } }, (error) => { HandleSnack("Erro!", true, "warning", "#FA8072"); diff --git a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js index fcfd7a225e2621bbfa8fede08475f43a886de04c..06f0f96defc4d9d738ad82d36d49d99038951350 100644 --- a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js +++ b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js @@ -32,12 +32,13 @@ import { Button, Typography } from '@material-ui/core'; import CircularProgress from '@material-ui/core/CircularProgress'; import AddRoundedIcon from '@material-ui/icons/AddRounded'; import UpdateRoundedIcon from '@material-ui/icons/UpdateRounded' +import EmailRoundedIcon from '@material-ui/icons/EmailRounded'; //Local files import TableData from '../../../Components/Components/Table'; import SnackBar from '../../../../Components/SnackbarComponent'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; //Services -import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' +import { getRequest, postRequest, putRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' import { Url } from '../../../Filters'; //routers import { Link } from 'react-router-dom'; @@ -81,12 +82,12 @@ const BlockedUsers = () => { const StateOptions = [ { - id : 1, - name : "Semanal" - }, + id: 1, + name: "Semanal" + }, { - id : 2, - name : "Permanente" + id: 2, + name: "Permanente" } ]; @@ -123,6 +124,63 @@ const BlockedUsers = () => { ) } + const handleChange = (event) => { + const type = event.target.value + switch (type) { + case "Semanal": + currPage = 0; + currContentFilter = 1; + getRequest( + Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'ASC'), + (data, header) => { + HandleSnack("Filtro aplicado com sucesso!", true, 'success', '#228B22') + const arrData = [...data] + setItems(arrData.concat(AddOneLenght)) + setIsUpdating(false) + }, + (error) => { + HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') + setIsUpdating(false) + } + ) + break; + case "Permanente": + currPage = 0; + currContentFilter = 2; + getRequest( + Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'ASC'), + (data, header) => { + HandleSnack("Filtro aplicado com sucesso!", true, 'success', '#228B22') + const arrData = [...data] + setItems(arrData.concat(AddOneLenght)) + setIsUpdating(false) + }, + (error) => { + HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') + setIsUpdating(false) + } + ) + break; + default: + currPage = 0; + currContentFilter = 1; + getRequest( + Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'ASC'), + (data, header) => { + HandleSnack("Filtro aplicado com sucesso!", true, 'success', '#228B22') + const arrData = [...data] + setItems(arrData.concat(AddOneLenght)) + setIsUpdating(false) + }, + (error) => { + HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') + setIsUpdating(false) + } + ) + break; + } + } + const InvertList = async () => { transformListToAsc = !transformListToAsc currPage = 0 @@ -190,7 +248,7 @@ const BlockedUsers = () => { style={{ textAlign: "center", padding: "0.5em", - backgroundColor: "#FA8072", + backgroundColor: "red", fontWeight: "500", color: "#FFFAFA", }} @@ -198,25 +256,43 @@ const BlockedUsers = () => { PERMANENTE </Paper> ); - case 3: + default: return ( <Paper style={{ textAlign: "center", padding: "0.5em", - backgroundColor: "#228B22", + backgroundColor: "#797D7F", fontWeight: "500", color: "#FFFAFA", }} > - AVALIADO + Não avaliado </Paper> ); - default: - return "NOTHING"; } }; + const ReactiveUser = (userId) => { + putRequest( + `/users/${userId}/reactivate_user`, + {}, + (data) => { + if (data.errors) + HandleSnack('Erro!', true, 'warning', '#FA8072') + else + { + currPage = 0 + HandleSnack('Usuário foi reativado com sucesso!', true, 'success', '#228B22') + UpdateHandler(Url('users', `"state" : "${currContentFilter}"`, `${currPage}`, 'DESC')) + } + }, + (error) => { + HandleSnack('Erro!', true, 'warning', '#FA8072') + } + ) + } + const DisplayDate = (date) => { const convertedData = moment.utc(date); return moment(convertedData) @@ -298,7 +374,7 @@ const BlockedUsers = () => { <TextField select label="Motivo" - // onChange={handleChange} + onChange={handleChange} helperText="Por favor, selecione uma das opções" > {StateOptions.map((option, index) => ( @@ -357,7 +433,20 @@ const BlockedUsers = () => { {BlockStatus(currContentFilter)} </StyledTableCell> <StyledTableCell align="right">{row.name}</StyledTableCell> - <StyledTableCell align="right">{row.email}</StyledTableCell> + <StyledTableCell align="right"> + { + row.email ? + <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> + <Button + variant='text' + color='primary' + startIcon={<EmailRoundedIcon />} + > + {row.email} + </Button> + </Link> : null + } + </StyledTableCell> <StyledTableCell align="right"> {DisplayDate(row.suspended_at)} </StyledTableCell> @@ -367,6 +456,7 @@ const BlockedUsers = () => { variant="contained" color="secondary" startIcon={<RemoveCircleOutlineRoundedIcon />} + onClick={() => ReactiveUser(row.id)} > Desbloquear </Button> diff --git a/src/Admin/Pages/Pages/SubPages/Collections.js b/src/Admin/Pages/Pages/SubPages/Collections.js index 15aa03813ded2f19924d208b2b812e1abcc3673f..4acb169bb479fcb42de78075b7629f267dc0a9cf 100644 --- a/src/Admin/Pages/Pages/SubPages/Collections.js +++ b/src/Admin/Pages/Pages/SubPages/Collections.js @@ -181,15 +181,19 @@ const Collections = () => { HandleStateAlertDialog(null); deleteRequest(DeleteFilter("collections", id), (data) => { - HandleSnack( - "A Coleção foi deletada com sucesso", - true, - "success", - "#228B22" - ); - currPage = 0; - HandleStateCircularProgress(null); - UpdateHandler(Url("collections", "", `${currPage}`, "DESC")); + if (data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else { + HandleSnack( + "A Coleção foi deletada com sucesso", + true, + "success", + "#228B22" + ); + currPage = 0; + HandleStateCircularProgress(null); + UpdateHandler(Url("collections", "", `${currPage}`, "DESC")); + } }, (error) => { HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); @@ -442,7 +446,7 @@ const Collections = () => { </StyledTableCell> <StyledTableCell align="right"> <Link to={`/admin/Collection/${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 7c35b1c0c7d66a4382588e057d7b3f01411e3f25..2375b739e418dc5fa1f24be5a95f4d07ebb05e58 100644 --- a/src/Admin/Pages/Pages/SubPages/Complaints.js +++ b/src/Admin/Pages/Pages/SubPages/Complaints.js @@ -77,6 +77,7 @@ const Complaints = () => { "ID", "DESCRIÇÃO", "ID OBJETO", + "TIPO", "DATA(MM/DD/YYYY)", "VISUALIZAR", "VISITAR", @@ -249,7 +250,7 @@ const Complaints = () => { } }; - const ComplaintStatus = (status) => { + const ComplaintStatus = (status, type) => { switch (status) { case "accepted": return ( @@ -262,7 +263,9 @@ const Complaints = () => { color: "#FFFAFA", }} > - REMOVIDO + { + type === "User" ? "BLOQUEADO" : "REMOVIDO" + } </Paper> ); case "complained": @@ -290,7 +293,7 @@ const Complaints = () => { color: "#FFFAFA", }} > - AVALIADO + REJEITADO </Paper> ); default: @@ -499,7 +502,7 @@ const Complaints = () => { style={{ flex: 1, width: "100%" }} > <StyledTableCell component="th" scope="row"> - {ComplaintStatus(row.state)} + {ComplaintStatus(row.state, row.complainable_type)} </StyledTableCell> <StyledTableCell align="right">{row.id}</StyledTableCell> <StyledTableCell align="right"> @@ -508,6 +511,9 @@ const Complaints = () => { <StyledTableCell align="right"> {row.complainable_id} </StyledTableCell> + <StyledTableCell align="right"> + {row.complainable_type} + </StyledTableCell> <StyledTableCell align="right"> {DisplayDate(row.created_at)} </StyledTableCell> diff --git a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js index fca838bcfd8c7cfd7b6e3896a9b65b2320400c5a..3dab65449433f0d10c02a803cd0dbd4742bf039c 100644 --- a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js +++ b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js @@ -219,15 +219,19 @@ const EducationalObjects = () => { deleteRequest( DeleteFilter("institutions", id), (data) => { - HandleSnack( - "A instituição foi deletada com sucesso", - true, - "success", - "#228B22" - ); - currPage = 0; - UpdtateListData(Url("institutions", "", `${currPage}`, "DESC")); - HandleStateCircularProgress(null); + if (data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else { + HandleSnack( + "A instituição foi deletada com sucesso", + true, + "success", + "#228B22" + ); + currPage = 0; + UpdtateListData(Url("institutions", "", `${currPage}`, "DESC")); + HandleStateCircularProgress(null); + } }, (error) => { HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); diff --git a/src/Admin/Pages/Pages/SubPages/Institutions.js b/src/Admin/Pages/Pages/SubPages/Institutions.js index 99dd554013f966ca51ed32c9fd2b1bc52d2d334c..81710dbff2df774ceba79f04e505a5f1311ade57 100644 --- a/src/Admin/Pages/Pages/SubPages/Institutions.js +++ b/src/Admin/Pages/Pages/SubPages/Institutions.js @@ -253,19 +253,24 @@ const Institutions = () => { deleteRequest( DeleteFilter("institutions", id), (data) => { - HandleSnack( - "A instituição foi deletada com sucesso", - true, - "success", - "#228B22" - ); - currPage = 0; - transformListToAsc = false - UpdtateListData(Url("institutions", "", `${currPage}`, "DESC")); - HandleStateCircularProgress(null); + if (data.errors) + HandleSnack("Ocorreu algum erro!", true, "warning", "#FA8072"); + else + { + HandleSnack( + "A instituição foi deletada com sucesso", + true, + "success", + "#228B22" + ); + currPage = 0; + transformListToAsc = false + UpdtateListData(Url("institutions", "", `${currPage}`, "DESC")); + HandleStateCircularProgress(null); + } }, (error) => { - HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + HandleSnack("Ocorreu algum erro!", true, "warning", "#FA8072"); HandleStateCircularProgress(null); } ) @@ -335,7 +340,7 @@ const Institutions = () => { setIsLoaded(true); setItems(data.concat(addOndeLenght)); }, - (error) => { + (error) => { setError(true); } ) @@ -511,7 +516,7 @@ const Institutions = () => { ); }} > - {isUpdating ? <CircularProgress /> : "Atualizar"} + {isUpdating ? <CircularProgress size={24}/> : "Atualizar"} </Button> </Grid> </Grid> @@ -576,7 +581,7 @@ const Institutions = () => { }} > {isLoadingMoreItems ? ( - <CircularProgress /> + <CircularProgress size={24}/> ) : ( "Carregar mais itens" )} diff --git a/src/Admin/Pages/Pages/SubPages/Languages.js b/src/Admin/Pages/Pages/SubPages/Languages.js index 56b467d9a30d33dca4c000095c2e9fc695c7a574..42c397aeb9d800a21c4d03b4b41741409145ae53 100644 --- a/src/Admin/Pages/Pages/SubPages/Languages.js +++ b/src/Admin/Pages/Pages/SubPages/Languages.js @@ -142,16 +142,21 @@ const Languages = () => { deleteRequest( DeleteFilter("languages", id), (data) => { - HandleSnack( - "A lÃngua foi deletada com sucesso", - true, - "success", - "#228B22" - ); - currPage = 0; - transformListToAsc = false - UpdateHandler(Url("languages", "", `${currPage}`, "DESC")); - HandleStateCircularProgress(null); + if(data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else + { + HandleSnack( + "A lÃngua foi deletada com sucesso", + true, + "success", + "#228B22" + ); + currPage = 0; + transformListToAsc = false + UpdateHandler(Url("languages", "", `${currPage}`, "DESC")); + HandleStateCircularProgress(null); + } }, (error) => { HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); diff --git a/src/Admin/Pages/Pages/SubPages/Permissions.js b/src/Admin/Pages/Pages/SubPages/Permissions.js index b0a927e2fa822f04eb9dda4cd42479364ba4bb7c..1ac3bda5a63bd59c1a2834830dddee310f6b6754 100644 --- a/src/Admin/Pages/Pages/SubPages/Permissions.js +++ b/src/Admin/Pages/Pages/SubPages/Permissions.js @@ -142,16 +142,21 @@ const UserPermissions = () => { deleteRequest( DeleteFilter("roles", id), (data) => { - HandleSnack( - "A lÃngua foi deletada com sucesso", - true, - "success", - "#228B22" - ); - currPage = 0; - transformListToAsc = false - UpdateHandler(Url("roles", "", `${currPage}`, "DESC")); - HandleStateCircularProgress(null); + if(data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else + { + HandleSnack( + "A lÃngua foi deletada com sucesso", + true, + "success", + "#228B22" + ); + currPage = 0; + transformListToAsc = false + UpdateHandler(Url("roles", "", `${currPage}`, "DESC")); + HandleStateCircularProgress(null); + } }, (error) => { HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); diff --git a/src/Admin/Pages/Pages/SubPages/Questions.js b/src/Admin/Pages/Pages/SubPages/Questions.js index 43fe07bb83686994df6953866846603ac8783244..87de31919c530f0def4f0b8cec257c4402a3c311 100644 --- a/src/Admin/Pages/Pages/SubPages/Questions.js +++ b/src/Admin/Pages/Pages/SubPages/Questions.js @@ -187,14 +187,18 @@ const Questions = () => { "description": description, "status": "inactive" } - } + } putRequest( EditFilter('questions', id), body, (data) => { - currPage = 0 - transformListToAsc = false - UpdateHandler(Url('questions', '', `${currPage}`, 'DESC')) + if (data.errors) + HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') + else { + currPage = 0 + transformListToAsc = false + UpdateHandler(Url('questions', '', `${currPage}`, 'DESC')) + } }, (error) => { HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') @@ -211,9 +215,13 @@ const Questions = () => { EditFilter('questions', id), body, (data) => { - currPage = 0 - transformListToAsc = false - UpdateHandler(Url('questions', '', `${currPage}`, 'DESC')) + if (data.errors) + HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') + else { + currPage = 0 + transformListToAsc = false + UpdateHandler(Url('questions', '', `${currPage}`, 'DESC')) + } }, (error) => { HandleSnack('Erro ao carregar os dados', true, 'warning', '#FA8072') diff --git a/src/Admin/Pages/Pages/SubPages/Rating.js b/src/Admin/Pages/Pages/SubPages/Rating.js index 688dd5b3a55a42f4116058b79a47ef742dedb4fe..fc7534cc763d685b4db6c66ca8354549c41d6049 100644 --- a/src/Admin/Pages/Pages/SubPages/Rating.js +++ b/src/Admin/Pages/Pages/SubPages/Rating.js @@ -168,16 +168,20 @@ const Ratings = () => { deleteRequest( DeleteFilter("ratings", id), (data) => { - HandleSnack( - "O rating foi deletada com sucesso", - true, - "success", - "#228B22" - ); - currPage = 0; - transformListToAsc = false - UpdateHandler(Url("ratings", "", `${currPage}`, "DESC")); - HandleStateCircularProgress(null); + if (data.errors) + HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); + else { + HandleSnack( + "O rating foi deletada com sucesso", + true, + "success", + "#228B22" + ); + currPage = 0; + transformListToAsc = false + UpdateHandler(Url("ratings", "", `${currPage}`, "DESC")); + HandleStateCircularProgress(null); + } }, (error) => { HandleSnack("Ocorreu algum erro", true, "warning", "#FA8072"); @@ -324,7 +328,7 @@ const Ratings = () => { <StyledTableCell align="right">{row.description}</StyledTableCell> <StyledTableCell align="right"> <Link to={`/admin/Rating/${row.id}`}> - <IconButton onClick={() => {currPage = 0}}> + <IconButton onClick={() => { currPage = 0 }}> <VisibilityIcon style={{ fill: '#00bcd4' }} /> </IconButton> </Link> diff --git a/src/Admin/Pages/Pages/SubPages/Users.js b/src/Admin/Pages/Pages/SubPages/Users.js index cc753454528c212ba27bfddde6e90454986bf703..9846c5efe682aeb2b2238993ebcfac0efce536c2 100644 --- a/src/Admin/Pages/Pages/SubPages/Users.js +++ b/src/Admin/Pages/Pages/SubPages/Users.js @@ -74,8 +74,8 @@ const Users = () => { const [isUpdating, setIsUpdating] = useState(false) const [showFilter, setShowFilter] = useState(false) const [loadingUserPublisher, setLoadingUserPublisher] = useState({ - id : null, - loading : false + id: null, + loading: false }) const [name, setName] = useState(""); @@ -217,7 +217,7 @@ const Users = () => { } const turnUserPublisher = (userRoles, userId) => { - let roles_ids = []; + let roles_ids = []; userRoles.map((role) => ( roles_ids.push(role.id) )) @@ -231,9 +231,14 @@ const Users = () => { `/users/${userId}`, body, (data) => { - currPage = 0; - HandleSnack(`O usuário ${userId}, agora é publicador`, true, 'success', '#228B22') - UpdateHandler(Url('users', `"name" : "${nameFilter}", "email" : "${emailFilter}"`, `${currPage}`, 'DESC')) + if (data.errors) { + HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') + } + else { + currPage = 0; + HandleSnack(`O usuário ${userId}, agora é publicador`, true, 'success', '#228B22') + UpdateHandler(Url('users', `"name" : "${nameFilter}", "email" : "${emailFilter}"`, `${currPage}`, 'DESC')) + } }, (error) => { HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072')