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
Conversation
@@ -21,24 +21,46 @@ class SchoolInfoConfirmationDialog extends Component { | |||
|
|||
constructor(props) { | |||
super(props); | |||
|
|||
this.state = { | |||
showSchoolInterstitial: false, | |||
schoolName: props.schoolName, |
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.
Should this be required? (Github won't let me put this comment comment in propTypes)
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.
@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
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.
Makes sense. Thanks!
fetch('/dashboardapi/v1/users/me/school_name') | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log(data); |
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.
Debug statement?
componentDidMount() { | ||
const {schoolName} = this.state; | ||
if (!schoolName && schoolName.length > 0) { | ||
fetch('/dashboardapi/v1/users/me/school_name') |
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.
Shouldn't this be supplied by the controller?
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, it is supplied by the controller. I added a controller method to get the school name
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.
Sorry if I've just forgotten a past PR but how do we decide when to show this dialog again? Where is that code?
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.
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 = { |
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.
How do these defaultProps get used?
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.
@epeach The default props will be used unless the parent component over-rides them.
schoolName: data.school_name | ||
}); | ||
}) | ||
.catch(error => this.setState({error})); |
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 not familiar with this setState syntax - to what is the error assigned?
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.
If the request to fetch schoolName is unsuccessful, an error is thrown to activate the catch call.
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.
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?
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.
Ah I see, it's the local state of the component
@epeach @bethanyaconnor Thanks for the code review, let me know if you have any additional questions or if this PR is good to go. |
render json: { | ||
school_name: current_user&.school | ||
} | ||
end |
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 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.
An api end point was added to fetch the school name for a signed in user (teacher).
Part 2: PR 27534