import React from "react"; import { useRouter } from "next/router"; // react-hook-form import { useForm, Controller } from "react-hook-form"; // ui import { SecondaryButton } from "components/ui"; // types import type { IIssueComment } from "types"; // fetch-keys import Tiptap, { ITiptapRichTextEditor } from "components/tiptap"; const TiptapEditor = React.forwardRef( (props, ref) => ); TiptapEditor.displayName = "TiptapEditor"; const defaultValues: Partial = { comment_json: "", comment_html: "", }; type Props = { disabled?: boolean; onSubmit: (data: IIssueComment) => Promise; }; export const AddComment: React.FC = ({ disabled = false, onSubmit }) => { const { control, formState: { isSubmitting }, handleSubmit, reset, setValue, watch, } = useForm({ defaultValues }); const editorRef = React.useRef(null); const router = useRouter(); const { workspaceSlug } = router.query; const handleAddComment = async (formData: IIssueComment) => { if (!formData.comment_html || !formData.comment_json || isSubmitting) return; await onSubmit(formData).then(() => { reset(defaultValues); editorRef.current?.clearEditor(); }); }; return (
( { onChange(comment_html); setValue("comment_json", comment_json); }} /> )} /> {isSubmitting ? "Adding..." : "Comment"}
); };