Skip to content

Commit 01165c3

Browse files
Alessandro GasperiniAlessandro Gasperini
authored andcommitted
DIGG 478 Cookie settings link in footer
1 parent 899ec44 commit 01165c3

File tree

7 files changed

+55
-16
lines changed

7 files changed

+55
-16
lines changed

components/global/CookieBanner/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ export type CookieProperties = {
2222
accepted: boolean;
2323
};
2424

25-
export const CookieBanner: FC = () => {
25+
export const CookieBanner: FC<{
26+
settingsOpen: boolean;
27+
setSettingsOpen: Function;
28+
}> = ({ settingsOpen, setSettingsOpen }) => {
2629
const { store, set } = useContext(LocalStoreContext);
2730
const { setActivation } = useContext(TrackingContext);
2831
const { t, lang } = useTranslation();
29-
const [settingsOpen, setSettingsOpen] = useState(false);
3032

3133
const initialCookieSetting: CookieSetting = {
3234
analytic: {

components/layout/Footer/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ import { CustomLink } from "@/components/global/CustomLink";
88
type FooterProps = {
99
openSideBar: boolean;
1010
setOpenSideBar: Function;
11+
setSettingsOpen: Function;
1112
};
1213

13-
export const Footer: FC<FooterProps> = ({ openSideBar, setOpenSideBar }) => {
14+
export const Footer: FC<FooterProps> = ({
15+
openSideBar,
16+
setOpenSideBar,
17+
setSettingsOpen,
18+
}) => {
1419
const { t } = useTranslation();
1520
return (
1621
<footer className="mt-xl border-t-2 border-brown-600 bg-white py-xl">
@@ -20,7 +25,10 @@ export const Footer: FC<FooterProps> = ({ openSideBar, setOpenSideBar }) => {
2025
}`}
2126
>
2227
<Container className="space-y-xl md:space-y-2xl">
23-
<FooterNav setOpenSideBar={setOpenSideBar} />
28+
<FooterNav
29+
setSettingsOpen={setSettingsOpen}
30+
setOpenSideBar={setOpenSideBar}
31+
/>
2432
<div className="flex flex-col justify-between gap-xl align-top md:flex-row md:gap-none">
2533
<div className="mr-lg">
2634
<span className="font-strong">Sveriges dataportal </span>

components/navigation/FooterNav/index.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { Heading } from "@/components/global/Typography/Heading";
44
import { footerNav } from "@/utilities/menuData";
55
import Link from "next/link";
66
import { SettingsContext } from "@/providers/SettingsProvider";
7+
import { LocalStoreContext } from "@/providers/LocalStoreProvider";
78

89
interface FooterNavItem {
910
title: string;
10-
icon: any;
11-
type?: "internal" | "external" | "email";
11+
icon?: any;
12+
type?: "internal" | "external" | "email" | "cookie";
1213
href?: string;
1314
}
1415

@@ -19,11 +20,16 @@ interface FooterNavData {
1920

2021
interface FooterNavProps {
2122
setOpenSideBar: Function;
23+
setSettingsOpen: Function;
2224
}
2325

24-
export const FooterNav: FC<FooterNavProps> = ({ setOpenSideBar }) => {
26+
export const FooterNav: FC<FooterNavProps> = ({
27+
setOpenSideBar,
28+
setSettingsOpen,
29+
}) => {
2530
const { t } = useTranslation();
2631
const { iconSize } = useContext(SettingsContext);
32+
const { set } = useContext(LocalStoreContext);
2733

2834
return (
2935
<nav
@@ -49,13 +55,25 @@ export const FooterNav: FC<FooterNavProps> = ({ setOpenSideBar }) => {
4955
{link.type === "external"
5056
? t(`common|${link.title}`)
5157
: link.title}
52-
<link.icon
53-
className="mb-[2px] ml-xs inline-block [&_path]:fill-green-600"
54-
width={iconSize}
55-
height={iconSize}
56-
viewBox="0 0 24 24"
57-
/>
58+
{link.icon && (
59+
<link.icon
60+
className="mb-[2px] ml-xs inline-block [&_path]:fill-green-600"
61+
width={iconSize}
62+
height={iconSize}
63+
viewBox="0 0 24 24"
64+
/>
65+
)}
5866
</Link>
67+
) : link.type === "cookie" ? (
68+
<button
69+
onClick={() => {
70+
set({ cookieSettings: {} });
71+
setSettingsOpen(true);
72+
}}
73+
className="cursor-pointer underline underline-offset-4 hover:no-underline"
74+
>
75+
{t(`common|${link.title}`)}
76+
</button>
5977
) : (
6078
<Link
6179
href={`/${t(`routes|${link.title}$path`)}`}

locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"lang-path": "/en",
9191
"dataportal": "The Swedish dataportal",
9292
"github": "Open source on GitHub",
93+
"cookie-settings": "Cookie settings",
9394
"feedback": "Feedback on dataportal.se",
9495
"toolbox-share-data": "Toolbox for sharing data",
9596
"documentation-services": "Documentation och services - Sweden's dataportal",

locales/sv/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"training": "Utbildning för chefer och ledare",
9191
"lang-path": "/sv",
9292
"github": "Öppen källkod på GitHub",
93+
"cookie-settings": "Cookie-inställningar",
9394
"feedback": "Feedback på dataportal.se",
9495
"toolbox-share-data": "Verktygslåda för att dela data",
9596
"documentation-services": "Dokumentation och tjänster - Sveriges dataportal",

pages/_app.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function Dataportal({ Component, pageProps }: DataportalenProps) {
7272
const { t, lang } = useTranslation();
7373
// Put shared props into state to persist between pages that doesn't use getStaticProps
7474
const [env, setEnv] = useState<EnvSettings>(SettingsUtil.create());
75+
const [settingsOpen, setSettingsOpen] = useState(false);
7576
const [matomoActivated, setMatomoActivated] = useState<boolean>(true);
7677
const [openSideBar, setOpenSideBar] = useState(false);
7778
const { seo, heading, heroImage, preamble } = resolvePage(
@@ -140,7 +141,10 @@ function Dataportal({ Component, pageProps }: DataportalenProps) {
140141
>
141142
<MetaData seo={seo} />
142143
<div id="scriptsPlaceholder" />
143-
<CookieBanner />
144+
<CookieBanner
145+
settingsOpen={settingsOpen}
146+
setSettingsOpen={setSettingsOpen}
147+
/>
144148
<div
145149
id="top"
146150
className={`relative h-[100dvh] md:h-full ${
@@ -192,6 +196,7 @@ function Dataportal({ Component, pageProps }: DataportalenProps) {
192196
</main>
193197
</div>
194198
<Footer
199+
setSettingsOpen={setSettingsOpen}
195200
setOpenSideBar={setOpenSideBar}
196201
openSideBar={openSideBar}
197202
/>

utilities/menuData.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ interface NavTopData {
3535

3636
interface NavFooterItem {
3737
title: string;
38-
icon: any;
39-
type?: "internal" | "external" | "email";
38+
icon?: any;
39+
type?: "internal" | "external" | "email" | "cookie";
4040
href?: string;
4141
}
4242

@@ -187,6 +187,10 @@ const footerNav: NavFooterData[] = [
187187
type: "external",
188188
icon: externalLinkIcon,
189189
},
190+
{
191+
title: "cookie-settings",
192+
type: "cookie",
193+
},
190194
{
191195
title: "info@digg.se",
192196
href: "mailto:info@digg.se",

0 commit comments

Comments
 (0)