import { useEffect, useState } from 'react'; import { Breadcrumbs, Item, Tabs, useToast } from 'react-basics'; import Link from 'next/link'; import Page from 'components/layout/Page'; import PageHeader from 'components/layout/PageHeader'; import { ROLES } from 'lib/constants'; import useUser from 'hooks/useUser'; import useApi from 'hooks/useApi'; import useMessages from 'hooks/useMessages'; import TeamEditForm from './TeamEditForm'; import TeamMembers from './TeamMembers'; import TeamWebsites from './TeamWebsites'; export default function TeamSettings({ teamId }) { const { formatMessage, labels, messages } = useMessages(); const { user } = useUser(); const [values, setValues] = useState(null); const [tab, setTab] = useState('details'); const { get, useQuery } = useApi(); const { toast, showToast } = useToast(); const { data, isLoading } = useQuery( ['team', teamId], () => { if (teamId) { return get(`/teams/${teamId}`); } }, { cacheTime: 0 }, ); const canEdit = data?.teamUser?.find( ({ userId, role }) => role === ROLES.teamOwner && userId === user.id, ); const handleSave = data => { showToast({ message: formatMessage(messages.saved), variant: 'success' }); setValues(state => ({ ...state, ...data })); }; useEffect(() => { if (data) { setValues(data); } }, [data]); return ( {toast} {formatMessage(labels.teams)} {values?.name} } /> {formatMessage(labels.details)} {formatMessage(labels.members)} {formatMessage(labels.websites)} {tab === 'details' && ( )} {tab === 'members' && } {tab === 'websites' && } ); }