From 0931379806f63bd457be8d07dc3402aa1ad0eb15 Mon Sep 17 00:00:00 2001 From: Terence Ho <> Date: Thu, 6 Oct 2022 23:48:01 +0800 Subject: [PATCH] [resumes][feat] Add router to query for comments --- apps/portal/prisma/schema.prisma | 2 + .../resumes/comments/CommentsForm.tsx | 3 +- .../resumes/comments/CommentsList.tsx | 11 +++++ .../resumes/comments/CommentsSection.tsx | 19 ++++++-- apps/portal/src/server/router/index.ts | 2 + .../server/router/resumes-reviews-router.ts | 44 +++++++++++++++++++ 6 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 apps/portal/src/server/router/resumes-reviews-router.ts diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index 95c4381f..668b5ba6 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -146,6 +146,8 @@ model ResumesCommentVote { updatedAt DateTime @updatedAt user User @relation(fields: [userId], references: [id], onDelete: Cascade) comment ResumesComment @relation(fields: [commentId], references: [id], onDelete: Cascade) + + @@unique([commentId, userId]) } // Start of Offers project models. diff --git a/apps/portal/src/components/resumes/comments/CommentsForm.tsx b/apps/portal/src/components/resumes/comments/CommentsForm.tsx index 97cbb34f..c21314f2 100644 --- a/apps/portal/src/components/resumes/comments/CommentsForm.tsx +++ b/apps/portal/src/components/resumes/comments/CommentsForm.tsx @@ -20,9 +20,8 @@ type IFormInput = { type InputKeys = keyof IFormInput; -// TODO: Retrieve resumeId and remove default export default function CommentsForm({ - resumeId = '', + resumeId, setShowCommentsForm, }: CommentsFormProps) { const [showDialog, setShowDialog] = useState(false); diff --git a/apps/portal/src/components/resumes/comments/CommentsList.tsx b/apps/portal/src/components/resumes/comments/CommentsList.tsx index 397c9551..c9521380 100644 --- a/apps/portal/src/components/resumes/comments/CommentsList.tsx +++ b/apps/portal/src/components/resumes/comments/CommentsList.tsx @@ -1,17 +1,28 @@ import { useState } from 'react'; import { Button, Tabs } from '@tih/ui'; +import { trpc } from '~/utils/trpc'; + import { COMMENTS_SECTIONS } from './constants'; type CommentsListProps = Readonly<{ + resumeId: string; setShowCommentsForm: (show: boolean) => void; }>; export default function CommentsList({ + resumeId, setShowCommentsForm, }: CommentsListProps) { const [tab, setTab] = useState(COMMENTS_SECTIONS[0].value); + // TODO: Render comments + const commentsQuery = trpc.useQuery(['resumes.reviews.list', { resumeId }]); + + /* eslint-disable no-console */ + console.log(commentsQuery); + /* eslint-enable no-console */ + return ( <>