-
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
Create census banner to show to teachers with nces school ids #19559
Conversation
<div style={styles.message}> | ||
<SchoolInfoInputs | ||
ref={this.bindSchoolInfoInputs} | ||
onCountryChange={this.onCountryChange.bind(this)} |
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.
note: you can avoid these explicit bindings by defining the callbacks with arrow functions. See above
onCountryChange(_, event) { | ||
const newCountry = event ? event.value : ''; | ||
this.setState({country: newCountry}); | ||
} |
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.
note: you can define these callbacks as arrow functions to automatically bind this and remove the need to do it explicitly later. E.g.
onCountryChange = (_, event) => {
const newCountry = event ? event.value : '';
this.setState({country: newCountry});
}
Also, nit: I prefer the callback supplied to an onVerb
handler to be called handleVerb
(rather than again onVerb
), like in the react examples.
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.
I'll change this.
url: "/users.json", | ||
type: "post", | ||
dataType: "json", | ||
data: $("#census-school-info-form").serialize() |
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.
Since this is all in React now, don't we have (or can construct) all the state in one place in the parent object and submit that? Why construct all these hidden fields (starting on line 276) and serializing the actual html form data? Is there something else we're gaining by doing that? This would be simpler, and more React-y, to maintain and submit state from a component, not render anything hidden (unless it's needed elsewhere), and not rely on finding an element by id. If we were to look for an element by id, using ref
is generally preferred.
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.
I'm going to change this to construct the POST from the component's state. I did it this way simply because all of the other forms I've touched have worked like this and I didn't consider doing it differently. I agree that we don't need an actual form here.
<div style={styles.main}> | ||
<form id="census-teacher-banner-form"> | ||
<input type="hidden" name="nces_school_s" value={schoolId}/> | ||
<input type="hidden" name="school_year" value={this.props.schoolYear}/> |
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.
Are these needed? See above
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.
I suppose if this is simpler as a form with uncontrolled elements so we don't need a bunch of state management then it makes sense. In that case, please move the whole form into a different component (or at the very least a function), and use ref to find that DOM element.
This render method is getting a bit long and unwieldy, hard to keep track of the branches.
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.
I agree about long and unwieldy. I'll break it up to be more readable.
showSchoolInfoUnknownError: false, | ||
}); | ||
this.loadSchoolName(this.props.ncesSchoolId); | ||
} |
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.
Is this needed? Will the dismissal also unmount the component? If we unmount the component on @DiSmiSSaL, and set default state (line 84) when it's new, then do we need to clear it on the way out?
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.
Yes, this is needed. This is handling the case where the user dismissed the "update your school" view, not the entire banner. In that case, there may have been partial state about the school changed. We do not want to use that partial state in the census submission so we need to reset to the previous values. I'll add a comment to make this clearer.
Updated based on PR comments from Friday. |
schoolLocation: '', | ||
showSchoolInfoErrors: false, | ||
showSchoolInfoUnknownError: false, | ||
}); |
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.
This appears to be the same as the initial state on line 79, plus the last 2 showSchoolInfo*
fields. This raises a couple questions:
- Should those 2 also be initialized on line 79?
- If the 2 state objects are identical, then why don't we wrap these into a single static property, e.g.
initialState
and set both the initialstate
and thissetState
to that value?
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.
Yes, those should be the same. I changed it to reference a common definition of that state.
…c-change Census teacher banner spec change
I've been asked to hold off merging this until Jan. |
…fixes Census teacher banner bug fixes
This creates a new simplified version of the census form that will be shown to teachers associated with an NCES school id.
Initial display:
With "yes" selected:
With "not yet":
When you opt to update school info: