#145: add success state for feedback form

This commit is contained in:
SleepWalker 2016-06-18 14:23:30 +03:00
parent 187d4f12f4
commit 3f77144a53

View File

@ -33,8 +33,8 @@ class ContactForm extends Component {
form = new FormModel();
render() {
const {onClose, user} = this.props;
const {form} = this;
const {isSuccessfullySent = false} = this.state || {};
const {onClose} = this.props;
return (
<div className={styles.contactForm}>
@ -46,6 +46,20 @@ class ContactForm extends Component {
<span className={classNames(icons.close, popupStyles.close)} onClick={onClose} />
</div>
{isSuccessfullySent
? (<div>Hello world<Button onClick={onClose} label="Close" /></div>)
: this.renderForm()
}
</div>
</div>
);
}
renderForm() {
const {form} = this;
const {user} = this.props;
return (
<Form form={form} onSubmit={this.onSubmit}>
<div className={popupStyles.body}>
<div className={styles.philosophicalThought}>
@ -94,14 +108,12 @@ class ContactForm extends Component {
<Button label={messages.send} block />
</div>
</Form>
</div>
</div>
);
}
onSubmit = () => {
feedback(this.form.serialize())
.then(this.props.onClose)
.then(() => this.setState({isSuccessfullySent: true}))
.catch((resp) => {
if (resp.errors) {
this.form.setErrors(resp.errors);