mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 04:39:45 +00:00
Фикс ширины капчи и её видимости
This commit is contained in:
1 parent
609d08651b
commit
2faef9ae65
3 files changed
+175
-6
No files matched your search
@@ -7,6 +7,7 @@ import "./ContactForm.styles.scss";
|
|||||||
import { fileUpload } from "../../assets/images";
|
import { fileUpload } from "../../assets/images";
|
||||||
|
|
||||||
function ContactForm() {
|
function ContactForm() {
|
||||||
|
<<<<<<< Updated upstream
|
||||||
return (
|
return (
|
||||||
<Form method="post" className="half contact-form">
|
<Form method="post" className="half contact-form">
|
||||||
<h2>Свяжитесь с нами!</h2>
|
<h2>Свяжитесь с нами!</h2>
|
||||||
@@ -46,6 +47,161 @@ function ContactForm() {
|
|||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
|
=======
|
||||||
|
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 (
|
||||||
|
<Form method="post" onSubmit={handleSubmit} className="half contact-form">
|
||||||
|
<h2>Свяжитесь с нами!</h2>
|
||||||
|
<div className="inputs">
|
||||||
|
<div className="row">
|
||||||
|
<Field
|
||||||
|
key={1}
|
||||||
|
type="text"
|
||||||
|
name="name"
|
||||||
|
placeholder="Имя"
|
||||||
|
value={formData.name}
|
||||||
|
onChange={handleChange}
|
||||||
|
required
|
||||||
|
isDisabled={isSubmitting}
|
||||||
|
/>
|
||||||
|
<Field
|
||||||
|
key={2}
|
||||||
|
type="email"
|
||||||
|
name="email"
|
||||||
|
placeholder="E-mail"
|
||||||
|
value={formData.email}
|
||||||
|
onChange={handleChange}
|
||||||
|
required
|
||||||
|
isDisabled={isSubmitting}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Field
|
||||||
|
key={3}
|
||||||
|
type="textarea"
|
||||||
|
name="message"
|
||||||
|
placeholder="Опишите в этом поле свой проект и, по возможности, прикрепите файл с ТЗ"
|
||||||
|
value={formData.message}
|
||||||
|
onChange={handleChange}
|
||||||
|
required
|
||||||
|
isDisabled={isSubmitting}
|
||||||
|
/>
|
||||||
|
<div className="row">
|
||||||
|
<Field
|
||||||
|
key={4}
|
||||||
|
type="file"
|
||||||
|
name="file"
|
||||||
|
onChange={handleFileChange}
|
||||||
|
handleRemoveFile={handleRemoveFile}
|
||||||
|
fileAttached={formData && formData.file ? true : false}
|
||||||
|
isDisabled={isSubmitting}
|
||||||
|
/>
|
||||||
|
<div className="submit-container">
|
||||||
|
{formData.captcha &&
|
||||||
|
<Field
|
||||||
|
key={5}
|
||||||
|
type="submit"
|
||||||
|
value={isSubmitting ? 'Отправляется' : 'Отправить'}
|
||||||
|
isDisabled={isSubmitting}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
<div
|
||||||
|
className="captcha-container"
|
||||||
|
style={formData.captcha ? { display: 'none' } : { display: 'block' }}
|
||||||
|
>
|
||||||
|
<SmartCaptcha
|
||||||
|
key={6}
|
||||||
|
sitekey="ysc1_8nFqhYasby2fJ9J7pCTxdBMe0Xc3Y6CrWk4aylB03d4f0045"
|
||||||
|
onSuccess={handleCaptchaChange}
|
||||||
|
onTokenExpired={handleTokenExpired}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
>>>>>>> Stashed changes
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ContactForm;
|
export default ContactForm;
|
||||||
@@ -47,9 +47,22 @@ $color-file-button: rgb(7, 42, 200);
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
|
<<<<<<< Updated upstream
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
line-height: normal;
|
line-height: normal;
|
||||||
|
=======
|
||||||
|
.submit-container {
|
||||||
|
|
||||||
|
.submit {
|
||||||
|
width: 100%;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
padding: 12px;
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: normal;
|
||||||
|
}
|
||||||
|
>>>>>>> Stashed changes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,15 +34,15 @@
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
.submit-container {
|
||||||
|
margin: 0;
|
||||||
|
max-width: 35%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.row > * {
|
.row>* {
|
||||||
flex: 1 1 calc(50% - ($gap / 2));
|
flex: 1 1 calc(50% - ($gap / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
.row:has(.submit)>* {
|
|
||||||
margin: 0;
|
|
||||||
max-width: 35%;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user