-
Notifications
You must be signed in to change notification settings - Fork 480
/
workshop_enrollment_school_info.jsx
298 lines (279 loc) · 9.89 KB
/
workshop_enrollment_school_info.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import PropTypes from 'prop-types';
import React from 'react';
import {connect} from 'react-redux';
import {Table} from 'react-bootstrap';
import ConfirmationDialog from '../../components/confirmation_dialog';
import {enrollmentShape} from '../types';
import {workshopEnrollmentStyles as styles} from '../workshop_enrollment_styles';
import {ScholarshipDropdown} from '../../components/scholarshipDropdown';
import Spinner from '../../components/spinner';
import {WorkshopAdmin, ProgramManager} from '../permission';
import {ScholarshipDropdownOptions} from '@cdo/apps/generated/pd/scholarshipInfoConstants';
const CSF = 'CS Fundamentals';
const DEEP_DIVE = 'Deep Dive';
const NA = 'N/A';
const LOCAL_SUMMER = '5-day Summer';
export class WorkshopEnrollmentSchoolInfo extends React.Component {
constructor(props) {
super(props);
this.state = {
pendingDelete: null,
pendingScholarshipUpdates: [],
enrollments: this.props.enrollments
};
this.handleClickDelete = this.handleClickDelete.bind(this);
this.handleDeleteCanceled = this.handleDeleteCanceled.bind(this);
this.handleDeleteConfirmed = this.handleDeleteConfirmed.bind(this);
this.handleScholarshipStatusChange = this.handleScholarshipStatusChange.bind(
this
);
}
handleClickDelete(event) {
this.setState({
pendingDelete: {
id: event.currentTarget.dataset.id,
email: event.currentTarget.dataset.email,
first_name: event.currentTarget.dataset.first_name,
last_name: event.currentTarget.dataset.last_name
}
});
}
handleDeleteCanceled() {
this.setState({
pendingDelete: null
});
}
handleDeleteConfirmed() {
const pendingDeleteId = this.state.pendingDelete.id;
this.setState({
pendingDelete: null
});
this.props.onDelete(pendingDeleteId);
}
handleScholarshipStatusChange(enrollment, selection) {
this.setState(state => {
const pendingScholarshipUpdates = state.pendingScholarshipUpdates.concat(
enrollment.id
);
return {pendingScholarshipUpdates};
});
$.ajax({
method: 'POST',
url: `/api/v1/pd/enrollment/${enrollment.id}/scholarship_info`,
contentType: 'application/json;charset=UTF-8',
data: JSON.stringify({scholarship_status: selection.value})
}).done(data => {
this.setState(state => {
// replace the old version of the enrollment in state with the newly updated version we just got back
const enrollments = state.enrollments.map(enrollment => {
if (enrollment.id === data.id) {
return data;
} else {
return enrollment;
}
});
// remove the updated enrollment from the list of enrollments pending an update
const pendingScholarshipUpdates = state.pendingScholarshipUpdates.filter(
e => {
return e !== data.id;
}
);
return {enrollments, pendingScholarshipUpdates};
});
});
}
formatCsfCourseExperience(csf_course_experience) {
if (!csf_course_experience) {
return NA;
}
const strs = Object.keys(csf_course_experience).map(
key => key + ': ' + csf_course_experience[key]
);
return strs.join(', ');
}
scholarshipInfo(enrollment) {
if (enrollment.scholarship_ineligible_reason) {
return <td>{enrollment.scholarship_ineligible_reason}</td>;
}
if (
this.props.permissionList.has(ProgramManager) ||
this.props.permissionList.has(WorkshopAdmin)
) {
return (
<td>
<ScholarshipDropdown
scholarshipStatus={enrollment.scholarship_status}
onChange={this.handleScholarshipStatusChange.bind(this, enrollment)}
/>
</td>
);
} else {
let scholarshipInfo = ScholarshipDropdownOptions.find(o => {
return o.value === enrollment.scholarship_status;
});
return <td>{scholarshipInfo ? scholarshipInfo.label : '--'}</td>;
}
}
render() {
const enrollmentRows = this.state.enrollments.map((enrollment, i) => {
let deleteCell;
if (enrollment.attended) {
// Don't give the option to delete an enrollment once the teacher has been marked attended.
deleteCell = <td />;
} else {
deleteCell = (
<td
style={styles.clickTarget}
onClick={this.handleClickDelete}
data-id={enrollment.id}
data-first_name={enrollment.first_name}
data-last_name={enrollment.last_name}
data-email={enrollment.email}
>
<i className="fa fa-minus" />
</td>
);
}
return (
<tr key={i}>
{deleteCell}
<td>{i + 1}</td>
<td>{enrollment.first_name}</td>
<td>{enrollment.last_name}</td>
<td>{enrollment.email}</td>
<td>{enrollment.district_name}</td>
<td>{enrollment.school}</td>
{this.props.workshopCourse === CSF && (
<td>{enrollment.role ? enrollment.role : NA}</td>
)}
{this.props.workshopCourse === CSF && (
<td>
{enrollment.grades_teaching
? enrollment.grades_teaching.join(', ')
: NA}
</td>
)}
{this.props.workshopCourse === CSF &&
this.props.workshopSubject === DEEP_DIVE && (
<td>
{this.formatCsfCourseExperience(
enrollment.csf_course_experience
)}
</td>
)}
{this.props.workshopCourse === CSF &&
this.props.workshopSubject === DEEP_DIVE && (
<td>
{enrollment.csf_courses_planned
? enrollment.csf_courses_planned.join(', ')
: NA}
</td>
)}
{this.props.workshopCourse === CSF &&
this.props.workshopSubject === DEEP_DIVE && (
<td>{enrollment.attended_csf_intro_workshop}</td>
)}
{this.props.workshopCourse === CSF &&
this.props.workshopSubject === DEEP_DIVE && (
<td>{enrollment.csf_has_physical_curriculum_guide}</td>
)}
{this.props.accountRequiredForAttendance && (
<td>{enrollment.user_id ? 'Yes' : 'No'}</td>
)}
{this.props.workshopSubject === LOCAL_SUMMER && (
<td>
{enrollment.attendances} / {this.props.numSessions}
</td>
)}
{this.props.workshopSubject === LOCAL_SUMMER &&
this.state.pendingScholarshipUpdates.includes(enrollment.id) && (
<td>
<Spinner size="small" />
</td>
)}
{this.props.workshopSubject === LOCAL_SUMMER &&
!this.state.pendingScholarshipUpdates.includes(enrollment.id) &&
this.scholarshipInfo(enrollment)}
</tr>
);
});
let confirmationDialog = null;
const pendingDelete = this.state.pendingDelete;
if (!!pendingDelete) {
const bodyText =
'Are you sure you want to delete the enrollment for ' +
`${pendingDelete.first_name} ${pendingDelete.last_name} (${
pendingDelete.email
})?`;
confirmationDialog = (
<ConfirmationDialog
show={true}
onOk={this.handleDeleteConfirmed}
onCancel={this.handleDeleteCanceled}
headerText="Delete Enrollment?"
bodyText={bodyText}
/>
);
}
return (
<Table condensed striped>
{confirmationDialog}
<thead>
<tr>
<th style={styles.th} />
<th style={styles.th}>#</th>
<th style={styles.th}>First Name</th>
<th style={styles.th}>Last Name</th>
<th style={styles.th}>Email</th>
<th style={styles.th}>District</th>
<th style={styles.th}>School</th>
{this.props.workshopCourse === CSF && (
<th style={styles.th}>Current Role</th>
)}
{this.props.workshopCourse === CSF && (
<th style={styles.th}>Grades Teaching This Year</th>
)}
{this.props.workshopCourse === CSF &&
this.props.workshopSubject === DEEP_DIVE && (
<th style={styles.th}>Prior CSF experience</th>
)}
{this.props.workshopCourse === CSF &&
this.props.workshopSubject === DEEP_DIVE && (
<th style={styles.th}>Courses Planning to Teach</th>
)}
{this.props.workshopCourse === CSF &&
this.props.workshopSubject === DEEP_DIVE && (
<th style={styles.th}>Attended Intro Workshop?</th>
)}
{this.props.workshopCourse === CSF &&
this.props.workshopSubject === DEEP_DIVE && (
<th style={styles.th}>Has Physical Copy of Curriculum?</th>
)}
{this.props.accountRequiredForAttendance && (
<th style={styles.th}>Code Studio Account?</th>
)}
{this.props.workshopSubject === LOCAL_SUMMER && (
<th style={styles.th}>Total Attendance</th>
)}
{this.props.workshopSubject === LOCAL_SUMMER && (
<th style={styles.th}>Scholarship Teacher?</th>
)}
</tr>
</thead>
<tbody>{enrollmentRows}</tbody>
</Table>
);
}
}
WorkshopEnrollmentSchoolInfo.propTypes = {
permissionList: PropTypes.object.isRequired,
enrollments: PropTypes.arrayOf(enrollmentShape).isRequired,
accountRequiredForAttendance: PropTypes.bool.isRequired,
onDelete: PropTypes.func.isRequired,
workshopCourse: PropTypes.string.isRequired,
workshopSubject: PropTypes.string.isRequired,
numSessions: PropTypes.number.isRequired
};
export default connect(state => ({
permissionList: state.workshopDashboard.permission.permissions
}))(WorkshopEnrollmentSchoolInfo);