From 7ca6a45542569ac1e194d2705230f3ac5a29c0de Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 17 Oct 2024 20:36:54 +0200 Subject: [PATCH 1/7] refactor: the timer should not start when the user ignores the 'Today plan' popup --- .../add-daily-plan-work-hours-modal.tsx | 39 +++++++++++++------ .../add-task-estimation-hours-modal.tsx | 26 +++++++++---- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx b/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx index aa66a0d35..473646fd8 100644 --- a/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx +++ b/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx @@ -1,4 +1,4 @@ -import { Card, InputField, Modal, Text } from 'lib/components'; +import { Card, InputField, Modal, SpinnerLoader, Text } from 'lib/components'; import { Button } from '@components/ui/button'; import { useCallback, useMemo, useState } from 'react'; import { DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE } from '@app/constants'; @@ -19,22 +19,35 @@ export function AddDailyPlanWorkHourModal(props: IAddDailyPlanWorkHoursModalProp const { updateDailyPlan } = useDailyPlan(); const { startTimer } = useTimerView(); const { activeTeam } = useTeamTasks(); - const [workTimePlanned, setworkTimePlanned] = useState(plan.workTimePlanned); const currentDate = useMemo(() => new Date().toISOString().split('T')[0], []); const requirePlan = useMemo(() => activeTeam?.requirePlanToTrack, [activeTeam?.requirePlanToTrack]); const hasWorkHours = useMemo(() => plan.workTimePlanned && plan.workTimePlanned > 0, [plan.workTimePlanned]); + const [loading, setLoading] = useState(false); const handleCloseModal = useCallback(() => { localStorage.setItem(DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE, currentDate); closeModal(); - startTimer(); - }, [closeModal, currentDate, startTimer]); + }, [closeModal, currentDate]); + + const handleSubmit = useCallback(async () => { + try { + setLoading(true); + + // Update the plan work time only if the user changed it + plan && + plan.workTimePlanned !== workTimePlanned && + (await updateDailyPlan({ workTimePlanned }, plan.id ?? '')); + + startTimer(); - const handleSubmit = useCallback(() => { - updateDailyPlan({ workTimePlanned }, plan.id ?? ''); - handleCloseModal(); - }, [handleCloseModal, plan.id, updateDailyPlan, workTimePlanned]); + handleCloseModal(); + } catch (error) { + console.log(error); + } finally { + setLoading(false); + } + }, [handleCloseModal, plan, startTimer, updateDailyPlan, workTimePlanned]); return ( @@ -66,7 +79,7 @@ export function AddDailyPlanWorkHourModal(props: IAddDailyPlanWorkHoursModalProp diff --git a/apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx b/apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx index 07441592f..6f8452e2d 100644 --- a/apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx +++ b/apps/web/lib/features/daily-plan/add-task-estimation-hours-modal.tsx @@ -108,12 +108,24 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa /** * The function that close the Planned tasks modal when the user ignores the modal (Today's plan) */ - const closeModalAndStartTimer = useCallback(() => { - handleCloseModal(); - if (canStartWorking) { - startTimer(); + const closeModalAndSubmit = useCallback(async () => { + try { + setLoading(true); + + // Update the plan work time only if the user changed it + plan && + plan.workTimePlanned !== workTimePlanned && + (await updateDailyPlan({ workTimePlanned }, plan.id ?? '')); + + setPlanEditState({ draft: false, saved: true }); + + handleCloseModal(); + } catch (error) { + console.log(error); + } finally { + setLoading(false); } - }, [canStartWorking, handleCloseModal, startTimer]); + }, [handleCloseModal, plan, updateDailyPlan, workTimePlanned]); /** * The function that opens the Change task modal if conditions are met (or start the timer) @@ -466,7 +478,7 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa variant="outline" type="submit" className="py-3 px-5 w-40 rounded-md font-light text-md dark:text-white dark:bg-slate-700 dark:border-slate-600" - onClick={isRenderedInSoftFlow ? closeModalAndStartTimer : handleCloseModal} + onClick={isRenderedInSoftFlow ? closeModalAndSubmit : handleCloseModal} > {isRenderedInSoftFlow ? t('common.SKIP_ADD_LATER') : t('common.CANCEL')} @@ -489,7 +501,7 @@ export function AddTasksEstimationHoursModal(props: IAddTasksEstimationHoursModa return ( <> {isRenderedInSoftFlow ? ( - + {content} From 07f0a94f6832f9225788ff514e0073d1848af06b Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 17 Oct 2024 20:50:48 +0200 Subject: [PATCH 2/7] refactor: the timer should not start when the user ignores the 'Today plan' popup --- .../lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx b/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx index 473646fd8..31a8732bb 100644 --- a/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx +++ b/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx @@ -87,7 +87,7 @@ export function AddDailyPlanWorkHourModal(props: IAddDailyPlanWorkHoursModalProp } > {/*button confirm*/} {/*button cancel*/} diff --git a/apps/web/locales/ar.json b/apps/web/locales/ar.json index 8d125389b..0cc29dff3 100644 --- a/apps/web/locales/ar.json +++ b/apps/web/locales/ar.json @@ -217,7 +217,8 @@ "EDIT_PLAN": "تعديل الخطة", "TRACKED_TIME": "الوقت المتعقب", "SEE_PLANS": "عرض الخطط", - "ADD_PLAN": "إضافة خطة" + "ADD_PLAN": "إضافة خطة", + "DELETE_THIS_PLAN": "احذف هذه الخطة" }, "timesheets": { "SINGULAR": "ورقة الحضور", diff --git a/apps/web/locales/bg.json b/apps/web/locales/bg.json index 3f8b6fe8c..f401eaa36 100644 --- a/apps/web/locales/bg.json +++ b/apps/web/locales/bg.json @@ -217,7 +217,8 @@ "EDIT_PLAN": "Редактиране на план", "TRACKED_TIME": "Проследено време", "SEE_PLANS": "Виж планове", - "ADD_PLAN": "Добави план" + "ADD_PLAN": "Добави план", + "DELETE_THIS_PLAN": "Изтрийте този план" }, "timesheets": { "SINGULAR": "Работен лист", diff --git a/apps/web/locales/de.json b/apps/web/locales/de.json index 133934101..f53a9a886 100644 --- a/apps/web/locales/de.json +++ b/apps/web/locales/de.json @@ -217,7 +217,8 @@ "EDIT_PLAN": "Plan bearbeiten", "TRACKED_TIME": "Verfolgte Zeit", "SEE_PLANS": "Pläne anzeigen", - "ADD_PLAN": "Plan hinzufügen" + "ADD_PLAN": "Plan hinzufügen", + "DELETE_THIS_PLAN": "Diesen Plan löschen" }, "timesheets": { "SINGULAR": "Stundenzettel", diff --git a/apps/web/locales/en.json b/apps/web/locales/en.json index 4692276dc..4ec15a92e 100644 --- a/apps/web/locales/en.json +++ b/apps/web/locales/en.json @@ -217,7 +217,8 @@ "EDIT_PLAN": "Edit Plan", "TRACKED_TIME": "Tracked time", "SEE_PLANS": "See plans", - "ADD_PLAN": "Add Plan" + "ADD_PLAN": "Add Plan", + "DELETE_THIS_PLAN": "Delete this plan" }, "timesheets": { "SINGULAR": "Timesheet", diff --git a/apps/web/locales/es.json b/apps/web/locales/es.json index 2bfadb58b..5f962410b 100644 --- a/apps/web/locales/es.json +++ b/apps/web/locales/es.json @@ -217,7 +217,8 @@ "ADD_PLAN": "Agregar Plan", "TRACKED_TIME": "Tiempo registrado", "SEE_PLANS": "Ver planes", - "FOR_TOMORROW": "Plan de mañana" + "FOR_TOMORROW": "Plan de mañana", + "DELETE_THIS_PLAN": "Eliminar este plan" }, "timesheets": { "SINGULAR": "Hoja de horas", diff --git a/apps/web/locales/fr.json b/apps/web/locales/fr.json index 32440addd..2237827a9 100644 --- a/apps/web/locales/fr.json +++ b/apps/web/locales/fr.json @@ -217,7 +217,8 @@ "EDIT_PLAN": "Modifier le plan", "TRACKED_TIME": "Temps suivi", "SEE_PLANS": "Voir les plans", - "ADD_PLAN": "Ajouter un plan" + "ADD_PLAN": "Ajouter un plan", + "DELETE_THIS_PLAN": "Supprimer ce plan" }, "timesheets": { "SINGULAR": "Feuille de temps", diff --git a/apps/web/locales/he.json b/apps/web/locales/he.json index 5d9df1e15..ed4bd8807 100644 --- a/apps/web/locales/he.json +++ b/apps/web/locales/he.json @@ -217,7 +217,8 @@ "EDIT_PLAN": "ערוך תוכנית", "TRACKED_TIME": "זמן מעקב", "SEE_PLANS": "ראה תוכניות", - "ADD_PLAN": "הוסף תוכנית" + "ADD_PLAN": "הוסף תוכנית", + "DELETE_THIS_PLAN": "מחק את התוכנית הזו" }, "timesheets": { "SINGULAR": "דוח שעות", diff --git a/apps/web/locales/it.json b/apps/web/locales/it.json index bd11fbd71..ef56b6976 100644 --- a/apps/web/locales/it.json +++ b/apps/web/locales/it.json @@ -221,7 +221,8 @@ "EDIT_PLAN": "Modifica Piano", "TRACKED_TIME": "Tempo tracciato", "SEE_PLANS": "Vedi piani", - "ADD_PLAN": "Aggiungi Piano" + "ADD_PLAN": "Aggiungi Piano", + "DELETE_THIS_PLAN": "Elimina questo piano" }, "COPY_ISSUE_LINK": "Copia collegamento problema", "MAKE_A_COPY": "Fai una copia", diff --git a/apps/web/locales/nl.json b/apps/web/locales/nl.json index c59d6f29d..dec963075 100644 --- a/apps/web/locales/nl.json +++ b/apps/web/locales/nl.json @@ -221,7 +221,8 @@ "EDIT_PLAN": "Plan bewerken", "TRACKED_TIME": "Gegeneraliseerde tijd", "SEE_PLANS": "Plannen bekijken", - "ADD_PLAN": "Plan toevoegen" + "ADD_PLAN": "Plan toevoegen", + "DELETE_THIS_PLAN": "Verwijder dit plan" }, "COPY_ISSUE_LINK": "Probleemlink kopiëren", "MAKE_A_COPY": "Maak een kopie", diff --git a/apps/web/locales/pl.json b/apps/web/locales/pl.json index 013652426..566aec919 100644 --- a/apps/web/locales/pl.json +++ b/apps/web/locales/pl.json @@ -221,7 +221,8 @@ "EDIT_PLAN": "Edytuj plan", "TRACKED_TIME": "Śledzony czas", "SEE_PLANS": "Zobacz plany", - "ADD_PLAN": "Dodaj plan" + "ADD_PLAN": "Dodaj plan", + "DELETE_THIS_PLAN": "Usuń ten plan" }, "COPY_ISSUE_LINK": "Skopiuj link do zgłoszenia", "MAKE_A_COPY": "Zrób kopię", diff --git a/apps/web/locales/pt.json b/apps/web/locales/pt.json index a21389cf1..e907d74e9 100644 --- a/apps/web/locales/pt.json +++ b/apps/web/locales/pt.json @@ -221,7 +221,8 @@ "EDIT_PLAN": "Editar Plano", "TRACKED_TIME": "Tempo rastreado", "SEE_PLANS": "Ver planos", - "ADD_PLAN": "Adicionar Plano" + "ADD_PLAN": "Adicionar Plano", + "DELETE_THIS_PLAN": "Excluir este plano" }, "COPY_ISSUE_LINK": "Copiar link do problema", "MAKE_A_COPY": "Fazer uma cópia", diff --git a/apps/web/locales/ru.json b/apps/web/locales/ru.json index 7c58dd7a6..63081f89b 100644 --- a/apps/web/locales/ru.json +++ b/apps/web/locales/ru.json @@ -221,7 +221,8 @@ "EDIT_PLAN": "Редактировать план", "TRACKED_TIME": "Отслеживаемое время", "SEE_PLANS": "Посмотреть планы", - "ADD_PLAN": "Agregar Plan" + "ADD_PLAN": "Agregar Plan", + "DELETE_THIS_PLAN": "Удалить этот план" }, "COPY_ISSUE_LINK": "Скопировать ссылку на проблему", "MAKE_A_COPY": "Сделать копию", diff --git a/apps/web/locales/zh.json b/apps/web/locales/zh.json index 5e8860b36..b3e5bae92 100644 --- a/apps/web/locales/zh.json +++ b/apps/web/locales/zh.json @@ -221,7 +221,8 @@ "EDIT_PLAN": "编辑计划", "TRACKED_TIME": "跟踪时间", "SEE_PLANS": "查看计划", - "ADD_PLAN": "添加计划" + "ADD_PLAN": "添加计划", + "DELETE_THIS_PLAN": "删除此计划" }, "COPY_ISSUE_LINK": "复制问题链接", "MAKE_A_COPY": "制作副本", From 9746b83fb567223f730f5e71fba0262d3316e2c5 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Fri, 18 Oct 2024 12:05:17 +0200 Subject: [PATCH 5/7] add requested changes --- .../daily-plan/add-daily-plan-work-hours-modal.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx b/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx index cb9c11d86..eb8ab7fc1 100644 --- a/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx +++ b/apps/web/lib/features/daily-plan/add-daily-plan-work-hours-modal.tsx @@ -35,9 +35,9 @@ export function AddDailyPlanWorkHourModal(props: IAddDailyPlanWorkHoursModalProp setLoading(true); // Update the plan work time only if the user changed it - plan && - plan.workTimePlanned !== workTimePlanned && - (await updateDailyPlan({ workTimePlanned }, plan.id ?? '')); + if (plan && plan.workTimePlanned !== workTimePlanned) { + await updateDailyPlan({ workTimePlanned }, plan.id ?? ''); + } startTimer(); @@ -87,7 +87,7 @@ export function AddDailyPlanWorkHourModal(props: IAddDailyPlanWorkHoursModalProp