mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
* migra for distance * adding distance calculator * adding ability to store home address * improve distance calculation * calculating distance * show distance in grid view * upgrading dependencies * moving to react 19 * ability to clone a job * fixing tests * polishing
81 lines
2.3 KiB
JavaScript
81 lines
2.3 KiB
JavaScript
/*
|
|
* Copyright (c) 2026 by Christian Kellner.
|
|
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
|
|
*/
|
|
|
|
import React from 'react';
|
|
|
|
import { Toast } from '@douyinfe/semi-ui-19';
|
|
import UserTable from '../../components/table/UserTable';
|
|
import { useActions, useSelector } from '../../services/state/store';
|
|
import { IconPlus } from '@douyinfe/semi-icons';
|
|
import { Button } from '@douyinfe/semi-ui-19';
|
|
import UserRemovalModal from './UserRemovalModal';
|
|
import { xhrDelete } from '../../services/xhr';
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
|
import './Users.less';
|
|
|
|
const Users = function Users() {
|
|
const actions = useActions();
|
|
const [loading, setLoading] = React.useState(true);
|
|
const users = useSelector((state) => state.user.users);
|
|
const [userIdToBeRemoved, setUserIdToBeRemoved] = React.useState(null);
|
|
const navigate = useNavigate();
|
|
|
|
React.useEffect(() => {
|
|
async function init() {
|
|
await actions.user.getUsers();
|
|
setLoading(false);
|
|
}
|
|
|
|
init();
|
|
}, []);
|
|
|
|
const onUserRemoval = async () => {
|
|
try {
|
|
await xhrDelete('/api/admin/users', { userId: userIdToBeRemoved });
|
|
Toast.success('User successfully remove');
|
|
setUserIdToBeRemoved(null);
|
|
await actions.jobsData.getJobs();
|
|
await actions.user.getUsers();
|
|
} catch (error) {
|
|
Toast.error(error);
|
|
setUserIdToBeRemoved(null);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
{!loading && (
|
|
<React.Fragment>
|
|
{userIdToBeRemoved && <UserRemovalModal onCancel={() => setUserIdToBeRemoved(null)} onOk={onUserRemoval} />}
|
|
|
|
<Button
|
|
type="primary"
|
|
className="users__newButton"
|
|
icon={<IconPlus />}
|
|
onClick={() => navigate('/users/new')}
|
|
>
|
|
New User
|
|
</Button>
|
|
|
|
<UserTable
|
|
user={users}
|
|
onUserEdit={(userId) => {
|
|
navigate(`/users/edit/${userId}`);
|
|
}}
|
|
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;
|