Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+77
@@ -0,0 +1,77 @@
|
||||
import { useLocation, useSearchParams, useSubmit } from "react-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { allCookieCategories } from "~/application/cookies/ApplicationCookies";
|
||||
import { CookieCategory } from "~/application/cookies/CookieCategory";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import CookieHelper from "~/utils/helpers/CookieHelper";
|
||||
import CookiesList from "./CookiesList";
|
||||
import { Button } from "../ui/button";
|
||||
|
||||
interface Props {
|
||||
onUpdated?: () => void;
|
||||
}
|
||||
export default function CookieConsentSettings({ onUpdated }: Props) {
|
||||
const { t } = useTranslation();
|
||||
let { userSession } = useRootData();
|
||||
const submit = useSubmit();
|
||||
let location = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const [selectedCookies, setSelectedCookies] = useState<CookieCategory[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const initial: CookieCategory[] = [];
|
||||
allCookieCategories.forEach((cookie) => {
|
||||
if (userSession.cookies.find((f) => f.allowed && f.category === CookieCategory[cookie])) {
|
||||
initial.push(cookie);
|
||||
}
|
||||
});
|
||||
setSelectedCookies(initial);
|
||||
}, [userSession.cookies]);
|
||||
|
||||
function setCookies(selectedCookies: CookieCategory[]) {
|
||||
const form = CookieHelper.getUpdateCookieConsentForm({ selectedCookies, location, searchParams });
|
||||
submit(form, { method: "post", action: "/preferences", preventScrollReset: true });
|
||||
if (onUpdated) {
|
||||
onUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
function toggle(category: CookieCategory) {
|
||||
if (selectedCookies.includes(category)) {
|
||||
setSelectedCookies(selectedCookies.filter((f) => f !== category));
|
||||
} else {
|
||||
setSelectedCookies([...selectedCookies, category]);
|
||||
}
|
||||
}
|
||||
function deny() {
|
||||
setCookies([CookieCategory.REQUIRED]);
|
||||
}
|
||||
function allowSelected() {
|
||||
setCookies(selectedCookies);
|
||||
}
|
||||
function allowAll() {
|
||||
setCookies(allCookieCategories);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="font-extrabold">{t("cookies.settings")}</div>
|
||||
|
||||
<CookiesList selectedCookies={selectedCookies} toggle={toggle} />
|
||||
|
||||
<div className="grid gap-2 sm:grid-cols-3">
|
||||
<Button variant="outline" onClick={deny}>
|
||||
{t("shared.deny")}
|
||||
</Button>
|
||||
<Button variant="outline" onClick={allowSelected}>
|
||||
{t("shared.allowSelected")}
|
||||
</Button>
|
||||
<Button variant="outline" type="button" onClick={allowAll}>
|
||||
{t("shared.allowAll")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user