source: client_app/src/components/main/App.js@ 6729ba5

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

finished work edit

  • Property mode set to 100644
File size: 7.6 KB
RevLine 
[3f5bf9e]1import React, {Component} from 'react';
[6f9b7b0]2import {BrowserRouter as Router, Route, Redirect} from 'react-router-dom';
[3f5bf9e]3import Login from '../login/login';
[c9fa474]4import Profile from "../profiles/profile";
[3f5bf9e]5import 'semantic-ui-css/semantic.min.css';
6import HeaderComp from '../template/header';
7import './App.css';
8import UserLogin from "../../repository/login_repo";
[c9fa474]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";
[19ad843]16import RegisterUser from "../register/register_user_form";
[df3a395]17import RegisterCompany from "../register/register_company_form";
18import RegisterTeam from "../register/register_team_form";
[580ba1a]19import Search from "../filter/search";
20import EditUser from "../account_edit/user_edit";
21import EditCompany from "../account_edit/company_edit";
[be373a8]22import EditTeam from "../account_edit/team_edit";
[db94dbd]23import JobRegister from "../work_register/job_register";
24import InternshipRegister from "../work_register/internship_register";
25import ProjectRegister from "../work_register/project_register";
[6729ba5]26import EditJob from "../work_edit/edit_job";
27import EditInternship from "../work_edit/edit_internship";
28import EditProject from "../work_edit/edit_project";
[3f5bf9e]29
30class App extends Component{
31 constructor(props) {
32 super(props);
33 this.state = {
[6f9b7b0]34 logged: false,
35 error: null,
[df3a395]36 success: null,
[fc8421e]37 currentUser: {
38 }
[3f5bf9e]39 }
40 }
41
[580ba1a]42 render(){
[6f9b7b0]43 return(
44 <Router>
[2e507a8]45 <HeaderComp acc={this.state.currentUser.email} accType={this.state.currentUser.type} name={this.state.currentUser.name} removeState={this.removeState}/>
[6f9b7b0]46 <main>
[df3a395]47 <Route path={"/login"} render={() => <Login success={this.state.success} error={this.state.error} onCompleteForm={this.attemptLogin} loggedIn={this.state.logged}/>}/>
[19ad843]48 <Route path={"/profile"} render={() => <Profile userProfile={this.state.currentUser}/>}/>
49 <Route path={"/user/jobs"} render={() => <UserJobs userProfile={this.state.currentUser}/>}/>
50 <Route path={"/user/internships"} render={() => <UserInternships userProfile={this.state.currentUser}/>}/>
51 <Route path={"/user/projects"} render={() => <UserProjects userProfile={this.state.currentUser}/>}/>
52 <Route path={"/team/jobs"} render={() => <TeamJobs userProfile={this.state.currentUser}/>}/>
53 <Route path={"/team/projects"} render={() => <TeamProjects userProfile={this.state.currentUser}/>}/>
54 <Route path={"/company/jobs"} render={() => <CompanyJobs userProfile={this.state.currentUser}/>}/>
55 <Route path={"/company/internships"} render={() => <CompanyInternships userProfile={this.state.currentUser}/>}/>
[df3a395]56 <Route path={"/register/user"} render={() => <RegisterUser message={this.setSuccess} />}/>
57 <Route path={"/register/company"} render={() => <RegisterCompany message={this.setSuccess} />}/>
58 <Route path={"/register/team"} render={() => <RegisterTeam message={this.setSuccess}/>}/>
[580ba1a]59 <Route path={"/user/search"} render={() => <Search loggedIn={this.state.logged}/>}/>
60 <Route path={"/user/edit"} render={() => <EditUser oldUser={this.state.currentUser} updateUser={this.updateUser} message={this.setSuccess}/>}/>
61 <Route path={"/company/edit"} render={() => <EditCompany oldUser={this.state.currentUser} updateUser={this.updateUser} message={this.setSuccess}/>}/>
[be373a8]62 <Route path={"/team/edit"} render={() => <EditTeam oldUser={this.state.currentUser} updateUser={this.updateUser} message={this.setSuccess}/>}/>
[db94dbd]63 <Route path={"/register/job"} render={() => <JobRegister accountId={this.state.currentUser.id} type={this.state.currentUser.type} updateJobs={this.updateJobs} />}/>
64 <Route path={"/register/internship"} render={() => <InternshipRegister accountId={this.state.currentUser.id} type={this.state.currentUser.type} updateInternships={this.updateInternships} />}/>
[5b36317]65 <Route path={"/register/project"} render={() => <ProjectRegister accountId={this.state.currentUser.id} type={this.state.currentUser.type} updateProjects={this.updateProjects} />}/>
[21175ba]66 <Route path={"/edit/job"} render={(props) => <EditJob {...props} editJob={this.editJob}/>} />
[6729ba5]67 <Route path={"/edit/internship"} render={(props) => <EditInternship {...props} editInternship={this.editInternship}/>} />
68 <Route path={"/edit/project"} render={(props) => <EditProject {...props} editProject={this.editProject}/>} />
[2e507a8]69 <Route path={"/logout"} render={() => <Redirect to={"/login"}/>}/>
[6f9b7b0]70 <Route path={"/"} render={() => <Redirect to={"/login"}/>}/>
71 </main>
72 </Router>
73 );
[3f5bf9e]74 }
75
[2e507a8]76 removeState = () => {
77 this.setState({
78 logged: false,
79 error: null,
80 currentUser: {}
81 })
82 }
83
[580ba1a]84 updateUser = (user) =>{
85 this.setState({
86 currentUser: user
87 })
88 }
89
[df3a395]90 setSuccess = (message) => {
91 this.setState({
[be373a8]92 success: message,
93 error: null
[df3a395]94 })
95 }
[2e507a8]96
[db94dbd]97 updateJobs = (job) => {
98 this.setState(prevState => ({
99 currentUser:{
100 ...prevState.currentUser,
101 jobs: [...prevState.currentUser.jobs, job]
102 }
103 }))
104 }
105
106 updateInternships = (internship) => {
107 this.setState(prevState => ({
108 currentUser:{
109 ...prevState.currentUser,
110 internships: [...prevState.currentUser.internships, internship]
111 }
112 }))
113 }
114
115 updateProjects = (project) => {
116 this.setState(prevState => ({
117 currentUser:{
118 ...prevState.currentUser,
119 projects: [...prevState.currentUser.projects, project]
120 }
121 }))
122 }
123
[21175ba]124 editJob = (job, index) => {
[6729ba5]125 let jobs = this.state.currentUser.jobs;
126 jobs[index] = job;
127
[21175ba]128 this.setState(prevState => ({
129 currentUser:{
130 ...prevState.currentUser,
[6729ba5]131 jobs: jobs
[21175ba]132 }
133 }))
134 }
135
136 editInternship = (internship, index) => {
[6729ba5]137 let interns = this.state.currentUser.internships;
138 interns[index] = internship;
139
[21175ba]140 this.setState(prevState => ({
141 currentUser:{
142 ...prevState.currentUser,
[6729ba5]143 internships: interns
[21175ba]144 }
145 }))
146 }
147
148 editProject = (project, index) => {
[6729ba5]149 let proj = this.state.currentUser.projects;
150 proj[index] = project;
151
[21175ba]152 this.setState(prevState => ({
153 currentUser:{
154 ...prevState.currentUser,
[6729ba5]155 projects: proj
[21175ba]156 }
157 }))
158 }
159
[17abe5e]160 attemptLogin = (email, password, type) => {
161 UserLogin.login(email, password, type).then((res) =>{
[6f9b7b0]162 if(res.data.email==null){
163 this.setState({
164 logged: false,
165 error: res.data.error,
166 });
167 }else{
168 this.setState({
169 logged: true,
170 currentUser: res.data,
171 error: null,
172 });
173 }
[3f5bf9e]174 });
[6f9b7b0]175
176 if(this.state.currentUser.email!=null){
177 return <Redirect to={"/profile"}/>;
178 }
[3f5bf9e]179 }
180}
181
182export default App;
Note: See TracBrowser for help on using the repository browser.