-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfile.jsx
More file actions
83 lines (67 loc) · 2.42 KB
/
Profile.jsx
File metadata and controls
83 lines (67 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import React from 'react';
import App from './App.jsx';
import axios from 'axios';
class Profile extends React.Component {
constructor(props) {
super(props);
this.state = {
courseid: 0
};
this.handleChange=this.handleChange.bind(this);
this.handleCourseSubmit=this.handleCourseSubmit.bind(this);
}
handleChange(e) {
this.setState({ courseid: e.target.value });
}
handleCourseSubmit(e) {
//to prevent default action happen
const {userID} = this.props.location.userDetails;
e.preventDefault();
axios.post("http://localhost:8086/usercourses", {userid: userID, courseid:parseInt(this.state.courseid)})
.then(res => {
console.log(res);
console.log(res.data);
})
alert('You selected '+this.state.courseid);
}
render() {
const {userID} = this.props.location.userDetails;
const {userName} = this.props.location.userDetails;
const {userCourse} =this.props.location.userDetails;
const {allCourses} = this.props.location.courseDetails;
return (
<div>
<h3 align="center"><u>Particular User Information</u></h3>
UserID: {userID}
<br /><br />
UserName: {userName}
<br />
<h4><u>Enrolled Courses :</u></h4>
<table>
<tbody>
<tr>
<th><u>CourseId</u> </th>
<th><u>CourseName</u> </th>
<th><u>Description</u> </th>
<th><u>Level</u> </th>
<th><u>Length</u></th>
</tr>
{userCourse.map((usercourse,i) => <tr key={'usercourse_' + i}><td>{usercourse.id} </td>
<td>{usercourse.courseName} </td>
<td> {usercourse.description} </td>
<td>{usercourse.level} </td>
<td>{usercourse.length}</td></tr>)}
</tbody>
</table>
<br /><br />
<hr/>
Add Courses:
<select value={this.state.courseid} onChange={this.handleChange} >
{allCourses.map((allcourse,i) => <option key={'allcourse_' + i} value={allcourse.id}>{allcourse.courseName}</option>)}
</select>
<button type="submit" onClick={this.handleCourseSubmit}>AddCourse</button>
</div>
);
}
}
export default Profile;