/** REACT / INERTIA */ import { usePage } from "@inertiajs/react"; import React, { SubmitEventHandler } from "react"; /** LUCIDE */ import { InfoIcon } from "lucide-react"; /** SHADCN */ import { Button } from "@/components/ui/button"; /** BASE */ import InputError from "$/base/InputError"; import { useRecaptcha } from "@/front/providers/RecaptchaProvider"; import trans 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: SubmitEventHandler; data: TFormData & CustomData; children: React.ReactNode; footer?: React.ReactNode; banner?: BannerClassName; classNames?: { wrapperClassName?: string; formClassName?: string; }; }; function RecaptchaNotice({ banner }: Readonly<{ banner?: BannerClassName }>) { const { enabled } = useRecaptcha(); const title = trans("cookie-notice.custom.recaptcha.title"); const warning = trans("cookie-notice.custom.recaptcha.warning"); const label = trans("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, }: Readonly>) { const { getToken, formRef, enabled } = useRecaptcha(); const { errors } = usePage().props; const { recaptchaKey } = usePage().props.cookieEnv as CookieEnv; const handleSubmit: SubmitEventHandler = (e) => { 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}
); }