import React, { useEffect, useState } from "react"; import Image from "next/image"; import dynamic from "next/dynamic"; // 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 } from "components/ui"; // helpers import { timeAgo } from "helpers/date-time.helper"; // types import type { IIssueComment } from "types"; const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), { ssr: false }); import { IRemirrorRichTextEditor } from "components/rich-text-editor"; const WrappedRemirrorRichTextEditor = React.forwardRef< IRemirrorRichTextEditor, IRemirrorRichTextEditor >((props, ref) => ); WrappedRemirrorRichTextEditor.displayName = "WrappedRemirrorRichTextEditor"; type Props = { comment: IIssueComment; onSubmit: (comment: IIssueComment) => void; handleCommentDeletion: (comment: string) => void; }; export const CommentCard: React.FC = ({ comment, onSubmit, handleCommentDeletion }) => { const { user } = useUser(); const editorRef = React.useRef(null); const showEditorRef = React.useRef(null); const [isEditing, setIsEditing] = useState(false); const { formState: { isSubmitting }, handleSubmit, setFocus, setValue, } = useForm({ defaultValues: comment, }); const onEnter = (formData: IIssueComment) => { if (isSubmitting) return; setIsEditing(false); onSubmit(formData); console.log(formData); editorRef.current?.setEditorValue(formData.comment_json); showEditorRef.current?.setEditorValue(formData.comment_json); }; useEffect(() => { isEditing && setFocus("comment"); }, [isEditing, setFocus]); return (
{comment.actor_detail.avatar && comment.actor_detail.avatar !== "" ? ( {comment.actor_detail.first_name} ) : (
{comment.actor_detail.first_name.charAt(0)}
)}
{comment.actor_detail.first_name} {comment.actor_detail.is_bot ? "Bot" : " " + comment.actor_detail.last_name}

Commented {timeAgo(comment.created_at)}

{ setValue("comment_json", jsonValue); setValue("comment_html", htmlValue); }} placeholder="Enter Your comment..." ref={editorRef} />
{user?.id === comment.actor && ( setIsEditing(true)}>Edit { handleCommentDeletion(comment.id); }} > Delete )}
); };