import { FC, useEffect, useRef, useState } from "react"; import { useForm } from "react-hook-form"; import { Check, Globe2, Lock, Pencil, Trash2, X } from "lucide-react"; // hooks import { useIssueDetail, useMention, useUser, useWorkspace } from "hooks/store"; // components import { IssueCommentBlock } from "./comment-block"; import { LiteTextEditorWithRef, LiteReadOnlyEditorWithRef } from "@plane/lite-text-editor"; import { IssueCommentReaction } from "../../reactions/issue-comment"; // ui import { CustomMenu } from "@plane/ui"; // services import { FileService } from "services/file.service"; // types import { TIssueComment } from "@plane/types"; import { TActivityOperations } from "../root"; const fileService = new FileService(); type TIssueCommentCard = { workspaceSlug: string; commentId: string; activityOperations: TActivityOperations; ends: "top" | "bottom" | undefined; showAccessSpecifier?: boolean; }; export const IssueCommentCard: FC = (props) => { const { workspaceSlug, commentId, activityOperations, ends, showAccessSpecifier = false } = props; // hooks const { comment: { getCommentById }, } = useIssueDetail(); const { currentUser } = useUser(); const { mentionHighlights, mentionSuggestions } = useMention(); // refs const editorRef = useRef(null); const showEditorRef = useRef(null); // state const [isEditing, setIsEditing] = useState(false); const comment = getCommentById(commentId); const workspaceStore = useWorkspace(); const workspaceId = workspaceStore.getWorkspaceBySlug(comment?.workspace_detail?.slug as string)?.id as string; const { formState: { isSubmitting }, handleSubmit, setFocus, watch, setValue, } = useForm>({ defaultValues: { comment_html: comment?.comment_html }, }); const onEnter = (formData: Partial) => { if (isSubmitting || !comment) return; setIsEditing(false); activityOperations.updateComment(comment.id, formData); editorRef.current?.setEditorValue(formData.comment_html); showEditorRef.current?.setEditorValue(formData.comment_html); }; useEffect(() => { isEditing && setFocus("comment_html"); }, [isEditing, setFocus]); if (!comment || !currentUser) return <>; return ( {currentUser?.id === comment.actor && ( setIsEditing(true)} className="flex items-center gap-1"> Edit comment {showAccessSpecifier && ( <> {comment.access === "INTERNAL" ? ( activityOperations.updateComment(comment.id, { access: "EXTERNAL" })} className="flex items-center gap-1" > Switch to public comment ) : ( activityOperations.updateComment(comment.id, { access: "INTERNAL" })} className="flex items-center gap-1" > Switch to private comment )} )} activityOperations.removeComment(comment.id)} className="flex items-center gap-1" > Delete comment )} } ends={ends} > <>
setValue("comment_html", comment_html)} mentionSuggestions={mentionSuggestions} mentionHighlights={mentionHighlights} />
{showAccessSpecifier && (
{comment.access === "INTERNAL" ? : }
)}
); };