diff --git a/apps/web/app/hooks/features/useStartStopTimerHandler.ts b/apps/web/app/hooks/features/useStartStopTimerHandler.ts index 48c5d74f8..449f888fb 100644 --- a/apps/web/app/hooks/features/useStartStopTimerHandler.ts +++ b/apps/web/app/hooks/features/useStartStopTimerHandler.ts @@ -15,6 +15,12 @@ export function useStartStopTimerHandler() { openModal: openEnforcePlannedTaskModal } = useModal(); + const { + isOpen: isEnforceTaskSoftModalOpen, + closeModal: _enforceTaskSoftCloseModal, + openModal: openEnforcePlannedTaskSoftModal + } = useModal(); + const { isOpen: isDailyPlanWorkHoursModalOpen, closeModal: dailyPlanWorkHoursCloseModal, @@ -54,6 +60,11 @@ export function useStartStopTimerHandler() { [activeTeamTask?.id, hasPlan?.tasks] ); + const enforceTaskSoftCloseModal = () => { + _enforceTaskSoftCloseModal(); + openAddTasksEstimationHoursModal(); + }; + const startStopTimerHandler = useCallback(() => { const currentDate = new Date().toISOString().split('T')[0]; const dailyPlanSuggestionModalDate = window && window?.localStorage.getItem(DAILY_PLAN_SUGGESTION_MODAL_DATE); @@ -61,6 +72,26 @@ export function useStartStopTimerHandler() { const dailyPlanEstimateHoursModalDate = window && window?.localStorage.getItem(DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE); + /** + * Check if the active task is planned + * If not, ask the user to add it to the today plan + */ + const handleCheckSelectedTaskOnTodayPlan = () => { + if (hasPlan) { + if (isActiveTaskPlaned) { + if (tasksEstimateHoursModalDate != currentDate) { + openAddTasksEstimationHoursModal(); + } else { + startTimer(); + } + } else { + openEnforcePlannedTaskSoftModal(); + } + } else { + startTimer(); + } + }; + /** * Handle missing working hour for a daily plan */ @@ -81,7 +112,9 @@ export function useStartStopTimerHandler() { */ const handleMissingTasksEstimationHours = () => { if (hasPlan) { - if (areAllTasksEstimated) { + if (tasksEstimateHoursModalDate != currentDate) { + handleCheckSelectedTaskOnTodayPlan(); + } else if (areAllTasksEstimated) { if (dailyPlanEstimateHoursModalDate != currentDate) { handleMissingDailyPlanWorkHour(); } else { @@ -149,6 +182,7 @@ export function useStartStopTimerHandler() { openAddDailyPlanWorkHoursModal, openAddTasksEstimationHoursModal, openEnforcePlannedTaskModal, + openEnforcePlannedTaskSoftModal, openSuggestDailyPlanModal, requirePlan, startTimer, @@ -170,7 +204,10 @@ export function useStartStopTimerHandler() { openAddTasksEstimationHoursModal, isSuggestDailyPlanModalOpen, suggestDailyPlanCloseModal, - openSuggestDailyPlanModal + openSuggestDailyPlanModal, + isEnforceTaskSoftModalOpen, + enforceTaskSoftCloseModal, + openEnforcePlannedTaskSoftModal }, startStopTimerHandler }; diff --git a/apps/web/components/shared/timer/timer-card.tsx b/apps/web/components/shared/timer/timer-card.tsx index 985053ddb..797408b31 100644 --- a/apps/web/components/shared/timer/timer-card.tsx +++ b/apps/web/components/shared/timer/timer-card.tsx @@ -9,7 +9,8 @@ import { PlayIcon } from '@components/ui/svgs/play-icon'; import { AddTasksEstimationHoursModal, AddDailyPlanWorkHourModal, - EnforcePlanedTaskModal + EnforcePlanedTaskModal, + SuggestDailyPlanModal } from 'lib/features/daily-plan'; import { useTranslations } from 'next-intl'; import { useMemo } from 'react'; @@ -22,7 +23,8 @@ const Timer = () => { timerStatusFetching, canRunTimer, hasPlan, - timerSeconds + timerSeconds, + startTimer } = useTimer(); const { activeTaskEstimation } = useTaskStatistics(timerSeconds); @@ -49,6 +51,25 @@ const Timer = () => { > {timerStatus?.running ? : } + + + + {/** + * Track time on planned task (SOFT FLOW) + */} + {hasPlan && activeTeamTask && ( + + )} + {hasPlan && hasPlan.tasks && ( { /> )} + {/** + * Track time on planned task (REQUIRE PLAN) + */} + {requirePlan && hasPlan && activeTeamTask && ( void; task: ITeamTask; plan: IDailyPlan; + content: ReactNode; + onOK?: () => void; } export function EnforcePlanedTaskModal(props: IEnforcePlannedTaskModalProps) { - const { closeModal, task, open, plan } = props; - const t = useTranslations(); + const { closeModal, task, open, plan, content, onOK } = props; const { addTaskToPlan, addTaskToPlanLoading } = useDailyPlan(); - const { startTimer } = useTimerView(); const { user } = useAuthenticateUser(); const handleAddTaskToPlan = useCallback(() => { if (user?.employee && task && plan.id) { addTaskToPlan({ employeeId: user.employee.id, taskId: task.id }, plan.id).then(() => { closeModal(); - startTimer(); + onOK?.(); }); } - }, [addTaskToPlan, closeModal, plan.id, startTimer, task, user?.employee]); + }, [addTaskToPlan, closeModal, onOK, plan.id, task, user?.employee]); return (
- {t('dailyPlan.SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN')} + {content}