import React from "react"; // swr import { mutate } from "swr"; // react hook form import { useForm } from "react-hook-form"; // services import issuesServices from "lib/services/issues.service"; // fetch keys import { PROJECT_ISSUES_COMMENTS } from "constants/fetch-keys"; // components import CommentCard from "components/project/issues/issue-detail/comment/IssueCommentCard"; // ui import { TextArea, Button, Spinner } from "ui"; // types import type { IIssueComment } from "types"; // icons import UploadingIcon from "public/animated-icons/uploading.json"; type Props = { comments?: IIssueComment[]; workspaceSlug: string; projectId: string; issueId: string; }; const defaultValues: Partial = { comment: "", }; const IssueCommentSection: React.FC = ({ comments, issueId, projectId, workspaceSlug }) => { const { register, handleSubmit, setValue, formState: { errors, isSubmitting }, reset, } = useForm({ defaultValues }); const onSubmit = async (formData: IIssueComment) => { await issuesServices .createIssueComment(workspaceSlug, projectId, issueId, formData) .then((response) => { console.log(response); mutate( PROJECT_ISSUES_COMMENTS, (prevData) => [...(prevData ?? []), response], false ); reset(defaultValues); }) .catch((error) => { console.log(error); }); }; const onCommentUpdate = async (comment: IIssueComment) => { await issuesServices .patchIssueComment(workspaceSlug, projectId, issueId, comment.id, comment) .then((response) => { console.log(response); }); }; const onCommentDelete = async (commentId: string) => { await issuesServices .deleteIssueComment(workspaceSlug, projectId, issueId, commentId) .then((response) => { console.log(response); }); }; return (
{comments ? ( comments.length > 0 ? (
{comments.map((comment) => ( ))}
) : (

No comments yet. Be the first to comment.

) ) : (
)}