diff --git a/src/components/Reservation/AddReserveForm.js b/src/components/Reservation/AddReserveForm.js index da6f163..8b85437 100644 --- a/src/components/Reservation/AddReserveForm.js +++ b/src/components/Reservation/AddReserveForm.js @@ -13,7 +13,7 @@ const AddReserveForm = () => { const [errorMessages, setErrorMessages] = React.useState([]); const { cars, reservations } = state; - const { user } = cars; + const { user } = state.user; const params = useParams(); const currentCar = cars.cars.find((car) => car.id === Number(params.carId)) || {}; const { @@ -32,9 +32,9 @@ const AddReserveForm = () => { const reservation = { ...data, user_id: user.id }; dispatch(createReserve(reservation)).then((response) => { if (response.type === 'reserve/createReserve/fulfilled') { - if (response.ok) { + if (response.payload.code === 200) { reset(); - navigate('/reservation-list'); + navigate('/cars/reservations'); } else { dispatch(isError(true)); setErrorMessages(response.payload.error); @@ -46,7 +46,7 @@ const AddReserveForm = () => { useEffect(() => () => { dispatch(addFromNav(false)); dispatch(isError(false)); - }, [reservations.addFromNav], dispatch); + }, [reservations.addFromNav, dispatch]); return (
diff --git a/src/components/reservation/Reservation.jsx b/src/components/Reservation/Reservation.js similarity index 91% rename from src/components/reservation/Reservation.jsx rename to src/components/Reservation/Reservation.js index c9a658b..d5b4ead 100644 --- a/src/components/reservation/Reservation.jsx +++ b/src/components/Reservation/Reservation.js @@ -12,6 +12,11 @@ function Reservations() {

Reservations

+ {reservations.length <= 0 && ( +
+

No reservations

+
+ )} {reservations.map((reservation) => (
diff --git a/src/components/Routing.js b/src/components/Routing.js index 78533f0..79bc6ec 100644 --- a/src/components/Routing.js +++ b/src/components/Routing.js @@ -7,6 +7,7 @@ import SignUpSuccesPage from './sign-in-sign-up/SignUpSuccesPage'; import CarsPage from './cars/CarsPage'; import Cars from './cars/Cars'; import CarsDetails from './cars/CarsDetails'; +import Unauthorized from './sign-in-sign-up/Unauthorized'; import Addcars from './cars/addcars'; import Delete from './cars/delete'; import AddReserveForm from './Reservation/AddReserveForm'; @@ -16,17 +17,18 @@ const Routing = () => ( } /> } /> + } /> } /> } /> }> } /> } /> + } /> + } /> + } /> + } /> + } /> - } /> - } /> - } /> - } /> - } /> 404: Not Found} /> ); diff --git a/src/components/cars/Carousel.js b/src/components/cars/Carousel.js index 29abefb..559dfc8 100644 --- a/src/components/cars/Carousel.js +++ b/src/components/cars/Carousel.js @@ -9,7 +9,6 @@ import CarCard from './CarCard'; const Carousel = () => { const carState = useSelector((state) => state.cars); - console.log(carState.cars); return ( { - const carState = useSelector((state) => state.cars); - const threeCars = carState.cars.slice(0, 3); - console.log(threeCars); + const navigate = useNavigate(); + const state = useSelector((state) => state); + const { cars } = state.cars; + const { user } = state; + // const threeCars = cars.slice(0, 3); + + useEffect(() => { + if (user.status === 'not-logged-in') { + navigate('/login'); + } + if (user.error === 'Unauthorized') { + navigate('/login'); + } + }, [user.status, user.error, navigate]); return (

Latest Models

Please select a car model

- { carState.cars.map((car) => ( + {(cars.length <= 0) && ( +
+

No Cars to show, Please add new car

+
+ )} + { cars.map((car) => (
{ e.preventDefault(); - console.log(car); dispatch(addcars(car)).then((response) => { const { code } = response.payload; if (code === 200) { diff --git a/src/components/navbar/Navbar.js b/src/components/navbar/Navbar.js index c26816d..7a3d273 100644 --- a/src/components/navbar/Navbar.js +++ b/src/components/navbar/Navbar.js @@ -12,6 +12,7 @@ import { HiMenu } from 'react-icons/hi'; import '../../styles/navbar.css'; import logo from '../../images/cars-bnb-logo.png'; import { addFromNav } from '../../redux/Reservations/ReserveSlice'; +import { logout } from '../../redux/Auth/authenticationSlice'; function Navbar() { const dispatch = useDispatch(); @@ -19,16 +20,25 @@ function Navbar() { return (
+
+ +
carsBnb Logo