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-16 13:12:56 +05:30
|
|
|
|
const {onClose, user} = this.props;
|
2016-05-22 22:55:38 +05:30
|
|
|
|
const {form} = this;
|
|
|
|
|
|
|
|
|
|
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-16 19:41:57 +05:30
|
|
|
|
<Form form={form} onSubmit={this.onSubmit}>
|
|
|
|
|
<div className={popupStyles.body}>
|
|
|
|
|
<div className={styles.philosophicalThought}>
|
|
|
|
|
<Message {...messages.philosophicalThought} />
|
|
|
|
|
</div>
|
2016-05-26 03:07:18 +05:30
|
|
|
|
|
2016-06-16 19:41:57 +05:30
|
|
|
|
<div className={styles.formDisclaimer}>
|
|
|
|
|
<Message {...messages.disclaimer} /><br />
|
|
|
|
|
</div>
|
2016-05-26 03:07:18 +05:30
|
|
|
|
|
2016-06-16 19:41:57 +05:30
|
|
|
|
<div className={styles.pairInputRow}>
|
|
|
|
|
<div className={styles.pairInput}>
|
|
|
|
|
<Input
|
|
|
|
|
{...form.bindField('subject')}
|
|
|
|
|
required
|
|
|
|
|
label={messages.subject}
|
|
|
|
|
skin="light"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.pairInput}>
|
|
|
|
|
<Input
|
|
|
|
|
{...form.bindField('email')}
|
|
|
|
|
required
|
|
|
|
|
label={messages.email}
|
|
|
|
|
type="email"
|
|
|
|
|
skin="light"
|
|
|
|
|
defaultValue={user.email}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2016-05-26 03:07:18 +05:30
|
|
|
|
</div>
|
|
|
|
|
|
2016-06-16 19:41:57 +05:30
|
|
|
|
<div className={styles.formMargin}>
|
|
|
|
|
<Dropdown label={messages.whichQuestion} items={CONTACT_CATEGORIES} block />
|
2016-05-26 03:07:18 +05:30
|
|
|
|
</div>
|
|
|
|
|
|
2016-06-16 19:41:57 +05:30
|
|
|
|
<TextArea
|
|
|
|
|
{...form.bindField('message')}
|
|
|
|
|
required
|
|
|
|
|
label={messages.message}
|
|
|
|
|
skin="light"
|
|
|
|
|
/>
|
2016-05-26 03:07:18 +05:30
|
|
|
|
</div>
|
|
|
|
|
|
2016-06-16 19:41:57 +05:30
|
|
|
|
<div className={styles.footer}>
|
|
|
|
|
<Button label={messages.send} block />
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
|
|
|
|
</div>
|
2016-05-22 22:55:38 +05:30
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSubmit = () => {
|
2016-06-16 02:24:13 +05:30
|
|
|
|
feedback(this.form.serialize())
|
2016-05-22 22:55:38 +05:30
|
|
|
|
.then(this.props.onClose)
|
|
|
|
|
.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);
|