user deactivation
parent
8b6f59b0f0
commit
7b3f892ed4
|
@ -8,7 +8,6 @@ import {
|
||||||
isEmailValid,
|
isEmailValid,
|
||||||
} from "../../utils";
|
} from "../../utils";
|
||||||
import { useContext, useState } from "react";
|
import { useContext, useState } from "react";
|
||||||
import { LockOutlined, MailOutlined, UserOutlined } from "@ant-design/icons";
|
|
||||||
|
|
||||||
export default function CreateUserModal({ isModalOpen, setIsModalOpen }) {
|
export default function CreateUserModal({ isModalOpen, setIsModalOpen }) {
|
||||||
const webSocketContext = useContext(WebSocketContext);
|
const webSocketContext = useContext(WebSocketContext);
|
||||||
|
|
|
@ -62,7 +62,8 @@ export default function AllUsers() {
|
||||||
hasOnePermission(
|
hasOnePermission(
|
||||||
webSocketContext.User.Permissions,
|
webSocketContext.User.Permissions,
|
||||||
Constants.PERMISSIONS.ALL_USERS.ACTION.CHANGE_ROLE,
|
Constants.PERMISSIONS.ALL_USERS.ACTION.CHANGE_ROLE,
|
||||||
Constants.PERMISSIONS.ALL_USERS.ACTION.DELETE_USER
|
Constants.PERMISSIONS.ALL_USERS.ACTION.DELETE_USER,
|
||||||
|
Constants.PERMISSIONS.ALL_USERS.ACTION.DEACTIVATE_USER
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
items.push({
|
items.push({
|
||||||
|
@ -161,9 +162,60 @@ export default function AllUsers() {
|
||||||
title="Are you sure you want to delete the user?"
|
title="Are you sure you want to delete the user?"
|
||||||
onConfirm={() => onUserDeletionConfirm(record.key)}
|
onConfirm={() => onUserDeletionConfirm(record.key)}
|
||||||
>
|
>
|
||||||
<Link to="#">Delete user</Link>
|
<Link to="#">Delete</Link>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!webSocketContext.AllUsers.find((user) => user.Id === record.key)
|
||||||
|
.Deactivated
|
||||||
|
? hasPermission(
|
||||||
|
webSocketContext.User.Permissions,
|
||||||
|
Constants.PERMISSIONS.ALL_USERS.ACTION.USER_DEACTIVATION
|
||||||
|
) &&
|
||||||
|
(webSocketContext.AllRoles.find(
|
||||||
|
(role) => role.Id === webSocketContext.User.RoleId
|
||||||
|
).SortingOrder <
|
||||||
|
webSocketContext.AllRoles.find(
|
||||||
|
(role) => role.Id === record._roleId
|
||||||
|
).SortingOrder ||
|
||||||
|
webSocketContext.AllRoles.find(
|
||||||
|
(role) => role.Id === webSocketContext.User.RoleId
|
||||||
|
).Master) && (
|
||||||
|
<Popconfirm
|
||||||
|
placement="top"
|
||||||
|
okText="Deactivate user"
|
||||||
|
title="Are you sure you want to deactivate the user?"
|
||||||
|
onConfirm={() =>
|
||||||
|
onUserDeactivationConfirm(record.key, true)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Link to="#">Deactivate</Link>
|
||||||
|
</Popconfirm>
|
||||||
|
)
|
||||||
|
: hasPermission(
|
||||||
|
webSocketContext.User.Permissions,
|
||||||
|
Constants.PERMISSIONS.ALL_USERS.ACTION.USER_DEACTIVATION
|
||||||
|
) &&
|
||||||
|
(webSocketContext.AllRoles.find(
|
||||||
|
(role) => role.Id === webSocketContext.User.RoleId
|
||||||
|
).SortingOrder <
|
||||||
|
webSocketContext.AllRoles.find(
|
||||||
|
(role) => role.Id === record._roleId
|
||||||
|
).SortingOrder ||
|
||||||
|
webSocketContext.AllRoles.find(
|
||||||
|
(role) => role.Id === webSocketContext.User.RoleId
|
||||||
|
).Master) && (
|
||||||
|
<Popconfirm
|
||||||
|
placement="top"
|
||||||
|
okText="Activate user"
|
||||||
|
title="Are you sure you want to activate the user?"
|
||||||
|
onConfirm={() =>
|
||||||
|
onUserDeactivationConfirm(record.key, false)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Link to="#">Activate</Link>
|
||||||
|
</Popconfirm>
|
||||||
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
@ -172,16 +224,23 @@ export default function AllUsers() {
|
||||||
return items;
|
return items;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTableItems = () => {
|
const activatedUsers = webSocketContext.AllUsers.filter(
|
||||||
|
(user) => user.Deactivated === false
|
||||||
|
);
|
||||||
|
const deactivatedUsers = webSocketContext.AllUsers.filter(
|
||||||
|
(user) => user.Deactivated === true
|
||||||
|
);
|
||||||
|
|
||||||
|
const getTableItems = (users) => {
|
||||||
let items = [];
|
let items = [];
|
||||||
|
|
||||||
webSocketContext.AllUsers.sort(
|
users.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
webSocketContext.AllRoles.find((r) => r.Id === a.RoleId).SortingOrder -
|
webSocketContext.AllRoles.find((r) => r.Id === a.RoleId).SortingOrder -
|
||||||
webSocketContext.AllRoles.find((r) => r.Id === b.RoleId).SortingOrder
|
webSocketContext.AllRoles.find((r) => r.Id === b.RoleId).SortingOrder
|
||||||
);
|
);
|
||||||
|
|
||||||
webSocketContext.AllUsers.forEach((user) => {
|
users.forEach((user) => {
|
||||||
items.push({
|
items.push({
|
||||||
key: user.Id,
|
key: user.Id,
|
||||||
avatar: (
|
avatar: (
|
||||||
|
@ -238,6 +297,16 @@ export default function AllUsers() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onUserDeactivationConfirm = (userId, deactivate) => {
|
||||||
|
webSocketContext.SendSocketMessage(
|
||||||
|
SentMessagesCommands.AllUsersUserDeactivation,
|
||||||
|
{
|
||||||
|
UserId: userId,
|
||||||
|
Deactivation: deactivate,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{notificationContextHolder}
|
{notificationContextHolder}
|
||||||
|
@ -250,7 +319,7 @@ export default function AllUsers() {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<h1 style={{ fontWeight: "bold" }}>
|
<h1 style={{ fontWeight: "bold" }}>
|
||||||
All users ({webSocketContext.AllUsers.length})
|
All users ({activatedUsers.length})
|
||||||
</h1>
|
</h1>
|
||||||
{hasPermission(
|
{hasPermission(
|
||||||
webSocketContext.User.Permissions,
|
webSocketContext.User.Permissions,
|
||||||
|
@ -265,7 +334,26 @@ export default function AllUsers() {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Table columns={getTableContent()} dataSource={getTableItems()} />
|
<Table
|
||||||
|
columns={getTableContent()}
|
||||||
|
dataSource={getTableItems(activatedUsers)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{hasPermission(
|
||||||
|
webSocketContext.User.Permissions,
|
||||||
|
Constants.PERMISSIONS.ALL_USERS.ACTION.USER_DEACTIVATION
|
||||||
|
) &&
|
||||||
|
deactivatedUsers.length > 0 && (
|
||||||
|
<>
|
||||||
|
<h1 style={{ fontWeight: "bold" }}>
|
||||||
|
Deactivated users ({deactivatedUsers.length})
|
||||||
|
</h1>
|
||||||
|
<Table
|
||||||
|
columns={getTableContent()}
|
||||||
|
dataSource={getTableItems(deactivatedUsers)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
<CreateUserModal
|
<CreateUserModal
|
||||||
isModalOpen={isCreateUserModalOpen}
|
isModalOpen={isCreateUserModalOpen}
|
||||||
|
|
|
@ -12,9 +12,17 @@ export default function Login() {
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
const [api, contextHolder] = notification.useNotification();
|
const [api, contextHolder] = notification.useNotification();
|
||||||
|
|
||||||
const showErrorNotification = () => {
|
const showErrorNotification = (errStatus) => {
|
||||||
|
if (errStatus === 401) {
|
||||||
|
api["error"]({
|
||||||
|
message: "Account deactivated",
|
||||||
|
description: "Please contact an administrator",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
api["error"]({
|
api["error"]({
|
||||||
message: "Login Failed!",
|
message: "Login failed",
|
||||||
description: "Please check your username and password!",
|
description: "Please check your username and password!",
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -49,10 +57,7 @@ export default function Login() {
|
||||||
setUserSessionToLocalStorage(data.Session);
|
setUserSessionToLocalStorage(data.Session);
|
||||||
window.location.href = "/";
|
window.location.href = "/";
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((errStatus) => showErrorNotification(errStatus));
|
||||||
console.error(err);
|
|
||||||
showErrorNotification();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
14
src/utils.js
14
src/utils.js
|
@ -54,6 +54,7 @@ export const Constants = {
|
||||||
ACTION: {
|
ACTION: {
|
||||||
CHANGE_ROLE: "all_users.action.change_role",
|
CHANGE_ROLE: "all_users.action.change_role",
|
||||||
DELETE_USER: "all_users.action.delete_user",
|
DELETE_USER: "all_users.action.delete_user",
|
||||||
|
USER_DEACTIVATION: "all_users.action.user_deactivation",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
SCANNER: {
|
SCANNER: {
|
||||||
|
@ -175,6 +176,7 @@ const ReceivedMessagesCommands = {
|
||||||
ErrorNoPermissions: 25,
|
ErrorNoPermissions: 25,
|
||||||
AllUsersNewUserCreated: 26,
|
AllUsersNewUserCreated: 26,
|
||||||
AllUsersUserDeleted: 27,
|
AllUsersUserDeleted: 27,
|
||||||
|
AllUsersUserDeactivation: 28,
|
||||||
};
|
};
|
||||||
|
|
||||||
// commands sent to the backend server
|
// commands sent to the backend server
|
||||||
|
@ -192,6 +194,7 @@ export const SentMessagesCommands = {
|
||||||
AllUsersUpdateUserRole: 11,
|
AllUsersUpdateUserRole: 11,
|
||||||
AllUsersCreateNewUser: 12,
|
AllUsersCreateNewUser: 12,
|
||||||
AllUsersDeleteUser: 13,
|
AllUsersDeleteUser: 13,
|
||||||
|
AllUsersUserDeactivation: 14,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function WebSocketProvider({
|
export function WebSocketProvider({
|
||||||
|
@ -814,6 +817,17 @@ export function WebSocketProvider({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ReceivedMessagesCommands.AllUsersUserDeactivation:
|
||||||
|
setAllUsers((arr) => {
|
||||||
|
let newArr = [...arr];
|
||||||
|
|
||||||
|
newArr[
|
||||||
|
newArr.findIndex((user) => user.Id === body.UserId)
|
||||||
|
].Deactivated = body.Deactivated;
|
||||||
|
|
||||||
|
return newArr;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.error("unknown command", cmd);
|
console.error("unknown command", cmd);
|
||||||
|
|
Loading…
Reference in New Issue