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

Milestone 9 : Create event handlers for the buttons #33

Merged
merged 1 commit into from
Jul 19, 2022
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
10 changes: 10 additions & 0 deletions src/Redux/Missions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ const loadMissions = (payload) => ({
payload,
});

export const joinMission = (id) => ({
type: JOIN_MISSION,
id,
});

export const leaveMission = (id) => ({
type: LEAVE_MISSION,
id,
});

export const fetchMissions = async (dispatch) => {
const response = await fetch(BASE_URL);
const missions = await response.json();
Expand Down
19 changes: 15 additions & 4 deletions src/components/Missions/Missions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Table from "react-bootstrap/Table";
import Badge from "react-bootstrap/Badge";
import Button from "react-bootstrap/Button";
import { useSelector, useDispatch } from "react-redux";
import { fetchMissions } from "../../Redux/Missions";
import { fetchMissions, joinMission, leaveMission } from "../../Redux/Missions";

const Missions = () => {
const dispatch = useDispatch();
Expand All @@ -19,6 +19,9 @@ const Missions = () => {
}
}, []);

const joinMissionHandler = (id) => dispatch(joinMission(id));
const leaveMissionHandler = (id) => dispatch(leaveMission(id));

return (
<Container>
<Table striped bordered hover>
Expand All @@ -42,17 +45,25 @@ const Missions = () => {
<p>{description}</p>
</td>
<td className="align-middle">
{reserved && <Badge bg="info">Active Member</Badge>}
{reserved && <Badge bg="success">Active Member</Badge>}
{!reserved && <Badge bg="secondary">NOT A MEMBER</Badge>}
</td>
<td className="col-2 align-middle text-center">
{reserved && (
<Button size="sm" variant="outline-danger">
<Button
size="sm"
variant="outline-danger"
onClick={() => leaveMissionHandler(id)}
>
Leave Mission
</Button>
)}
{!reserved && (
<Button size="sm" variant="outline-secondary">
<Button
size="sm"
variant="outline-secondary"
onClick={() => joinMissionHandler(id)}
>
Join Mission
</Button>
)}
Expand Down