Skip to content

Commit

Permalink
[TM-1711] add notification open when new reach (#895)
Browse files Browse the repository at this point in the history
* [TM-1711] add notification open when new reach

* [TM-1711] remove log
  • Loading branch information
egrojMonroy authored Feb 7, 2025
1 parent 9f3dcff commit 3ca7081
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/components/elements/Notification/FloatNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LinearProgress } from "@mui/material";
import { useT } from "@transifex/react";
import classNames from "classnames";
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { When } from "react-if";

import Icon, { IconNames } from "@/components/extensive/Icon/Icon";
Expand All @@ -23,10 +23,13 @@ export interface FloatNotificationProps {
}

const FloatNotification = () => {
const firstRender = useRef(true);
const t = useT();
const [openModalNotification, setOpenModalNotification] = useState(false);
const [isLoaded, { delayedJobs }] = useDelayedJobs();
const [notAcknowledgedJobs, setNotAcknowledgedJobs] = useState<DelayedJobDto[]>([]);
const prevDelayedJobsRef = useRef<DelayedJobDto[]>([]);

const clearJobs = () => {
if (delayedJobs === undefined) return;
const newJobsData: DelayedJobData[] = delayedJobs
Expand All @@ -43,10 +46,20 @@ const FloatNotification = () => {
triggerBulkUpdate(newJobsData);
};
useEffect(() => {
if (delayedJobs === undefined) return;
const notAcknowledgedJobs = delayedJobs.filter((job: DelayedJobDto) => !job.isAcknowledged);
setNotAcknowledgedJobs(notAcknowledgedJobs);
if (!delayedJobs) return;
const newJobs = delayedJobs.filter(job => !job.isAcknowledged);
const isNewJob = JSON.stringify(newJobs) !== JSON.stringify(prevDelayedJobsRef.current);

if (isNewJob) {
setNotAcknowledgedJobs(newJobs);
prevDelayedJobsRef.current = newJobs;
if (newJobs.length > notAcknowledgedJobs.length && !firstRender.current) {
setOpenModalNotification(true);
}
firstRender.current = false;
}
}, [delayedJobs]);

useEffect(() => {
if (!notAcknowledgedJobs.length) {
setOpenModalNotification(false);
Expand Down

0 comments on commit 3ca7081

Please sign in to comment.