From 6c1e2980fdef8f920242c806bde27f33d29462e7 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Mon, 5 Aug 2024 20:07:24 +0200 Subject: [PATCH] fix: the same task should not be planned multiple times for the same day --- apps/web/lib/features/task/task-card.tsx | 57 ++++++++++++++---------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/apps/web/lib/features/task/task-card.tsx b/apps/web/lib/features/task/task-card.tsx index 197f1dbad..aa2212556 100644 --- a/apps/web/lib/features/task/task-card.tsx +++ b/apps/web/lib/features/task/task-card.tsx @@ -514,16 +514,23 @@ function TaskCardMenu({ const canSeeActivity = useCanSeeActivityScreen(); const { todayPlan, futurePlans } = useDailyPlan(); - const taskPlannedToday = todayPlan[0]?.tasks?.find((_task) => _task.id === task.id); + const taskPlannedToday = useMemo( + () => todayPlan[todayPlan.length - 1]?.tasks?.find((_task) => _task.id === task.id), + [task.id, todayPlan] + ); - const taskPlannedTomorrow = futurePlans - .filter((_plan) => - moment(_plan.date) - .format('YYYY-MM-DD') - ?.toString() - ?.startsWith(moment()?.add(1, 'day').format('YYYY-MM-DD')) - )[0] - ?.tasks?.find((_task) => _task.id === task.id); + const taskPlannedTomorrow = useMemo( + () => + futurePlans + .filter((_plan) => + moment(_plan.date) + .format('YYYY-MM-DD') + ?.toString() + ?.startsWith(moment()?.add(1, 'day').format('YYYY-MM-DD')) + )[0] + ?.tasks?.find((_task) => _task.id === task.id), + [futurePlans, task.id] + ); return ( @@ -575,14 +582,17 @@ function TaskCardMenu({ <>
-
  • - -
  • + {!taskPlannedToday && ( +
  • + +
  • + )} +
  • { @@ -717,12 +727,13 @@ export function PlanTask({ return ( <> - {planMode === 'today' && !taskPlannedToday && ( - - {isPending ? ( + + {isPending || createDailyPlanLoading ? ( ) : ( t('dailyPlan.PLAN_FOR_TODAY') @@ -751,7 +762,7 @@ export function PlanTask({ )} {planMode === 'custom' && t('dailyPlan.PLAN_FOR_SOME_DAY')} - + ); }