Connect, collaborate, and grow with a community of TypeScript developers
Add the user badge to the comments (#216)
Sean Boult6379a3720350
diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 98f61d14..fa29f652 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -81,7 +81,7 @@ model Role {model User {id String @id @default(uuid())- name String?+ name Stringemail String? @uniqueemailVerified DateTime?image String?diff --git a/src/components/admin/reports.tsx b/src/components/admin/reports.tsxindex f3ef50f3..43fc228f 100644--- a/src/components/admin/reports.tsx+++ b/src/components/admin/reports.tsx@@ -24,6 +24,8 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '.import { Textarea } from '../ui/textarea';import { TypographyH3 } from '../ui/typography/h3';import { toast } from '../ui/use-toast';+import { UserBadge } from '../ui/user-badge';+interface ReportsProps {data: AdminReportDetails;}@@ -144,7 +146,9 @@ export const ReportDetails = ({ data }: ReportsProps) => {? challengeName.substring(0, 10) + '...': challengeName}</TableCell>- <TableCell>@{report.author.name}</TableCell>+ <TableCell>+ <UserBadge username={report.author.name} />+ </TableCell><TableCell title={absoluteTime}>{relativeTime}</TableCell><TableCell title={text}>{text.length > 15 ? text.substring(0, 10) : text}@@ -163,142 +167,145 @@ export const ReportDetails = ({ data }: ReportsProps) => {})}</TableBody></Table>- {/* // TODO: good first issue, dont use controlled state for this */}- <Dialog open={dialogOpen} onOpenChange={(e) => setDialogOpen(!e)}>- {/* max-w-xl is not the best solution, the dialog width need fixing with the markdown. */}- <DialogContent className="max-w-xl">- <ScrollArea className="h-[500px]">- <div className="flex flex-col gap-4">- <Card>- <CardHeader>- <CardTitle>Challenge</CardTitle>- <CardDescription>A detailed description of the challenge.</CardDescription>- </CardHeader>- <CardContent>- <div className="flex flex-col space-y-2">- <div className="flex flex-col space-y-2">- <h5 className="text-sm text-neutral-400 dark:text-neutral-600">Name</h5>- <TypographyP>{selectedIssue?.challenge.name}</TypographyP>- </div>++ {selectedIssue && (+ <Dialog open={dialogOpen} onOpenChange={(e) => setDialogOpen(!e)}>+ <DialogContent className="max-w-xl">+ <ScrollArea className="h-[500px]">+ <div className="flex flex-col gap-4">+ <Card>+ <CardHeader>+ <CardTitle>Challenge</CardTitle>+ <CardDescription>A detailed description of the challenge.</CardDescription>+ </CardHeader>+ <CardContent><div className="flex flex-col space-y-2">- <h5 className="text-sm text-neutral-400 dark:text-neutral-600">- Description- </h5>- <div className="prose-invert flex-1 leading-8 prose-h3:text-xl">- {/* todo: fix the width overflow because of markdown component. */}+ <div className="flex flex-col space-y-2">+ <h5 className="text-sm text-neutral-400 dark:text-neutral-600">Name</h5>+ <TypographyP>{selectedIssue.challenge.name}</TypographyP>+ </div>+ <div className="flex flex-col space-y-2">+ <h5 className="text-sm text-neutral-400 dark:text-neutral-600">+ Description+ </h5>+ <div className="prose-invert flex-1 leading-8 prose-h3:text-xl">+ {/* todo: fix the width overflow because of markdown component. */}- <Markdown>- {selectedIssue?.challenge.description ?? 'Not Specified.'}- </Markdown>+ <Markdown>+ {selectedIssue.challenge.description ?? 'Not Specified.'}+ </Markdown>+ </div></div>- </div>- <div className="flex flex-col space-y-2">- <h5 className="text-sm text-neutral-400 dark:text-neutral-600">Created By</h5>- <TypographyP>@{selectedIssue?.challenge.user.name}</TypographyP>- </div>- </div>- </CardContent>- </Card>- <Card>- <CardHeader>- <CardTitle>Report</CardTitle>- <CardDescription>A detailed description of the report.</CardDescription>- </CardHeader>- <CardContent>- <div className="flex flex-col space-y-2">- <div className="flex flex-col space-y-2">- <h5 className="text-sm text-neutral-400 dark:text-neutral-600">Reason</h5>- <TypographyP>- {selectedIssue?.text && selectedIssue.text.length > 0- ? selectedIssue.text- : 'Not Specified.'}- </TypographyP>- </div>- <div className="flex flex-col space-y-2">- <h5 className="text-sm text-neutral-400 dark:text-neutral-600">Tags</h5>- <div className="flex flex-wrap gap-2">- {selectedIssue?.derogatory && (- <Badge variant="destructive">Derogatory</Badge>- )}- {selectedIssue?.unclear && <Badge variant="outline">Unclear</Badge>}+ <div className="flex flex-col space-y-2">+ <h5 className="text-sm text-neutral-400 dark:text-neutral-600">+ Created By+ </h5>+ <UserBadge username={selectedIssue.challenge.user.name} /></div></div>- </div>- </CardContent>- </Card>- {selectedIssue?.moderator && (+ </CardContent>+ </Card><Card><CardHeader>- <CardTitle>Activity</CardTitle>- <CardDescription>An account of activity on the report.</CardDescription>+ <CardTitle>Report</CardTitle>+ <CardDescription>A detailed description of the report.</CardDescription></CardHeader><CardContent><div className="flex flex-col space-y-2"><div className="flex flex-col space-y-2">- <h5 className="text-sm text-neutral-400 dark:text-neutral-600">- Handled By- </h5>- <TypographyP>@{selectedIssue.moderator.name}</TypographyP>+ <h5 className="text-sm text-neutral-400 dark:text-neutral-600">Reason</h5>+ <TypographyP>+ {selectedIssue.text && selectedIssue.text.length > 0+ ? selectedIssue.text+ : 'Not Specified.'}+ </TypographyP></div><div className="flex flex-col space-y-2">- <h5 className="text-sm text-neutral-400 dark:text-neutral-600">At</h5>- <div className="flex">- {new Intl.DateTimeFormat('en-US', {- dateStyle: 'medium',- timeStyle: 'medium',- }).format(selectedIssue.updatedAt)}+ <h5 className="text-sm text-neutral-400 dark:text-neutral-600">Tags</h5>+ <div className="flex flex-wrap gap-2">+ {selectedIssue.derogatory && (+ <Badge variant="destructive">Derogatory</Badge>+ )}+ {selectedIssue.unclear && <Badge variant="outline">Unclear</Badge>}</div></div></div></CardContent></Card>- )}- <div className="flex flex-col space-y-2">- <div className="flex flex-col gap-2">- <Label htmlFor="ban_reason">Ban Reason</Label>- <Textarea- className="max-w-xl"- id="ban_reason"- placeholder="An optional ban reason..."- value={banReason}- onChange={(e) => {- setBanReason(e.target.value);- }}- />- </div>- <Button- variant={'destructive'}- onClick={handleUserBan}- className="flex items-center justify-center gap-2"- >- <Gavel className="h-4 w-4" />- Ban @{selectedIssue?.challenge.user.name}- </Button>- <Separator />- <div className="flex flex-col gap-2">- <Button- variant={'outline'}- onClick={() => {- handleDisableChallenge();- }}- className="flex items-center justify-center gap-2"- >- <EyeOff className="h-4 w-4" />- Disable Challenge- </Button>+ {selectedIssue.moderator && (+ <Card>+ <CardHeader>+ <CardTitle>Activity</CardTitle>+ <CardDescription>An account of activity on the report.</CardDescription>+ </CardHeader>+ <CardContent>+ <div className="flex flex-col space-y-2">+ <div className="flex flex-col space-y-2">+ <h5 className="text-sm text-neutral-400 dark:text-neutral-600">+ Handled By+ </h5>+ <TypographyP>@{selectedIssue.moderator.name}</TypographyP>+ </div>+ <div className="flex flex-col space-y-2">+ <h5 className="text-sm text-neutral-400 dark:text-neutral-600">At</h5>+ <div className="flex">+ {new Intl.DateTimeFormat('en-US', {+ dateStyle: 'medium',+ timeStyle: 'medium',+ }).format(selectedIssue.updatedAt)}+ </div>+ </div>+ </div>+ </CardContent>+ </Card>+ )}+ <div className="flex flex-col space-y-2">+ <div className="flex flex-col gap-2">+ <Label htmlFor="ban_reason">Ban Reason</Label>+ <Textarea+ className="max-w-xl"+ id="ban_reason"+ placeholder="An optional ban reason..."+ value={banReason}+ onChange={(e) => {+ setBanReason(e.target.value);+ }}+ />+ </div><Button- onClick={handleDismissReport}+ variant={'destructive'}+ onClick={handleUserBan}className="flex items-center justify-center gap-2">- <X className="h-4 w-4" />- Dismiss Report+ <Gavel className="h-4 w-4" />+ Ban @{selectedIssue?.challenge.user.name}</Button>+ <Separator />+ <div className="flex flex-col gap-2">+ <Button+ variant={'outline'}+ onClick={() => {+ handleDisableChallenge();+ }}+ className="flex items-center justify-center gap-2"+ >+ <EyeOff className="h-4 w-4" />+ Disable Challenge+ </Button>+ <Button+ onClick={handleDismissReport}+ className="flex items-center justify-center gap-2"+ >+ <X className="h-4 w-4" />+ Dismiss Report+ </Button>+ </div></div></div>- </div>- </ScrollArea>- </DialogContent>- </Dialog>+ </ScrollArea>+ </DialogContent>+ </Dialog>+ )}</div>);};diff --git a/src/components/admin/users.tsx b/src/components/admin/users.tsxindex 6539f4a7..67893fdc 100644--- a/src/components/admin/users.tsx+++ b/src/components/admin/users.tsx@@ -23,13 +23,13 @@ export const BannedUsers = ({ data }: BannedUsersProps) => {await unbanUser(user.id);toast({title: 'Unbanned',- description: `The user ${user.name ? '@' + user.name + ' ' : ''}was successfully unbanned.`,+ description: `The user @${user.name} was successfully unbanned.`,});} catch (e) {toast({title: 'Something went wrong.',variant: 'destructive',- description: `The user ${user.name ? '@' + user.name + ' ' : ''}could not be unbanned.`,+ description: `The user @${user.name} could not be unbanned.`,});} finally {router.refresh();diff --git a/src/components/challenge/comments/comment.tsx b/src/components/challenge/comments/comment.tsxindex 8054cfc6..406ff442 100644--- a/src/components/challenge/comments/comment.tsx+++ b/src/components/challenge/comments/comment.tsx@@ -15,6 +15,7 @@ import { TypographyLarge } from '~/components/ui/typography/large';import { toast } from '~/components/ui/use-toast';import { reportChallengeComment } from './comment.action';import { Tooltip, TooltipContent, TooltipTrigger } from '~/components/ui/tooltip';+import { UserBadge } from '~/components/ui/user-badge';interface CommentProps {comment: ChallengeRouteData['comment'][number];@@ -94,9 +95,7 @@ const Comment = ({ comment }: CommentProps) => {<div className="flex cursor-pointer flex-col gap-2 p-4 pt-2 duration-300 hover:bg-neutral-100 dark:rounded-none dark:hover:bg-zinc-700/50"><div className="flex justify-between"><div className="flex items-center gap-2">- <span className="my-auto max-w-fit rounded-full bg-neutral-200 p-1 px-2 text-xs font-bold text-neutral-500 dark:bg-zinc-700 dark:text-neutral-400">- @ {comment.user.name}- </span>+ <UserBadge username={comment.user.name} /><Tooltip delayDuration={0.05}><TooltipTrigger asChild><span className="text-sm text-neutral-500">{getRelativeTime(comment.createdAt)}</span>@@ -129,9 +128,7 @@ const Comment = ({ comment }: CommentProps) => {<div className="space-y-2"><div className="flex flex-col space-y-2 rounded-3xl border bg-zinc-900 p-3"><div className="flex items-center gap-2">- <span className="my-auto max-w-fit rounded-full bg-neutral-200 p-1 px-2 text-xs font-bold text-neutral-500 dark:bg-zinc-700 dark:text-neutral-400">- @ {comment.user.name}- </span>+ <UserBadge username={comment.user.name} /><Tooltip><span className="text-sm text-neutral-500">{getRelativeTime(comment.createdAt)}diff --git a/src/components/challenge/description/index.tsx b/src/components/challenge/description/index.tsxindex f509cd2f..609f9148 100644--- a/src/components/challenge/description/index.tsx+++ b/src/components/challenge/description/index.tsx@@ -233,7 +233,7 @@ export function Description({ challenge }: Props) {</div><div className="mb-6 flex items-center gap-2">- <UserBadge username={challenge.user.name ? challenge.user.name : ''} />+ <UserBadge username={challenge.user.name} /><DifficultyBadge difficulty={challenge.difficulty} /><TooltipProvider>diff --git a/src/components/ui/navigation.tsx b/src/components/ui/navigation.tsxindex acc250d9..fb1ad15e 100644--- a/src/components/ui/navigation.tsx+++ b/src/components/ui/navigation.tsx@@ -76,7 +76,7 @@ export function Navigation() {<span>Create a Challange</span></DropdownMenuItem></Link>- <Link className="block" href={`/@${session.user.name ?? ''}`}>+ <Link className="block" href={`/@${session.user.name}`}><DropdownMenuItem className="rounded-lg p-2 duration-300 focus:bg-accent focus:outline-none"><User className="mr-2 h-4 w-4" /><span>Profile</span>