Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

feat: cookie consent banner (#800)

Gerardoe8c527222c22
diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx
index dd89a5e9..5ab81ef0 100644
--- a/apps/web/src/app/layout.tsx
+++ b/apps/web/src/app/layout.tsx
@@ -8,6 +8,7 @@ import { Toaster } from '@repo/ui/components/toaster';
import { Providers } from './providers';
import { buildMetaForDefault } from './metadata';
import { Navigation } from '~/components/navigation';
+import { CookieBanner } from '~/components/cookie-banner';
const inter = Inter({ subsets: ['latin'] });
@@ -34,6 +35,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<Navigation />
<main className="flex-1">{children}</main>
<Toaster />
+ <CookieBanner />
</Providers>
<Analytics />
</body>
diff --git a/apps/web/src/components/cookie-banner.tsx b/apps/web/src/components/cookie-banner.tsx
new file mode 100644
index 00000000..f5506aa9
--- /dev/null
+++ b/apps/web/src/components/cookie-banner.tsx
@@ -0,0 +1,36 @@
+'use client';
+
+import { useEffect, useState } from 'react';
+import { Button } from '@repo/ui/components/button';
+import { useLocalStorage } from '~/utils/useLocalStorage';
+
+export const CookieBanner = () => {
+ const [mounted, setMounted] = useState(false);
+ const [showCookieBanner, setShowCookieBanner] = useLocalStorage('cookie-banner', 'true');
+
+ useEffect(() => {
+ setMounted(true);
+ }, []);
+
+ if (!mounted || showCookieBanner === 'false') {
+ return null;
+ }
+
+ return (
+ <div className="animate-in fade-in bg-background fixed bottom-0 right-0 z-[999] flex w-full flex-col gap-2 rounded-b-none rounded-t-2xl border p-4 sm:bottom-2 sm:right-2 sm:w-[330px] sm:rounded-2xl">
+ <div className="text-center text-xl font-semibold">TypeHero Uses Cookies 🍪</div>
+ <div className="text-sm">
+ We use cookies to improve your experience. By using TypeHero, you consent to our use of
+ cookies.
+ </div>
+ <div className="flex gap-2 self-end">
+ <Button variant="outline" size="sm" onClick={() => setShowCookieBanner('false')}>
+ Close
+ </Button>
+ <Button variant="outline" size="sm" onClick={() => setShowCookieBanner('false')}>
+ Ok
+ </Button>
+ </div>
+ </div>
+ );
+};