Skip to content

Commit

Permalink
Merge pull request #2806 from ever-co/2785-feature-daily-plan--enforc…
Browse files Browse the repository at this point in the history
…ed-plan-should-let-track-time-only-on-planned-task

[Feat] Enforced plan should let track time only on planned task
  • Loading branch information
evereq authored Jul 30, 2024
2 parents b3b6531 + b0199e6 commit fe733a2
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { useAuthenticateUser, useDailyPlan, useTimerView } from '@app/hooks';
import { IDailyPlan, ITeamTask } from '@app/interfaces';
import { Button, Card, Modal, Text } from 'lib/components';
import { useTranslations } from 'next-intl';
import { useCallback } from 'react';

interface IProps {
open: boolean;
closeModal: () => void;
task: ITeamTask;
plan: IDailyPlan;
}

export function EnforcePlanedTaskModal(props: IProps) {
const { closeModal, task, open, plan } = props;
const t = useTranslations();
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();
});
}
}, [addTaskToPlan, closeModal, plan.id, startTimer, task, user?.employee]);

return (
<Modal isOpen={open} closeModal={closeModal} className="w-[98%] md:w-[530px] relative" showCloseIcon={false}>
<Card className="w-full" shadow="custom">
<div className="w-full flex flex-col justify-between gap-6">
<Text.Heading as="h5" className="mb-3 text-center">
{t('dailyPlan.SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN')}
</Text.Heading>
<div className="w-full flex items-center justify-evenly">
<Button
variant="outline"
type="button"
onClick={closeModal}
className="rounded-md font-light text-md dark:text-white dark:bg-slate-700 dark:border-slate-600"
>
No
</Button>
<Button
onClick={handleAddTaskToPlan}
loading={addTaskToPlanLoading}
variant="primary"
type="submit"
className=" rounded-md font-light text-md dark:text-white"
>
Yes
</Button>
</div>
</div>
</Card>
</Modal>
);
}
5 changes: 3 additions & 2 deletions apps/web/lib/features/daily-plan/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './plans-work-time-and-estimate';
export * from './add-task-to-plan';
export * from './daily-plan-compare-estimate-modal'
export * from './create-daily-plan-form-modal'
export * from './daily-plan-compare-estimate-modal';
export * from './create-daily-plan-form-modal';
export * from './daily-plan-enforce-planed-task-modal';
30 changes: 28 additions & 2 deletions apps/web/lib/features/timer/timer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pad } from '@app/helpers';
import { HostKeys, useDetectOS, useHotkeys, useModal, useTimerView } from '@app/hooks';
import { HostKeys, useDetectOS, useHotkeys, useModal, useTeamTasks, useTimerView } from '@app/hooks';
import { IClassName, TimerSource } from '@app/interfaces';
import { clsxm } from '@app/utils';
import { ProgressBar, Text, Tooltip, VerticalSeparator } from 'lib/components';
Expand All @@ -15,12 +15,17 @@ import {
} from '@heroicons/react/24/outline';
import { HotkeysEvent } from 'hotkeys-js';
import { useCallback, useMemo } from 'react';
import { AddWorkTimeAndEstimatesToPlan } from '../daily-plan/plans-work-time-and-estimate';
import { ESTIMATE_POPUP_SHOWN_DATE, TODAY_PLAN_ALERT_SHOWN_DATE } from '@app/constants';
import { EnforcePlanedTaskModal, AddWorkTimeAndEstimatesToPlan } from '../daily-plan';

