diff --git a/src/Components/Header.js b/src/Components/Header.js index 88694bd3dbceb978e008c2a7ccd97efb7c43ee69..329e455e9692552e6e6f93d27e34cc93ccadbc1e 100644 --- a/src/Components/Header.js +++ b/src/Components/Header.js @@ -30,7 +30,6 @@ import Snackbar from '@material-ui/core/Snackbar'; import MuiAlert from '@material-ui/lab/Alert'; import {useLocation} from 'react-router-dom' import MenuBarMobile from './MenuBarMobile.js' -import { useCookies } from "react-cookie"; //const StyledButton = styled(Button)` // background : #ffa54c !important; @@ -47,7 +46,6 @@ export default function Header(props){ const [loginOpen, setLogin] = useState(false) const [successfulLoginOpen, handleSuccessfulLogin] = useState(false) const [modalColaborar, setModalColaborar] = useState(false) - const [cookies, setCookie, removeCookie] = useCookies(["auth_headers"]); const validateToken = (config) => { axios.get(`${apiUrl}/auth/validate_token/`, config).then( @@ -62,8 +60,7 @@ export default function Header(props){ login: response.data.data } ) - sessionStorage.setItem('@portalmec/accessToken', response.headers['access-token']) - sessionStorage.setItem('@portalmec/clientToken', response.headers.client) + sessionStorage.setItem('@portalmec/id', response.data.data.id) sessionStorage.setItem('@portalmec/username', response.data.data.name) sessionStorage.setItem('@portalmec/uid', response.data.data.uid) @@ -150,7 +147,7 @@ export default function Header(props){ let windowWidth = window.innerWidth return ( - <React.Fragment style={{paddingTop : "10px"}}> + <React.Fragment> {/* windowWidth > 990 && <AcessibilityBar/> diff --git a/src/Components/MenuBar.js b/src/Components/MenuBar.js index ebcea91971f2d5fe4bf09719e33faaffb52809a9..dd911f2b4f04d9f33403cb8eda7f1d0a0d30f408 100644 --- a/src/Components/MenuBar.js +++ b/src/Components/MenuBar.js @@ -98,7 +98,7 @@ export const ButtonPubRecursoStyled = styled(Button)` export default function MenuBar(props){ - const { state, dispatch } = useContext(Store) + const { state } = useContext(Store) const menuSobre = [ { name: "Sobre a Plataforma", href: "sobre" }, @@ -145,7 +145,7 @@ export default function MenuBar(props){ ? ( <> <div style={{boxSizing:"border-box"}}> - <Link to="/termos-publicar-recurso" cameFromPublishButton={true}> + <Link to="/termos-publicar-recurso"> <ButtonPublicarRecurso> <CloudUploadIcon style={{color:"white", marginLeft : "0"}}/> <span style={{color : "#fff", textAlign: "center", alignSelf : "center", fontWeight:"500"}} > diff --git a/src/Components/MenuList.js b/src/Components/MenuList.js index 6236239d8809005fd81d79cc0593fc8a3d9a8a64..08b98c5a770610790ace06b2309a49183186d0dd 100644 --- a/src/Components/MenuList.js +++ b/src/Components/MenuList.js @@ -127,7 +127,7 @@ export default function MenuList(props) { <Link to={{ pathname : item.href, state : item.value - }} style={{textDecoration:"none"}} key={item.value}><MenuItem style= {{fontSize:"14px", padding:"5px 20px", color:"#666"}}>{item.name}</MenuItem></Link> + }} style={{textDecoration:"none"}} key={item.value}><MenuItem style= {{fontSize:"14px", padding:"5px 20px", color:"#666"}} key={item.value}>{item.name}</MenuItem></Link> ) } <StyledButtonSair onClick={handleLogout}> <StyledMenuItem disableGutters={true}>Sair<StyledExitToAppIcon/></StyledMenuItem></StyledButtonSair> diff --git a/src/Components/ReportColecaoForm.js b/src/Components/ReportColecaoForm.js index fcea00e793912b73c072b2b146a33d809be9402c..a64164eb04fbc3e8aa7bdff9f9ce4e19dc0439aa 100644 --- a/src/Components/ReportColecaoForm.js +++ b/src/Components/ReportColecaoForm.js @@ -15,7 +15,7 @@ GNU Affero General Public License for more details. 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, {useContext} from 'react'; +import React from 'react'; import { Button } from '@material-ui/core'; import styled from 'styled-components' import Radio from '@material-ui/core/Radio'; diff --git a/src/Components/ReportCollectionForm.js b/src/Components/ReportCollectionForm.js index 0832b014c1a6bd9314eccbce7fd712918f33ed26..34fd87b2417016fa80fc43bce90300242a764901 100644 --- a/src/Components/ReportCollectionForm.js +++ b/src/Components/ReportCollectionForm.js @@ -15,7 +15,7 @@ GNU Affero General Public License for more details. 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, {useContext} from 'react'; +import React from 'react'; import { Button } from '@material-ui/core'; import styled from 'styled-components' import Radio from '@material-ui/core/Radio'; @@ -101,4 +101,3 @@ export default function ReportRecursoForm (props) { </form> ) } - diff --git a/src/Components/ReportRecursoForm.js b/src/Components/ReportRecursoForm.js index 66704bde8cda4ddad3c60c4aaf3ecd22e74760f8..d6c2a70b9429ab08ecefb8257dade87bdf152264 100644 --- a/src/Components/ReportRecursoForm.js +++ b/src/Components/ReportRecursoForm.js @@ -15,7 +15,7 @@ GNU Affero General Public License for more details. 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, {useContext} from 'react'; +import React from 'react'; import { Button } from '@material-ui/core'; import styled from 'styled-components' import Radio from '@material-ui/core/Radio'; diff --git a/src/Components/StoreGuide.js b/src/Components/StoreGuide.js index a4b0f509b11a3c8ab590e397c1fe07e9ba616c5c..3d9ca95a54437548d1d18f01dfabe7a0a12c738e 100644 --- a/src/Components/StoreGuide.js +++ b/src/Components/StoreGuide.js @@ -15,7 +15,7 @@ GNU Affero General Public License for more details. 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, {useState, useContext} from 'react'; +import React from 'react'; import styled from 'styled-components'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; @@ -68,7 +68,7 @@ export default function ItemStoreContainer (props) { As seções da loja dividem os itens por <strong>categoria</strong>. <ul> <li> - Itens adquiridos <strong>somente por conquistas</strong> não aparecem + Itens adquiridos <strong>somente por conquistas</strong> não aparecem na loja (exceto pelos que você já tem); </li> <li> diff --git a/src/Components/TabPanels/UserPageTabs/ModalExcluirConta.js b/src/Components/TabPanels/UserPageTabs/ModalExcluirConta.js index 43ff66284eca688e2582703fa8c988bcb6798027..05c08553ec5aa93fbc965266cf89dacf0f59bbd0 100644 --- a/src/Components/TabPanels/UserPageTabs/ModalExcluirConta.js +++ b/src/Components/TabPanels/UserPageTabs/ModalExcluirConta.js @@ -124,7 +124,7 @@ export default function ModalExcluirConta (props) { handleChange={e => handleChange(e)} required={true} error = {formEmail.key} - help = {formEmail.key ? ( formEmail.value.length == 0 ? "Faltou preencher seu e-mail." : "O e-mail deve ser o mesmo no qual você cadastrou esta conta") : ""} + help = {formEmail.key ? ( formEmail.value.length === 0 ? "Faltou preencher seu e-mail." : "O e-mail deve ser o mesmo no qual você cadastrou esta conta") : ""} /> <div style={{display : "flex", flexDirection : "row", justifyContent : "space-evenly", paddingTop : "15px"}}> <GreyButton callback={props.handleClose} text={"Cancelar"}/> diff --git a/src/Components/TabPanels/UserPageTabs/PanelAtividades.js b/src/Components/TabPanels/UserPageTabs/PanelAtividades.js index 7e7b7b00cbebbe058420cdbb184d808920c2c7cf..3f3632dd609ec9598fc0ab201a81f872ca060d85 100644 --- a/src/Components/TabPanels/UserPageTabs/PanelAtividades.js +++ b/src/Components/TabPanels/UserPageTabs/PanelAtividades.js @@ -27,6 +27,7 @@ import Bolo from '../../../img/Bolo.png' import LoadingSpinner from '../../LoadingSpinner.js' import ActivityListItem from '../../ActivityListItem.js' import List from '@material-ui/core/List'; +import {getAxiosConfig} from '../../HelperFunctions/getAxiosConfig.js' export default function TabPanelAtividades (props) { const [loading, handleLoading] = useState(true) @@ -41,22 +42,22 @@ export default function TabPanelAtividades (props) { } useEffect( () => { - axios.get(`${apiUrl}/feed?offset=0&limit=30`, props.config) + let config = getAxiosConfig() + + axios.get(`${apiUrl}/feed?offset=0&limit=30`, config) .then( (response) => { if ( response.headers['access-token'] ) { sessionStorage.setItem('@portalmec/accessToken', response.headers['access-token']) } - console.log('atividades response: ', response) setNotifications(response.data) setNotificationsSlice(response.data.slice(0,30)) setLength(response.data.length) - handleLoading(false) }, (error) => { - console.log('error while running getNotifications') + console.log(error) } ) }, []) @@ -85,7 +86,7 @@ export default function TabPanelAtividades (props) { { notificatonsLength == 0 ? ( - [ + <NoNotificationsDiv> <div> <div> @@ -99,11 +100,11 @@ export default function TabPanelAtividades (props) { </p> </div> </NoNotificationsDiv> - ] + ) : ( - [ <> + <> <List height={400} width={300}> { notificationsSlice.map( (notification) => @@ -125,7 +126,6 @@ export default function TabPanelAtividades (props) { <LoadMoreButton onClick={() => {showMore(20)}}><span>CARREGAR MAIS 20</span></LoadMoreButton> <span style={{fontSize:"14px", color : "#666"}}>Mostrando {notificationsSlice.length} de {notificatonsLength}</span> </> - ] ) } </div> diff --git a/src/Components/TabPanels/UserPageTabs/PanelEditarPerfil.js b/src/Components/TabPanels/UserPageTabs/PanelEditarPerfil.js index 25bf953c61b91c41329ec2c58fa1ae576d913afb..4f6030b43b6799661b2517d909a89a5b567e6fdf 100644 --- a/src/Components/TabPanels/UserPageTabs/PanelEditarPerfil.js +++ b/src/Components/TabPanels/UserPageTabs/PanelEditarPerfil.js @@ -61,14 +61,14 @@ export default function TabPanelEditarPerfil (props) { key : flag, value : userInput }) - console.log(formNome) + } else if (type === 'aboutMe') { setAboutMe({...formAboutMe, key : flag, value : userInput, }) - console.log(formAboutMe) + } } @@ -86,12 +86,12 @@ export default function TabPanelEditarPerfil (props) { const handleSubmit = (e) => { e.preventDefault() - const info = {nome : formNome.value, aboutMe : formAboutMe.value} + const info = {user : {name : formNome.value, description : formAboutMe.value, email : sessionStorage.getItem('@portalmec/uid')}} const flagNome = formNome.key const flagAboutMe = formAboutMe.key if (!(flagNome || flagAboutMe)) { - console.log(info) + props.updateUserInfo(info) limpaCamposForm() } } diff --git a/src/Components/TabPanels/UserPageTabs/PanelGerenciarConta.js b/src/Components/TabPanels/UserPageTabs/PanelGerenciarConta.js index e111f1a941dada230b02d11f440a3bd424dd3da6..0726f2c3db218e54a0762813501bc02928e7b7f2 100644 --- a/src/Components/TabPanels/UserPageTabs/PanelGerenciarConta.js +++ b/src/Components/TabPanels/UserPageTabs/PanelGerenciarConta.js @@ -59,21 +59,18 @@ export default function TabPanelGerenciarConta (props) { key : flag, value : userInput }) - console.log(senhaAtual) } else if(type === 'novaSenha') { setNovaSenha({...novaSenha, key : flag, value : userInput }) - console.log(novaSenha) } else if (type === 'confirmacao'){ setNovaSenhaConfirmacao({...novaSenhaConfirmacao, key : flag, value : userInput }) - console.log(novaSenhaConfirmacao) } } @@ -86,7 +83,6 @@ export default function TabPanelGerenciarConta (props) { value : userInput }) - console.log(novoEmail) } const limpaCamposForm = () => { @@ -110,21 +106,18 @@ export default function TabPanelGerenciarConta (props) { e.preventDefault() if (type === 'senha'){ - if (senhaAtual.value === localStorage.getItem("@portalmec/senha")) { - const login = {senhaAtual : senhaAtual.value, novaSenha : novaSenha.value, novaSenhaConfirmacao : novaSenhaConfirmacao.value} - - if (!(senhaAtual.key || novaSenha.key || novaSenhaConfirmacao.key)) { - console.log(login) - limpaCamposForm() - props.handleSnackbar() - } - } - else { - console.log(localStorage.getItem("@portalmec/senha"), senhaAtual.value) + if (!(senhaAtual.key || novaSenha.key || novaSenhaConfirmacao.key)) { + const info = {user : {password : novaSenha.value}} + props.updateUserPassword(info) + + limpaCamposForm() } } else { - console.log(novoEmail.value) + const info = {user : {email : novoEmail.value}} + + props.updateUserEmail(info) + } } @@ -222,4 +215,3 @@ export default function TabPanelGerenciarConta (props) { </> ) } - diff --git a/src/Components/UserCardGamified.js b/src/Components/UserCardGamified.js index 711b9ee433f6a13fcb6f6cbea4c120d8c5793233..701092103949ec94cd529977d44b2396205e7fae 100644 --- a/src/Components/UserCardGamified.js +++ b/src/Components/UserCardGamified.js @@ -15,7 +15,7 @@ GNU Affero General Public License for more details. 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, {useState, useContext} from 'react'; +import React from 'react'; import styled from 'styled-components'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; diff --git a/src/Components/UserPageComponents/SubmitterStatus.js b/src/Components/UserPageComponents/SubmitterStatus.js index 47924373223205e9a81575cc957fbb4f371bce34..435b369560774f2342c7a8ec1676564d2ae3f1db 100644 --- a/src/Components/UserPageComponents/SubmitterStatus.js +++ b/src/Components/UserPageComponents/SubmitterStatus.js @@ -39,7 +39,7 @@ export default function SubmitterStatus (props) { <p style={{fontSize:"15px", lineHeight:"22px", textAlign:"left", margin:"0 0 10px"}}> <span style={{cursor:"pointer"}}> <span style={{paddingRight:"5px"}}> - <img src={CheckDecagram}/> + <img src={CheckDecagram} alt='check icon'/> </span> {text} <span style={{color:"#00bcd4"}}> SAIBA MAIS</span> diff --git a/src/Pages/Accessibility.js b/src/Pages/Accessibility.js index ff57fd98b3f5d3f546dfa3018f28b6f0478b32d2..4f10f78403c02603b95d1d6355fd9c25a3333df8 100644 --- a/src/Pages/Accessibility.js +++ b/src/Pages/Accessibility.js @@ -15,7 +15,7 @@ GNU Affero General Public License for more details. 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, {useState, useContext} from 'react'; +import React from 'react'; import styled from 'styled-components' import { Link } from "react-router-dom"; import Breadcrumbs from "@material-ui/core/Breadcrumbs"; diff --git a/src/Pages/EditProfilePage.js b/src/Pages/EditProfilePage.js index 2d142d5932ada235c199b1e011ff168025afad35..35d8e5632a01d89fc375c538933aae0570e127c5 100644 --- a/src/Pages/EditProfilePage.js +++ b/src/Pages/EditProfilePage.js @@ -12,8 +12,15 @@ import MuiAlert from '@material-ui/lab/Alert'; import {Alert} from '../Components/LoginModal.js' import Grid from '@material-ui/core/Grid' import CustomizedBreadcrumbs from '../Components/TabPanels/Breadcrumbs.js' +import axios from 'axios' +import {getAxiosConfig} from '../Components/HelperFunctions/getAxiosConfig' +import {apiUrl} from '../env.js' +import {Store} from '../Store.js' export default function EditProfilePage (props) { + const {state} = useContext(Store) + const id = state.currentUser.id + const [tabs, setTabs] = useState([ 'Editar Perfil', 'Solicitar conta de Professor', 'Gerenciar Conta' ]) @@ -30,6 +37,67 @@ export default function EditProfilePage (props) { handleSnackbar(false); } + + const updateUserInfo = (newUserInfo) => { + console.log(newUserInfo) + let config = getAxiosConfig() + + axios.put( (`${apiUrl}/users/` + id), newUserInfo, config + ).then ( + (res) => { + console.log(res) + if ( res.headers['access-token'] ) { + sessionStorage.setItem('@portalmec/accessToken', res.headers['access-token']) + } + + props.history.push('/perfil') + + }, + (err) => { + console.log(err) + } + ) + } + + const updateUserEmail = (newUserInfo) => { + let config = getAxiosConfig() + + axios.put( (`${apiUrl}/users/` + id), newUserInfo, config + ).then ( + (res) => { + console.log(res) + if ( res.headers['access-token'] ) { + sessionStorage.setItem('@portalmec/accessToken', res.headers['access-token']) + } + + sessionStorage.setItem('@portalmec/uid', res.headers['uid']) + }, + (err) => { + console.log(err) + } + ) + } + + const updateUserPassword = (newUserInfo) => { + let config = getAxiosConfig() + + axios.put( (`${apiUrl}/users/` + id), newUserInfo, config + ).then ( + (res) => { + console.log(res) + if ( res.headers['access-token'] ) { + sessionStorage.setItem('@portalmec/accessToken', res.headers['access-token']) + } + + handleSnackbar(true) + + }, + (err) => { + console.log(err) + } + ) + } + return ( <div style={{backgroundColor:"#f4f4f4", color:"#666"}}> <Snackbar open={snackbarOpened} autoHideDuration={1000} onClose={handleCloseSnackbar} @@ -66,10 +134,12 @@ export default function EditProfilePage (props) { </Grid> <TabContentDiv item xs={9}> <Paper elevation={3} style= {{width:"100%"}}> - {tabValue === 0 && <TabPanelEditarPerfil />} + {tabValue === 0 && <TabPanelEditarPerfil updateUserInfo={updateUserInfo}/>} {tabValue === 1 && <TabPanelSolicitarContaProfessor/>} </Paper> - {tabValue === 2 && <TabPanelGerenciarConta handleSnackbar={() => {handleSnackbar(true)}}/>} + {tabValue === 2 && <TabPanelGerenciarConta updateUserEmail={updateUserEmail} + updateUserPassword={updateUserPassword} + />} </TabContentDiv> </MainContainerDiv> </div> diff --git a/src/Pages/SiteMap.js b/src/Pages/SiteMap.js index 13d6eb97e97a57234e4a7f452c264ba5995b3392..492d885c0013422940f28347fed261584f82977d 100644 --- a/src/Pages/SiteMap.js +++ b/src/Pages/SiteMap.js @@ -15,7 +15,7 @@ GNU Affero General Public License for more details. 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, {useState, useContext} from 'react'; +import React from 'react'; import styled from 'styled-components' import { Link } from "react-router-dom"; import Breadcrumbs from "@material-ui/core/Breadcrumbs"; @@ -98,7 +98,7 @@ const StyledBreadCrumbs = styled(Breadcrumbs)` export default function SiteMap (props) { return ( <div style={{ padding:"0 0 30px 0",backgroundColor :"#f4f4f4"}}> - + <div style={breadCrumbs}> <StyledBreadCrumbs> <Link to="/">Página Inicial</Link> @@ -126,7 +126,7 @@ export default function SiteMap (props) { style={item} to={{ pathname: "plataforma-mec", - + state: { value: "0" } }} > O que é a Plataforma MEC</Link> @@ -138,7 +138,7 @@ export default function SiteMap (props) { }} > Publicando Recurso </Link> - + <Link style={item} to={{ @@ -151,7 +151,7 @@ export default function SiteMap (props) { style={item} to={{ pathname: "/participando-da-rede", - + state: { value: "0" } }} > Participando da Rede @@ -160,7 +160,7 @@ export default function SiteMap (props) { style={item} to={{ pathname: "gerenciando-conta", - + state: { value: "0" } }} > Gerenciando a conta @@ -183,6 +183,6 @@ export default function SiteMap (props) { </div> </div> </div> - </div> + </div> ); } diff --git a/src/Pages/UserPage.js b/src/Pages/UserPage.js index 139f63b60d93e7c147d53622ea4c50b5ac29ebd2..3e50ca2a57390a80cb912233f05dbd0072e5bfd9 100644 --- a/src/Pages/UserPage.js +++ b/src/Pages/UserPage.js @@ -40,6 +40,7 @@ import ProfileAvatar from '../Components/UserPageComponents/Avatar.js' import UserInfo from '../Components/UserPageComponents/UserInfo.js' import EditProfileButton from '../Components/UserPageComponents/EditProfileButton.js' import SubmitterStatus from '../Components/UserPageComponents/SubmitterStatus.js' +import {getAxiosConfig} from '../Components/HelperFunctions/getAxiosConfig.js' const GetHeaderConfig = () => { @@ -58,7 +59,7 @@ const GetHeaderConfig = () => { } export default function UserPage (props){ - const {state} = useContext(Store) + const {state, dispatch} = useContext(Store) const id = state.currentUser.id const [tabValue, setTabValue] = useState( @@ -72,26 +73,31 @@ export default function UserPage (props){ } useEffect( () => { + let config = getAxiosConfig() if (id != '') { - axios.get( (`${apiUrl}/users/` + id), { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Host': 'api.portalmec.c3sl.ufpr.br', - 'Cookie': '' - }) - .then( (response) => { - console.log(response) + axios.get( (`${apiUrl}/users/` + id), config) + .then( (response) => { + console.log(response) + dispatch ( { + type: 'GET_USER', + user: response.data + } + ) if((response.data.role_ids.includes(4))) { setTabs([ 'Atividades', 'Meus Recursos', 'Favoritos', 'Coleções', 'Rede', 'Curadoria' ]) } - }, - (error) => { - console.log('error while running ComponentDidMout') - } - )} + }).catch( (error) => { + if (error.statusText === 401) { + console.log('erro 401') + //validate Token + + //retry request + } + }) + } }, []) const redirect = () => { diff --git a/src/Store.js b/src/Store.js index 421c0128b55d8ce77d86b48fa82e0251258e820f..d53af64db8a76e34c23dd854893b0a03dd23dec6 100644 --- a/src/Store.js +++ b/src/Store.js @@ -113,26 +113,29 @@ function reducer(state, action) { ...state, userIsLoggedIn:false, currentUser: { - askTeacherQuestion : true, - id : '', - username : '', - email : '', - accessToken : '', - clientToken : '', - userAvatar : '', - userCover : '', - uid : '', - followCount : 0, - collectionsCount : 0, - submitter_request : 'default', - roles : [] - }, + askTeacherQuestion : false, + id : '', + name : '', + email : '', + avatar_file_name : '', + cover_file_name : '', + uid : '', + follows_count : 0, + collections_count : 0, + submitter_request : 'default', + roles : [] + }, } case 'TOGGLE_MODAL_COLABORAR_PLATAFORMA': return { ...state, modalColaborarPlataformaOpen : action.modalColaborarPlataformaOpen } + case 'GET_USER': + return { + ...state, + currentUser:action.user + } default: return state }