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 { formatMessage, labels } = useMessages();
const canEdit = team?.teamUser?.find(
({ userId, role }) => role === ROLES.teamOwner && userId === user.id,
);
const canEdit =
team?.teamUser?.find(({ userId, role }) => role === ROLES.teamOwner && userId === user.id) &&
user.role !== ROLES.viewOnly;
return (
<>

View File

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

View File

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

View File

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

View File

@ -1,14 +1,11 @@
'use client';
import WebsitesHeader from 'app/(main)/settings/websites/WebsitesHeader';
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 (
<>
<WebsitesHeader teamId={teamId} allowCreate={user.role !== 'view-only'} />
<WebsitesHeader teamId={teamId} allowCreate={false} />
<WebsitesDataTable teamId={teamId} allowEdit={false} />
</>
);