From 9137943cac1c0b878c051bcc28259ec9539cfe3f Mon Sep 17 00:00:00 2001 From: Joni Laukka <joni.laukka.overflow@gmail.com> Date: Mon, 15 Jul 2019 14:04:16 +0300 Subject: [PATCH] Leave faction --- src/components/GameView.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/components/GameView.js b/src/components/GameView.js index 84dae80..83ef451 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]; -- GitLab