Skip to content

My reservations feature #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed src/assets/reserve_page_background_option_2.png
Binary file not shown.
Binary file removed src/assets/reserve_page_background_option_3.jpg
Binary file not shown.
Binary file added src/assets/yellow-background-image-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 35 additions & 1 deletion src/components/MyReservations/MyReservationsList.js
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
// my reservations list component
import React, {useEffect} from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchCarReservations } from '../../redux/thunk';

const MyReservationsList = () => {
const dispatch = useDispatch();
const myReservations = useSelector((state) => state.reservation.reservations);
const status = useSelector((state) => state.reservation.status);
const error = useSelector((state) => state.reservation.error);

useEffect(() => {
dispatch(fetchCarReservations());
}, [dispatch]);

if (status === 'loading') {
return <p>Loading...</p>;
}

if (status === 'failed') {
return <p>Error: {error}</p>;
}

return (
<div>
<h1>My Reservations</h1>
{myReservations.map((reservation) => (
<div key={reservation.id}>
<p>{`Car: ${reservation.car.name}, Date: ${reservation.date}, City: ${reservation.city}`}</p>
</div>
))}
</div>
);
};

export default MyReservationsList;
9 changes: 6 additions & 3 deletions src/pages/Auth/SignIn/SignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import React from 'react';
import SignInForm from './SigninForm';

const SignIn = () => (
<div>
<h1>Login Page</h1>
<SignInForm />
<div className='signin-page-outer'>
<h1 id='login-title'>Sign in</h1>
<p className='user-headline'>Hello there! Sign in and start managing your application</p>
<div className='login-form-outer'>
<SignInForm />
</div>
</div>
);

Expand Down
9 changes: 6 additions & 3 deletions src/pages/Auth/SignUp/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { NavLink } from 'react-router-dom';
import SignUpForm from './SignupForm';

const SignUp = () => (
<div>
<h1>Signup page</h1>
<SignUpForm />
<div className='signup-page-outer'>
<h1 id='signup-title'>Sign up</h1>
<p className='user-headline'>Hello there! Register and start managing your application</p>
<div className='signup-form-outer'>
<SignUpForm />
</div>
<p>Have an existing account ?</p>
<NavLink to="/account/signin">
Log In
Expand Down
8 changes: 7 additions & 1 deletion src/pages/LandingPage/MyReservation/MyReservation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from 'react';
import MyReservationsList from '../../../components/MyReservations/MyReservationsList';

const MyReservations = () => <p>My Reservations</p>;
const MyReservations = () => (
<div className='my-reservations-page-outer'>
<h1>My Current Reservations</h1>
<MyReservationsList />
</div>
);

export default MyReservations;
15 changes: 14 additions & 1 deletion src/redux/reservations/reservationSlice.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createSlice } from '@reduxjs/toolkit';
import { postReserveCar } from '../thunk';
import { fetchCarReservations, postReserveCar } from '../thunk';

const initialState = {
reservation: {},
reservations: [],
status: 'idle',
error: null,
};
Expand All @@ -24,6 +25,18 @@ const reservationSlice = createSlice({
.addCase(postReserveCar.rejected, (state, action) => {
state.status = 'failed';
state.error = action.error.message;
})
.addCase(fetchCarReservations.pending, (state) => {
state.status = 'loading';
state.error = null;
})
.addCase(fetchCarReservations.fulfilled, (state, action) => {
state.status = 'succeeded';
state.reservations = action.payload.data;
})
.addCase(fetchCarReservations.rejected, (state, action) => {
state.status = 'failed';
state.error = action.error.message;
});
},
});
Expand Down
17 changes: 17 additions & 0 deletions src/redux/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,20 @@ export const postReserveCar = createAsyncThunk(
}
},
);

export const fetchCarReservations = createAsyncThunk(
'reservations/fetchCarReservations',
async (_, thunkAPI) => {
try {
const token = localStorage.getItem('token');
const response = await axios.get(`${baseURL}/my_reservations`, {
headers: {
Authorization: token,
},
});
return response.data;
} catch (error) {
return thunkAPI.rejectWithValue(error);
}
},
);
22 changes: 20 additions & 2 deletions src/styles/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,31 @@
font-family: 'Lato', sans-serif;
}

.signin-page-outer,
.signup-page-outer,
.my-reservations-page-outer {
background: #ffd700;
width: 100%;
height: 100vh;
display: flex;
gap: 2rem;
flex-direction: column;
align-items: center;
justify-content: center;
}

p.user-headline {
text-align: center;
width: 70%;
}

.reserve-car-outer {
background: url('../assets/reserve_page_background.png') center/cover;
background: url('../assets/yellow-background-image-2.png') center/cover;
height: 100vh;
}

.reserve-car-inner {
color: #fff;
color: #000;
width: 100%;
height: 100%;
display: flex;
Expand Down