add website in team context, permissions, display non-deleted users

This commit is contained in:
Francis Cao 2024-02-07 16:37:48 -08:00
parent b885f57f40
commit 8da3811c73
7 changed files with 33 additions and 13 deletions

View File

@ -36,7 +36,7 @@ export function DashboardPage() {
</PageHeader>
{!hasData && (
<EmptyPlaceholder message={formatMessage(messages.noWebsitesConfigured)}>
<LinkButton href={renderTeamUrl('/settings/websites')}>
<LinkButton href={renderTeamUrl('/settings')}>
<Icon rotate={dir === 'rtl' ? 180 : 0}>
<Icons.ArrowRight />
</Icon>

View File

@ -1,15 +1,27 @@
'use client';
import TeamWebsitesDataTable from './TeamWebsitesDataTable';
import { TeamContext } from 'app/(main)/teams/[teamId]/TeamProvider';
import WebsiteAddButton from 'app/(main)/settings/websites/WebsiteAddButton';
import { useLogin, useMessages } from 'components/hooks';
import PageHeader from 'components/layout/PageHeader';
import { useMessages } from 'components/hooks';
import TeamWebsitesDataTable from './TeamWebsitesDataTable';
import { ROLES } from 'lib/constants';
import { useContext } from 'react';
export function TeamWebsitesPage({ teamId }: { teamId: string }) {
const team = useContext(TeamContext);
const { formatMessage, labels } = useMessages();
const { user } = useLogin();
const canEdit = team?.teamUser?.find(
({ userId, role }) => role !== ROLES.viewOnly && userId === user.id,
);
return (
<>
<PageHeader title={formatMessage(labels.websites)} />
<TeamWebsitesDataTable teamId={teamId} allowEdit={true} />
<PageHeader title={formatMessage(labels.websites)}>
{canEdit && <WebsiteAddButton teamId={teamId} />}
</PageHeader>
<TeamWebsitesDataTable teamId={teamId} allowEdit={canEdit} />
</>
);
}

View File

@ -6,7 +6,7 @@ import LinkButton from 'components/common/LinkButton';
export function TeamWebsitesTable({
teamId,
data = [],
allowEdit,
allowEdit = false,
}: {
teamId: string;
data: any[];
@ -21,7 +21,7 @@ export function TeamWebsitesTable({
<GridColumn name="domain" label={formatMessage(labels.domain)} />
<GridColumn name="action" label=" " alignment="end">
{row => {
const { websiteId } = row;
const { id: websiteId } = row;
return (
<>
{allowEdit && (teamId || user?.isAdmin) && (

View File

@ -1,7 +1,7 @@
import { Button, Icon, Icons, Modal, ModalTrigger, Text, useToasts } from 'react-basics';
import WebsiteAddForm from './WebsiteAddForm';
import { useMessages } from 'components/hooks';
import { Button, Icon, Icons, Modal, ModalTrigger, Text, useToasts } from 'react-basics';
import { touch } from 'store/modified';
import WebsiteAddForm from './WebsiteAddForm';
export function WebsiteAddButton({ teamId, onSave }: { teamId: string; onSave?: () => void }) {
const { formatMessage, labels, messages } = useMessages();
@ -9,7 +9,8 @@ export function WebsiteAddButton({ teamId, onSave }: { teamId: string; onSave?:
const handleSave = async () => {
showToast({ message: formatMessage(messages.saved), variant: 'success' });
touch('websites');
teamId ? touch('teams:websites') : touch('websites');
onSave?.();
};

View File

@ -1,6 +1,6 @@
import useModified from 'store/modified';
import useApi from './useApi';
import useFilterQuery from './useFilterQuery';
import useModified from 'store/modified';
export function useTeamMembers(teamId: string) {
const { get } = useApi();

View File

@ -1,11 +1,13 @@
import useApi from './useApi';
import useFilterQuery from './useFilterQuery';
import useModified from 'store/modified';
export function useTeamWebsites(teamId: string) {
const { get } = useApi();
const modified = useModified((state: any) => state?.['teams:websites']);
return useFilterQuery({
queryKey: ['teams:websites', { teamId }],
queryKey: ['teams:websites', { teamId, modified }],
queryFn: (params: any) => {
return get(`/teams/${teamId}/websites`, params);
},

View File

@ -48,7 +48,12 @@ export default async (
const users = await getTeamUsers(
{
where: { teamId },
where: {
teamId,
user: {
deletedAt: null,
},
},
include: {
user: {
select: {