From 8b8ef229682c3f3c28dfe766ff948e4f3b83b2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladan=20Tomi=C4=87?= Date: Wed, 25 Oct 2023 13:36:57 +0200 Subject: [PATCH 1/2] feat: optional matomo --- src/components/Forms/LoginForm/LoginForm.tsx | 28 ++++++++ .../Inputs/CustomCheckbox/CustomCheckbox.tsx | 5 +- src/context/Matomo.tsx | 72 +++++++++++++++++-- src/locales/en-US.json | 3 +- src/pages/_app.tsx | 6 +- 5 files changed, 102 insertions(+), 12 deletions(-) diff --git a/src/components/Forms/LoginForm/LoginForm.tsx b/src/components/Forms/LoginForm/LoginForm.tsx index f4ec46a8..3443a668 100644 --- a/src/components/Forms/LoginForm/LoginForm.tsx +++ b/src/components/Forms/LoginForm/LoginForm.tsx @@ -17,6 +17,16 @@ import { Network } from '@data/networks'; import NetworkDropdown from '@components/Dropdowns/NetworkDropdown/NetworkDropdown'; import { setDefaultNetwork } from '@utils/localStorage'; import { useLocales } from '@context/LocalesContext'; +import CustomCheckbox from '@components/Inputs/CustomCheckbox/CustomCheckbox'; +import { useMatomoContext } from '@context/Matomo'; + +const ALLOW_TRACKING_KEY = 'allow-matomo'; + +function getDefaultTrackingValue(): boolean { + const enabled = localStorage.getItem(ALLOW_TRACKING_KEY); + + return enabled === 'true' || enabled === null ? true : false; +} const LoginForm: FC = () => { const CREATE_USER_URL = process.env.NEXT_PUBLIC_CREATE_ACCOUNT_REDIRECT; @@ -26,8 +36,10 @@ const LoginForm: FC = () => { const { errors, isValid } = formState; const { setUser, errorMessage, setErrorMessage } = useContext(UserContext); + const [allowTracking, setAllowTracking] = useState(getDefaultTrackingValue()); const [network, setNetwork] = useState(getDefaultNetwork()); const [loading, setLoading] = useState(false); + const { setEnabled } = useMatomoContext(); const { fdpClientRef, @@ -46,6 +58,7 @@ const LoginForm: FC = () => { setErrorMessage(null); const { user_name, password } = data; setFdpStorageType('native', network.config); + setEnabled(allowTracking); const wallet = await fdpClientRef.current.account.login( user_name, password @@ -67,6 +80,12 @@ const LoginForm: FC = () => { setNetwork(network); }; + const onAllowTrackingClick = () => { + const enabled = !allowTracking; + setAllowTracking(enabled); + localStorage.setItem(ALLOW_TRACKING_KEY, String(enabled)); + }; + useEffect(() => { setErrorMessage(null); }, []); @@ -154,6 +173,15 @@ const LoginForm: FC = () => { error={errors.password} /> + + {intl.get('ALLOW_TRACKING')} + +
-