Skip to content

Commit 962ebc9

Browse files
committed
refactor: reactively add name change banner
1 parent f95cbaa commit 962ebc9

2 files changed

Lines changed: 33 additions & 24 deletions

File tree

frontend/src/ts/auth.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import {
2323
signInWithPopup,
2424
resetIgnoreAuthCallback,
2525
} from "./firebase";
26-
import { showPopup } from "./modals/simple-modals-base";
2726
import * as Sentry from "./sentry";
28-
import { addBanner } from "./states/banners";
2927
import { showLoaderBar, hideLoaderBar } from "./states/loader-bar";
3028
import {
3129
showNoticeNotification,
@@ -75,28 +73,6 @@ async function getDataAndInit(): Promise<boolean> {
7573
}
7674

7775
void Sentry.setUser(snapshot.uid, snapshot.name);
78-
if (snapshot.needsToChangeName) {
79-
addBanner({
80-
level: "error",
81-
icon: "fas fa-exclamation-triangle",
82-
customContent: (
83-
<>
84-
You need to update your account name.{" "}
85-
<button
86-
type="button"
87-
class="px-2 py-1"
88-
onClick={() => {
89-
showPopup("updateName");
90-
}}
91-
>
92-
Click here
93-
</button>{" "}
94-
to change it and learn more about why.
95-
</>
96-
),
97-
important: true,
98-
});
99-
}
10076

10177
await updateConfigFromServer();
10278
return true;

frontend/src/ts/components/layout/overlays/Banners.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import { debounce } from "throttle-debounce";
33

44
import { createEffectOn } from "../../../hooks/effects";
55
import { useRefWithUtils } from "../../../hooks/useRefWithUtils";
6+
import { showPopup } from "../../../modals/simple-modals-base";
67
import {
78
Banner as BannerType,
9+
addBanner,
810
getBanners,
911
removeBanner,
1012
} from "../../../states/banners";
1113
import { setGlobalOffsetTop } from "../../../states/core";
14+
import { getSnapshot } from "../../../states/snapshot";
1215
import { cn } from "../../../utils/cn";
1316
import { Conditional } from "../../common/Conditional";
1417
import { Fa } from "../../common/Fa";
@@ -78,6 +81,36 @@ function Banner(props: BannerType): JSXElement {
7881
export function Banners(): JSXElement {
7982
const [ref, element] = useRefWithUtils();
8083

84+
let nameChangeAdded = false;
85+
createEffectOn(
86+
() => getSnapshot()?.needsToChangeName,
87+
(needsToChange) => {
88+
if (needsToChange && !nameChangeAdded) {
89+
nameChangeAdded = true;
90+
addBanner({
91+
level: "error",
92+
icon: "fas fa-exclamation-triangle",
93+
customContent: (
94+
<>
95+
You need to update your account name.{" "}
96+
<button
97+
type="button"
98+
class="px-2 py-1"
99+
onClick={() => {
100+
showPopup("updateName");
101+
}}
102+
>
103+
Click here
104+
</button>{" "}
105+
to change it and learn more about why.
106+
</>
107+
),
108+
important: true,
109+
});
110+
}
111+
},
112+
);
113+
81114
const setGlobalOffsetSignal = (): void => {
82115
const height = element()?.getOffsetHeight() ?? 0;
83116
setGlobalOffsetTop(height);

0 commit comments

Comments
 (0)