Friendly Captcha ook voor de SLP-site: gedeelde widget in formulier B en het terminalformulier van E
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useMemo, useRef } from 'react';
|
||||
import { lazy, Suspense, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import {
|
||||
useContactForm,
|
||||
@@ -13,6 +13,8 @@ import { buildSubjectOptions, subjectForSlug } from '../../../shared/contact/sub
|
||||
import { contactForm, contactInfo } from '../data/content';
|
||||
import { usePackagesQuery } from '../hooks/usePackagesQuery';
|
||||
|
||||
const CaptchaWidget = lazy(() => import('../../../shared/contact/CaptchaWidget'));
|
||||
|
||||
const INPUT =
|
||||
'w-full rounded-none border-0 border-b-2 border-text bg-field px-3.5 py-[13px] text-[17px] font-normal text-text focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent disabled:opacity-70';
|
||||
|
||||
@@ -69,6 +71,7 @@ export function ContactFormView({ client, token, refreshToken }: ContactFormView
|
||||
onEvent: (event) => trackEvent(event === 'sent' ? 'contact-sent' : 'contact-failed'),
|
||||
});
|
||||
|
||||
const [captchaProblem, setCaptchaProblem] = useState(false);
|
||||
const successRef = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (form.status === 'sent') {
|
||||
@@ -139,6 +142,28 @@ export function ContactFormView({ client, token, refreshToken }: ContactFormView
|
||||
<input type="text" id={hpId} {...hpProps} />
|
||||
</div>
|
||||
|
||||
{/* Robot check (Friendly Captcha) when the server asks for it; client only, own chunk. */}
|
||||
{form.captcha ? (
|
||||
<div style={{ minHeight: 76 }}>
|
||||
<Suspense fallback={null}>
|
||||
<CaptchaWidget
|
||||
captcha={form.captcha}
|
||||
resetCount={form.captchaResetCount}
|
||||
onToken={form.setCaptchaToken}
|
||||
onProblem={setCaptchaProblem}
|
||||
/>
|
||||
</Suspense>
|
||||
</div>
|
||||
) : null}
|
||||
{captchaProblem ? (
|
||||
<p role="alert" className="font-medium text-danger" data-testid="contact-captcha-problem">
|
||||
{contactForm.captchaProblem}{' '}
|
||||
<a href={`mailto:${contactInfo.email}`} className="underline">
|
||||
{contactInfo.email}
|
||||
</a>
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{form.failureMessage ? (
|
||||
<p role="alert" className="font-medium text-danger" data-testid="contact-failure">
|
||||
{form.failureMessage}
|
||||
|
||||
Reference in New Issue
Block a user