The cars are being displayed even when the drop-off location isn't entered and also when both pick-up time and date is same as drop off time and date.
`const [showPickupCalendar, setShowPickupCalendar] = useState(false);
const [showDropoffCalendar, setShowDropoffCalendar] = useState(false);
const [showPickupTimetable, setShowPickupTimetable] = useState(false);
const [showDropoffTimetable, setShowDropoffTimetable] = useState(false);
const handlePickupDateChange = (date) => {
setPickupDate(date);
setDropoffDate(date); // Set dropoff date to pickup date initially
togglePickupCalendar();
};
The cars are being displayed even when the drop-off location isn't entered and also when both pick-up time and date is same as drop off time and date. `const [showPickupCalendar, setShowPickupCalendar] = useState(false); const [showDropoffCalendar, setShowDropoffCalendar] = useState(false); const [showPickupTimetable, setShowPickupTimetable] = useState(false); const [showDropoffTimetable, setShowDropoffTimetable] = useState(false);
const times = [ '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00','24:00' ];
const togglePickupCalendar = () => { setShowPickupCalendar(!showPickupCalendar); };
const toggleDropoffCalendar = () => { setShowDropoffCalendar(!showDropoffCalendar); };
const togglePickupTimetable = () => { setShowPickupTimetable(!showPickupTimetable); };
const toggleDropoffTimetable = () => { setShowDropoffTimetable(!showDropoffTimetable); };
const handlePickupDateChange = (date) => { setPickupDate(date); setDropoffDate(date); // Set dropoff date to pickup date initially togglePickupCalendar(); };
const handleDropoffDateChange = (date) => { setDropoffDate(date); toggleDropoffCalendar(); };
const handlePickupTimeChange = (time) => { setPickupTime(time); togglePickupTimetable(); };
const handleDropoffTimeChange = (time) => { setDropoffTime(time); toggleDropoffTimetable(); };
const [pickupInput, setPickupInput] = useState(""); const [pickupFilteredResults, setPickupFilteredResults] = useState([]); const [dropoffInput, setDropoffInput] = useState(""); const [dropoffFilteredResults, setDropoffFilteredResults] = useState([]);
const [pickupError, setPickupError] = useState(""); // Pickup location error message const [dropoffError, setDropoffError] = useState(""); // Dropoff location error message const [timeGapError, setTimeGapError] = useState(""); // Time gap error message
// Function to fetch data based on input value const fetchDate = (value, setterFunction, setFilteredResultsFunction) => { fetch("https://jsonplaceholder.typicode.com/users") .then((response) => response.json()) .then((json) => { const filteredResults = json.filter((user) => { return ( value && user && user.name && user.name.toLowerCase().includes(value.toLowerCase()) ); }); setFilteredResultsFunction(filteredResults); }); };
const handleInputChange = (value, setterFunction, setFilteredResultsFunction) => { const lowercaseValue = value.toLowerCase(); setterFunction(lowercaseValue); if (lowercaseValue.trim() === "") { setFilteredResultsFunction([]); return; } fetchDate(lowercaseValue, setterFunction, setFilteredResultsFunction); };
// Function to handle click on suggestion const handleSuggestionClick = (value, setterFunction, setFilteredResultsFunction) => { setterFunction(value); setFilteredResultsFunction([]); };
const navigate = useNavigate()
const handleSubmit = (e) => { e.preventDefault();
};
return (
Car hire for any kind of trip
Great deals at great prices
{pickupError}
} {pickupFilteredResults.length > 0 && ({pickupFilteredResults.map((user, index) => (- handleSuggestionClick(user.name, setPickupInput, setPickupFilteredResults)}>
{user.name}
))}
)} handleInputChange(e.target.value, setDropoffInput, setDropoffFilteredResults)} /> {dropoffError &&{dropoffError}
} {dropoffFilteredResults.length > 0 && ({dropoffFilteredResults.map((user, index) => (- handleSuggestionClick(user.name, setDropoffInput, setDropoffFilteredResults)}>
{user.name}
))}
)});`
On it shubham. Will let you know after the completion
The code is updated shubham.. You can test it now