diff --git a/src/Admin/Components/Components/DataCards/ActivityCard.js b/src/Admin/Components/Components/DataCards/ActivityCard.js index d3bdcbe1d1f8d11122a150950099243f1a9cf510..915df2f99fdb31c17741d362555721f14a3753f9 100644 --- a/src/Admin/Components/Components/DataCards/ActivityCard.js +++ b/src/Admin/Components/Components/DataCards/ActivityCard.js @@ -32,7 +32,7 @@ import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfi import { Link } from 'react-router-dom' import LoadingSpinner from '../../../../Components/LoadingSpinner'; -const ActivityCard = ({ match }) => { +const ActivityCard = () => { const classes = useStyles(); const [error, setError] = useState(null); //Necessary to consult the API, catch errors @@ -48,7 +48,9 @@ const ActivityCard = ({ match }) => { //getting data from server useEffect(() => { - getRequest(GetAData("activities", match.params.id), + const urlParams = new URLSearchParams(window.location.search); + const query = urlParams.get("activity"); + getRequest(GetAData("activities", query), (data, header) => { setItem(data); setIsLoaded(true); @@ -120,7 +122,7 @@ const ActivityCard = ({ match }) => { </Link> </Grid> </Grid> - <div style={{height: "1em"}}/> + <div style={{ height: "1em" }} /> {DATA.map((info, index) => ( <div className={classes.displayColumn} key={index}> <Typography color="initial" className={classes.subTitle}> diff --git a/src/Admin/Components/Components/DataCards/CollectionCard.js b/src/Admin/Components/Components/DataCards/CollectionCard.js index fa06198a87093ad05ca72addaed66fd26e566b0f..a4ef28da2b30bdff799545b79d7936b5415e19ca 100644 --- a/src/Admin/Components/Components/DataCards/CollectionCard.js +++ b/src/Admin/Components/Components/DataCards/CollectionCard.js @@ -36,9 +36,11 @@ import LoadingSpinner from '../../../../Components/LoadingSpinner'; import SnackBar from '../../../../Components/SnackbarComponent'; import { getRequest, deleteRequest } from '../../../../Components/HelperFunctions/getAxiosConfig'; -const CollectionCard = ({ match }) => { +const CollectionCard = () => { let history = useHistory() const classes = useStyles(); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("collection"); 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 @@ -69,7 +71,6 @@ const CollectionCard = ({ match }) => { //Called when user want to delete one institution async function DeleteHandler() { - const id = match.params.id deleteRequest( DeleteFilter("collections", id), (data) => { @@ -93,7 +94,7 @@ const CollectionCard = ({ match }) => { useEffect(() => { getRequest( - GetAData("collections", match.params.id), + GetAData("collections", id), (data, header) => { setItem(data); setIsLoaded(true); @@ -178,14 +179,14 @@ const CollectionCard = ({ match }) => { </Button> </Link> - <Link style={{ textDecoration: 'none' }} to={`/admin/EditCollection/${item.id}`}> + <Link style={{ textDecoration: 'none' }} to={`/admin/EditCollection?collection=${item.id}`}> <Button startIcon={<EditRoundedIcon />} color="primary" variant="outlined" > Editar - </Button> + </Button> </Link> <Button @@ -198,7 +199,7 @@ const CollectionCard = ({ match }) => { </Button> </Grid> </Grid> - <div style={{height: "1em"}}/> + <div style={{ height: "1em" }} /> {DATA.map((info, index) => ( <div className={classes.displayColumn} key={index}> <Typography color="initial" className={classes.subTitle}> diff --git a/src/Admin/Components/Components/DataCards/CommunityQuestionCard.js b/src/Admin/Components/Components/DataCards/CommunityQuestionCard.js index 4ee4a1448f3a4f1efb90df90e9bcd63bd4164ffc..b8ae952c3dabc4ff4c7fd73ceb45a6d3123972b1 100644 --- a/src/Admin/Components/Components/DataCards/CommunityQuestionCard.js +++ b/src/Admin/Components/Components/DataCards/CommunityQuestionCard.js @@ -36,7 +36,7 @@ import Unauthorized from "../Unauthorized"; import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' import LoadingSpinner from '../../../../Components/LoadingSpinner'; -const CommunityQuestions = ({ match }) => { +const CommunityQuestions = () => { const { state } = useContext(Store); const classes = useStyles(); @@ -68,8 +68,10 @@ const CommunityQuestions = ({ match }) => { } useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const query = urlParams.get("question"); getRequest( - GetAData("contacts", match.params.id), + GetAData("contacts", query), (data, header) => { setItem(data); setIsLoaded(true); @@ -100,7 +102,7 @@ const CommunityQuestions = ({ match }) => { subTitle: "Email", prop: item.email ? - <Link to={`/admin/sendEmail/${item.email}`} style={{ textDecoration: 'none' }}> + <Link to={`/admin/sendEmail/?email=${item.email}`} style={{ textDecoration: 'none' }}> <Button variant='text' color='primary' diff --git a/src/Admin/Components/Components/DataCards/ComplaintsCard.js b/src/Admin/Components/Components/DataCards/ComplaintsCard.js index 17f7623e403413685bd15f2e2a56474f736b1dcd..4ac22b4eda29442a79606cc6b6a8751e718aa94a 100644 --- a/src/Admin/Components/Components/DataCards/ComplaintsCard.js +++ b/src/Admin/Components/Components/DataCards/ComplaintsCard.js @@ -51,8 +51,10 @@ import { getRequest, postRequest } from '../../../../Components/HelperFunctions/ const PORTAL_MEC = "https://plataformaintegrada.mec.gov.br/"; -const CollectionCard = ({ match }) => { +const CollectionCard = () => { const classes = useStyles(); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("id"); const [error, setError] = useState(null); //Necessary to consult the API, catch errors @@ -179,7 +181,7 @@ const CollectionCard = ({ match }) => { const reloadData = () => { setIsLoaded(false) getRequest( - GetAData("complaints", match.params.id), + GetAData("complaints", id), (data, header) => { setItem(data) setIsLoaded(true); @@ -212,7 +214,7 @@ const CollectionCard = ({ match }) => { HandleSnack('Alteração feito com sucesso!', true, 'success', '#228B22') reloadData() } - }, + }, (error) => { HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') } @@ -566,13 +568,12 @@ const CollectionCard = ({ match }) => { const HandleComplainObj = async (method) => { postRequest( - MethodsToComplain("complaints", match.params.id, method), + MethodsToComplain("complaints", id, method), {}, (data) => { if (data.errors) HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') - else - { + else { HandleSnack('Alteração feito com sucesso', true, 'success', '#228B22') reloadData() } @@ -595,7 +596,7 @@ const CollectionCard = ({ match }) => { useEffect(() => { getRequest( - GetAData("complaints", match.params.id), + GetAData("complaints", id), (data, header) => { setItem(data) setIsLoaded(true); @@ -685,7 +686,7 @@ const CollectionCard = ({ match }) => { > { - item.complainable_type === "User" ? `Usuário #${item.complainable_id}` : `Recurso #${item.complainable_id}` + item.complainable_type === "User" ? `Usuário #${item.complainable_id}` : `Recurso #${item.complainable_id}` } </Typography> </Grid> @@ -704,7 +705,7 @@ const CollectionCard = ({ match }) => { </Link> </Grid> </Grid> - <div style={{height: "1em"}}/> + <div style={{ height: "1em" }} /> {DATA.map((info, index) => ( <div className={classes.displayColumn} key={index}> <Typography color="initial" className={classes.subTitle}> diff --git a/src/Admin/Components/Components/DataCards/EducationalObjectsCard.js b/src/Admin/Components/Components/DataCards/EducationalObjectsCard.js index 493f577fa3f1b2a31a0724312e1c24923af61e98..08a8f3255e1015758e98373e8c2d7e25c70cd05e 100644 --- a/src/Admin/Components/Components/DataCards/EducationalObjectsCard.js +++ b/src/Admin/Components/Components/DataCards/EducationalObjectsCard.js @@ -41,9 +41,11 @@ import { } from "../../../../Components/HelperFunctions/getAxiosConfig"; import SnackBar from "../../../../Components/SnackbarComponent"; -const CommunityQuestions = ({ match }) => { +const CommunityQuestions = () => { const classes = useStyles(); let history = useHistory(); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("learnObj"); 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 @@ -73,7 +75,6 @@ const CommunityQuestions = ({ match }) => { }); async function DeleteHandler() { - const id = match.params.id; deleteRequest( DeleteFilter("learning_objects", id), (data) => { @@ -97,7 +98,7 @@ const CommunityQuestions = ({ match }) => { useEffect(() => { getRequest( - GetAData("learning_objects", match.params.id), + GetAData("learning_objects", id), (data, header) => { setItem(data); setIsLoaded(true); @@ -264,7 +265,7 @@ const CommunityQuestions = ({ match }) => { href={ apiUrl + "/learning_objects/" + - match.params.id + + id + "/download" } > @@ -273,7 +274,7 @@ const CommunityQuestions = ({ match }) => { </Button> <Link style={{ textDecoration: "none" }} - to={`/admin/learningObjectEdit/${item.id}`} + to={`/admin/learningObjectEdit?learnObj=${item.id}`} > <Button startIcon={<EditRoundedIcon />} @@ -293,7 +294,7 @@ const CommunityQuestions = ({ match }) => { </Button> </Grid> </Grid> - <div style={{height: "1em"}}/> + <div style={{ height: "1em" }} /> {item.thumbnail ? ( <div style={{ marginTop: "1em", marginBottom: "1em" }}> <a target="_blank" rel="noreferrer" href={apiDomain + item.thumbnail}> diff --git a/src/Admin/Components/Components/DataCards/InstitutionsCard.js b/src/Admin/Components/Components/DataCards/InstitutionsCard.js index 817fcfad40a7b73678cb2b9dfd6637df166980c7..b4981b7bb93715a8bbfa0bc94f8d85e628df3416 100644 --- a/src/Admin/Components/Components/DataCards/InstitutionsCard.js +++ b/src/Admin/Components/Components/DataCards/InstitutionsCard.js @@ -36,9 +36,12 @@ import { Link, useHistory } from 'react-router-dom'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; import SnackBar from '../../../../Components/SnackbarComponent'; -const InstitutionCard = ({ match }) => { +const InstitutionCard = () => { const classes = useStyles(); - let history = useHistory() + let history = useHistory(); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("institution"); + 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 @@ -68,7 +71,6 @@ const InstitutionCard = ({ match }) => { }); async function DeleteHandler() { - const id = match.params.id deleteRequest( DeleteFilter("institutions", id), (data) => { @@ -92,7 +94,7 @@ const InstitutionCard = ({ match }) => { useEffect(() => { getRequest( - GetAData('institutions', match.params.id), + GetAData('institutions', id), (data, header) => { setIsLoaded(true); setItem(data); @@ -176,7 +178,7 @@ const InstitutionCard = ({ match }) => { </Button> </Link> - <Link style={{ textDecoration: 'none' }} to={`/admin/institutionEdit/${item.id}`}> + <Link style={{ textDecoration: 'none' }} to={`/admin/institutionEdit?institution=${item.id}`}> <Button startIcon={<EditRoundedIcon />} color="primary" @@ -196,7 +198,7 @@ const InstitutionCard = ({ match }) => { </Button> </Grid> </Grid> - <div style={{height: "1em"}}/> + <div style={{ height: "1em" }} /> {DATA.map((info, index) => ( <div className={classes.displayColumn} key={index}> <Typography color="initial" className={classes.subTitle}> diff --git a/src/Admin/Components/Components/DataCards/NoteVarCard.js b/src/Admin/Components/Components/DataCards/NoteVarCard.js index 6b72bddfa0ebd118b13bba0dfc0866b135b14ae4..7c7b4356f9f174607e330987ee15081724b080e8 100644 --- a/src/Admin/Components/Components/DataCards/NoteVarCard.js +++ b/src/Admin/Components/Components/DataCards/NoteVarCard.js @@ -34,9 +34,10 @@ import { getRequest } from '../../../../Components/HelperFunctions/getAxiosConfi import { Link } from 'react-router-dom'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; -const NoteCard = ({ match }) => { - console.log(match); +const NoteCard = () => { const classes = useStyles(); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("id"); 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 @@ -52,7 +53,7 @@ const NoteCard = ({ match }) => { useEffect(() => { getRequest( - GetAData('scores', match.params.id), + GetAData('scores', id), (data, header) => { setIsLoaded(true); setItem(data); @@ -116,7 +117,7 @@ const NoteCard = ({ match }) => { </Button> </Link> - <Link style={{ textDecoration: 'none' }} to={`/admin/noteVarEdit/${item.id}`}> + <Link style={{ textDecoration: 'none' }} to={`/admin/noteVarEdit?id=${item.id}`}> <Button startIcon={<EditRoundedIcon />} color="primary" diff --git a/src/Admin/Components/Components/DataCards/RatingCard.js b/src/Admin/Components/Components/DataCards/RatingCard.js index c333b56c6c5946e87370693780eb622288338b7c..b5f69a53c800dce0324ec0afb274a97ce315fc8e 100644 --- a/src/Admin/Components/Components/DataCards/RatingCard.js +++ b/src/Admin/Components/Components/DataCards/RatingCard.js @@ -36,9 +36,11 @@ import { Link, useHistory } from 'react-router-dom'; import LoadingSpinner from '../../../../Components/LoadingSpinner'; import SnackBar from '../../../../Components/SnackbarComponent'; -const RatingCard = ({ match }) => { +const RatingCard = () => { const classes = useStyles(); - let history = useHistory() + let history = useHistory(); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("rating"); 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 @@ -68,7 +70,6 @@ const RatingCard = ({ match }) => { }; async function DeleteHandler() { - const id = match.params.id deleteRequest( DeleteFilter("ratings", id), (data) => { @@ -93,7 +94,7 @@ const RatingCard = ({ match }) => { useEffect(() => { getRequest( - GetAData('ratings', match.params.id), + GetAData('ratings', id), (data, header) => { setIsLoaded(true); setItem(data); @@ -165,7 +166,7 @@ const RatingCard = ({ match }) => { </Button> </Link> - <Link style={{ textDecoration: 'none' }} to={`/admin/EditRating/${item.id}`}> + <Link style={{ textDecoration: 'none' }} to={`/admin/EditRating?rating=${item.id}`}> <Button startIcon={<EditRoundedIcon />} color="primary" @@ -185,7 +186,7 @@ const RatingCard = ({ match }) => { </Button> </Grid> </Grid> - <div style={{height: "1em"}}/> + <div style={{ height: "1em" }} /> {DATA.map((info, index) => ( <div className={classes.displayColumn} key={index}> <Typography color="initial" className={classes.subTitle}> diff --git a/src/Admin/Components/Components/DataCards/UserCard.js b/src/Admin/Components/Components/DataCards/UserCard.js index d4e82906c3470fdaac4fbbbfd0308d5bd7baf0e3..a34f96b390a075eed4c3aed1a28b3baacc968734 100644 --- a/src/Admin/Components/Components/DataCards/UserCard.js +++ b/src/Admin/Components/Components/DataCards/UserCard.js @@ -45,9 +45,12 @@ import { getRequest, postRequest, deleteRequest, putRequest } from '../../../../ //styles import styled from 'styled-components'; -const CollectionCard = ({ match }, props) => { +const CollectionCard = () => { let history = useHistory() const classes = useStyles(); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("id"); + 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({}); @@ -138,7 +141,7 @@ const CollectionCard = ({ match }, props) => { const reloadData = () => { setIsLoaded(false) getRequest( - GetAData("users", match.params.id), + GetAData("users", id), (data, header) => { setItem(data) setIsLoaded(true); @@ -159,13 +162,12 @@ const CollectionCard = ({ match }, props) => { url, body, (data) => { - if(data.errors) + if (data.errors) HandleSnack("Erro!", true, "warning", "#FA8072"); - else - { + else { HandleSnack(`${userName} aceito como professor!`, true, "success", "#228B22"); reloadData() - } + } }, (error) => { HandleSnack("Erro!", true, "warning", "#FA8072"); @@ -182,13 +184,12 @@ const CollectionCard = ({ match }, props) => { url, body, (data) => { - if(data.errors) + if (data.errors) HandleSnack("Erro!", true, "warning", "#FA8072"); - else - { - HandleSnack(`${userName} rejeitado como professor!`, true, "success", "#228B22"); - reloadData() - } + else { + HandleSnack(`${userName} rejeitado como professor!`, true, "success", "#228B22"); + reloadData() + } }, (error) => { HandleSnack("Erro!", true, "warning", "#FA8072"); @@ -200,10 +201,9 @@ const CollectionCard = ({ match }, props) => { deleteRequest( `/users/${userId}`, (data) => { - if(data.errors) + if (data.errors) HandleSnack("Erro!", true, "warning", "#FA8072") - else - { + else { HandleSnack(`${item.name} deletado com sucesso!`, true, "success", "#228B22"); history.goBack() } @@ -243,8 +243,8 @@ const CollectionCard = ({ match }, props) => { </Button> ) } - return <Typography color="textSecondary"> - Usuário não bloqueado + return <Typography color="textSecondary"> + Usuário não bloqueado </Typography> } @@ -294,16 +294,15 @@ const CollectionCard = ({ match }, props) => { const ReactiveUser = () => { putRequest( - `/users/${match.params.id}/reactivate_user`, + `/users/${id}/reactivate_user`, {}, (data) => { - if(data.errors) + if (data.errors) HandleSnack('Erro ao tentar reativar usuário!', true, 'warning', '#FA8072') - else - { + else { HandleSnack('Usuário foi reativado com sucesso!', true, 'success', '#228B22') reloadData() - } + } }, (error) => { HandleSnack('Erro ao tentar reativar usuário!', true, 'warning', '#FA8072') @@ -313,7 +312,7 @@ const CollectionCard = ({ match }, props) => { useEffect(() => { getRequest( - GetAData("users", match.params.id), + GetAData("users", id), (data, header) => { setItem(data) setIsLoaded(true); @@ -390,7 +389,7 @@ const CollectionCard = ({ match }, props) => { </Button> </Grid> <Grid item> - <Link to={`/admin/EditUser/${item.id}`} style={{ textDecoration: "none" }}> + <Link to={`/admin/EditUser?id=${item.id}`} style={{ textDecoration: "none" }}> <Button startIcon={<EditRoundedIcon />} color="primary" @@ -425,7 +424,7 @@ const CollectionCard = ({ match }, props) => { </Typography> { item.email ? - <Link to={`/admin/sendEmail/${item.email}`} style={{ textDecoration: 'none' }}> + <Link to={`/admin/sendEmail?email=${item.email}`} style={{ textDecoration: 'none' }}> <Button variant='text' color='primary' diff --git a/src/Admin/Components/Components/Inputs/EditCollection.js b/src/Admin/Components/Components/Inputs/EditCollection.js index 67917eb60ac05c634de6f5b5bb0d9d317bdf2938..13aabcf16dac0ebc5f77ca965b60cfa6b5508395 100644 --- a/src/Admin/Components/Components/Inputs/EditCollection.js +++ b/src/Admin/Components/Components/Inputs/EditCollection.js @@ -38,14 +38,15 @@ import { Link } from 'react-router-dom'; import ClassicEditor from "@ckeditor/ckeditor5-build-classic" import { CKEditor } from '@ckeditor/ckeditor5-react'; -const EditCollection = ({ match }) => { +const EditCollection = () => { const { state } = useContext(Store); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("collection"); 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 [isLoading, setIsLoading] = useState(false); - const id = match.params.id const [name, setName] = useState('') const [privacy, setPrivacy] = useState('') const [description, setDescription] = useState(''); @@ -149,10 +150,10 @@ const EditCollection = ({ match }) => { api, body, (data) => { - if(data.errors){ + if (data.errors) { HandleSnack(`${data.errors[0]}`, true, 'warning', '#FA8072') } - else{ + else { HandleSnack('A Coleção foi alterada com sucesso', true, 'success', '#228B22') } setIsLoading(false) @@ -166,7 +167,7 @@ const EditCollection = ({ match }) => { useEffect(() => { getRequest( - GetAData("collections", match.params.id), + GetAData("collections", id), (data, header) => { setIsLoaded(true); setError(false); diff --git a/src/Admin/Components/Components/Inputs/EditEducationalObect.js b/src/Admin/Components/Components/Inputs/EditEducationalObect.js index f5eca6838ec49afecb190b9cff6928b7a475352c..5996383029e0fc08a2b770c8fe7aa32a6b6f2b9e 100644 --- a/src/Admin/Components/Components/Inputs/EditEducationalObect.js +++ b/src/Admin/Components/Components/Inputs/EditEducationalObect.js @@ -62,14 +62,14 @@ const useStyles = makeStyles((theme) => ({ let text; -const EditEducationalObject = ({ match }) => { +const EditEducationalObject = () => { const { state } = useContext(Store); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("learnObj"); const theme = useTheme(); const classes = useStyles(); - const id = match.params.id; - 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 [isLoading, setIsLoading] = useState(false); //is loading to submit @@ -275,7 +275,7 @@ const EditEducationalObject = ({ match }) => { "#228B22" ); } else { - if(data.errors){ + if (data.errors) { HandleSnack(`${data.errors[0]}`, true, 'warning', '#FA8072') } if (data.author) { @@ -399,7 +399,7 @@ const EditEducationalObject = ({ match }) => { useEffect(() => { const urls = [ - `/learning_objects/${match.params.id}`, + `/learning_objects/${id}`, "/languages", "/object_types", ]; diff --git a/src/Admin/Components/Components/Inputs/EditLanguage.js b/src/Admin/Components/Components/Inputs/EditLanguage.js index 8215429e0c0a0f0cbcedbccf9122295dd5b3e970..44df71ceed76a2846983700ced3f66f60143e7e4 100644 --- a/src/Admin/Components/Components/Inputs/EditLanguage.js +++ b/src/Admin/Components/Components/Inputs/EditLanguage.js @@ -37,15 +37,16 @@ import DeleteRoundedIcon from "@material-ui/icons/DeleteRounded"; import { Link, useHistory } from 'react-router-dom'; import Unauthorized from '../Unauthorized'; -const EditLanguage = ({ match }) => { +const EditLanguage = () => { const { state } = useContext(Store); let history = useHistory() + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("language"); 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 [isLoading, setIsLoading] = useState(false); - const id = match.params.id const [name, setName] = useState() const [code, setCode] = useState() @@ -67,7 +68,6 @@ const EditLanguage = ({ match }) => { }) async function DeleteHandler() { - const id = match.params.id deleteRequest( DeleteFilter("languages", id), (data) => { @@ -180,7 +180,7 @@ const EditLanguage = ({ match }) => { if (data.id) HandleSnack('A linguagem foi alterada com sucesso!', true, 'success', '#228B22') else { - if(data.errors){ + if (data.errors) { HandleSnack(`${data.errors[0]}`, true, 'warning', '#FA8072') } if (data.name) { @@ -215,7 +215,7 @@ const EditLanguage = ({ match }) => { useEffect(() => { getRequest( - GetAData("languages", match.params.id), + GetAData("languages", id), (data, header) => { setIsLoaded(true); setName(data.name) diff --git a/src/Admin/Components/Components/Inputs/EditRating.js b/src/Admin/Components/Components/Inputs/EditRating.js index a42363d639aacd2ea9051c60eb07f02e0ef23075..1b8e0e6fd7c2c054f389dd7f62316778c4aebfa1 100644 --- a/src/Admin/Components/Components/Inputs/EditRating.js +++ b/src/Admin/Components/Components/Inputs/EditRating.js @@ -33,17 +33,18 @@ import LoadingSpinner from '../../../../Components/LoadingSpinner'; import { getRequest, putRequest } from '../../../../Components/HelperFunctions/getAxiosConfig' import { EditFilter, GetAData } from '../../../Filters'; //routers -import {Link} from 'react-router-dom'; +import { Link } from 'react-router-dom'; import Unauthorized from '../Unauthorized'; -const EditRating = ({ match }) => { +const EditRating = () => { const { state } = useContext(Store); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("rating"); 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 [isLoading, setIsLoading] = useState(false); - const id = match.params.id const [name, setName] = useState() const [description, setDescription] = useState() @@ -161,7 +162,7 @@ const EditRating = ({ match }) => { api, body, (data, header) => { - if(data.errors) + if (data.errors) HandleSnack('Ocorreu algum erro', true, 'warning', '#FA8072') else HandleSnack('O rating foi alterada com sucesso', true, 'success', '#228B22') @@ -193,7 +194,7 @@ const EditRating = ({ match }) => { useEffect(() => { getRequest( - GetAData("ratings", match.params.id), + GetAData("ratings", id), (data, header) => { setIsLoaded(true); setName(data.name) @@ -209,8 +210,8 @@ const EditRating = ({ 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 @@ -233,7 +234,7 @@ const EditRating = ({ match }) => { </Typography> </Grid> <Grid item> - <Link style={{textDecoration: 'none'}} to={'/admin/Ratings'}> + <Link style={{ textDecoration: 'none' }} to={'/admin/Ratings'}> <Button startIcon={<ListRoundedIcon />} variant='outlined' @@ -282,7 +283,7 @@ const EditRating = ({ match }) => { </CardAction> </Card> ) - } else return <Unauthorized/> + } else return <Unauthorized /> } export default EditRating; \ No newline at end of file diff --git a/src/Admin/Components/Components/Inputs/EditRoles.js b/src/Admin/Components/Components/Inputs/EditRoles.js index 9b2ecaa148bbc29ba1c0a7aefa5da22111767042..d08e14b223a4562385206878d12e971ef2bc6dec 100644 --- a/src/Admin/Components/Components/Inputs/EditRoles.js +++ b/src/Admin/Components/Components/Inputs/EditRoles.js @@ -38,15 +38,16 @@ import { EditFilter, GetAData, DeleteFilter } from '../../../Filters'; import { Link, useHistory } from 'react-router-dom'; import Unauthorized from '../Unauthorized'; -const EditLanguage = ({ match }) => { +const EditLanguage = () => { const { state } = useContext(Store); let history = useHistory() + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("role"); 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 [isLoading, setIsLoading] = useState(false); - const id = match.params.id const [name, setName] = useState() const [desc, setDesc] = useState() const [snackInfo, setSnackInfo] = useState({ @@ -157,7 +158,7 @@ const EditLanguage = ({ match }) => { if (data.id) HandleSnack('A role foi alterada com sucesso', true, 'success', '#228B22') else { - if(data.errors){ + if (data.errors) { HandleSnack(`${data.errors[0]}`, true, 'warning', '#FA8072') } if (data.name) { @@ -182,7 +183,6 @@ const EditLanguage = ({ match }) => { } async function DeleteHandler() { - const id = match.params.id deleteRequest( DeleteFilter("roles", id), (data) => { @@ -206,7 +206,7 @@ const EditLanguage = ({ match }) => { useEffect(() => { getRequest( - GetAData("roles", match.params.id), + GetAData("roles", id), (data, header) => { setIsLoaded(true); setName(data.name) diff --git a/src/Admin/Components/Components/Inputs/EditUser.js b/src/Admin/Components/Components/Inputs/EditUser.js index 73a42e96bf77ee04eb29cefc25ba18c305b91cf0..fe9a61c8931170c9685afa20e5a1ac118d569511 100644 --- a/src/Admin/Components/Components/Inputs/EditUser.js +++ b/src/Admin/Components/Components/Inputs/EditUser.js @@ -57,11 +57,12 @@ const useStyles = makeStyles((theme) => ({ }, })); -const EditUser = ({ match }) => { +const EditUser = () => { const classes = useStyles(); let history = useHistory(); const { state } = useContext(Store) - const id = match.params.id + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("id"); const [error, setError] = useState(id !== "-1" ? null : false); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(id === "-1" ? true : false); //Necessary to consult the API, wait until complete diff --git a/src/Admin/Components/Components/Inputs/IntitutionsInputs.js b/src/Admin/Components/Components/Inputs/IntitutionsInputs.js index a4098e68855cea0deacccf7705205923e740c818..47031b7b9ff32d85315348767544275ef45ac193 100644 --- a/src/Admin/Components/Components/Inputs/IntitutionsInputs.js +++ b/src/Admin/Components/Components/Inputs/IntitutionsInputs.js @@ -39,7 +39,7 @@ import { Link } from 'react-router-dom'; let id; -const EditInstitution = ({ match }) => { +const EditInstitution = () => { const { state } = useContext(Store); const [error, setError] = useState(null); //Necessary to consult the API, catch errors @@ -98,7 +98,7 @@ const EditInstitution = ({ match }) => { } setCountry(e.target.value) } - + // Handle snack infos const HandleSnack = (message, state, icon, color) => { setSnackInfo({ @@ -145,7 +145,7 @@ const EditInstitution = ({ match }) => { if (data.id) HandleSnack('A instituição foi criada com sucesso!', true, 'success', '#228B22') else { - if(data.errors){ + if (data.errors) { HandleSnack(`${data.errors[0]}`, true, 'warning', '#FA8072') } if (data.name) { @@ -209,8 +209,10 @@ const EditInstitution = ({ match }) => { ] useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("institution"); getRequest( - GetAData("institutions", match.params.id), + GetAData("institutions", id), (data, header) => { setIsLoaded(true); setName(data.name) @@ -218,7 +220,6 @@ const EditInstitution = ({ match }) => { setAdress(data.adress) setCity(data.city) setCountry(data.country) - id = data.id }, (error) => { setIsLoaded(true); diff --git a/src/Admin/Components/Components/Inputs/NoteVarInputs.js b/src/Admin/Components/Components/Inputs/NoteVarInputs.js index 8753d1a21b214342965e7bbc9f6cbc0427ab8f40..3cc63a702065bdf5b35bc1eef5f1af8989eeec2b 100644 --- a/src/Admin/Components/Components/Inputs/NoteVarInputs.js +++ b/src/Admin/Components/Components/Inputs/NoteVarInputs.js @@ -37,14 +37,15 @@ import { EditFilter, GetAData } from '../../../Filters'; import { Link } from 'react-router-dom'; import Unauthorized from '../Unauthorized'; -const NoteVarInputs = ({ match }) => { +const NoteVarInputs = () => { const { state } = useContext(Store); + const urlParams = new URLSearchParams(window.location.search); + const id = urlParams.get("id"); 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 [isLoading, setIsLoading] = useState(false); - const id = match.params.id const [name, setName] = useState() const [code, setCode] = useState() const [weight, setWeight] = useState() @@ -217,7 +218,7 @@ const NoteVarInputs = ({ match }) => { useEffect(() => { getRequest( - GetAData("scores", match.params.id), + GetAData("scores", id), (data, header) => { setIsLoaded(true); setName(data.name) diff --git a/src/Admin/Components/Components/Table.js b/src/Admin/Components/Components/Table.js index 5e74b53f158fc26f834a67b9aa2658721ef6e448..ddb7a377b4fea041f52c881835700312b7f8e6c8 100644 --- a/src/Admin/Components/Components/Table.js +++ b/src/Admin/Components/Components/Table.js @@ -23,23 +23,7 @@ const StyledTableCell = withStyles((theme) => ({ const useStyles = makeStyles({ table: { minWidth: 700, - width : "100%" - }, - root: { - minWidth: 275, - boxShadow: '2px 2px 1px #A9A9A9' - }, - bullet: { - display: 'inline-block', - margin: '0 2px', - transform: 'scale(0.8)', - }, - title: { - fontSize: 28, - fontWeight: "500" - }, - pos: { - marginBottom: 12, + width: "100%" }, }); @@ -53,12 +37,13 @@ const TableData = (props) => { <TableRow> { props.top.map((top, index) => ( - index === 0 ? + top === "ID" ? <StyledTableCell key={index}> <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}> {top} { - props.onIconPressed === undefined ? <div></div> : <IconButton onClick={props.onIconPressed} color='primary'> + props.onIconPressed && + <IconButton onClick={props.onIconPressed} color='primary'> <FilterListRoundedIcon style={{ color: 'white' }} /> </IconButton> } diff --git a/src/Admin/Pages/AdminLabelTabs/LabelTabs.js b/src/Admin/Pages/AdminLabelTabs/LabelTabs.js index 1c7e9ac592642dda7ccba3bb2077472457896219..9b2894cdd76621ad349aa9fa4fd02012c25e1e7e 100644 --- a/src/Admin/Pages/AdminLabelTabs/LabelTabs.js +++ b/src/Admin/Pages/AdminLabelTabs/LabelTabs.js @@ -119,7 +119,7 @@ const TabsItens = [ }, { label: "Enviar email", - href: '/admin/sendEmail/none', + href: '/admin/sendEmail?email=none', icon: <EmailRoundedIcon style={{ fill: blue }} />, }, ]; diff --git a/src/Admin/Pages/Pages/SubPages/Activity.js b/src/Admin/Pages/Pages/SubPages/Activity.js index 6cb62ff13efb698fa0b3d2dc64a57356bbc3eccf..54d37dc49c7cc536855b7d26a08aa82a61502c2b 100644 --- a/src/Admin/Pages/Pages/SubPages/Activity.js +++ b/src/Admin/Pages/Pages/SubPages/Activity.js @@ -245,10 +245,10 @@ const Activity = () => { {items.map((row, index) => index === items.length - 1 ? ( <StyledDivButton - key="Load more" + key={new Date().toISOString() + row.created_at} > <Button - key={index} + key={new Date().toISOString() + row.created_at} color="primary" variant="text" // disabled={isLoadingMoreItems} @@ -268,12 +268,12 @@ const Activity = () => { ) : ( <> <MobileList - key={index} + key={new Date().toISOString() + row.created_at} title={row.id} subtitle={row.privacy} backColor={"#673ab7"} avatar={<AllOutIcon />} - href={`/admin/activity/${row.id}`} + href={`/admin/activity?activity=${row.id}`} reset={() => { }} @@ -371,7 +371,7 @@ const Activity = () => { <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow key={row.created_at} style={{ padding: "1em" }}> + <StyledTableRow key={new Date().toISOString() + row.created_at} style={{ padding: "1em" }}> {/* Button to load more data */} <StyledTableCell> <Button @@ -393,7 +393,7 @@ const Activity = () => { </StyledTableCell> </StyledTableRow> ) : ( - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row"> {DisplayDate(row.created_at)} </StyledTableCell> @@ -407,7 +407,7 @@ const Activity = () => { </StyledTableCell> <StyledTableCell align="right">{row.privacy}</StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/activity/${row.id}`}> + <Link to={`/admin/activity?activity=${row.id}`}> <IconButton> <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/AproveTeacher.js b/src/Admin/Pages/Pages/SubPages/AproveTeacher.js index c6078dba1293b6162d2b239c68db184fa7707625..8fae644f5c26e5aa072f16a14bf578081629f986 100644 --- a/src/Admin/Pages/Pages/SubPages/AproveTeacher.js +++ b/src/Admin/Pages/Pages/SubPages/AproveTeacher.js @@ -85,6 +85,7 @@ const AproveTeacher = () => { "AÇÕES", ]; //Labels from Table + const [invertList, setInvertList] = useState(false) const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -273,25 +274,31 @@ const AproveTeacher = () => { ); }; - const buildUrl = (email, submitter_request, name) => { + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + + const buildUrl = (email, submitter_request, name, direction) => { if (email && submitter_request && name) - return Url("users", `"submitter_request" : "${submitter_request}", "email" : "${email}", "name" : "${name}"`, currPage, "DESC") + return Url("users", `"submitter_request" : "${submitter_request}", "email" : "${email}", "name" : "${name}"`, currPage, direction) else if (email && name) - return Url("users", `"email" : "${email}", "name" : "${name}"`, currPage, "DESC") + return Url("users", `"email" : "${email}", "name" : "${name}"`, currPage, direction) else if (email && submitter_request) - return Url("users", `"email" : "${email}", "submitter_request" : "${submitter_request}"`, currPage, "DESC") + return Url("users", `"email" : "${email}", "submitter_request" : "${submitter_request}"`, currPage, direction) else if (name && submitter_request) - return Url("users", `"name" : "${name}", "submitter_request" : "${submitter_request}"`, currPage, "DESC") + return Url("users", `"name" : "${name}", "submitter_request" : "${submitter_request}"`, currPage, direction) else if (email) - return Url("users", `"email" : "${email}"`, currPage, "DESC") + return Url("users", `"email" : "${email}"`, currPage, direction) else if (submitter_request) - return Url("users", `"submitter_request" : "${submitter_request}"`, currPage, "DESC") + return Url("users", `"submitter_request" : "${submitter_request}"`, currPage, direction) else if (name) - return Url("users", `"name" : ${name}`, currPage, "DESC") + return Url("users", `"name" : ${name}`, currPage, direction) else - return Url("users", "", currPage, "DESC") + return Url("users", "", currPage, direction) } useEffect(() => { @@ -300,7 +307,7 @@ const AproveTeacher = () => { else setIsLoadingMoreItems(true) getRequest( - buildUrl(email, option, name), + buildUrl(email, option, name, invertList ? "ASC" : "DESC"), (data, header) => { const arrData = [...data] if (arrData.length === 0) { @@ -326,7 +333,7 @@ const AproveTeacher = () => { setError(true) } ) - }, [currPage, option, email, name]) + }, [currPage, option, email, name, invertList]) useEffect(() => { setOption("requested") @@ -376,6 +383,13 @@ const AproveTeacher = () => { setShowFilter(!showFilter); }, icon: <FilterListRoundedIcon /> + }, + { + name: "Inverter lista", + isLoading: false, + func: () => { + cleanArrayAndInvert() + }, } ]} > @@ -441,7 +455,7 @@ const AproveTeacher = () => { index === items.length - 1 ? ( <StyledDivButton> <Button - key={index} + key={new Date().toISOString() + row.created_at} color="primary" variant="text" // disabled={isLoadingMoreItems} @@ -461,7 +475,7 @@ const AproveTeacher = () => { ) : ( <> <MobileList - key={index} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.id} backColor={"#00bcd4"} @@ -476,7 +490,7 @@ const AproveTeacher = () => { }} /> } - href={`/admin/user/${row.id}`} + href={`/admin/user?id=${row.id}`} reset={() => { }} @@ -484,7 +498,7 @@ const AproveTeacher = () => { { title: "Email", subtitle: row.email ? - <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> + <Link to={`/admin/sendEmail?email=${row.email}`} style={{ textDecoration: 'none' }}> <Button variant='text' color='primary' @@ -647,11 +661,14 @@ const AproveTeacher = () => { <div style={{ height: "2em" }}></div> <Grid xs={12} container> - <TableData top={TOP_LABELS}> + <TableData + top={TOP_LABELS} + onIconPressed={cleanArrayAndInvert} + > <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -674,7 +691,7 @@ const AproveTeacher = () => { </StyledTableRow> ) : ( <StyledTableRow - key={index} + key={new Date().toISOString() + row.created_at} style={{ flex: 1, width: "100%" }} > <StyledTableCell component="th" scope="row"> @@ -691,7 +708,7 @@ const AproveTeacher = () => { {DisplayDate(row.created_at)} </StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/user/${row.id}`}> + <Link to={`/admin/user?id=${row.id}`}> <IconButton> <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js index ac2f09de0a5fb6d08a5b9aab54a8dd2191a8131a..e6083f390eda6f8eb98cd943907216ec56968dcb 100644 --- a/src/Admin/Pages/Pages/SubPages/BlockedUsers.js +++ b/src/Admin/Pages/Pages/SubPages/BlockedUsers.js @@ -71,6 +71,7 @@ const BlockedUsers = () => { const ADD_ONE_LENGHT = ['']; const WINDOW_WIDTH = window.innerWidth + const [invertList, setInvertList] = useState(false) const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -190,13 +191,19 @@ const BlockedUsers = () => { .toString(); }; + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + useEffect(() => { if (currPage === 0) setIsLoaded(false) else setIsLoadingMoreItems(true) getRequest( - Url('users', `"state" : ${stateOpt}`, currPage, 'DESC'), + Url('users', `"state" : ${stateOpt}`, currPage, invertList ? "ASC" : 'DESC'), (data, header) => { const arrData = [...data] @@ -223,7 +230,7 @@ const BlockedUsers = () => { setError(true) } ) - }, [currPage, stateOpt]) + }, [currPage, stateOpt, invertList]) if (error) { return <div>Error: {error.message}</div>; @@ -259,6 +266,13 @@ const BlockedUsers = () => { }, icon: <UpdateRoundedIcon /> }, + { + name: "Inverter lista", + isLoading: false, + func: () => { + cleanArrayAndInvert() + }, + }, ]} > <Grid item> @@ -287,7 +301,7 @@ const BlockedUsers = () => { index === items.length - 1 ? ( <StyledDivButton> <Button - key={index} + key={new Date().toISOString() + row.created_at} color="primary" variant="text" // disabled={isLoadingMoreItems} @@ -307,7 +321,7 @@ const BlockedUsers = () => { ) : ( <> <MobileList - key={index} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.id} backColor={"#e81f4f"} @@ -322,7 +336,7 @@ const BlockedUsers = () => { }} /> } - href={`/admin/user/${row.id}`} + href={`/admin/user?id=${row.id}`} reset={() => { }} data={ @@ -330,7 +344,7 @@ const BlockedUsers = () => { { title: "Email", subtitle: row.email ? - <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> + <Link to={`/admin/sendEmail?email=${row.email}`} style={{ textDecoration: 'none' }}> <Button variant='text' color='primary' @@ -419,11 +433,12 @@ const BlockedUsers = () => { <TableData top={topTable} + onIconPressed={cleanArrayAndInvert} > <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -444,7 +459,7 @@ const BlockedUsers = () => { : - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row">{row.id}</StyledTableCell> <StyledTableCell align="right"> {BlockStatus(row.state)} @@ -453,7 +468,7 @@ const BlockedUsers = () => { <StyledTableCell align="right"> { row.email ? - <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> + <Link to={`/admin/sendEmail?email=${row.email}`} style={{ textDecoration: 'none' }}> <Button variant='text' color='primary' @@ -477,7 +492,7 @@ const BlockedUsers = () => { > Desbloquear </Button> - <Link to={`/admin/user/${row.id}`}> + <Link to={`/admin/user?id=${row.id}`}> <Button style={{ width: "100%" }} variant="contained" diff --git a/src/Admin/Pages/Pages/SubPages/Collections.js b/src/Admin/Pages/Pages/SubPages/Collections.js index 493d50a296f8fe1e4b9d104f8802e63596a97b5e..b312aa5306aa8feaca26308fa44e3c9e40931752 100644 --- a/src/Admin/Pages/Pages/SubPages/Collections.js +++ b/src/Admin/Pages/Pages/SubPages/Collections.js @@ -350,7 +350,7 @@ const Collections = () => { {items.map((row, index) => index === items.length - 1 ? ( <StyledDivButton - key="Load more" + key={new Date().toISOString() + row.created_at} > <Button color="primary" @@ -372,12 +372,12 @@ const Collections = () => { ) : ( <> <MobileList - key={index} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.privacy} backColor={"#e81f4f"} avatar={<PeopleRoundedIcon />} - href={`/admin/Collection/${row.id}`} + href={`/admin/Collection?collection=${row.id}`} reset={() => { }} @@ -517,10 +517,9 @@ const Collections = () => { <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow key={row.created_at}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell> <Button - key={index} color="primary" variant="text" // disabled={isLoadingMoreItems} @@ -539,7 +538,7 @@ const Collections = () => { </StyledTableCell> </StyledTableRow> ) : ( - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row"> {row.name} </StyledTableCell> @@ -559,7 +558,7 @@ const Collections = () => { </StyledTableCell> <StyledTableCell align="right">{row.privacy}</StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/Collection/${row.id}`}> + <Link to={`/admin/Collection?collection=${row.id}`}> <IconButton> <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js b/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js index 52bc6b89eef14542f1ff4628f02c719f2d73518e..029c566aa70ca0564e1ac9341716f02bf8e5a155 100644 --- a/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js +++ b/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js @@ -85,6 +85,7 @@ const CommunityQuestion = () => { const [currPage, setCurrPage] = useState(0) //Works with the filter + const [invertList, setInvertList] = useState(false) const [showFilter, setShowFilter] = useState(false) const [valueOfMessageField, setValueOfMessageField] = useState("") const [message, setMessage] = useState(""); @@ -132,25 +133,31 @@ const CommunityQuestion = () => { .toString(); }; - const buildUrl = (message, email, name) => { + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + + const buildUrl = (message, email, name, direction) => { if (message && email && name) - return Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : "${name}"`, currPage, "DESC") + return Url("contacts", `"message" : "${message}", "email" : "${email}", "name" : "${name}"`, currPage, direction) else if (message && name) - return Url("contacts", `"message" : "${message}", "name" : "${name}"`, currPage, "DESC") + return Url("contacts", `"message" : "${message}", "name" : "${name}"`, currPage, direction) else if (message && email) - return Url("contacts", `"message" : "${message}", "email" : "${email}"`, currPage, "DESC") + return Url("contacts", `"message" : "${message}", "email" : "${email}"`, currPage, direction) else if (name && email) - return Url("contacts", `"name" : "${name}", "email" : "${email}"`, currPage, "DESC") + return Url("contacts", `"name" : "${name}", "email" : "${email}"`, currPage, direction) else if (message) - return Url("contacts", `"message" : "${message}"`, currPage, "DESC") + return Url("contacts", `"message" : "${message}"`, currPage, direction) else if (email) - return Url("contacts", `"email" : "${email}"`, currPage, "DESC") + return Url("contacts", `"email" : "${email}"`, currPage, direction) else if (name) - return Url("contacts", `"name" : "${name}"`, currPage, "DESC") + return Url("contacts", `"name" : "${name}"`, currPage, direction) else - return Url("contacts", "", currPage, "DESC") + return Url("contacts", "", currPage, direction) } useEffect(() => { @@ -159,7 +166,7 @@ const CommunityQuestion = () => { else setIsLoadingMoreItems(true) getRequest( - buildUrl(message, email, name), + buildUrl(message, email, name, invertList ? "ASC" : "DESC"), (data, header) => { const arrData = [...data] if (arrData.length === 0) { @@ -185,7 +192,7 @@ const CommunityQuestion = () => { setError(true) } ) - }, [currPage, message, email, name]) + }, [currPage, message, email, name, invertList]) useEffect(() => { setCurrPage(0) @@ -237,6 +244,13 @@ const CommunityQuestion = () => { setShowFilter(!showFilter); }, icon: <FilterListRoundedIcon /> + }, + { + name: "Inverter lista de dados", + isLoading: false, + func: () => { + cleanArrayAndInvert() + }, } ]} > @@ -316,7 +330,7 @@ const CommunityQuestion = () => { subtitle={row.id} backColor={"#00bcd4"} avatar={<ContactSupportRoundedIcon />} - href={`/admin/CommunityQuestion/${row.id}`} + href={`/admin/CommunityQuestion?question=${row.id}`} reset={() => { }} data={ @@ -325,7 +339,7 @@ const CommunityQuestion = () => { title: "Email", subtitle: row.email ? - <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> + <Link to={`/admin/sendEmail?email=${row.email}`} style={{ textDecoration: 'none' }}> <Button variant='text' color='primary' @@ -439,7 +453,7 @@ const CommunityQuestion = () => { <div style={{ height: "2em" }}></div> - <TableData top={TOP_LABELS}> + <TableData top={TOP_LABELS} onIconPressed={cleanArrayAndInvert}> <TableBody> {items.map((row, index) => index === items.length - 1 ? ( @@ -477,7 +491,7 @@ const CommunityQuestion = () => { <StyledTableCell align="right"> { row.email ? - <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> + <Link to={`/admin/sendEmail?email=${row.email}`} style={{ textDecoration: 'none' }}> <Button variant='text' color='primary' @@ -492,7 +506,7 @@ const CommunityQuestion = () => { {row.message} </StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/CommunityQuestion/${row.id}`}> + <Link to={`/admin/CommunityQuestion?question=${row.id}`}> <IconButton> <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/Complaints.js b/src/Admin/Pages/Pages/SubPages/Complaints.js index d2fb9de2e76587bd85e3b688379757c95aeba8fe..2c8dff2e776f72dd9bcfa6f3318edb3b5a27aa61 100644 --- a/src/Admin/Pages/Pages/SubPages/Complaints.js +++ b/src/Admin/Pages/Pages/SubPages/Complaints.js @@ -80,6 +80,7 @@ const Complaints = () => { "VISITAR", ]; //Labels from Table + const [invertList, setInvertList] = useState(false) const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -207,25 +208,31 @@ const Complaints = () => { .toString(); }; - const buildUrl = (complainOpt, state, description) => { + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + + const buildUrl = (complainOpt, state, description, direction) => { if (complainOpt && (state >= 0 && state <= 2) && description) - return Url("complaints", `"state" : ${state}, "complaint_reason_id" : ${complainOpt}, "description" : "${description}"`, currPage, "DESC") + return Url("complaints", `"state" : ${state}, "complaint_reason_id" : ${complainOpt}, "description" : "${description}"`, currPage, direction) else if (complainOpt && description) - return Url("complaints", `"complaint_reason_id" : ${complainOpt}, "description" : "${description}"`, currPage, "DESC") + return Url("complaints", `"complaint_reason_id" : ${complainOpt}, "description" : "${description}"`, currPage, direction) else if (complainOpt && (state >= 0 && state <= 2)) - return Url("complaints", `"complaint_reason_id" : ${complainOpt}, "state" : ${state}`, currPage, "DESC") + return Url("complaints", `"complaint_reason_id" : ${complainOpt}, "state" : ${state}`, currPage, direction) else if (description && (state >= 0 && state <= 2)) - return Url("complaints", `"description" : "${description}", "state" : ${state}`, currPage, "DESC") + return Url("complaints", `"description" : "${description}", "state" : ${state}`, currPage, direction) else if (complainOpt) - return Url("complaints", `"complaint_reason_id" : ${complainOpt}`, currPage, "DESC") + return Url("complaints", `"complaint_reason_id" : ${complainOpt}`, currPage, direction) else if (state >= 0 && state <= 2) - return Url("complaints", `"state" : ${state}`, currPage, "DESC") + return Url("complaints", `"state" : ${state}`, currPage, direction) else if (description) - return Url("complaints", `"description" : ${description}`, currPage, "DESC") + return Url("complaints", `"description" : ${description}`, currPage, direction) else - return Url("complaints", "", currPage, "DESC") + return Url("complaints", "", currPage, direction) } useEffect(() => { @@ -234,7 +241,7 @@ const Complaints = () => { else setIsLoadingMoreItems(true) getRequest( - buildUrl(complainOption, stateOption, description), + buildUrl(complainOption, stateOption, description, invertList ? "ASC" : "DESC"), (data, header) => { const arrData = [...data] if (arrData.length === 0) { @@ -260,7 +267,7 @@ const Complaints = () => { setError(true) } ) - }, [currPage, complainOption, stateOption, description]) + }, [currPage, complainOption, stateOption, description, invertList]) useEffect(() => { setComplainOption() @@ -310,6 +317,13 @@ const Complaints = () => { setShowFilter(!showFilter); }, icon: <FilterListRoundedIcon /> + }, + { + name: "Inverter lista", + isLoading: false, + func: () => { + cleanArrayAndInvert() + }, } ]} > @@ -373,7 +387,7 @@ const Complaints = () => { {items.map((row, index) => index === items.length - 1 ? ( <StyledDivButton - key="Load more items" + key={new Date().toISOString() + row.created_at} > <Button color="primary" @@ -395,12 +409,12 @@ const Complaints = () => { ) : ( <> <MobileList - key={row.created_at} + key={new Date().toISOString() + row.created_at} title={row.complainable_type} subtitle={row.id} backColor={"#673ab7"} avatar={<AnnouncementRoundedIcon />} - href={`/admin/complaint/${row.id}`} + href={`/admin/complaint?id=${row.id}`} reset={() => { }} @@ -530,11 +544,14 @@ const Complaints = () => { <div style={{ height: "2em" }}></div> <Grid xs={12} container> - <TableData top={TOP_LABELS}> + <TableData + top={TOP_LABELS} + onIconPressed={cleanArrayAndInvert} + > <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow key={row.created_at}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -557,7 +574,7 @@ const Complaints = () => { </StyledTableRow> ) : ( <StyledTableRow - key={index} + key={new Date().toISOString() + row.created_at} style={{ flex: 1, width: "100%" }} > <StyledTableCell component="th" scope="row"> @@ -577,7 +594,7 @@ const Complaints = () => { {DisplayDate(row.created_at)} </StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/complaint/${row.id}`}> + <Link to={`/admin/complaint?id=${row.id}`}> <IconButton onClick={() => { }} diff --git a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js index 837797d4763d6e382f5e583f4b4c885dfa945cd7..612272ca0f7b7187e9426ef3fbc3e2145fda3692 100644 --- a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js +++ b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js @@ -369,7 +369,7 @@ const EducationalObjects = () => { index === items.length - 1 ? ( <StyledDivButton> <Button - key={index} + key={new Date().toISOString() + row.created_at} color="primary" variant="text" // disabled={isLoadingMoreItems} @@ -389,12 +389,12 @@ const EducationalObjects = () => { ) : ( <> <MobileList - key={index} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.id} backColor={"#673ab7"} avatar={<MenuBookRoundedIcon />} - href={`/admin/learningObject/${row.id}`} + href={`/admin/learningObject?learnObj=${row.id}`} reset={() => { }} @@ -511,7 +511,7 @@ const EducationalObjects = () => { <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -534,7 +534,7 @@ const EducationalObjects = () => { </StyledTableCell> </StyledTableRow> ) : ( - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row"> {DisplayDate(row.created_at)} </StyledTableCell> @@ -551,7 +551,7 @@ const EducationalObjects = () => { {row.score} </StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/learningObject/${row.id}`}> + <Link to={`/admin/learningObject?learnObj=${row.id}`}> <IconButton> <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/Institutions.js b/src/Admin/Pages/Pages/SubPages/Institutions.js index 24d099a696fc1670b8bd0f21b59fff79cd6a0129..93d0af1a1cc4f7c6a789f85351ff5d593e37f3e8 100644 --- a/src/Admin/Pages/Pages/SubPages/Institutions.js +++ b/src/Admin/Pages/Pages/SubPages/Institutions.js @@ -74,7 +74,8 @@ const Institutions = () => { const ADD_ONE_LENGHT = [""]; const router = useHistory() - + + const [invertList, setInvertList] = useState(false) const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -185,8 +186,14 @@ const Institutions = () => { } } + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + const buildUrl = () => { - return Url("institutions", `"name" : "${search}", "description" : "${description}", "city" : "${city}", "country" : "${country}"`, currPage, "DESC") + return Url("institutions", `"name" : "${search}", "description" : "${description}", "city" : "${city}", "country" : "${country}"`, currPage, invertList ? "ASC" : "DESC") } useEffect(() => { @@ -221,7 +228,7 @@ const Institutions = () => { setError(true) } ) - }, [currPage, description, country, search, city]) + }, [currPage, description, country, search, city, invertList]) useEffect(() => { setSeacrh("") @@ -369,7 +376,7 @@ const Institutions = () => { {items.map((row, index) => index === items.length - 1 ? ( <StyledDivButton - key="Load more" + key={new Date().toISOString() + row.created_at} > <Button color="primary" @@ -391,12 +398,12 @@ const Institutions = () => { ) : ( <> <MobileList - key={index} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.id} backColor={"#ff7f00"} avatar={<AccountBalanceRoundedIcon />} - href={`/admin/institution/${row.id}`} + href={`/admin/institution?institution=${row.id}`} reset={() => { }} @@ -516,11 +523,11 @@ const Institutions = () => { <div style={{ height: "2em" }}></div> {/************** Start of display data in table **************/} - <TableData top={topTable}> + <TableData top={topTable} onIconPressed={cleanArrayAndInvert}> <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow key={row.created_at}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -541,7 +548,7 @@ const Institutions = () => { </StyledTableCell> </StyledTableRow> ) : ( - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row"> {row.id} </StyledTableCell> @@ -554,7 +561,7 @@ const Institutions = () => { {row.country} </StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/institution/${row.id}`}> + <Link to={`/admin/institution?institution=${row.id}`}> <IconButton> <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/Languages.js b/src/Admin/Pages/Pages/SubPages/Languages.js index 3d11c4a46f9feb2e606feea30c00f819ee91465c..3f68cbf4c89e4f21c0ae2edcb55ab68682dfbdb8 100644 --- a/src/Admin/Pages/Pages/SubPages/Languages.js +++ b/src/Admin/Pages/Pages/SubPages/Languages.js @@ -69,6 +69,7 @@ const Languages = () => { const WINDOW_WIDTH = window.innerWidth const router = useHistory() + const [invertList, setInvertList] = useState(false) const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -151,6 +152,12 @@ const Languages = () => { } } + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + //getting data from server useEffect(() => { if (currPage === 0) @@ -159,7 +166,7 @@ const Languages = () => { setIsLoadingMoreItems(true) getRequest( - Url("languages", "", currPage, "DESC"), + Url("languages", "", currPage, invertList ? "ASC" : "DESC"), (data, header) => { const arrData = [...data] if (arrData.length === 0) { @@ -185,7 +192,7 @@ const Languages = () => { setError(true) } ) - }, [currPage]) + }, [currPage, invertList]) if (error) { return <div>Error: {error.message}</div>; @@ -243,7 +250,7 @@ const Languages = () => { {items.map((row, index) => index === items.length - 1 ? ( - <StyledDivButton key="Load"> + <StyledDivButton key={new Date().toISOString() + row.created_at}> <Button color="primary" variant="text" @@ -264,12 +271,12 @@ const Languages = () => { ) : ( <> <MobileList - key={row.created_at} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.id} backColor={"#e81f4f"} avatar={<LanguageRoundedIcon />} - href={`/admin/languageEdit/${row.id}`} + href={`/admin/languageEdit?language=${row.id}`} reset={() => { }} @@ -278,7 +285,6 @@ const Languages = () => { { title: "Code", subtitle: row.code - }, { title: "Deletar", @@ -348,11 +354,12 @@ const Languages = () => { <TableData top={TOP_LABELS} + onIconPressed={cleanArrayAndInvert} > <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <StyledTableRow key="Load more"> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -374,12 +381,12 @@ const Languages = () => { : - <StyledTableRow key={row.created_at}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row">{row.id}</StyledTableCell> <StyledTableCell align="right">{row.name}</StyledTableCell> <StyledTableCell align="right">{row.code}</StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/languageEdit/${row.id}`}> + <Link to={`/admin/languageEdit?language=${row.id}`}> <IconButton> <EditRoundedIcon style={{ fill: '#00bcd4' }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/NoteVariables.js b/src/Admin/Pages/Pages/SubPages/NoteVariables.js index 5e58e14d173acc6b3a867f4a1d5df0799886c59a..71b6abc844244a1a11f0ae8a944744bf965ac3f1 100644 --- a/src/Admin/Pages/Pages/SubPages/NoteVariables.js +++ b/src/Admin/Pages/Pages/SubPages/NoteVariables.js @@ -68,6 +68,7 @@ const NoteVariables = () => { const WINDOW_WIDTH = window.innerWidth const ADD_ONE_LENGHT = [""]; + const [invertList, setInvertList] = useState(false) 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 [currPage, setCurrPage] = useState(0) @@ -91,13 +92,19 @@ const NoteVariables = () => { }) } + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + useEffect(() => { if (currPage === 0) setIsLoaded(false) else setIsLoadingMoreItems(true) getRequest( - Url("scores", "", currPage, "DESC"), + Url("scores", "", currPage, invertList ? "ASC" : "DESC"), (data, header) => { const arrData = [...data] if (arrData.length === 0) { @@ -123,7 +130,7 @@ const NoteVariables = () => { setError(true) } ) - }, [currPage]) + }, [currPage, invertList]) if (error) { return <div>Error: {error.message}</div>; @@ -160,6 +167,13 @@ const NoteVariables = () => { }, icon: <UpdateRoundedIcon /> }, + { + name: "Inverter lista", + isLoading: false, + func: () => { + cleanArrayAndInvert() + }, + }, ]} > </MobilePageHeader> @@ -168,7 +182,7 @@ const NoteVariables = () => { {items.map((row, index) => index === items.length - 1 ? ( - <StyledDivButton key="Load"> + <StyledDivButton key={new Date().toISOString() + row.created_at}> <Button color="primary" variant="text" @@ -189,12 +203,12 @@ const NoteVariables = () => { ) : ( <> <MobileList - key={row.created_at} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.id} backColor={"#e81f4f"} avatar={<TrendingUpRoundedIcon />} - href={`/admin/noteVar/${row.id}`} + href={`/admin/noteVar?id=${row.id}`} reset={() => { }} data={ @@ -239,7 +253,7 @@ const NoteVariables = () => { })} /> <PageHeader - title="Linguagens" + title="Variáveis de nota" actions={[ { name: "Atualizar", @@ -257,11 +271,12 @@ const NoteVariables = () => { <TableData top={topTable} + onIconPressed={cleanArrayAndInvert} > <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <StyledTableRow key="Load more"> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -282,7 +297,7 @@ const NoteVariables = () => { : - <StyledTableRow key={row.created_at}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row">{row.id}</StyledTableCell> <StyledTableCell align="right">{row.name}</StyledTableCell> <StyledTableCell align="right">{row.code}</StyledTableCell> @@ -302,7 +317,7 @@ const NoteVariables = () => { } </StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/noteVar/${row.id}`}> + <Link to={`/admin/noteVar?id=${row.id}`}> <IconButton> <VisibilityIcon style={{ fill: '#00bcd4' }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/Permissions.js b/src/Admin/Pages/Pages/SubPages/Permissions.js index 89c3bb55238737c90e42ed24527c9946d66edb20..d8484ac19455a2e558736d5366ed3df129d84850 100644 --- a/src/Admin/Pages/Pages/SubPages/Permissions.js +++ b/src/Admin/Pages/Pages/SubPages/Permissions.js @@ -69,6 +69,7 @@ const UserPermissions = () => { const router = useHistory() + const [invertList, setInvertList] = useState(false) const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -150,13 +151,19 @@ const UserPermissions = () => { setOpenAlertDialog(!openAlertDialog); }; + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + useEffect(() => { if (currPage === 0) setIsLoaded(false) else setIsLoadingMoreItems(true) getRequest( - Url("roles", "", currPage, "DESC"), + Url("roles", "", currPage, invertList ? "ASC" : "DESC"), (data, header) => { const arrData = [...data] if (arrData.length === 0) { @@ -182,7 +189,7 @@ const UserPermissions = () => { setError(true) } ) - }, [currPage]) + }, [currPage, invertList]) if (error) { return <div>Error: {error.message}</div>; @@ -231,6 +238,13 @@ const UserPermissions = () => { router.push('/admin/CreateRole') }, icon: <AddRoundedIcon /> + }, + { + name: "Inverter lista", + isLoading: false, + func: () => { + cleanArrayAndInvert() + }, } ]} > @@ -240,7 +254,7 @@ const UserPermissions = () => { {items.map((row, index) => index === items.length - 1 ? ( - <StyledDivButton key="Load"> + <StyledDivButton key={new Date().toISOString() + row.created_at}> <Button color="primary" variant="text" @@ -261,12 +275,12 @@ const UserPermissions = () => { ) : ( <> <MobileList - key={row.created_at} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.id} backColor={"#ff7f00"} avatar={<AccountCircleRoundedIcon />} - href={`/admin/EditPermissions/${row.id}`} + href={`/admin/EditPermissions?role=${row.id}`} reset={() => { }} data={ @@ -343,11 +357,12 @@ const UserPermissions = () => { <TableData top={TOP_LABELS} + onIconPressed={cleanArrayAndInvert} > <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <StyledTableRow key="Load more"> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -369,12 +384,12 @@ const UserPermissions = () => { : - <StyledTableRow key={row.created_at}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row">{row.id}</StyledTableCell> <StyledTableCell align="right">{row.name}</StyledTableCell> <StyledTableCell align="right">{row.description}</StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/EditPermissions/${row.id}`}> + <Link to={`/admin/EditPermissions?role=${row.id}`}> <Button style={{ width: "100%", marginBottom: "0.5em" }} variant="contained" diff --git a/src/Admin/Pages/Pages/SubPages/Questions.js b/src/Admin/Pages/Pages/SubPages/Questions.js index aa4532af91f4bb73924e95c306f01ed8bed15853..296c62d7ac95288b3ad708de3d0dcb993fd6a6d6 100644 --- a/src/Admin/Pages/Pages/SubPages/Questions.js +++ b/src/Admin/Pages/Pages/SubPages/Questions.js @@ -67,6 +67,7 @@ const Questions = () => { const TOP_LABELS = ['ID', 'CRIAÇÃO EM', 'DESCRIÇÃO', 'STATUS', 'ATUALIZAÇÃO EM'] //Labels from Table const router = useHistory() + const [invertList, setInvertList] = useState(false) const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -155,13 +156,19 @@ const Questions = () => { .toString(); }; + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + useEffect(() => { if (currPage === 0) setIsLoaded(false) else setIsLoadingMoreItems(true) getRequest( - Url("questions", "", currPage, "DESC"), + Url("questions", "", currPage, invertList ? "ASC" : "DESC"), (data, header) => { const arrData = [...data] if (arrData.length === 0) { @@ -187,7 +194,7 @@ const Questions = () => { setError(true) } ) - }, [currPage]) + }, [currPage, invertList]) if (error) { @@ -228,7 +235,15 @@ const Questions = () => { func: () => { router.push('/admin/CreateQuestion') }, - } + icon: <AddRoundedIcon /> + }, + { + name: "Inverter lista", + isLoading: false, + func: () => { + cleanArrayAndInvert() + }, + }, ]} > </MobilePageHeader> @@ -238,7 +253,7 @@ const Questions = () => { {items.map((row, index) => index === items.length - 1 ? ( <StyledDivButton - key="Load" + key={new Date().toISOString() + row.created_at} > <Button color="primary" @@ -260,7 +275,7 @@ const Questions = () => { ) : ( <> <MobileList - key={row.created_at} + key={new Date().toISOString() + row.created_at} title={row.id} subtitle={DisplayDate(row.created_at)} backColor={"#673ab7"} @@ -339,6 +354,7 @@ const Questions = () => { func: () => { router.push('/admin/CreateQuestion') }, + icon: <AddRoundedIcon /> } ]} > @@ -348,11 +364,12 @@ const Questions = () => { <TableData top={TOP_LABELS} + onIconPressed={cleanArrayAndInvert} > <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <StyledTableRow key="Load more"> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -374,7 +391,7 @@ const Questions = () => { : - <StyledTableRow key={row.created_at}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row">{row.id}</StyledTableCell> <StyledTableCell align="right">{DisplayDate(row.created_at)}</StyledTableCell> <StyledTableCell align="right">{row.description}</StyledTableCell> diff --git a/src/Admin/Pages/Pages/SubPages/Rating.js b/src/Admin/Pages/Pages/SubPages/Rating.js index 8f00fd9dc1fdc319b63cb459f3d369367cfc92aa..71f648dd790a531298570cc2a3076d00d2d30f87 100644 --- a/src/Admin/Pages/Pages/SubPages/Rating.js +++ b/src/Admin/Pages/Pages/SubPages/Rating.js @@ -71,6 +71,7 @@ const Ratings = () => { const router = useHistory() + const [invertList, setInvertList] = useState(false) const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -151,13 +152,19 @@ const Ratings = () => { setOpenAlertDialog(!openAlertDialog); }; + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + useEffect(() => { if (currPage === 0) setIsLoaded(false) else setIsLoadingMoreItems(true) getRequest( - Url("ratings", "", currPage, "DESC"), + Url("ratings", "", currPage, invertList ? "ASC" : "DESC"), (data, header) => { const arrData = [...data] if (arrData.length === 0) { @@ -183,7 +190,7 @@ const Ratings = () => { setError(true) } ) - }, [currPage]) + }, [currPage, invertList]) if (error) { return <div>Error: {error.message}</div>; @@ -244,9 +251,8 @@ const Ratings = () => { {items.map((row, index) => index === items.length - 1 ? ( - <StyledDivButton key="Load"> + <StyledDivButton key={new Date().toISOString() + row.created_at}> <Button - key={index} color="primary" variant="text" // disabled={isLoadingMoreItems} @@ -266,12 +272,12 @@ const Ratings = () => { ) : ( <> <MobileList - key={row.created_at} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.id} backColor={"#00bcd4"} avatar={<StarRoundedIcon />} - href={`/admin/Rating/${row.id}`} + href={`/admin/Rating?rating=${row.id}`} reset={() => { }} @@ -348,11 +354,12 @@ const Ratings = () => { <TableData top={topTable} + onIconPressed={cleanArrayAndInvert} > <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <StyledTableRow key={row.created_at}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -373,12 +380,12 @@ const Ratings = () => { : - <StyledTableRow key={row.created_at}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row">{row.id}</StyledTableCell> <StyledTableCell align="right">{row.name}</StyledTableCell> <StyledTableCell align="right">{row.description}</StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/Rating/${row.id}`}> + <Link to={`/admin/Rating?rating=${row.id}`}> <IconButton> <VisibilityIcon style={{ fill: '#00bcd4' }} /> </IconButton> diff --git a/src/Admin/Pages/Pages/SubPages/SendEmail.js b/src/Admin/Pages/Pages/SubPages/SendEmail.js index c6e8c4d0afc41d9909bc8731d916972d844121f5..aff09bc843ce63f5238516695dd3887398987756 100644 --- a/src/Admin/Pages/Pages/SubPages/SendEmail.js +++ b/src/Admin/Pages/Pages/SubPages/SendEmail.js @@ -54,8 +54,11 @@ const useStyles = makeStyles({ }, }); + const SendEmail = ({ match }) => { const classes = useStyles(); + const urlParams = new URLSearchParams(window.location.search); + const email = urlParams.get("email"); return ( <Card> @@ -67,7 +70,7 @@ const SendEmail = ({ match }) => { > Enviar email </Typography> - <EmailInputs email={`${match.params.email}`} /> + <EmailInputs email={email} /> </CardContent> </Card> ); diff --git a/src/Admin/Pages/Pages/SubPages/Users.js b/src/Admin/Pages/Pages/SubPages/Users.js index 31857677ac417d346cc8c3c62652068a436bba1c..95e8d38f4ec1b5202813854ec2aefe8a68c5c238 100644 --- a/src/Admin/Pages/Pages/SubPages/Users.js +++ b/src/Admin/Pages/Pages/SubPages/Users.js @@ -73,6 +73,7 @@ const Users = () => { const router = useHistory() + const [invertList, setInvertList] = useState(false) const [error, setError] = useState(null); //Necessary to consult the API, catch errors const [isLoaded, setIsLoaded] = useState(false); //Necessary to consult the API, wait until complete const [items, setItems] = useState([]); //Necessary to consult the API, data @@ -174,15 +175,21 @@ const Users = () => { ) } - const buildUrl = (email, name) => { + const cleanArrayAndInvert = () => { + setInvertList(!invertList) + setCurrPage(0) + setItems([]) + } + + const buildUrl = (email, name, direction) => { if (email && name) - return Url("users", `"email" : "${email}", "name" : "${name}"`, currPage, "DESC") + return Url("users", `"email" : "${email}", "name" : "${name}"`, currPage, direction) if (email) - return Url("users", `"email" : "${email}"`, currPage, "DESC") + return Url("users", `"email" : "${email}"`, currPage, direction) if (name) - return Url("users", `"name" : "${name}"`, currPage, "DESC") + return Url("users", `"name" : "${name}"`, currPage, direction) else - return Url("users", "", currPage, "DESC") + return Url("users", "", currPage, direction) } useEffect(() => { @@ -191,7 +198,7 @@ const Users = () => { else setIsLoadingMoreItems(true) getRequest( - buildUrl(email, name), + buildUrl(email, name, invertList ? "ASC" : "DESC"), (data, header) => { const arrData = [...data] if (arrData.length === 0) { @@ -217,7 +224,7 @@ const Users = () => { setIsLoadingMoreItems(false) } ) - }, [currPage, email, name]) + }, [currPage, email, name, invertList]) useEffect(() => { setNameValue("") @@ -272,7 +279,15 @@ const Users = () => { name: "Novo", isLoading: false, func: () => { - router.push('/admin/EditUser/-1') + router.push('/admin/EditUser?id=-1') + }, + icon: <AddRoundedIcon /> + }, + { + name: "Inverter lista", + isLoading: false, + func: () => { + cleanArrayAndInvert() }, } ]} @@ -307,9 +322,8 @@ const Users = () => { {items.map((row, index) => index === items.length - 1 ? ( - <StyledDivButton> + <StyledDivButton key={new Date().toISOString() + row.created_at}> <Button - key={index} color="primary" variant="text" // disabled={isLoadingMoreItems} @@ -329,7 +343,7 @@ const Users = () => { ) : ( <> <MobileList - key={index} + key={new Date().toISOString() + row.created_at} title={row.name} subtitle={row.id} backColor={"#00bcd4"} @@ -344,14 +358,14 @@ const Users = () => { }} /> } - href={`/admin/user/${row.id}`} + href={`/admin/user?id=${row.id}`} reset={() => { }} data={[ { title: "Email", subtitle: row.email ? - <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> + <Link to={`/admin/sendEmail?email=${row.email}`} style={{ textDecoration: 'none' }}> <Button variant='text' color='primary' @@ -440,8 +454,9 @@ const Users = () => { name: "Novo", isLoading: false, func: () => { - router.push('/admin/EditUser/-1') + router.push('/admin/EditUser?id=-1') }, + icon: <AddRoundedIcon /> } ]} > @@ -475,11 +490,12 @@ const Users = () => { <TableData top={topTable} + onIconPressed={cleanArrayAndInvert} > <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> {/* Button to load more data */} <StyledTableCell> <Button @@ -500,7 +516,7 @@ const Users = () => { : - <StyledTableRow key={index}> + <StyledTableRow key={new Date().toISOString() + row.created_at}> <StyledTableCell component="th" scope="row">{row.id}</StyledTableCell> <StyledTableCell align="right">{row.name}</StyledTableCell> <StyledTableCell align="right">{row.email ? row.email : ""}</StyledTableCell> @@ -528,7 +544,7 @@ const Users = () => { </Button> </StyledTableCell> <StyledTableCell align="right"> - <Link to={`/admin/user/${row.id}`}> + <Link to={`/admin/user?id=${row.id}`}> <IconButton> <VisibilityIcon style={{ fill: '#00bcd4' }} /> </IconButton> diff --git a/src/App.js b/src/App.js index d687e65a632fa71de18a80bb365a6113e9aa4e52..dda0148c569a630c764dda053ceeb41794976ed8 100644 --- a/src/App.js +++ b/src/App.js @@ -209,14 +209,14 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/institution/:id" render={() => { + <Route path="/admin/institution" render={() => { if (CheckUserPermission()) return <InstitutionCard /> else return <Unauthorized /> }} /> <Route - path="/admin/institutionEdit/:id" + path="/admin/institutionEdit" render={() => { if (CheckUserPermission()) return <InstitutionsInput /> @@ -239,13 +239,13 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/noteVar/:id" render={() => { + <Route path="/admin/noteVar" render={() => { if (CheckUserPermission()) return <NoteVarCard /> else return <Unauthorized /> }} /> - <Route path="/admin/noteVarEdit/:id" render={() => { + <Route path="/admin/noteVarEdit" render={() => { if (CheckUserPermission()) return <NoteVarInputs /> else @@ -257,7 +257,7 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/languageEdit/:id" render={() => { + <Route path="/admin/languageEdit" render={() => { if (CheckUserPermission()) return <EditLanguage /> else @@ -279,7 +279,7 @@ export default function App() { }} /> <Route - path="/admin/CommunityQuestion/:id" + path="/admin/CommunityQuestion" render={() => { if (CheckUserPermission()) return <CommunityCard /> @@ -293,14 +293,14 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/Collection/:id" render={() => { + <Route path="/admin/Collection" render={() => { if (CheckUserPermission()) return <CollectionCard /> else return <Unauthorized /> }} /> <Route - path="/admin/EditCollection/:id" + path="/admin/EditCollection" render={() => { if (CheckUserPermission()) return <EditCollection /> @@ -314,13 +314,13 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/Rating/:id" render={() => { + <Route path="/admin/Rating" render={() => { if (CheckUserPermission()) return <RatingCard /> else return <Unauthorized /> }} /> - <Route path="/admin/EditRating/:id" render={() => { + <Route path="/admin/EditRating" render={() => { if (CheckUserPermission()) return <EditRating /> else @@ -350,7 +350,7 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/activity/:id" render={() => { + <Route path="/admin/activity" render={() => { if (CheckUserPermission()) return <ActivityCard /> else @@ -365,7 +365,7 @@ export default function App() { return <Unauthorized /> }} /> <Route - path="/admin/learningObject/:id" + path="/admin/learningObject" render={() => { if (CheckUserPermission()) return <EducationalObjectCard /> @@ -373,7 +373,7 @@ export default function App() { return <Unauthorized /> }} /> <Route - path="/admin/learningObjectEdit/:id" + path="/admin/learningObjectEdit" render={() => { if (CheckUserPermission()) return <EducationalObjectEdit /> @@ -386,7 +386,7 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/complaint/:id" render={() => { + <Route path="/admin/complaint" render={() => { if (CheckUserPermission()) return <ComplaintCard /> else @@ -406,13 +406,13 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/user/:id" render={() => { + <Route path="/admin/user" render={() => { if (CheckUserPermission()) return <UserCard /> else return <Unauthorized /> }} /> - <Route path="/admin/EditUser/:id" render={() => { + <Route path="/admin/EditUser" render={() => { if (CheckUserPermission()) return <EditUser /> else @@ -424,7 +424,7 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/EditPermissions/:id" render={() => { + <Route path="/admin/EditPermissions" render={() => { if (CheckUserPermission()) return <EditRole /> else @@ -442,7 +442,7 @@ export default function App() { else return <Unauthorized /> }} /> - <Route path="/admin/sendEmail/:email" ender={() => { + <Route path="/admin/sendEmail" render={() => { if (CheckUserPermission()) return <SendEmail /> else