2019-12-07 16:58:52 +05:30
|
|
|
|
import React from 'react';
|
2019-06-30 19:02:50 +05:30
|
|
|
|
import { connect } from 'react-redux';
|
2019-12-08 01:13:08 +05:30
|
|
|
|
import clsx from 'clsx';
|
2016-05-22 22:55:38 +05:30
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
2019-11-27 14:33:32 +05:30
|
|
|
|
import {
|
|
|
|
|
Input,
|
|
|
|
|
TextArea,
|
|
|
|
|
Button,
|
|
|
|
|
Form,
|
|
|
|
|
FormModel,
|
|
|
|
|
Dropdown,
|
2019-12-08 00:32:00 +05:30
|
|
|
|
} from 'app/components/ui/form';
|
|
|
|
|
import feedback from 'app/services/api/feedback';
|
|
|
|
|
import icons from 'app/components/ui/icons.scss';
|
|
|
|
|
import popupStyles from 'app/components/ui/popup/popup.scss';
|
|
|
|
|
import { RootState } from 'app/reducers';
|
|
|
|
|
import logger from 'app/services/logger';
|
|
|
|
|
import { User } from 'app/components/user';
|
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 = [
|
2019-11-27 14:33:32 +05:30
|
|
|
|
// TODO: сюда позже проставить реальные id категорий с backend
|
|
|
|
|
<Message key="m1" {...messages.cannotAccessMyAccount} />,
|
|
|
|
|
<Message key="m2" {...messages.foundBugOnSite} />,
|
|
|
|
|
<Message key="m3" {...messages.improvementsSuggestion} />,
|
|
|
|
|
<Message key="m4" {...messages.integrationQuestion} />,
|
|
|
|
|
<Message key="m5" {...messages.other} />,
|
2016-06-06 04:32:36 +05:30
|
|
|
|
];
|
2016-05-28 04:44:28 +05:30
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
|
export class ContactForm extends React.Component<
|
|
|
|
|
{
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
user: User;
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
isSuccessfullySent: boolean;
|
|
|
|
|
lastEmail: string | null;
|
|
|
|
|
}
|
|
|
|
|
> {
|
2019-11-27 14:33:32 +05:30
|
|
|
|
static defaultProps = {
|
|
|
|
|
onClose() {},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
state = {
|
|
|
|
|
isLoading: false,
|
|
|
|
|
isSuccessfullySent: false,
|
2019-12-07 16:58:52 +05:30
|
|
|
|
lastEmail: null,
|
2019-11-27 14:33:32 +05:30
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
form = new FormModel();
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { isSuccessfullySent } = this.state || {};
|
|
|
|
|
const { onClose } = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
data-e2e="feedbackPopup"
|
|
|
|
|
className={
|
|
|
|
|
isSuccessfullySent ? styles.successState : styles.contactForm
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<div className={popupStyles.popup}>
|
|
|
|
|
<div className={popupStyles.header}>
|
|
|
|
|
<h2 className={popupStyles.headerTitle}>
|
|
|
|
|
<Message {...messages.title} />
|
|
|
|
|
</h2>
|
|
|
|
|
<span
|
2019-12-08 01:13:08 +05:30
|
|
|
|
className={clsx(icons.close, popupStyles.close)}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
onClick={onClose}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{isSuccessfullySent ? this.renderSuccess() : this.renderForm()}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderForm() {
|
|
|
|
|
const { form } = this;
|
|
|
|
|
const { user } = this.props;
|
|
|
|
|
const { isLoading } = this.state;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Form form={form} onSubmit={this.onSubmit} isLoading={isLoading}>
|
|
|
|
|
<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')}
|
|
|
|
|
required
|
|
|
|
|
label={messages.subject}
|
|
|
|
|
skin="light"
|
|
|
|
|
/>
|
2016-06-18 16:53:30 +05:30
|
|
|
|
</div>
|
2016-05-22 22:55:38 +05:30
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
<div className={styles.pairInput}>
|
|
|
|
|
<Input
|
|
|
|
|
{...form.bindField('email')}
|
|
|
|
|
required
|
|
|
|
|
label={messages.email}
|
|
|
|
|
type="email"
|
|
|
|
|
skin="light"
|
|
|
|
|
defaultValue={user.email}
|
|
|
|
|
/>
|
2016-06-18 21:05:39 +05:30
|
|
|
|
</div>
|
2019-11-27 14:33:32 +05:30
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.formMargin}>
|
|
|
|
|
<Dropdown
|
|
|
|
|
{...form.bindField('category')}
|
|
|
|
|
label={messages.whichQuestion}
|
|
|
|
|
items={CONTACT_CATEGORIES}
|
|
|
|
|
block
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<TextArea
|
|
|
|
|
{...form.bindField('message')}
|
|
|
|
|
required
|
|
|
|
|
label={messages.message}
|
|
|
|
|
skin="light"
|
|
|
|
|
minRows={6}
|
|
|
|
|
maxRows={6}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.footer}>
|
|
|
|
|
<Button label={messages.send} block type="submit" />
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderSuccess() {
|
|
|
|
|
const { lastEmail: email } = this.state;
|
|
|
|
|
const { onClose } = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<div className={styles.successBody}>
|
|
|
|
|
<span className={styles.successIcon} />
|
|
|
|
|
<div className={styles.successDescription}>
|
|
|
|
|
<Message {...messages.youMessageReceived} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.sentToEmail}>{email}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.footer}>
|
|
|
|
|
<Button label={messages.close} block onClick={onClose} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSubmit = () => {
|
|
|
|
|
if (this.state.isLoading) {
|
|
|
|
|
return;
|
2016-06-18 21:05:39 +05:30
|
|
|
|
}
|
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
this.setState({ isLoading: true });
|
|
|
|
|
|
|
|
|
|
return feedback
|
|
|
|
|
.send(this.form.serialize())
|
|
|
|
|
.then(() =>
|
|
|
|
|
this.setState({
|
|
|
|
|
isSuccessfullySent: true,
|
|
|
|
|
lastEmail: this.form.value('email'),
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.catch(resp => {
|
|
|
|
|
if (resp.errors) {
|
|
|
|
|
this.form.setErrors(resp.errors);
|
|
|
|
|
|
|
|
|
|
return;
|
2016-12-10 21:28:47 +05:30
|
|
|
|
}
|
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
|
logger.warn('Error sending feedback', resp);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => this.setState({ isLoading: false }));
|
|
|
|
|
};
|
2016-05-22 22:55:38 +05:30
|
|
|
|
}
|
2016-06-16 13:12:56 +05:30
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
|
export default connect((state: RootState) => ({
|
2019-11-27 14:33:32 +05:30
|
|
|
|
user: state.user,
|
2016-06-16 13:12:56 +05:30
|
|
|
|
}))(ContactForm);
|