Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oy2 31159 - simplify notification logic (#1581) #1582

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions services/ui-src/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const DEFAULT_AUTH_STATE: Omit<

const App = () => {
const [authState, setAuthState] = useState(DEFAULT_AUTH_STATE);
const [notifications, setNotifications] = useState<NotificationType[]>([]);
// mmdlNotification = all notifications
const { mmdlNotification } = useFlags();
const [confirmationDialog, setConfirmationDialog] = useState<{
Expand Down Expand Up @@ -156,7 +157,6 @@ const App = () => {
try {
if (authState.isAuthenticated) {
const email: any = authState.userProfile.email;
let userData: any = authState.userProfile.userData;

let notifications: NotificationType[] = [];
// if notification flag is on, find and display notifications otherwise keep empty array
Expand All @@ -167,37 +167,24 @@ const App = () => {
);
if (
storedNotifications !== undefined &&
storedNotifications?.length &&
storedNotifications.length > 2
storedNotifications?.length
) {
userData.notifications = JSON.parse(storedNotifications);
setNotifications(JSON.parse(storedNotifications));
} else {
// get the notifications & set local storage
notifications = await NotificationsApi.createUserNotifications(
email
);
// set the notifications: Needs to be stored locally to persist on reload
if (notifications) {
userData.notifications = notifications;
localStorage.setItem(
LOCAL_STORAGE_USERNOTIFICATIONS,
JSON.stringify(notifications)
);
setNotifications(notifications);
}
}
}
// set authState userData notifications
setAuthState((prevState) => ({
...prevState,
userProfile: {
...prevState.userProfile,
userData: {
...prevState.userProfile?.userData,
notifications: notifications,
roleList: prevState.userProfile?.userData?.roleList ?? [], // typescript UserProfile type def needs a value
},
},
}));
}
} catch (error) {
console.log("There was an error retreiving notifications.", error);
Expand Down Expand Up @@ -253,17 +240,11 @@ const App = () => {
[authState, setUserInfo, updatePhoneNumber, confirmAction]
);

const notifcations = useMemo(() => {
if (authState.userProfile.userData?.notifications) {
return authState.userProfile.userData?.notifications;
} else return [];
}, [authState.userProfile.userData]);

return authState.isAuthenticating ? null : (
<AppContext.Provider value={contextValue}>
<IdleTimerWrapper />
<div className="header-and-content">
{notifcations.map((n) => (
{notifications.map((n: NotificationType) => (
<NotificationBanner
key={n.sk}
{...n}
Expand Down
Loading