Changeset 6f9b7b0 for client_app/src/components/main
- Timestamp:
- 01/10/21 21:16:40 (4 years ago)
- Branches:
- master
- Children:
- fc8421e
- Parents:
- 17abe5e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client_app/src/components/main/App.js
r17abe5e r6f9b7b0 1 1 import React, {Component} from 'react'; 2 import {BrowserRouter as Router, Route } from 'react-router-dom';2 import {BrowserRouter as Router, Route, Redirect} from 'react-router-dom'; 3 3 import Login from '../login/login'; 4 4 import Profile from "../data/profile"; … … 12 12 super(props); 13 13 this.state = { 14 currentUser: {} 14 logged: false, 15 error: null, 16 currentUser: {} 15 17 } 16 18 } 17 19 18 20 render(){ 19 return( 20 <Router> 21 <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name}/> 22 <main> 23 <Route path={"/login"} render={() => <Login onCompleteForm={this.attemptLogin}/>}/> 24 <Route path={"/profile"} render={() => <Profile userProfile={this.state.currentUser}/>}/> 25 <Route path={"/"}/> 26 <Route path={"/jobs"}/> 27 <Route path={"/internships"}/> 28 </main> 29 </Router> 30 ); 21 return( 22 <Router> 23 <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name}/> 24 <main> 25 <Route path={"/login"} render={() => <Login error={this.state.error} onCompleteForm={this.attemptLogin} loggedIn={this.state.logged}/>}/> 26 <Route path={"/profile"} render={() => <Profile userProfile={this.state.currentUser}/>}/> 27 <Route path={"/"} render={() => <Redirect to={"/login"}/>}/> 28 </main> 29 </Router> 30 ); 31 31 } 32 32 33 33 attemptLogin = (email, password, type) => { 34 35 34 UserLogin.login(email, password, type).then((res) =>{ 36 35 console.log(res.data); 37 this.setState({ 38 currentUser: res.data 39 }); 36 if(res.data.email==null){ 37 this.setState({ 38 logged: false, 39 error: res.data.error, 40 }); 41 }else{ 42 this.setState({ 43 logged: true, 44 currentUser: res.data, 45 error: null, 46 }); 47 } 40 48 }); 49 50 if(this.state.currentUser.email!=null){ 51 return <Redirect to={"/profile"}/>; 52 } 41 53 } 42 54 }
Note:
See TracChangeset
for help on using the changeset viewer.