}>
-
diff --git a/src/components/UserSettings/UserSettings.tsx b/src/components/UserSettings/UserSettings.tsx
index 8d6f69e0f5..7d23e8a093 100644
--- a/src/components/UserSettings/UserSettings.tsx
+++ b/src/components/UserSettings/UserSettings.tsx
@@ -13,16 +13,15 @@ import {
import { enqueueSnackbar } from "notistack";
import { FormEvent, Fragment, ReactElement, useState } from "react";
import { useTranslation } from "react-i18next";
-import { show } from "vanilla-cookieconsent";
import { OffOnSetting, User } from "api/models";
import { isEmailTaken, updateUser } from "backend";
import { getAvatar, getCurrentUser } from "backend/localStorage";
+import AnalyticsConsent from "components/AnalyticsConsent";
import { asyncLoadSemanticDomains } from "components/Project/ProjectActions";
import ClickableAvatar from "components/UserSettings/ClickableAvatar";
import { updateLangFromUser } from "i18n";
-import { useAppDispatch, useAppSelector } from "rootRedux/hooks";
-import { StoreState } from "rootRedux/types";
+import { useAppDispatch } from "rootRedux/hooks";
import theme from "types/theme";
import { uiWritingSystems } from "types/writingSystem";
@@ -58,13 +57,11 @@ export function UserSettings(props: {
}): ReactElement {
const dispatch = useAppDispatch();
- const analyticsConsent = useAppSelector(
- (state: StoreState) => state.analyticsState.consent
- );
-
const [name, setName] = useState(props.user.name);
const [phone, setPhone] = useState(props.user.phone);
const [email, setEmail] = useState(props.user.email);
+ const [displayConsent, setDisplayConsent] = useState(false);
+ const [analyticsOn, setAnalyticsOn] = useState(props.user.analyticsOn);
const [uiLang, setUiLang] = useState(props.user.uiLang ?? "");
const [glossSuggestion, setGlossSuggestion] = useState(
props.user.glossSuggestion
@@ -80,10 +77,16 @@ export function UserSettings(props: {
return unchanged || !(await isEmailTaken(unicodeEmail));
}
+ const handleConsentChange = (consentVal?: boolean): void => {
+ setAnalyticsOn(consentVal ?? analyticsOn);
+ setDisplayConsent(false);
+ };
+
const disabled =
name === props.user.name &&
phone === props.user.phone &&
punycode.toUnicode(email) === props.user.email &&
+ analyticsOn === props.user.analyticsOn &&
uiLang === (props.user.uiLang ?? "") &&
glossSuggestion === props.user.glossSuggestion;
@@ -95,6 +98,7 @@ export function UserSettings(props: {
name,
phone,
email: punycode.toUnicode(email),
+ analyticsOn,
uiLang,
glossSuggestion,
hasAvatar: !!avatar,
@@ -286,20 +290,29 @@ export function UserSettings(props: {
{t(
- analyticsConsent
+ analyticsOn
? "userSettings.analyticsConsent.consentYes"
: "userSettings.analyticsConsent.consentNo"
)}
+
+
+
+ {displayConsent && (
+
+ )}
diff --git a/src/cookies/CookieConsent.tsx b/src/cookies/CookieConsent.tsx
deleted file mode 100644
index 613f6f6ea7..0000000000
--- a/src/cookies/CookieConsent.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import { Fragment, type ReactElement } from "react";
-
-import useCookieConsent from "cookies/useCookieConsent";
-
-/** Empty component for running useCookieConsent within a ,
- * because it depends on i18n localization loading first. */
-export default function CookieConsent(): ReactElement {
- useCookieConsent();
- return ;
-}
diff --git a/src/cookies/cc.css b/src/cookies/cc.css
deleted file mode 100644
index 39a08b42bd..0000000000
--- a/src/cookies/cc.css
+++ /dev/null
@@ -1,12 +0,0 @@
-#cc-main {
- --primary: #1e88e5; /* themeColors.primary: blue[600] */
- --dark-shade: #0d47a1; /* themeColors.darkShade: blue[900] */
-
- --cc-btn-primary-bg: var(--primary);
- --cc-btn-primary-border-color: var(--primary);
- --cc-btn-primary-hover-bg: var(--dark-shade);
- --cc-btn-primary-hover-border-color: var(--dark-shade);
- --cc-font-family: "Noto Sans", "Open Sans", Roboto, Helvetica, Arial, sans-serif;
- --cc-primary-color: var(--primary);
- --cc-secondary-color: #000000
-}
diff --git a/src/cookies/useCookieConsent.tsx b/src/cookies/useCookieConsent.tsx
deleted file mode 100644
index 5469409426..0000000000
--- a/src/cookies/useCookieConsent.tsx
+++ /dev/null
@@ -1,55 +0,0 @@
-import { useCallback, useEffect } from "react";
-import { useTranslation } from "react-i18next";
-import { eraseCookies, run } from "vanilla-cookieconsent";
-
-import "vanilla-cookieconsent/dist/cookieconsent.css";
-import "cookies/cc.css";
-
-import { useAppDispatch } from "rootRedux/hooks";
-import { updateConsent } from "types/Redux/analytics";
-
-export default function useCookieConsent(): void {
- const dispatch = useAppDispatch();
- const { t } = useTranslation();
-
- const updateAnalytics = useCallback(
- (param: { cookie: CookieConsent.CookieValue }): void => {
- console.info("C is for Cookie...");
- dispatch(updateConsent());
- if (!param.cookie.categories.includes("analytics")) {
- eraseCookies(/^(?!cookie_consent$)/); // Only keep cookie with name "cookie_consent"
- }
- },
- [dispatch]
- );
-
- useEffect(() => {
- run({
- categories: { analytics: {}, necessary: {} },
- cookie: { expiresAfterDays: 365, name: "cookie_consent" },
- guiOptions: { consentModal: { layout: "bar inline" } },
- language: {
- default: "i18n",
- translations: {
- i18n: {
- consentModal: {
- acceptAllBtn: t(
- "userSettings.analyticsConsent.consentModal.acceptAllBtn"
- ),
- acceptNecessaryBtn: t(
- "userSettings.analyticsConsent.consentModal.acceptNecessaryBtn"
- ),
- description: t(
- "userSettings.analyticsConsent.consentModal.description"
- ),
- title: t("userSettings.analyticsConsent.consentModal.title"),
- },
- preferencesModal: { sections: [] },
- },
- },
- },
- onChange: updateAnalytics,
- onFirstConsent: updateAnalytics,
- }).then(() => dispatch(updateConsent()));
- }, [dispatch, t, updateAnalytics]);
-}