/** REACT / INERTIA */ import React, { FormEvent } from "react"; import { usePage } from "@inertiajs/react"; /** LUCIDE */ import { InfoIcon } from "lucide-react"; /** SHADCN */ import { Button } from "@/components/ui/button"; /** BASE */ import { useRecaptcha } from "@/front/providers/RecaptchaProvider"; import InputError from "$/base/InputError"; import useTrans from "@/hooks/use-translations"; import { cn } from "@/lib/utils"; interface CustomData { "g-recaptcha-response"?: string; } type BannerClassName = { classNames?: { wrapperClassName?: string; btnClassName?: string; }; }; type Props = { /* eslint-disable no-unused-vars, @typescript-eslint/no-unused-vars */ onSubmit: (e: FormEvent) => void; data: TFormData & CustomData; children: React.ReactNode; footer?: React.ReactNode; banner?: BannerClassName; classNames?: { wrapperClassName?: string; formClassName?: string; }; }; function RecaptchaNotice({ banner }: { banner?: BannerClassName }) { const { enabled } = useRecaptcha(); const title = useTrans("cookie-notice.custom.recaptcha.title"); const warning = useTrans("cookie-notice.custom.recaptcha.warning"); const label = useTrans("cookie-notice.custom.recaptcha.accept"); const handleAccept = () => { // @ts-expect-error External library window.WebCookieNotice?.acceptCookie("recaptcha"); }; if (enabled) return null; return (

{title}

{warning}
); } export default function RecaptchaForm({ onSubmit, classNames, banner, data, children, footer, }: Props) { const { getToken, formRef, enabled } = useRecaptcha(); const { errors } = usePage().props; const recaptchaKey = usePage().props.recaptchaKey as string; const handleSubmit = (e: FormEvent) => { e.preventDefault(); if (!enabled) return; const token = getToken(); // eslint-disable-next-line no-param-reassign data["g-recaptcha-response"] = token; onSubmit(e); }; return (
{children} {enabled && ( <>
)} {footer}
); }