fix create website / teams permissions

This commit is contained in:
Francis Cao 2024-02-22 22:21:11 -08:00
parent 8fbd6871f7
commit 490bb11771
5 changed files with 20 additions and 17 deletions

View File

@ -11,9 +11,9 @@ export function TeamMembersPage({ teamId }: { teamId: string }) {
const { user } = useLogin(); const { user } = useLogin();
const { formatMessage, labels } = useMessages(); const { formatMessage, labels } = useMessages();
const canEdit = team?.teamUser?.find( const canEdit =
({ userId, role }) => role === ROLES.teamOwner && userId === user.id, team?.teamUser?.find(({ userId, role }) => role === ROLES.teamOwner && userId === user.id) &&
); user.role !== ROLES.viewOnly;
return ( return (
<> <>

View File

@ -15,9 +15,9 @@ export function TeamDetails({ teamId }: { teamId: string }) {
const { user } = useLogin(); const { user } = useLogin();
const [tab, setTab] = useState('details'); const [tab, setTab] = useState('details');
const canEdit = !!team?.teamUser?.find( const canEdit =
({ userId, role }) => role === ROLES.teamOwner && userId === user.id, !!team?.teamUser?.find(({ userId, role }) => role === ROLES.teamOwner && userId === user.id) &&
); user.role !== ROLES.viewOnly;
return ( return (
<Flexbox direction="column"> <Flexbox direction="column">

View File

@ -12,16 +12,17 @@ export function TeamWebsitesPage({ teamId }: { teamId: string }) {
const { formatMessage, labels } = useMessages(); const { formatMessage, labels } = useMessages();
const { user } = useLogin(); const { user } = useLogin();
const allowEdit = !!team?.teamUser?.find( const canEdit =
({ userId, role }) => userId === user.id && role !== ROLES.teamViewOnly, !!team?.teamUser?.find(
); ({ userId, role }) => userId === user.id && role !== ROLES.teamViewOnly,
) && user.role !== ROLES.viewOnly;
return ( return (
<> <>
<PageHeader title={formatMessage(labels.websites)}> <PageHeader title={formatMessage(labels.websites)}>
{allowEdit && <WebsiteAddButton teamId={teamId} />} {canEdit && <WebsiteAddButton teamId={teamId} />}
</PageHeader> </PageHeader>
<TeamWebsitesDataTable teamId={teamId} allowEdit={allowEdit} /> <TeamWebsitesDataTable teamId={teamId} allowEdit={canEdit} />
</> </>
); );
} }

View File

@ -1,11 +1,16 @@
'use client'; 'use client';
import { useLogin } from 'components/hooks';
import WebsitesDataTable from './WebsitesDataTable'; import WebsitesDataTable from './WebsitesDataTable';
import WebsitesHeader from './WebsitesHeader'; import WebsitesHeader from './WebsitesHeader';
import { ROLES } from 'lib/constants';
export default function WebsitesSettingsPage({ teamId }: { teamId: string }) { export default function WebsitesSettingsPage({ teamId }: { teamId: string }) {
const { user } = useLogin();
const canCreate = user.role !== ROLES.viewOnly;
return ( return (
<> <>
<WebsitesHeader teamId={teamId} /> <WebsitesHeader teamId={teamId} allowCreate={canCreate} />
<WebsitesDataTable teamId={teamId} /> <WebsitesDataTable teamId={teamId} />
</> </>
); );

View File

@ -1,14 +1,11 @@
'use client'; 'use client';
import WebsitesHeader from 'app/(main)/settings/websites/WebsitesHeader'; import WebsitesHeader from 'app/(main)/settings/websites/WebsitesHeader';
import WebsitesDataTable from 'app/(main)/settings/websites/WebsitesDataTable'; import WebsitesDataTable from 'app/(main)/settings/websites/WebsitesDataTable';
import { useLogin } from 'components/hooks';
export default function WebsitesPage({ teamId }: { teamId: string; userId: string }) {
const { user } = useLogin();
export default function WebsitesPage({ teamId }: { teamId: string }) {
return ( return (
<> <>
<WebsitesHeader teamId={teamId} allowCreate={user.role !== 'view-only'} /> <WebsitesHeader teamId={teamId} allowCreate={false} />
<WebsitesDataTable teamId={teamId} allowEdit={false} /> <WebsitesDataTable teamId={teamId} allowEdit={false} />
</> </>
); );