-
Notifications
You must be signed in to change notification settings - Fork 480
/
TeachingBackground.jsx
146 lines (130 loc) · 4.49 KB
/
TeachingBackground.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
import React from 'react';
import LabeledFormComponent from '../../form_components/LabeledFormComponent';
import UsPhoneNumberInput from '../../form_components/UsPhoneNumberInput';
import {
PageLabels,
SectionHeaders,
TextFields
} from '@cdo/apps/generated/pd/teacher2021ApplicationConstants';
import {Row, Col, ControlLabel, FormGroup} from 'react-bootstrap';
import SchoolAutocompleteDropdown from '@cdo/apps/templates/SchoolAutocompleteDropdown';
import {isEmail} from '@cdo/apps/util/formatValidation';
import {styles} from './TeacherApplicationConstants';
export default class TeachingBackground extends LabeledFormComponent {
static labels = {
...PageLabels.teachingBackground,
...PageLabels.aboutYou
};
static associatedFields = [
...Object.keys(PageLabels.teachingBackground),
'school',
'schoolName',
'schoolDistrictName',
'schoolAddress',
'schoolCity',
'schoolState',
'schoolZipCode',
'schoolType',
'principalTitle',
'principalFirstName',
'principalLastName',
'principalEmail',
'principalConfirmEmail',
'principalPhoneNumber',
'currentRole'
];
handleSchoolChange = selectedSchool => {
this.handleChange({
school: selectedSchool && selectedSchool.value,
schoolZipCode:
selectedSchool && selectedSchool.school && selectedSchool.school.zip
});
};
render() {
return (
<FormGroup>
<h3>Section 2: {SectionHeaders.teachingBackground}</h3>
<p>Please provide your school and principal information below:</p>
<FormGroup
id="school"
controlId="school"
validationState={this.getValidationState('school')}
>
<Row>
<Col md={6}>
<ControlLabel>
School
<span style={{color: 'red'}}> *</span>
</ControlLabel>
</Col>
</Row>
<Row>
<Col md={6}>
<SchoolAutocompleteDropdown
value={this.props.data.school}
onChange={this.handleSchoolChange}
/>
</Col>
</Row>
</FormGroup>
{this.props.data.school && this.props.data.school === '-1' && (
<div style={styles.indented}>
{this.inputFor('schoolName')}
{this.inputFor('schoolDistrictName', {required: false})}
{this.inputFor('schoolAddress', {required: false})}
{this.inputFor('schoolCity', {required: false})}
{this.selectFor('schoolState', {placeholder: 'Select a state'})}
{this.inputFor('schoolZipCode')}
{this.radioButtonsFor('schoolType')}
</div>
)}
{
// Disable auto complete for principal fields, so they are not filled with the teacher's details.
// Using a custom unmatched string "never" instead of "off" for wider browser compatibility.
// See https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion#Disabling_autocompletion
}
{this.inputFor('principalFirstName', {autoComplete: 'never'})}
{this.inputFor('principalLastName', {autoComplete: 'never'})}
{this.inputFor('principalEmail', {autoComplete: 'never'})}
{this.inputFor('principalConfirmEmail', {autoComplete: 'never'})}
{this.usPhoneNumberInputFor('principalPhoneNumber', {
autoComplete: 'never'
})}
{this.radioButtonsWithAdditionalTextFieldsFor('currentRole', {
[TextFields.otherPleaseList]: 'other'
})}
{this.checkBoxesFor('previousYearlongCdoPd')}
</FormGroup>
);
}
/**
* @override
*/
static getDynamicallyRequiredFields(data) {
const requiredFields = [];
if (data.school === '-1') {
requiredFields.push('schoolName');
requiredFields.push('schoolState');
requiredFields.push('schoolZipCode');
requiredFields.push('schoolType');
}
return requiredFields;
}
/**
* @override
*/
static getErrorMessages(data) {
const formatErrors = {};
if (!UsPhoneNumberInput.isValid(data.principalPhoneNumber)) {
formatErrors.principalPhoneNumber =
'Must be a valid phone number including area code';
}
if (!isEmail(data.principalEmail)) {
formatErrors.principalEmail = 'Must be a valid email address';
}
if (data.principalEmail !== data.principalConfirmEmail) {
formatErrors.principalConfirmEmail = 'Must match above email';
}
return formatErrors;
}
}