import React from "react"; import { useRouter } from "next/router"; import { useForm, Controller } from "react-hook-form"; import { Globe2, Lock } from "lucide-react"; // hooks import { useMention, useWorkspace } from "hooks/store"; // services import { FileService } from "services/file.service"; // components import { LiteTextEditorWithRef } from "@plane/lite-text-editor"; // ui import { Button } from "@plane/ui"; // types import type { IIssueActivity } from "@plane/types"; const defaultValues: Partial = { access: "INTERNAL", comment_html: "", }; type IIssueCommentEditor = { disabled?: boolean; onSubmit: (data: IIssueActivity) => Promise; showAccessSpecifier?: boolean; }; type commentAccessType = { icon: any; key: string; label: "Private" | "Public"; }; const commentAccess: commentAccessType[] = [ { icon: Lock, key: "INTERNAL", label: "Private", }, { icon: Globe2, key: "EXTERNAL", label: "Public", }, ]; // services const fileService = new FileService(); export const IssueCommentEditor: React.FC = (props) => { const { disabled = false, onSubmit, showAccessSpecifier = false } = props; // refs const editorRef = React.useRef(null); // router const router = useRouter(); const { workspaceSlug } = router.query; const workspaceStore = useWorkspace(); const workspaceId = workspaceStore.getWorkspaceBySlug(workspaceSlug as string)?.id as string; // store hooks const { mentionHighlights, mentionSuggestions } = useMention(); // form info const { control, formState: { isSubmitting }, handleSubmit, reset, } = useForm({ defaultValues }); const handleAddComment = async (formData: IIssueActivity) => { if (!formData.comment_html || isSubmitting) return; await onSubmit(formData).then(() => { reset(defaultValues); editorRef.current?.clearEditor(); }); }; return (
( (

" : commentValue} customClassName="p-2 h-full" editorContentCustomClassNames="min-h-[35px]" debouncedUpdatesEnabled={false} mentionSuggestions={mentionSuggestions} mentionHighlights={mentionHighlights} onChange={(comment_json: Object, comment_html: string) => onCommentChange(comment_html)} commentAccessSpecifier={ showAccessSpecifier ? { accessValue: accessValue ?? "INTERNAL", onAccessChange, showAccessSpecifier, commentAccess } : undefined } submitButton={ } /> )} /> )} />
); };