fix(forms): Naprawa formularza multisplit i dodanie reCAPTCHA v3 do wszystkich formularzy
This commit is contained in:
@@ -125,6 +125,14 @@ export function AwariaClient() {
|
||||
}
|
||||
setIsSubmitting(true);
|
||||
|
||||
let recaptchaToken = '';
|
||||
if (process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY) {
|
||||
recaptchaToken = await (window as any).grecaptcha.execute(
|
||||
process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY,
|
||||
{ action: 'submit' }
|
||||
);
|
||||
}
|
||||
|
||||
await submitAwariaForm({
|
||||
isUrgent,
|
||||
brand,
|
||||
@@ -139,6 +147,7 @@ export function AwariaClient() {
|
||||
city,
|
||||
preferredDate: '',
|
||||
preferredTime: '',
|
||||
recaptchaToken,
|
||||
});
|
||||
|
||||
setIsSubmitting(false);
|
||||
|
||||
@@ -49,6 +49,14 @@ export function ContactForm() {
|
||||
});
|
||||
formData.append("consent", consent ? 'true' : 'false');
|
||||
|
||||
if (process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY) {
|
||||
const token = await (window as any).grecaptcha.execute(
|
||||
process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY,
|
||||
{ action: 'submit' }
|
||||
);
|
||||
formData.append('recaptchaToken', token);
|
||||
}
|
||||
|
||||
const response = await submitContactForm(null, formData);
|
||||
|
||||
setServerState({
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Check, Loader2 } from 'lucide-react';
|
||||
import { submitMultisplitForm } from '@/app/zapytanie-multisplit/actions';
|
||||
|
||||
interface Props {
|
||||
productName: string;
|
||||
@@ -38,20 +39,28 @@ export default function MultisplitContactForm({ productName, productSku }: Props
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
const res = await fetch('/api/contact', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name: form.name,
|
||||
phone: form.phone,
|
||||
email: form.email,
|
||||
city: form.city,
|
||||
subject: `Zapytanie o multisplit: ${productName} (${productSku})`,
|
||||
message: `Liczba pomieszczeń: ${form.rooms}\n\n${form.message}`,
|
||||
}),
|
||||
let recaptchaToken = '';
|
||||
if (process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY) {
|
||||
recaptchaToken = await (window as any).grecaptcha.execute(
|
||||
process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY,
|
||||
{ action: 'submit' }
|
||||
);
|
||||
}
|
||||
|
||||
const res = await submitMultisplitForm({
|
||||
name: form.name,
|
||||
phone: form.phone,
|
||||
email: form.email,
|
||||
city: form.city,
|
||||
rooms: form.rooms,
|
||||
message: form.message,
|
||||
consent: form.consent,
|
||||
productName,
|
||||
productSku,
|
||||
recaptchaToken,
|
||||
});
|
||||
if (res.ok) setSent(true);
|
||||
else setError('Błąd wysyłki. Zadzwoń do nas bezpośrednio.');
|
||||
if (res.success) setSent(true);
|
||||
else setError(res.message || 'Błąd wysyłki. Zadzwoń do nas bezpośrednio.');
|
||||
} catch {
|
||||
setError('Błąd połączenia. Spróbuj ponownie.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user