first
This commit is contained in:
commit
8538ab969a
434 changed files with 44051 additions and 0 deletions
42
apps/web/modules/shared/components/ConsentProvider.tsx
Normal file
42
apps/web/modules/shared/components/ConsentProvider.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue