@@ -24,13 +24,15 @@ import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
2424import { TFileContent } from '@/lib/definitions'
2525import { isValidFileContent } from '@/lib/utils'
2626
27- import { saveReport } from '@/server/actions/report'
27+ import { saveReport , countReports } from '@/server/actions/report'
2828import { saveLog } from '@/server/actions/log'
2929import { saveMetric , getMetric , updateMetric } from '@/server/actions/metric'
3030import type { ReportInferType } from '@/server/types'
3131
3232import { useEvents , EventTypes } from '@/hooks/use-events'
3333
34+ const FREE_MAX_REPORT_COUNT = 10
35+
3436export const ImportReport = ( { children } : { children : React . ReactElement } ) => {
3537 const [ loading , setLoading ] = useState < boolean > ( false )
3638 const [ reportName , setReportName ] = useState < string > ( '' )
@@ -59,7 +61,14 @@ export const ImportReport = ({ children }: { children: React.ReactElement }) =>
5961 }
6062 }
6163
62- const handleSubmit = ( ) => {
64+ const handleSubmit = async ( ) => {
65+ const userReportCount = await countReports ( { userId : userId as string } )
66+
67+ if ( userReportCount [ 0 ] . count >= FREE_MAX_REPORT_COUNT ) {
68+ toast . error ( 'You have reached the maximum number of reports allowed' )
69+ return
70+ }
71+
6372 if ( ! isValidFileContent ( reportContent ) ) {
6473 toast . error ( 'Invalid report format' )
6574 return
0 commit comments