parent
de0d2c4ca4
commit
043dd5ce3d
|
|
@ -4,38 +4,40 @@ import { content_pl } from "../content/kamil"
|
||||||
import { content_en } from "../content/kamil"
|
import { content_en } from "../content/kamil"
|
||||||
import ReCAPTCHA from "react-google-recaptcha"
|
import ReCAPTCHA from "react-google-recaptcha"
|
||||||
|
|
||||||
const RECAPTCHA_SITE_KEY = process.env.GATSBY_RECAPTCHA_SITE_KEY || "YOUR_RECAPTCHA_SITE_KEY"
|
// Klucz strony reCAPTCHA
|
||||||
|
const RECAPTCHA_SITE_KEY = process.env.GATSBY_RECAPTCHA_SITE_KEY || "YOUR_RECAPTCHA_SITE_KEY";
|
||||||
|
|
||||||
|
// Komponent obsługujący reCAPTCHA
|
||||||
const CaptchaWrapper = ({ onVerified }) => {
|
const CaptchaWrapper = ({ onVerified }) => {
|
||||||
const [error, setError] = React.useState(null);
|
const [error, setError] = React.useState(null);
|
||||||
const isMounted = React.useRef(true);
|
const recaptchaRef = React.useRef(null);
|
||||||
|
|
||||||
React.useEffect(() => {
|
const handleCaptchaChange = () => {
|
||||||
return () => {
|
try {
|
||||||
isMounted.current = false;
|
const token = recaptchaRef.current.getValue();
|
||||||
};
|
if (token) {
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleCaptchaChange = (value) => {
|
|
||||||
if (isMounted.current && value) {
|
|
||||||
onVerified(true);
|
onVerified(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
}
|
}
|
||||||
};
|
} catch (err) {
|
||||||
|
console.error("reCAPTCHA error:", err);
|
||||||
const handleCaptchaError = () => {
|
setError("Wystąpił błąd podczas weryfikacji. Spróbuj ponownie.");
|
||||||
if (isMounted.current) {
|
|
||||||
setError('Wystąpił błąd podczas weryfikacji CAPTCHA');
|
|
||||||
onVerified(false);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="captcha-container">
|
<div className="captcha-container">
|
||||||
<ReCAPTCHA
|
<ReCAPTCHA
|
||||||
|
ref={recaptchaRef}
|
||||||
sitekey={RECAPTCHA_SITE_KEY}
|
sitekey={RECAPTCHA_SITE_KEY}
|
||||||
onChange={handleCaptchaChange}
|
onChange={handleCaptchaChange}
|
||||||
onError={handleCaptchaError}
|
onErrored={() => setError("Wystąpił błąd podczas weryfikacji. Spróbuj ponownie.")}
|
||||||
|
onExpired={() => {
|
||||||
|
if (recaptchaRef.current) {
|
||||||
|
recaptchaRef.current.reset();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
hl="pl"
|
||||||
/>
|
/>
|
||||||
{error && (
|
{error && (
|
||||||
<div className="error-message" role="alert">
|
<div className="error-message" role="alert">
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,9 @@ body {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
|
padding: 10px;
|
||||||
|
|
||||||
.error-message {
|
.error-message {
|
||||||
color: #ff4444;
|
color: #ff4444;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue