[3f5bf9e] | 1 | import React, {Component} from 'react';
|
---|
[6f9b7b0] | 2 | import {BrowserRouter as Router, Route, Redirect} from 'react-router-dom';
|
---|
[3f5bf9e] | 3 | import Login from '../login/login';
|
---|
[c9fa474] | 4 | import Profile from "../profiles/profile";
|
---|
[3f5bf9e] | 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";
|
---|
[c9fa474] | 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";
|
---|
[351c43f] | 16 | import UserRegister from "../../repository/register_repo";
|
---|
[19ad843] | 17 | import RegisterUser from "../register/register_user_form";
|
---|
[3f5bf9e] | 18 |
|
---|
| 19 | class App extends Component{
|
---|
| 20 | constructor(props) {
|
---|
| 21 | super(props);
|
---|
| 22 | this.state = {
|
---|
[6f9b7b0] | 23 | logged: false,
|
---|
| 24 | error: null,
|
---|
[fc8421e] | 25 | currentUser: {
|
---|
| 26 | }
|
---|
[3f5bf9e] | 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | render(){
|
---|
[6f9b7b0] | 31 | return(
|
---|
| 32 | <Router>
|
---|
[2e507a8] | 33 | <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name} removeState={this.removeState}/>
|
---|
[6f9b7b0] | 34 | <main>
|
---|
[19ad843] | 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}/>}/>
|
---|
[7944fab] | 44 | <Route path={"/register/user"} render={() => <RegisterUser error={null} success={null}/>}/>
|
---|
[2e507a8] | 45 | <Route path={"/logout"} render={() => <Redirect to={"/login"}/>}/>
|
---|
[6f9b7b0] | 46 | <Route path={"/"} render={() => <Redirect to={"/login"}/>}/>
|
---|
| 47 | </main>
|
---|
| 48 | </Router>
|
---|
| 49 | );
|
---|
[3f5bf9e] | 50 | }
|
---|
| 51 |
|
---|
[2e507a8] | 52 | removeState = () => {
|
---|
| 53 | this.setState({
|
---|
| 54 | logged: false,
|
---|
| 55 | error: null,
|
---|
| 56 | currentUser: {}
|
---|
| 57 | })
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 |
|
---|
[17abe5e] | 61 | attemptLogin = (email, password, type) => {
|
---|
| 62 | UserLogin.login(email, password, type).then((res) =>{
|
---|
[3f5bf9e] | 63 | console.log(res.data);
|
---|
[6f9b7b0] | 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 | }
|
---|
[3f5bf9e] | 76 | });
|
---|
[6f9b7b0] | 77 |
|
---|
| 78 | if(this.state.currentUser.email!=null){
|
---|
| 79 | return <Redirect to={"/profile"}/>;
|
---|
| 80 | }
|
---|
[3f5bf9e] | 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | export default App;
|
---|