Skip to content
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

Implement rocket booking cancelation #38

Merged
merged 3 commits into from
Jul 25, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d
- [x] **Use Redux to manage the states of rockets, missions**
- [x] **Fetch data using the spaceX API**
- [x] **Add actions and other functionality to Reserve Rocket**
- [ ] **Add actions and other functionality to Cancel Reservation**
- [x] **Add actions and other functionality to Cancel Reservation**
- [x] **Add actions and other functionality to Join Missions**
- [ ] **Add actions and other functionality to Leave Missions**
- [x] **Add actions and other functionality to Leave Missions**
- [ ] **Create the list of My Missions and My Rockets in the My Profile view**
- [ ] **Add CSS styles to the UI following the mobile first approach**
- [ ] **Create Unit tests using Jest and React testing library**
Expand Down
7 changes: 6 additions & 1 deletion src/components/RocketItem.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useDispatch } from 'react-redux';
import PropTypes from 'prop-types';
import { addReserve } from '../redux/rockets/rocketsSlice';
import { addReserve, cancelReserve } from '../redux/rockets/rocketsSlice';

const RocketItem = ({ rocket }) => {
const dispatch = useDispatch();
const handleClickAddReserve = () => {
dispatch(addReserve(rocket.id));
};

const handleClickCancelReserve = () => {
dispatch(cancelReserve(rocket.id));
};

return (
<div className="rocket-item">
<div className="rocket-image">
Expand All @@ -20,6 +24,7 @@ const RocketItem = ({ rocket }) => {
</p>
<div className="reserve">
<button type="button" className="btn btn-blue" onClick={handleClickAddReserve}>Reserve Rocket</button>
<button type="button" className="btn btn-gray" onClick={handleClickCancelReserve}>Cancel Reservation</button>
</div>
</div>
</div>
Expand Down
11 changes: 10 additions & 1 deletion src/redux/rockets/rocketsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ const rocketsSlice = createSlice({
});
state.rockets = newRocketState;
},
cancelReserve: (state, action) => {
const newRocketState = state.rockets.map((rocket) => {
if (rocket.id === action.payload) {
return { ...rocket, reserved: false };
}
return rocket;
});
state.rockets = newRocketState;
},
},
extraReducers: (builder) => {
builder
Expand Down Expand Up @@ -61,5 +70,5 @@ const rocketsSlice = createSlice({
},
});

export const { addReserve } = rocketsSlice.actions;
export const { addReserve, cancelReserve } = rocketsSlice.actions;
export default rocketsSlice.reducer;