-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change census forms to post directly to census tables #19193
Changes from all commits
2ab1a00
0693cd5
f40d483
1f038af
89b23b7
405bc60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,14 +63,14 @@ class CensusForm extends Component { | |
checkShowFollowUp() { | ||
const twentyHours = this.state.submission.twentyHours; | ||
this.setState({ | ||
showFollowUp: (twentyHours === 'some' || twentyHours === 'all') | ||
showFollowUp: (twentyHours === 'SOME' || twentyHours === 'ALL') | ||
}, this.checkShowPledge); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like for HoC signup we also show the follow up questions if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They actually have different checks. I'm already changing so much here that I didn't want to change this behavior also. |
||
|
||
checkShowPledge() { | ||
const role = this.state.submission.role; | ||
this.setState({ | ||
showPledge: (role === 'teacher' || role === 'administrator') | ||
showPledge: (role === 'TEACHER' || role === 'ADMINISTRATOR') | ||
}); | ||
} | ||
|
||
|
@@ -132,22 +132,36 @@ class CensusForm extends Component { | |
window.location.href = "/yourschool/thankyou"; | ||
} | ||
|
||
// Here we're using the built-in functionality of pegasus form helpers to | ||
// validate the email address. It's the only server-side validation for this | ||
// form; all other validations are done client-side before the POST request is | ||
// submitted. This slightly atypical approach because the logic for email | ||
// validation is more complex and there wasn't a need to duplicate what already | ||
// exists; the other validations are much more straightforward to implement | ||
// here in the React. | ||
// The response in the error case is JSON with an entry for | ||
// each submitted field that is problematic. The specifics of | ||
// the problem are not important here since we just need a boolean value | ||
// of whether there was an error or not. | ||
processError(error) { | ||
if (error.responseJSON.email_s[0] === "invalid") { | ||
const errorMap = { | ||
submitter_email_address: 'invalidEmail', | ||
class_frequency: 'frequency', | ||
nces_school_s: 'nces', | ||
submitter_role: 'role', | ||
how_many_do_hoc: 'hoc', | ||
how_many_after_school: 'afterSchool', | ||
how_many_10_hours: 'tenHours', | ||
how_many_20_hours: 'twentyHours', | ||
country: 'country', | ||
school_type: 'school', | ||
state: 'school', | ||
zip: 'school', | ||
school_name: 'school' | ||
}; | ||
|
||
const errorJSON = error.responseJSON; | ||
Object.keys(errorJSON).map((key) => { | ||
const errorKey = errorMap[key]; | ||
let newErrors = this.state.errors; | ||
newErrors[errorKey] = true; | ||
this.setState({ | ||
errors: { | ||
...this.state.errors, | ||
invalidEmail: true | ||
} | ||
errors: newErrors | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
validateSchoolDropdown() { | ||
|
@@ -207,7 +221,7 @@ class CensusForm extends Component { | |
const { errors } = this.state; | ||
if (!errors.email && !errors.topics && !errors.frequency && !errors.school && !errors.nces && !errors.role && !errors.hoc && !errors.afterSchool && !errors.tenHours && !errors.twentyHours && !errors.country) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe tighten with something like: if (Object.values(errors).every(error => !error)) {
// Submit... |
||
$.ajax({ | ||
url: "/forms/Census2017", | ||
url: "/dashboardapi/v1/census/CensusYourSchool2017v4", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this match line 267 in apps/src/sites/hourofcode.com/pages/public/index.js? What are the different versions of the form? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The different form versions map to different models with different validation. They all write to the same table (census_submission) but with a different value for 'type'. This also allows us to map responses back to which version of the form was used. |
||
type: "post", | ||
dataType: "json", | ||
data: $('#census-form').serialize() | ||
|
@@ -243,7 +257,7 @@ class CensusForm extends Component { | |
{i18n.yourSchoolTellUs()} | ||
</h2> | ||
<form id="census-form"> | ||
<input type="hidden" id="version" name="version" value="4"/> | ||
<input type="hidden" id="school_year" name="school_year" value="2017"/> | ||
<CountryAutocompleteDropdown | ||
onChange={this.handleDropdownChange.bind("country")} | ||
value={submission.country} | ||
|
@@ -300,7 +314,7 @@ class CensusForm extends Component { | |
)} | ||
</div> | ||
<select | ||
name="hoc_s" | ||
name="how_many_do_hoc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we don't need the data type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I changed the naming in the forms to match the models and controller rather than making the models and controller match the existing form fields. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
value={this.state.submission.hoc} | ||
onChange={this.handleChange.bind(this, 'hoc')} | ||
style={styles.dropdown} | ||
|
@@ -327,7 +341,7 @@ class CensusForm extends Component { | |
)} | ||
</div> | ||
<select | ||
name="after_school_s" | ||
name="how_many_after_school" | ||
value={this.state.submission.afterSchool} | ||
onChange={this.handleChange.bind(this, 'afterSchool')} | ||
style={styles.dropdown} | ||
|
@@ -354,7 +368,7 @@ class CensusForm extends Component { | |
)} | ||
</div> | ||
<select | ||
name="ten_hours_s" | ||
name="how_many_10_hours" | ||
value={this.state.submission.tenHours} | ||
onChange={this.handleChange.bind(this, 'tenHours')} | ||
style={styles.dropdown} | ||
|
@@ -381,7 +395,7 @@ class CensusForm extends Component { | |
)} | ||
</div> | ||
<select | ||
name="twenty_hours_s" | ||
name="how_many_20_hours" | ||
value={this.state.submission.twentyHours} | ||
onChange={this.handleChange.bind(this, 'twentyHours')} | ||
style={styles.dropdown} | ||
|
@@ -401,7 +415,7 @@ class CensusForm extends Component { | |
<label> | ||
<input | ||
type="checkbox" | ||
name="otherCS_b" | ||
name="other_classes_under_20_hours" | ||
checked={submission.otherCS} | ||
onChange={() => this.toggleOtherCS()} | ||
/> | ||
|
@@ -435,14 +449,14 @@ class CensusForm extends Component { | |
| ||
<input | ||
type="text" | ||
name="topic_other_desc_s" | ||
name="topic_other_description" | ||
value={this.state.otherTopicsDesc} | ||
onChange={this.updateOtherTopicsDesc.bind(this)} | ||
style={styles.inputInline} | ||
/> | ||
</div> | ||
<div style={styles.leftMargin}> | ||
{this.topicCheckbox("topic_dont_know_b", i18n.iDontKnow())} | ||
{this.topicCheckbox("topic_do_not_know", i18n.iDontKnow())} | ||
</div> | ||
</div> | ||
<label> | ||
|
@@ -456,7 +470,7 @@ class CensusForm extends Component { | |
</div> | ||
)} | ||
<select | ||
name="followup_frequency_s" | ||
name="class_frequency" | ||
value={this.state.submission.followUpFrequency} | ||
onChange={this.handleChange.bind(this, 'followUpFrequency')} | ||
style={styles.wideDropdown} | ||
|
@@ -477,7 +491,7 @@ class CensusForm extends Component { | |
</div> | ||
<textarea | ||
type="text" | ||
name="followup_more_s" | ||
name="tell_us_more" | ||
value={this.state.submission.followUpMore} | ||
onChange={this.handleChange.bind(this, 'followUpMore')} | ||
style={styles.textArea} | ||
|
@@ -496,7 +510,7 @@ class CensusForm extends Component { | |
</div> | ||
)} | ||
<select | ||
name="role_s" | ||
name="submitter_role" | ||
value={this.state.submission.role} | ||
onChange={this.handleChange.bind(this, 'role')} | ||
style={styles.wideDropdown} | ||
|
@@ -529,7 +543,7 @@ class CensusForm extends Component { | |
)} | ||
<input | ||
type="text" | ||
name="email_s" | ||
name="submitter_email_address" | ||
value={this.state.submission.email} | ||
onChange={this.handleChange.bind(this, 'email')} | ||
placeholder={i18n.yourEmailPlaceholder()} | ||
|
@@ -544,7 +558,7 @@ class CensusForm extends Component { | |
</div> | ||
<input | ||
type="text" | ||
name="name_s" | ||
name="submitter_name" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
value={this.state.submission.name} | ||
onChange={this.handleChange.bind(this, 'name')} | ||
placeholder={i18n.yourName()} | ||
|
@@ -557,7 +571,7 @@ class CensusForm extends Component { | |
<label> | ||
<input | ||
type="checkbox" | ||
name="pledge_b" | ||
name="pledged" | ||
checked={submission.acceptedPledge} | ||
onChange={() => this.togglePledge()} | ||
/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: break this long line up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. From our styleguide: