+
{projectInfo.shortName
? projectInfo.shortName
@@ -227,12 +228,7 @@ const ProjectCard = ({ projectData, recall }) => {
Task: {formatNumber(projectInfo.completedWork)} / {formatNumber(projectInfo.plannedWork)}
- {Math.floor(
- getProgressInNumber(
- projectInfo.plannedWork,
- projectInfo.completedWork
- )
- ) || 0}{" "}
+ {getCompletionPercentage(projectInfo.completedWork, projectInfo.plannedWork)}
% Completed
diff --git a/src/components/Project/ProjectOverview.jsx b/src/components/Project/ProjectOverview.jsx
index c489c339..f258ce8b 100644
--- a/src/components/Project/ProjectOverview.jsx
+++ b/src/components/Project/ProjectOverview.jsx
@@ -3,7 +3,7 @@ import {
useEmployeesByProjectAllocated,
useProjects,
} from "../../hooks/useProjects";
-import { formatNumber } from "../../utils/dateUtils";
+import { formatNumber, getCompletionPercentage } from "../../utils/dateUtils";
import ProgressBar from "../common/ProgressBar";
const ProjectOverview = ({ project }) => {
@@ -49,9 +49,8 @@ const ProjectOverview = ({ project }) => {
)
) || 0}{" "} */}
{
- (formatNumber(project_detail.plannedWork),
- "/",
- formatNumber(project_detail.completedWork))
+ getCompletionPercentage( formatNumber(project_detail.completedWork),formatNumber(project_detail.plannedWork))
+
}
% Completed
diff --git a/src/hooks/useProjects.js b/src/hooks/useProjects.js
index 2cc5ee1d..daf705fa 100644
--- a/src/hooks/useProjects.js
+++ b/src/hooks/useProjects.js
@@ -6,7 +6,12 @@ import { useDispatch, useSelector } from "react-redux";
import { setProjectId } from "../slices/localVariablesSlice";
import EmployeeList from "../components/Directory/EmployeeList";
import eventBus from "../services/eventBus";
-import {Mutation, useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
+import {
+ Mutation,
+ useMutation,
+ useQuery,
+ useQueryClient,
+} from "@tanstack/react-query";
import showToast from "../services/toastService";
// export const useProjects = () => {
@@ -211,7 +216,7 @@ export const useProjects = () => {
error,
refetch,
} = useQuery({
- queryKey: ['ProjectsList'],
+ queryKey: ["ProjectsList"],
queryFn: async () => {
const response = await ProjectRepository.getProjectList();
return response.data;
@@ -227,97 +232,112 @@ export const useProjects = () => {
};
};
-export const useEmployeesByProjectAllocated = (selectedProject) =>
-{
- const {data = [], isLoading, refetch, error} = useQuery( {
- queryKey: ["empListByProjectAllocated", selectedProject ],
- queryFn: async () =>
- {
- const res = await ProjectRepository.getProjectAllocation( selectedProject );
- return res.data || res
+export const useEmployeesByProjectAllocated = (selectedProject) => {
+ const {
+ data = [],
+ isLoading,
+ refetch,
+ error,
+ } = useQuery({
+ queryKey: ["empListByProjectAllocated", selectedProject],
+ queryFn: async () => {
+ const res = await ProjectRepository.getProjectAllocation(selectedProject);
+ return res.data || res;
},
enabled: !!selectedProject,
- onError: ( error ) =>
- {
- showToast(error.message || "Error while Fetching project Allocated Employees", "error");
- }
- } )
-
+ onError: (error) => {
+ showToast(
+ error.message || "Error while Fetching project Allocated Employees",
+ "error"
+ );
+ },
+ });
+
return {
projectEmployees: data,
- loading:isLoading,
+ loading: isLoading,
error,
- refetch
- }
-}
+ refetch,
+ };
+};
-export const useProjectDetails = ( projectId,isAuto = true ) =>
-{
- const {data: projects_Details, isLoading, error, refetch} = useQuery( {
- queryKey: [ "projectInfo", projectId ],
- queryFn: async () =>
- {
- const res = await ProjectRepository.getProjectByprojectId( projectId );
+export const useProjectDetails = (projectId, isAuto = true) => {
+ const {
+ data: projects_Details,
+ isLoading,
+ error,
+ refetch,
+ } = useQuery({
+ queryKey: ["projectInfo", projectId],
+ queryFn: async () => {
+ const res = await ProjectRepository.getProjectByprojectId(projectId);
return res.data || res;
},
enabled: !!projectId && isAuto,
- onError: ( error ) =>
- {
- showToast(error.message || "Error while Fetching project Details", "error");
- }
- } )
- return { projects_Details, loading:isLoading, error, refetch };
-}
+ onError: (error) => {
+ showToast(
+ error.message || "Error while Fetching project Details",
+ "error"
+ );
+ },
+ });
+ return { projects_Details, loading: isLoading, error, refetch };
+};
-export const useProjectsByEmployee = (employeeId) =>
-{
- const { data:projectNameList =[],isLoading,error,refetch} = useQuery( {
- queryKey: [ "ProjectsByEmployee", employeeId ],
- queryFn: async () =>
- {
- const res = await ProjectRepository.getProjectsByEmployee( employeeId );
+export const useProjectsByEmployee = (employeeId) => {
+ const {
+ data: projectNameList = [],
+ isLoading,
+ error,
+ refetch,
+ } = useQuery({
+ queryKey: ["ProjectsByEmployee", employeeId],
+ queryFn: async () => {
+ const res = await ProjectRepository.getProjectsByEmployee(employeeId);
return res.data || res;
},
enabled: !!employeeId,
- onError: ( error ) =>
- {
- showToast(error.message || "Error while Fetching project Employee", "error");
- }
- })
- return {projectList, loading:isLoading,error,refetch }
-}
+ onError: (error) => {
+ showToast(
+ error.message || "Error while Fetching project Employee",
+ "error"
+ );
+ },
+ });
+ return { projectList, loading: isLoading, error, refetch };
+};
-export const useProjectName = () =>
-{
- const {data = [],isLoading,error,refetch} = useQuery( {
- queryKey: [ "basicProjectNameList" ],
- queryFn: async () =>
- {
+export const useProjectName = () => {
+ const {
+ data = [],
+ isLoading,
+ error,
+ refetch,
+ } = useQuery({
+ queryKey: ["basicProjectNameList"],
+ queryFn: async () => {
const res = await ProjectRepository.projectNameList();
return res.data || res;
},
- onError: ( error ) =>
- {
- showToast(error.message || "Error while Fetching project Name", "error");
- }
- } )
- return {projectNames:data,loading:isLoading,Error:error,refetch}
-}
+ onError: (error) => {
+ showToast(error.message || "Error while Fetching project Name", "error");
+ },
+ });
+ return { projectNames: data, loading: isLoading, Error: error, refetch };
+};
-
-
export const useProjectInfra = (projectId) => {
const {
data: projectInfra,
isLoading,
error,
} = useQuery({
- queryKey: ["ProjectInfra", projectId],
+ queryKey: ["ProjectInfra", projectId],
queryFn: async () => {
const res = await ProjectRepository.getProjectInfraByproject(projectId);
return res.data;
},
- enabled: !!projectId ,
+ enabled: !!projectId,
onError: (error) => {
showToast(error.message || "Error while fetching project infra", "error");
},
@@ -326,30 +346,27 @@ export const useProjectInfra = (projectId) => {
return { projectInfra, isLoading, error };
};
-
-export const useProjectTasks = (workAreaId,IsExpandedArea=false) =>
-{
- const { data:ProjectTaskList,isLoading,error } = useQuery( {
- queryKey: [ "WorkItems",workAreaId ],
- queryFn: async () =>
- {
+export const useProjectTasks = (workAreaId, IsExpandedArea = false) => {
+ const {
+ data: ProjectTaskList,
+ isLoading,
+ error,
+ } = useQuery({
+ queryKey: ["WorkItems", workAreaId],
+ queryFn: async () => {
const res = await ProjectRepository.getProjectTasksByWorkArea(workAreaId);
return res.data;
},
enabled: !!workAreaId && !!IsExpandedArea,
- onError: ( error ) =>
- {
- showToast(error.message || "Error while Fetching project Tasks", "error");
- }
- } )
- return {ProjectTaskList,isLoading,error}
-}
-
+ onError: (error) => {
+ showToast(error.message || "Error while Fetching project Tasks", "error");
+ },
+ });
+ return { ProjectTaskList, isLoading, error };
+};
// -- -------------Mutation-------------------------------
-
-
export const useCreateProject = ({ onSuccessCallback }) => {
const queryClient = useQueryClient();
@@ -360,8 +377,8 @@ export const useCreateProject = ({ onSuccessCallback }) => {
},
onSuccess: (data) => {
// Invalidate the cache
- queryClient.invalidateQueries( {queryKey: [ 'ProjectsList' ]} );
- queryClient.invalidateQueries({queryKey:['basicProjectNameList']});
+ queryClient.invalidateQueries({ queryKey: ["ProjectsList"] });
+ queryClient.invalidateQueries({ queryKey: ["basicProjectNameList"] });
// Emit event for consumers (like useProjects or others)
eventBus.emit("project", {
@@ -381,27 +398,19 @@ export const useCreateProject = ({ onSuccessCallback }) => {
});
};
-
export const useUpdateProject = ({ onSuccessCallback }) => {
const queryClient = useQueryClient();
- const {
- mutate,
- isPending,
- isSuccess,
- isError,
- } = useMutation({
- mutationFn: async ( {projectId, updatedData} ) =>
- {
+ const { mutate, isPending, isSuccess, isError } = useMutation({
+ mutationFn: async ({ projectId, updatedData }) => {
return await ProjectRepository.updateProject(projectId, updatedData);
},
- onSuccess: ( data, variables ) =>
- {
+ onSuccess: (data, variables) => {
const { projectId } = variables;
-
- queryClient.invalidateQueries({queryKey:["ProjectsList"]});
- queryClient.invalidateQueries( {queryKey: [ "projectInfo", projectId ]} );
- queryClient.invalidateQueries({queryKey:['basicProjectNameList']});
+
+ queryClient.invalidateQueries({ queryKey: ["ProjectsList"] });
+ queryClient.invalidateQueries({ queryKey: ["projectInfo", projectId] });
+ queryClient.invalidateQueries({ queryKey: ["basicProjectNameList"] });
eventBus.emit("project", {
keyword: "Update_Project",
@@ -415,9 +424,8 @@ export const useUpdateProject = ({ onSuccessCallback }) => {
}
},
- onError: ( error ) =>
- {
- console.log(error)
+ onError: (error) => {
+ console.log(error);
showToast(error?.message || "Error while updating project", "error");
},
});
@@ -430,20 +438,16 @@ export const useUpdateProject = ({ onSuccessCallback }) => {
};
};
-
-export const useManageProjectInfra = ( {onSuccessCallback} ) =>
-{
+export const useManageProjectInfra = ({ onSuccessCallback }) => {
const queryClient = useQueryClient();
return useMutation({
- mutationFn: async ( {infraObject, projectId} ) =>
- {
+ mutationFn: async ({ infraObject, projectId }) => {
return await ProjectRepository.manageProjectInfra(infraObject);
},
- onSuccess: ( data, variables ) =>
- {
- const { projectId } = variables;
- queryClient.invalidateQueries({queryKey:["ProjectInfra", projectId]});
- if (onSuccessCallback) onSuccessCallback(data,variables);
+ onSuccess: (data, variables) => {
+ const { projectId } = variables;
+ queryClient.invalidateQueries({ queryKey: ["ProjectInfra", projectId] });
+ if (onSuccessCallback) onSuccessCallback(data, variables);
},
onError: (error) => {
showToast(error.message || "Failed to update Project Infra", "error");
@@ -451,39 +455,36 @@ export const useManageProjectInfra = ( {onSuccessCallback} ) =>
});
};
-
export const useManageProjectAllocation = ({
onSuccessCallback,
onErrorCallback,
}) => {
const queryClient = useQueryClient();
- const {
- mutate,
- isPending,
- isSuccess,
- isError,
- } = useMutation({
- mutationFn: async ( {items} ) =>
- {
+ const { mutate, isPending, isSuccess, isError } = useMutation({
+ mutationFn: async ({ items }) => {
const response = await ProjectRepository.manageProjectAllocation(items);
return response.data;
},
onSuccess: (data, variables, context) => {
- queryClient.invalidateQueries({queryKey:['empListByProjectAllocated']});
- queryClient.removeQueries({queryKey:["projectEmployees"]})
+ queryClient.invalidateQueries({
+ queryKey: ["empListByProjectAllocated"],
+ });
+ queryClient.removeQueries({ queryKey: ["projectEmployees"] });
if (variables?.added) {
- showToast('Employee Assigned Successfully', 'success');
+ showToast("Employee Assigned Successfully", "success");
} else {
- showToast('Removed Employee Successfully', 'success');
+ showToast("Removed Employee Successfully", "success");
}
if (onSuccessCallback) onSuccessCallback(data, context);
},
onError: (error) => {
const message =
- error?.response?.data?.message || error.message || 'Error occurred during API call';
- showToast(message, 'error');
+ error?.response?.data?.message ||
+ error.message ||
+ "Error occurred during API call";
+ showToast(message, "error");
if (onErrorCallback) onErrorCallback(error);
},
});
@@ -496,48 +497,199 @@ export const useManageProjectAllocation = ({
};
};
-export const useManageTask = ({onSuccessCallback}) =>
-{
+export const useManageTask = ({ onSuccessCallback }) => {
const queryClient = useQueryClient();
+ const selectedProject = useSelector(
+ (store) => store.localVariables.projectId
+ );
+ return useMutation({
+ mutationFn: async ({
+ payload,
+ PreviousPlannedWork,
+ previousCompletedWork,
+ buildingId,
+ floorId,
+ workAreaId,
+ }) => await ProjectRepository.manageProjectTasks(payload),
+ onSuccess: (data, variables) => {
+ const {
+ workAreaId,
+ buildingId,
+ floorId,
+ PreviousPlannedWork,
+ previousCompletedWork,
+ } = variables;
+ queryClient.invalidateQueries({ queryKey: ["WorkItems"] });
+ const getPlannedDelta = (previous, current) => current - previous;
+ queryClient.setQueryData(["ProjectInfra", selectedProject], (oldData) => {
+ if (!oldData) return oldData;
+ const { workAreaId, floorId, buildingId } = variables;
+ const updatedData = JSON.parse(JSON.stringify(oldData));
+ return updatedData.map((building) => {
+ if (building.id !== buildingId) return building;
+ return {
+ ...building,
+ floors: building.floors.map((floor) => {
+ if (floor.id !== floorId) return floor;
- return useMutation( {
- mutationFn: async ( payload ) => await ProjectRepository.manageProjectTasks( payload ),
- onSuccess: ( data, variables ) =>
- {
- queryClient.invalidateQueries({ queryKey: ["WorkItems"] })
+ return {
+ ...floor,
+ workAreas: floor.workAreas.map((area) => {
+ if (area.id !== workAreaId) return area;
+
+ const previousPlanned = PreviousPlannedWork ?? 0;
+ const currentPlanned =
+ data?.data[0]?.workItem.plannedWork ?? 0;
+
+ const plannedWorkDelta = getPlannedDelta(
+ previousPlanned,
+ currentPlanned
+ );
+ const updatedPlannedWork =
+ (area.plannedWork ?? 0) + plannedWorkDelta;
+ const previousCompleted = previousCompletedWork;
+
+ const currentCompleted =
+ data?.data[0]?.workItem.completedWork ?? 0;
+ const completedWorkDelta = getPlannedDelta(
+ previousCompleted,
+ currentCompleted
+ );
+ const updatedCompletedWork =
+ (area.completedWork ?? 0) + completedWorkDelta;
+ return {
+ ...area,
+ plannedWork: updatedPlannedWork,
+ completedWork: updatedCompletedWork,
+ };
+ }),
+ };
+ }),
+ };
+ });
+ });
+
+ queryClient.setQueryData(["ProjectsList"], (projects) => {
+ if (!projects) return projects;
+
+ return projects.map((project) => {
+ if (project.id !== selectedProject) return project;
+
+ const previousPlanned = PreviousPlannedWork ?? 0;
+ const currentPlanned = data?.data[0]?.workItem.plannedWork ?? 0;
+
+ const plannedWorkDelta = getPlannedDelta(
+ previousPlanned,
+ currentPlanned
+ );
+ const updatedPlannedWork =
+ (project.plannedWork ?? 0) + plannedWorkDelta;
+ const previousCompleted = previousCompletedWork;
+ const currentCompleted = data?.data[0]?.workItem.completedWork ?? 0;
+ const completedWorkDelta = getPlannedDelta(
+ previousCompleted,
+ currentCompleted
+ );
+ const updatedCompletedWork =
+ (project.completedWork ?? 0) + completedWorkDelta;
+ return {
+ ...project,
+ plannedWork: updatedPlannedWork,
+ completedWork: updatedCompletedWork,
+ };
+ });
+ });
if (onSuccessCallback) onSuccessCallback(data);
},
- onError: (error) =>
- {
- const message =
- error?.response?.data?.message || error.message || 'Error occurred during API call';
- showToast(message, 'error');
- }
-
- })
-}
-
-export const useDeleteProjectTask = (onSuccessCallback) => {
- const queryClient = useQueryClient();
-
- return useMutation({
- mutationFn: async ( {workItemId, workAreaId} ) =>
- {
- return await ProjectRepository.deleteProjectTask(workItemId);
- },
- onSuccess: ( _, variables ) =>
- {
- showToast("Task deleted successfully", "success");
- queryClient.invalidateQueries({queryKey:[ "WorkItems",variables.workAreaId]});
- if (onSuccessCallback) onSuccessCallback();
- },
onError: (error) => {
- showToast(
- error?.response?.data?.message || error.message || "Failed to delete task",
- "error"
- );
- if (onSuccessCallback) onSuccessCallback();
+ const message =
+ error?.response?.data?.message ||
+ error.message ||
+ "Error occurred during API call";
+ showToast(message, "error");
},
});
};
+export const useDeleteProjectTask = (onSuccessCallback) => {
+ const queryClient = useQueryClient();
+ const selectedProject = useSelector(
+ (store) => store.localVariables.projectId
+ );
+ return useMutation({
+ mutationFn: async ({
+ workItemId,
+ workAreaId,
+ completedTask,
+ plannedTask,
+ }) => {
+ return await ProjectRepository.deleteProjectTask(workItemId);
+ },
+ onSuccess: (_, variables) => {
+ const { completedTask, plannedTask, workAreaId, buildingId, floorId } =
+ variables;
+
+ queryClient.invalidateQueries({
+ queryKey: ["WorkItems", variables.workAreaId],
+ });
+
+ queryClient.setQueryData(["ProjectInfra", selectedProject], (oldData) => {
+ if (!oldData) return oldData;
+
+ const { workAreaId, floorId, buildingId, plannedTask, completedTask } =
+ variables;
+
+ const updatedData = JSON.parse(JSON.stringify(oldData));
+
+ return updatedData.map((building) => {
+ if (building.id !== buildingId) return building;
+
+ return {
+ ...building,
+ floors: building.floors.map((floor) => {
+ if (floor.id !== floorId) return floor;
+
+ return {
+ ...floor,
+ workAreas: floor.workAreas.map((area) => {
+ if (area.id !== workAreaId) return area;
+
+ return {
+ ...area,
+ plannedWork: (area.plannedWork ?? 0) - plannedTask,
+ completedWork: (area.completedWork ?? 0) - completedTask,
+ };
+ }),
+ };
+ }),
+ };
+ });
+ });
+
+ queryClient.setQueryData(["ProjectsList"], (projects) => {
+ if (!projects) return projects;
+
+ return projects.map((project) => {
+ if (project.id !== selectedProject) return project;
+
+ return {
+ ...project,
+ plannedWork: (project.plannedWork ?? 0) - plannedTask,
+ completedWork: (project.completedWork ?? 0) - completedTask,
+ };
+ });
+ });
+ showToast("Task deleted successfully", "success");
+ if (onSuccessCallback) onSuccessCallback();
+ },
+ onError: (error) => {
+ showToast(
+ error?.response?.data?.message ||
+ error.message ||
+ "Failed to delete task",
+ "error"
+ );
+ if (onSuccessCallback) onSuccessCallback();
+ },
+ });
+};
diff --git a/src/hooks/useTasks.js b/src/hooks/useTasks.js
index 1cf531c0..b793ced4 100644
--- a/src/hooks/useTasks.js
+++ b/src/hooks/useTasks.js
@@ -1,11 +1,10 @@
import { useEffect, useState } from "react";
import { TasksRepository } from "../repositories/TaskRepository";
import { cacheData, getCachedData } from "../slices/apiDataManager";
-import {MasterRespository} from "../repositories/MastersRepository";
+import { MasterRespository } from "../repositories/MastersRepository";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import showToast from "../services/toastService";
-import {useSelector} from "react-redux";
-
+import { useSelector } from "react-redux";
// ---------Query---------------------------------
@@ -28,7 +27,6 @@ export const useTaskList = (projectId, dateFrom, toDate) => {
return response.data;
},
enabled,
-
});
return { TaskList, loading, error, refetch };
@@ -46,7 +44,7 @@ export const useTaskById = (TaskId) => {
const res = await TasksRepository.getTaskById(TaskId);
return res.data;
},
- enabled: !!TaskId,
+ enabled: !!TaskId,
});
return { Task, loading, error, refetch };
@@ -75,47 +73,80 @@ export const useAuditStatus = () => {
const res = await MasterRespository.getAuditStatus();
return res.data;
},
-
});
return { status, loading, error, refetch };
};
-
// -----------------------Mutation------------------------
-const toDate = new Date().toISOString().split('T')[0];
-const dateFrom = new Date(Date.now() - 6 * 24 * 60 * 60 * 1000).toISOString().split('T')[0];
+const toDate = new Date().toISOString().split("T")[0];
+const dateFrom = new Date(Date.now() - 6 * 24 * 60 * 60 * 1000)
+ .toISOString()
+ .split("T")[0];
-
-
-export const useReportTask = ( {onSuccessCallback, onErrorCallback} = {} ) =>
-{
+export const useReportTask = ({ onSuccessCallback, onErrorCallback } = {}) => {
const queryClient = useQueryClient();
- const {
- mutate,
- isPending,
- isSuccess,
- isError,
- error,
- } = useMutation({
- mutationFn: async ( {reportData,workAreaId} ) =>
- {
- debugger
+ const selectedProject = useSelector(
+ (store) => store.localVariables.projectId
+ );
+ const { mutate, isPending, isSuccess, isError, error } = useMutation({
+ mutationFn: async ({ reportData, workAreaId }) => {
return await TasksRepository.reportTask(reportData);
},
- onSuccess: ( data, variables ) =>
- {
- const {workAreaId} = variables;
- queryClient.invalidateQueries( {queryKey: [ "taskList" ]} );
- queryClient.invalidateQueries( {queryKey: [ "WorkItems", workAreaId ]} );
- queryClient.invalidateQueries( {queryKey: [ 'ProjectsList' ]} );
- showToast( "Task Reported Successfully.", "success" );
+ onSuccess: (data, variables) => {
+ const { workAreaId, buildingId, floorId } = variables;
+ queryClient.invalidateQueries({ queryKey: ["taskList"] });
+ queryClient.invalidateQueries({ queryKey: ["WorkItems", workAreaId] });
+ queryClient.setQueryData(["ProjectInfra", selectedProject], (oldData) => {
+ if (!oldData) return oldData;
+ const { workAreaId, floorId, buildingId } = variables;
+ const updatedData = JSON.parse(JSON.stringify(oldData));
+
+ return updatedData.map((building) => {
+ if (building.id !== buildingId) return building;
+ return {
+ ...building,
+ floors: building.floors.map((floor) => {
+ if (floor.id !== floorId) return floor;
+
+ return {
+ ...floor,
+ workAreas: floor.workAreas.map((area) => {
+ if (area.id !== workAreaId) return area;
+ return {
+ ...area,
+ completedWork:
+ (area.completedWork ?? 0) +
+ (data?.data?.completedTask ?? 0),
+ };
+ }),
+ };
+ }),
+ };
+ });
+ });
+ queryClient.setQueryData(["ProjectsList"], (projects) => {
+ if (!projects) return projects;
+ const updatedProject = JSON.parse(JSON.stringify(projects));
+ return updatedProject.map((project) => {
+ if (project.id !== selectedProject) return project;
+
+ return {
+ ...project,
+ completedWork:
+ (project.completedWork ?? 0) + (data?.data?.completedTask ?? 0),
+ };
+ });
+ });
+ showToast("Task Reported Successfully.", "success");
if (onSuccessCallback) onSuccessCallback(data);
},
onError: (error) => {
const msg =
- error?.response?.data?.message || error.message || "Error occurred during API call";
- showToast( msg, "error" );
+ error?.response?.data?.message ||
+ error.message ||
+ "Error occurred during API call";
+ showToast(msg, "error");
},
});
@@ -145,16 +176,12 @@ export const useSubmitTaskComment = ({ actionAllow, onSuccessCallback }) => {
return response.data;
},
- onSuccess: ( data,variables ) =>
- {
-
+ onSuccess: (data, variables) => {
const workAreaId = variables?.commentsData?.workItem?.workArea?.id;
queryClient.invalidateQueries({ queryKey: ["taskList"] });
if (actionAllow) {
- showToast( "Review submitted successfully.", "success" );
-
- } else
- {
+ showToast("Review submitted successfully.", "success");
+ } else {
showToast("Comment sent successfully.", "success");
}
@@ -162,7 +189,10 @@ export const useSubmitTaskComment = ({ actionAllow, onSuccessCallback }) => {
},
onError: (error) => {
- const msg = error?.response?.data?.message || error.message || "Error during API call";
+ const msg =
+ error?.response?.data?.message ||
+ error.message ||
+ "Error during API call";
showToast(msg, "error");
},
});
@@ -170,24 +200,23 @@ export const useSubmitTaskComment = ({ actionAllow, onSuccessCallback }) => {
return { submitComment: mutate, isPending };
};
-export const useCreateTask = ( {onSuccessCallback, onErrorCallback} = {} ) =>
-{
+export const useCreateTask = ({ onSuccessCallback, onErrorCallback } = {}) => {
const queryClient = useQueryClient();
return useMutation({
- mutationFn: async ({payload,workAreaId}) => {
+ mutationFn: async ({ payload, workAreaId }) => {
return await TasksRepository.assignTask(payload);
},
- onSuccess: ( _, variables ) =>
- {
- queryClient.invalidateQueries( {queryKey: [ "taskList" ]} );
- queryClient.invalidateQueries( {queryKey: [ "WorkItems", variables?.workAreaId ]} );
- showToast( "Task Assigned Successfully.", "success" );
+ onSuccess: (_, variables) => {
+ queryClient.invalidateQueries({ queryKey: ["taskList"] });
+ queryClient.invalidateQueries({
+ queryKey: ["WorkItems", variables?.workAreaId],
+ });
+ showToast("Task Assigned Successfully.", "success");
if (onSuccessCallback) onSuccessCallback(variables);
},
- onError: ( error ) =>
- {
+ onError: (error) => {
showToast("Something went wrong. Please try again.", "error");
if (onErrorCallback) onErrorCallback(error);
},
});
-};
\ No newline at end of file
+};
diff --git a/src/pages/Activities/DailyTask.jsx b/src/pages/Activities/DailyTask.jsx
index dba18d18..fb121a89 100644
--- a/src/pages/Activities/DailyTask.jsx
+++ b/src/pages/Activities/DailyTask.jsx
@@ -14,6 +14,8 @@ import GlobalModel from "../../components/common/GlobalModel";
import AssignTask from "../../components/Project/AssignTask";
import SubTask from "../../components/Activities/SubTask";
import {formatNumber} from "../../utils/dateUtils";
+import { useHasUserPermission } from "../../hooks/useHasUserPermission";
+import { APPROVE_TASK, ASSIGN_REPORT_TASK } from "../../utils/constants";
const DailyTask = () => {
const [searchParams] = useSearchParams();
@@ -32,6 +34,8 @@ const DailyTask = () => {
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
+ const ApprovedTaskRights = useHasUserPermission(APPROVE_TASK)
+ const ReportTaskRights = useHasUserPermission(ASSIGN_REPORT_TASK)
const {
TaskList,
@@ -386,6 +390,7 @@ const DailyTask = () => {
+ { ReportTaskRights &&
- {task.reportedDate && (
+ }
+ {(ApprovedTaskRights && task.reportedDate ) && (
|