This commit is contained in:
 Илья Шалонин 2025-10-29 13:43:43 +05:00
commit 8538ab969a
434 changed files with 44051 additions and 0 deletions

View file

@ -0,0 +1,42 @@
"use client";
import Cookies from "js-cookie";
import { createContext, useState } from "react";
export const ConsentContext = createContext<{
userHasConsented: boolean;
allowCookies: () => void;
declineCookies: () => void;
}>({
userHasConsented: false,
allowCookies: () => {},
declineCookies: () => {},
});
export function ConsentProvider({
children,
initialConsent,
}: {
children: React.ReactNode;
initialConsent?: boolean;
}) {
const [userHasConsented, setUserHasConsented] = useState(!!initialConsent);
const allowCookies = () => {
Cookies.set("consent", "true", { expires: 30 });
setUserHasConsented(true);
};
const declineCookies = () => {
Cookies.set("consent", "false", { expires: 30 });
setUserHasConsented(false);
};
return (
<ConsentContext.Provider
value={{ userHasConsented, allowCookies, declineCookies }}
>
{children}
</ConsentContext.Provider>
);
}