import { FC, useEffect, useState } from "react"; import dynamic from "next/dynamic"; // types import { IIssue } from "types"; // components import { Loader, Input } from "components/ui"; const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), { ssr: false, loading: () => ( ), }); // hooks import useDebounce from "hooks/use-debounce"; export interface IssueDescriptionFormValues { name: string; description: any; description_html: string; } export interface IssueDetailsProps { issue: IIssue; handleSubmit: (value: IssueDescriptionFormValues) => void; } export const IssueDescriptionForm: FC = ({ issue, handleSubmit }) => { // states // const [issueFormValues, setIssueFormValues] = useState({ // name: issue.name, // description: issue?.description, // description_html: issue?.description_html, // }); const [issueName, setIssueName] = useState(issue?.name); const [issueDescription, setIssueDescription] = useState(issue?.description); const [issueDescriptionHTML, setIssueDescriptionHTML] = useState(issue?.description_html); // hooks const formValues = useDebounce( { name: issueName, description: issueDescription, description_html: issueDescriptionHTML }, 2000 ); const stringFromValues = JSON.stringify(formValues); useEffect(() => { handleSubmit(formValues); // eslint-disable-next-line react-hooks/exhaustive-deps }, [handleSubmit, stringFromValues]); return (
setIssueName(e.target.value)} mode="transparent" className="text-xl font-medium" required={true} /> setIssueDescription(json)} onHTMLChange={(html) => setIssueDescriptionHTML(html)} />
); };