Rev 2800 | Rev 3186 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'
import { useForm } from 'react-hook-form'
import { useSelector } from 'react-redux'
import Input from '@components/UI/inputs/Input'
export default function CommentForm({ onSubmit = () => null }) {
const labels = useSelector(({ intl }) => intl.labels)
const {
control,
handleSubmit,
reset,
formState: { errors }
} = useForm({
defaultValues: {
comment: ''
}
})
const submitHandler = handleSubmit(({ comment }) => {
onSubmit(comment)
reset()
})
return (
<Input
name='comment'
placeholder={labels.write_a_comment}
control={control}
error={errors.comment?.message}
rules={{ required: 'Este campo es requerido' }}
onKeyDown={(e) => e.key === 'Enter' && submitHandler()}
variant='search'
/>
)
}