source: client_app/src/components/main/App.js@ c9fa474

Last change on this file since c9fa474 was c9fa474, checked in by i-ina <76742075+i-ina@…>, 3 years ago

cleaning

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