import React, { useState } from "react"; import { apiRequest } from "../../api/request"; import del from "../../assets/icons/delete.svg"; import edit from "../../assets/icons/edit.svg"; import accept from "../../assets/images/accept.png"; import { urlForLocal } from "../../utils/helper"; import { getCorrectDate } from "../Calendar/calendarHelper"; import TrackerTaskSubComment from "../TrackerTaskComment/TrackerTaskComment"; export const TrackerTaskComment = ({ taskId, comment, commentDelete, addSubComment, subCommentDelete, }) => { const [commentsEditOpen, setCommentsEditOpen] = useState(false); const [commentsEditText, setCommentsEditText] = useState(comment.text); const [subCommentsCreateOpen, setSubCommentsCreateOpen] = useState(false); const [subCommentsCreateText, setSubCommentsCreateText] = useState(""); function editComment() { if (commentsEditText === comment.text) return; apiRequest("/comment/update", { method: "PUT", data: { comment_id: comment.id, text: commentsEditText, }, }).then(() => {}); } function deleteComment() { apiRequest("/comment/update", { method: "PUT", data: { comment_id: comment.id, status: 0, }, }).then(() => { if (comment.parent_id) { subCommentDelete(comment); } else { commentDelete(comment); } }); } function createSubComment() { setSubCommentsCreateOpen(false); if (!subCommentsCreateText) return; apiRequest("/comment/create", { method: "POST", data: { text: subCommentsCreateText, entity_type: 2, entity_id: taskId, parent_id: comment.id, }, }).then((res) => { let newSubComment = res; newSubComment.created_at = new Date(); setSubCommentsCreateText(""); addSubComment(comment.id, newSubComment); }); } return (
{comment.user.fio}
{commentsEditText}
)} {!comment.parent_id && ( <> {subCommentsCreateOpen ? (