Connect, collaborate, and grow with a community of TypeScript developers
fix(admin): Add comment reports (#627)
Jim Burbridge572029de2ce2
diff --git a/apps/admin/src/app/challenge/[challengeId]/challenge-review.tsx b/apps/admin/src/app/challenge/[challengeId]/challenge-review.tsxindex 617cdfd9..69dc0b97 100644--- a/apps/admin/src/app/challenge/[challengeId]/challenge-review.tsx+++ b/apps/admin/src/app/challenge/[challengeId]/challenge-review.tsx@@ -32,7 +32,7 @@ export function ChallengeReview({ challenge }: Props) {variant: 'success',title: 'Challenge Approved Successfully',});- router.push('/admin');+ router.push('/?tab=challengeReviews');} catch {toast({variant: 'destructive',@@ -48,7 +48,7 @@ export function ChallengeReview({ challenge }: Props) {variant: 'success',title: 'Challenge Denied Successfully',});- router.push('/admin');+ router.push('/?tab=challengeReviews');} catch {toast({variant: 'destructive',diff --git a/apps/admin/src/app/report/[id]/_components/report/comment.report.tsx b/apps/admin/src/app/report/[id]/_components/report/comment.report.tsxindex db9a7840..d302bed3 100644--- a/apps/admin/src/app/report/[id]/_components/report/comment.report.tsx+++ b/apps/admin/src/app/report/[id]/_components/report/comment.report.tsx@@ -1,5 +1,7 @@import Link from 'next/link';+import { ExternalLink } from '@repo/ui/icons';import type { ReportWithInfo } from '../../report.action';+import { Markdown } from '@repo/ui/components/markdown';export function CommentReport({ report }: { report: NonNullable<ReportWithInfo> }) {if (report.type !== 'COMMENT' || report.commentId === null || !report.comment) return null;@@ -10,7 +12,7 @@ export function CommentReport({ report }: { report: NonNullable<ReportWithInfo><header>Commented on{' '}<Link- className="rounded-full bg-zinc-800 px-2 py-1 text-blue-600 dark:text-blue-400"+ className="inline-flex items-baseline gap-2 rounded-full bg-zinc-800 px-2 py-1 text-blue-600 dark:text-blue-400"href={`/${report.comment.rootType.toLowerCase()}/${report.comment.rootChallengeId || report.comment.rootSolutionId}`}@@ -21,11 +23,21 @@ export function CommentReport({ report }: { report: NonNullable<ReportWithInfo>{report.comment.rootType === 'CHALLENGE'? report.comment.rootChallenge?.name: report.comment.rootSolution?.title}+ <ExternalLink size={16} /></Link></header>- <section className="mt-4 rounded-lg bg-zinc-800">- <pre>{JSON.stringify(report.comment, null, 2)}</pre>- {/* <Comment comment={report.comment} readonly rootId={rootId} type={report.comment.rootType} /> */}+ <section className="mt-4 rounded-lg bg-zinc-800 p-4">+ <header className="flex gap-4">+ <div className="font-semibold">@{report.comment.user.name}</div>+ <div>+ {report.comment.createdAt.toLocaleString(undefined, {+ dateStyle: 'medium',+ timeStyle: 'medium',+ })}+ </div>+ </header>+ <Markdown>{report.comment.text}</Markdown>+ <footer className="text-zinc-400">{report.comment._count.replies} Replies</footer></section></div>);diff --git a/apps/admin/src/app/report/[id]/actions.tsx b/apps/admin/src/app/report/[id]/actions.tsxindex 6ab4b15c..a82362a1 100644--- a/apps/admin/src/app/report/[id]/actions.tsx+++ b/apps/admin/src/app/report/[id]/actions.tsx@@ -59,7 +59,7 @@ export function ReportActions({ report }: ReportActionsProps) {title: 'Success',description: <p>Comment deleted successfully</p>,});- router.push('/admin');+ router.push('/?tab=reports');} catch (e) {toast({title: 'Error',@@ -72,7 +72,7 @@ export function ReportActions({ report }: ReportActionsProps) {async function handleDisableChallenge(challengeId: number, reportId: number) {try {await banChallenge(challengeId, reportId);- router.push('/admin');+ router.push('/?tab=reports');} catch (e) {toast({title: 'Error',@@ -89,7 +89,7 @@ export function ReportActions({ report }: ReportActionsProps) {title: 'Success',description: <p>User banned successfully.</p>,});- router.push('/admin');+ router.push('/?tab=reports');} catch (e) {toast({title: 'Error',@@ -106,7 +106,7 @@ export function ReportActions({ report }: ReportActionsProps) {title: 'Success',description: <p>Dismissed successfully.</p>,});- router.push('/admin');+ router.push('/?tab=reports');} catch (e) {console.error(e);toast({@@ -123,7 +123,7 @@ export function ReportActions({ report }: ReportActionsProps) {toast({title: 'Successfully removed solution',});- router.push('/admin');+ router.push('/?tab=reports');} else {toast({title: 'Error',diff --git a/apps/admin/src/app/report/[id]/page.tsx b/apps/admin/src/app/report/[id]/page.tsxindex 3fcb396c..55f6dfcf 100644--- a/apps/admin/src/app/report/[id]/page.tsx+++ b/apps/admin/src/app/report/[id]/page.tsx@@ -21,12 +21,12 @@ const Report = async function (props: Props) {const idNum = Number(props.params.id);// Double check that we have a number, redirect out if we don'tif (isNaN(idNum)) {- return redirect('/admin');+ return redirect('/?tab=reports');}const report = await getReport(idNum);- if (!report) return redirect('/admin');+ if (!report) return redirect('/?tab=reports');let title = '';@@ -60,7 +60,7 @@ const Report = async function (props: Props) {return (<div className="container ">- <Link className="inline-flex gap-2" href="/admin">+ <Link className="inline-flex gap-2" href="/">{' '}<ChevronLeft /> <span>Back to reports</span></Link>diff --git a/apps/admin/src/app/report/[id]/report.action.ts b/apps/admin/src/app/report/[id]/report.action.tsindex c220e787..1d3c0c89 100644--- a/apps/admin/src/app/report/[id]/report.action.ts+++ b/apps/admin/src/app/report/[id]/report.action.ts@@ -1,30 +1,5 @@import { prisma } from '@repo/db';-// todo: remove this. it's not used.-export async function getReports() {- const challengeReports = await prisma.report.findMany({- where: {- type: 'CHALLENGE',- },- include: {- challenge: {- include: {- user: true,- },- },- },- });- const otherReports = await prisma.report.findMany({- where: {- type: { not: 'CHALLENGE' },- },- });- return {- challengeReports,- otherReports,- };-}-export type ReportWithInfo = Awaited<ReturnType<typeof getReport>>;export async function getReport(idNum: number) {diff --git a/packages/ui/src/icons.ts b/packages/ui/src/icons.tsindex 44b72e74..9d8b970e 100644--- a/packages/ui/src/icons.ts+++ b/packages/ui/src/icons.ts@@ -15,6 +15,7 @@ export {Clipboard,Copy,Diamond,+ ExternalLink,Flag,GitBranch,Github,