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

Last change on this file since be373a8 was be373a8, checked in by Vzdra <vladko.zdravkovski@…>, 3 years ago

edit complete

  • Property mode set to 100644
File size: 4.7 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";
16import RegisterUser from "../register/register_user_form";
17import RegisterCompany from "../register/register_company_form";
18import RegisterTeam from "../register/register_team_form";
19import Search from "../filter/search";
20import EditUser from "../account_edit/user_edit";
21import EditCompany from "../account_edit/company_edit";
22import EditTeam from "../account_edit/team_edit";
23
24class 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
107export default App;
Note: See TracBrowser for help on using the repository browser.