diff --git a/src/frontend/src/components/browsingPage/SearchBox.jsx b/src/frontend/src/components/browsingPage/SearchBox.jsx index 713ade11..29c0c67f 100644 --- a/src/frontend/src/components/browsingPage/SearchBox.jsx +++ b/src/frontend/src/components/browsingPage/SearchBox.jsx @@ -7,7 +7,7 @@ import { branchContext } from "../../Pages/BrowsingPage"; export default function SearchBox() { const {branchName, setBranchName} = useContext(branchContext); - const [dateRange, setDateRange] = useState([new Date(), new Date()]); + const [dateRange, setDateRange] = useState([new Date(), new Date(new Date().setDate(new Date().getDate() + 7))]); const [expandMap, setExpandMap] = useState(false); diff --git a/src/frontend/src/components/browsingPage/SortFilterButtons.jsx b/src/frontend/src/components/browsingPage/SortFilterButtons.jsx index 5da907d4..2c4bcef2 100644 --- a/src/frontend/src/components/browsingPage/SortFilterButtons.jsx +++ b/src/frontend/src/components/browsingPage/SortFilterButtons.jsx @@ -1,6 +1,6 @@ import React, { useState, useRef } from 'react'; -export default function SortFilterButtons({ setVehicles, vehicles }) { +export default function SortFilterButtons({ allVehicles, sortedVehicles, setVehicles}) { const [isOpen1, setIsOpen1] = useState(false); const [selectedCategory1, setSelectedCategory1] = useState(null); @@ -16,12 +16,48 @@ export default function SortFilterButtons({ setVehicles, vehicles }) { const buttonRef4 = useRef(null); + const [filter , setFilter] = useState({ + numberOfSeats: null, + numberOfDoors: null, + price: null + }); + const resetAllFilters = () => { - setVehicles(vehicles); - handleCategoryClick1(null); - handleCategoryClick2(null); - handleCategoryClick3(null); + setSelectedCategory1(null); + setSelectedCategory2(null); + setSelectedCategory3(null); + setVehicles(allVehicles); } + const filterVehicles = (numberOfSeats, numberOfDoors, price) => { + setFilter({ + numberOfSeats: numberOfSeats, + numberOfDoors: numberOfDoors, + price: price + }); + let filteredVehicles = allVehicles; + if(numberOfSeats !== null){ + filteredVehicles = filteredVehicles.filter((vehicle) => vehicle.numberOfSeats === numberOfSeats); + } + if(numberOfDoors !== null){ + filteredVehicles = filteredVehicles.filter((vehicle) => vehicle.numberOfDoors === numberOfDoors); + } + + // sort the filtered vehicles + sortVehicles(filter.price); + + setVehicles(filteredVehicles); + } + + const sortVehicles = (price) => { + if(price !== null){ + if(price === 1){ + setVehicles(sortedVehicles.sort((a, b) => a.price - b.price)); + } + if(price === 2){ + setVehicles(sortedVehicles.sort((a, b) => b.price - a.price)); + } + } + } const toggleDropdown1 = () => { setIsOpen1(!isOpen1); @@ -35,51 +71,48 @@ export default function SortFilterButtons({ setVehicles, vehicles }) { setIsOpen3(!isOpen3); } - const handleCategoryClick1 = (category) => { + const handleFilterBySeats = (category) => { if(category!==null){ - const sortedVehicles = vehicles.filter((vehicle) => vehicle.numberOfSeats === category); - setVehicles(sortedVehicles); + // const sortedVehicles = vehicles.filter((vehicle) => vehicle.numberOfSeats === category); + // setVehicles(sortedVehicles); setSelectedCategory1(category + " seats"); - setIsOpen1(false); }else{ - setVehicles(vehicles); - setSelectedCategory1(category); - setIsOpen1(false); + // setVehicles(vehicles); + setSelectedCategory1(null); } - + setIsOpen1(false); + filterVehicles(category, filter.numberOfDoors, filter.price); }; - const handleCategoryClick2 = (category) => { + const handleFilterByDoors = (category) => { if(category!==null){ - const sortedVehicles = vehicles.filter((vehicle) => vehicle.numberOfDoors === category); - setVehicles(sortedVehicles); + // const sortedVehicles = vehicles.filter((vehicle) => vehicle.numberOfDoors === category); + // setVehicles(sortedVehicles); setSelectedCategory2(category + " Doors"); - setIsOpen2(false); }else{ - setVehicles(vehicles); - setSelectedCategory2(category); - setIsOpen2(false); + // setVehicles(vehicles); + setSelectedCategory2(null); } - + setIsOpen2(false); + filterVehicles(filter.numberOfSeats, category, filter.price); }; - const handleCategoryClick3 = (category) => { + const handleSortByPrice = (category) => { if(category!==null){ - const sortedVehicles = vehicles.filter((vehicle) => vehicle.price === category); - setVehicles(sortedVehicles); + // const sortedVehicles = vehicles.filter((vehicle) => vehicle.price === category); + // setVehicles(sortedVehicles); if(category === 1){ setSelectedCategory3("Low to High"); } if(category === 2){ setSelectedCategory3("High to Low"); } - setIsOpen3(false); }else{ - setVehicles(vehicles); - setSelectedCategory3(category); - setIsOpen3(false); + // setVehicles(vehicles); + setSelectedCategory3(null); } - + setIsOpen3(false); + filterVehicles(filter.numberOfSeats, filter.numberOfDoors, category); }; return ( @@ -113,35 +146,35 @@ export default function SortFilterButtons({ setVehicles, vehicles }) {
  • handleCategoryClick1(null)}> + onClick={() => handleFilterBySeats(null)}> Reset
  • handleCategoryClick1(2)}> + onClick={() => handleFilterBySeats(2)}> 2 seats
  • handleCategoryClick1(4)}> + onClick={() => handleFilterBySeats(4)}> 4 seats
  • handleCategoryClick1(5)}> + onClick={() => handleFilterBySeats(5)}> 5 seats
  • handleCategoryClick1(6)}> + onClick={() => handleFilterBySeats(6)}> 6 seats
  • @@ -174,21 +207,21 @@ export default function SortFilterButtons({ setVehicles, vehicles }) {
  • handleCategoryClick2(null)}> + onClick={() => handleFilterByDoors(null)}> Reset
  • handleCategoryClick2(2)}> + onClick={() => handleFilterByDoors(2)}> 2 Doors
  • handleCategoryClick2(4)}> + onClick={() => handleFilterByDoors(4)}> 4 Doors
  • @@ -196,7 +229,6 @@ export default function SortFilterButtons({ setVehicles, vehicles }) { )} - {/* Button 3 {isOpen3 && ( - +
    handleCategoryClick3(null)}> + onClick={() => handleSortByPrice(null)}> Reset
  • handleCategoryClick3(1)}> + onClick={() => handleSortByPrice(1)}> Low to High
  • handleCategoryClick3(2)}> + onClick={() => handleSortByPrice(2)}> High to Low
  • - )} */} + )} {/* Button 4 */} } - closeOnDocumentClick={false}> - {close => ( + {( <> { className: "signatureCanvas" }} /> - - - + )} - {imageURL1 ? ( { ) : null}
    - - -
    - - - -
    +
    + + + +
    +

    Renter

    - Electronic Signature: } - closeOnDocumentClick={false}> - {close => ( - <> - - - - - - )} - - {imageURL2 ? ( - my signature - ) : null} -
    - - - -
    - - - -
    + {( + <> + + + + )} + {imageURL1 ? ( + signature + ) : null} +
    + +
    + + + +
    +
    diff --git a/src/frontend/src/utilities/cancelReservation.js b/src/frontend/src/utilities/cancelReservation.js deleted file mode 100644 index 1c463133..00000000 --- a/src/frontend/src/utilities/cancelReservation.js +++ /dev/null @@ -1,20 +0,0 @@ -// import fetchData from "./fetchData" -// -// export default async function deleteReservation(reservationID){ -// -// const response = await fetchData(`http://localhost:3000/api/reservations/${reservationID}`, { -// method: "DELETE", -// mode: "cors", -// credentials: "include", -// headers: { -// "Content-Type": "application/json", -// "Authorization": `Bearer ${localStorage.getItem("token")}`, -// } -// }); -// if(response.data){ -// console.log("Successfully canceled the reservation") -// } -// else if(response.error){ -// alert("failed to cancel the reservation"); -// } -// } \ No newline at end of file diff --git a/src/frontend/src/utilities/createReservation.js b/src/frontend/src/utilities/createReservation.js deleted file mode 100644 index 62e4a9df..00000000 --- a/src/frontend/src/utilities/createReservation.js +++ /dev/null @@ -1,32 +0,0 @@ -// import fetchData from "./fetchData" -// -// -// -// export default async function createReservation(vin,userId,pickupDate,returnDate,addons){ -// -// const response = await fetchData(`http://localhost:3000/api/reservations/`, { -// method: "POST", -// mode: "cors", -// credentials: "include", -// headers: { -// "Content-Type": "application/json", -// "Authorization": `Bearer ${localStorage.getItem("token")}`, -// }, -// body: JSON.stringify({ -// vin:vin, -// reservationDate: new Date().toISOString(), -// pickupDate: new Date(pickupDate), // Convert string to Date object -// returnDate: new Date(returnDate), // Convert string to Date object -// userID: userId, -// addons: addons -// }) -// }); -// if(response.data){ -// console.log("Successfully created the reservation") -// return true; -// } -// else if(response.error){ -// alert("failed to create the reservation"); -// } -// return false; -// } \ No newline at end of file diff --git a/src/frontend/src/utilities/modifyReservation.js b/src/frontend/src/utilities/modifyReservation.js deleted file mode 100644 index 48533c96..00000000 --- a/src/frontend/src/utilities/modifyReservation.js +++ /dev/null @@ -1,38 +0,0 @@ -// import fetchData from "./fetchData" -// -// -// -// export default async function modifyReservation(reservationID,pickupDate,returnDate, addons, status){ -// -// const response = await fetchData(`http://localhost:3000/api/reservations/${reservationID}`, { -// method: "PUT", -// mode: "cors", -// credentials: "include", -// headers: { -// "Content-Type": "application/json", -// "Authorization": `Bearer ${localStorage.getItem("token")}`, -// }, -// body: JSON.stringify(getBody(pickupDate,returnDate, addons, status)) -// }); -// if(response.data){ -// console.log("Successfully modified the reservation") -// } -// else if(response.error){ -// alert("failed to modify the reservation"); -// } -// } -// -// function getBody(pickupDate,returnDate, addons, status){ -// if(addons==null || pickupDate==null || returnDate==null) { -// return { -// status: status -// }; -// }else{ -// return { -// pickupDate: pickupDate, -// returnDate: returnDate, -// status: status, -// addons: addons -// }; -// } -// } \ No newline at end of file