Skip to content
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

School Info Confirmation Dialog - fetch school name for signed in user #27742

Merged
merged 6 commits into from Apr 9, 2019

Conversation

nkiruka
Copy link
Contributor

@nkiruka nkiruka commented Mar 28, 2019

An api end point was added to fetch the school name for a signed in user (teacher).
Part 2: PR 27534

@@ -21,24 +21,46 @@ class SchoolInfoConfirmationDialog extends Component {

constructor(props) {
super(props);

this.state = {
showSchoolInterstitial: false,
schoolName: props.schoolName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be required? (Github won't let me put this comment comment in propTypes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bethanyaconnor Are you referring to schoolName? There might be times that a teacher did not enter the name of the school; so I decided to have a default value of an empty string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thanks!

fetch('/dashboardapi/v1/users/me/school_name')
.then(response => response.json())
.then(data => {
console.log(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug statement?

componentDidMount() {
const {schoolName} = this.state;
if (!schoolName && schoolName.length > 0) {
fetch('/dashboardapi/v1/users/me/school_name')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be supplied by the controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is supplied by the controller. I added a controller method to get the school name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I've just forgotten a past PR but how do we decide when to show this dialog again? Where is that code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I sent another PR that includes the code. I added a helper method that contains the logic for when to show the dialog.

this.state = {
showSchoolInterstitial: false,
schoolName: props.schoolName,
isOpen: true
};
}

static defaultProps = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do these defaultProps get used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epeach The default props will be used unless the parent component over-rides them.

schoolName: data.school_name
});
})
.catch(error => this.setState({error}));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with this setState syntax - to what is the error assigned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the request to fetch schoolName is unsuccessful, an error is thrown to activate the catch call.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - my question should have been clearer! Once the catch call is activated, and this.setState({error}) is called, to which part of the state is error set?

Copy link
Contributor Author

@nkiruka nkiruka Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, it's the local state of the component

@nkiruka
Copy link
Contributor Author

nkiruka commented Apr 5, 2019

@epeach @bethanyaconnor Thanks for the code review, let me know if you have any additional questions or if this PR is good to go.

@nkiruka nkiruka merged commit 6d35ab5 into staging Apr 9, 2019
@nkiruka nkiruka deleted the fetch-school-name branch April 9, 2019 20:23
render json: {
school_name: current_user&.school
}
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole controller strikes me as very odd. Our route takes a user_id parameter, but it must be me or the current user's id, and our controller method here ignores the parameter anyway. Something we'd want to clean up in the future? At the very least, I'd suggest this method use @user.school, and have a test that confirms we can only get the current_user's school name, so if the load_user method is changed in the future we know this behavior is preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants