import React, { useEffect, useState, useRef } from "react"; // react-hook-form import { useForm } from "react-hook-form"; // mobx import { observer } from "mobx-react-lite"; import { useMobxStore } from "lib/mobx/store-provider"; // headless ui import { Menu, Transition } from "@headlessui/react"; // icons import { ChatBubbleLeftEllipsisIcon, CheckIcon, XMarkIcon, EllipsisVerticalIcon } from "@heroicons/react/24/outline"; // helpers import { timeAgo } from "helpers/date-time.helper"; // types import { Comment } from "store/types"; import Tiptap, { ITiptapRichTextEditor } from "components/tiptap"; const TiptapEditor = React.forwardRef((props, ref) => ( )); TiptapEditor.displayName = "TiptapEditor"; type Props = { workspaceSlug: string; comment: Comment; }; export const CommentCard: React.FC = observer((props) => { const { comment, workspaceSlug } = props; const { user: userStore, issue: issueStore } = useMobxStore(); const editorRef = useRef(null); const showEditorRef = useRef(null); const [isEditing, setIsEditing] = useState(false); const { formState: { isSubmitting }, handleSubmit, setFocus, watch, setValue, } = useForm({ defaultValues: comment, }); const handleDelete = async () => { if (!workspaceSlug || !issueStore.activePeekOverviewIssueId) return; await issueStore.deleteIssueCommentAsync( workspaceSlug, comment.project, issueStore.activePeekOverviewIssueId, comment.id ); }; const handleCommentUpdate = async (formData: Comment) => { if (!workspaceSlug || !issueStore.activePeekOverviewIssueId) return; const response = await issueStore.updateIssueCommentAsync( workspaceSlug, comment.project, issueStore.activePeekOverviewIssueId, comment.id, formData ); if (response) { editorRef.current?.setEditorValue(response.comment_html); showEditorRef.current?.setEditorValue(response.comment_html); } setIsEditing(false); }; useEffect(() => { isEditing && setFocus("comment_html"); }, [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); }} />
{userStore?.currentUser?.id === comment?.actor_detail?.id && ( {}} className="relative grid place-items-center rounded p-1 text-custom-text-200 hover:text-custom-text-100 outline-none cursor-pointer hover:bg-custom-background-80" > {({ active }) => (
)}
{({ active }) => (
)}
)}
); });