import { useState } from 'react'; import type { SubmitHandler } from 'react-hook-form'; import { useForm } from 'react-hook-form'; import { Button, Dialog, TextArea } from '@tih/ui'; import { trpc } from '~/utils/trpc'; type ResumeCommentsFormProps = Readonly<{ resumeId: string; setShowCommentsForm: (show: boolean) => void; }>; type IFormInput = { education: string; experience: string; general: string; projects: string; skills: string; }; type InputKeys = keyof IFormInput; export default function ResumeCommentsForm({ resumeId, setShowCommentsForm, }: ResumeCommentsFormProps) { const [showDialog, setShowDialog] = useState(false); const { register, handleSubmit, setValue, formState: { isDirty }, } = useForm({ defaultValues: { education: '', experience: '', general: '', projects: '', skills: '', }, }); const trpcContext = trpc.useContext(); const commentCreateMutation = trpc.useMutation( 'resumes.comments.user.create', { onSuccess: () => { // New Comment added, invalidate query to trigger refetch trpcContext.invalidateQueries(['resumes.comments.list']); }, }, ); // TODO: Give a feedback to the user if the action succeeds/fails const onSubmit: SubmitHandler = async (data) => { return await commentCreateMutation.mutate( { resumeId, ...data, }, { onSuccess: () => { // Redirect back to comments section setShowCommentsForm(false); }, }, ); }; const onCancel = () => { if (isDirty) { setShowDialog(true); } else { setShowCommentsForm(false); } }; const onValueChange = (section: InputKeys, value: string) => { setValue(section, value.trim(), { shouldDirty: true }); }; return (

Add your review

Please fill in at least one section to submit your review