Skip to content

Commit

Permalink
Fix deleteReservation
Browse files Browse the repository at this point in the history
  • Loading branch information
flemton committed Dec 17, 2023
1 parent 1237a24 commit ec3731c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/pages/ReservationsList/ReservationList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import Sidebar from '../../components/Sidebar/Sidebar';
import getUserReservations from '../../redux/requests/getUserReservations';
import { deleteReservation } from '../../redux/slices/reservationSlice';

const ReservationList = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -77,7 +78,7 @@ const ReservationList = () => {
{reservation.tesla_model.deposit}
</p>
</div>
<button type="button" className="btn btn-danger btn-text mt-2">
<button type="button" className="btn btn-danger btn-text mt-2" onClick={() => dispatch(deleteReservation(reservation.id))}>
Delete
</button>
</li>
Expand Down
13 changes: 7 additions & 6 deletions src/redux/slices/reservationSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ const reservationSlice = createSlice({
state.loading = true;
state.error = null;
})
.addCase(deleteReservation.fulfilled, (state, action) => {
state.loading = false;
state.reservations = state.reservations.filter(
(reservation) => reservation.reservation.id !== action.payload,
);
})
.addCase(deleteReservation.fulfilled, (state, action) => ({
...state,
loading: false,
reservations: state.reservations.filter(
(reservation) => reservation.id !== action.payload,
),
}))
.addCase(deleteReservation.rejected, (state, action) => {
state.loading = false;
state.error = action.error.message;
Expand Down

0 comments on commit ec3731c

Please sign in to comment.