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

Joining mission #136

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
61 changes: 59 additions & 2 deletions src/pages/Missions/Missions.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
.mission {
display: flex;
table {
width: 92%;
margin: 5% auto;
border-collapse: collapse;
}

td {
text-align: start;
border: 1px solid #858484;
padding: 8px;
}

td:first-child {
font-weight: bold;
}

th {
font-weight: bold;
border: 1px solid #858484;
padding: 8px;
text-align: start;
}

tr:nth-child(even) {
background-color: #f0f0f0;
}

td p {
padding: 8px;
border-radius: 4px;
width: max-content;
text-align: center;
color: white;
cursor: pointer;
}

td p.active {
background-color: #419bf9;
}

td p.not-member {
background-color: #6d757d;
}

button {
padding: 8px 16px;
border: 1px solid #ccc;
border-radius: 4px;
cursor: pointer;
}

button.leave {
color: red;
border: 1px solid red;
}

button.join {
color: red;
border: 1px solid red;
}
38 changes: 35 additions & 3 deletions src/pages/Missions/Missions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchMissionAsync } from '../../redux/missionSlice';
import { fetchMissionAsync, joiningMission } from '../../redux/missionSlice';
import './Missions.css';

function Missions() {
Expand All @@ -25,9 +25,41 @@ function Missions() {
</div>
);
}
console.log('=======', missions);
return (
<></>
<table>
<thead>
<tr>
<th>Mission</th>
<th>Description</th>
<th>Status</th>
<th> </th>
</tr>
</thead>
<tbody className="border border-gray-300">
{missions.map((mission) => (
<tr key={mission.mission_id}>
<td>{mission.mission_name}</td>
<td>{mission.description}</td>
<td><p style={{ backgroundColor: mission.reserved ? '#419bf9' : '#6d757d' }}>{mission.reserved ? 'ACTIVE MEMBER' : 'NOT A MEMBER'}</p></td>
<td>
<button
type="button"
style={{ color: mission.reserved ? 'red' : '', border: mission.reserved ? '1px solid red' : '' }}
>
Leave Mission
</button>
<button
type="button"
style={{ color: mission.reserved ? 'red' : '', border: mission.reserved ? '1px solid red' : '' }}
onClick={() => dispatch(joiningMission(mission.mission_id))}
>
Join Mission
</button>
</td>
</tr>
))}
</tbody>
</table>
);
}

Expand Down
13 changes: 12 additions & 1 deletion src/redux/missionSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ export const fetchMissionAsync = createAsyncThunk(
const missionSlice = createSlice({
name: 'missions',
initialState,
reducers: {},
reducers: {
joiningMission: (state, action) => {
const id = action.payload;
state.missions = state.missions.map((mission) => {
if (mission.mission_id !== id) {
return mission;
}
return { ...mission, reserved: true };
});
},
},
extraReducers: (builder) => {
builder
.addCase(fetchMissionAsync.pending, (state) => {
Expand All @@ -37,4 +47,5 @@ const missionSlice = createSlice({
},
});

export const { joiningMission } = missionSlice.actions;
export default missionSlice.reducer;