import { ChangeEvent, FC, useCallback, useEffect, useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { useMobxStore } from "lib/mobx/store-provider"; // hooks import debounce from "lodash/debounce"; // components import { TextArea } from "@plane/ui"; import { RichTextEditor } from "@plane/rich-text-editor"; // types import { IIssue } from "types"; // services import { FileService } from "services/file.service"; import useEditorSuggestions from "hooks/use-editor-suggestions"; export interface IssueDescriptionFormValues { name: string; description_html: string; } export interface IssueDetailsProps { issue: { name: string; description_html: string; project_id?: string; }; workspaceSlug: string; handleFormSubmit: (value: IssueDescriptionFormValues) => Promise; isAllowed: boolean; setShowAlert: (value: boolean) => void; } const fileService = new FileService(); export const IssueDescriptionForm: FC = (props) => { const { issue, handleFormSubmit, workspaceSlug, isAllowed,setShowAlert } = props; // states const [characterLimit, setCharacterLimit] = useState(false); // mobx store const { projectIssues: { setIsSubmitting }, } = useMobxStore(); const editorSuggestion = useEditorSuggestions(); const { handleSubmit, watch, reset, control, formState: { errors }, } = useForm({ defaultValues: { name: "", description_html: "", }, }); const [localTitleValue, setLocalTitleValue] = useState(""); const issueTitleCurrentValue = watch("name"); useEffect(() => { if (localTitleValue === "" && issueTitleCurrentValue !== "") { setLocalTitleValue(issueTitleCurrentValue); } }, [issueTitleCurrentValue, localTitleValue]); const handleDescriptionFormSubmit = useCallback( async (formData: Partial) => { if (!formData?.name || formData?.name.length === 0 || formData?.name.length > 255) return; await handleFormSubmit({ name: formData.name ?? "", description_html: formData.description_html ?? "

", }); }, [handleFormSubmit] ); // reset form values useEffect(() => { if (!issue) return; reset({ ...issue, }); }, [issue, reset]); const debouncedFormSave = debounce(async () => { handleSubmit(handleDescriptionFormSubmit)(); }, 1500); return (
{isAllowed ? ( (