import * as React from 'react'; import { useForm, SubmitHandler } from 'react-hook-form'; import I18n from 'i18n-js'; import Button from '../../common/Button'; import { DangerText } from '../../common/CustomTexts'; import { MarkdownIcon } from '../../common/Icons'; interface Props { mode: 'create' | 'update'; id?: number; name?: string; description?: string; slug?: string; handleCreate?( name: string, description: string, onSuccess: Function, ): void; handleUpdate?( id: number, name: string, description?: string, slug?: string, ): void; } interface IBoardForm { name: string; description: string; slug?: string; } const BoardForm = ({ mode, id, name, description, slug, handleCreate, handleUpdate, }: Props) => { const { register, handleSubmit, reset, formState: { isValid, errors }, watch, } = useForm({ mode: 'onChange', defaultValues: { name: name || '', description: description || '', slug: slug || undefined, }, }); const formBoardName = watch('name'); const onSubmit: SubmitHandler = data => { if (mode === 'create') { handleCreate( data.name, data.description, () => reset({ name: '', description: '' }) ); } else { handleUpdate(id, data.name, data.description, data.slug); } } return (