mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-27 05:23:06 +00:00
delete user
This commit is contained in:
@@ -3,14 +3,17 @@ import { FC, useEffect, useState } from 'react';
|
|||||||
import Api from '../../../helpers/api';
|
import Api from '../../../helpers/api';
|
||||||
import { useCommonStyles } from '../../../helpers/commonStyle';
|
import { useCommonStyles } from '../../../helpers/commonStyle';
|
||||||
import ConfirmationModal from '../../UI/Modals/ConfirmationModal';
|
import ConfirmationModal from '../../UI/Modals/ConfirmationModal';
|
||||||
|
import {toast} from "react-toastify";
|
||||||
import SelectList from '../../UI/SelectList';
|
import SelectList from '../../UI/SelectList';
|
||||||
import './AddUserModal.sass';
|
import './AddUserModal.sass';
|
||||||
import spinner from "../../assets/spinner.svg";
|
import spinner from "../../assets/spinner.svg";
|
||||||
|
import { values } from 'mobx';
|
||||||
|
|
||||||
export type UserData = {
|
export type UserData = {
|
||||||
role:string;
|
role:string;
|
||||||
username : string;
|
username : string;
|
||||||
workspace : string;
|
workspace : string;
|
||||||
|
userId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AddUserModalProps {
|
interface AddUserModalProps {
|
||||||
@@ -53,26 +56,37 @@ export const AddUserModal: FC<AddUserModalProps> = ({isOpen, onCloseModal, userD
|
|||||||
"id": "c7ad9158-d840-46c0-b5ce-2487c013723f",
|
"id": "c7ad9158-d840-46c0-b5ce-2487c013723f",
|
||||||
"name": "test"
|
"name": "test"
|
||||||
}
|
}
|
||||||
]//{"default":true} //await api.getWorkspaces()
|
].map((obj) => {return {key:obj.id, value:obj.name,isChecked:false}})
|
||||||
setWorkspaces(workspacesList)
|
//await api.getWorkspaces()
|
||||||
|
setWorkspaces(workspacesList)
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
toast.error("Error finding workspaces")
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
},[])
|
},[])
|
||||||
|
|
||||||
useEffect(()=> {
|
useEffect(()=> {
|
||||||
setUserData(userData as UserData)
|
(async () => {
|
||||||
|
try {
|
||||||
|
//if edit
|
||||||
|
// const userDetails = await api.getUserDetails(userData)
|
||||||
|
// setUserData(userDetails)
|
||||||
|
setUserData(userData as UserData)
|
||||||
|
} catch (e) {
|
||||||
|
toast.error("Error getting user details")
|
||||||
|
}
|
||||||
|
})();
|
||||||
},[userData])
|
},[userData])
|
||||||
|
|
||||||
// const onClose = () => {
|
// const onClose = () => {
|
||||||
// setIsOpen(false)
|
// setIsOpen(false)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const onConfirm = () => {
|
const onClose = () => {
|
||||||
setUserData({} as UserData)
|
|
||||||
onCloseModal()
|
onCloseModal()
|
||||||
|
setUserData({} as UserData)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspaceChange = (newVal) => {
|
const workspaceChange = (newVal) => {
|
||||||
@@ -105,18 +119,20 @@ export const AddUserModal: FC<AddUserModalProps> = ({isOpen, onCloseModal, userD
|
|||||||
const setGenarateDisabledState = () => {
|
const setGenarateDisabledState = () => {
|
||||||
const isValid = isFormValid()
|
const isValid = isFormValid()
|
||||||
setDisable(!isValid)
|
setDisable(!isValid)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const generateLink = () => {
|
const generateLink = () => {
|
||||||
try {
|
try {
|
||||||
//const res = await api.genareteInviteLink(userDataModel)
|
//const res = await api.genareteInviteLink(userDataModel)
|
||||||
//setInvite({...invite,isSuceeded:true,sent:true,link:res})
|
//setInvite({...invite,isSuceeded:true,sent:true,link:res})
|
||||||
|
//toast.success("User has been added")
|
||||||
|
|
||||||
|
//if edit
|
||||||
|
api.updateUser(userDataModel)
|
||||||
setInvite({...invite,isSuceeded:true,sent:true,link:"asdasdasdasdasdasdasdasdads"})
|
setInvite({...invite,isSuceeded:true,sent:true,link:"asdasdasdasdasdasdasdasdads"})
|
||||||
setShowAlert({open:true,sevirity:"error"})
|
toast.success("User has been modified")
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setShowAlert({open:true,sevirity:"error"})
|
toast.error("Error accrued generating link")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -148,7 +164,7 @@ export const AddUserModal: FC<AddUserModalProps> = ({isOpen, onCloseModal, userD
|
|||||||
label="Invite link"
|
label="Invite link"
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<Button style={{height: '100%'}} className={classes.button} size={"small"} onClick={onConfirm}>
|
<Button style={{height: '100%'}} className={classes.button} size={"small"} onClick={onClose}>
|
||||||
Done
|
Done
|
||||||
</Button>
|
</Button>
|
||||||
</div>}
|
</div>}
|
||||||
@@ -156,7 +172,7 @@ export const AddUserModal: FC<AddUserModalProps> = ({isOpen, onCloseModal, userD
|
|||||||
|
|
||||||
return (<>
|
return (<>
|
||||||
|
|
||||||
<ConfirmationModal isOpen={isOpen} onClose={onCloseModal} onConfirm={onConfirm} title='Add User' customActions={modalCustomActions}>
|
<ConfirmationModal isOpen={isOpen} onClose={onClose} onConfirm={onClose} title='Add User' customActions={modalCustomActions}>
|
||||||
|
|
||||||
<h3 className='comfirmation-modal__sub-section-header'>DETAILS</h3>
|
<h3 className='comfirmation-modal__sub-section-header'>DETAILS</h3>
|
||||||
<div className='comfirmation-modal__sub-section'>
|
<div className='comfirmation-modal__sub-section'>
|
||||||
|
@@ -3,6 +3,8 @@ import {ColsType, FilterableTableAction} from "../UI/FilterableTableAction"
|
|||||||
// import Api from "../../helpers/api"
|
// import Api from "../../helpers/api"
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { UserData,AddUserModal } from "../Modals/AddUserModal/AddUserModal";
|
import { UserData,AddUserModal } from "../Modals/AddUserModal/AddUserModal";
|
||||||
|
import Api from '../../helpers/api';
|
||||||
|
|
||||||
import {Snackbar} from "@material-ui/core";
|
import {Snackbar} from "@material-ui/core";
|
||||||
import MuiAlert from "@material-ui/lab/Alert";
|
import MuiAlert from "@material-ui/lab/Alert";
|
||||||
import { Select } from "../UI/Select";
|
import { Select } from "../UI/Select";
|
||||||
@@ -10,17 +12,19 @@ import { MenuItem } from "@material-ui/core";
|
|||||||
import { settings } from "cluster";
|
import { settings } from "cluster";
|
||||||
import { SettingsModal } from "../SettingsModal/SettingModal";
|
import { SettingsModal } from "../SettingsModal/SettingModal";
|
||||||
import OasModal from "../Modals/OasModal/OasModal";
|
import OasModal from "../Modals/OasModal/OasModal";
|
||||||
|
import { apiDefineProperty } from "mobx/dist/internal";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// const api = Api.getInstance();
|
const api = Api.getInstance();
|
||||||
|
|
||||||
export const UserSettings : React.FC<Props> = ({}) => {
|
export const UserSettings : React.FC<Props> = ({}) => {
|
||||||
|
|
||||||
const [usersRows, setUserRows] = useState([]);
|
const [usersRows, setUserRows] = useState([]);
|
||||||
const [userData,SetUsetData] = useState({} as UserData)
|
const [userData,userUserData] = useState({} as UserData)
|
||||||
const cols : ColsType[] = [{field : "username",header:"User"},
|
const cols : ColsType[] = [{field : "username",header:"User"},
|
||||||
{field : "role",header:"Role"},
|
{field : "role",header:"Role"},
|
||||||
{field : "status",header:"Status",getCellClassName : (field, val) =>{
|
{field : "status",header:"Status",getCellClassName : (field, val) =>{
|
||||||
@@ -33,7 +37,8 @@ export const UserSettings : React.FC<Props> = ({}) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const users = [{username:"asd",role:"Admin",status:"Active"}]//await api.getUsers()
|
const users = [{username:"asd",role:"Admin",status:"Active",userId : "1"},
|
||||||
|
{username:"aaaaaaa",role:"User",status:"Active",userId : "2"}]//await api.getUsers()
|
||||||
setUserRows(users)
|
setUserRows(users)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@@ -43,21 +48,32 @@ export const UserSettings : React.FC<Props> = ({}) => {
|
|||||||
|
|
||||||
const filterFuncFactory = (searchQuery: string) => {
|
const filterFuncFactory = (searchQuery: string) => {
|
||||||
return (row) => {
|
return (row) => {
|
||||||
return row.username.toLowerCase().includes(searchQuery.toLowerCase())
|
return row.username.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
|
row.userId.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchConfig = { searchPlaceholder: "Search User",filterRows: filterFuncFactory}
|
const searchConfig = { searchPlaceholder: "Search User",filterRows: filterFuncFactory}
|
||||||
|
|
||||||
const onRowDelete = (row) => {
|
const onRowDelete = (user) => {
|
||||||
const filterFunc = filterFuncFactory(row.username)
|
const findFunc = filterFuncFactory(user.userId);
|
||||||
const newUserList = usersRows.filter(filterFunc)
|
const userToDelete = usersRows.find(findFunc);
|
||||||
setUserRows(newUserList)
|
(async() => {
|
||||||
|
try {
|
||||||
|
//await api.deleteUser(user)
|
||||||
|
const usersLeft = usersRows.filter(e => !findFunc(e))
|
||||||
|
setUserRows(usersLeft)
|
||||||
|
toast.success("User Deleted succesesfully")
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("User want not deleted")
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const onRowEdit = (row) => {
|
const onRowEdit = (row) => {
|
||||||
//SetUsetData(row)
|
userUserData(row)
|
||||||
//setIsOpen(true)
|
setIsOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -68,14 +84,14 @@ export const UserSettings : React.FC<Props> = ({}) => {
|
|||||||
<FilterableTableAction onRowEdit={onRowEdit} onRowDelete={onRowDelete} searchConfig={searchConfig}
|
<FilterableTableAction onRowEdit={onRowEdit} onRowDelete={onRowDelete} searchConfig={searchConfig}
|
||||||
buttonConfig={buttonConfig} rows={usersRows} cols={cols}>
|
buttonConfig={buttonConfig} rows={usersRows} cols={cols}>
|
||||||
</FilterableTableAction>
|
</FilterableTableAction>
|
||||||
<AddUserModal isOpen={isOpenModal} onCloseModal={() => { setIsOpen(false); } } userData={userData} setShowAlert={setAlert}>
|
<AddUserModal isOpen={isOpenModal} onCloseModal={() => { setIsOpen(false);userUserData({} as UserData) } } userData={userData} setShowAlert={setAlert}>
|
||||||
</AddUserModal>
|
</AddUserModal>
|
||||||
<Snackbar open={alert.open} classes={{root: "alert--right"}}>
|
{/* <Snackbar open={alert.open} classes={{root: "alert--right"}}>
|
||||||
<MuiAlert classes={{filledWarning: 'customWarningStyle'}} elevation={6} variant="filled"
|
<MuiAlert classes={{filledWarning: 'customWarningStyle'}} elevation={6} variant="filled"
|
||||||
onClose={() => setAlert({...alert,open:false})} severity={"success"}>
|
onClose={() => setAlert({...alert,open:false})} severity={"success"}>
|
||||||
User has been added
|
User has been added
|
||||||
</MuiAlert>
|
</MuiAlert>
|
||||||
</Snackbar>
|
</Snackbar> */}
|
||||||
{/* <SettingsModal isOpen={false} onClose={function (): void {
|
{/* <SettingsModal isOpen={false} onClose={function (): void {
|
||||||
throw new Error("Function not implemented.");
|
throw new Error("Function not implemented.");
|
||||||
} } isFirstLogin={false}></SettingsModal> */}
|
} } isFirstLogin={false}></SettingsModal> */}
|
||||||
|
@@ -53,6 +53,21 @@ export default class Api {
|
|||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUserDetails = async(user) => {
|
||||||
|
const response = await this.client.get(`/user/${user.userId}`);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateUser = async(user) => {
|
||||||
|
const response = await this.client.put(`/user/${user.userId}`,user);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteUser = async(user) => {
|
||||||
|
const response = await this.client.delete(`/user/${user.userId}`);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
genareteInviteLink = async(userData) =>{
|
genareteInviteLink = async(userData) =>{
|
||||||
const response = await this.client.post(`/user/createUserAndInvite`,userData);
|
const response = await this.client.post(`/user/createUserAndInvite`,userData);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
Reference in New Issue
Block a user