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';
|
2020-06-04 22:11:27 +05:30
|
|
|
|
import { FormattedMessage as Message, defineMessages } from 'react-intl';
|
2020-05-24 04:38:24 +05:30
|
|
|
|
import { Input, TextArea, Button, Form, FormModel, Dropdown } from 'app/components/ui/form';
|
2019-12-08 00:32:00 +05:30
|
|
|
|
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';
|
|
|
|
|
|
2019-12-28 15:35:41 +05:30
|
|
|
|
const CONTACT_CATEGORIES = {
|
2020-05-24 04:38:24 +05:30
|
|
|
|
// TODO: сюда позже проставить реальные id категорий с backend
|
2020-06-04 22:11:27 +05:30
|
|
|
|
0: <Message key="cannotAccessMyAccount" defaultMessage="Can not access my account" />,
|
|
|
|
|
1: <Message key="foundBugOnSite" defaultMessage="I found a bug on the site" />,
|
|
|
|
|
2: <Message key="improvementsSuggestion" defaultMessage="I have a suggestion for improving the functional" />,
|
|
|
|
|
3: <Message key="integrationQuestion" defaultMessage="Service integration question" />,
|
|
|
|
|
4: <Message key="other" defaultMessage="Other" />,
|
2019-12-28 15:35:41 +05:30
|
|
|
|
};
|
2016-05-28 04:44:28 +05:30
|
|
|
|
|
2020-06-04 22:11:27 +05:30
|
|
|
|
const labels = defineMessages({
|
|
|
|
|
subject: 'Subject',
|
|
|
|
|
email: 'E‑mail',
|
|
|
|
|
message: 'Message',
|
|
|
|
|
whichQuestion: 'What are you interested in?',
|
|
|
|
|
|
|
|
|
|
send: 'Send',
|
|
|
|
|
|
|
|
|
|
close: 'Close',
|
|
|
|
|
});
|
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
|
export class ContactForm extends React.Component<
|
2020-05-24 04:38:24 +05:30
|
|
|
|
{
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
user: User;
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
isSuccessfullySent: boolean;
|
|
|
|
|
lastEmail: string | null;
|
|
|
|
|
}
|
2019-12-07 16:58:52 +05:30
|
|
|
|
> {
|
2020-05-24 04:38:24 +05:30
|
|
|
|
static defaultProps = {
|
|
|
|
|
onClose() {},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
state = {
|
|
|
|
|
isLoading: false,
|
|
|
|
|
isSuccessfullySent: false,
|
|
|
|
|
lastEmail: null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
form = new FormModel();
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { isSuccessfullySent } = this.state || {};
|
|
|
|
|
const { onClose } = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div data-testid="feedbackPopup" className={isSuccessfullySent ? styles.successState : styles.contactForm}>
|
|
|
|
|
<div className={popupStyles.popup}>
|
|
|
|
|
<div className={popupStyles.header}>
|
|
|
|
|
<h2 className={popupStyles.headerTitle}>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Message key="title" defaultMessage="Feedback form" />
|
2020-05-24 04:38:24 +05:30
|
|
|
|
</h2>
|
|
|
|
|
<span
|
|
|
|
|
className={clsx(icons.close, popupStyles.close)}
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
data-testid="feedback-popup-close"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{isSuccessfullySent ? this.renderSuccess() : this.renderForm()}
|
|
|
|
|
</div>
|
2016-06-18 16:53:30 +05:30
|
|
|
|
</div>
|
2020-05-24 04:38:24 +05:30
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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}>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Message
|
|
|
|
|
key="philosophicalThought"
|
|
|
|
|
defaultMessage="Properly formulated question — half of the answer"
|
|
|
|
|
/>
|
2020-05-24 04:38:24 +05:30
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.formDisclaimer}>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Message
|
|
|
|
|
key="disclaimer"
|
|
|
|
|
defaultMessage="Please formulate your feedback providing as much useful information, as possible to help us understand your problem and solve it"
|
|
|
|
|
/>
|
2020-05-24 04:38:24 +05:30
|
|
|
|
<br />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.pairInputRow}>
|
|
|
|
|
<div className={styles.pairInput}>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Input {...form.bindField('subject')} required label={labels.subject} skin="light" />
|
2020-05-24 04:38:24 +05:30
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.pairInput}>
|
|
|
|
|
<Input
|
|
|
|
|
{...form.bindField('email')}
|
|
|
|
|
required
|
2020-06-04 22:11:27 +05:30
|
|
|
|
label={labels.email}
|
2020-05-24 04:38:24 +05:30
|
|
|
|
type="email"
|
|
|
|
|
skin="light"
|
|
|
|
|
defaultValue={user.email}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.formMargin}>
|
|
|
|
|
<Dropdown
|
|
|
|
|
{...form.bindField('category')}
|
2020-06-04 22:11:27 +05:30
|
|
|
|
label={labels.whichQuestion}
|
2020-05-24 04:38:24 +05:30
|
|
|
|
items={CONTACT_CATEGORIES}
|
|
|
|
|
block
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<TextArea
|
|
|
|
|
{...form.bindField('message')}
|
|
|
|
|
required
|
2020-06-04 22:11:27 +05:30
|
|
|
|
label={labels.message}
|
2020-05-24 04:38:24 +05:30
|
|
|
|
skin="light"
|
|
|
|
|
minRows={6}
|
|
|
|
|
maxRows={6}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.footer}>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Button label={labels.send} block type="submit" disabled={isLoading} />
|
2020-05-24 04:38:24 +05:30
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-05-22 22:55:38 +05:30
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
renderSuccess() {
|
|
|
|
|
const { lastEmail: email } = this.state;
|
|
|
|
|
const { onClose } = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<div className={styles.successBody}>
|
|
|
|
|
<span className={styles.successIcon} />
|
|
|
|
|
<div className={styles.successDescription}>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Message
|
|
|
|
|
key="youMessageReceived"
|
|
|
|
|
defaultMessage="Your message was received. We will respond to you shortly. The answer will come to your E‑mail:"
|
|
|
|
|
/>
|
2020-05-24 04:38:24 +05:30
|
|
|
|
</div>
|
|
|
|
|
<div className={styles.sentToEmail}>{email}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className={styles.footer}>
|
2020-06-04 22:11:27 +05:30
|
|
|
|
<Button label={labels.close} block onClick={onClose} data-testid="feedback-popup-close-button" />
|
2020-05-24 04:38:24 +05:30
|
|
|
|
</div>
|
2016-06-18 21:05:39 +05:30
|
|
|
|
</div>
|
2020-05-24 04:38:24 +05:30
|
|
|
|
);
|
2016-06-18 21:05:39 +05:30
|
|
|
|
}
|
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
|
onSubmit = (): Promise<void> => {
|
|
|
|
|
if (this.state.isLoading) {
|
|
|
|
|
return Promise.resolve();
|
2016-12-10 21:28:47 +05:30
|
|
|
|
}
|
|
|
|
|
|
2020-05-24 04:38:24 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) => ({
|
2020-05-24 04:38:24 +05:30
|
|
|
|
user: state.user,
|
2016-06-16 13:12:56 +05:30
|
|
|
|
}))(ContactForm);
|