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