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