mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-03-07 00:09:13 +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 = () => {
|
onFormSubmit = () => {
|
||||||
const {activeStep} = this.state;
|
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) {
|
if (!promise || !promise.then) {
|
||||||
throw new Error('Expecting promise from onSubmit');
|
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 = () => {
|
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 = () => {
|
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 = {
|
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
|
PropTypes.string
|
||||||
]),
|
]),
|
||||||
error: PropTypes.string,
|
error: PropTypes.oneOfType([
|
||||||
|
PropTypes.string,
|
||||||
|
PropTypes.shape({
|
||||||
|
type: PropTypes.string.isRequired,
|
||||||
|
payload: PropTypes.object.isRequired
|
||||||
|
})
|
||||||
|
]),
|
||||||
icon: PropTypes.string,
|
icon: PropTypes.string,
|
||||||
skin: PropTypes.oneOf(skins),
|
skin: PropTypes.oneOf(skins),
|
||||||
color: PropTypes.oneOf(colors),
|
color: PropTypes.oneOf(colors),
|
||||||
|
@ -26,7 +26,7 @@ class ChangePasswordPage extends Component {
|
|||||||
|
|
||||||
onSubmit = () => {
|
onSubmit = () => {
|
||||||
const {form} = this;
|
const {form} = this;
|
||||||
this.context.onSubmit({
|
return this.context.onSubmit({
|
||||||
form,
|
form,
|
||||||
sendData: () => accounts.changePassword(form.serialize())
|
sendData: () => accounts.changePassword(form.serialize())
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
@ -45,10 +45,10 @@ class ChangeUsernamePage extends Component {
|
|||||||
const {form} = this;
|
const {form} = this;
|
||||||
if (this.actualUsername === this.props.username) {
|
if (this.actualUsername === this.props.username) {
|
||||||
this.context.goToProfile();
|
this.context.goToProfile();
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.context.onSubmit({
|
return this.context.onSubmit({
|
||||||
form,
|
form,
|
||||||
sendData: () => accounts.changeUsername(form.serialize())
|
sendData: () => accounts.changeUsername(form.serialize())
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
@ -86,6 +86,8 @@ export default connect(null, {
|
|||||||
logger.warn('Unexpected profile editing error', {
|
logger.warn('Unexpected profile editing error', {
|
||||||
resp
|
resp
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
return Promise.reject(resp);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => form.endLoading());
|
.finally(() => form.endLoading());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user