2022-12-27 01:57:59 +01:00
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { Breadcrumbs, Item, Tabs, 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 Link from 'next/link';
|
|
|
|
import Page from 'components/layout/Page';
|
2023-01-10 08:59:26 +01:00
|
|
|
import TeamEditForm from 'components/pages/settings/teams/TeamEditForm';
|
2022-12-27 01:57:59 +01:00
|
|
|
import PageHeader from 'components/layout/PageHeader';
|
2023-01-10 08:59:26 +01:00
|
|
|
import TeamMembers from 'components/pages/settings/teams/TeamMembers';
|
2022-12-27 01:57:59 +01:00
|
|
|
|
|
|
|
export default function TeamDetails({ teamId }) {
|
|
|
|
const [values, setValues] = useState(null);
|
2023-01-10 08:59:26 +01:00
|
|
|
const [tab, setTab] = useState('details');
|
|
|
|
const { get, useQuery } = useApi();
|
2022-12-27 01:57:59 +01:00
|
|
|
const { toast, showToast } = useToast();
|
|
|
|
const { data, isLoading } = useQuery(
|
|
|
|
['team', teamId],
|
|
|
|
() => {
|
|
|
|
if (teamId) {
|
|
|
|
return get(`/teams/${teamId}`);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ cacheTime: 0 },
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleSave = data => {
|
|
|
|
showToast({ message: 'Saved successfully.', variant: 'success' });
|
|
|
|
setValues(state => ({ ...state, ...data }));
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (data) {
|
|
|
|
setValues(data);
|
|
|
|
}
|
|
|
|
}, [data]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page loading={isLoading || !values}>
|
|
|
|
{toast}
|
|
|
|
<PageHeader>
|
|
|
|
<Breadcrumbs>
|
|
|
|
<Item>
|
2023-01-10 08:59:26 +01:00
|
|
|
<Link href="/settings/teams">Teams</Link>
|
2022-12-27 01:57:59 +01:00
|
|
|
</Item>
|
|
|
|
<Item>{values?.name}</Item>
|
|
|
|
</Breadcrumbs>
|
|
|
|
</PageHeader>
|
|
|
|
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30, fontSize: 14 }}>
|
2023-01-10 08:59:26 +01:00
|
|
|
<Item key="details">Details</Item>
|
2022-12-27 01:57:59 +01:00
|
|
|
<Item key="members">Members</Item>
|
|
|
|
<Item key="websites">Websites</Item>
|
|
|
|
</Tabs>
|
2023-01-10 08:59:26 +01:00
|
|
|
{tab === 'details' && <TeamEditForm teamId={teamId} data={values} onSave={handleSave} />}
|
|
|
|
{tab === 'members' && <TeamMembers teamId={teamId} />}
|
2022-12-27 01:57:59 +01:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|