Skip to content

Commit

Permalink
Updated handlechange to contron date selection
Browse files Browse the repository at this point in the history
  • Loading branch information
arpit-chakraborty committed Dec 26, 2024
1 parent 5ab9418 commit 4a8a367
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/screens/UserPortal/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4a8a367

Please sign in to comment.