Refactored signup handling

We had two implementations for the same signup logic, which meant that we would
have to update two places when modifying the logic. This consolidates the logic
into a single method so that when we add the terms and checkbox feature we can
make the checks in a single place.
This commit is contained in:
Fabien "egg" O'Carroll 2023-04-04 15:20:17 +07:00 committed by Fabien 'egg' O'Carroll
parent bdaa992ced
commit ab8304fa5c

View File

@ -263,14 +263,13 @@ class SignupPage extends React.Component {
clearTimeout(this.timeoutId);
}
handleSignup(e) {
const {site, onAction} = this.context;
e.preventDefault();
doSignup() {
this.setState((state) => {
return {
errors: ValidateInputForm({fields: this.getInputFields({state})})
};
}, () => {
const {site, onAction} = this.context;
const {name, email, plan, errors} = this.state;
const hasFormErrors = (errors && Object.values(errors).filter(d => !!d).length > 0);
if (!hasFormErrors) {
@ -290,30 +289,15 @@ class SignupPage extends React.Component {
});
}
handleSignup(e) {
e.preventDefault();
this.doSignup();
}
handleChooseSignup(e, plan) {
e.preventDefault();
this.setState((state) => {
return {
errors: ValidateInputForm({fields: this.getInputFields({state})})
};
}, () => {
const {onAction, site} = this.context;
const {name, email, errors} = this.state;
const hasFormErrors = (errors && Object.values(errors).filter(d => !!d).length > 0);
if (!hasFormErrors) {
if (hasMultipleNewsletters({site})) {
this.setState({
showNewsletterSelection: true,
pageData: {name, email, plan},
errors: {}
});
} else {
onAction('signup', {name, email, plan});
this.setState({
errors: {}
});
}
}
this.setState({plan}, () => {
this.doSignup();
});
}