Skip to content

Commit

Permalink
feat: add planned vs estimations check & warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
CREDO23 committed Aug 23, 2024
1 parent 47f80af commit f490bb6
Showing 1 changed file with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,34 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
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 > 1) {
setWarning('Please add more tasks to the plan');
} else if (tasksEstimationTimes - workTimePlanned > 1) {
setWarning('Total estimated time exceeds your Planned time, please optimize your plan');
} else {
setWarning('');
}
} else {
setWarning(t('dailyPlan.planned_tasks_popup.warning.PLANNED_TIME'));
}
}, [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)) {
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(
Expand Down Expand Up @@ -115,20 +142,29 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
</div>
<div className="text-sm flex flex-col gap-3">
<div className="text-sm flex flex-col gap-3">
<span>
{t('timer.todayPlanSettings.TASKS_WITH_NO_ESTIMATIONS')}{' '}
<span className="text-red-600">*</span>
</span>
<div className="w-full flex items-center justify-between gap-2">
<div className="flex items-center justify-center gap-1">
<span>Tasks</span>
<span className="text-red-600">*</span>
</div>
<div className="flex items-center justify-center gap-1">
<span>Total estimate:</span>
<span className=" font-medium">
{tasksEstimationTimes}
{' h'}
</span>
</div>
</div>
<div className="flex flex-col gap-1">
{sortedTasks.map((task, index) => (
<TaskCard key={index} task={task} />
))}
</div>
</div>
<div className="flex gap-2 items-center h-6 text-red-500">
<div className="flex gap-2 items-center text-sm h-6 text-red-500">
{warning && (
<>
<PiWarningCircleFill className="text-2xl" />
<PiWarningCircleFill />
<p>{warning}</p>
</>
)}
Expand Down Expand Up @@ -174,7 +210,7 @@ function TaskCard({ task }: ITaskCardProps) {
<Card
shadow="custom"
className={clsx(
'lg:flex items-center justify-between py-3 md:px-4 hidden min-h-[4.5rem] w-[30rem] h-[4.5rem] dark:bg-[#1E2025] border-[0.05rem] dark:border-[#FFFFFF0D] relative !text-xs cursor-pointer',
'lg:flex items-center justify-between py-3 md:px-4 hidden min-h-[4.5rem] min-w-[30rem] w-full h-[4.5rem] dark:bg-[#1E2025] border-[0.05rem] dark:border-[#FFFFFF0D] relative !text-xs cursor-pointer',
task.id === activeTeamTask?.id && 'border-primary-light border-[0.15rem]'
)}
onClick={() => setActiveTask(task)}
Expand Down

0 comments on commit f490bb6

Please sign in to comment.