import React, { useEffect, useState } from "react"; // next import Image from "next/image"; // headless ui import { Menu } from "@headlessui/react"; // react hook form import { useForm } from "react-hook-form"; // hooks import useUser from "lib/hooks/useUser"; // common import { timeAgo } from "constants/common"; // ui import { TextArea } from "ui"; // icon import { CheckIcon, EllipsisHorizontalIcon, XMarkIcon } from "@heroicons/react/24/outline"; // types import type { IIssueComment } from "types"; type Props = { comment: IIssueComment; onSubmit: (comment: IIssueComment) => void; handleCommentDeletion: (comment: string) => void; }; const CommentCard: React.FC = ({ comment, onSubmit, handleCommentDeletion }) => { const { user } = useUser(); const [isEditing, setIsEditing] = useState(false); const { register, formState: { isSubmitting }, handleSubmit, setFocus, } = useForm({ defaultValues: comment, }); const onEnter = (formData: IIssueComment) => { if (isSubmitting) return; setIsEditing(false); onSubmit(formData); }; useEffect(() => { isEditing && setFocus("comment"); }, [isEditing, setFocus]); return (
{comment.actor_detail.avatar && comment.actor_detail.avatar !== "" ? ( {comment.actor_detail.name} ) : (
{comment.actor_detail.first_name.charAt(0)}
)}
{isEditing ? (