2022-12-27 01:57:59 +01:00
|
|
|
import { useState } from 'react';
|
2023-01-10 08:59:26 +01:00
|
|
|
import { Button, Icon, Modal, useToast } from 'react-basics';
|
2022-12-28 05:20:44 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
2022-12-27 01:57:59 +01:00
|
|
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
2023-01-10 08:59:26 +01:00
|
|
|
import TeamAddForm from 'components/pages/settings/teams/TeamAddForm';
|
2022-12-27 01:57:59 +01:00
|
|
|
import PageHeader from 'components/layout/PageHeader';
|
2023-01-10 08:59:26 +01:00
|
|
|
import TeamsTable from 'components/pages/settings/teams/TeamsTable';
|
2022-12-27 01:57:59 +01:00
|
|
|
import Page from 'components/layout/Page';
|
|
|
|
|
|
|
|
export default function TeamsList() {
|
|
|
|
const [edit, setEdit] = useState(false);
|
|
|
|
const [update, setUpdate] = useState(0);
|
2023-01-10 08:59:26 +01:00
|
|
|
const { get, useQuery } = useApi();
|
2022-12-27 01:57:59 +01:00
|
|
|
const { data, isLoading, error } = useQuery(['teams', update], () => get(`/teams`));
|
|
|
|
const hasData = data && data.length !== 0;
|
|
|
|
const { toast, showToast } = useToast();
|
|
|
|
|
|
|
|
const handleAdd = () => {
|
|
|
|
setEdit(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleSave = () => {
|
|
|
|
setEdit(false);
|
|
|
|
setUpdate(state => state + 1);
|
|
|
|
showToast({ message: 'Team saved.', variant: 'success' });
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
setEdit(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page loading={isLoading} error={error}>
|
|
|
|
{toast}
|
|
|
|
<PageHeader title="Teams">
|
|
|
|
<Button onClick={handleAdd}>
|
|
|
|
<Icon icon="plus" /> Create team
|
|
|
|
</Button>
|
|
|
|
</PageHeader>
|
2023-01-10 08:59:26 +01:00
|
|
|
{hasData && <TeamsTable data={data} />}
|
2022-12-27 01:57:59 +01:00
|
|
|
{!hasData && (
|
2023-01-10 08:59:26 +01:00
|
|
|
<EmptyPlaceholder message="You don't have any teams configured.">
|
|
|
|
<Button variant="primary" onClick={handleAdd}>
|
|
|
|
<Icon icon="plus" /> Create team
|
|
|
|
</Button>
|
2022-12-27 01:57:59 +01:00
|
|
|
</EmptyPlaceholder>
|
|
|
|
)}
|
|
|
|
{edit && (
|
|
|
|
<Modal title="Create team" onClose={handleClose}>
|
|
|
|
{close => <TeamAddForm onSave={handleSave} onClose={close} />}
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|