Skip to content

Commit

Permalink
Set an analytics prop on User based on analytics consent state
Browse files Browse the repository at this point in the history
  • Loading branch information
andracc committed Dec 4, 2024
1 parent 55384c3 commit 9e14a13
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
7 changes: 7 additions & 0 deletions Backend/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class User
[BsonElement("username")]
public string Username { get; set; }

[BsonElement("otelConsent")]
public bool OtelConsent { get; set; }

[BsonElement("uiLang")]
public string UILang { get; set; }

Expand Down Expand Up @@ -97,6 +100,7 @@ public User()
Agreement = false;
Password = "";
Username = "";
OtelConsent = false;
UILang = "";
GlossSuggestion = AutocompleteSetting.On;
Token = "";
Expand All @@ -119,6 +123,7 @@ public User Clone()
Agreement = Agreement,
Password = Password,
Username = Username,
OtelConsent = OtelConsent,
UILang = UILang,
GlossSuggestion = GlossSuggestion,
Token = Token,
Expand All @@ -141,6 +146,7 @@ public bool ContentEquals(User other)
other.Agreement == Agreement &&
other.Password.Equals(Password, StringComparison.Ordinal) &&
other.Username.Equals(Username, StringComparison.Ordinal) &&
other.OtelConsent == OtelConsent &&
other.UILang.Equals(UILang, StringComparison.Ordinal) &&
other.GlossSuggestion.Equals(GlossSuggestion) &&
other.Token.Equals(Token, StringComparison.Ordinal) &&
Expand Down Expand Up @@ -178,6 +184,7 @@ public override int GetHashCode()
hash.Add(Agreement);
hash.Add(Password);
hash.Add(Username);
hash.Add(OtelConsent);
hash.Add(UILang);
hash.Add(GlossSuggestion);
hash.Add(Token);
Expand Down
1 change: 1 addition & 0 deletions Backend/Repositories/UserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public async Task<ResultOfUpdate> Update(string userId, User user, bool updateIs
.Set(x => x.ProjectRoles, user.ProjectRoles)
.Set(x => x.Agreement, user.Agreement)
.Set(x => x.Username, user.Username)
.Set(x => x.OtelConsent, user.OtelConsent)
.Set(x => x.UILang, user.UILang)
.Set(x => x.GlossSuggestion, user.GlossSuggestion);

Expand Down
18 changes: 12 additions & 6 deletions src/api/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export interface User {
* @memberof User
*/
username: string;
/**
*
* @type {boolean}
* @memberof User
*/
otelConsent?: boolean;
/**
*
* @type {string}
Expand All @@ -100,20 +106,20 @@ export interface User {
uiLang?: string | null;
/**
*
* @type {string}
* @type {AutocompleteSetting}
* @memberof User
*/
token: string;
glossSuggestion: AutocompleteSetting;
/**
*
* @type {boolean}
* @type {string}
* @memberof User
*/
isAdmin: boolean;
token: string;
/**
*
* @type {AutocompleteSetting}
* @type {boolean}
* @memberof User
*/
glossSuggestion: AutocompleteSetting;
isAdmin: boolean;
}
9 changes: 8 additions & 1 deletion src/components/UserSettings/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Typography,
} from "@mui/material";
import { enqueueSnackbar } from "notistack";
import { FormEvent, Fragment, ReactElement, useState } from "react";
import { FormEvent, Fragment, ReactElement, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { show } from "vanilla-cookieconsent";

Expand Down Expand Up @@ -65,6 +65,7 @@ export function UserSettings(props: {
const [name, setName] = useState(props.user.name);
const [phone, setPhone] = useState(props.user.phone);
const [email, setEmail] = useState(props.user.email);
const [otelConsent, setOtelConsent] = useState(analyticsConsent);
const [uiLang, setUiLang] = useState(props.user.uiLang ?? "");
const [glossSuggestion, setGlossSuggestion] = useState(
props.user.glossSuggestion
Expand All @@ -80,10 +81,15 @@ export function UserSettings(props: {
return unchanged || !(await isEmailTaken(unicodeEmail));
}

useEffect(() => {
setOtelConsent(analyticsConsent);
}, [analyticsConsent]);

const disabled =
name === props.user.name &&
phone === props.user.phone &&
punycode.toUnicode(email) === props.user.email &&
otelConsent === props.user.otelConsent &&
uiLang === (props.user.uiLang ?? "") &&
glossSuggestion === props.user.glossSuggestion;

Expand All @@ -95,6 +101,7 @@ export function UserSettings(props: {
name,
phone,
email: punycode.toUnicode(email),
otelConsent,
uiLang,
glossSuggestion,
hasAvatar: !!avatar,
Expand Down

0 comments on commit 9e14a13

Please sign in to comment.