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