/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ import React, { useRef, useState } from "react"; import { observer } from "mobx-react"; import { Controller, useForm } from "react-hook-form"; import { MessageSquare, MoreVertical } from "lucide-react"; import { Menu, Transition } from "@headlessui/react"; // plane imports import type { EditorRefApi } from "@plane/editor"; import { CheckIcon, CloseIcon } from "@plane/propel/icons"; import type { TIssuePublicComment } from "@plane/types"; import { getFileURL } from "@plane/utils"; // components import { LiteTextEditor } from "@/components/editor/lite-text-editor"; import { CommentReactions } from "@/components/issues/peek-overview/comment/comment-reactions"; // helpers import { timeAgo } from "@/helpers/date-time.helper"; // hooks import { usePublish } from "@/hooks/store/publish"; import { useIssueDetails } from "@/hooks/store/use-issue-details"; import { useUser } from "@/hooks/store/use-user"; import useIsInIframe from "@/hooks/use-is-in-iframe"; type Props = { anchor: string; comment: TIssuePublicComment; }; export const CommentCard = observer(function CommentCard(props: Props) { const { anchor, comment } = props; // store hooks const { peekId, deleteIssueComment, updateIssueComment, uploadCommentAsset } = useIssueDetails(); const { data: currentUser } = useUser(); const { workspace: workspaceID } = usePublish(anchor); const isInIframe = useIsInIframe(); // 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 (!anchor || !peekId) return; deleteIssueComment(anchor, peekId, comment.id); }; const handleCommentUpdate = async (formData: TIssuePublicComment) => { if (!anchor || !peekId) return; updateIssueComment(anchor, peekId, comment.id, formData); setIsEditing(false); editorRef.current?.setEditorValue(formData.comment_html); showEditorRef.current?.setEditorValue(formData.comment_html); }; return (
{comment.actor_detail.avatar_url && comment.actor_detail.avatar_url !== "" ? ( { ) : (
{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} uploadFile={async (blockId, file) => { const { asset_id } = await uploadCommentAsset(file, anchor, comment.id); return asset_id; }} displayConfig={{ fontSize: "small-font", }} /> )} />
{!isInIframe && currentUser?.id === comment?.actor_detail?.id && ( {}} className="relative grid cursor-pointer place-items-center rounded-sm p-1 text-tertiary outline-none hover:bg-layer-transparent-hover" > {({ active }) => (
)}
{({ active }) => (
)}
)}
); });