From b39a3d7e97ba5a08112396a958c907588a81fad2 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Thu, 3 Jul 2025 19:10:49 +0530 Subject: [PATCH] fixed: visible sub task without refresh page --- src/components/Activities/ReportTask.jsx | 12 ++-- .../Activities/ReportTaskComments.jsx | 62 +------------------ src/components/Activities/SubTask.jsx | 36 +++++------ .../Infrastructure/EditActivityModal.jsx | 5 +- .../Project/Infrastructure/TaskModel.jsx | 7 ++- src/hooks/useProjects.js | 8 --- src/hooks/useTasks.js | 4 +- 7 files changed, 32 insertions(+), 102 deletions(-) diff --git a/src/components/Activities/ReportTask.jsx b/src/components/Activities/ReportTask.jsx index f3dd57c2..8194a5cc 100644 --- a/src/components/Activities/ReportTask.jsx +++ b/src/components/Activities/ReportTask.jsx @@ -8,16 +8,11 @@ import { TasksRepository } from "../../repositories/TaskRepository"; import { useReportTask } from "../../hooks/useTasks"; export const ReportTask = ({ report, closeModal }) => { - const [loading, setloading] = useState(false); const { mutate: reportTask, isPending } = useReportTask({ onSuccessCallback: () => { reset(); - setloading(false); closeModal(); }, - onErrorCallback: () => { - setloading(false); - }, }); const maxPending = @@ -59,7 +54,7 @@ export const ReportTask = ({ report, closeModal }) => { }, [report, reset]); const onSubmit = (data) => { - setloading(true); + const reportData = { ...data, id: report?.id, @@ -186,13 +181,14 @@ export const ReportTask = ({ report, closeModal }) => {
- diff --git a/src/components/Activities/ReportTaskComments.jsx b/src/components/Activities/ReportTaskComments.jsx index 22e69306..c48f9796 100644 --- a/src/components/Activities/ReportTaskComments.jsx +++ b/src/components/Activities/ReportTaskComments.jsx @@ -99,63 +99,6 @@ const ReportTaskComments = ({ } }, [comments]); - // const onSubmit = async (data) => { - // let payload = { - // ...data, - // [actionAllow ? "id" : "taskAllocationId"]: commentsData?.id, - // ...(actionAllow ? {} : { commentDate: new Date().toISOString() }), - // }; - - // try { - // setloading(true); - // const resp = actionAllow - // ? await TasksRepository.auditTask(payload) - // : await TasksRepository.taskComments(payload); - - // setComment((prevItems) => [...prevItems, resp.data]); - - // const taskList = getCachedData("taskList"); - - // if (actionAllow) { - // handleCloseAction(IsNeededSubTask); - // showToast( - // "Review submitted successfully. Record has been updated.", - // "success" - // ); - // } else { - // if (taskList && taskList.data) { - // 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, - // }); - // } - // showToast("Successfully Sent", "success"); - // } - - // reset(); - // setloading(false); - // } catch (error) { - // setloading(false); - // showToast( - // error.response.data?.message || "Something went wrong", - // "error" - // ); - // } - // }; - const onSubmit = (formData) => { submitComment({ data: formData, commentsData }); }; @@ -421,15 +364,16 @@ const ReportTaskComments = ({ className="btn btn-sm btn-secondary" onClick={closeModal} data-bs-dismiss="modal" + disabled={isPending} > Close diff --git a/src/components/Project/Infrastructure/EditActivityModal.jsx b/src/components/Project/Infrastructure/EditActivityModal.jsx index 64698139..f6a86a3b 100644 --- a/src/components/Project/Infrastructure/EditActivityModal.jsx +++ b/src/components/Project/Infrastructure/EditActivityModal.jsx @@ -58,7 +58,10 @@ const EditActivityModal = ({ }, }); const { mutate: UpdateTask, isPending } = useManageTask({ - onSuccessCallback: () => onClose?.() + onSuccessCallback: (response) => + { + showToast(response?.message,"success") + } }); const activityID = watch("activityID"); diff --git a/src/components/Project/Infrastructure/TaskModel.jsx b/src/components/Project/Infrastructure/TaskModel.jsx index ba062c59..12cf8c87 100644 --- a/src/components/Project/Infrastructure/TaskModel.jsx +++ b/src/components/Project/Infrastructure/TaskModel.jsx @@ -7,6 +7,7 @@ import { useWorkCategoriesMaster, } from "../../../hooks/masterHook/useMaster"; import { useManageTask } from "../../../hooks/useProjects"; +import showToast from "../../../services/toastService"; const taskSchema = z.object({ buildingID: z.string().min(1, "Building is required"), @@ -68,7 +69,11 @@ const TaskModel = ({ project, onSubmit, onClose }) => { const selectedCategory = categoryData?.find((c) => c.id === watchCategoryId); const { mutate: CreateTask, isPending } = useManageTask({ - onSuccessCallback: () => onClose?.(), + onSuccessCallback: ( response ) => + { + showToast( response?.message, "success" ) + onClose?.() + }, }); useEffect(() => { reset(defaultModel); diff --git a/src/hooks/useProjects.js b/src/hooks/useProjects.js index 43463370..0b7eafb5 100644 --- a/src/hooks/useProjects.js +++ b/src/hooks/useProjects.js @@ -499,14 +499,6 @@ export const useManageTask = ({onSuccessCallback}) => mutationFn: async ( payload ) => await ProjectRepository.manageProjectTasks( payload ), onSuccess: ( data, variables ) => { - - if ( variables[ 0 ]?.id ) - { - showToast( 'Activity Updated Successfully', 'success' ); - } else - { - showToast( 'Activity Created Successfully', 'success' ); - } queryClient.invalidateQueries(["WorkItems"]) if (onSuccessCallback) onSuccessCallback(data); }, diff --git a/src/hooks/useTasks.js b/src/hooks/useTasks.js index d7dbe0b3..ce0d4746 100644 --- a/src/hooks/useTasks.js +++ b/src/hooks/useTasks.js @@ -115,7 +115,6 @@ export const useReportTask = ( {onSuccessCallback, onErrorCallback} = {} ) => const msg = error?.response?.data?.message || error.message || "Error occurred during API call"; showToast( msg, "error" ); - if (onErrorCallback) onErrorCallback(error); }, }); @@ -153,7 +152,6 @@ export const useSubmitTaskComment = ({ actionAllow, onSuccessCallback }) => { if (actionAllow) { showToast( "Review submitted successfully.", "success" ); - // queryClient.invalidateQueries({ queryKey: [ "WorkItems", workAreaId ] }); } else { showToast("Comment sent successfully.", "success"); @@ -181,7 +179,7 @@ export const useCreateTask = ( {onSuccessCallback, onErrorCallback} = {} ) => onSuccess: ( _, variables ) => { queryClient.invalidateQueries(["taskList"]); - showToast("Task Assigned Successfully.", "success"); + showToast( "Task Assigned Successfully.", "success" ); if (onSuccessCallback) onSuccessCallback(variables); }, onError: ( error ) =>