[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";
|
---|
[3f5bf9e] | 17 |
|
---|
| 18 | class App extends Component{
|
---|
| 19 | constructor(props) {
|
---|
| 20 | super(props);
|
---|
| 21 | this.state = {
|
---|
[6f9b7b0] | 22 | logged: false,
|
---|
| 23 | error: null,
|
---|
[fc8421e] | 24 | currentUser: {
|
---|
| 25 | }
|
---|
[3f5bf9e] | 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | render(){
|
---|
[6f9b7b0] | 30 | return(
|
---|
| 31 | <Router>
|
---|
[2e507a8] | 32 | <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name} removeState={this.removeState}/>
|
---|
[6f9b7b0] | 33 | <main>
|
---|
[2e507a8] | 34 | <Route path={"/login"} render={() => <Login error={this.state.error} onCompleteForm={this.attemptLogin} loggedIn={this.state.logged}/>} />
|
---|
| 35 | <Route path={"/profile"} render={() => <Profile userProfile={this.state.currentUser}/>} />
|
---|
| 36 | <Route path={"/user/jobs"} render={() => <UserJobs userProfile={this.state.currentUser}/>} />
|
---|
| 37 | <Route path={"/user/internships"} render={() => <UserInternships userProfile={this.state.currentUser}/>} />
|
---|
| 38 | <Route path={"/user/projects"} render={() => <UserProjects userProfile={this.state.currentUser}/>} />
|
---|
[48e4a3e] | 39 | <Route path={"/team/jobs"} render={() => <TeamJobs userProfile={this.state.currentUser} />}/>
|
---|
| 40 | <Route path={"/team/projects"} render={() => <TeamProjects userProfile={this.state.currentUser} />}/>
|
---|
[2e507a8] | 41 | <Route path={"/company/jobs"} render={() => <CompanyJobs userProfile={this.state.currentUser} />}/>
|
---|
[48e4a3e] | 42 | <Route path={"/company/internships"} render={() => <CompanyInternships userProfile={this.state.currentUser}/>} />
|
---|
[2e507a8] | 43 | <Route path={"/profile/edit"} />
|
---|
| 44 | <Route path={"/job/edit"} />
|
---|
| 45 | <Route path={"/internship/edit"}/>
|
---|
| 46 | <Route path={"/project/edit"} />
|
---|
| 47 | <Route path={"/logout"} render={() => <Redirect to={"/login"}/>}/>
|
---|
[6f9b7b0] | 48 | <Route path={"/"} render={() => <Redirect to={"/login"}/>}/>
|
---|
| 49 | </main>
|
---|
| 50 | </Router>
|
---|
| 51 | );
|
---|
[3f5bf9e] | 52 | }
|
---|
| 53 |
|
---|
[2e507a8] | 54 | removeState = () => {
|
---|
| 55 | this.setState({
|
---|
| 56 | logged: false,
|
---|
| 57 | error: null,
|
---|
| 58 | currentUser: {}
|
---|
| 59 | })
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 |
|
---|
[17abe5e] | 63 | attemptLogin = (email, password, type) => {
|
---|
| 64 | UserLogin.login(email, password, type).then((res) =>{
|
---|
[3f5bf9e] | 65 | console.log(res.data);
|
---|
[6f9b7b0] | 66 | if(res.data.email==null){
|
---|
| 67 | this.setState({
|
---|
| 68 | logged: false,
|
---|
| 69 | error: res.data.error,
|
---|
| 70 | });
|
---|
| 71 | }else{
|
---|
| 72 | this.setState({
|
---|
| 73 | logged: true,
|
---|
| 74 | currentUser: res.data,
|
---|
| 75 | error: null,
|
---|
| 76 | });
|
---|
| 77 | }
|
---|
[3f5bf9e] | 78 | });
|
---|
[6f9b7b0] | 79 |
|
---|
[351c43f] | 80 |
|
---|
| 81 |
|
---|
| 82 | registerUser = () =>{
|
---|
| 83 | UserRegister.userRegister()
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[6f9b7b0] | 86 | if(this.state.currentUser.email!=null){
|
---|
| 87 | return <Redirect to={"/profile"}/>;
|
---|
| 88 | }
|
---|
[3f5bf9e] | 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | export default App;
|
---|