import React from "react"; import { useRouter } from "next/router"; // react-hook-form import { useForm, Controller } from "react-hook-form"; // components import { SecondaryButton } from "components/ui"; import { TipTapEditor } from "components/tiptap"; // types import type { IIssueComment } from "types"; 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"}
); };