Commit 2392edeb authored by devendra's avatar devendra
Browse files

Feat: Delete user- api integration

1 merge request!10Delete user feature for super admin
Showing with 36 additions and 4 deletions
+36 -4
......@@ -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",
......
......@@ -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
}, []);
......
......@@ -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,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment