Skip to content

Commit

Permalink
fix: fix the number of outstanding tasks in notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
CREDO23 committed Aug 7, 2024
1 parent 379ab35 commit ce51800
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apps/web/lib/features/team/team-outstanding-notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Tooltip } from 'lib/components';
import { useTranslations } from 'next-intl';
import Link from 'next/link';
import { useEffect, useState } from 'react';
import { estimatedTotalTime } from '../task/daily-plan';

interface IEmployeeWithOutstanding {
employeeId: string | undefined;
Expand All @@ -25,7 +26,7 @@ export function TeamOutstandingNotifications() {
return (
<div className="flex flex-col gap-4">
{outstandingPlans && outstandingPlans.length > 0 && (
<UserOutstandingNotification outstandingTasks={outstandingPlans} user={user} />
<UserOutstandingNotification outstandingPlans={outstandingPlans} user={user} />
)}

{dailyPlan.items && dailyPlan.items.length > 0 && isTeamManager && (
Expand All @@ -35,7 +36,7 @@ export function TeamOutstandingNotifications() {
);
}

function UserOutstandingNotification({ outstandingTasks, user }: { outstandingTasks: IDailyPlan[]; user?: IUser }) {
function UserOutstandingNotification({ outstandingPlans, user }: { outstandingPlans: IDailyPlan[]; user?: IUser }) {
const t = useTranslations();

// Notification will be displayed 6 hours after the user closed it
Expand All @@ -45,7 +46,9 @@ function UserOutstandingNotification({ outstandingTasks, user }: { outstandingTa
const name = user?.name || user?.firstName || user?.lastName || user?.username;

const [visible, setVisible] = useState(false);
const tasks = outstandingTasks.flatMap((plan) => plan.tasks);
const outStandingTasksCount = estimatedTotalTime(
outstandingPlans.map((plan) => plan.tasks?.map((task) => task))
).totalTasks;

useEffect(() => {
const checkNotification = () => {
Expand Down Expand Up @@ -73,7 +76,7 @@ function UserOutstandingNotification({ outstandingTasks, user }: { outstandingTa
{visible && (
<div className="rounded-2xl dark:border-dark--theme-light border py-2 px-6 flex justify-between items-center text-xs mb-2">
<div>
{t('pages.home.OUTSTANDING_NOTIFICATIONS.SUBJECT')} {tasks?.length}{' '}
{t('pages.home.OUTSTANDING_NOTIFICATIONS.SUBJECT')} {outStandingTasksCount}{' '}
{t('pages.home.OUTSTANDING_NOTIFICATIONS.USER_LABEL')}{' '}
<span className="font-medium">
{t('pages.home.OUTSTANDING_NOTIFICATIONS.OUTSTANDING_VIEW')}
Expand Down

0 comments on commit ce51800

Please sign in to comment.