From 3dfd8392ef6c52ae33bcc4fbb5120a0b36201e22 Mon Sep 17 00:00:00 2001
From: Haakon Tideman Kanter <haakotka@stud.ntnu.no>
Date: Tue, 3 May 2022 15:15:06 +0200
Subject: [PATCH] Added member requests for admin in private groups

---
 src/components/CommunityComponents/MemberList.vue |  9 ++++++++-
 src/utils/apiutil.js                              | 13 +++++++++++++
 src/views/CommunityViews/AdminView.vue            |  4 ++--
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/components/CommunityComponents/MemberList.vue b/src/components/CommunityComponents/MemberList.vue
index a201e1d..bf2d75a 100644
--- a/src/components/CommunityComponents/MemberList.vue
+++ b/src/components/CommunityComponents/MemberList.vue
@@ -10,6 +10,7 @@
 <script>
 import UserListItemCard from "@/components/UserProfileComponents/UserListItemCard.vue";
 import CommunityService from "@/services/community.service";
+import {GetMemberRequestsOfCommunity} from "@/utils/apiutil";
 
 export default {
   name: "MemberList",
@@ -18,6 +19,7 @@ export default {
   },
   props: {
     buttons: Array,
+    requests: Boolean,
   },
   data() {
     return {
@@ -30,9 +32,14 @@ export default {
   },
   async created() {
     this.loading = true;
-    this.members = await CommunityService.getCommunityMembers(
+    if(this.requests){
+       this.members = await GetMemberRequestsOfCommunity(
       this.$route.params.communityID
     );
+    } else {
+    this.members = await CommunityService.getCommunityMembers(
+      this.$route.params.communityID 
+    );}
     this.loading = false;
   },
 };
diff --git a/src/utils/apiutil.js b/src/utils/apiutil.js
index d77f41d..7193b8a 100644
--- a/src/utils/apiutil.js
+++ b/src/utils/apiutil.js
@@ -237,6 +237,19 @@ export async function GetMembersOfCommunity(communityID) {
     });
 }
 
+export async function GetMemberRequestsOfCommunity(communityID) {
+  return axios
+    .get(API_URL + "communities/" + communityID + "/requests", {
+      headers: tokenHeader(),
+    })
+    .then((response) => {
+      return response.data;
+    })
+    .catch((error) => {
+      console.error(error);
+    });
+}
+
 export function JoinOpenCommunity(communityId) {
   if (tokenHeader().Authorization == "Bearer " + null) {
     //console.log("ikke logget på!");
diff --git a/src/views/CommunityViews/AdminView.vue b/src/views/CommunityViews/AdminView.vue
index cd801eb..4c7fa00 100644
--- a/src/views/CommunityViews/AdminView.vue
+++ b/src/views/CommunityViews/AdminView.vue
@@ -13,8 +13,8 @@
       {{ tab }}
     </button>
   </div>
-  <MemberList :buttons="['chat', 'kick']" v-if="currentTab === 0" />
-  <MemberList :buttons="['accept', 'reject']" v-if="currentTab === 1" />
+  <MemberList :requests ='false' :buttons="['chat', 'kick']" v-if="currentTab === 0" />
+  <MemberList :requests ='true' :buttons="['accept', 'reject']" v-if="currentTab === 1" />
   <CommunitySettings v-if="currentTab === 2" />
 </template>
 
-- 
GitLab