From 4786adb052420c5836667ae6573d41da058964bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Mon, 11 Mar 2024 21:17:11 +0100 Subject: [PATCH] dashboard: allow accepted users in --- .../src/app/(app)/[organizationId]/page.tsx | 27 +++++++++++-------- apps/dashboard/src/app/(app)/page.tsx | 27 ++++++++++--------- .../migration.sql | 2 ++ packages/db/prisma/schema.prisma | 1 + packages/db/src/services/user.service.ts | 17 ++++++++++++ 5 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 packages/db/prisma/migrations/20240311201118_add_accepted_to_waitinglist/migration.sql diff --git a/apps/dashboard/src/app/(app)/[organizationId]/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/page.tsx index 1b1b08ba..ea705c60 100644 --- a/apps/dashboard/src/app/(app)/[organizationId]/page.tsx +++ b/apps/dashboard/src/app/(app)/[organizationId]/page.tsx @@ -1,10 +1,12 @@ import { LogoSquare } from '@/components/Logo'; import { ProjectCard } from '@/components/projects/project-card'; +import { notFound, redirect } from 'next/navigation'; + import { getOrganizationBySlug, getProjectsByOrganizationSlug, + isWaitlistUserAccepted, } from '@openpanel/db'; -import { notFound, redirect } from 'next/navigation'; import { CreateProject } from './create-project'; @@ -25,18 +27,21 @@ export default async function Page({ params: { organizationId } }: PageProps) { } if (process.env.BLOCK) { - return ( -
-
- -

Not quite there yet

-
- We're still working on Openpanel, but we're not quite there yet. - We'll let you know when we're ready to go! + const isAccepted = await isWaitlistUserAccepted(); + if (!isAccepted) { + return ( +
+
+ +

Not quite there yet

+
+ We're still working on Openpanel, but we're not quite there yet. + We'll let you know when we're ready to go! +
-
- ); + ); + } } if (projects.length === 0) { diff --git a/apps/dashboard/src/app/(app)/page.tsx b/apps/dashboard/src/app/(app)/page.tsx index 86a03e2b..45907d65 100644 --- a/apps/dashboard/src/app/(app)/page.tsx +++ b/apps/dashboard/src/app/(app)/page.tsx @@ -1,27 +1,30 @@ // import { CreateOrganization } from '@clerk/nextjs'; import { LogoSquare } from '@/components/Logo'; -import { getCurrentOrganizations } from '@openpanel/db'; import { redirect } from 'next/navigation'; +import { getCurrentOrganizations, isWaitlistUserAccepted } from '@openpanel/db'; + import { CreateOrganization } from './create-organization'; export default async function Page() { const organizations = await getCurrentOrganizations(); - if (process.env.BLOCK) { - return ( -
-
- -

Not quite there yet

-
- We're still working on Openpanel, but we're not quite there yet. - We'll let you know when we're ready to go! + const isAccepted = await isWaitlistUserAccepted(); + if (!isAccepted) { + return ( +
+
+ +

Not quite there yet

+
+ We're still working on Openpanel, but we're not quite there yet. + We'll let you know when we're ready to go! +
-
- ); + ); + } } if (organizations.length > 0) { diff --git a/packages/db/prisma/migrations/20240311201118_add_accepted_to_waitinglist/migration.sql b/packages/db/prisma/migrations/20240311201118_add_accepted_to_waitinglist/migration.sql new file mode 100644 index 00000000..4d3ef305 --- /dev/null +++ b/packages/db/prisma/migrations/20240311201118_add_accepted_to_waitinglist/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "waitlist" ADD COLUMN "accepted" BOOLEAN NOT NULL DEFAULT false; diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 815e63c5..1800d578 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -153,6 +153,7 @@ model Waitlist { email String @unique createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt + accepted Boolean @default(false) @@map("waitlist") } diff --git a/packages/db/src/services/user.service.ts b/packages/db/src/services/user.service.ts index a41815ce..8921fe1c 100644 --- a/packages/db/src/services/user.service.ts +++ b/packages/db/src/services/user.service.ts @@ -1,6 +1,8 @@ import { auth, clerkClient } from '@clerk/nextjs'; import type { User } from '@clerk/nextjs/dist/types/server'; +import { db } from '../prisma-client'; + export function transformUser(user: User) { return { name: `${user.firstName} ${user.lastName}`, @@ -22,3 +24,18 @@ export async function getCurrentUser() { export async function getUserById(id: string) { return clerkClient.users.getUser(id).then(transformUser); } + +export async function isWaitlistUserAccepted() { + const user = await getCurrentUser(); + const waitlist = await db.waitlist.findFirst({ + where: { + email: user?.email, + }, + }); + + if (!waitlist) { + return false; + } + + return waitlist.accepted; +}