From ea21a04d895f155ee277eae61b09e4f9a234b2d2 Mon Sep 17 00:00:00 2001 From: EyalIlan Date: Wed, 7 Dec 2022 19:32:25 +0200 Subject: [PATCH 1/2] add option to delete user from manager table --- .../adminManagement/AdminManagementForm.tsx | 12 +++++++++++- src/services/user.service.ts | 12 ++++++++++++ src/store/user.store.ts | 16 +++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/components/molecules/adminManagement/AdminManagementForm.tsx b/src/components/molecules/adminManagement/AdminManagementForm.tsx index 2b26f069..afba6050 100644 --- a/src/components/molecules/adminManagement/AdminManagementForm.tsx +++ b/src/components/molecules/adminManagement/AdminManagementForm.tsx @@ -1,5 +1,6 @@ import { observer } from 'mobx-react-lite'; import React from 'react'; +import Axios from 'axios' import DialogWithHeader from '../DialogWithHeader'; import { useTranslation } from 'react-i18next'; import { makeStyles } from '@material-ui/core/styles'; @@ -9,7 +10,7 @@ import RootStore from 'store/root.store'; import OverlayLoader from 'components/molecules/OverlayLoader'; import { StyledTableCell, StyledTableRow } from '../Table/TableView'; import { maxHeightTable } from 'style/_sizes'; -import { TableContainer, Button, Box, Table, TableBody, TableCell, TableHead, Theme } from '@material-ui/core'; +import { TableContainer, Button, Box, Table, TableBody, TableCell, TableHead, Theme,ButtonGroup } from '@material-ui/core'; import { blackColor } from 'style'; import { EditModeButtons } from './EditModeButtons'; import { OrganizationEditList } from './OrganizationEditList'; @@ -55,6 +56,10 @@ const AdminManagementForm: React.FC = ({ saveUserChanges, isShowing, onC addUserToUpdate[element.email] = element.name; setUsersForUpdate(addUserToUpdate); }; + const removeUser = async(element: ISingleOrgDetails) =>{ + + userStore.removeUser(element.email) + } return ( = ({ saveUserChanges, isShowing, onC /> ) : ( + + + )} diff --git a/src/services/user.service.ts b/src/services/user.service.ts index 91795e20..015e6d77 100644 --- a/src/services/user.service.ts +++ b/src/services/user.service.ts @@ -55,6 +55,18 @@ export const fetchUserInfo = async function (): Promise { return userInfo; }; + +export const removeUsersCall = async (email:string) =>{ + + try{ + const request = await axios.post('https://www.anyway.co.il/user/delete_user',{email}) + } + catch(e){ + console.log(e); + } +} + + export const addRoleToUser = async (role: string, email: string) => { try { await axios.post(ADD_ROLE_TO_USER_URL, { role, email }, { withCredentials: true }); diff --git a/src/store/user.store.ts b/src/store/user.store.ts index f96e2444..3a7f1b49 100644 --- a/src/store/user.store.ts +++ b/src/store/user.store.ts @@ -9,6 +9,7 @@ import { getUsersList, getOrganizationsDataList, updateUserOrganization, + removeUsersCall } from 'services/user.service'; import { IUserInfo } from 'models/user/IUserInfo'; import { ROLE_ADMIN_NAME } from 'const/generalConst'; @@ -17,7 +18,7 @@ import { IFormInput } from 'components/molecules/UserUpdateForm'; export default class UserStore { isUserAuthenticated: boolean = false; isAdmin: boolean = false; - usersInfoList: [IUserInfo] | null = null; + usersInfoList: Array | null = null; organizationsList: Array | null = null; userInfo: IAnywayUserDetails | null = null; userApiError: boolean = false; @@ -74,6 +75,19 @@ export default class UserStore { }); } + async removeUser (email:string) { + try{ + await removeUsersCall(email) + if(this.usersInfoList !== null && this.usersInfoList.length > 1){ + this.usersInfoList = this.usersInfoList.filter(p =>{ + return p.email !== email + }) + } + } + catch(e){ + console.log(e); + } + } getUserLoginDetails() { fetchUserInfo() .then((userData) => { From 4db679cc50d223a420e5b281cd2797f70ce3f9c7 Mon Sep 17 00:00:00 2001 From: EyalIlan Date: Tue, 20 Dec 2022 05:13:03 +0200 Subject: [PATCH 2/2] remove unused axios and request --- .../molecules/adminManagement/AdminManagementForm.tsx | 1 - src/services/user.service.ts | 2 +- src/store/user.store.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/molecules/adminManagement/AdminManagementForm.tsx b/src/components/molecules/adminManagement/AdminManagementForm.tsx index afba6050..904dc28a 100644 --- a/src/components/molecules/adminManagement/AdminManagementForm.tsx +++ b/src/components/molecules/adminManagement/AdminManagementForm.tsx @@ -1,6 +1,5 @@ import { observer } from 'mobx-react-lite'; import React from 'react'; -import Axios from 'axios' import DialogWithHeader from '../DialogWithHeader'; import { useTranslation } from 'react-i18next'; import { makeStyles } from '@material-ui/core/styles'; diff --git a/src/services/user.service.ts b/src/services/user.service.ts index 015e6d77..80e2eab7 100644 --- a/src/services/user.service.ts +++ b/src/services/user.service.ts @@ -59,7 +59,7 @@ export const fetchUserInfo = async function (): Promise { export const removeUsersCall = async (email:string) =>{ try{ - const request = await axios.post('https://www.anyway.co.il/user/delete_user',{email}) + await axios.post('https://www.anyway.co.il/user/delete_user',{email}) } catch(e){ console.log(e); diff --git a/src/store/user.store.ts b/src/store/user.store.ts index 3a7f1b49..ac713e2d 100644 --- a/src/store/user.store.ts +++ b/src/store/user.store.ts @@ -78,7 +78,7 @@ export default class UserStore { async removeUser (email:string) { try{ await removeUsersCall(email) - if(this.usersInfoList !== null && this.usersInfoList.length > 1){ + if(this.usersInfoList !== null && this.usersInfoList.length >= 1){ this.usersInfoList = this.usersInfoList.filter(p =>{ return p.email !== email })