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 04a70aafb..d92c54202 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 @@ -37,13 +37,39 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa const handleCloseModal = useCallback(() => { localStorage.setItem(TASKS_ESTIMATE_HOURS_MODAL_DATE, currentDate); closeModal(); - }, [closeModal, currentDate]); + startTimer(); + }, [closeModal, currentDate, startTimer]); const handleSubmit = useCallback(() => { updateDailyPlan({ workTimePlanned }, plan.id ?? ''); - startTimer(); handleCloseModal(); - }, [handleCloseModal, plan.id, startTimer, updateDailyPlan, workTimePlanned]); + }, [handleCloseModal, plan.id, updateDailyPlan, workTimePlanned]); + + const checkPlannedAndEstimateTimeDiff = useCallback(() => { + if (workTimePlanned) { + if (workTimePlanned > tasksEstimationTimes) { + setWarning(t('dailyPlan.planned_tasks_popup.warning.PLAN_MORE_TASKS')); + } else { + setWarning(t('dailyPlan.planned_tasks_popup.warning.OPTIMIZE_PLAN')); + } + } else { + setWarning(t('dailyPlan.planned_tasks_popup.warning.PLANNED_TIME')); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [tasksEstimationTimes, workTimePlanned]); + + useEffect(() => { + if (!workTimePlanned || workTimePlanned <= 0) { + setWarning(t('dailyPlan.planned_tasks_popup.warning.PLANNED_TIME')); + } else if (plan.tasks?.find((task) => !task.estimate)) { + setWarning(t('dailyPlan.planned_tasks_popup.warning.TASKS_ESTIMATION')); + } else if (Math.abs(workTimePlanned - tasksEstimationTimes) > 1) { + checkPlannedAndEstimateTimeDiff(); + } else { + setWarning(''); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [workTimePlanned, tasksEstimationTimes, plan.tasks, myDailyPlans]); // Put tasks without estimates at the top of the list const sortedTasks = useMemo( @@ -72,21 +98,10 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa // eslint-disable-next-line react-hooks/exhaustive-deps }, [isOpen]); - useEffect(() => { - if (!workTimePlanned || workTimePlanned <= 0) { - setWarning(t('dailyPlan.planned_tasks_popup.warning.PLANNED_TIME')); - } else if (plan.tasks?.find((task) => !task.estimate)) { - setWarning(t('dailyPlan.planned_tasks_popup.warning.TASKS_ESTIMATION')); - } else { - setWarning(''); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [workTimePlanned, tasksEstimationTimes, plan.tasks, myDailyPlans]); - return ( -
+
{t('timer.todayPlanSettings.TITLE')} @@ -115,21 +130,30 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
- - {t('timer.todayPlanSettings.TASKS_WITH_NO_ESTIMATIONS')}{' '} - * - +
+
+ Tasks + * +
+
+ Total estimate: + + {tasksEstimationTimes} + {' h'} + +
+
{sortedTasks.map((task, index) => ( ))}
-
+
{warning && ( <> - -

{warning}

+ + {warning} )}
@@ -174,7 +198,7 @@ function TaskCard({ task }: ITaskCardProps) {