import React, { useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { Controller, useForm } from "react-hook-form"; import { Check, MessageSquare, MoreVertical, X } from "lucide-react"; import { Menu, Transition } from "@headlessui/react"; // components import { EditorRefApi } from "@plane/lite-text-editor"; import { LiteTextEditor, LiteTextReadOnlyEditor } from "@/components/editor"; import { CommentReactions } from "@/components/issues/peek-overview"; // helpers import { timeAgo } from "@/helpers/date-time.helper"; // mobx store import { useMobxStore } from "@/lib/mobx/store-provider"; // store import { RootStore } from "@/store/root"; // types import { Comment } from "@/types/issue"; type Props = { workspaceSlug: string; comment: Comment; }; export const CommentCard: React.FC = observer((props) => { const { comment, workspaceSlug } = props; const { project }: RootStore = useMobxStore(); const workspaceId = project.workspace?.id; // store const { user: userStore, issueDetails: issueDetailStore } = useMobxStore(); // states const [isEditing, setIsEditing] = useState(false); // refs const editorRef = useRef(null); const showEditorRef = useRef(null); // form info const { control, formState: { isSubmitting }, handleSubmit, } = useForm({ defaultValues: { comment_html: comment.comment_html }, }); const handleDelete = () => { if (!workspaceSlug || !issueDetailStore.peekId) return; issueDetailStore.deleteIssueComment(workspaceSlug, comment.project, issueDetailStore.peekId, comment.id); }; const handleCommentUpdate = async (formData: Comment) => { if (!workspaceSlug || !issueDetailStore.peekId) return; issueDetailStore.updateIssueComment(workspaceSlug, comment.project, issueDetailStore.peekId, comment.id, formData); setIsEditing(false); editorRef.current?.setEditorValue(formData.comment_html); showEditorRef.current?.setEditorValue(formData.comment_html); }; return (
{comment.actor_detail.avatar && comment.actor_detail.avatar !== "" ? ( // eslint-disable-next-line @next/next/no-img-element { ) : (
{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)}

( onChange(comment_html)} isSubmitting={isSubmitting} showSubmitButton={false} /> )} />
{userStore?.currentUser?.id === comment?.actor_detail?.id && ( {}} className="relative grid cursor-pointer place-items-center rounded p-1 text-custom-text-200 outline-none hover:bg-custom-background-80 hover:text-custom-text-100" > {({ active }) => (
)}
{({ active }) => (
)}
)}
); });