Newer
Older
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React, { Component } from "react";
import Form from 'react-bootstrap/Form';
import Button from "react-bootstrap/esm/Button";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as applicationManagementActions from "../../actions/ApplicationManagementActions"
const mapStateToProps = state => {
return {
accessToken: state.AuthenticationReducer.accessToken,
isAdmin: state.AuthenticationReducer.isAdmin,
user: state.AuthenticationReducer.user
};
}
class CreateNewApplicationForm extends Component {
constructor(props) {
super(props);
if (!this.props.isAdmin) {
this.state = {
degreeCourseID: this.props.degreeCourse.id,
targetPeriodYear: "",
targetPeriodShortName: ""
}
} else {
this.state = {
applicantUserID: "",
degreeCourseID: this.props.degreeCourse.id,
targetPeriodYear: "",
targetPeriodShortName: ""
};
}
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(e) {
const { name, value } = e.target;
this.setState({ [name]: value })
console.log(JSON.stringify(this.state))
}
async handleSubmit(e) {
e.preventDefault();
const { createNewApplicationAction } = this.props;
console.log("application sollte angelegt werden")
this.props.goBack()
await createNewApplicationAction(this.state, this.props.accessToken)
}
handle
render() {
let degreeCourse = this.props.degreeCourse
let userIDField
console.log(this.props.user)
if (this.props.isAdmin) {
userIDField = (
<>
<Form.Group className="mb-3">
<Form.Label>User-ID</Form.Label>
<Form.Control id="CreateDegreeCourseApplicationEditUserID" name="applicantUserID" type="text" placeholder="Bitte User-ID eingeben" onChange={this.handleChange} />
</Form.Group>
</>)
} else {
userIDField = (
<>
<Form.Group className="mb-3">
<Form.Label>User-ID</Form.Label>
<Form.Control id="CreateDegreeCourseApplicationEditUserID" name="applicantUserID" type="read" disabled value={this.props.user} />
</Form.Group>
</>)
}
return (
<div style={{ display: 'flex', justifyContent: 'center', textAlign: 'left', padding: '2em', background: "#fff" }}>
<Form style={{ width: '60rem' }}>
<Form.Group className="mb-3">
<Form.Label>Studiengang</Form.Label>
<Form.Control id="CreateDegreeCourseComponentEditDegreeCourseName" disabled value={degreeCourse.shortName + ": " + degreeCourse.name} type="text" onChange={this.handleChange} required />
</Form.Group>
{userIDField}
<Form.Group className="mb-3">
<Form.Label>Year</Form.Label>
<Form.Control id="CreateDegreeCourseApplicationEditTargetPeriodYear" name="targetPeriodYear" type="number" min={new Date().getFullYear()} placeholder="Year" onChange={this.handleChange} />
</Form.Group>
<Form.Group>
<Form.Label>Semester</Form.Label>
<Form.Control id="CreateDegreeCourseApplicationEditTargetPeriodName" as="select" name="targetPeriodShortName" aria-label="Default select example" onChange={this.handleChange}>
<option value="">Bitte Semester auswählen</option>
<option value="WiSe">Wintersemester</option>
<option value="SoSe">Sommersemester</option>
</Form.Control>
</Form.Group>
<Button id="CreateDegreeCourseApplicationCancelButton" variant="primary" type="button" onClick={this.props.goBack}>
Cancel
</Button>
<Button id="CreateDegreeCourseApplicationCreateButton" variant="primary" type="submit" onClick={this.handleSubmit}>
Submit
</Button>
</Form>
</div>
)
}
}
const mapDispatchToProps = dispatch => bindActionCreators({
createNewApplicationAction: applicationManagementActions.passNewApplication
}, dispatch)
const ConnectedApplicationForm = connect(mapStateToProps, mapDispatchToProps)(CreateNewApplicationForm)
export default ConnectedApplicationForm