[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";
|
---|
[580ba1a] | 19 | import Search from "../filter/search";
|
---|
| 20 | import EditUser from "../account_edit/user_edit";
|
---|
| 21 | import EditCompany from "../account_edit/company_edit";
|
---|
[be373a8] | 22 | import EditTeam from "../account_edit/team_edit";
|
---|
[db94dbd] | 23 | import JobRegister from "../work_register/job_register";
|
---|
| 24 | import InternshipRegister from "../work_register/internship_register";
|
---|
| 25 | import ProjectRegister from "../work_register/project_register";
|
---|
[3f5bf9e] | 26 |
|
---|
| 27 | class App extends Component{
|
---|
| 28 | constructor(props) {
|
---|
| 29 | super(props);
|
---|
| 30 | this.state = {
|
---|
[6f9b7b0] | 31 | logged: false,
|
---|
| 32 | error: null,
|
---|
[df3a395] | 33 | success: null,
|
---|
[fc8421e] | 34 | currentUser: {
|
---|
| 35 | }
|
---|
[3f5bf9e] | 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
[580ba1a] | 39 | render(){
|
---|
[6f9b7b0] | 40 | return(
|
---|
| 41 | <Router>
|
---|
[2e507a8] | 42 | <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name} removeState={this.removeState}/>
|
---|
[6f9b7b0] | 43 | <main>
|
---|
[df3a395] | 44 | <Route path={"/login"} render={() => <Login success={this.state.success} error={this.state.error} onCompleteForm={this.attemptLogin} loggedIn={this.state.logged}/>}/>
|
---|
[19ad843] | 45 | <Route path={"/profile"} render={() => <Profile userProfile={this.state.currentUser}/>}/>
|
---|
| 46 | <Route path={"/user/jobs"} render={() => <UserJobs userProfile={this.state.currentUser}/>}/>
|
---|
| 47 | <Route path={"/user/internships"} render={() => <UserInternships userProfile={this.state.currentUser}/>}/>
|
---|
| 48 | <Route path={"/user/projects"} render={() => <UserProjects userProfile={this.state.currentUser}/>}/>
|
---|
| 49 | <Route path={"/team/jobs"} render={() => <TeamJobs userProfile={this.state.currentUser}/>}/>
|
---|
| 50 | <Route path={"/team/projects"} render={() => <TeamProjects userProfile={this.state.currentUser}/>}/>
|
---|
| 51 | <Route path={"/company/jobs"} render={() => <CompanyJobs userProfile={this.state.currentUser}/>}/>
|
---|
| 52 | <Route path={"/company/internships"} render={() => <CompanyInternships userProfile={this.state.currentUser}/>}/>
|
---|
[df3a395] | 53 | <Route path={"/register/user"} render={() => <RegisterUser message={this.setSuccess} />}/>
|
---|
| 54 | <Route path={"/register/company"} render={() => <RegisterCompany message={this.setSuccess} />}/>
|
---|
| 55 | <Route path={"/register/team"} render={() => <RegisterTeam message={this.setSuccess}/>}/>
|
---|
[580ba1a] | 56 | <Route path={"/user/search"} render={() => <Search loggedIn={this.state.logged}/>}/>
|
---|
| 57 | <Route path={"/user/edit"} render={() => <EditUser oldUser={this.state.currentUser} updateUser={this.updateUser} message={this.setSuccess}/>}/>
|
---|
| 58 | <Route path={"/company/edit"} render={() => <EditCompany oldUser={this.state.currentUser} updateUser={this.updateUser} message={this.setSuccess}/>}/>
|
---|
[be373a8] | 59 | <Route path={"/team/edit"} render={() => <EditTeam oldUser={this.state.currentUser} updateUser={this.updateUser} message={this.setSuccess}/>}/>
|
---|
[db94dbd] | 60 | <Route path={"/register/job"} render={() => <JobRegister accountId={this.state.currentUser.id} type={this.state.currentUser.type} updateJobs={this.updateJobs} />}/>
|
---|
| 61 | <Route path={"/register/internship"} render={() => <InternshipRegister accountId={this.state.currentUser.id} type={this.state.currentUser.type} updateInternships={this.updateInternships} />}/>
|
---|
| 62 | <Route path={"/register/project"} render={() => <ProjectRegister accountId={this.state.currentUser.id} type={this.state.currentUser.type} updateInternships={this.updateProjects} />}/>
|
---|
[2e507a8] | 63 | <Route path={"/logout"} render={() => <Redirect to={"/login"}/>}/>
|
---|
[6f9b7b0] | 64 | <Route path={"/"} render={() => <Redirect to={"/login"}/>}/>
|
---|
| 65 | </main>
|
---|
| 66 | </Router>
|
---|
| 67 | );
|
---|
[3f5bf9e] | 68 | }
|
---|
| 69 |
|
---|
[2e507a8] | 70 | removeState = () => {
|
---|
| 71 | this.setState({
|
---|
| 72 | logged: false,
|
---|
| 73 | error: null,
|
---|
| 74 | currentUser: {}
|
---|
| 75 | })
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[580ba1a] | 78 | updateUser = (user) =>{
|
---|
| 79 | this.setState({
|
---|
| 80 | currentUser: user
|
---|
| 81 | })
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[df3a395] | 84 | setSuccess = (message) => {
|
---|
| 85 | this.setState({
|
---|
[be373a8] | 86 | success: message,
|
---|
| 87 | error: null
|
---|
[df3a395] | 88 | })
|
---|
| 89 | }
|
---|
[2e507a8] | 90 |
|
---|
[db94dbd] | 91 | updateJobs = (job) => {
|
---|
| 92 | this.setState(prevState => ({
|
---|
| 93 | currentUser:{
|
---|
| 94 | ...prevState.currentUser,
|
---|
| 95 | jobs: [...prevState.currentUser.jobs, job]
|
---|
| 96 | }
|
---|
| 97 | }))
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | updateInternships = (internship) => {
|
---|
| 101 | this.setState(prevState => ({
|
---|
| 102 | currentUser:{
|
---|
| 103 | ...prevState.currentUser,
|
---|
| 104 | internships: [...prevState.currentUser.internships, internship]
|
---|
| 105 | }
|
---|
| 106 | }))
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | updateProjects = (project) => {
|
---|
| 110 | this.setState(prevState => ({
|
---|
| 111 | currentUser:{
|
---|
| 112 | ...prevState.currentUser,
|
---|
| 113 | projects: [...prevState.currentUser.projects, project]
|
---|
| 114 | }
|
---|
| 115 | }))
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[17abe5e] | 118 | attemptLogin = (email, password, type) => {
|
---|
| 119 | UserLogin.login(email, password, type).then((res) =>{
|
---|
[6f9b7b0] | 120 | if(res.data.email==null){
|
---|
| 121 | this.setState({
|
---|
| 122 | logged: false,
|
---|
| 123 | error: res.data.error,
|
---|
| 124 | });
|
---|
| 125 | }else{
|
---|
| 126 | this.setState({
|
---|
| 127 | logged: true,
|
---|
| 128 | currentUser: res.data,
|
---|
| 129 | error: null,
|
---|
| 130 | });
|
---|
| 131 | }
|
---|
[3f5bf9e] | 132 | });
|
---|
[6f9b7b0] | 133 |
|
---|
| 134 | if(this.state.currentUser.email!=null){
|
---|
| 135 | return <Redirect to={"/profile"}/>;
|
---|
| 136 | }
|
---|
[3f5bf9e] | 137 | }
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | export default App;
|
---|