2023-03-22 22:05:55 +01:00
|
|
|
import { Loading, useToast } from 'react-basics';
|
2023-01-10 08:59:26 +01:00
|
|
|
import TeamMembersTable from 'components/pages/settings/teams/TeamMembersTable';
|
2023-03-10 08:21:19 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
2023-03-22 22:05:55 +01:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2023-01-10 08:59:26 +01:00
|
|
|
|
2023-02-02 20:59:38 +01:00
|
|
|
export default function TeamMembers({ teamId, readOnly }) {
|
2023-03-10 08:21:19 +01:00
|
|
|
const { toast, showToast } = useToast();
|
2023-01-10 08:59:26 +01:00
|
|
|
const { get, useQuery } = useApi();
|
2023-03-22 22:05:55 +01:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2023-03-10 08:21:19 +01:00
|
|
|
const { data, isLoading, refetch } = useQuery(['teams:users', teamId], () =>
|
2023-01-10 08:59:26 +01:00
|
|
|
get(`/teams/${teamId}/users`),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
return <Loading icon="dots" position="block" />;
|
|
|
|
}
|
|
|
|
|
2023-03-10 08:21:19 +01:00
|
|
|
const handleSave = async () => {
|
|
|
|
await refetch();
|
2023-03-22 22:05:55 +01:00
|
|
|
showToast({ message: formatMessage(labels.saved), variant: 'success' });
|
2023-03-10 08:21:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{toast}
|
|
|
|
<TeamMembersTable onSave={handleSave} data={data} readOnly={readOnly} />
|
|
|
|
</>
|
|
|
|
);
|
2023-01-10 08:59:26 +01:00
|
|
|
}
|