From 2bc22946e64fb339c44fd163be69c2e49c90a98f Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 8 Aug 2024 22:51:04 +0200 Subject: [PATCH] fix: user should be able to close popup after selection the appropriate date --- .../create-daily-plan-form-modal.tsx | 82 +++++++++++++++---- apps/web/lib/features/task/task-card.tsx | 38 +++++---- 2 files changed, 88 insertions(+), 32 deletions(-) diff --git a/apps/web/lib/features/daily-plan/create-daily-plan-form-modal.tsx b/apps/web/lib/features/daily-plan/create-daily-plan-form-modal.tsx index a483882c7..f3ca4f409 100644 --- a/apps/web/lib/features/daily-plan/create-daily-plan-form-modal.tsx +++ b/apps/web/lib/features/daily-plan/create-daily-plan-form-modal.tsx @@ -13,6 +13,8 @@ import { ScrollArea } from '@components/ui/scroll-bar'; import { clsxm, isValidUrl } from '@app/utils'; import stc from 'string-to-color'; import { Check } from 'lucide-react'; +import { cn } from 'lib/utils'; +import { MdOutlineKeyboardArrowDown } from 'react-icons/md'; export function CreateDailyPlanFormModal({ open, @@ -46,11 +48,24 @@ export function CreateDailyPlanFormModal({ const [date, setDate] = useState(new Date(tomorrowDate)); const [selectedEmployee, setSelectedEmployee] = useState(isManagerConnectedUser); + const [isOpen, setIsOpen] = useState(false); const handleMemberClick = useCallback((member: OT_Member) => { setSelectedEmployee(member); }, []); + const handleCloseModal = useCallback(() => { + closeModal(); + }, [closeModal]); + + const handleSelect = useCallback(() => { + reset(); + }, [reset]); + + const handleSelectAndClose = useCallback(() => { + handleCloseModal(); + }, [handleCloseModal]); + const onSubmit = useCallback( async (values: any) => { const toDay = new Date(); @@ -69,7 +84,6 @@ export function CreateDailyPlanFormModal({ organizationId: user?.employee.organizationId }).then(() => { reset(); - closeModal(); }); }, [ @@ -81,20 +95,19 @@ export function CreateDailyPlanFormModal({ user?.employee.organizationId, employeeId, selectedEmployee?.employeeId, - reset, - closeModal + reset ] ); return ( - +
{/* Form header */}
- Plan this task for {moment(date).format('DD.MM.YYYY').toString()} + Select Date
@@ -135,15 +148,56 @@ export function CreateDailyPlanFormModal({ > Cancel - +
+ + {isOpen && ( +
+
+ + +
+
+ )} +
diff --git a/apps/web/lib/features/task/task-card.tsx b/apps/web/lib/features/task/task-card.tsx index 7ccd4b84a..01d918240 100644 --- a/apps/web/lib/features/task/task-card.tsx +++ b/apps/web/lib/features/task/task-card.tsx @@ -537,13 +537,14 @@ function TaskCardMenu({ ); const allPlans = [...todayPlan, ...futurePlans]; - const isTaskPlannedMultipleTimes = allPlans.reduce((count, plan) => { - if (plan?.tasks) { - const taskCount = plan.tasks.filter(_task => _task.id === task.id).length; - return count + taskCount; - } - return count; - }, 0) > 1; + const isTaskPlannedMultipleTimes = + allPlans.reduce((count, plan) => { + if (plan?.tasks) { + const taskCount = plan.tasks.filter((_task) => _task.id === task.id).length; + return count + taskCount; + } + return count; + }, 0) > 1; const taskPlannedTomorrow = useMemo( () => @@ -667,7 +668,8 @@ function TaskCardMenu({ task={task} member={profile?.member} /> - )} + + )} ) : ( <> @@ -753,7 +755,15 @@ export function PlanTask({ }; return ( - <> +
+ - +
); }