Skip to content

Commit

Permalink
feat: assemble manage consent menu
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhall1515 committed May 3, 2024
1 parent d1788da commit 1e6ec74
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
66 changes: 66 additions & 0 deletions components/cookies/manage/formContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type { Control, FieldErrors, UseFormRegister, UseFormSetValue } from "react-hook-form";

import Logo from "@/components/logo";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";

import AboutTab from "./about";
import { AcceptAll, AcceptSelection, DenyAll } from "./buttons";
import ConsentTab from "./consent";
import DetailsTab from "./details";

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

export default function FormContent({
control,
register,
errors,
isSubmitting,
setValue,
}: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
control: Control<CookieInputs, any>;
register: UseFormRegister<CookieInputs>;
errors: FieldErrors<CookieInputs>;
isSubmitting: boolean;
setValue: UseFormSetValue<CookieInputs>;
}) {
return (
<>
<Logo className="mb-6" />
<Tabs
defaultValue="Consent"
className="flex h-auto w-full flex-col overflow-auto bg-[transparent] py-6 align-baseline"
>
<TabsList className="mx-auto mb-6">
<TabsTrigger value="Consent">Consent</TabsTrigger>
<TabsTrigger value="Details">Details</TabsTrigger>
<TabsTrigger value="About">About</TabsTrigger>
</TabsList>
<ConsentTab
control={control}
errors={errors}
isSubmitting={isSubmitting}
register={register}
/>
<DetailsTab
control={control}
errors={errors}
isSubmitting={isSubmitting}
register={register}
/>
<AboutTab />
</Tabs>
<div className="relative flex w-full flex-shrink-0 flex-col-reverse gap-6 p-6 md:flex-row md:flex-nowrap">
<div className="absolute -top-[4.125rem] left-0 h-16 w-full bg-gradient-to-b from-[transparent] to-background to-50%"></div>
<DenyAll setValue={setValue} />
<AcceptSelection />
<AcceptAll setValue={setValue} />
</div>
</>
);
}
30 changes: 30 additions & 0 deletions components/cookies/manage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";
import TabNav from "@/components/cookies/manage/tabNav";
import { useCookieContext } from "@/context/cookie";
import { cn } from "@/lib/utils";

export default function ManageConsent() {
const cookieStore = useCookieContext();
return (
<>
<div
className={cn(
"cover bottom-[-100%] left-[-100%] right-[-100%] top-[-100%] m-auto h-[100vh] w-full bg-opacity-50 !bg-no-repeat object-cover backdrop-blur backdrop-brightness-50",
"fixed z-40 overflow-hidden bg-black bg-opacity-50",
cookieStore.isManageConsentMenuOpen ? "block" : "hidden"
)}
id="#ManageConsentMenuDialog"
>
<div
className={cn(
" flex flex-col items-center rounded-2xl text-foreground",
"fixed left-1/2 top-1/2 z-[99] box-border -translate-x-1/2 -translate-y-1/2 overflow-hidden",
"h-auto max-h-[calc(100%-16px)] w-[calc(100%-16px)] max-w-[80rem] rounded-2xl bg-background pt-6 shadow transition-all"
)}
>
<TabNav />
</div>
</div>
</>
);
}
53 changes: 53 additions & 0 deletions components/cookies/manage/tabNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use client";
import type { SubmitHandler } from "react-hook-form";
import { useForm } from "react-hook-form";

import FormContent from "@/components/cookies/manage/formContent";
import { useCookieContext } from "@/context/cookie";
import { setCookie } from "@/lib/cookie/utils";

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

export default function TabNav() {
const cookieStore = useCookieContext();
const {
register,
handleSubmit,
control,
setValue,
formState: { errors, isSubmitting },
} = useForm<CookieInputs>({
defaultValues: {
necessary: true,
preferences: cookieStore.preferences,
advertising: cookieStore.advertising,
analytics: cookieStore.analytics,
},
});
const onSubmit: SubmitHandler<CookieInputs> = (data) => {
setCookie(`1:${data.preferences ? 1 : 0}${data.analytics ? 1 : 0}${data.advertising ? 1 : 0}`);
cookieStore.toggleSelectCookies(data.preferences, data.analytics, data.advertising, true);
};
return (
<>
<form
className="flex h-full w-full flex-col items-center overflow-auto bg-[transparent] align-baseline"
onSubmit={handleSubmit(onSubmit)}
id="cookieForm"
>
<FormContent
control={control}
errors={errors}
isSubmitting={isSubmitting}
register={register}
setValue={setValue}
/>
</form>
</>
);
}

0 comments on commit 1e6ec74

Please sign in to comment.