source: client_app/src/components/main/App.js@ 351c43f

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

begining register form

  • Property mode set to 100644
File size: 3.5 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 UserRegister from "../../repository/register_repo";
17
18class App extends Component{
19 constructor(props) {
20 super(props);
21 this.state = {
22 logged: false,
23 error: null,
24 currentUser: {
25 }
26 }
27 }
28
29 render(){
30 return(
31 <Router>
32 <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name} removeState={this.removeState}/>
33 <main>
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}/>} />
39 <Route path={"/team/jobs"} render={() => <TeamJobs userProfile={this.state.currentUser} />}/>
40 <Route path={"/team/projects"} render={() => <TeamProjects userProfile={this.state.currentUser} />}/>
41 <Route path={"/company/jobs"} render={() => <CompanyJobs userProfile={this.state.currentUser} />}/>
42 <Route path={"/company/internships"} render={() => <CompanyInternships userProfile={this.state.currentUser}/>} />
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"}/>}/>
48 <Route path={"/"} render={() => <Redirect to={"/login"}/>}/>
49 </main>
50 </Router>
51 );
52 }
53
54 removeState = () => {
55 this.setState({
56 logged: false,
57 error: null,
58 currentUser: {}
59 })
60 }
61
62
63 attemptLogin = (email, password, type) => {
64 UserLogin.login(email, password, type).then((res) =>{
65 console.log(res.data);
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 }
78 });
79
80
81
82 registerUser = () =>{
83 UserRegister.userRegister()
84 }
85
86 if(this.state.currentUser.email!=null){
87 return <Redirect to={"/profile"}/>;
88 }
89 }
90}
91
92export default App;
Note: See TracBrowser for help on using the repository browser.