From 999f3ce044fd06d363dae0c5fa297ae61c39bd10 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Fri, 23 Aug 2024 10:46:53 +0200 Subject: [PATCH] feat: add planned vs estimations check & warnings --- .../add-task-estimation-hours-modal.tsx | 70 +++++++++++++------ apps/web/locales/ar.json | 4 +- apps/web/locales/bg.json | 4 +- apps/web/locales/de.json | 4 +- apps/web/locales/en.json | 4 +- apps/web/locales/es.json | 4 +- apps/web/locales/fr.json | 4 +- apps/web/locales/he.json | 4 +- apps/web/locales/it.json | 4 +- apps/web/locales/nl.json | 4 +- apps/web/locales/pl.json | 4 +- apps/web/locales/pt.json | 4 +- apps/web/locales/ru.json | 4 +- apps/web/locales/zh.json | 4 +- 14 files changed, 86 insertions(+), 36 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 04a70aafb..c49e2d8b2 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.toFixed(1)} + {' h'} + +
+
{sortedTasks.map((task, index) => ( ))}
-
+
{warning && ( <> - -

{warning}

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