diff --git a/apps/portal/src/components/resumes/comments/CommentsForm.tsx b/apps/portal/src/components/resumes/comments/CommentsForm.tsx index a20bfd0c..98ff8d82 100644 --- a/apps/portal/src/components/resumes/comments/CommentsForm.tsx +++ b/apps/portal/src/components/resumes/comments/CommentsForm.tsx @@ -3,7 +3,10 @@ import type { SubmitHandler } from 'react-hook-form'; import { useForm } from 'react-hook-form'; import { Button, Dialog, TextInput } from '@tih/ui'; +import { trpc } from '~/utils/trpc'; + type CommentsFormProps = Readonly<{ + resumeId: string; setShowCommentsForm: (show: boolean) => void; }>; @@ -18,6 +21,7 @@ type IFormInput = { type InputKeys = keyof IFormInput; export default function CommentsForm({ + resumeId, setShowCommentsForm, }: CommentsFormProps) { const [showDialog, setShowDialog] = useState(false); @@ -35,10 +39,17 @@ export default function CommentsForm({ skills: '', }, }); + const reviewCreateMutation = trpc.useMutation('resumes.reviews.user.create'); - // TODO: Implement mutation to database - const onSubmit: SubmitHandler = (data) => { - alert(JSON.stringify(data)); + // TODO: Give a feedback to the user if the action succeeds/fails + const onSubmit: SubmitHandler = async (data) => { + await reviewCreateMutation.mutate({ + resumeId, + ...data, + }); + + // Redirect back to comments section + setShowCommentsForm(false); }; const onCancel = () => { @@ -54,8 +65,11 @@ export default function CommentsForm({ }; return ( - <> +

Add your review

+

+ Please fill in at least one section to submit your review +

Note that your review will not be saved!
- +
); } diff --git a/apps/portal/src/components/resumes/comments/CommentsList.tsx b/apps/portal/src/components/resumes/comments/CommentsList.tsx index 397c9551..0b1d2d35 100644 --- a/apps/portal/src/components/resumes/comments/CommentsList.tsx +++ b/apps/portal/src/components/resumes/comments/CommentsList.tsx @@ -1,25 +1,31 @@ import { useState } from 'react'; -import { Button, Tabs } from '@tih/ui'; +import { Tabs } from '@tih/ui'; +import { trpc } from '~/utils/trpc'; + +import CommentsListButton from './CommentsListButton'; 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); + const commentsQuery = trpc.useQuery(['resumes.reviews.list', { resumeId }]); + + /* eslint-disable no-console */ + console.log(commentsQuery.data); + /* eslint-enable no-console */ + return ( - <> -