1 | import React, {Component} from 'react';
|
---|
2 | import {BrowserRouter as Router, Route, Redirect} from 'react-router-dom';
|
---|
3 | import Login from '../login/login';
|
---|
4 | import Profile from "../profiles/profile";
|
---|
5 | import 'semantic-ui-css/semantic.min.css';
|
---|
6 | import HeaderComp from '../template/header';
|
---|
7 | import './App.css';
|
---|
8 | import UserLogin from "../../repository/login_repo";
|
---|
9 | import UserJobs from "../work/user_jobs";
|
---|
10 | import UserInternships from "../work/user_internships";
|
---|
11 | import UserProjects from "../work/user_projects";
|
---|
12 | import CompanyJobs from "../work/company_jobs";
|
---|
13 | import TeamProjects from "../work/team_projects";
|
---|
14 | import TeamJobs from "../work/team_jobs";
|
---|
15 | import CompanyInternships from "../work/company_internships";
|
---|
16 | import UserRegister from "../../repository/register_repo";
|
---|
17 | import RegisterUser from "../register/register_user_form";
|
---|
18 |
|
---|
19 | class App extends Component{
|
---|
20 | constructor(props) {
|
---|
21 | super(props);
|
---|
22 | this.state = {
|
---|
23 | logged: false,
|
---|
24 | error: null,
|
---|
25 | currentUser: {
|
---|
26 | }
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | render(){
|
---|
31 | return(
|
---|
32 | <Router>
|
---|
33 | <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name} removeState={this.removeState}/>
|
---|
34 | <main>
|
---|
35 | <Route path={"/login"} render={() => <Login error={this.state.error} onCompleteForm={this.attemptLogin} loggedIn={this.state.logged}/>}/>
|
---|
36 | <Route path={"/profile"} render={() => <Profile userProfile={this.state.currentUser}/>}/>
|
---|
37 | <Route path={"/user/jobs"} render={() => <UserJobs userProfile={this.state.currentUser}/>}/>
|
---|
38 | <Route path={"/user/internships"} render={() => <UserInternships userProfile={this.state.currentUser}/>}/>
|
---|
39 | <Route path={"/user/projects"} render={() => <UserProjects userProfile={this.state.currentUser}/>}/>
|
---|
40 | <Route path={"/team/jobs"} render={() => <TeamJobs userProfile={this.state.currentUser}/>}/>
|
---|
41 | <Route path={"/team/projects"} render={() => <TeamProjects userProfile={this.state.currentUser}/>}/>
|
---|
42 | <Route path={"/company/jobs"} render={() => <CompanyJobs userProfile={this.state.currentUser}/>}/>
|
---|
43 | <Route path={"/company/internships"} render={() => <CompanyInternships userProfile={this.state.currentUser}/>}/>
|
---|
44 | <Route path={"/register/user"} render={() => <RegisterUser error={null}/>}/>
|
---|
45 | <Route path={"/logout"} render={() => <Redirect to={"/login"}/>}/>
|
---|
46 | <Route path={"/"} render={() => <Redirect to={"/login"}/>}/>
|
---|
47 | </main>
|
---|
48 | </Router>
|
---|
49 | );
|
---|
50 | }
|
---|
51 |
|
---|
52 | removeState = () => {
|
---|
53 | this.setState({
|
---|
54 | logged: false,
|
---|
55 | error: null,
|
---|
56 | currentUser: {}
|
---|
57 | })
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | attemptLogin = (email, password, type) => {
|
---|
62 | UserLogin.login(email, password, type).then((res) =>{
|
---|
63 | console.log(res.data);
|
---|
64 | if(res.data.email==null){
|
---|
65 | this.setState({
|
---|
66 | logged: false,
|
---|
67 | error: res.data.error,
|
---|
68 | });
|
---|
69 | }else{
|
---|
70 | this.setState({
|
---|
71 | logged: true,
|
---|
72 | currentUser: res.data,
|
---|
73 | error: null,
|
---|
74 | });
|
---|
75 | }
|
---|
76 | });
|
---|
77 |
|
---|
78 | if(this.state.currentUser.email!=null){
|
---|
79 | return <Redirect to={"/profile"}/>;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | export default App;
|
---|