export function Timer({ className }: IClassName) {
const t = useTranslations();
const { closeModal, isOpen, openModal } = useModal();
const {
isOpen: isEnforceTaskModalOpen,
closeModal: enforceTaskCloseModal,
openModal: enforceTaskOpenModal
} = useModal();
const {
hours,
minutes,
Expand All @@ -37,6 +42,13 @@ export function Timer({ className }: IClassName) {
isPlanVerified,
hasPlan
} = useTimerView();
const { activeTeam, activeTeamTask } = useTeamTasks();
const requirePlan = useMemo(() => activeTeam?.requirePlanToTrack, [activeTeam?.requirePlanToTrack]);

const isActiveTaskPlaned = useMemo(
() => hasPlan?.tasks?.some((task) => task.id === activeTeamTask?.id),
[activeTeamTask?.id, hasPlan?.tasks]
);

const timerHanlderStartStop = useCallback(() => {
const currentDate = new Date().toISOString().split('T')[0];
Expand All @@ -47,6 +59,8 @@ export function Timer({ className }: IClassName) {
if (timerStatusFetching || !canRunTimer) return;
if (timerStatus?.running) {
stopTimer();
} else if (requirePlan && !isActiveTaskPlaned) {
enforceTaskOpenModal();
} else {
if (lastPlanPopupDate == currentDate && lastEstimatesPopupDate == currentDate) {
startTimer();
Expand All @@ -63,17 +77,21 @@ export function Timer({ className }: IClassName) {
}
}, [
canRunTimer,
enforceTaskOpenModal,
hasPlan?.tasks,
hasPlan?.workTimePlanned,
isActiveTaskPlaned,
isPlanVerified,
openModal,
requirePlan,
startTimer,
stopTimer,
timerStatus?.running,
timerStatusFetching
]);

const { os } = useDetectOS();

const osSpecificTimerTooltipLabel = useMemo(() => {
if (os === 'Mac') {
if (!timerStatus?.running) {
Expand Down Expand Up @@ -177,6 +195,14 @@ export function Timer({ className }: IClassName) {
startTimer={startTimer}
hasPlan={!!hasPlan}
/>
{requirePlan && hasPlan && activeTeamTask && (
<EnforcePlanedTaskModal
closeModal={enforceTaskCloseModal}
plan={hasPlan}
open={isEnforceTaskModalOpen}
task={activeTeamTask}
/>
)}
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "إزالة من هذه الخطة",
"CREATE_A_PLAN_FOR_TODAY": "إنشاء خطة لليوم",
"TODAY_PLAN_SUB_TITLE": "لا توجد خطة لليوم",
"DAILY_PLAN_DESCRIPTION": "'الخطة اليومية' تساعد في تنظيم عملية العمل لتحقيق أفضل النتائج"
"DAILY_PLAN_DESCRIPTION": "'الخطة اليومية' تساعد في تنظيم عملية العمل لتحقيق أفضل النتائج",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "لم تكن هذه المهمة مخططة لخطة اليوم. هل ترغب في إضافة شيء إلى الخطة؟"
},
"form": {
"NAME_PLACEHOLDER": "أدخل اسمك",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Премахни от този план",
"CREATE_A_PLAN_FOR_TODAY": "Създайте план за днес",
"TODAY_PLAN_SUB_TITLE": "Няма план за днес",
"DAILY_PLAN_DESCRIPTION": "'Дневният план' помага да се организира работният процес за постигане на най-добри резултати"
"DAILY_PLAN_DESCRIPTION": "'Дневният план' помага да се организира работният процес за постигане на най-добри резултати",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Тази задача не беше планирана за днешния план. Искате ли да добавите към плана?"
},
"form": {
"NAME_PLACEHOLDER": "Въведете името си",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Aus diesem Plan entfernen",
"CREATE_A_PLAN_FOR_TODAY": "Erstellen Sie einen Plan für heute",
"TODAY_PLAN_SUB_TITLE": "Es gibt keinen Plan für heute",
"DAILY_PLAN_DESCRIPTION": "'Tagesplan' hilft, den Arbeitsprozess zu organisieren, um die besten Ergebnisse zu erzielen"
"DAILY_PLAN_DESCRIPTION": "'Tagesplan' hilft, den Arbeitsprozess zu organisieren, um die besten Ergebnisse zu erzielen",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Deze taak was niet gepland voor het plan van vandaag. Wilt u iets toevoegen aan het plan?"
},
"form": {
"NAME_PLACEHOLDER": "Ihren Namen eingeben",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Remove from this plan",
"CREATE_A_PLAN_FOR_TODAY": "Create a Plan for Today",
"TODAY_PLAN_SUB_TITLE": " There is no plan for Today",
"DAILY_PLAN_DESCRIPTION": "'Daily Plan' helps organize the work process to achieve the best results"
"DAILY_PLAN_DESCRIPTION": "'Daily Plan' helps organize the work process to achieve the best results",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "This task was not planned for Today's plan. Would you like to add to the plan?"
},
"form": {
"NAME_PLACEHOLDER": "Enter your name",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Eliminar de este plan",
"CREATE_A_PLAN_FOR_TODAY": "Crear un plan para hoy",
"TODAY_PLAN_SUB_TITLE": "No hay plan para hoy",
"DAILY_PLAN_DESCRIPTION": "'Plan diario' ayuda a organizar el proceso de trabajo para lograr los mejores resultados"
"DAILY_PLAN_DESCRIPTION": "'Plan diario' ayuda a organizar el proceso de trabajo para lograr los mejores resultados",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Esta tarea no estaba prevista en el plan de hoy. ¿Te gustaría añadir algo al plan?"
},
"form": {
"NAME_PLACEHOLDER": "Ingresa tu nombre",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Retirer de ce plan",
"CREATE_A_PLAN_FOR_TODAY": "Créer un plan pour aujourd'hui",
"TODAY_PLAN_SUB_TITLE": "Il n'y a pas de plan pour aujourd'hui",
"DAILY_PLAN_DESCRIPTION": "'Plan quotidien' aide à organiser le processus de travail pour obtenir les meilleurs résultats"
"DAILY_PLAN_DESCRIPTION": "'Plan quotidien' aide à organiser le processus de travail pour obtenir les meilleurs résultats",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Cette tâche n'était pas prévue dans le planning d'aujourd'hui. Souhaitez-vous l'ajouter au planning ?"
},
"form": {
"NAME_PLACEHOLDER": "Entrez votre nom",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "הסר מתוכנית זו",
"CREATE_A_PLAN_FOR_TODAY": "צור תוכנית להיום",
"TODAY_PLAN_SUB_TITLE": "אין תוכנית להיום",
"DAILY_PLAN_DESCRIPTION": "'תוכנית יומית' עוזרת לארגן את תהליך העבודה להשגת התוצאות הטובות ביותר"
"DAILY_PLAN_DESCRIPTION": "'תוכנית יומית' עוזרת לארגן את תהליך העבודה להשגת התוצאות הטובות ביותר",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "משימה זו לא תוכננה עבור התוכנית של היום. האם תרצה להוסיף לתוכנית?"
},
"form": {
"NAME_PLACEHOLDER": "הכנס את השם שלך",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Rimuovi da questo piano",
"CREATE_A_PLAN_FOR_TODAY": "Crea un piano per oggi",
"TODAY_PLAN_SUB_TITLE": "Non c'è nessun piano per oggi",
"DAILY_PLAN_DESCRIPTION": "'Piano giornaliero' aiuta a organizzare il processo di lavoro per ottenere i migliori risultati"
"DAILY_PLAN_DESCRIPTION": "'Piano giornaliero' aiuta a organizzare il processo di lavoro per ottenere i migliori risultati",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Questa attività non era pianificata per il piano di oggi. Vuoi aggiungerla al piano?"
},
"form": {
"NAME_PLACEHOLDER": "Inserisci il tuo nome",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Verwijder uit dit plan",
"CREATE_A_PLAN_FOR_TODAY": "Maak een plan voor vandaag",
"TODAY_PLAN_SUB_TITLE": "Er is geen plan voor vandaag",
"DAILY_PLAN_DESCRIPTION": "'Dagelijkse planning' helpt om het werkproces te organiseren om de beste resultaten te behalen"
"DAILY_PLAN_DESCRIPTION": "'Dagelijkse planning' helpt om het werkproces te organiseren om de beste resultaten te behalen",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Diese Aufgabe war für den heutigen Plan nicht vorgesehen. Möchten Sie den Plan ergänzen?"
},
"form": {
"NAME_PLACEHOLDER": "Voer uw naam in",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Usuń z tego planu",
"CREATE_A_PLAN_FOR_TODAY": "Utwórz plan na dziś",
"TODAY_PLAN_SUB_TITLE": "Brak planu na dziś",
"DAILY_PLAN_DESCRIPTION": "'Plan dnia' pomaga zorganizować proces pracy, aby osiągnąć najlepsze wyniki"
"DAILY_PLAN_DESCRIPTION": "'Plan dnia' pomaga zorganizować proces pracy, aby osiągnąć najlepsze wyniki",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "To zadanie nie było zaplanowane na dzisiejszy plan. Czy chcesz dodać do planu?"
},
"form": {
"NAME_PLACEHOLDER": "Wprowadź swoje imię",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Remover deste plano",
"CREATE_A_PLAN_FOR_TODAY": "Criar um plano para hoje",
"TODAY_PLAN_SUB_TITLE": "Não há plano para hoje",
"DAILY_PLAN_DESCRIPTION": "'Plano diário' ajuda a organizar o processo de trabalho para obter os melhores resultados"
"DAILY_PLAN_DESCRIPTION": "'Plano diário' ajuda a organizar o processo de trabalho para obter os melhores resultados",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Esta tarefa não foi planeada no plano de hoje. Gostaria de acrescentar ao plano?"
},
"form": {
"NAME_PLACEHOLDER": "Digite seu nome",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "Убрать из этого плана",
"CREATE_A_PLAN_FOR_TODAY": "Создать план на сегодня",
"TODAY_PLAN_SUB_TITLE": "На сегодня нет плана",
"DAILY_PLAN_DESCRIPTION": "'Ежедневный план' помогает организовать рабочий процесс для достижения наилучших результатов"
"DAILY_PLAN_DESCRIPTION": "'Ежедневный план' помогает организовать рабочий процесс для достижения наилучших результатов",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Эта задача не была запланирована в плане на сегодня. Хотите добавить в план?"
},
"form": {
"NAME_PLACEHOLDER": "Введите ваше имя",
Expand Down
3 changes: 2 additions & 1 deletion apps/web/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"REMOVE_FROM_THIS_PLAN": "从计划中移除",
"CREATE_A_PLAN_FOR_TODAY": "为今天制定计划",
"TODAY_PLAN_SUB_TITLE": "今天没有计划",
"DAILY_PLAN_DESCRIPTION": "'每日计划' 有助于组织工作流程以实现最佳结果"
"DAILY_PLAN_DESCRIPTION": "'每日计划' 有助于组织工作流程以实现最佳结果",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "此任务未列入今日计划。要添加到计划中吗?"
},
"form": {
"NAME_PLACEHOLDER": "输入您的姓名",
Expand Down

0 comments on commit fe733a2

Please sign in to comment.