diff --git a/src/components/Activities/ReportTask.jsx b/src/components/Activities/ReportTask.jsx
index e376433f..f3dd57c2 100644
--- a/src/components/Activities/ReportTask.jsx
+++ b/src/components/Activities/ReportTask.jsx
@@ -1,33 +1,34 @@
-import React, { useState,useEffect } from "react";
+import React, { useState, useEffect } from "react";
import { formatDate } from "../../utils/dateUtils";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import showToast from "../../services/toastService";
import { TasksRepository } from "../../repositories/TaskRepository";
-import {useReportTask} from "../../hooks/useTasks";
+import { useReportTask } from "../../hooks/useTasks";
export const ReportTask = ({ report, closeModal }) => {
- const [ loading, setloading ] = useState( false );
+ const [loading, setloading] = useState(false);
const { mutate: reportTask, isPending } = useReportTask({
- onSuccessCallback: () => {
- // refetch();
- reset();
- setloading(false);
- closeModal();
- },
- onErrorCallback: () => {
- setloading(false);
- },
- } );
+ onSuccessCallback: () => {
+ reset();
+ setloading(false);
+ closeModal();
+ },
+ onErrorCallback: () => {
+ setloading(false);
+ },
+ });
const maxPending =
report?.workItem?.plannedWork - report?.workItem?.completedWork;
const schema = z.object({
- completedTask: z
- .preprocess(
- (val) => (val === "" || val === null || Number.isNaN(val) ? undefined : Number(val)),
+ completedTask: z.preprocess(
+ (val) =>
+ val === "" || val === null || Number.isNaN(val)
+ ? undefined
+ : Number(val),
z
.number({
required_error: "Completed Work must be a number",
@@ -38,215 +39,165 @@ export const ReportTask = ({ report, closeModal }) => {
message: `Completed task cannot exceed total pending tasks: ${maxPending}`,
})
),
- comment: z.string().min(1, "Comment cannot be empty"),
-});
+ comment: z.string().min(1, "Comment cannot be empty"),
+ });
-
const {
register,
handleSubmit,
- formState: {errors},
- reset
+ formState: { errors },
+ reset,
} = useForm({
resolver: zodResolver(schema),
defaultValues: { completedTask: 0, comment: "" },
});
-
-useEffect(() => {
- if (report) {
- reset({ completedTask: 0, comment: "" });
- }
-}, [report, reset]);
-
-
- // const onSubmit = async (data) => {
- // try {
- // setloading(true);
- // const reportData = {
- // ...data,
- // id: report?.id,
- // reportedDate: new Date().toISOString(),
- // checkList: [],
- // };
-
- // let response = await TasksRepository.reportTask(reportData);
- // showToast("Task Reported Successfully.", "success");
- // refetch();
- // reset()
- // setloading(false);
- // closeModal();
- // } catch ( error )
- // {
- // const msg = error.response.data.message || error.message || "Error Occur During Api Call"
- // showToast(msg, "error");
- // }
- // }
+ useEffect(() => {
+ if (report) {
+ reset({ completedTask: 0, comment: "" });
+ }
+ }, [report, reset]);
const onSubmit = (data) => {
- setloading(true);
- const reportData = {
- ...data,
- id: report?.id,
- reportedDate: new Date().toISOString(),
- checkList: [],
- };
+ setloading(true);
+ const reportData = {
+ ...data,
+ id: report?.id,
+ reportedDate: new Date().toISOString(),
+ checkList: [],
+ };
- reportTask(reportData);
-};
+ reportTask({ reportData, workAreaId: report?.workItem?.workArea?.id });
+ };
const handleClose = () => {
closeModal();
reset();
};
return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
);
};
diff --git a/src/hooks/useProjects.js b/src/hooks/useProjects.js
index e68861a2..43463370 100644
--- a/src/hooks/useProjects.js
+++ b/src/hooks/useProjects.js
@@ -459,14 +459,15 @@ export const useManageProjectAllocation = ({
isSuccess,
isError,
} = useMutation({
- mutationFn: async ({ items }) => {
+ mutationFn: async ( {items} ) =>
+ {
const response = await ProjectRepository.manageProjectAllocation(items);
return response.data;
},
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries(['empListByProjectAllocated']);
- if (context?.added) {
+ if (variables?.added) {
showToast('Employee Assigned Successfully', 'success');
} else {
showToast('Removed Employee Successfully', 'success');
diff --git a/src/hooks/useTasks.js b/src/hooks/useTasks.js
index a416dd38..d7dbe0b3 100644
--- a/src/hooks/useTasks.js
+++ b/src/hooks/useTasks.js
@@ -5,106 +5,7 @@ import {MasterRespository} from "../repositories/MastersRepository";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import showToast from "../services/toastService";
import {useSelector} from "react-redux";
-// import {formatDate} from "../utils/dateUtils";
-// export const useTaskList = (projectId, dateFrom, toDate) => {
-// const [TaskList, setTaskList] = useState([]);
-// const [loading, setLoading] = useState(false);
-// const [error, setError] = useState(null);
-
-// const fetchList = async (projectId, dateFrom, toDate) => {
-// const taskList_cached = getCachedData("taskList");
-// // if (!taskList_cached || taskList_cached?.projectId !== projectId) {
-// try {
-// setLoading(true);
-// const resp = await TasksRepository.getTaskList(
-// projectId,
-// dateFrom,
-// toDate
-// );
-// setTaskList(resp.data);
-// cacheData("taskList", { projectId: projectId, data: resp.data });
-// setLoading(false);
-// } catch (err) {
-// setLoading(false);
-// setError(err);
-// }
-// // } else {
-// // setTaskList(taskList_cached.data);
-// // }
-// };
-// useEffect( () =>
-// {
-
-// if (projectId && dateFrom && toDate) {
-// fetchList(projectId, dateFrom, toDate);
-// }
-
-// }, [projectId, dateFrom, toDate]);
-
-// return { TaskList, loading, error, refetch:fetchList};
-// };
-
-
-// export const useTaskById = (TaskId) =>
-// {
-// const [Task, setTask] = useState([]);
-// const [loading, setLoading] = useState(false);
-// const [ error, setError ] = useState( null );
-
-
-
-// const fetchTask = async(TaskId) =>
-// {
-// try
-// {
-// let res = await TasksRepository.getTaskById( TaskId );
-// setTask( res.data );
-
-// } catch ( error )
-// {
-// setError(err)
-// }
-// }
-// useEffect( () =>
-// {
-// if ( TaskId )
-// {
-// fetchTask(TaskId)
-// }
-// }, [ TaskId ] )
-// return { Task,loading}
-// }
-
-// export const useAuditStatus = () =>
-// {
-// const [ status, setStatus ] = useState( [] );
-// const [ error, setError ] = useState( '' );
-// const [ loading, setLoading ] = useState( false )
-
-// const fetchStatus = async() =>
-// {
-// try
-// {
-// const res = await MasterRespository.getAuditStatus()
-// setStatus( res.data )
-// cacheData("AuditStatus",res.data)
-// } catch ( err )
-// {
-// setError(err)
-// }
-// }
-// useEffect(() => {
-// const cache_status = getCachedData('AuditStatus');
-// if (cache_status) {
-// setStatus(cache_status);
-// } else {
-// fetchStatus();
-// }
-// }, []);
-
-// return {status,error,loading}
-// }
// ---------Query---------------------------------
@@ -197,12 +98,17 @@ export const useReportTask = ( {onSuccessCallback, onErrorCallback} = {} ) =>
isError,
error,
} = useMutation({
- mutationFn: async (reportData) => {
+ mutationFn: async ( {reportData,workAreaId} ) =>
+ {
+ debugger
return await TasksRepository.reportTask(reportData);
},
- onSuccess: (data) => {
+ onSuccess: ( data, variables ) =>
+ {
+ const {workAreaId} = variables;
+ queryClient.invalidateQueries( {queryKey: [ "taskList" ]} );
+ queryClient.invalidateQueries( {queryKey: [ "WorkItems", workAreaId ]} );
showToast( "Task Reported Successfully.", "success" );
- queryClient.invalidateQueries({ queryKey: ["taskList"] });
if (onSuccessCallback) onSuccessCallback(data);
},
onError: (error) => {
@@ -247,7 +153,7 @@ export const useSubmitTaskComment = ({ actionAllow, onSuccessCallback }) => {
if (actionAllow) {
showToast( "Review submitted successfully.", "success" );
- queryClient.invalidateQueries({ queryKey: [ "WorkItems", workAreaId ] });
+ // queryClient.invalidateQueries({ queryKey: [ "WorkItems", workAreaId ] });
} else
{
showToast("Comment sent successfully.", "success");