diff --git a/src/components/Activities/ReportTaskComments.jsx b/src/components/Activities/ReportTaskComments.jsx index f116eb07..0c2f7a43 100644 --- a/src/components/Activities/ReportTaskComments.jsx +++ b/src/components/Activities/ReportTaskComments.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useState, useRef } from "react"; import { useProfile } from "../../hooks/useProfile"; import moment from "moment"; import { useForm } from "react-hook-form"; @@ -6,6 +6,9 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { TasksRepository } from "../../repositories/TaskRepository"; import showToast from "../../services/toastService"; +import Avatar from "../common/Avatar"; +import { getBgClassFromHash } from "../../utils/projectStatus"; +import {cacheData, getCachedData} from "../../slices/apiDataManager"; const schema = z.object({ comment: z.string().min(1, "Comment cannot be empty"), @@ -15,6 +18,7 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { const [loading, setloading] = useState(false); const { profile } = useProfile(); const [comments, setComment] = useState([]); + const [bgClass, setBgClass] = useState(""); const { register, handleSubmit, @@ -24,10 +28,17 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { resolver: zodResolver(schema), }); + const containerRef = useRef(null); useEffect(() => { setComment(commentsData?.comments); }, [commentsData]); - const isLoggedUser = (usrId) => profile?.employeeInfo.id; + + useEffect(() => { + if (containerRef.current) { + containerRef.current.scrollTop = containerRef.current.scrollHeight; + } + }, [comments]); + const isLoggedUser = (usrId) => profile?.employeeInfo.id === usrId; const onSubmit = async (data) => { let sendComment = { @@ -35,117 +46,113 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { taskAllocationId: commentsData?.id, commentDate: new Date().toISOString(), }; - try { setloading(true); - // const resp = await TasksRepository.taskComments( sendComment ); - // console.timeLog( resp ) + const resp = await TasksRepository.taskComments(sendComment); + setComment((prevItems) => [...prevItems, resp.data]); + const taskList = getCachedData("taskList") + const updatedTaskList = taskList.data.map((task) => { + if (task.id === resp.data.taskAllocationId) { + const existingComments = Array.isArray(task.comments) ? task.comments : []; + return { + ...task, + comments: [...existingComments, resp.data], + }; + } + return task; + }) + cacheData("taskList",{data:updatedTaskList,projectId:taskList.projectId}) reset(); setloading(false); showToast("Successfully Sent", "success"); - closeModal(); - } catch (err) { - setloading(false); + // closeModal(); + } catch (error) { + setloading( false ); + console.log(error) showToast(error.response.data?.message || "Something wrong", "error"); } }; return (
{`${ commentsData?.workItem?.workArea?.floor?.building?.name }`} {`${ commentsData?.workItem?.workArea?.floor?.floorName } `} {`${ commentsData?.workItem?.workArea?.areaName }`}{` ${commentsData?.workItem?.activityMaster?.activityName}`}
- { - comments && comments.map( ( data ) => - ( -- { `${data?.employee?.firstName} ${data?.employee?.lastName}`} -
- { moment(data?.commentDate).fromNow()} -{ data?.comment - }
-- Mahajan -
- 2 hour ago -Stylized implementation of HTML’s element for abbreviations and acronyms to show the expanded version on hover. Abbreviations have a default underline and gain a help cursor to provide additional context on hov
-- Pramod Mahajan +
{fullName}
++ + {moment.utc(data?.commentDate).local().fromNow()} + +
++ {data?.comment}
- 2 hour ago -Stylized implementation of HTML’s element for abbreviations and acronyms to show the expanded version on hover. Abbreviations have a default underline and gain a help cursor to provide additional context on hov
-