From 78df680548f8658a2dde156a833ee78f6bdcc3d6 Mon Sep 17 00:00:00 2001 From: "Thierry CH." Date: Thu, 19 Sep 2024 18:52:14 +0200 Subject: [PATCH] feat: disable actions on all past plans (#3050) --- .../add-task-estimation-hours-modal.tsx | 207 ++++++++++++------ 1 file changed, 141 insertions(+), 66 deletions(-) diff --git a/apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx b/apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx index 116f58b74..8d57812f8 100644 --- a/apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx +++ b/apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx @@ -20,6 +20,7 @@ import { TaskDetailsModal } from './task-details-modal'; import { Popover, Transition } from '@headlessui/react'; import { ScrollArea, ScrollBar } from '@components/ui/scroll-bar'; import { Cross2Icon } from '@radix-ui/react-icons'; +import { checkPastDate } from 'lib/utils'; /** * A modal that allows user to add task estimation / planned work time, etc. @@ -58,6 +59,15 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa const currentDate = useMemo(() => new Date().toISOString().split('T')[0], []); const requirePlan = useMemo(() => activeTeam?.requirePlanToTrack, [activeTeam?.requirePlanToTrack]); const tasksEstimationTimes = useMemo(() => estimatedTotalTime(plan.tasks).timesEstimated / 3600, [plan.tasks]); + const totalWorkedTime = useMemo( + () => + plan.tasks?.reduce((acc, cur) => { + const totalWorkedTime = cur.totalWorkedTime ?? 0; + + return acc + totalWorkedTime; + }, 0), + [plan] + ); const [warning, setWarning] = useState(''); const [loading, setLoading] = useState(false); const [defaultTask, setDefaultTask] = useState(null); @@ -261,44 +271,76 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa selectedPlan={plan} /> ) : ( -
- - {t('timer.todayPlanSettings.WORK_TIME_PLANNED')} * - -
- { - !isNaN(parseInt(e.target.value)) - ? setWorkTimePlanned(parseInt(e.target.value)) - : setWorkTimePlanned(0); - }} - required - noWrapper - min={0} - value={ - !isNaN(workTimePlanned) && workTimePlanned.toString() !== '0' - ? workTimePlanned.toString().replace(/^0+/, '') - : isWorkingTimeInputFocused - ? '' - : 0 - } - onFocus={() => setWorkingTimeInputFocused(true)} - onBlur={() => setWorkingTimeInputFocused(false)} - defaultValue={plan.workTimePlanned ? parseInt(plan.workTimePlanned.toString()) : 0} - /> - +
+
+ {checkPastDate(plan.date) ? ( + {t('dailyPlan.PLANNED_TIME')} + ) : ( + + {t('timer.todayPlanSettings.WORK_TIME_PLANNED')}{' '} + * + + )} +
+ {checkPastDate(plan.date) ? ( +
+ {formatIntegerToHour(tasksEstimationTimes)} +
+ ) : ( + { + !isNaN(parseInt(e.target.value)) + ? setWorkTimePlanned(parseInt(e.target.value)) + : setWorkTimePlanned(0); + }} + required + noWrapper + min={0} + value={ + !isNaN(workTimePlanned) && workTimePlanned.toString() !== '0' + ? workTimePlanned.toString().replace(/^0+/, '') + : isWorkingTimeInputFocused + ? '' + : 0 + } + onFocus={() => setWorkingTimeInputFocused(true)} + onBlur={() => setWorkingTimeInputFocused(false)} + defaultValue={ + plan.workTimePlanned ? parseInt(plan.workTimePlanned.toString()) : 0 + } + readOnly={checkPastDate(plan.date)} + /> + )} + + {!checkPastDate(plan.date) && ( + + )} +
+ {checkPastDate(plan.date) && ( +
+ Tracked time +
+ {formatIntegerToHour(totalWorkedTime ?? 0)} +
+
+ )}
)} @@ -308,10 +350,14 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
{t('task.TITLE_PLURAL')} - * + {!checkPastDate(plan.date) && *}
- {t('dailyPlan.TOTAL_ESTIMATED')} : + {checkPastDate(plan.date) ? ( + {t('dailyPlan.ESTIMATED')} : + ) : ( + {t('dailyPlan.TOTAL_ESTIMATED')} : + )} {formatIntegerToHour(tasksEstimationTimes)}
@@ -333,7 +379,7 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
- {warning && ( + {!checkPastDate(plan.date) && warning && ( <> {warning} @@ -584,6 +630,8 @@ function TaskCard(props: ITaskCardProps) { const t = useTranslations(); + const status = useTaskStatus(); + /** * The function that adds the task to the selected plan */ @@ -599,11 +647,13 @@ function TaskCard(props: ITaskCardProps) { } }, [addTaskToPlan, plan.id, task.id]); + console.log(status.taskStatus); + return (