source: client_app/src/components/main/App.js@ 8f1f460

Last change on this file since 8f1f460 was fc8421e, checked in by i-ina <76742075+i-ina@…>, 4 years ago

initial jobs interface

  • Property mode set to 100644
File size: 1.9 KB
Line 
1import React, {Component} from 'react';
2import {BrowserRouter as Router, Route, Redirect} from 'react-router-dom';
3import Login from '../login/login';
4import Profile from "../data/profile";
5import 'semantic-ui-css/semantic.min.css';
6import HeaderComp from '../template/header';
7import './App.css';
8import UserLogin from "../../repository/login_repo";
9import UserJobs from "../data/components/user_jobs";
10
11class App extends Component{
12 constructor(props) {
13 super(props);
14 this.state = {
15 logged: false,
16 error: null,
17 currentUser: {
18 }
19 }
20 }
21
22 render(){
23 return(
24 <Router>
25 <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name}/>
26 <main>
27 <Route path={"/login"} render={() => <Login error={this.state.error} onCompleteForm={this.attemptLogin} loggedIn={this.state.logged}/>}/>
28 <Route path={"/profile"} render={() => <Profile userProfile={this.state.currentUser}/>}/>
29 <Route path={"/jobs"} render={() => <UserJobs userProfile={this.state.currentUser}/>}/>
30 <Route path={"/"} render={() => <Redirect to={"/login"}/>}/>
31 </main>
32 </Router>
33 );
34 }
35
36 attemptLogin = (email, password, type) => {
37 UserLogin.login(email, password, type).then((res) =>{
38 console.log(res.data);
39 if(res.data.email==null){
40 this.setState({
41 logged: false,
42 error: res.data.error,
43 });
44 }else{
45 this.setState({
46 logged: true,
47 currentUser: res.data,
48 error: null,
49 });
50 }
51 });
52
53 if(this.state.currentUser.email!=null){
54 return <Redirect to={"/profile"}/>;
55 }
56 }
57}
58
59export default App;
Note: See TracBrowser for help on using the repository browser.