diff --git a/src/Pages/EditProfilePage.js b/src/Pages/EditProfilePage.js index 2d142d5932ada235c199b1e011ff168025afad35..922c154498bb4e6c6ef94ccfda0dec34d6b20260 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,28 @@ 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) + } + ) + } + return ( <div style={{backgroundColor:"#f4f4f4", color:"#666"}}> <Snackbar open={snackbarOpened} autoHideDuration={1000} onClose={handleCloseSnackbar} @@ -66,7 +95,7 @@ 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)}}/>}