Skip to content

Commit e179f21

Browse files
authored
feat: set a limit to user report import (#453)
1 parent b1d9e86 commit e179f21

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/app/(studio)/studio/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ const Page = () => {
146146

147147
<Card>
148148
<CardHeader>
149-
<CardTitle>Recent Activities</CardTitle>
150-
<CardDescription>Your last 3 activities</CardDescription>
149+
<CardTitle>Recent Logs</CardTitle>
150+
<CardDescription>Your last 3 logs</CardDescription>
151151
</CardHeader>
152152
<CardContent>
153153
<Table>

src/components/mods/studio/import-report.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
2424
import { TFileContent } from '@/lib/definitions'
2525
import { isValidFileContent } from '@/lib/utils'
2626

27-
import { saveReport } from '@/server/actions/report'
27+
import { saveReport, countReports } from '@/server/actions/report'
2828
import { saveLog } from '@/server/actions/log'
2929
import { saveMetric, getMetric, updateMetric } from '@/server/actions/metric'
3030
import type { ReportInferType } from '@/server/types'
3131

3232
import { useEvents, EventTypes } from '@/hooks/use-events'
3333

34+
const FREE_MAX_REPORT_COUNT = 10
35+
3436
export 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

Comments
 (0)