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

AFE: Make state updates and session storage updates asynchronous #35532

Merged
merged 1 commit into from
Jun 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ export default class AmazonFutureEngineerEligibility extends React.Component {
getSessionEligibilityData = () =>
JSON.parse(sessionStorage.getItem(sessionStorageKey)) || {};

updateFormData = (change, callback = () => {}) => {
this.setState({formData: {...this.state.formData, ...change}}, callback);
updateFormData = change => {
this.setState({formData: {...this.state.formData, ...change}});
};

// Wrapper to allow saving data to session
// as a callback once a user submits the full eligibility form.
// Otherwise, component can be reloaded before data is stored to session,
// which can result in the incorrect component being rendered.
updateAndStoreFormData = formData => {
this.updateFormData(formData, this.saveToSessionStorage);
// once a user submits the full eligibility form.
updateAndStoreFormData = change => {
let newFormData = {...this.state.formData, ...change};

sessionStorage.setItem(sessionStorageKey, JSON.stringify(newFormData));
this.setState({formData: newFormData});
};

saveToSessionStorage = () => {
Expand Down Expand Up @@ -223,16 +224,15 @@ export default class AmazonFutureEngineerEligibility extends React.Component {
});
};

loadCompletionPage = () => {
loadCompletionPage = async () => {
let sessionEligibilityData = this.getSessionEligibilityData();

if (!sessionEligibilityData.submitted) {
this.submitToAFE().then(() => {
sessionStorage.setItem(
sessionStorageKey,
JSON.stringify({...sessionEligibilityData, submitted: true})
);
});
await this.submitToAFE();
sessionStorage.setItem(
sessionStorageKey,
JSON.stringify({...sessionEligibilityData, submitted: true})
);
}

window.location = pegasus('/afe/success');
Expand All @@ -241,6 +241,10 @@ export default class AmazonFutureEngineerEligibility extends React.Component {
render() {
let {formData} = this.state;

if (formData.schoolEligible && formData.consentAFE && formData.signedIn) {
this.loadCompletionPage();
}

return (
<div style={styles.container}>
{formData.schoolEligible === null && (
Expand Down Expand Up @@ -293,10 +297,6 @@ export default class AmazonFutureEngineerEligibility extends React.Component {
{formData.schoolEligible &&
formData.consentAFE &&
!formData.signedIn && <AmazonFutureEngineerAccountConfirmation />}
{formData.schoolEligible &&
formData.consentAFE &&
formData.signedIn &&
this.loadCompletionPage()}
</div>
);
}
Expand Down