Skip to content

Commit

Permalink
feat: add more elements to the 'Planned tasks' popup
Browse files Browse the repository at this point in the history
feat: add warning messages

feat: add logic of 'Start working' button on the planned tasks popup
  • Loading branch information
CREDO23 committed Aug 23, 2024
1 parent ed51f03 commit 1d43e55
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 37 deletions.
34 changes: 32 additions & 2 deletions apps/web/app/hooks/features/useTeamTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ import {
updateTaskAPI,
deleteEmployeeFromTasksAPI,
getTasksByIdAPI,
getTasksByEmployeeIdAPI
getTasksByEmployeeIdAPI,
getAllDayPlansAPI,
getMyDailyPlansAPI
} from '@app/services/client/api';
import {
activeTeamState,
activeTeamTaskId,
dailyPlanListState,
detailedTaskState,
// employeeTasksState,
memberActiveTaskIdState,
myDailyPlanListState,
userState
} from '@app/stores';
import { activeTeamTaskState, tasksByTeamState, tasksFetchingState, teamTasksState } from '@app/stores';
Expand Down Expand Up @@ -59,6 +63,9 @@ export function useTeamTasks() {

const { firstLoad, firstLoadData: firstLoadTasksData } = useFirstLoad();

const setDailyPlan = useSetRecoilState(dailyPlanListState);
const setMyDailyPlans = useSetRecoilState(myDailyPlanListState);

// Queries hooks
const { queryCall, loading, loadingRef } = useQuery(getTeamTasksAPI);
const { queryCall: getTasksByIdQueryCall, loading: getTasksByIdLoading } = useQuery(getTasksByIdAPI);
Expand All @@ -71,9 +78,30 @@ export function useTeamTasks() {

const { queryCall: updateQueryCall, loading: updateLoading } = useQuery(updateTaskAPI);

const { queryCall: getAllQueryCall } = useQuery(getAllDayPlansAPI);
const { queryCall: getMyDailyPlansQueryCall } = useQuery(getMyDailyPlansAPI);

const { queryCall: deleteEmployeeFromTasksQueryCall, loading: deleteEmployeeFromTasksLoading } =
useQuery(deleteEmployeeFromTasksAPI);

const getAllDayPlans = useCallback(() => {
getAllQueryCall().then((response) => {
if (response.data.items.length) {
const { items, total } = response.data;
setDailyPlan({ items, total });
}
});
}, [getAllQueryCall, setDailyPlan]);

const getMyDailyPlans = useCallback(() => {
getMyDailyPlansQueryCall().then((response) => {
if (response.data.items.length) {
const { items, total } = response.data;
setMyDailyPlans({ items, total });
}
});
}, [getMyDailyPlansQueryCall, setMyDailyPlans]);

const getTaskById = useCallback(
(taskId: string) => {
tasksRef.current.forEach((task) => {
Expand Down Expand Up @@ -126,13 +154,15 @@ export function useTeamTasks() {
const activeTeamTasks = tasksRef.current.slice().sort((a, b) => a.title.localeCompare(b.title));

if (!isEqual(latestActiveTeamTasks, activeTeamTasks)) {
getMyDailyPlans();
getAllDayPlans();
setAllTasks(responseTasks);
}
} else {
setAllTasks(responseTasks);
}
},
[activeTeamRef, setAllTasks, tasksRef]
[activeTeamRef, getAllDayPlans, getMyDailyPlans, setAllTasks, tasksRef]
);

const loadTeamTasksData = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { TaskNameInfoDisplay } from '../task/task-displays';
import { TaskEstimate } from '../task/task-estimate';
import { IDailyPlan, ITeamTask } from '@app/interfaces';
import clsx from 'clsx';
import { AddIcon, ThreeCircleOutlineVerticalIcon } from 'assets/svg';
import { estimatedTotalTime } from '../task/daily-plan';
import { clsxm } from '@app/utils';

interface IAddTasksEstimationHoursModalProps {
closeModal: () => void;
Expand All @@ -21,13 +24,15 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
const { isOpen, closeModal, plan, tasks } = props;

const t = useTranslations();
const { updateDailyPlan } = useDailyPlan();
const { updateDailyPlan, myDailyPlans } = useDailyPlan();
const { startTimer } = useTimerView();
const { activeTeam, activeTeamTask, setActiveTask } = useTeamTasks();

const [workTimePlanned, setworkTimePlanned] = useState<number | undefined>(plan.workTimePlanned);
const currentDate = useMemo(() => new Date().toISOString().split('T')[0], []);
const requirePlan = useMemo(() => activeTeam?.requirePlanToTrack, [activeTeam?.requirePlanToTrack]);
const tasksEstimationTimes = useMemo(() => estimatedTotalTime(plan.tasks).timesEstimated / 3600, [plan.tasks]);
const [warning, setWarning] = useState('');

const handleCloseModal = useCallback(() => {
localStorage.setItem(TASKS_ESTIMATE_HOURS_MODAL_DATE, currentDate);
Expand Down Expand Up @@ -67,6 +72,17 @@ 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 (
<Modal isOpen={isOpen} closeModal={handleCloseModal} showCloseIcon={requirePlan ? false : true}>
<Card className="w-full" shadow="custom">
Expand All @@ -79,18 +95,23 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
<span className="text-sm">
{t('timer.todayPlanSettings.WORK_TIME_PLANNED')} <span className="text-red-600">*</span>
</span>

<InputField
type="number"
placeholder={t('timer.todayPlanSettings.WORK_TIME_PLANNED_PLACEHOLDER')}
className="mb-0 min-w-[350px]"
wrapperClassName="mb-0 rounded-lg"
onChange={(e) => setworkTimePlanned(parseFloat(e.target.value))}
required
min={0}
value={workTimePlanned}
defaultValue={plan.workTimePlanned ?? 0}
/>
<div className="w-full flex gap-3 h-[3rem]">
<InputField
type="number"
placeholder={t('timer.todayPlanSettings.WORK_TIME_PLANNED_PLACEHOLDER')}
className="h-full"
wrapperClassName=" h-full"
onChange={(e) => setworkTimePlanned(parseFloat(e.target.value))}
required
noWrapper
min={0}
value={workTimePlanned}
defaultValue={plan.workTimePlanned ?? 0}
/>
<div className="h-full shrink-0 rounded-lg border w-10 flex items-center justify-center">
<AddIcon className="w-4 h-4 text-dark dark:text-white" />
</div>
</div>
</div>
<div className="text-sm flex flex-col gap-3">
<div className="text-sm flex flex-col gap-3">
Expand All @@ -104,9 +125,13 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
))}
</div>
</div>
<div className="flex gap-2 items-center text-red-500">
<PiWarningCircleFill className="text-2xl" />
<p>{t('timer.todayPlanSettings.WARNING_PLAN_ESTIMATION')}</p>
<div className="flex gap-2 items-center h-6 text-red-500">
{warning && (
<>
<PiWarningCircleFill className="text-2xl" />
<p>{warning}</p>
</>
)}
</div>
</div>
</div>
Expand All @@ -120,9 +145,13 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
{t('common.SKIP_ADD_LATER')}
</Button>
<Button
disabled={warning ? true : false}
variant="default"
type="submit"
className="py-3 px-5 rounded-md font-light text-md dark:text-white"
className={clsxm(
'py-3 px-5 rounded-md font-light text-md dark:text-white',
warning && 'bg-gray-400'
)}
onClick={handleSubmit}
>
{t('timer.todayPlanSettings.START_WORKING_BUTTON')}
Expand All @@ -145,16 +174,23 @@ function TaskCard({ task }: ITaskCardProps) {
<Card
shadow="custom"
className={clsx(
'lg:flex items-center justify-between py-3 px-4 md:px-4 hidden min-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] w-[30rem] 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)}
>
<div className="min-w-[50%] max-w-[50%]">
<div className="min-w-[48%] flex items-center h-full max-w-[50%]">
<TaskNameInfoDisplay task={task} />
</div>
<VerticalSeparator />
<TaskEstimate _task={task} />
<div className="h-full grow flex items-center justify-end gap-2">
<div className="h-full flex items-center justify-center gap-1">
<span>Estimation :</span> <TaskEstimate _task={task} />
</div>
<span className="w-4 h-full flex items-center justify-center">
<ThreeCircleOutlineVerticalIcon className=" dark:text-[#B1AEBC]" />
</span>
</div>
</Card>
);
}
2 changes: 1 addition & 1 deletion apps/web/lib/features/task/task-displays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function TaskNameInfoDisplay({
const short: string = taskSizeColor[size].short;
return (
<Tooltip label={task?.title || ''} placement="top" enabled={(task?.title && task?.title.length > 60) || false}>
<span className="flex">
<span className="flex items-center">
{task && (
// Show task issue and task number
<div>
Expand Down
3 changes: 2 additions & 1 deletion apps/web/lib/features/task/task-estimate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ export function TaskEstimate({
{!updateLoading ? (
editableMode ? (
<button
onClick={() => {
onClick={(e) => {
e.stopPropagation();
handleSubmit();
setEditableMode(false);
}}
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "تقديري",
"TOTAL_TASK": "إجمالي المهام",
"DAILY_PLAN_DESCRIPTION": "'الخطة اليومية' تساعد في تنظيم عملية العمل لتحقيق أفضل النتائج",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "لم تكن هذه المهمة مخططة لخطة اليوم. هل ترغب في إضافة شيء إلى الخطة؟"
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "لم تكن هذه المهمة مخططة لخطة اليوم. هل ترغب في إضافة شيء إلى الخطة؟",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "يرجى إضافة الوقت المخطط",
"TASKS_ESTIMATION": "يرجى تقدير جميع المهام"
}
}
},
"form": {
"NAME_PLACEHOLDER": "أدخل اسمك",
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "Оценено",
"TOTAL_TASK": "Общо задачи",
"DAILY_PLAN_DESCRIPTION": "'Дневният план' помага да се организира работният процес за постигане на най-добри резултати",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Тази задача не беше планирана за днешния план. Искате ли да добавите към плана?"
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Тази задача не беше планирана за днешния план. Искате ли да добавите към плана?",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "Моля, добавете планираното време",
"TASKS_ESTIMATION": "Моля, оценете всички задачи"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Въведете името си",
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "Geschätzt",
"TOTAL_TASK": "Gesamte Aufgaben",
"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?"
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Deze taak was niet gepland voor het plan van vandaag. Wilt u iets toevoegen aan het plan?",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "Bitte fügen Sie die geplante Zeit hinzu",
"TASKS_ESTIMATION": "Bitte schätzen Sie alle Aufgaben"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Ihren Namen eingeben",
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "Estimated",
"TOTAL_TASK": "Total tasks",
"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?"
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "This task was not planned for Today's plan. Would you like to add to the plan?",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "Please, add planned time",
"TASKS_ESTIMATION": "Please, estimate all tasks"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Enter your name",
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "Estimado",
"TOTAL_TASK": "Tareas totales",
"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?"
"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?",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "Por favor, añade tiempo planificado",
"TASKS_ESTIMATION": "Por favor, estima todas las tareas"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Ingresa tu nombre",
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "Estimé",
"TOTAL_TASK": "Tâches totales",
"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 ?"
"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 ?",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "Veuillez ajouter le temps planifié",
"TASKS_ESTIMATION": "Veuillez estimer toutes les tâches"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Entrez votre nom",
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "משוער",
"TOTAL_TASK": "סך כל המשימות",
"DAILY_PLAN_DESCRIPTION": "'תוכנית יומית' עוזרת לארגן את תהליך העבודה להשגת התוצאות הטובות ביותר",
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "משימה זו לא תוכננה עבור התוכנית של היום. האם תרצה להוסיף לתוכנית?"
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "משימה זו לא תוכננה עבור התוכנית של היום. האם תרצה להוסיף לתוכנית?",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "אנא הוסף זמן מתוכנן",
"TASKS_ESTIMATION": "אנא הערך את כל המשימות"
}
}
},
"form": {
"NAME_PLACEHOLDER": "הכנס את השם שלך",
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "Stimato",
"TOTAL_TASK": "Compiti totali",
"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?"
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Questa attività non era pianificata per il piano di oggi. Vuoi aggiungerla al piano?",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "Per favore, aggiungi il tempo pianificato",
"TASKS_ESTIMATION": "Per favore, stima tutte le attività"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Inserisci il tuo nome",
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "Geschat",
"TOTAL_TASK": "Totale taken",
"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?"
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "Diese Aufgabe war für den heutigen Plan nicht vorgesehen. Möchten Sie den Plan ergänzen?",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "Voeg alstublieft de geplande tijd toe",
"TASKS_ESTIMATION": "Schat alstublieft alle taken in"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Voer uw naam in",
Expand Down
8 changes: 7 additions & 1 deletion apps/web/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@
"ESTIMATED": "Szacowany",
"TOTAL_TASK": "Łączna liczba zadań",
"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?"
"SUGGESTS_TO_ADD_TASK_TO_TODAY_PLAN": "To zadanie nie było zaplanowane na dzisiejszy plan. Czy chcesz dodać do planu?",
"planned_tasks_popup": {
"warning": {
"PLANNED_TIME": "Proszę dodać planowany czas",
"TASKS_ESTIMATION": "Proszę oszacować wszystkie zadania"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Wprowadź swoje imię",
Expand Down
Loading

0 comments on commit 1d43e55

Please sign in to comment.