2022-12-27 01:57:59 +01:00
|
|
|
import { useEffect, useState } from 'react';
|
2023-01-25 16:42:46 +01:00
|
|
|
import { useIntl } from 'react-intl';
|
2022-12-27 01:57:59 +01:00
|
|
|
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';
|
2023-01-25 16:42:46 +01:00
|
|
|
import { labels, messages } from 'components/messages';
|
|
|
|
import TeamWebsites from './TeamWebsites';
|
2022-12-27 01:57:59 +01:00
|
|
|
|
2023-01-25 16:42:46 +01:00
|
|
|
export default function TeamSettings({ teamId }) {
|
|
|
|
const { formatMessage } = useIntl();
|
2022-12-27 01:57:59 +01:00
|
|
|
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 => {
|
2023-01-25 16:42:46 +01:00
|
|
|
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
2022-12-27 01:57:59 +01:00
|
|
|
setValues(state => ({ ...state, ...data }));
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (data) {
|
|
|
|
setValues(data);
|
|
|
|
}
|
|
|
|
}, [data]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page loading={isLoading || !values}>
|
|
|
|
{toast}
|
2023-02-02 03:39:54 +01:00
|
|
|
<PageHeader
|
|
|
|
title={
|
|
|
|
<Breadcrumbs>
|
|
|
|
<Item>
|
|
|
|
<Link href="/settings/teams">Teams</Link>
|
|
|
|
</Item>
|
|
|
|
<Item>{values?.name}</Item>
|
|
|
|
</Breadcrumbs>
|
|
|
|
}
|
|
|
|
/>
|
2023-01-25 16:42:46 +01:00
|
|
|
<Tabs selectedKey={tab} onSelect={setTab} style={{ marginBottom: 30 }}>
|
|
|
|
<Item key="details">{formatMessage(labels.details)}</Item>
|
|
|
|
<Item key="members">{formatMessage(labels.members)}</Item>
|
|
|
|
<Item key="websites">{formatMessage(labels.websites)}</Item>
|
2022-12-27 01:57:59 +01:00
|
|
|
</Tabs>
|
2023-01-10 08:59:26 +01:00
|
|
|
{tab === 'details' && <TeamEditForm teamId={teamId} data={values} onSave={handleSave} />}
|
|
|
|
{tab === 'members' && <TeamMembers teamId={teamId} />}
|
2023-01-25 16:42:46 +01:00
|
|
|
{tab === 'websites' && <TeamWebsites teamId={teamId} />}
|
2022-12-27 01:57:59 +01:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|