From 762cf959d793b4605835bd581c46ea0adb058771 Mon Sep 17 00:00:00 2001 From: Luis Felipe Risch <lfr20@inf.ufpr.br> Date: Thu, 3 Dec 2020 08:59:32 -0300 Subject: [PATCH] fixed some errors from console of the browser --- .../DataCards/CommunityQuestionCard.js | 2 +- .../Components/DataCards/InstitutionsCard.js | 18 ---- .../Components/Inputs/CreateInstitution.js | 2 +- .../Components/Inputs/CreateLanguage.js | 2 +- .../Components/Inputs/CreateQuestion.js | 2 +- .../Components/Inputs/CreateRating.js | 2 +- .../Components/Inputs/EditCollection.js | 2 +- .../Components/Inputs/EditEducationalObect.js | 2 +- .../Components/Inputs/EditLanguage.js | 2 +- .../Components/Inputs/EditRating.js | 2 +- .../Components/Inputs/EmailInputs.js | 4 + .../Components/Inputs/IntitutionsInputs.js | 2 +- .../Components/Inputs/NoteVarInputs.js | 2 +- src/Admin/Pages/Pages/Admin.js | 38 +------- src/Admin/Pages/Pages/SubPages/Activity.js | 61 +++++++------ src/Admin/Pages/Pages/SubPages/Collections.js | 73 ++++++++------- .../Pages/SubPages/CommunityQuestions.js | 89 +++++++++---------- src/Admin/Pages/Pages/SubPages/Complaints.js | 87 +++++++++--------- .../Pages/SubPages/EducationalObjects.js | 55 ++++++------ .../Pages/Pages/SubPages/Institutions.js | 83 +++++++++-------- src/Admin/Pages/Pages/SubPages/Languages.js | 69 +++++++------- .../Pages/Pages/SubPages/NoteVariables.js | 49 +++++----- src/Admin/Pages/Pages/SubPages/Questions.js | 72 +++++++-------- src/Admin/Pages/Pages/SubPages/Rating.js | 48 +++++----- src/Admin/Pages/Pages/SubPages/SendEmail.js | 4 +- src/App.js | 1 + 26 files changed, 354 insertions(+), 419 deletions(-) diff --git a/src/Admin/Components/Components/DataCards/CommunityQuestionCard.js b/src/Admin/Components/Components/DataCards/CommunityQuestionCard.js index 812a2c6a..4e7bafaf 100644 --- a/src/Admin/Components/Components/DataCards/CommunityQuestionCard.js +++ b/src/Admin/Components/Components/DataCards/CommunityQuestionCard.js @@ -53,10 +53,10 @@ const CommunityQuestions = ({ match }) => { }; const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Components/Components/DataCards/InstitutionsCard.js b/src/Admin/Components/Components/DataCards/InstitutionsCard.js index a3513dc4..a918cb9d 100644 --- a/src/Admin/Components/Components/DataCards/InstitutionsCard.js +++ b/src/Admin/Components/Components/DataCards/InstitutionsCard.js @@ -43,7 +43,6 @@ const InstitutionCard = ({ 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(false); const [item, setItem] = useState({}); //Necessary to consult the API, data @@ -54,20 +53,6 @@ const InstitutionCard = ({ match }) => { .toString(); }; - const CheckUserPermission = async () => { - console.log(state) - if(state.userIsLoggedIn){ - console.log("logged") - for (let i = 0; i < state.currentUser.roles.length; i++) - if (state.currentUser.roles[i].name === 'admin' || state.currentUser.roles[i].name === 'editor') - return true; - else return false; - } - else{ - return false; - } - } - useEffect(() => { fetch(GetAData('institutions', match.params.id)) .then((res) => res.json()) @@ -81,8 +66,6 @@ const InstitutionCard = ({ match }) => { setError(error); } ); - if(CheckUserPermission) setIsAuthorized(true); - else setIsAuthorized(false); }, []); if (error) { @@ -154,7 +137,6 @@ const InstitutionCard = ({ match }) => { startIcon={<EditRoundedIcon/>} color="primary" variant="outlined" - onClick={() => console.log(state.userIsLoggedIn, isAuthorized)} > Editar </Button> diff --git a/src/Admin/Components/Components/Inputs/CreateInstitution.js b/src/Admin/Components/Components/Inputs/CreateInstitution.js index cd36b0ab..20ad3c14 100644 --- a/src/Admin/Components/Components/Inputs/CreateInstitution.js +++ b/src/Admin/Components/Components/Inputs/CreateInstitution.js @@ -109,10 +109,10 @@ const CreateInstitution = (props) => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Components/Components/Inputs/CreateLanguage.js b/src/Admin/Components/Components/Inputs/CreateLanguage.js index 67dcd596..8b72fffd 100644 --- a/src/Admin/Components/Components/Inputs/CreateLanguage.js +++ b/src/Admin/Components/Components/Inputs/CreateLanguage.js @@ -98,10 +98,10 @@ const CreateLanguage = (props) => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Components/Components/Inputs/CreateQuestion.js b/src/Admin/Components/Components/Inputs/CreateQuestion.js index 05deca7d..6a4a6640 100644 --- a/src/Admin/Components/Components/Inputs/CreateQuestion.js +++ b/src/Admin/Components/Components/Inputs/CreateQuestion.js @@ -89,10 +89,10 @@ const CreateQuestion = (props) => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; 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; diff --git a/src/Admin/Components/Components/Inputs/CreateRating.js b/src/Admin/Components/Components/Inputs/CreateRating.js index 15ae0756..290bea81 100644 --- a/src/Admin/Components/Components/Inputs/CreateRating.js +++ b/src/Admin/Components/Components/Inputs/CreateRating.js @@ -98,10 +98,10 @@ const CreateRating = (props) => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Components/Components/Inputs/EditCollection.js b/src/Admin/Components/Components/Inputs/EditCollection.js index c3e67100..6065d23e 100644 --- a/src/Admin/Components/Components/Inputs/EditCollection.js +++ b/src/Admin/Components/Components/Inputs/EditCollection.js @@ -158,10 +158,10 @@ const EditCollection = ({ match }) => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Components/Components/Inputs/EditEducationalObect.js b/src/Admin/Components/Components/Inputs/EditEducationalObect.js index 66a3a867..0ebb0b71 100644 --- a/src/Admin/Components/Components/Inputs/EditEducationalObect.js +++ b/src/Admin/Components/Components/Inputs/EditEducationalObect.js @@ -503,10 +503,10 @@ const EditEducationalObject = ({ match }) => { ]; const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Components/Components/Inputs/EditLanguage.js b/src/Admin/Components/Components/Inputs/EditLanguage.js index d45bf1a4..f3e778b2 100644 --- a/src/Admin/Components/Components/Inputs/EditLanguage.js +++ b/src/Admin/Components/Components/Inputs/EditLanguage.js @@ -129,10 +129,10 @@ const EditLanguage = ({ match }) => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Components/Components/Inputs/EditRating.js b/src/Admin/Components/Components/Inputs/EditRating.js index 42b41bb3..066ecaf6 100644 --- a/src/Admin/Components/Components/Inputs/EditRating.js +++ b/src/Admin/Components/Components/Inputs/EditRating.js @@ -131,10 +131,10 @@ const EditRating = ({ match }) => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Components/Components/Inputs/EmailInputs.js b/src/Admin/Components/Components/Inputs/EmailInputs.js index d9269f13..8faecf8d 100644 --- a/src/Admin/Components/Components/Inputs/EmailInputs.js +++ b/src/Admin/Components/Components/Inputs/EmailInputs.js @@ -497,6 +497,10 @@ const EmailInputs = (props) => { /> </div> + <div style={{fontSize : 14}}> + * Se você deseja enviar foto da sua máquina, é preciso <a href="mailto:name@email.com">Clicar aqui</a> + </div> + <div style={{ marginTop: 18 }}> <Button onClick={() => { diff --git a/src/Admin/Components/Components/Inputs/IntitutionsInputs.js b/src/Admin/Components/Components/Inputs/IntitutionsInputs.js index 4bc11001..11c2194e 100644 --- a/src/Admin/Components/Components/Inputs/IntitutionsInputs.js +++ b/src/Admin/Components/Components/Inputs/IntitutionsInputs.js @@ -117,10 +117,10 @@ const EditInstitution = ({ match }) => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Components/Components/Inputs/NoteVarInputs.js b/src/Admin/Components/Components/Inputs/NoteVarInputs.js index 7f8b20b3..3692e546 100644 --- a/src/Admin/Components/Components/Inputs/NoteVarInputs.js +++ b/src/Admin/Components/Components/Inputs/NoteVarInputs.js @@ -198,10 +198,10 @@ const NoteVarInputs = ({ match }) => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; diff --git a/src/Admin/Pages/Pages/Admin.js b/src/Admin/Pages/Pages/Admin.js index ab5d4379..607dd85d 100644 --- a/src/Admin/Pages/Pages/Admin.js +++ b/src/Admin/Pages/Pages/Admin.js @@ -141,7 +141,7 @@ export default function Admin() { <BrowserRouter> <Switch> <div style={{ paddingTop: '2em', paddingLeft: '2em', paddingRight: '2em', paddingBottom: '2em', backgroundColor: ' #D3D3D3' }}> - <Route path='/admin/home' component={Welcome} /> + <Route path='/admin/home' exact={true} component={Welcome}/> <Route path='/admin/intitutions' component={Institution} /> <Route path='/admin/institution/:id' component={InstitutionCard} /> @@ -197,40 +197,4 @@ export default function Admin() { </Fab> </BrowserRouter> ); - - // if (state.userIsLoggedIn) { - // var obj = { ...(state.currentUser.roles)[0] } - // if (obj.id === 3 || obj.id === 7) { - // return ( - // <div> - // {/**************** Begin of the Drawer ****************/} - // <React.Fragment> - // <Drawer anchor={'left'} open={State['left']} onClose={toggleDrawer('left', false)}> - // {list('left')} - // </Drawer> - // </React.Fragment> - // {/**************** End of the Drawer****************/} - - // {/**************** Begin of the Content ****************/} - // <div style={{ paddingTop: '2em', paddingLeft: '2em', paddingRight: '2em', paddingBottom: '2em', backgroundColor: ' #D3D3D3' }}> - // <DisplayContent i={IndexIcon} /> - // </div> - // {/**************** End of the Content ****************/} - - // {/**************** FLoating action Button ****************/} - // <Fab color="primary" aria-label="add" style={fab} onClick={toggleDrawer('left', true)}> - // <MenuIcon /> - // </Fab> - // </div> - // ); - // } else { - // return ( - // <Unauthorized/> - // ) - // } - // } else { - // return ( - // <Unauthorized/> - // ) - // } } diff --git a/src/Admin/Pages/Pages/SubPages/Activity.js b/src/Admin/Pages/Pages/SubPages/Activity.js index dbdc94fd..9f5b6581 100644 --- a/src/Admin/Pages/Pages/SubPages/Activity.js +++ b/src/Admin/Pages/Pages/SubPages/Activity.js @@ -17,7 +17,7 @@ You should have received a copy of the GNU Affero General Public License along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/ import React, { useEffect, useState } from "react"; -import moment from 'moment'; +import moment from 'moment'; //imports from local files import TableData from "../../../Components/Components/Table"; import SnackBar from "../../../../Components/SnackbarComponent"; @@ -233,7 +233,7 @@ const Activity = () => { if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> + return <LoadingSpinner text="Carregando..." /> } else { return <> @@ -260,9 +260,6 @@ const Activity = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -333,33 +330,35 @@ const Activity = () => { <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow style={{ padding: "1em" }}> + <StyledTableRow key={index} style={{ padding: "1em" }}> {/* Button to load more data */} - <Button - color="primary" - variant="text" - // disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - disabled={isLoadingMoreItems} - onClick={() => { - currPage++; - if (showFilter) { - LoadMoreItens( - Url("activities", `"privacy" : "${option}"`, `${currPage}`, "DESC") - ); - } else { - LoadMoreItens( - Url("activities", "", `${currPage}`, "DESC") - ); - } - }} - > - {isLoadingMoreItems ? ( - <CircularProgress size={24} /> - ) : ( - "Carregar mais itens" - )} - </Button> + <StyledTableCell> + <Button + color="primary" + variant="text" + // disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + disabled={isLoadingMoreItems} + onClick={() => { + currPage++; + if (showFilter) { + LoadMoreItens( + Url("activities", `"privacy" : "${option}"`, `${currPage}`, "DESC") + ); + } else { + LoadMoreItens( + Url("activities", "", `${currPage}`, "DESC") + ); + } + }} + > + {isLoadingMoreItems ? ( + <CircularProgress size={24} /> + ) : ( + "Carregar mais itens" + )} + </Button> + </StyledTableCell> </StyledTableRow> ) : ( <StyledTableRow key={index}> diff --git a/src/Admin/Pages/Pages/SubPages/Collections.js b/src/Admin/Pages/Pages/SubPages/Collections.js index fb89bfbf..a55b4d49 100644 --- a/src/Admin/Pages/Pages/SubPages/Collections.js +++ b/src/Admin/Pages/Pages/SubPages/Collections.js @@ -305,7 +305,7 @@ const Collections = () => { if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> + return <LoadingSpinner text="Carregando..." /> } else { return <> @@ -332,9 +332,6 @@ const Collections = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -388,7 +385,7 @@ const Collections = () => { > {options.map((option, index) => ( <MenuItem - key={option.value} + key={index} value={option.value} > {option.label} @@ -416,40 +413,42 @@ const Collections = () => { <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow style={{ padding: "1em" }}> - {/* Button to load more data */} - <Button - color="primary" - variant="text" - // disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - disabled={isLoadingMoreItems} - onClick={() => { - currPage++; - if (showFilter) { - if (search) { - LoadMoreItens( - Url("collections", `"name" : "${search}"`, `${currPage}`, "DESC") - ); - } - else { + <StyledTableRow key={index}> + <StyledTableCell> + <Button + key={index} + color="primary" + variant="text" + // disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + disabled={isLoadingMoreItems} + onClick={() => { + currPage++; + if (showFilter) { + if (search) { + LoadMoreItens( + Url("collections", `"name" : "${search}"`, `${currPage}`, "DESC") + ); + } + else { + LoadMoreItens( + Url("collections", `"privacy" : "${option}"`, `${currPage}`, "DESC") + ); + } + } else { LoadMoreItens( - Url("collections", `"privacy" : "${option}"`, `${currPage}`, "DESC") + Url("collections", "", `${currPage}`, "DESC") ); } - } else { - LoadMoreItens( - Url("collections", "", `${currPage}`, "DESC") - ); - } - }} - > - {isLoadingMoreItems ? ( - <CircularProgress size={24} /> - ) : ( - "Carregar mais itens" - )} - </Button> + }} + > + {isLoadingMoreItems ? ( + <CircularProgress size={24} /> + ) : ( + "Carregar mais itens" + )} + </Button> + </StyledTableCell> </StyledTableRow> ) : ( <StyledTableRow key={index}> @@ -457,7 +456,7 @@ const Collections = () => { {row.name} </StyledTableCell> <StyledTableCell align="right"> - <div dangerouslySetInnerHTML={{__html : row.description}}> + <div dangerouslySetInnerHTML={{ __html: row.description }}> </div> </StyledTableCell> <StyledTableCell align="right"> diff --git a/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js b/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js index 3f855606..a0d161cf 100644 --- a/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js +++ b/src/Admin/Pages/Pages/SubPages/CommunityQuestions.js @@ -265,19 +265,19 @@ const CommunityQuestion = () => { }; const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; - 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' || roles[i].name === 'editor') - canUserEdit = true; + canUserEdit = true; } else { canUserEdit = false; - } + } - return canUserEdit; + return canUserEdit; } //getting data from server @@ -301,8 +301,8 @@ const CommunityQuestion = () => { if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> - } else if(CheckUserPermission()){ + return <LoadingSpinner text="Carregando..." /> + } else if (CheckUserPermission()) { return <> <SnackBar severity={snackInfo.icon} @@ -327,9 +327,6 @@ const CommunityQuestion = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -489,40 +486,42 @@ const CommunityQuestion = () => { <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow style={{ padding: "1em" }}> + <StyledTableRow key={index} style={{ padding: "1em" }}> {/* Button to load more data */} - <Button - color="primary" - variant="text" - startIcon={<AddRoundedIcon />} - disabled={isLoadingMoreItems} - onClick={() => { - currPage++; - if (showMessageFilter) { - LoadMoreItens( - Url("contacts", `"message" : "${message}"`, `${currPage}`, "DESC") - ); - } else if (showEmailFilter) { - LoadMoreItens( - Url("contacts", `"email" : "${email}"`, `${currPage}`, "DESC") - ); - } else if (showNameFilter) { - LoadMoreItens( - Url("contacts", `"name" : "${name}"`, `${currPage}`, "DESC") - ); - } else { - LoadMoreItens( - Url("contacts", "", `${currPage}`, "DESC") - ); - } - }} - > - {isLoadingMoreItems ? ( - <CircularProgress size={24} /> - ) : ( - "Carregar mais itens" - )} - </Button> + <StyledTableCell> + <Button + color="primary" + variant="text" + startIcon={<AddRoundedIcon />} + disabled={isLoadingMoreItems} + onClick={() => { + currPage++; + if (showMessageFilter) { + LoadMoreItens( + Url("contacts", `"message" : "${message}"`, `${currPage}`, "DESC") + ); + } else if (showEmailFilter) { + LoadMoreItens( + Url("contacts", `"email" : "${email}"`, `${currPage}`, "DESC") + ); + } else if (showNameFilter) { + LoadMoreItens( + Url("contacts", `"name" : "${name}"`, `${currPage}`, "DESC") + ); + } else { + LoadMoreItens( + Url("contacts", "", `${currPage}`, "DESC") + ); + } + }} + > + {isLoadingMoreItems ? ( + <CircularProgress size={24} /> + ) : ( + "Carregar mais itens" + )} + </Button> + </StyledTableCell> </StyledTableRow> ) : ( <StyledTableRow key={index}> @@ -538,7 +537,7 @@ const CommunityQuestion = () => { <StyledTableCell align="right"> { row.email ? - <Link to={`/admin/sendEmail/${row.email}`} style={{textDecoration : 'none'}}> + <Link to={`/admin/sendEmail/${row.email}`} style={{ textDecoration: 'none' }}> <Button variant='text' color='primary' @@ -565,6 +564,6 @@ const CommunityQuestion = () => { </TableBody> </TableData> </> - } else return <Unauthorized/> + } else return <Unauthorized /> } export default CommunityQuestion; diff --git a/src/Admin/Pages/Pages/SubPages/Complaints.js b/src/Admin/Pages/Pages/SubPages/Complaints.js index f88fe4fd..8b4ad0c7 100644 --- a/src/Admin/Pages/Pages/SubPages/Complaints.js +++ b/src/Admin/Pages/Pages/SubPages/Complaints.js @@ -125,19 +125,19 @@ const Complaints = () => { }; const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; - 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' || roles[i].name === 'editor') - canUserEdit = true; + canUserEdit = true; } else { canUserEdit = false; - } + } - return canUserEdit; + return canUserEdit; } //handle load more items @@ -338,8 +338,8 @@ const Complaints = () => { if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> - } else if(CheckUserPermission()){ + return <LoadingSpinner text="Carregando..." /> + } else if (CheckUserPermission()) { return ( <> <SnackBar @@ -366,9 +366,6 @@ const Complaints = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -412,7 +409,7 @@ const Complaints = () => { container direction="row" justify="space-between" - alignItems="center" + alignItems="center" alignContent="flex-end" spacing={3} xs={12} @@ -473,38 +470,40 @@ const Complaints = () => { <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <StyledTableRow style={{ padding: "1em" }}> + <StyledTableRow key={index}> {/* Button to load more data */} - <Button - color="primary" - variant="text" - // disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - disabled={isLoadingMoreItems} - onClick={() => { - currPage++; - if (showFilter) { - LoadMoreItens( - Url( - "complaints", - `"${currTypeFilter}" : "${currIdFilter}"`, - `${currPage}`, - "DESC" - ) - ); - } else { - LoadMoreItens( - Url("complaints", "", `${currPage}`, "DESC") - ); - } - }} - > - {isLoadingMoreItems ? ( - <CircularProgress size={24} /> - ) : ( - "Carregar mais itens" - )} - </Button> + <StyledTableCell> + <Button + color="primary" + variant="text" + // disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + disabled={isLoadingMoreItems} + onClick={() => { + currPage++; + if (showFilter) { + LoadMoreItens( + Url( + "complaints", + `"${currTypeFilter}" : "${currIdFilter}"`, + `${currPage}`, + "DESC" + ) + ); + } else { + LoadMoreItens( + Url("complaints", "", `${currPage}`, "DESC") + ); + } + }} + > + {isLoadingMoreItems ? ( + <CircularProgress size={24} /> + ) : ( + "Carregar mais itens" + )} + </Button> + </StyledTableCell> </StyledTableRow> ) : ( <StyledTableRow @@ -527,7 +526,7 @@ const Complaints = () => { <StyledTableCell align="right"> <Link to={`/admin/complaint/${row.id}`}> <IconButton - onClick={() => {currPage = 0}} + onClick={() => { currPage = 0 }} > <VisibilityIcon style={{ fill: "#00bcd4" }} /> </IconButton> @@ -567,6 +566,6 @@ const Complaints = () => { </Grid> </> ); - } else return <Unauthorized/> + } else return <Unauthorized /> }; export default Complaints; diff --git a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js index 519db7af..67eeecd2 100644 --- a/src/Admin/Pages/Pages/SubPages/EducationalObjects.js +++ b/src/Admin/Pages/Pages/SubPages/EducationalObjects.js @@ -363,9 +363,6 @@ const EducationalObjects = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -435,7 +432,7 @@ const EducationalObjects = () => { <Grid item xs={12}> <Grid container justify="space-between" spacing={3}> {TextFieldOfTheFilter.map((field, index) => ( - <Grid item> + <Grid item key={index}> {field.show ? ( <div> <TextField @@ -467,32 +464,32 @@ const EducationalObjects = () => { <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <div style={{ padding: "1em" }}> + <StyledTableRow key={index}> {/* Button to load more data */} - <Button - color="primary" - variant="text" - startIcon={<AddRoundedIcon />} - disabled={ - isLoadingMoreItems - } - onClick={() => { - currPage++ - if(showAuthorField) LoadMoreItens(Url("learning_objects", `"author" : "${author}"`, currPage, "DESC")) - else if(showDescriptionField) LoadMoreItens(Url("learning_objects", `"description" : "${description}"`, currPage, "DESC")) - else if(showStandadSearch) LoadMoreItens(Url("learning_objects", `"name" : "${search}"`, currPage, "DESC")) - else LoadMoreItens(Url('learning_objects', '', `${currPage}`, 'DESC')) - - - }} - > - {isLoadingMoreItems ? ( - <CircularProgress size={24} /> - ) : ( - "Carregar mais itens" - )} - </Button> - </div> + <StyledTableCell> + <Button + color="primary" + variant="text" + startIcon={<AddRoundedIcon />} + disabled={ + isLoadingMoreItems + } + onClick={() => { + currPage++ + if(showAuthorField) LoadMoreItens(Url("learning_objects", `"author" : "${author}"`, currPage, "DESC")) + else if(showDescriptionField) LoadMoreItens(Url("learning_objects", `"description" : "${description}"`, currPage, "DESC")) + else if(showStandadSearch) LoadMoreItens(Url("learning_objects", `"name" : "${search}"`, currPage, "DESC")) + else LoadMoreItens(Url('learning_objects', '', `${currPage}`, 'DESC')) + }} + > + {isLoadingMoreItems ? ( + <CircularProgress size={24} /> + ) : ( + "Carregar mais itens" + )} + </Button> + </StyledTableCell> + </StyledTableRow> ) : ( <StyledTableRow key={index}> <StyledTableCell component="th" scope="row"> diff --git a/src/Admin/Pages/Pages/SubPages/Institutions.js b/src/Admin/Pages/Pages/SubPages/Institutions.js index 9e6243c0..8f73792d 100644 --- a/src/Admin/Pages/Pages/SubPages/Institutions.js +++ b/src/Admin/Pages/Pages/SubPages/Institutions.js @@ -315,22 +315,22 @@ const Institutions = () => { useEffect(() => { GetFullList(Url("institutions", "", `${currPage}`, "DESC")) - .then( - (result) => { - if(result.state){ - setIsLoaded(true); - setItems(result.data.concat(addOndeLenght)); - } else setError(true); - }, - ); - + .then( + (result) => { + if (result.state) { + setIsLoaded(true); + setItems(result.data.concat(addOndeLenght)); + } else setError(true); + }, + ); + }, []); if (error) { return <div>Error: {error.message}</div>; } if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> + return <LoadingSpinner text="Carregando..." /> } else { //Words that defines that column const topTable = [ @@ -422,9 +422,6 @@ const Institutions = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -467,7 +464,7 @@ const Institutions = () => { </Grid> <Grid item> - <Link style={{textDecoration: 'none'}} to={'/admin/InstitutionCreate'}> + <Link style={{ textDecoration: 'none' }} to={'/admin/InstitutionCreate'}> <Button variant="contained" color="secondary" @@ -508,7 +505,7 @@ const Institutions = () => { <Grid item xs={12}> <Grid container justify="space-between" spacing={3}> {TextFieldOfTheFilter.map((field, index) => ( - <Grid item> + <Grid item key={index}> {field.show ? ( <div> <TextField @@ -540,35 +537,37 @@ const Institutions = () => { <TableBody> {items.map((row, index) => index === items.length - 1 ? ( - <div style={{ padding: "1em" }}> + <StyledTableRow key={index}> {/* Button to load more data */} - <Button - color="primary" - variant="text" - startIcon={<AddRoundedIcon />} - disabled={ - isLoadingMoreItems || - isFilteringByCity || - isFilteringByCounty || - isFilteringByDesc || - isFilteringByName - } - onClick={() => { - currPage++ - if (transformListToAsc) { - LoadMoreItens(Url('institutions', '', `${currPage}`, 'ASC')) - } else { - LoadMoreItens(Url('institutions', '', `${currPage}`, 'DESC')) + <StyledTableCell> + <Button + color="primary" + variant="text" + startIcon={<AddRoundedIcon />} + disabled={ + isLoadingMoreItems || + isFilteringByCity || + isFilteringByCounty || + isFilteringByDesc || + isFilteringByName } - }} - > - {isLoadingMoreItems ? ( - <CircularProgress /> - ) : ( - "Carregar mais itens" - )} - </Button> - </div> + onClick={() => { + currPage++ + if (transformListToAsc) { + LoadMoreItens(Url('institutions', '', `${currPage}`, 'ASC')) + } else { + LoadMoreItens(Url('institutions', '', `${currPage}`, 'DESC')) + } + }} + > + {isLoadingMoreItems ? ( + <CircularProgress /> + ) : ( + "Carregar mais itens" + )} + </Button> + </StyledTableCell> + </StyledTableRow> ) : ( <StyledTableRow key={index}> <StyledTableCell component="th" scope="row"> diff --git a/src/Admin/Pages/Pages/SubPages/Languages.js b/src/Admin/Pages/Pages/SubPages/Languages.js index 317ffcbd..2d0dd391 100644 --- a/src/Admin/Pages/Pages/SubPages/Languages.js +++ b/src/Admin/Pages/Pages/SubPages/Languages.js @@ -189,23 +189,23 @@ const Languages = () => { //getting data from server useEffect(() => { GetFullList(Url('languages', '', `${currPage}`, 'DESC')) - .then( - (result) => { - if(result.state){ - setIsLoaded(true); - setItems(result.data.concat(ADD_ONE_LENGHT)); - } else { - setError(true); - } - }, - ) + .then( + (result) => { + if (result.state) { + setIsLoaded(true); + setItems(result.data.concat(ADD_ONE_LENGHT)); + } else { + setError(true); + } + }, + ) }, []); if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> + return <LoadingSpinner text="Carregando..." /> } else { return ( <> @@ -232,9 +232,6 @@ const Languages = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -256,7 +253,7 @@ const Languages = () => { </Grid> <Grid item> - <Link style={{textDecoration: 'none'}} to={'/admin/languageCreate'}> + <Link style={{ textDecoration: 'none' }} to={'/admin/languageCreate'}> <Button variant="contained" color="secondary" @@ -280,28 +277,30 @@ const Languages = () => { <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <div style={{ padding: '1em' }}> + <StyledTableRow key={index}> {/* Button to load more data */} - <Button - color='primary' - variant='text' - // disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - disabled={isLoadingMoreItems} - onClick={() => { - currPage++ - if (transformListToAsc) { - LoadMoreItens(Url('languages', '', `${currPage}`, 'ASC')) - } else { - LoadMoreItens(Url('languages', '', `${currPage}`, 'DESC')) + <StyledTableCell> + <Button + color='primary' + variant='text' + // disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + disabled={isLoadingMoreItems} + onClick={() => { + currPage++ + if (transformListToAsc) { + LoadMoreItens(Url('languages', '', `${currPage}`, 'ASC')) + } else { + LoadMoreItens(Url('languages', '', `${currPage}`, 'DESC')) + } + }} + > + { + isLoadingMoreItems ? <CircularProgress size={24} /> : 'Carregar mais itens' } - }} - > - { - isLoadingMoreItems ? <CircularProgress size={24} /> : 'Carregar mais itens' - } - </Button> - </div> + </Button> + </StyledTableCell> + </StyledTableRow> : diff --git a/src/Admin/Pages/Pages/SubPages/NoteVariables.js b/src/Admin/Pages/Pages/SubPages/NoteVariables.js index aa5213c5..3d242bb2 100644 --- a/src/Admin/Pages/Pages/SubPages/NoteVariables.js +++ b/src/Admin/Pages/Pages/SubPages/NoteVariables.js @@ -150,11 +150,11 @@ const NoteVariables = () => { GetFullList(Url('scores', '', '0', 'DESC')) .then( (result) => { - if(result.state){ + if (result.state) { setIsLoaded(true); setItems(result.data.concat(AddOneLenght)); } else setError(true); - + }, ) }, []); @@ -163,7 +163,7 @@ const NoteVariables = () => { if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> + return <LoadingSpinner text="Carregando..." /> } else { //Words in the top part of the table @@ -193,9 +193,6 @@ const NoteVariables = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -229,27 +226,29 @@ const NoteVariables = () => { <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <div style={{ padding: '1em' }}> + <StyledTableRow key={index}> {/* Button to load more data */} - <Button - color='primary' - variant='text' - disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - onClick={() => { - currPage++ - if (transformListToAsc) { - LoadMoreItens(Url('scores', '', `${currPage}`, 'ASC')) - } else { - LoadMoreItens(Url('scores', '', `${currPage}`, 'DESC')) + <StyledTableCell> + <Button + color='primary' + variant='text' + disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + onClick={() => { + currPage++ + if (transformListToAsc) { + LoadMoreItens(Url('scores', '', `${currPage}`, 'ASC')) + } else { + LoadMoreItens(Url('scores', '', `${currPage}`, 'DESC')) + } + }} + > + { + isLoadingMoreItems ? <CircularProgress /> : 'Carregar mais itens' } - }} - > - { - isLoadingMoreItems ? <CircularProgress /> : 'Carregar mais itens' - } - </Button> - </div> + </Button> + </StyledTableCell> + </StyledTableRow> : diff --git a/src/Admin/Pages/Pages/SubPages/Questions.js b/src/Admin/Pages/Pages/SubPages/Questions.js index 7d83877e..08fcdd01 100644 --- a/src/Admin/Pages/Pages/SubPages/Questions.js +++ b/src/Admin/Pages/Pages/SubPages/Questions.js @@ -93,19 +93,19 @@ const Questions = () => { } const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; - 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 load more items @@ -220,8 +220,7 @@ const Questions = () => { GetFullList(Url('questions', '', `${currPage}`, 'DESC')) .then( (result) => { - if(result.state) - { + if (result.state) { setIsLoaded(true); setItems(result.data.concat(ADD_ONE_LENGHT)); } else setError(true) @@ -233,8 +232,8 @@ const Questions = () => { if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> - } else if(CheckUserPermission()){ + return <LoadingSpinner text="Carregando..." /> + } else if (CheckUserPermission()) { return ( <> <SnackBar @@ -260,9 +259,6 @@ const Questions = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -289,7 +285,7 @@ const Questions = () => { variant="contained" color="secondary" startIcon={<AddRoundedIcon />} - onClick={() => {currPage = 0}} + onClick={() => { currPage = 0 }} > Novo </Button> @@ -309,28 +305,30 @@ const Questions = () => { <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <div style={{ padding: '1em' }}> + <StyledTableRow key={index}> {/* Button to load more data */} - <Button - color='primary' - variant='text' - // disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - disabled={isLoadingMoreItems} - onClick={() => { - currPage++ - if (transformListToAsc) { - LoadMoreItens(Url('questions', '', `${currPage}`, 'ASC')) - } else { - LoadMoreItens(Url('questions', '', `${currPage}`, 'DESC')) + <StyledTableCell> + <Button + color='primary' + variant='text' + // disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + disabled={isLoadingMoreItems} + onClick={() => { + currPage++ + if (transformListToAsc) { + LoadMoreItens(Url('questions', '', `${currPage}`, 'ASC')) + } else { + LoadMoreItens(Url('questions', '', `${currPage}`, 'DESC')) + } + }} + > + { + isLoadingMoreItems ? <CircularProgress size={24} /> : 'Carregar mais itens' } - }} - > - { - isLoadingMoreItems ? <CircularProgress size={24} /> : 'Carregar mais itens' - } - </Button> - </div> + </Button> + </StyledTableCell> + </StyledTableRow> : @@ -341,12 +339,10 @@ const Questions = () => { <StyledTableCell align="right"> { row.status === 'active' ? - <Grid container justify='flex-end' alignItems='center' direction='row'> + <Grid container direction='row'> <Grid item> <CheckCircleRoundedIcon style={{ fill: '#3CB371' }} /> - </Grid> - - <Grid item> + <Switch checked={true} onChange={() => handleChange(index, row.status)} @@ -381,6 +377,6 @@ const Questions = () => { </TableData> </> ); - } else return <Unauthorized/> + } else return <Unauthorized /> } export default Questions; \ No newline at end of file diff --git a/src/Admin/Pages/Pages/SubPages/Rating.js b/src/Admin/Pages/Pages/SubPages/Rating.js index b16ddeab..e102e928 100644 --- a/src/Admin/Pages/Pages/SubPages/Rating.js +++ b/src/Admin/Pages/Pages/SubPages/Rating.js @@ -189,8 +189,7 @@ const Ratings = () => { GetFullList(Url('ratings', '', currPage, 'DESC')) .then( (result) => { - if(result.state) - { + if (result.state) { setIsLoaded(true); setItems(result.data.concat(AddOneLenght)); } else setError(true) @@ -202,7 +201,7 @@ const Ratings = () => { if (error) { return <div>Error: {error.message}</div>; } else if (!isLoaded) { - return <LoadingSpinner text="Carregando..."/> + return <LoadingSpinner text="Carregando..." /> } else { //Words in the top part of the table @@ -232,9 +231,6 @@ const Ratings = () => { <Grid item xs={6} - alignItems="center" - justify="center" - direction="row" > <Grid container justify="flex-end" spacing={3}> <Grid item> @@ -283,27 +279,29 @@ const Ratings = () => { <TableBody> {items.map((row, index) => ( index === items.length - 1 ? - <div style={{ padding: '1em' }}> + <StyledTableRow key={index}> {/* Button to load more data */} - <Button - color='primary' - variant='text' - disabled={isLoadingMoreItems} - startIcon={<AddRoundedIcon />} - onClick={() => { - currPage++ - if (transformListToAsc) { - LoadMoreItens(Url('ratings', '', `${currPage}`, 'ASC')) - } else { - LoadMoreItens(Url('ratings', '', `${currPage}`, 'DESC')) + <StyledTableCell> + <Button + color='primary' + variant='text' + disabled={isLoadingMoreItems} + startIcon={<AddRoundedIcon />} + onClick={() => { + currPage++ + if (transformListToAsc) { + LoadMoreItens(Url('ratings', '', `${currPage}`, 'ASC')) + } else { + LoadMoreItens(Url('ratings', '', `${currPage}`, 'DESC')) + } + }} + > + { + isLoadingMoreItems ? <CircularProgress size={24} /> : 'Carregar mais itens' } - }} - > - { - isLoadingMoreItems ? <CircularProgress size={24} /> : 'Carregar mais itens' - } - </Button> - </div> + </Button> + </StyledTableCell> + </StyledTableRow> : diff --git a/src/Admin/Pages/Pages/SubPages/SendEmail.js b/src/Admin/Pages/Pages/SubPages/SendEmail.js index 2ec61774..e48e5361 100644 --- a/src/Admin/Pages/Pages/SubPages/SendEmail.js +++ b/src/Admin/Pages/Pages/SubPages/SendEmail.js @@ -61,10 +61,10 @@ const SendEmail = ({ match }) => { const classes = useStyles(); const CheckUserPermission = () => { - const roles = [...state.currentUser.roles]; let canUserEdit = false; if (state.userIsLoggedIn) { + const roles = [...state.currentUser.roles]; for (let i = 0; i < roles.length; i++) if (roles[i].name === 'admin' || roles[i].name === 'editor') canUserEdit = true; @@ -78,7 +78,7 @@ const SendEmail = ({ match }) => { if(CheckUserPermission()){ return ( - <Card className={classes.root} variant="outlined"> + <Card> <CardContent> <Typography className={classes.title} diff --git a/src/App.js b/src/App.js index 65519f67..411ffd82 100644 --- a/src/App.js +++ b/src/App.js @@ -46,6 +46,7 @@ import EditProfilePage from './Pages/EditProfilePage.js' import PublicUserPage from './Pages/PublicUserPage.js' import UploadPage from './Pages/UploadPage.js' import EditLearningObjectPage from './Pages/EditLearningObjectPage.js' +import Welcome from './Admin/Components/Components/Welcome'; const App = (props) => { // eslint-disable-next-line -- GitLab