Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to delete user from manager table #944

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/molecules/adminManagement/AdminManagementForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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';
Expand Down Expand Up @@ -55,6 +55,10 @@ const AdminManagementForm: React.FC<IProps> = ({ saveUserChanges, isShowing, onC
addUserToUpdate[element.email] = element.name;
setUsersForUpdate(addUserToUpdate);
};
const removeUser = async(element: ISingleOrgDetails) =>{

userStore.removeUser(element.email)
}
return (
<DialogWithHeader
fullWidth
Expand Down Expand Up @@ -110,9 +114,14 @@ const AdminManagementForm: React.FC<IProps> = ({ saveUserChanges, isShowing, onC
/>
) : (
<Box>
<ButtonGroup>
<Button onClick={() => addUsersToUpdate(item)} variant="contained">
{t('usersManagement.edit')}
</Button>
<Button onClick={() => removeUser(item)} variant="contained">
מחק
</Button>
</ButtonGroup>
</Box>
)}
</TableCell>
Expand Down
12 changes: 12 additions & 0 deletions src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ export const fetchUserInfo = async function (): Promise<IAnywayUserDetails> {
return userInfo;
};


export const removeUsersCall = async (email:string) =>{

try{
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 });
Expand Down
14 changes: 14 additions & 0 deletions src/store/user.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getUsersList,
getOrganizationsDataList,
updateUserOrganization,
removeUsersCall
} from 'services/user.service';
import { IUserInfo } from 'models/user/IUserInfo';
import { ROLE_ADMIN_NAME, ROLE_LOCATION_APPROVER_NAME } from 'const/generalConst';
Expand Down Expand Up @@ -83,6 +84,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) => {
Expand Down
Loading