From 2392edeb48b1d8f4e191a84adb18962bcd320979 Mon Sep 17 00:00:00 2001
From: devendra <devendra@devendras-MacBook-Pro.local>
Date: Tue, 3 Jan 2023 17:16:41 +0530
Subject: [PATCH] Feat: Delete user- api integration

---
 src/constants/ApiConstants.ts  |  1 +
 src/layouts/reviewer/Users.tsx | 27 +++++++++++++++++++++++----
 src/services/user.service.js   | 12 ++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/src/constants/ApiConstants.ts b/src/constants/ApiConstants.ts
index b5d5239..81ce623 100644
--- a/src/constants/ApiConstants.ts
+++ b/src/constants/ApiConstants.ts
@@ -32,6 +32,7 @@ export const APIS = {
     CREATE_OR_UPDATE_USER: "user/createOrUpdate",
     GET_USER_BY_ID: "user/getUserById",
     GET_ALL_USERS: "user/v1/getAllUser",
+    DELETE_USER: "user/admin/deleteUser"
   },
   DASHBOARD: {
     GET_DASHBOARD_CONFIG: "dashboard/getDashboardConfig/SMF/home",
diff --git a/src/layouts/reviewer/Users.tsx b/src/layouts/reviewer/Users.tsx
index 6e14369..8dd8fcd 100644
--- a/src/layouts/reviewer/Users.tsx
+++ b/src/layouts/reviewer/Users.tsx
@@ -90,12 +90,27 @@ export const Users = ({ data }: userProps) => {
   };
 
   const deleteUser = () => {
-    console.log(userToDelete);
-    //Make api call to soft delete user
-    setShowConfirmModal(false);
+    UserService.deleteUser(userToDelete?.id).then(
+      (response) => {
+          if (response.statusInfo && response.statusInfo.statusCode === APP.CODE.SUCCESS) {
+              console.log(response.responseData);
+              Notify.success('User deleted successfully!');
+              getAllUsers();
+          } else {
+              Notify.error(response.statusInfo.errorMessage);
+          }
+          setShowConfirmModal(false);
+      },
+      (error) => {
+          error.statusInfo
+              ? Notify.error(error.statusInfo.errorMessage)
+              : Notify.error(error.message);
+          setShowConfirmModal(false);
+      }
+    );
   }
 
-  useEffect(() => {
+  const getAllUsers = () => {
     // get users
     UserService.getAllUsers().then(
       (response2) => {
@@ -115,6 +130,10 @@ export const Users = ({ data }: userProps) => {
           : Notify.error(error.message);
       }
     );
+  }
+
+  useEffect(() => {
+    getAllUsers();
      // eslint-disable-next-line react-hooks/exhaustive-deps
   }, []);
 
diff --git a/src/services/user.service.js b/src/services/user.service.js
index adf0321..38a253c 100644
--- a/src/services/user.service.js
+++ b/src/services/user.service.js
@@ -10,6 +10,7 @@ export const UserService = {
   createOrUpdateUser,
   getUserByID,
   getAllUsers,
+  deleteUser,
 };
 
 function login(username, otp) {
@@ -64,6 +65,17 @@ function createOrUpdateUser(user) {
   );
 }
 
+function deleteUser(userId) {
+  const requestOptions = {
+    method: APP.REQUEST.POST,
+    headers: authHeader(),
+    body: JSON.stringify({id: userId})
+  };
+  return fetch(APIS.BASE_URL + APIS.USER.DELETE_USER, requestOptions).then(
+    handleResponse
+  );
+}
+
 function getUserByID(id) {
   const requestOptions = {
     method: APP.REQUEST.GET,
-- 
GitLab