From d02cdf0e0914f7b715501972caf0757837e3d9c5 Mon Sep 17 00:00:00 2001 From: lade6501 Date: Mon, 14 Oct 2024 23:55:05 +0530 Subject: [PATCH 1/2] Chore: fixed past date selection for reservation --- frontend/src/components/Pages/Register.jsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/Pages/Register.jsx b/frontend/src/components/Pages/Register.jsx index 906a3a15..6eb35073 100644 --- a/frontend/src/components/Pages/Register.jsx +++ b/frontend/src/components/Pages/Register.jsx @@ -8,10 +8,10 @@ import pic5 from '../../assets/img/abt4.png'; import MainHOC from '../MainHOC'; function Register() { - const [date, setDate] = useState(''); const [time, setTime] = useState(''); const [guests, setGuests] = useState(); + const [minDate, setMinDate] = useState(''); const handleSubmit = (e) => { console.log(guests); @@ -35,8 +35,18 @@ function Register() { .catch((error) => console.log(error)); }; + const handleDateValidation = () => { + if (date.length === 10 && date < minDate) { + // Reset to today's date if the selected date is invalid + setDate(minDate); + alert('You cannot select a date before today.'); + } + }; + useEffect(() => { window.scrollTo(0, 0); + const today = new Date().toISOString().split('T')[0]; + setMinDate(today); }, []); return ( @@ -105,9 +115,10 @@ function Register() { { - setDate(e.target.value); - }} + min={minDate} + value={date} + onChange={(e) => setDate(e.target.value)} + onBlur={handleDateValidation} className="flex h-10 w-full items-center rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50" /> From 7f38ea372ed97107830561e0d39b6ad482c5cec2 Mon Sep 17 00:00:00 2001 From: lade6501 Date: Wed, 16 Oct 2024 07:20:54 +0530 Subject: [PATCH 2/2] antd message for past date --- frontend/src/components/Pages/Register.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/Pages/Register.jsx b/frontend/src/components/Pages/Register.jsx index 6eb35073..665bdb30 100644 --- a/frontend/src/components/Pages/Register.jsx +++ b/frontend/src/components/Pages/Register.jsx @@ -6,6 +6,7 @@ import pic3 from '../../assets/img/abt2.png'; import pic4 from '../../assets/img/abt3.png'; import pic5 from '../../assets/img/abt4.png'; import MainHOC from '../MainHOC'; +import { message } from 'antd'; function Register() { const [date, setDate] = useState(''); @@ -39,7 +40,7 @@ function Register() { if (date.length === 10 && date < minDate) { // Reset to today's date if the selected date is invalid setDate(minDate); - alert('You cannot select a date before today.'); + message.warning('You cannot select a date before today.'); } };