From 4a8a367b50e2a0e9646f9b6b3febc8db27667b7a Mon Sep 17 00:00:00 2001 From: Arpit Chakraborty Date: Thu, 26 Dec 2024 15:22:54 +0530 Subject: [PATCH] Updated handlechange to contron date selection --- src/screens/UserPortal/Settings/Settings.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/screens/UserPortal/Settings/Settings.tsx b/src/screens/UserPortal/Settings/Settings.tsx index 2c382d412b..385c3d639e 100644 --- a/src/screens/UserPortal/Settings/Settings.tsx +++ b/src/screens/UserPortal/Settings/Settings.tsx @@ -126,6 +126,19 @@ export default function settings(): JSX.Element { * @param value - The new value for the field. */ const handleFieldChange = (fieldName: string, value: string): void => { + // If the field is 'birthDate', validate the date + if (fieldName === 'birthDate') { + const today = new Date(); + const selectedDate = new Date(value); + + // Prevent updating the state if the selected date is in the future + if (selectedDate > today) { + console.error('Future dates are not allowed for the birth date.'); + return; // Exit without updating the state + } + } + + // Update state if the value passes validation setisUpdated(true); setUserDetails((prevState) => ({ ...prevState,