Files
plimi/src/core/privacy/analytics-consent-context.ts
2026-06-07 17:43:45 +02:00

26 lines
667 B
TypeScript

import { createContext, useContext } from "react";
export type ConsentChoice = "pending" | "granted" | "denied";
export interface AnalyticsConsentValue {
choice: ConsentChoice;
isSettingsOpen: boolean;
accept: () => void;
reject: () => void;
openSettings: () => void;
closeSettings: () => void;
}
export const AnalyticsConsentContext =
createContext<AnalyticsConsentValue | null>(null);
export function useAnalyticsConsent(): AnalyticsConsentValue {
const context = useContext(AnalyticsConsentContext);
if (!context) {
throw new Error(
"useAnalyticsConsent must be used inside AnalyticsConsentProvider."
);
}
return context;
}