Skip to content

Commit

Permalink
refactor/cookie-menu
Browse files Browse the repository at this point in the history
Refactors cookie components and context to make it easier to manage
in the future.
  • Loading branch information
rikhall1515 authored May 5, 2024
2 parents e32083e + e38ee14 commit ed5c163
Show file tree
Hide file tree
Showing 24 changed files with 584 additions and 730 deletions.
5 changes: 4 additions & 1 deletion app/(private)/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import Sidebar from "@/app/(private)/_components/sidebar";
import CookieBanner from "@/components/cookies";
import CookieContextProvider from "@/context/cookie";
import { useDashboardContext } from "@/context/dashboard";
import { cn } from "@/lib/utils";
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
Expand All @@ -17,7 +18,9 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
>
{children}
</main>
<CookieBanner />
<CookieContextProvider>
<CookieBanner />
</CookieContextProvider>
</>
);
}
7 changes: 5 additions & 2 deletions app/(public)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import CookieBanner from "@/components/cookies";
import Footer from "@/components/footer";
import Header from "@/components/header";
import CookieContextProvider from "@/context/cookie";

export default function PublicLayout({ children }: { children: React.ReactNode }) {
return (
<>
<Header />
<main id="content">{children}</main>
<Footer />
<CookieBanner />
<CookieContextProvider>
<Footer />
<CookieBanner />
</CookieContextProvider>
</>
);
}
8 changes: 1 addition & 7 deletions components/cookies/changeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default function ChangeMenu() {
onClick={() => {
cookie.toggleSelectCookies(false, false, false, false);
resetCookieConsentValue();
cookie.toggleChangeConsentMenu();
}}
variant="outline"
>
Expand All @@ -90,13 +91,6 @@ export default function ChangeMenu() {
onClick={() => {
cookie.toggleChangeConsentMenu();
cookie.toggleManageConsentMenu();
cookie.toggleSelectCookies(
cookie.preferences,
cookie.analytics,
cookie.advertising,
false
);
resetCookieConsentValue();
}}
>
Change Consent
Expand Down
5 changes: 4 additions & 1 deletion components/cookies/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CookieFormContextProvider from "@/context/cookie/form";
import { cn } from "@/lib/utils";

import ChangeMenu from "./changeMenu";
Expand All @@ -8,7 +9,9 @@ export default function CookieTray() {
return (
<>
<div className={cn("transition-all")}>
<ManageConsent />
<CookieFormContextProvider>
<ManageConsent />
</CookieFormContextProvider>
<ChangeMenu />
<CookieToast />
</div>
Expand Down
26 changes: 0 additions & 26 deletions components/cookies/manage/about.tsx

This file was deleted.

19 changes: 5 additions & 14 deletions components/cookies/manage/buttons.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
"use client";
import type { UseFormSetValue } from "react-hook-form";

import { Button } from "@/components/ui/button";
import { useCookieContext } from "@/context/cookie";
import { useCookieFormContext } from "@/context/cookie/form";

type CookieInputs = {
necessary: boolean;
preferences: boolean;
analytics: boolean;
advertising: boolean;
};

type ButtonProps = {
setValue: UseFormSetValue<CookieInputs>;
};

export function DenyAll({ setValue }: ButtonProps) {
export function DenyAll() {
const cookieStore = useCookieContext();
const { setValue } = useCookieFormContext();
return (
<>
<Button
Expand All @@ -38,8 +28,9 @@ export function DenyAll({ setValue }: ButtonProps) {
);
}

export function AcceptAll({ setValue }: ButtonProps) {
export function AcceptAll() {
const cookieStore = useCookieContext();
const { setValue } = useCookieFormContext();
return (
<>
<Button
Expand Down
124 changes: 0 additions & 124 deletions components/cookies/manage/consent.tsx

This file was deleted.

Loading

0 comments on commit ed5c163

Please sign in to comment.