From e42377dcd8e400e80acdc818992326561b93faf9 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Thu, 9 May 2024 20:18:32 +0530 Subject: [PATCH] sort filter done for vehicleVaiant page, AddProduct page ui updated, AddProduct toast updated --- client/src/App.jsx | 2 + client/src/components/Filter.jsx | 24 +- client/src/components/Sort.jsx | 6 +- .../admin/components/AddProductModal.jsx | 25 +- .../pages/admin/components/Addproductcopy.jsx | 453 ----------- client/src/pages/admin/pages/AllVehicles.jsx | 77 +- .../src/pages/user/AllVehiclesofSameModel.jsx | 216 +++--- .../user/AvailableVehiclesAfterSearch.jsx | 2 + client/src/pages/user/Vehicles.jsx | 332 ++++---- .../Components/VendorAddVehilceModal.jsx | 734 ++++++++++-------- .../Components/VendorDeleteVehicleModal.jsx | 4 +- .../pages/vendor/Components/VendorHeader.jsx | 41 + .../vendor/Dashboard/VendorDashboard.jsx | 2 +- .../vendor/data/vendorSidebarContents.jsx | 2 +- .../pages/vendor/pages/VendorAllVehicles.jsx | 7 +- .../adminDashboardSlice/StatusSlice.jsx | 20 +- client/src/redux/user/sortfilterSlice.jsx | 54 +- 17 files changed, 872 insertions(+), 1129 deletions(-) delete mode 100644 client/src/pages/admin/components/Addproductcopy.jsx create mode 100644 client/src/pages/vendor/Components/VendorHeader.jsx diff --git a/client/src/App.jsx b/client/src/App.jsx index 74bcf60..88b23a9 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -29,6 +29,7 @@ import CheckoutPage from "./pages/user/CheckoutPage"; import Razorpay from "./pages/user/Razorpay"; import AllVehiclesofSameModel from "./pages/user/AllVehiclesofSameModel"; import AddProductModal from "./pages/admin/components/AddProductModal"; +import VendorAddProductModal from "./pages/vendor/Components/VendorAddVehilceModal"; function App() { @@ -76,6 +77,7 @@ function App() { element={} /> } /> + } /> {/* admin private routes */} diff --git a/client/src/components/Filter.jsx b/client/src/components/Filter.jsx index 2bc41d3..ab021e5 100644 --- a/client/src/components/Filter.jsx +++ b/client/src/components/Filter.jsx @@ -5,18 +5,19 @@ import { GoPlus } from "react-icons/go"; import { Controller, useForm } from "react-hook-form"; import { useDispatch, useSelector } from "react-redux"; -// import { setFilter, setfilterData } from "../redux/user/sortfilterSlice"; import { setFilteredData } from "../redux/user/sortfilterSlice"; const Filter = () => { const { control, handleSubmit } = useForm(); - const { userAllVehicles } = useSelector((state) => state.userListVehicles); + const { userAllVehicles, allVariants } = useSelector( + (state) => state.userListVehicles + ); + const { variantMode } = useSelector((state) => state.sortfilterSlice); const dispatch = useDispatch(); let transformedData = []; const handleData = async (data) => { - console.log(data) const typeMapping = { suv: "car_type", sedan: "car_type", @@ -31,7 +32,7 @@ const Filter = () => { .filter(([key, value]) => value == true) .map(([key, value]) => ({ [key]: value, type: typeMapping[key] })); - if (transformedData && transformedData.length<=0 ) { + if (transformedData && transformedData.length <= 0 && !variantMode) { dispatch(setFilteredData(userAllVehicles)); } else if (transformedData && transformedData.length > 0) { try { @@ -46,6 +47,19 @@ const Filter = () => { if (res.ok) { const data = await res.json(); const filtData = data.data.filteredVehicles; + + //from filtData filtering vehicles that are available allVariants currently + //this is done when we have allVariants which means we are searching for available vehicles in Homepage and is redirected + if (allVariants) { + const filteredData = filtData.filter((data) => + allVariants.some((variant) => variant._id === data._id) + ); + dispatch(setFilteredData(filteredData)); + return; + } + + //this is in the other case when we are filtering from AllVehicles + //when we use filter from Vehicles in Navbar dispatch(setFilteredData(filtData)); } } catch (error) { @@ -108,9 +122,7 @@ const Filter = () => { {...field} checked={field["value"] ?? false} /> - )} - /> } label="Suv" diff --git a/client/src/components/Sort.jsx b/client/src/components/Sort.jsx index 884b674..9612691 100644 --- a/client/src/components/Sort.jsx +++ b/client/src/components/Sort.jsx @@ -7,7 +7,7 @@ import { useEffect } from "react"; import { setData, setFilteredData, setPriceHightoLow, setPriceLowtoHigh, setYearAscending, setYearDecending } from "../redux/user/sortfilterSlice"; const Sort = () => { - const {userAllVehicles} = useSelector(state => state.userListVehicles) + const {userAllVehicles,allVariants} = useSelector(state => state.userListVehicles) const dispatch = useDispatch(); const { handleSubmit, control } = useForm(); @@ -31,7 +31,9 @@ const Sort = () => { }; useEffect(()=> { - dispatch(setFilteredData(userAllVehicles)) + if(!allVariants){ + dispatch(setFilteredData(userAllVehicles)) + } },[]) return ( diff --git a/client/src/pages/admin/components/AddProductModal.jsx b/client/src/pages/admin/components/AddProductModal.jsx index 6969a07..f395aef 100644 --- a/client/src/pages/admin/components/AddProductModal.jsx +++ b/client/src/pages/admin/components/AddProductModal.jsx @@ -20,6 +20,7 @@ import { IoMdClose } from "react-icons/io"; import { LocalizationProvider } from "@mui/x-date-pickers"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; import { DatePicker } from "@mui/x-date-pickers/DatePicker"; +import { setLoading, setadminAddVehicleSuccess, setadminCrudError } from "../../../redux/adminSlices/adminDashboardSlice/StatusSlice"; export const fetchModelData = async (dispatch) => { try { @@ -74,13 +75,14 @@ export const fetchModelData = async (dispatch) => { }; const AddProductModal = () => { - const { register, handleSubmit, control } = useForm(); + const { register, handleSubmit, control , reset } = useForm(); const navigate = useNavigate(); const dispatch = useDispatch(); const { isAddVehicleClicked } = useSelector((state) => state.addVehicle); const { modelData, companyData, locationData, districtData } = useSelector( (state) => state.modelDataSlice ); + const {loading} = useSelector(state => state.statusSlice) useEffect(() => { fetchModelData(dispatch); @@ -88,7 +90,7 @@ const AddProductModal = () => { }, []); const onSubmit = async (addData) => { - console.log(addData.Registeration_end_date.$d) + try { const img = []; for (let i = 0; i < addData.image.length; i++) { @@ -117,16 +119,12 @@ const AddProductModal = () => { formData.append("location", addData.vehicleLocation); formData.append("district", addData.vehicleDistrict ); - - - - - - console.log(formData) + let tostID; if (formData) { tostID = toast.loading("saving...", { position: "bottom-center" }); + dispatch(setLoading(true)) } const res = await fetch("/api/admin/addProduct", { method: "POST", @@ -136,14 +134,17 @@ const AddProductModal = () => { if (!res.ok) { toast.error("error"); toast.dismiss(tostID); + dispatch(setLoading(false)) } if (res.ok) { - toast.success("added"); - toast.dismiss(tostID); + dispatch(setadminAddVehicleSuccess(true)); + toast.dismiss(tostID) + dispatch(setLoading(false)) } - // reset(); + reset(); } catch (error) { + dispatch(setadminCrudError(true)) console.log(error); } dispatch(addVehicleClicked(false)); @@ -156,7 +157,7 @@ const AddProductModal = () => { return ( <> - + {loading ? : null } {isAddVehicleClicked && (