From c9d98a25efffd5cd1a53a3eb5c4b00f76a449f90 Mon Sep 17 00:00:00 2001 From: bender Date: Thu, 28 May 2026 10:10:31 +0000 Subject: [PATCH] Add src/app/components/AgeVerificationModal.tsx --- src/app/components/AgeVerificationModal.tsx | 65 +++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/app/components/AgeVerificationModal.tsx diff --git a/src/app/components/AgeVerificationModal.tsx b/src/app/components/AgeVerificationModal.tsx new file mode 100644 index 0000000..963df59 --- /dev/null +++ b/src/app/components/AgeVerificationModal.tsx @@ -0,0 +1,65 @@ +"use client"; + +import React, { useState, useEffect } from "react"; +import { createPortal } from "react-dom"; + +const AgeVerificationModal = ({ children }: { children: React.ReactNode }) => { + const [isModalOpen, setIsModalOpen] = useState(false); + const [isVerified, setIsVerified] = useState(false); + + useEffect(() => { + if (typeof window !== "undefined") { + const ageVerified = localStorage.getItem("ageVerified"); + if (ageVerified === "true") { + setIsVerified(true); + } else { + setIsModalOpen(true); + } + } + }, []); + + const handleVerifyAge = (verified: boolean) => { + if (typeof window !== "undefined") { + localStorage.setItem("ageVerified", verified ? "true" : "false"); + setIsVerified(verified); + setIsModalOpen(false); + if (!verified) { + window.location.href = "https://www.google.com"; // Redirect if not verified + } + } + }; + + if (isVerified) { + return <>{children}; + } + + if (typeof window === "undefined" || !isModalOpen) { + return null; + } + + return createPortal( +
+
+

Leeftijdsverificatie

+

U moet 18 jaar of ouder zijn om deze website te bezoeken.

+
+ + +
+
+
, + document.body + ); +}; + +export default AgeVerificationModal;