import BeerPostQueryResult from '@/services/BeerPost/types/BeerPostQueryResult'; import { Dispatch, FunctionComponent, SetStateAction } from 'react'; import { z } from 'zod'; import FormLabel from '@/components/ui/forms/FormLabel'; import FormError from '@/components/ui/forms/FormError'; import FormTextArea from '@/components/ui/forms/FormTextArea'; import { SubmitHandler, useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import Button from '@/components/ui/forms/Button'; import FormInfo from '@/components/ui/forms/FormInfo'; // @ts-expect-error import ReactStars from 'react-rating-stars-component'; import FormSegment from '@/components/ui/forms/FormSegment'; import BeerCommentQueryResult from '@/services/BeerPost/types/BeerCommentQueryResult'; import BeerCommentValidationSchema from '@/validation/CreateBeerCommentValidationSchema'; import sendCreateBeerCommentRequest from '@/requests/sendCreateBeerCommentRequest'; interface BeerCommentFormProps { beerPost: BeerPostQueryResult; setComments: Dispatch>; } const BeerCommentForm: FunctionComponent = ({ beerPost, setComments, }) => { const { register, handleSubmit, formState: { errors }, reset, setValue, } = useForm>({ defaultValues: { beerPostId: beerPost.id, rating: 0, }, resolver: zodResolver(BeerCommentValidationSchema), }); const onSubmit: SubmitHandler> = async ( data, ) => { setValue('rating', 0); await sendCreateBeerCommentRequest(data); setComments((prev) => prev); reset(); }; return (
Leave a comment {errors.content?.message} Rating {errors.rating?.message} setValue('rating', value)} /> ); }; export default BeerCommentForm;