From 407680fa9b45660590bf6e6ef5902e40b002830b Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Mon, 16 Jun 2025 19:41:35 +0530 Subject: [PATCH] added logic for audit activity as well as comment --- .../Activities/ReportTaskComments.jsx | 174 +++++++++++++----- 1 file changed, 132 insertions(+), 42 deletions(-) diff --git a/src/components/Activities/ReportTaskComments.jsx b/src/components/Activities/ReportTaskComments.jsx index a63a4fe6..c10df7a1 100644 --- a/src/components/Activities/ReportTaskComments.jsx +++ b/src/components/Activities/ReportTaskComments.jsx @@ -9,28 +9,48 @@ import Avatar from "../common/Avatar"; import { getBgClassFromHash } from "../../utils/projectStatus"; import { cacheData, getCachedData } from "../../slices/apiDataManager"; import ImagePreview from "../common/ImagePreview"; +import { useAuditStatus } from "../../hooks/useTasks"; -const schema = z.object({ - comment: z.string().min(1, "Comment cannot be empty"), -}); +const ReportTaskComments = ({ + commentsData, + closeModal, + actionAllow = false, +}) => { + const schema = actionAllow + ? z.object({ + comment: z.string().min(1, "Comment cannot be empty"), + workStatus: z.string().nonempty({ message: "Audit status is required" }).default(''), + approvedTask: z.preprocess( + (val) => + val === "" || val === null || Number.isNaN(val) + ? undefined + : Number(val), + z + .number({ + required_error: "Completed Work must be a number", + invalid_type_error: "Completed Work must be a number", + }) + .min(0, "Completed Work must be greater than 0") + .max(commentsData?.completedTask, { + message: `Completed task cannot exceed : ${commentsData?.completedTask}`, + }) + ), + }) + : z.object({ + comment: z.string().min(1, "Comment cannot be empty"), + }); -/** - * ReportTaskComments component for displaying and adding comments to a task. - * It also shows a summary of the activity and task details. - * - * @param {object} props - The component props. - * @param {object} props.commentsData - Data related to the task and its comments, including the description. - * @param {function} props.closeModal - Callback function to close the modal. - */ - -const ReportTaskComments = ({ commentsData, closeModal }) => { const [loading, setloading] = useState(false); const [comments, setComment] = useState([]); + const { status, loading: auditStatusLoading } = useAuditStatus(); + const { + watch, register, handleSubmit, + setValue, formState: { errors }, - reset, // Destructure reset from useForm + reset, } = useForm({ resolver: zodResolver(schema), }); @@ -64,14 +84,18 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { }, [comments]); const onSubmit = async (data) => { - let sendComment = { + let payload = { ...data, - taskAllocationId: commentsData?.id, - commentDate: new Date().toISOString(), + [actionAllow ? "id" : "taskAllocationId"]: commentsData?.id, + ...(actionAllow ? {} : { commentDate: new Date().toISOString() }), }; + try { setloading(true); - const resp = await TasksRepository.taskComments(sendComment); + const resp = actionAllow + ? await TasksRepository.auditTask(payload) + : await TasksRepository.taskComments(payload); + setComment((prevItems) => [...prevItems, resp.data]); @@ -108,12 +132,15 @@ const ReportTaskComments = ({ commentsData, closeModal }) => { ); } }; + + const selectedAuditStatus = watch("workStatus"); return ( -
+
Activity Summary

+ Location : {`${commentsData?.workItem?.workArea?.floor?.building?.name}`}{" "} @@ -127,6 +154,7 @@ const ReportTaskComments = ({ commentsData, closeModal }) => {

+ Assigned By : {commentsData?.assignedBy?.firstName + @@ -136,23 +164,19 @@ const ReportTaskComments = ({ commentsData, closeModal }) => {

- Reported By : - - {" "} - - - {/* {commentsData?.assignedBy?.firstName + - " " + - commentsData?.assignedBy?.lastName} */} - {" "} + + Reported By :-

+ {" "} + Planned Work: {commentsData?.plannedTask}{" "} {commentsData?.workItem?.activityMaster?.unitOfMeasurement}

{commentsData?.reportedDate != null && (

- {" "} + Completed Work : {commentsData?.completedTask}{" "} {commentsData?.workItem?.activityMaster?.unitOfMeasurement}

@@ -161,7 +185,9 @@ const ReportTaskComments = ({ commentsData, closeModal }) => {

Completed Work :  -

)}
-

Team :

+

+ Team : +

{commentsData?.teamMembers?.map((member, idx) => ( @@ -176,7 +202,9 @@ const ReportTaskComments = ({ commentsData, closeModal }) => {
- Note: + + Note: +
{
{commentsData?.reportedPreSignedUrls?.length > 0 && ( -
-

Attachment

- -
+ <> +

+ Attachment : +

+
+ +
+ )} +
+ {/* Taking Action Reported Task */} + {actionAllow && ( +
+
+ + + {errors.approvedTask && ( +

+ {errors.approvedTask.message} +

+ )} +
+
+ + {errors.workStatus && (

{ errors.workStatus.message}

)} +
+
+ )} +