Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2942 feature planned button stat working on the popup #2953

Merged
35 changes: 33 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(async () => {
const response = await getAllQueryCall();

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

const getMyDailyPlans = useCallback(async () => {
const response = await getMyDailyPlansQueryCall();

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,16 @@ export function useTeamTasks() {
const activeTeamTasks = tasksRef.current.slice().sort((a, b) => a.title.localeCompare(b.title));

if (!isEqual(latestActiveTeamTasks, activeTeamTasks)) {
// Fetch plans with updated task(s)
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 @@ -11,8 +11,10 @@ import { TaskEstimate } from '../task/task-estimate';
import { IDailyPlan, ITeamTask } from '@app/interfaces';
import clsx from 'clsx';
import { AddIcon, ThreeCircleOutlineVerticalIcon } from 'assets/svg';
import { Popover, Transition } from '@headlessui/react';
import { estimatedTotalTime } from '../task/daily-plan';
import { clsxm } from '@app/utils';
import { formatIntegerToHour } from '@app/helpers';
import { Popover, Transition } from '@headlessui/react';
import Link from 'next/link';

interface IAddTasksEstimationHoursModalProps {
Expand All @@ -26,13 +28,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 All @@ -42,10 +46,35 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa

const handleSubmit = useCallback(() => {
updateDailyPlan({ workTimePlanned }, plan.id ?? '');

handleCloseModal();
}, [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(
() =>
Expand Down Expand Up @@ -76,7 +105,7 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa
return (
<Modal isOpen={isOpen} closeModal={handleCloseModal} showCloseIcon={requirePlan ? false : true}>
<Card className="w-full" shadow="custom">
<div className="flex flex-col justify-between">
<div className="flex w-[32rem] flex-col justify-between">
<div className="mb-7">
<Text.Heading as="h3" className="mb-3 text-center">
{t('timer.todayPlanSettings.TITLE')}
Expand Down Expand Up @@ -105,19 +134,31 @@ 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>{t('task.TITLE_PLURAL')}</span>
<span className="text-red-600">*</span>
</div>
<div className="flex items-center justify-center gap-1">
<span>{t('dailyPlan.TOTAL_ESTIMATED')} :</span>
<span className=" font-medium">
{formatIntegerToHour(tasksEstimationTimes)}
</span>
</div>
</div>
<div className="flex flex-col gap-1">
{sortedTasks.map((task, index) => (
<TaskCard plan={plan} key={index} task={task} />
))}
</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 text-sm h-6 text-red-500">
{warning && (
<>
<PiWarningCircleFill />
<span>{warning}</span>
</>
)}
</div>
</div>
</div>
Expand All @@ -131,9 +172,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 @@ -152,12 +197,13 @@ interface ITaskCardProps {

function TaskCard({ task, plan }: ITaskCardProps) {
const { setActiveTask, activeTeamTask } = useTeamTasks();
const t = useTranslations();

return (
<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] 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]'
)}
>
Expand All @@ -167,7 +213,7 @@ function TaskCard({ task, plan }: ITaskCardProps) {
<VerticalSeparator />
<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} />
<span>{t('dailyPlan.ESTIMATED')} :</span> <TaskEstimate _task={task} />
</div>
<span className="w-4 h-full flex items-center justify-center">
<TaskCardActions selectedPlan={plan} task={task} />
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
12 changes: 11 additions & 1 deletion apps/web/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
},
"task": {
"TITLE": "المهمة",
"TITLE_PLURAL": "مهام",
"ASSIGN_NEW_TASK": "تعيين مهمة جديدة",
"ASSIGNED_BY": "تم التعيين بواسطة",
"NO_ONE_FOR_TASK": "لم يتم تعيين أحد لهذه المهمة",
Expand Down Expand Up @@ -602,9 +603,18 @@
"COMPLETION": "إتمام",
"PLANNED_TASKS": "المهمة المخططة",
"ESTIMATED": "تقديري",
"TOTAL_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": "يرجى تقدير جميع المهام",
"OPTIMIZE_PLAN": "الوقت المقدر الإجمالي يتجاوز الوقت المخطط له، يرجى تحسين خطتك",
"PLAN_MORE_TASKS": "يرجى إضافة المزيد من المهام إلى الخطة"
}
}
},
"form": {
"NAME_PLACEHOLDER": "أدخل اسمك",
Expand Down
12 changes: 11 additions & 1 deletion apps/web/locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
},
"task": {
"TITLE": "Задача",
"TITLE_PLURAL": "Задачи",
"ASSIGN_NEW_TASK": "Възлагане на нова задача",
"ASSIGNED_BY": "Възложено от",
"NO_ONE_FOR_TASK": "Няма отговорник за тази задача",
Expand Down Expand Up @@ -602,9 +603,18 @@
"COMPLETION": "Завършване",
"PLANNED_TASKS": "Планирана задача",
"ESTIMATED": "Оценено",
"TOTAL_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": "Моля, оценете всички задачи",
"OPTIMIZE_PLAN": "Общото прогнозирано време надвишава планираното време, моля оптимизирайте плана си",
"PLAN_MORE_TASKS": "Моля, добавете още задачи към плана"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Въведете името си",
Expand Down
12 changes: 11 additions & 1 deletion apps/web/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
},
"task": {
"TITLE": "Aufgabe",
"TITLE_PLURAL": "Aufgaben",
"ASSIGN_NEW_TASK": "Neue Aufgabe zuweisen",
"ASSIGNED_BY": "Zugewiesen von",
"NO_ONE_FOR_TASK": "Niemand dieser Aufgabe zugewiesen",
Expand Down Expand Up @@ -602,9 +603,18 @@
"COMPLETION": "Abschluss",
"PLANNED_TASKS": "Geplante Aufgabe",
"ESTIMATED": "Geschätzt",
"TOTAL_ESTIMATED": "Gesamtschätzung",
"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",
"OPTIMIZE_PLAN": "Die geschätzte Gesamtzeit übersteigt Ihre geplante Zeit, bitte optimieren Sie Ihren Plan",
"PLAN_MORE_TASKS": "Bitte fügen Sie dem Plan mehr Aufgaben hinzu"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Ihren Namen eingeben",
Expand Down
12 changes: 11 additions & 1 deletion apps/web/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
},
"task": {
"TITLE": "Task",
"TITLE_PLURAL": "Tasks",
"ASSIGN_NEW_TASK": "Assign new task",
"ASSIGNED_BY": "Assigned By",
"NO_ONE_FOR_TASK": "No One Assigned to this Task",
Expand Down Expand Up @@ -602,9 +603,18 @@
"COMPLETION": "Completion",
"PLANNED_TASKS": "Planned task",
"ESTIMATED": "Estimated",
"TOTAL_ESTIMATED": "Total 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",
"OPTIMIZE_PLAN": "Total estimated time exceeds your Planned time, please optimize your plan",
"PLAN_MORE_TASKS": "Please add more tasks to the plan"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Enter your name",
Expand Down
12 changes: 11 additions & 1 deletion apps/web/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
},
"task": {
"TITLE": "Tarea",
"TITLE_PLURAL": "Tareas",
"ASSIGN_NEW_TASK": "Asignar nueva tarea",
"ASSIGNED_BY": "Asignado por",
"NO_ONE_FOR_TASK": "Nadie asignado a esta tarea",
Expand Down Expand Up @@ -602,9 +603,18 @@
"COMPLETION": "Finalización",
"PLANNED_TASKS": "Tarea planificada",
"ESTIMATED": "Estimado",
"TOTAL_ESTIMATED": "Estimado total",
"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",
"OPTIMIZE_PLAN": "El tiempo total estimado excede tu tiempo planificado, por favor optimiza tu plan",
"PLAN_MORE_TASKS": "Por favor, añade más tareas al plan"
}
}
},
"form": {
"NAME_PLACEHOLDER": "Ingresa tu nombre",
Expand Down
Loading
Loading