import React, { useEffect, useState } from "react"; // react-hook-form import { useForm } from "react-hook-form"; // icons import { ChatBubbleLeftEllipsisIcon, CheckIcon, XMarkIcon } from "@heroicons/react/24/outline"; // hooks import useUser from "hooks/use-user"; // ui import { CustomMenu, Icon } from "components/ui"; import { CommentReaction } from "components/issues"; import { LiteTextEditorWithRef, LiteReadOnlyEditorWithRef } from "@plane/lite-text-editor"; // helpers import { timeAgo } from "helpers/date-time.helper"; // types import type { IIssueComment } from "types"; import fileService from "services/file.service"; // services type Props = { comment: IIssueComment; handleCommentDeletion: (comment: string) => void; onSubmit: (commentId: string, data: Partial) => void; showAccessSpecifier?: boolean; workspaceSlug: string; }; export const CommentCard: React.FC = ({ comment, handleCommentDeletion, onSubmit, showAccessSpecifier = false, workspaceSlug, }) => { const { user } = useUser(); const editorRef = React.useRef(null); const showEditorRef = React.useRef(null); const [isEditing, setIsEditing] = useState(false); const { formState: { isSubmitting }, handleSubmit, setFocus, watch, setValue, } = useForm({ defaultValues: comment, }); const onEnter = (formData: Partial) => { if (isSubmitting) return; setIsEditing(false); onSubmit(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 {timeAgo(comment.created_at)}

{ setValue("comment_json", comment_json); setValue("comment_html", comment_html); }} />
{showAccessSpecifier && (
)}
{user?.id === comment.actor && ( setIsEditing(true)} className="flex items-center gap-1" > Edit comment {showAccessSpecifier && ( <> {comment.access === "INTERNAL" ? ( onSubmit(comment.id, { access: "EXTERNAL" })} className="flex items-center gap-1" > Switch to public comment ) : ( onSubmit(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 )}
); };