-
Notifications
You must be signed in to change notification settings - Fork 481
/
organizer_form_part.jsx
103 lines (95 loc) · 2.31 KB
/
organizer_form_part.jsx
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
import PropTypes from 'prop-types';
import React from 'react';
import {Row, Col} from 'react-bootstrap';
export default class OrganizerFormPart extends React.Component {
static propTypes = {
workshopId: PropTypes.number,
organizerId: PropTypes.number,
organizerName: PropTypes.string,
onChange: PropTypes.func,
readOnly: PropTypes.bool
};
state = {
loading: true,
potentialOrganizers: null,
error: false
};
UNSAFE_componentWillMount() {
this.load(this.props.workshopId);
}
load() {
let url = `/api/v1/pd/workshops/${
this.props.workshopId
}/potential_organizers`;
$.ajax({
method: 'GET',
url: url,
dataType: 'json'
})
.done(data => {
this.setState({
loading: false,
potentialOrganizers: data
});
})
.error(() => {
this.setState({error: true});
});
}
renderOrganizerOption(organizer) {
return (
<option value={organizer.value} key={organizer.value}>
{organizer.label}
</option>
);
}
render() {
let organizerOptions;
if (this.state.potentialOrganizers) {
organizerOptions = this.state.potentialOrganizers.map(o =>
this.renderOrganizerOption(o)
);
} else {
organizerOptions = [];
}
return (
<div>
<h3>Organizer (admin)</h3>
<Row>
<Col sm={8}>
{this.state.potentialOrganizers && (
<select
className="form-control"
value={this.props.organizerId}
onChange={this.props.onChange}
disabled={this.props.readOnly}
style={this.props.readOnly && styles.readOnlyInput}
>
{organizerOptions}
</select>
)}
{!this.state.potentialOrganizers && (
<h4>{this.props.organizerName}</h4>
)}
{this.state.error && (
<p style={styles.error}>
An error occurred loading the organizer dropdown. Try reloading
the page.
</p>
)}
</Col>
</Row>
</div>
);
}
}
const styles = {
readOnlyInput: {
backgroundColor: 'inherit',
cursor: 'default',
border: 'none'
},
error: {
color: 'red'
}
};