2025-12-11 10:40:55 +01:00
|
|
|
/*
|
2026-01-12 15:00:36 +01:00
|
|
|
* Copyright (c) 2026 by Christian Kellner.
|
2025-12-11 10:40:55 +01:00
|
|
|
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2021-01-21 16:09:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
2026-01-22 16:09:36 +01:00
|
|
|
import { Toast } from '@douyinfe/semi-ui-19';
|
2021-01-21 16:09:23 +01:00
|
|
|
import UserTable from '../../components/table/UserTable';
|
2025-09-18 20:09:11 +02:00
|
|
|
import { useActions, useSelector } from '../../services/state/store';
|
2023-03-20 08:52:13 +01:00
|
|
|
import { IconPlus } from '@douyinfe/semi-icons';
|
2026-01-22 16:09:36 +01:00
|
|
|
import { Button } from '@douyinfe/semi-ui-19';
|
2021-01-21 16:09:23 +01:00
|
|
|
import UserRemovalModal from './UserRemovalModal';
|
|
|
|
|
import { xhrDelete } from '../../services/xhr';
|
2025-09-02 20:18:37 +02:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
2021-01-21 16:09:23 +01:00
|
|
|
|
|
|
|
|
import './Users.less';
|
|
|
|
|
|
|
|
|
|
const Users = function Users() {
|
2025-09-18 20:09:11 +02:00
|
|
|
const actions = useActions();
|
2021-01-21 16:09:23 +01:00
|
|
|
const [loading, setLoading] = React.useState(true);
|
|
|
|
|
const users = useSelector((state) => state.user.users);
|
|
|
|
|
const [userIdToBeRemoved, setUserIdToBeRemoved] = React.useState(null);
|
2025-09-02 20:18:37 +02:00
|
|
|
const navigate = useNavigate();
|
2021-01-21 16:09:23 +01:00
|
|
|
|
2022-12-19 21:10:00 +01:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
async function init() {
|
2025-09-18 20:09:11 +02:00
|
|
|
await actions.user.getUsers();
|
2022-12-19 21:10:00 +01:00
|
|
|
setLoading(false);
|
|
|
|
|
}
|
2023-03-20 08:52:13 +01:00
|
|
|
|
2022-12-19 21:10:00 +01:00
|
|
|
init();
|
2021-01-21 16:09:23 +01:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const onUserRemoval = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await xhrDelete('/api/admin/users', { userId: userIdToBeRemoved });
|
2023-03-20 08:52:13 +01:00
|
|
|
Toast.success('User successfully remove');
|
2021-01-21 16:09:23 +01:00
|
|
|
setUserIdToBeRemoved(null);
|
2025-12-23 08:47:51 +01:00
|
|
|
await actions.jobsData.getJobs();
|
2025-09-18 20:09:11 +02:00
|
|
|
await actions.user.getUsers();
|
2021-01-21 16:09:23 +01:00
|
|
|
} catch (error) {
|
2023-03-20 08:52:13 +01:00
|
|
|
Toast.error(error);
|
2021-01-21 16:09:23 +01:00
|
|
|
setUserIdToBeRemoved(null);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
{!loading && (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
{userIdToBeRemoved && <UserRemovalModal onCancel={() => setUserIdToBeRemoved(null)} onOk={onUserRemoval} />}
|
|
|
|
|
|
2023-03-20 08:52:13 +01:00
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
className="users__newButton"
|
|
|
|
|
icon={<IconPlus />}
|
2025-09-02 20:18:37 +02:00
|
|
|
onClick={() => navigate('/users/new')}
|
2023-03-20 08:52:13 +01:00
|
|
|
>
|
2025-09-29 20:36:56 +02:00
|
|
|
New User
|
2021-01-21 16:09:23 +01:00
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
<UserTable
|
|
|
|
|
user={users}
|
|
|
|
|
onUserEdit={(userId) => {
|
2025-09-02 20:18:37 +02:00
|
|
|
navigate(`/users/edit/${userId}`);
|
2021-01-21 16:09:23 +01:00
|
|
|
}}
|
|
|
|
|
onUserRemoval={(userId) => {
|
|
|
|
|
setUserIdToBeRemoved(userId);
|
|
|
|
|
//throw warning message that all jobs will be removed associated to this user
|
|
|
|
|
//check if at least 1 admin is available
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Users;
|