diff --git a/src/app/(main)/dashboard/DashboardPage.tsx b/src/app/(main)/dashboard/DashboardPage.tsx
new file mode 100644
index 00000000..c05e411d
--- /dev/null
+++ b/src/app/(main)/dashboard/DashboardPage.tsx
@@ -0,0 +1,17 @@
+'use client';
+import { Column } from '@umami/react-zen';
+import { PageHeader } from '@/components/common/PageHeader';
+import { useMessages } from '@/components/hooks';
+import { PageBody } from '@/components/common/PageBody';
+
+export function DashboardPage() {
+ const { formatMessage, labels } = useMessages();
+
+ return (
+
+
+
+
+
+ );
+}
diff --git a/src/app/(main)/dashboard/page.tsx b/src/app/(main)/dashboard/page.tsx
new file mode 100644
index 00000000..e934e6ad
--- /dev/null
+++ b/src/app/(main)/dashboard/page.tsx
@@ -0,0 +1,10 @@
+import { Metadata } from 'next';
+import { DashboardPage } from './DashboardPage';
+
+export default async function () {
+ return ;
+}
+
+export const metadata: Metadata = {
+ title: 'Dashboard',
+};
diff --git a/src/app/(main)/websites/WebsitesDataTable.tsx b/src/app/(main)/websites/WebsitesDataTable.tsx
index 612dc502..93b1a7c7 100644
--- a/src/app/(main)/websites/WebsitesDataTable.tsx
+++ b/src/app/(main)/websites/WebsitesDataTable.tsx
@@ -1,20 +1,23 @@
import Link from 'next/link';
import { WebsitesTable } from './WebsitesTable';
import { DataGrid } from '@/components/common/DataGrid';
-import { useNavigation, useUserWebsitesQuery } from '@/components/hooks';
+import { useLoginQuery, useNavigation, useUserWebsitesQuery } from '@/components/hooks';
export function WebsitesDataTable({
+ userId,
teamId,
allowEdit = true,
allowView = true,
showActions = true,
}: {
+ userId?: string;
teamId?: string;
allowEdit?: boolean;
allowView?: boolean;
showActions?: boolean;
}) {
- const queryResult = useUserWebsitesQuery({ teamId });
+ const { user } = useLoginQuery();
+ const queryResult = useUserWebsitesQuery({ userId: userId || user?.id, teamId });
const { renderUrl } = useNavigation();
const renderLink = (row: any) => (
diff --git a/src/app/(main)/websites/WebsitesTable.tsx b/src/app/(main)/websites/WebsitesTable.tsx
index 3fc22a98..3f781cb7 100644
--- a/src/app/(main)/websites/WebsitesTable.tsx
+++ b/src/app/(main)/websites/WebsitesTable.tsx
@@ -3,6 +3,7 @@ import { Row, Text, Icon, DataTable, DataColumn, MenuItem } from '@umami/react-z
import { useMessages, useNavigation } from '@/components/hooks';
import { MenuButton } from '@/components/input/MenuButton';
import { Eye, SquarePen } from '@/components/icons';
+import { Empty } from '@/components/common/Empty';
export function WebsitesTable({
data = [],
@@ -10,20 +11,18 @@ export function WebsitesTable({
allowEdit,
allowView,
renderLink,
- children,
}: {
data: Record[];
showActions?: boolean;
allowEdit?: boolean;
allowView?: boolean;
renderLink?: (row: any) => ReactNode;
- children?: ReactNode;
}) {
const { formatMessage, labels } = useMessages();
const { renderUrl } = useNavigation();
- if (!data?.length) {
- return children;
+ if (data.length === 0) {
+ return ;
}
return (
diff --git a/src/app/(main)/websites/[websiteId]/WebsiteNav.tsx b/src/app/(main)/websites/[websiteId]/WebsiteNav.tsx
index e0d5ffb0..5f9d8940 100644
--- a/src/app/(main)/websites/[websiteId]/WebsiteNav.tsx
+++ b/src/app/(main)/websites/[websiteId]/WebsiteNav.tsx
@@ -21,7 +21,7 @@ import { WebsiteSelect } from '@/components/input/WebsiteSelect';
export function WebsiteNav({ websiteId }: { websiteId: string }) {
const { formatMessage, labels } = useMessages();
- const { pathname, renderUrl, teamId } = useNavigation();
+ const { pathname, renderUrl, teamId, router } = useNavigation();
const renderPath = (path: string) =>
renderUrl(`/websites/${websiteId}${path}`, {
@@ -143,13 +143,17 @@ export function WebsiteNav({ websiteId }: { websiteId: string }) {
},
];
+ const handleChange = (value: string) => {
+ router.push(renderUrl(`/websites/${value}`));
+ };
+
const selectedKey = items
.flatMap(e => e.items)
.find(({ path }) => path && pathname.endsWith(path.split('?')[0]))?.id;
return (
-
+
);
}
diff --git a/src/app/api/me/websites/route.ts b/src/app/api/me/websites/route.ts
index 41a8756d..75f8fbe1 100644
--- a/src/app/api/me/websites/route.ts
+++ b/src/app/api/me/websites/route.ts
@@ -1,6 +1,6 @@
import { z } from 'zod';
import { pagingParams } from '@/lib/schema';
-import { getUserWebsites } from '@/queries';
+import { getAllUserWebsitesIncludingTeamOwner, getUserWebsites } from '@/queries';
import { json } from '@/lib/response';
import { parseRequest, getQueryFilters } from '@/lib/request';
@@ -17,7 +17,9 @@ export async function GET(request: Request) {
const filters = await getQueryFilters(query);
- const websites = await getUserWebsites(auth.user.id, filters);
+ if (query.includeTeams) {
+ return json(await getAllUserWebsitesIncludingTeamOwner(auth.user.id, filters));
+ }
- return json(websites);
+ return json(await getUserWebsites(auth.user.id, filters));
}
diff --git a/src/app/api/websites/[websiteId]/stats/route.ts b/src/app/api/websites/[websiteId]/stats/route.ts
index 7041f484..f3b1a708 100644
--- a/src/app/api/websites/[websiteId]/stats/route.ts
+++ b/src/app/api/websites/[websiteId]/stats/route.ts
@@ -40,5 +40,5 @@ export async function GET(
endDate,
});
- return json({ ...data[0], comparison });
+ return json({ ...data, comparison });
}
diff --git a/src/components/input/WebsiteSelect.tsx b/src/components/input/WebsiteSelect.tsx
index 0df4c1af..572d6d7d 100644
--- a/src/components/input/WebsiteSelect.tsx
+++ b/src/components/input/WebsiteSelect.tsx
@@ -3,28 +3,28 @@ import { Select, SelectProps, ListItem, Text } from '@umami/react-zen';
import {
useUserWebsitesQuery,
useWebsiteQuery,
- useNavigation,
useMessages,
+ useLoginQuery,
} from '@/components/hooks';
import { Empty } from '@/components/common/Empty';
export function WebsiteSelect({
websiteId,
teamId,
+ onChange,
...props
}: {
websiteId?: string;
teamId?: string;
} & SelectProps) {
const { formatMessage, messages } = useMessages();
- const { router, renderUrl } = useNavigation();
const [search, setSearch] = useState('');
const { data: website } = useWebsiteQuery(websiteId);
- const { data, isLoading } = useUserWebsitesQuery({ teamId }, { search, pageSize: 5 });
-
- const handleSelect = (value: any) => {
- router.push(renderUrl(`/websites/${value}`));
- };
+ const { user } = useLoginQuery();
+ const { data, isLoading } = useUserWebsitesQuery(
+ { userId: user?.id, teamId },
+ { search, pageSize: 5 },
+ );
const handleSearch = (value: string) => {
setSearch(value);
@@ -45,7 +45,7 @@ export function WebsiteSelect({
allowSearch={true}
searchValue={search}
onSearch={handleSearch}
- onChange={handleSelect}
+ onChange={onChange}
onOpenChange={handleOpenChange}
listProps={{
renderEmptyState: () => ,
diff --git a/src/queries/prisma/website.ts b/src/queries/prisma/website.ts
index fc10bcfd..6a0c0913 100644
--- a/src/queries/prisma/website.ts
+++ b/src/queries/prisma/website.ts
@@ -46,46 +46,34 @@ export async function getWebsites(
return pagedQuery('website', { ...criteria, where }, filters);
}
-export async function getAllWebsites(userId: string) {
- return prisma.client.website.findMany({
- where: {
- OR: [
- { userId },
- {
- team: {
- deletedAt: null,
- teamUser: {
- some: {
- userId,
+export async function getAllUserWebsitesIncludingTeamOwner(
+ userId: string,
+ filters?: QueryFilters,
+): Promise> {
+ return getWebsites(
+ {
+ where: {
+ OR: [
+ { userId },
+ {
+ team: {
+ deletedAt: null,
+ members: {
+ some: {
+ role: ROLES.teamOwner,
+ userId,
+ },
},
},
},
- },
- ],
- deletedAt: null,
+ ],
+ },
},
- });
-}
-
-export async function getAllUserWebsitesIncludingTeamOwner(userId: string) {
- return prisma.client.website.findMany({
- where: {
- OR: [
- { userId },
- {
- team: {
- deletedAt: null,
- teamUser: {
- some: {
- role: ROLES.teamOwner,
- userId,
- },
- },
- },
- },
- ],
+ {
+ orderBy: 'name',
+ ...filters,
},
- });
+ );
}
export async function getUserWebsites(
diff --git a/src/queries/sql/getWebsiteStats.ts b/src/queries/sql/getWebsiteStats.ts
index 925c4081..79fb8bbe 100644
--- a/src/queries/sql/getWebsiteStats.ts
+++ b/src/queries/sql/getWebsiteStats.ts
@@ -58,7 +58,7 @@ async function relationalQuery(
) as t
`,
queryParams,
- );
+ ).then(result => result?.[0]);
}
async function clickhouseQuery(