umami/components/pages/settings/teams/TeamWebsites.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

import {
ActionForm,
Button,
Icon,
Icons,
Loading,
Modal,
ModalTrigger,
Text,
2023-06-13 20:59:12 +02:00
useToasts,
} from 'react-basics';
2023-03-22 22:05:55 +01:00
import TeamWebsitesTable from 'components/pages/settings/teams/TeamWebsitesTable';
2023-04-10 01:04:28 +02:00
import TeamAddWebsiteForm from 'components/pages/settings/teams/TeamAddWebsiteForm';
2023-03-22 22:05:55 +01:00
import useApi from 'hooks/useApi';
import useMessages from 'hooks/useMessages';
2023-01-25 16:42:46 +01:00
2023-04-21 17:00:42 +02:00
export function TeamWebsites({ teamId }) {
2023-06-13 20:59:12 +02:00
const { showToast } = useToasts();
2023-03-22 22:05:55 +01:00
const { formatMessage, labels, messages } = useMessages();
2023-01-25 16:42:46 +01:00
const { get, useQuery } = useApi();
const { data, isLoading, refetch } = useQuery(['teams:websites', teamId], () =>
2023-01-25 16:42:46 +01:00
get(`/teams/${teamId}/websites`),
);
const hasData = data && data.length !== 0;
if (isLoading) {
2023-04-13 02:43:08 +02:00
return <Loading icon="dots" style={{ minHeight: 300 }} />;
2023-01-25 16:42:46 +01:00
}
const handleSave = async () => {
await refetch();
showToast({ message: formatMessage(messages.saved), variant: 'success' });
};
const addButton = (
<ModalTrigger>
<Button variant="primary">
<Icon>
<Icons.Plus />
</Icon>
<Text>{formatMessage(labels.addWebsite)}</Text>
</Button>
<Modal title={formatMessage(labels.addWebsite)}>
2023-04-10 01:04:28 +02:00
{close => <TeamAddWebsiteForm teamId={teamId} onSave={handleSave} onClose={close} />}
</Modal>
</ModalTrigger>
);
2023-01-25 16:42:46 +01:00
return (
<div>
2023-04-13 02:43:08 +02:00
<ActionForm description={formatMessage(messages.teamWebsitesInfo)}>{addButton}</ActionForm>
{hasData && <TeamWebsitesTable teamId={teamId} data={data} onSave={handleSave} />}
2023-01-25 16:42:46 +01:00
</div>
);
}
2023-04-21 17:00:42 +02:00
export default TeamWebsites;