11import { Card , Metric , Text , Flex , ProgressBar , Grid } from "@tremor/react" ;
2- import Link from "next/link" ;
3- import { useSession } from "next-auth/react" ;
4- import { Plan , PrismaClient , Project , Role } from "@prisma/client" ;
5- import { getServerSession } from "next-auth" ;
6- import { authOptions } from "@/app/api/auth/[...nextauth]/AuthOptions" ;
2+ import { Role } from "@prisma/client" ;
73import { UpgradeButton } from "./UpgradeButton" ;
4+ import { getSession , prisma } from "@/app/utils" ;
85
96export default async function DashboardStatistics ( ) {
10- const session = await getServerSession ( authOptions ) ;
7+ const session = await getSession ( ) ;
118
12- const prisma = new PrismaClient ( ) ;
139 // @ts -ignore
14- const currentProjectId = session ? .user ? .currentProjectId ;
10+ const currentProjectId = session . user . currentProjectId ;
1511 const project = await prisma . project . findFirst ( {
1612 where : {
1713 id : currentProjectId ,
@@ -23,14 +19,11 @@ export default async function DashboardStatistics() {
2319
2420 if ( ! project ) return null ;
2521
26- const limits : Record < Plan , number > = { Free : 5 , Pro : 100 , Growth : 1000 } ;
27-
2822 const totalVideoUploads = await prisma . upload . count ( {
2923 where : {
3024 projectId : currentProjectId ,
3125 } ,
3226 } ) ;
33- const limit = limits [ project . plan as Plan ] ;
3427
3528 // @ts -ignore
3629 const userId = session ?. user ?. id ;
@@ -42,12 +35,16 @@ export default async function DashboardStatistics() {
4235 if ( ! userId || ! email || ! projectId || ! projectPlan )
4336 return < div > Something went wrong</ div > ;
4437
45- const currentUserRole = project . users . find ( ( user ) => user . userId === userId ) ?. role ?? Role . member ;
38+ const currentUserRole =
39+ project . users . find ( ( user ) => user . userId === userId ) ?. role ?? Role . member ;
4640
4741 return (
4842 < >
4943 < Grid numItemsSm = { 2 } numItemsLg = { 2 } className = "gap-6 mb-4" >
50- < MonthlyUsage limit = { limit } total = { totalVideoUploads } />
44+ < MonthlyUsage
45+ limit = { project . monthlyUploads }
46+ total = { totalVideoUploads }
47+ />
5148 < Card className = "p-4" >
5249 < Text > Plan</ Text >
5350 < Metric className = "text-tremor-content-emphasis" >
@@ -58,13 +55,14 @@ export default async function DashboardStatistics() {
5855 </ span >
5956 </ Metric >
6057 < Flex className = "mt-4" >
61- { ( currentUserRole == "admin" || currentUserRole == "owner" ) && projectPlan != "Growth" && (
62- < UpgradeButton
63- clientReferenceId = { clientReferenceId }
64- email = { email }
65- plan = { projectPlan }
66- />
67- ) }
58+ { ( currentUserRole == "admin" || currentUserRole == "owner" ) &&
59+ projectPlan != "Growth" && (
60+ < UpgradeButton
61+ clientReferenceId = { clientReferenceId }
62+ email = { email }
63+ plan = { projectPlan }
64+ />
65+ ) }
6866 </ Flex >
6967 </ Card >
7068 </ Grid >
0 commit comments