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.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Fixed team website create.
Mike Caod9670f10a434
diff --git a/src/app/(main)/websites/Websites.tsx b/src/app/(main)/websites/Websites.tsxnew file mode 100644index 000000000..8769d6adb--- /dev/null+++ b/src/app/(main)/websites/Websites.tsx@@ -0,0 +1,8 @@+'use client';+import WebsitesDataTable from '../settings/websites/WebsitesDataTable';++export function Websites({ teamId, userId }: { teamId: string; userId: string }) {+ return <WebsitesDataTable teamId={teamId} userId={userId} allowEdit={false} />;+}++export default Websites;diff --git a/src/app/(main)/websites/WebsitesBrowse.tsx b/src/app/(main)/websites/WebsitesBrowse.tsxdeleted file mode 100644index 88fa9e5e2..000000000--- a/src/app/(main)/websites/WebsitesBrowse.tsx+++ /dev/null@@ -1,12 +0,0 @@-'use client';-import WebsitesDataTable from '../settings/websites/WebsitesDataTable';-import { useLogin } from 'components/hooks';--export function WebsitesBrowse({ teamId, userId }: { teamId: string; userId: string }) {- const { user } = useLogin();- const allowEdit = !process.env.cloudMode;-- return <WebsitesDataTable teamId={teamId} userId={userId || user.id} allowEdit={allowEdit} />;-}--export default WebsitesBrowse;diff --git a/src/app/(main)/websites/page.tsx b/src/app/(main)/websites/page.tsxindex 3062bbba3..4f4d5e240 100644--- a/src/app/(main)/websites/page.tsx+++ b/src/app/(main)/websites/page.tsx@@ -1,12 +1,12 @@import WebsitesHeader from 'app/(main)/settings/websites/WebsitesHeader';-import WebsitesBrowse from './WebsitesBrowse';+import Websites from './Websites';import { Metadata } from 'next';export default function WebsitesPage({ params: { teamId, userId } }) {return (<>- <WebsitesHeader teamId={teamId} showActions={false} />- <WebsitesBrowse teamId={teamId} userId={userId} />+ <WebsitesHeader teamId={teamId} />+ <Websites teamId={teamId} userId={userId} /></>);}diff --git a/src/pages/api/scripts/telemetry.js b/src/pages/api/scripts/telemetry.tssimilarity index 83%rename from src/pages/api/scripts/telemetry.jsrename to src/pages/api/scripts/telemetry.tsindex 6a249de0c..bc0fd5032 100644--- a/src/pages/api/scripts/telemetry.js+++ b/src/pages/api/scripts/telemetry.ts@@ -1,7 +1,8 @@import { ok } from 'next-basics';import { CURRENT_VERSION, TELEMETRY_PIXEL } from 'lib/constants';+import { NextApiRequest, NextApiResponse } from 'next';-export default function handler(req, res) {+export default function handler(req: NextApiRequest, res: NextApiResponse) {if (process.env.NODE_ENV === 'production') {res.setHeader('content-type', 'text/javascript');diff --git a/src/pages/api/teams/[teamId]/websites/index.ts b/src/pages/api/teams/[teamId]/websites/index.tsindex 2f6fe3254..fa3afe23d 100644--- a/src/pages/api/teams/[teamId]/websites/index.ts+++ b/src/pages/api/teams/[teamId]/websites/index.ts@@ -1,12 +1,11 @@import * as yup from 'yup';-import { canCreateTeamWebsite, canViewTeam } from 'lib/auth';+import { canViewTeam } from 'lib/auth';import { useAuth, useValidate } from 'lib/middleware';import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';import { pageInfo } from 'lib/schema';import { NextApiResponse } from 'next';-import { methodNotAllowed, ok, unauthorized } from 'next-basics';-import { createWebsite, getTeamWebsites } from 'queries';-import { uuid } from 'lib/crypto';+import { ok, unauthorized } from 'next-basics';+import { getTeamWebsites } from 'queries';export interface TeamWebsiteRequestQuery extends SearchFilter {teamId: string;@@ -54,18 +53,4 @@ export default async (return ok(res, websites);}-- if (req.method === 'POST') {- if (!(await canCreateTeamWebsite(req.auth, teamId))) {- return unauthorized(res);- }-- const { name, domain, shareId } = req.body;-- const website = await createWebsite({ id: uuid(), name, domain, shareId });-- return ok(res, website);- }-- return methodNotAllowed(res);};diff --git a/src/pages/api/websites/index.ts b/src/pages/api/websites/index.tsindex 9aabad650..686c48239 100644--- a/src/pages/api/websites/index.ts+++ b/src/pages/api/websites/index.ts@@ -1,4 +1,4 @@-import { canCreateWebsite } from 'lib/auth';+import { canCreateTeamWebsite, canCreateWebsite } from 'lib/auth';import { uuid } from 'lib/crypto';import { useAuth, useCors, useValidate } from 'lib/middleware';import { NextApiRequestQueryBody, SearchFilter } from 'lib/types';@@ -15,6 +15,7 @@ export interface WebsitesRequestBody {name: string;domain: string;shareId: string;+ teamId: string;}const schema = {@@ -25,6 +26,7 @@ const schema = {name: yup.string().max(100).required(),domain: yup.string().max(500).required(),shareId: yup.string().max(50).nullable(),+ teamId: yup.string().nullable(),}),};@@ -49,9 +51,12 @@ export default async (}if (req.method === 'POST') {- const { name, domain, shareId } = req.body;+ const { name, domain, shareId, teamId } = req.body;- if (!(await canCreateWebsite(req.auth))) {+ if (+ (teamId && !(await canCreateTeamWebsite(req.auth, teamId))) ||+ !(await canCreateWebsite(req.auth))+ ) {return unauthorized(res);}@@ -60,9 +65,12 @@ export default async (name,domain,shareId,+ teamId,};- data.userId = userId;+ if (!teamId) {+ data.userId = userId;+ }const website = await createWebsite(data);diff --git a/src/queries/admin/website.ts b/src/queries/admin/website.tsindex ab63d255a..246ac2d04 100644--- a/src/queries/admin/website.ts+++ b/src/queries/admin/website.ts@@ -109,7 +109,7 @@ export async function createWebsite(.create({data,})- .then(async data => {+ .then(async (data: { id: any }) => {if (cache.enabled) {await cache.storeWebsite(data);}diff --git a/src/queries/index.js b/src/queries/index.tssimilarity index 100%rename from src/queries/index.jsrename to src/queries/index.ts