mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-03-03 06:32:49 +05:30
#311: fix validation in profile forms
This commit is contained in:
parent
359ac19cc0
commit
1debe774ae
@ -323,12 +323,20 @@ export default class ChangeEmail extends Component {
|
||||
|
||||
onFormSubmit = () => {
|
||||
const {activeStep} = this.state;
|
||||
const promise = this.props.onSubmit(activeStep, this.props.stepForms[activeStep]);
|
||||
const form = this.props.stepForms[activeStep];
|
||||
const promise = this.props.onSubmit(activeStep, form);
|
||||
|
||||
if (!promise || !promise.then) {
|
||||
throw new Error('Expecting promise from onSubmit');
|
||||
}
|
||||
|
||||
promise.then(() => this.nextStep(), () => this.forceUpdate());
|
||||
promise.then(() => this.nextStep(), (resp) => {
|
||||
if (resp.errors) {
|
||||
form.setErrors(resp.errors);
|
||||
this.forceUpdate();
|
||||
} else {
|
||||
return Promise.reject(resp);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -95,6 +95,15 @@ export default class ChangePassword extends Component {
|
||||
}
|
||||
|
||||
onFormSubmit = () => {
|
||||
this.props.onSubmit(this.props.form);
|
||||
const {form} = this.props;
|
||||
|
||||
this.props.onSubmit(form)
|
||||
.catch((resp) => {
|
||||
if (resp.errors) {
|
||||
form.setErrors(resp.errors);
|
||||
} else {
|
||||
return Promise.reject(resp);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -80,6 +80,15 @@ export default class ChangeUsername extends Component {
|
||||
};
|
||||
|
||||
onFormSubmit = () => {
|
||||
this.props.onSubmit(this.props.form);
|
||||
const {form} = this.props;
|
||||
|
||||
this.props.onSubmit(form)
|
||||
.catch((resp) => {
|
||||
if (resp.errors) {
|
||||
form.setErrors(resp.errors);
|
||||
} else {
|
||||
return Promise.reject(resp);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -13,5 +13,11 @@ export default function FormError({error}) {
|
||||
}
|
||||
|
||||
FormError.propTypes = {
|
||||
error: PropTypes.string
|
||||
error: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.shape({
|
||||
type: PropTypes.string.isRequired,
|
||||
payload: PropTypes.object.isRequired
|
||||
})
|
||||
])
|
||||
};
|
||||
|
@ -25,7 +25,13 @@ export default class Input extends FormInputComponent {
|
||||
}),
|
||||
PropTypes.string
|
||||
]),
|
||||
error: PropTypes.string,
|
||||
error: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.shape({
|
||||
type: PropTypes.string.isRequired,
|
||||
payload: PropTypes.object.isRequired
|
||||
})
|
||||
]),
|
||||
icon: PropTypes.string,
|
||||
skin: PropTypes.oneOf(skins),
|
||||
color: PropTypes.oneOf(colors),
|
||||
|
@ -26,7 +26,7 @@ class ChangePasswordPage extends Component {
|
||||
|
||||
onSubmit = () => {
|
||||
const {form} = this;
|
||||
this.context.onSubmit({
|
||||
return this.context.onSubmit({
|
||||
form,
|
||||
sendData: () => accounts.changePassword(form.serialize())
|
||||
}).then(() => {
|
||||
|
@ -45,10 +45,10 @@ class ChangeUsernamePage extends Component {
|
||||
const {form} = this;
|
||||
if (this.actualUsername === this.props.username) {
|
||||
this.context.goToProfile();
|
||||
return;
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
this.context.onSubmit({
|
||||
return this.context.onSubmit({
|
||||
form,
|
||||
sendData: () => accounts.changeUsername(form.serialize())
|
||||
}).then(() => {
|
||||
|
@ -86,6 +86,8 @@ export default connect(null, {
|
||||
logger.warn('Unexpected profile editing error', {
|
||||
resp
|
||||
});
|
||||
} else {
|
||||
return Promise.reject(resp);
|
||||
}
|
||||
})
|
||||
.finally(() => form.endLoading());
|
||||
|
Loading…
x
Reference in New Issue
Block a user