import React, { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { Check, Globe2, Lock, MessageSquare, Pencil, Trash2, X } from "lucide-react"; // hooks import { useMention, useWorkspace } from "hooks/store"; // services import { FileService } from "services/file.service"; // ui import { CustomMenu } from "@plane/ui"; import { LiteTextEditorWithRef, LiteReadOnlyEditorWithRef } from "@plane/lite-text-editor"; // components import { IssueCommentReaction } from "./comment-reaction"; // helpers import { calculateTimeAgo } from "helpers/date-time.helper"; // types import type { IIssueActivity, IUser } from "@plane/types"; // services const fileService = new FileService(); type IIssueCommentCard = { comment: IIssueActivity; handleCommentDeletion: (comment: string) => void; onSubmit: (data: Partial) => void; showAccessSpecifier?: boolean; workspaceSlug: string; projectId: string; issueId: string; user: IUser | null; issueCommentReactionCreate: (commentId: string, reaction: string) => void; issueCommentReactionRemove: (commentId: string, reaction: string) => void; }; export const IssueCommentCard: React.FC = (props) => { const { comment, handleCommentDeletion, onSubmit, showAccessSpecifier = false, workspaceSlug, projectId, issueId, user, issueCommentReactionCreate, issueCommentReactionRemove, } = props; const workspaceStore = useWorkspace(); const workspaceId = workspaceStore.getWorkspaceBySlug(workspaceSlug)?.id as string; // states const [isEditing, setIsEditing] = useState(false); // refs const editorRef = React.useRef(null); const showEditorRef = React.useRef(null); // store hooks const { mentionHighlights, mentionSuggestions } = useMention(); // form info const { formState: { isSubmitting }, handleSubmit, setFocus, watch, setValue, } = useForm({ defaultValues: comment, }); const formSubmit = (formData: Partial) => { if (isSubmitting) return; setIsEditing(false); onSubmit({ id: comment.id, ...formData }); editorRef.current?.setEditorValue(formData.comment_html); showEditorRef.current?.setEditorValue(formData.comment_html); }; useEffect(() => { isEditing && setFocus("comment"); }, [isEditing, setFocus]); return (
{comment.actor_detail.avatar && comment.actor_detail.avatar !== "" ? ( { ) : (
{comment.actor_detail.is_bot ? comment.actor_detail.first_name.charAt(0) : comment.actor_detail.display_name.charAt(0)}
)}
{comment.actor_detail.is_bot ? comment.actor_detail.first_name + " Bot" : comment.actor_detail.display_name}

commented {calculateTimeAgo(comment.created_at)}

setValue("comment_html", comment_html)} mentionSuggestions={mentionSuggestions} mentionHighlights={mentionHighlights} />
{showAccessSpecifier && (
{comment.access === "INTERNAL" ? : }
)}
{user?.id === comment.actor && ( setIsEditing(true)} className="flex items-center gap-1"> Edit comment {showAccessSpecifier && ( <> {comment.access === "INTERNAL" ? ( onSubmit({ id: comment.id, access: "EXTERNAL" })} className="flex items-center gap-1" > Switch to public comment ) : ( onSubmit({ id: comment.id, access: "INTERNAL" })} className="flex items-center gap-1" > Switch to private comment )} )} { handleCommentDeletion(comment.id); }} className="flex items-center gap-1" > Delete comment )}
); };