Skip to content

Commit

Permalink
Merge pull request #36 from NitBravoA92/implement-mission-joining
Browse files Browse the repository at this point in the history
Implement mission joining functionality
  • Loading branch information
NitBravoA92 authored Jul 25, 2023
2 parents 6cf5cb5 + e0900df commit 08abfed
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d
- [x] **Create Rockets view**
- [x] **Use Redux to manage the states of rockets, missions**
- [x] **Fetch data using the spaceX API**
- [ ] **Add actions and other functionality to Join/Leave Missions**
- [ ] **Add actions and other functionality to Reserve Rocket and Cancel Reservation**
- [x] **Add actions and other functionality to Reserve Rocket**
- [ ] **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**
- [ ] **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
34 changes: 22 additions & 12 deletions src/components/MissionItem.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import { useDispatch } from 'react-redux';
import PropTypes from 'prop-types';
import { addReservedMission } from '../redux/missions/missionsSlice';

const MissionItem = ({ mission }) => (
<tr>
<td className="mission-name">{ mission.mission_name }</td>
<td className="mission-description">{ mission.description}</td>
<td className="mission-status">
<span className="badge badge-gray">Not a member</span>
</td>
<td className="mission-join-button">
<button type="button" className="btn btn-gray">Join Mission</button>
</td>
</tr>
);
const MissionItem = ({ mission }) => {
const dispatch = useDispatch();
const handleClickAddReservedMission = () => {
dispatch(addReservedMission(mission.mission_id));
};

return (
<tr>
<td className="mission-name">{ mission.mission_name }</td>
<td className="mission-description">{ mission.description}</td>
<td className="mission-status">
<span className="badge badge-gray">Not a member</span>
</td>
<td className="mission-join-button">
<button type="button" className="btn btn-gray" onClick={handleClickAddReservedMission}>Join Mission</button>
</td>
</tr>
);
};

MissionItem.propTypes = {
mission: PropTypes.shape({
mission_id: PropTypes.string.isRequired,
mission_name: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
reserved: PropTypes.bool,
}).isRequired,
};

Expand Down
13 changes: 12 additions & 1 deletion src/redux/missions/missionsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ const initialState = {
const missionsSlice = createSlice({
name: 'missions',
initialState,
reducers: {},
reducers: {
addReservedMission: (state, action) => {
const newMissionState = state.missions.map((mission) => {
if (mission.mission_id === action.payload) {
return { ...mission, reserved: true };
}
return mission;
});
state.missions = newMissionState;
},
},
extraReducers: (builder) => {
builder
.addCase(getAllMissions.pending, (state) => {
Expand All @@ -50,4 +60,5 @@ const missionsSlice = createSlice({
},
});

export const { addReservedMission } = missionsSlice.actions;
export default missionsSlice.reducer;

0 comments on commit 08abfed

Please sign in to comment.