Skip to content

Commit

Permalink
Merge pull request #288 from lade6501/issue#237-past-date-selection
Browse files Browse the repository at this point in the history
Chore: fixed past date selection for reservation #237
  • Loading branch information
RamakrushnaBiswal authored Oct 18, 2024
2 parents 7dcc595 + 7f38ea3 commit 654d4bb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions frontend/src/components/Pages/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ 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('');
const [time, setTime] = useState('');
const [guests, setGuests] = useState();
const [minDate, setMinDate] = useState('');

const handleSubmit = (e) => {
console.log(guests);
Expand All @@ -35,8 +36,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);
message.warning('You cannot select a date before today.');
}
};

useEffect(() => {
window.scrollTo(0, 0);
const today = new Date().toISOString().split('T')[0];
setMinDate(today);
}, []);

return (
Expand Down Expand Up @@ -105,9 +116,10 @@ function Register() {
<input
type="date"
id="date"
onChange={(e) => {
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"
/>
</div>
Expand Down

0 comments on commit 654d4bb

Please sign in to comment.