import React, { ComponentType, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { FormattedMessage as Message, defineMessages } from 'react-intl';
import Popup from 'app/components/ui/popup';
import { Input, TextArea, Button, Form, FormModel, Dropdown } from 'app/components/ui/form';
import styles from './contactForm.scss';
const CONTACT_CATEGORIES = {
// TODO: сюда позже проставить реальные id категорий с backend
0: ,
1: ,
2: ,
3: ,
4: ,
};
const labels = defineMessages({
subject: 'Subject',
email: 'E‑mail',
message: 'Message',
whichQuestion: 'What are you interested in?',
});
interface Props {
initEmail?: string;
onSubmit?: (params: { subject: string; email: string; category: string; message: string }) => Promise;
onClose?: () => void;
}
const ContactFormPopup: ComponentType = ({ initEmail = '', onSubmit, onClose }) => {
const form = useMemo(() => new FormModel(), []);
const [isLoading, setIsLoading] = useState(false);
const isMountedRef = useRef(true);
const onSubmitCallback = useCallback((): Promise => {
if (isLoading || !onSubmit) {
return Promise.resolve();
}
setIsLoading(true);
return (
// @ts-ignore serialize() returns Record, but we exactly know returning keys
onSubmit(form.serialize())
.catch((resp) => {
if (resp.errors) {
form.setErrors(resp.errors);
return;
}
})
.finally(() => isMountedRef.current && setIsLoading(false))
);
}, [isLoading, onSubmit]);
useEffect(
() => () => {
isMountedRef.current = false;
},
[],
);
return (
}
wrapperClassName={styles.contactFormBoundings}
onClose={onClose}
data-testid="feedbackPopup"
>
);
};
export default ContactFormPopup;