mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-29 21:23:14 +08:00
[resumes][feat] Add API to submit & query for resume reviews (#313)
* [resumes][feat] Add route to submit resume reviews * [resumes][feat] Add router to query for comments * [resumes][refactor] Change limit of upvotes query * [resumes][chore] revert changes * [resumes][chore] remove comment * [resumes][chore] Use ResumesSection enum instead of hard-coded string * [resumes][refactor] Add check for user session in comments * [resumes][fix] fix linting issues Co-authored-by: Terence Ho <>
This commit is contained in:
@ -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<IFormInput> = (data) => {
|
||||
alert(JSON.stringify(data));
|
||||
// TODO: Give a feedback to the user if the action succeeds/fails
|
||||
const onSubmit: SubmitHandler<IFormInput> = 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 (
|
||||
<>
|
||||
<div className="h-[calc(100vh-13rem)] overflow-y-scroll">
|
||||
<h2 className="text-xl font-semibold text-gray-800">Add your review</h2>
|
||||
<p className="text-gray-800">
|
||||
Please fill in at least one section to submit your review
|
||||
</p>
|
||||
|
||||
<form
|
||||
className="w-full space-y-8 divide-y divide-gray-200"
|
||||
@ -144,6 +158,6 @@ export default function CommentsForm({
|
||||
}}>
|
||||
<div>Note that your review will not be saved!</div>
|
||||
</Dialog>
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -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 (
|
||||
<>
|
||||
<Button
|
||||
display="block"
|
||||
label="Add your review"
|
||||
variant="tertiary"
|
||||
onClick={() => setShowCommentsForm(true)}
|
||||
/>
|
||||
<div className="space-y-3">
|
||||
<CommentsListButton setShowCommentsForm={setShowCommentsForm} />
|
||||
<Tabs
|
||||
label="comments"
|
||||
tabs={COMMENTS_SECTIONS}
|
||||
@ -27,6 +33,6 @@ export default function CommentsList({
|
||||
onChange={(value) => setTab(value)}
|
||||
/>
|
||||
{/* TODO: Add comments lists */}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
import { signIn, useSession } from 'next-auth/react';
|
||||
import { Button } from '@tih/ui';
|
||||
|
||||
type CommentsListButtonProps = {
|
||||
setShowCommentsForm: (show: boolean) => void;
|
||||
};
|
||||
|
||||
export default function CommentsListButton({
|
||||
setShowCommentsForm,
|
||||
}: CommentsListButtonProps) {
|
||||
const { data: session, status } = useSession();
|
||||
const isSessionLoading = status === 'loading';
|
||||
|
||||
// Don't render anything
|
||||
if (isSessionLoading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Not signed in
|
||||
if (session == null) {
|
||||
return (
|
||||
<div className="flex justify-center">
|
||||
<p>
|
||||
<a
|
||||
className="text-primary-800 hover:text-primary-500"
|
||||
href="/api/auth/signin"
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
signIn();
|
||||
}}>
|
||||
Sign in
|
||||
</a>{' '}
|
||||
to join discussion
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Signed in. Return Add review button
|
||||
return (
|
||||
<Button
|
||||
display="block"
|
||||
label="Add your review"
|
||||
variant="tertiary"
|
||||
onClick={() => setShowCommentsForm(true)}
|
||||
/>
|
||||
);
|
||||
}
|
@ -3,12 +3,25 @@ import { useState } from 'react';
|
||||
import CommentsForm from './CommentsForm';
|
||||
import CommentsList from './CommentsList';
|
||||
|
||||
export default function CommentsSection() {
|
||||
type ICommentsSectionProps = {
|
||||
resumeId: string;
|
||||
};
|
||||
|
||||
// TODO: Retrieve resumeId for CommentsSection
|
||||
export default function CommentsSection({
|
||||
resumeId = '',
|
||||
}: ICommentsSectionProps) {
|
||||
const [showCommentsForm, setShowCommentsForm] = useState(false);
|
||||
|
||||
return showCommentsForm ? (
|
||||
<CommentsForm setShowCommentsForm={setShowCommentsForm} />
|
||||
<CommentsForm
|
||||
resumeId={resumeId}
|
||||
setShowCommentsForm={setShowCommentsForm}
|
||||
/>
|
||||
) : (
|
||||
<CommentsList setShowCommentsForm={setShowCommentsForm} />
|
||||
<CommentsList
|
||||
resumeId={resumeId}
|
||||
setShowCommentsForm={setShowCommentsForm}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@ -1,23 +1,24 @@
|
||||
// TODO: Move to a general enums/constants file? For resumes
|
||||
import { ResumesSection } from '@prisma/client';
|
||||
|
||||
export const COMMENTS_SECTIONS = [
|
||||
{
|
||||
label: 'General',
|
||||
value: 'general',
|
||||
value: ResumesSection.GENERAL,
|
||||
},
|
||||
{
|
||||
label: 'Education',
|
||||
value: 'education',
|
||||
value: ResumesSection.EDUCATION,
|
||||
},
|
||||
{
|
||||
label: 'Experience',
|
||||
value: 'experience',
|
||||
value: ResumesSection.EXPERIENCE,
|
||||
},
|
||||
{
|
||||
label: 'Projects',
|
||||
value: 'projects',
|
||||
value: ResumesSection.PROJECTS,
|
||||
},
|
||||
{
|
||||
label: 'Skills',
|
||||
value: 'skills',
|
||||
value: ResumesSection.SKILLS,
|
||||
},
|
||||
];
|
||||
|
Reference in New Issue
Block a user