diff --git a/src/components/GameView.js b/src/components/GameView.js index 84dae802ec3a35a721eed87f4da1cc2100533dab..83ef4513152731bdef597ab8206eedd58b45a4f1 100644 --- a/src/components/GameView.js +++ b/src/components/GameView.js @@ -48,7 +48,31 @@ export default class GameView extends React.Component { .catch(error => console.log(error)); } - handleLeaveFaction = e => {}; + handleLeaveFaction = e => { + let token = sessionStorage.getItem("token"); + fetch( + `${process.env.REACT_APP_API_URL}/faction/leave/${ + this.state.gameInfo.id + }`, + { + method: "DELETE", + headers: { + Authorization: "Bearer " + token + } + } + ) + .then(res => { + if (res.ok) { + return res.json(); + } else { + throw Error(res.statusText); + } + }) + .then(res => { + alert(res.message); + }) + .catch(error => console.log(error)); + }; render() { const initialPosition = [this.state.lat, this.state.lng];