From 48a9c883e7248a40e73f7c33ffdccce98486831b Mon Sep 17 00:00:00 2001
From: Joni Laukka <joni.laukka.overflow@gmail.com>
Date: Thu, 18 Jul 2019 11:09:06 +0300
Subject: [PATCH] Confirmation added to faction leaving

---
 src/components/GameView.js | 42 ++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/components/GameView.js b/src/components/GameView.js
index 2a0f890..f6b075e 100644
--- a/src/components/GameView.js
+++ b/src/components/GameView.js
@@ -67,27 +67,29 @@ export default class GameView extends React.Component {
   }
 
   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) {
+    if (window.confirm("Are you sure you want to leave your faction?")) {
+      let token = sessionStorage.getItem("token");
+      fetch(
+        `${process.env.REACT_APP_API_URL}/faction/leave/${
+          this.state.gameInfo.id
+        }`,
+        {
+          method: "DELETE",
+          headers: {
+            Authorization: "Bearer " + token
+          }
         }
-        return res.json();
-      })
-      .then(res => {
-        alert(res.message);
-      })
-      .catch(error => console.log(error));
+      )
+        .then(res => {
+          if (!res.ok) {
+          }
+          return res.json();
+        })
+        .then(res => {
+          alert(res.message);
+        })
+        .catch(error => console.log(error));
+    }
   };
 
   // setting the socket signal automatically fires shouldComponentUpdate function where socketSignal prop is present
-- 
GitLab