Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

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

Francis Cao8da3811c730f
diff --git a/src/app/(main)/dashboard/DashboardPage.tsx b/src/app/(main)/dashboard/DashboardPage.tsx
index 0b8a7d904..60bf17998 100644
--- a/src/app/(main)/dashboard/DashboardPage.tsx
+++ b/src/app/(main)/dashboard/DashboardPage.tsx
@@ -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>
diff --git a/src/app/(main)/settings/teams/[teamId]/websites/TeamWebsitesPage.tsx b/src/app/(main)/settings/teams/[teamId]/websites/TeamWebsitesPage.tsx
index d600c9cd0..ade430146 100644
--- a/src/app/(main)/settings/teams/[teamId]/websites/TeamWebsitesPage.tsx
+++ b/src/app/(main)/settings/teams/[teamId]/websites/TeamWebsitesPage.tsx
@@ -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} />
</>
);
}
diff --git a/src/app/(main)/settings/teams/[teamId]/websites/TeamWebsitesTable.tsx b/src/app/(main)/settings/teams/[teamId]/websites/TeamWebsitesTable.tsx
index b07f3dbfd..99a5d7fef 100644
--- a/src/app/(main)/settings/teams/[teamId]/websites/TeamWebsitesTable.tsx
+++ b/src/app/(main)/settings/teams/[teamId]/websites/TeamWebsitesTable.tsx
@@ -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) && (
diff --git a/src/app/(main)/settings/websites/WebsiteAddButton.tsx b/src/app/(main)/settings/websites/WebsiteAddButton.tsx
index 35e9bbc3f..58b3001c1 100644
--- a/src/app/(main)/settings/websites/WebsiteAddButton.tsx
+++ b/src/app/(main)/settings/websites/WebsiteAddButton.tsx
@@ -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?.();
};
diff --git a/src/components/hooks/queries/useTeamMembers.ts b/src/components/hooks/queries/useTeamMembers.ts
index d18ada3f9..866e28e78 100644
--- a/src/components/hooks/queries/useTeamMembers.ts
+++ b/src/components/hooks/queries/useTeamMembers.ts
@@ -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();
diff --git a/src/components/hooks/queries/useTeamWebsites.ts b/src/components/hooks/queries/useTeamWebsites.ts
index 19bcdf762..5259f9d33 100644
--- a/src/components/hooks/queries/useTeamWebsites.ts
+++ b/src/components/hooks/queries/useTeamWebsites.ts
@@ -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);
},
diff --git a/src/pages/api/teams/[teamId]/users/index.ts b/src/pages/api/teams/[teamId]/users/index.ts
index 53f0dd0ab..47394eefe 100644
--- a/src/pages/api/teams/[teamId]/users/index.ts
+++ b/src/pages/api/teams/[teamId]/users/index.ts
@@ -48,7 +48,12 @@ export default async (
const users = await getTeamUsers(
{
- where: { teamId },
+ where: {
+ teamId,
+ user: {
+ deletedAt: null,
+ },
+ },
include: {
user: {
select: {