diff --git a/src/components/ContactForm/ContactForm.jsx b/src/components/ContactForm/ContactForm.jsx index db46509..2bde5a7 100644 --- a/src/components/ContactForm/ContactForm.jsx +++ b/src/components/ContactForm/ContactForm.jsx @@ -7,6 +7,7 @@ import "./ContactForm.styles.scss"; import { fileUpload } from "../../assets/images"; function ContactForm() { +<<<<<<< Updated upstream return (
); +======= + const [formData, setFormData] = useState({ + name: '', + email: '', + message: '', + file: null, + captcha: '', + }); + const [isSubmitting, setIsSubmitting] = useState(false); + + const handleChange = (e) => { + const { name, value } = e.target; + setFormData({ ...formData, [name]: value }); + }; + + const mb = 10; // Ограничение размера в мегабайтах + const MAX_FILE_SIZE = mb * 1024 * 1024; // Переменная для проверки размера. Не менять + + const handleFileChange = (e) => { + const file = e.target.files[0]; + // Проверка размера + if (file.size > MAX_FILE_SIZE) { + alert(`Превышено ограничение размера файла (10 Мб)`); + return; + } + // Проверка расширения + const extension = file.name.match(/\.([^.]+)$/)[1]; + switch (extension) { + case 'doc': + case 'docx': + case 'pdf': + case 'txt': + case 'pptx': + case 'ppt': + setFormData({ ...formData, file: e.target.files[0] }); + break; + default: + alert('Неверный формат файла.'); + } + }; + + const handleRemoveFile = () => { + setFormData({ ...formData, file: null }); + }; + + const handleCaptchaChange = (token) => { + setFormData({ ...formData, captcha: token }); + console.log('Капча пришла'); + }; + + const handleTokenExpired = useCallback(() => { + setFormData({ ...formData, captcha: null }); + console.log('Капча просрочилась'); + }, []); + + const handleSubmit = async (e) => { + e.preventDefault(); + setIsSubmitting(true); + console.log('handleSubmit isSubmitting: ', isSubmitting); + + const formDataObj = new FormData(); + formDataObj.append('name', formData.name); + formDataObj.append('email', formData.email); + formDataObj.append('message', formData.message); + formDataObj.append('file', formData.file); + formDataObj.append('captcha', formData.captcha); + + try { + const response = await sendContactForm(formDataObj); + if (response) { + alert('Сообщение отправлено!'); + console.log('response', response); + } else { + alert('Ошибка отправки.'); + } + } catch (error) { + console.error('Ошибка:', error); + alert('Ошибка отправки.'); + } finally { + setIsSubmitting(false); + } + }; + + return ( + + ); +>>>>>>> Stashed changes } export default ContactForm; \ No newline at end of file diff --git a/src/components/ContactForm/ContactForm.styles.scss b/src/components/ContactForm/ContactForm.styles.scss index d47ed4c..b0cdd89 100644 --- a/src/components/ContactForm/ContactForm.styles.scss +++ b/src/components/ContactForm/ContactForm.styles.scss @@ -47,9 +47,22 @@ $color-file-button: rgb(7, 42, 200); width: 100%; cursor: pointer; +<<<<<<< Updated upstream padding: 12px; font-size: 18px; line-height: normal; +======= + .submit-container { + + .submit { + width: 100%; + cursor: pointer; + + padding: 12px; + font-size: 18px; + line-height: normal; + } +>>>>>>> Stashed changes } } } \ No newline at end of file diff --git a/src/pages/Contact/Contact.styles.scss b/src/pages/Contact/Contact.styles.scss index d719093..c099bd6 100644 --- a/src/pages/Contact/Contact.styles.scss +++ b/src/pages/Contact/Contact.styles.scss @@ -6,7 +6,7 @@ flex-wrap: wrap; justify-content: space-between; flex: 1 1 50%; - + margin-bottom: 2em; h1 { @@ -34,15 +34,15 @@ flex-wrap: wrap; justify-content: space-between; align-items: center; + + .submit-container { + margin: 0; + max-width: 35%; + } } - .row > * { + .row>* { flex: 1 1 calc(50% - ($gap / 2)); } - - .row:has(.submit)>* { - margin: 0; - max-width: 35%; - } } } \ No newline at end of file