mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 05:50:35 +03:00
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:
parent
bdaa992ced
commit
ab8304fa5c
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user