2016-05-22 22:55:38 +05:30
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
|
|
2016-05-26 03:07:18 +05:30
|
|
|
|
import { Input, TextArea, Button, Form, FormModel, Dropdown } from 'components/ui/form';
|
2016-06-16 02:24:13 +05:30
|
|
|
|
import feedback from 'services/api/feedback';
|
2016-05-22 22:55:38 +05:30
|
|
|
|
import icons from 'components/ui/icons.scss';
|
2016-05-28 04:06:01 +05:30
|
|
|
|
import popupStyles from 'components/ui/popup/popup.scss';
|
2016-05-22 22:55:38 +05:30
|
|
|
|
|
|
|
|
|
import styles from './contactForm.scss';
|
|
|
|
|
import messages from './contactForm.intl.json';
|
|
|
|
|
|
2016-06-06 04:32:36 +05:30
|
|
|
|
const CONTACT_CATEGORIES = [
|
|
|
|
|
// TODO: сюда позже проставить реальные id категорий с backend
|
|
|
|
|
<Message {...messages.cannotAccessMyAccount} />,
|
|
|
|
|
<Message {...messages.foundBugOnSite} />,
|
|
|
|
|
<Message {...messages.improvementsSuggestion} />,
|
|
|
|
|
<Message {...messages.integrationQuestion} />,
|
|
|
|
|
<Message {...messages.other} />
|
|
|
|
|
];
|
2016-05-28 04:44:28 +05:30
|
|
|
|
|
2016-06-16 13:12:56 +05:30
|
|
|
|
class ContactForm extends Component {
|
2016-05-22 22:55:38 +05:30
|
|
|
|
static displayName = 'ContactForm';
|
|
|
|
|
|
|
|
|
|
static propTypes = {
|
2016-06-16 13:12:56 +05:30
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
|
user: PropTypes.shape({
|
|
|
|
|
email: PropTypes.string
|
|
|
|
|
}).isRequired
|
2016-05-22 22:55:38 +05:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
form = new FormModel();
|
|
|
|
|
|
|
|
|
|
render() {
|
2016-06-18 16:53:30 +05:30
|
|
|
|
const {isSuccessfullySent = false} = this.state || {};
|
|
|
|
|
const {onClose} = this.props;
|
2016-05-22 22:55:38 +05:30
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.contactForm}>
|
2016-06-16 19:41:57 +05:30
|
|
|
|
<div className={popupStyles.popup}>
|
|
|
|
|
<div className={popupStyles.header}>
|
|
|
|
|
<h2 className={popupStyles.headerTitle}>
|
|
|
|
|
<Message {...messages.title} />
|
|
|
|
|
</h2>
|
|
|
|
|
<span className={classNames(icons.close, popupStyles.close)} onClick={onClose} />
|
|
|
|
|
</div>
|
2016-05-22 22:55:38 +05:30
|
|
|
|
|
2016-06-18 16:53:30 +05:30
|
|
|
|
{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}>
|
|
|
|
|
<Message {...messages.philosophicalThought} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.formDisclaimer}>
|
|
|
|
|
<Message {...messages.disclaimer} /><br />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.pairInputRow}>
|
|
|
|
|
<div className={styles.pairInput}>
|
|
|
|
|
<Input
|
|
|
|
|
{...form.bindField('subject')}
|
2016-06-16 19:41:57 +05:30
|
|
|
|
required
|
2016-06-18 16:53:30 +05:30
|
|
|
|
label={messages.subject}
|
2016-06-16 19:41:57 +05:30
|
|
|
|
skin="light"
|
|
|
|
|
/>
|
2016-05-26 03:07:18 +05:30
|
|
|
|
</div>
|
|
|
|
|
|
2016-06-18 16:53:30 +05:30
|
|
|
|
<div className={styles.pairInput}>
|
|
|
|
|
<Input
|
|
|
|
|
{...form.bindField('email')}
|
|
|
|
|
required
|
|
|
|
|
label={messages.email}
|
|
|
|
|
type="email"
|
|
|
|
|
skin="light"
|
|
|
|
|
defaultValue={user.email}
|
|
|
|
|
/>
|
2016-06-16 19:41:57 +05:30
|
|
|
|
</div>
|
2016-06-18 16:53:30 +05:30
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.formMargin}>
|
|
|
|
|
<Dropdown label={messages.whichQuestion} items={CONTACT_CATEGORIES} block />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<TextArea
|
|
|
|
|
{...form.bindField('message')}
|
|
|
|
|
required
|
|
|
|
|
label={messages.message}
|
|
|
|
|
skin="light"
|
|
|
|
|
/>
|
2016-06-16 19:41:57 +05:30
|
|
|
|
</div>
|
2016-06-18 16:53:30 +05:30
|
|
|
|
|
|
|
|
|
<div className={styles.footer}>
|
|
|
|
|
<Button label={messages.send} block />
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
2016-05-22 22:55:38 +05:30
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSubmit = () => {
|
2016-06-16 02:24:13 +05:30
|
|
|
|
feedback(this.form.serialize())
|
2016-06-18 16:53:30 +05:30
|
|
|
|
.then(() => this.setState({isSuccessfullySent: true}))
|
2016-05-22 22:55:38 +05:30
|
|
|
|
.catch((resp) => {
|
|
|
|
|
if (resp.errors) {
|
|
|
|
|
this.form.setErrors(resp.errors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Promise.reject(resp);
|
|
|
|
|
})
|
|
|
|
|
;
|
|
|
|
|
};
|
|
|
|
|
}
|
2016-06-16 13:12:56 +05:30
|
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
|
|
export default connect((state) => ({
|
|
|
|
|
user: state.user
|
|
|
|
|
}))(ContactForm);
|