updated some queries and mutation for prevent to duplicates calls
This commit is contained in:
parent
52c5e3d2d2
commit
80083aa5db
@ -47,7 +47,7 @@ const InfraPlanning = () =>
|
||||
<div className="align-items-center">
|
||||
<div className="row ">
|
||||
{isLoading && ( <p>Loading...</p> )}
|
||||
{( !isLoading && projectInfra.length === 0 ) && ( <p>No Result Found</p> )}
|
||||
{( !isLoading && projectInfra?.length === 0 ) && ( <p>No Result Found</p> )}
|
||||
{(!isLoading && projectInfra?.length > 0) && (<InfraTable buildings={projectInfra} projectId={selectedProject}/>)}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -22,7 +22,7 @@ const mobileNumberRegex = /^[0-9]\d{9}$/;
|
||||
|
||||
const ManageEmployee = ({ employeeId, onClosed,IsAllEmployee }) => {
|
||||
const dispatch = useDispatch();
|
||||
const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
||||
const { mutate: updateEmployee, isPending } = useUpdateEmployee();
|
||||
|
||||
const {
|
||||
employee,
|
||||
@ -163,40 +163,6 @@ const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
||||
});
|
||||
|
||||
const AadharNumberValue = watch("aadharNumber") || "";
|
||||
|
||||
// const onSubmit = (data) => {
|
||||
// setLoading(true);
|
||||
// if (data.email == "") {
|
||||
// data.email = null;
|
||||
// }
|
||||
// EmployeeRepository.manageEmployee(data)
|
||||
// .then((response) => {
|
||||
// cacheData("employeeProfileInfo", data);
|
||||
// showToast(
|
||||
// `Employee details ${
|
||||
// data.id == null ? "created" : "updated"
|
||||
// } successfully.`,
|
||||
// "success"
|
||||
// );
|
||||
// clearCacheKey("employeeListByProject");
|
||||
// clearCacheKey("allEmployeeList");
|
||||
// clearCacheKey("allInactiveEmployeeList");
|
||||
// clearCacheKey("employeeProfile");
|
||||
|
||||
// setLoading(false);
|
||||
// reset();
|
||||
// // navigation("/employees");
|
||||
// onClosed();
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// const message =
|
||||
// error?.response?.data?.message ||
|
||||
// error?.message ||
|
||||
// "Error occured during api calling";
|
||||
// showToast(message, "error");
|
||||
// setLoading(false);
|
||||
// });
|
||||
// };
|
||||
|
||||
const onSubmit = (data) => {
|
||||
if (data.email === "") {
|
||||
@ -240,7 +206,7 @@ const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
||||
phoneNumber: currentEmployee.phoneNumber || "",
|
||||
jobRoleId: currentEmployee.jobRoleId?.toString() || "",
|
||||
}
|
||||
: {} // Empty object resets the form
|
||||
: {}
|
||||
);
|
||||
setCurrentAddressLength(currentEmployee?.currentAddress?.length || 0);
|
||||
setPermanentAddressLength(currentEmployee?.permanentAddress?.length || 0);
|
||||
@ -625,9 +591,9 @@ const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
||||
aria-label="manage employee"
|
||||
type="submit"
|
||||
className="btn btn-sm btn-primary"
|
||||
disabled={isloading}
|
||||
disabled={isPending}
|
||||
>
|
||||
{isloading
|
||||
{isPending
|
||||
? "Please Wait..."
|
||||
: employeeId
|
||||
? "Update"
|
||||
@ -638,7 +604,7 @@ const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
||||
aria-label="manage employee"
|
||||
type="reset"
|
||||
className="btn btn-sm btn-primary ms-2"
|
||||
disabled={isloading}
|
||||
disabled={isPending}
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
|
@ -22,7 +22,7 @@ import { MANAGE_PROJECT } from "../../utils/constants";
|
||||
const Header = () => {
|
||||
const {profile} = useProfile();
|
||||
const location = useLocation();
|
||||
const dispatch = useDispatch(changeMaster("Job Role"));
|
||||
const dispatch = useDispatch();
|
||||
const { data, loading } = useMaster();
|
||||
const navigate = useNavigate();
|
||||
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
|
||||
@ -145,7 +145,10 @@ const Header = () => {
|
||||
// return () => eventBus.off("project", newProjectHandler);
|
||||
// }, [handler]);
|
||||
|
||||
|
||||
useDispatch( () =>
|
||||
{
|
||||
dispatch(changeMaster("Job Role"))
|
||||
},[])
|
||||
useEffect(() => {
|
||||
eventBus.on("assign_project_one", handler);
|
||||
eventBus.on("project", newProjectHandler);
|
||||
|
@ -15,10 +15,8 @@ import { useCreateTask } from "../../hooks/useTasks";
|
||||
|
||||
const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
const maxPlanned =
|
||||
assignData?.workItem?.workItem?.plannedWork -
|
||||
assignData?.workItem?.workItem?.completedWork;
|
||||
|
||||
// Zod schema for form validation
|
||||
assignData?.workItem?.plannedWork -
|
||||
assignData?.workItem?.completedWork;
|
||||
const schema = z.object({
|
||||
selectedEmployees: z
|
||||
.array(z.string())
|
||||
@ -51,9 +49,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
const infoRef = useRef(null);
|
||||
const infoRef1 = useRef(null);
|
||||
|
||||
// Initialize Bootstrap Popovers on component mount
|
||||
useEffect(() => {
|
||||
// Check if Bootstrap is available globally
|
||||
if (typeof bootstrap !== "undefined") {
|
||||
if (infoRef.current) {
|
||||
new bootstrap.Popover(infoRef.current, {
|
||||
@ -75,8 +71,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
} else {
|
||||
console.warn("Bootstrap is not available. Popovers might not function.");
|
||||
}
|
||||
}, []); // Empty dependency array ensures this runs once on mount
|
||||
// Redux state and hooks
|
||||
}, []);
|
||||
const selectedProject = useSelector(
|
||||
(store) => store.localVariables.projectId
|
||||
);
|
||||
@ -86,14 +81,11 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
recallEmployeeData,
|
||||
} = useEmployeesAllOrByProjectId(selectedProject, false);
|
||||
const dispatch = useDispatch();
|
||||
const { loading } = useMaster(); // Assuming this is for jobRoleData loading
|
||||
const jobRoleData = getCachedData("Job Role");
|
||||
const { loading } = useMaster();
|
||||
const {data:jobRoleData} = useMaster();
|
||||
|
||||
// Local component states
|
||||
const [selectedRole, setSelectedRole] = useState("all");
|
||||
const [displayedSelection, setDisplayedSelection] = useState(""); // This state is not updated in the provided code, consider if it's still needed or how it should be updated
|
||||
|
||||
// React Hook Form setup
|
||||
const [displayedSelection, setDisplayedSelection] = useState("");
|
||||
const {
|
||||
handleSubmit,
|
||||
control,
|
||||
@ -101,50 +93,43 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
watch,
|
||||
formState: { errors },
|
||||
reset,
|
||||
trigger, // <--- IMPORTANT: Destructure 'trigger' here
|
||||
trigger,
|
||||
} = useForm({
|
||||
defaultValues: {
|
||||
selectedEmployees: [],
|
||||
description: "",
|
||||
plannedTask: "",
|
||||
},
|
||||
resolver: zodResolver(schema), // Integrate Zod schema with react-hook-form
|
||||
resolver: zodResolver(schema),
|
||||
});
|
||||
|
||||
// Handler for employee checkbox changes
|
||||
const handleCheckboxChange = (event, user) => {
|
||||
const isChecked = event.target.checked;
|
||||
let updatedSelectedEmployees = watch("selectedEmployees") || []; // Get current selected employees from form state
|
||||
let updatedSelectedEmployees = watch("selectedEmployees") || [];
|
||||
|
||||
if (isChecked) {
|
||||
// Add employee if checked and not already in the list
|
||||
if (!updatedSelectedEmployees.includes(user.id)) {
|
||||
updatedSelectedEmployees = [...updatedSelectedEmployees, user.id];
|
||||
}
|
||||
} else {
|
||||
// Remove employee if unchecked
|
||||
updatedSelectedEmployees = updatedSelectedEmployees.filter(
|
||||
updatedSelectedEmployees = updatedSelectedEmployees?.filter(
|
||||
(id) => id !== user.id
|
||||
);
|
||||
}
|
||||
// Update the form state with the new list of selected employees
|
||||
setValue("selectedEmployees", updatedSelectedEmployees);
|
||||
trigger("selectedEmployees"); // <--- IMPORTANT: Trigger validation here
|
||||
trigger("selectedEmployees");
|
||||
};
|
||||
|
||||
// Effect to dispatch action for Job Role master data
|
||||
useEffect(() => {
|
||||
dispatch(changeMaster("Job Role"));
|
||||
// Cleanup function to reset selected role when component unmounts or dispatch changes
|
||||
|
||||
return () => setSelectedRole("all");
|
||||
}, [dispatch]);
|
||||
|
||||
// Handler for role filter change
|
||||
const handleRoleChange = (event) => {
|
||||
setSelectedRole(event.target.value);
|
||||
};
|
||||
|
||||
// Filter employees based on selected role
|
||||
const filteredEmployees =
|
||||
selectedRole === "all"
|
||||
? employees
|
||||
@ -152,36 +137,6 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
(emp) => String(emp.jobRoleId || "") === selectedRole
|
||||
);
|
||||
|
||||
// Form submission handler
|
||||
// const onSubmit = async (data) => {
|
||||
// const selectedEmployeeIds = data.selectedEmployees;
|
||||
// setIsSubmitting(true);
|
||||
// // Prepare taskTeam data (only IDs are needed for the backend based on previous context)
|
||||
// const taskTeamWithDetails = selectedEmployeeIds
|
||||
// .map((empId) => {
|
||||
// return empId; // Return just the ID as per previous discussions
|
||||
// })
|
||||
// .filter(Boolean); // Ensure no nulls if employee not found (though unlikely with current logic)
|
||||
|
||||
// // Format data for API call
|
||||
// const formattedData = {
|
||||
// taskTeam: taskTeamWithDetails,
|
||||
// plannedTask: data.plannedTask,
|
||||
// description: data.description,
|
||||
// assignmentDate: new Date().toISOString(), // Current date/time
|
||||
// workItemId: assignData?.workItem?.workItem.id,
|
||||
// };
|
||||
|
||||
// try {
|
||||
// await TasksRepository.assignTask(formattedData);
|
||||
// setIsSubmitting( false );
|
||||
// showToast("Task Assined Successfully.", "success");
|
||||
// closedModel();
|
||||
// } catch (error) {
|
||||
// setIsSubmitting(false);
|
||||
// showToast("Something went wrong. Please try again.", "error");
|
||||
// }
|
||||
// };
|
||||
|
||||
const onSubmit = (data) => {
|
||||
const selectedEmployeeIds = data.selectedEmployees;
|
||||
@ -192,13 +147,12 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
plannedTask: data.plannedTask,
|
||||
description: data.description,
|
||||
assignmentDate: new Date().toISOString(),
|
||||
workItemId: assignData?.workItem?.workItem.id,
|
||||
workItemId: assignData?.workItem.id,
|
||||
};
|
||||
|
||||
assignTask(formattedData);
|
||||
};
|
||||
|
||||
// Handler to close the modal and reset form
|
||||
const closedModel = () => {
|
||||
reset();
|
||||
onClose();
|
||||
@ -212,10 +166,10 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
<span className="text-dark text-start d-flex align-items-center flex-wrap form-text">
|
||||
<span className="me-2 m-0 font-bold">Work Location :</span>
|
||||
{[
|
||||
assignData?.building?.name,
|
||||
assignData?.building?.buildingName,
|
||||
assignData?.floor?.floorName,
|
||||
assignData?.workArea?.areaName,
|
||||
assignData?.workItem?.workItem?.activityMaster?.activityName,
|
||||
assignData?.workItem?.activityMaster?.activityName,
|
||||
]
|
||||
.filter(Boolean) // Filter out any undefined/null values
|
||||
.map((item, index, array) => (
|
||||
@ -378,7 +332,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
"selectedEmployees",
|
||||
updatedSelected
|
||||
);
|
||||
trigger("selectedEmployees"); // <--- IMPORTANT: Trigger validation on removing badge
|
||||
trigger("selectedEmployees");
|
||||
}}
|
||||
>
|
||||
<i className="icon-base bx bx-x icon-md "></i>
|
||||
@ -395,11 +349,10 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
{!loading && errors.selectedEmployees && (
|
||||
<div className="danger-text mt-1">
|
||||
<p>{errors.selectedEmployees.message}</p>{" "}
|
||||
{/* Use message from Zod schema */}
|
||||
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Pending Task of Activity section */}
|
||||
<div className="col-md text-start mx-0 px-0">
|
||||
<div className="form-check form-check-inline mt-3 px-1">
|
||||
<label
|
||||
@ -412,12 +365,12 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
htmlFor="inlineCheckbox1"
|
||||
>
|
||||
<strong>
|
||||
{assignData?.workItem?.workItem?.plannedWork -
|
||||
assignData?.workItem?.workItem?.completedWork}
|
||||
{assignData?.workItem?.plannedWork -
|
||||
assignData?.workItem?.completedWork}
|
||||
</strong>{" "}
|
||||
<u>
|
||||
{
|
||||
assignData?.workItem?.workItem?.activityMaster
|
||||
assignData?.workItem?.activityMaster
|
||||
?.unitOfMeasurement
|
||||
}
|
||||
</u>
|
||||
|
@ -76,21 +76,24 @@ const { mutate: UpdateTask, isPending } = useManageTask({
|
||||
[categories]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
reset({
|
||||
activityID: String(
|
||||
workItem?.workItem?.activityId || workItem?.activityId || ""
|
||||
),
|
||||
workCategoryId: String(
|
||||
workItem?.workItem?.workCategoryId || workItem?.workCategoryId || ""
|
||||
),
|
||||
plannedWork:
|
||||
workItem?.workItem?.plannedWork || workItem?.plannedWork || 0,
|
||||
completedWork:
|
||||
workItem?.workItem?.completedWork || workItem?.completedWork || 0,
|
||||
comment: workItem?.workItem?.description || workItem?.description || "",
|
||||
});
|
||||
}, [workItem, activities]);
|
||||
useEffect(() => {
|
||||
if (!workItem) return;
|
||||
|
||||
reset({
|
||||
activityID: String(
|
||||
workItem?.workItem?.activityId || workItem?.activityId || ""
|
||||
),
|
||||
workCategoryId: String(
|
||||
workItem?.workItem?.workCategoryId || workItem?.workCategoryId || ""
|
||||
),
|
||||
plannedWork:
|
||||
workItem?.workItem?.plannedWork || workItem?.plannedWork || 0,
|
||||
completedWork:
|
||||
workItem?.workItem?.completedWork || workItem?.completedWork || 0,
|
||||
comment: workItem?.workItem?.description || workItem?.description || "",
|
||||
});
|
||||
}, [workItem?.id]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const selected = activities?.find((a) => a.id === activityID);
|
||||
|
@ -49,46 +49,6 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
|
||||
setWorkAreaStatus({ completed: totalCompleted, planned: totalPlanned });
|
||||
}, [ProjectTaskList]);
|
||||
|
||||
const HanldeDeleteActivity = async (workItemId) => {
|
||||
try {
|
||||
const updatedProject = { ...Project.data };
|
||||
await ProjectRepository.deleteProjectTask(workItemId);
|
||||
|
||||
const newProject = {
|
||||
...updatedProject,
|
||||
buildings: updatedProject?.buildings.map((building) => ({
|
||||
...building,
|
||||
floors: building?.floors.map((floor) => ({
|
||||
...floor,
|
||||
workAreas: floor.workAreas.map((wa) =>
|
||||
wa.id === workArea.id
|
||||
? {
|
||||
...wa,
|
||||
workItems: wa.workItems.filter(
|
||||
(item) =>
|
||||
String(item?.workItem?.id ?? item?.id) !==
|
||||
String(workItemId)
|
||||
),
|
||||
}
|
||||
: wa
|
||||
),
|
||||
})),
|
||||
})),
|
||||
};
|
||||
|
||||
cacheData("projectInfo", {
|
||||
projectId: newProject.id,
|
||||
data: newProject,
|
||||
});
|
||||
|
||||
dispatch(refreshData(true));
|
||||
showToast("Activity Deleted Successfully", "success");
|
||||
} catch (error) {
|
||||
const message =
|
||||
error.response?.data?.message || error.message || "An error occurred";
|
||||
showToast(message, "error");
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const collapseElement = document.getElementById(`collapse-${workArea.id}`);
|
||||
@ -190,14 +150,13 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="table-border-bottom-0">
|
||||
{ProjectTaskList.map((workItem) => (
|
||||
{ProjectTaskList.map((workItem,index) => (
|
||||
<WorkItem
|
||||
key={workItem.workItemId}
|
||||
key={workItem.workItemId || `fallback-${index}`}
|
||||
workItem={workItem}
|
||||
forBuilding={forBuilding}
|
||||
forFloor={floor}
|
||||
forWorkArea={workArea}
|
||||
deleteHandleTask={HanldeDeleteActivity}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
|
@ -10,16 +10,16 @@ import {
|
||||
} from "../../../utils/constants";
|
||||
import ConfirmModal from "../../common/ConfirmModal";
|
||||
import ProjectRepository from "../../../repositories/ProjectRepository";
|
||||
import { useProjectDetails } from "../../../hooks/useProjects";
|
||||
import { useDeleteProjectTask, useProjectDetails } from "../../../hooks/useProjects";
|
||||
import showToast from "../../../services/toastService";
|
||||
import {
|
||||
cacheData,
|
||||
clearCacheKey,
|
||||
getCachedData,
|
||||
} from "../../../slices/apiDataManager";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { refreshData } from "../../../slices/localVariablesSlice";
|
||||
import GlobalModel from "../../common/GlobalModel";
|
||||
import {useDeleteMasterItem} from "../../../hooks/masterHook/useMaster";
|
||||
|
||||
const WorkItem = ({
|
||||
workItem,
|
||||
@ -39,18 +39,24 @@ const WorkItem = ({
|
||||
const ManageAndAssignTak = useHasUserPermission(ASSIGN_REPORT_TASK);
|
||||
const [loadingDelete, setLoadingDelete] = useState(false);
|
||||
const project = getCachedData("projectInfo");
|
||||
const dispatch = useDispatch();
|
||||
|
||||
|
||||
const openModal = () => setIsModalOpen(true);
|
||||
const closeModal = () => setIsModalOpen(false);
|
||||
const closeModal = () => setIsModalOpen( false );
|
||||
|
||||
const showModalDelete = () => setShowModal2(true);
|
||||
const closeModalDelete = () => setShowModal2(false);
|
||||
const getProgress = (planned, completed) => {
|
||||
return (completed * 100) / planned + "%";
|
||||
};
|
||||
|
||||
const {mutate:DeleteTask,isPending } = useDeleteProjectTask(() => {
|
||||
closeModalDelete?.();
|
||||
});
|
||||
|
||||
const handleAssignTask = () => {
|
||||
setItemName("");
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setNewWorkItem(workItem);
|
||||
}, [workItem]);
|
||||
@ -80,15 +86,14 @@ const WorkItem = ({
|
||||
}, []);
|
||||
|
||||
|
||||
const showModalDelete = () => setShowModal2(true);
|
||||
const closeModalDelete = () => setShowModal2(false);
|
||||
|
||||
|
||||
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setLoadingDelete(true);
|
||||
let WorkItemId = workItem.workItemId || workItem.id;
|
||||
deleteHandleTask(WorkItemId);
|
||||
setLoadingDelete(false);
|
||||
closeModalDelete();
|
||||
DeleteTask({workItemId:WorkItemId,workAreaId:forWorkArea?.id})
|
||||
|
||||
};
|
||||
|
||||
const PlannedWork =
|
||||
@ -197,7 +202,6 @@ const WorkItem = ({
|
||||
: "NA"}
|
||||
</td>
|
||||
|
||||
{/* Progress Bar - always visible */}
|
||||
<td className="text-center " style={{ width: "15%" }}>
|
||||
<div className="progress p-0">
|
||||
<div
|
||||
@ -224,7 +228,6 @@ const WorkItem = ({
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* Actions - always visible */}
|
||||
{(ManageInfra ||
|
||||
(!projectId &&
|
||||
ManageAndAssignTak &&
|
||||
|
@ -3,7 +3,6 @@ import { useForm, Controller } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
|
||||
// const currentDate = new Date().toISOString().split("T")[0];
|
||||
const currentDate = new Date().toLocaleDateString('en-CA');
|
||||
const formatDate = (date) => {
|
||||
if (!date) {
|
||||
@ -13,7 +12,6 @@ const formatDate = (date) => {
|
||||
if (isNaN(d.getTime())) {
|
||||
return currentDate;
|
||||
}
|
||||
// return d.toISOString().split("T")[0];
|
||||
return d.toLocaleDateString('en-CA');
|
||||
};
|
||||
const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => {
|
||||
@ -95,7 +93,7 @@ const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => {
|
||||
projectAddress: project?.projectAddress || "",
|
||||
startDate: formatDate(project?.startDate) || "",
|
||||
endDate: formatDate(project?.endDate) || "",
|
||||
projectStatusId: String(project.projectStatusId) || "00000000-0000-0000-0000-000000000000",
|
||||
projectStatusId: String(project?.projectStatus?.id) || "00000000-0000-0000-0000-000000000000",
|
||||
}
|
||||
: {}
|
||||
);
|
||||
@ -116,7 +114,7 @@ const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => {
|
||||
projectAddress: project?.projectAddress || "",
|
||||
startDate: formatDate(project?.startDate) || currentDate,
|
||||
endDate: formatDate(project?.endDate) || currentDate,
|
||||
projectStatusId: String(project?.projectStatusId || "00000000-0000-0000-0000-000000000000"),
|
||||
projectStatusId: String(project?.projectStatus?.id || "00000000-0000-0000-0000-000000000000"),
|
||||
});
|
||||
onClose();
|
||||
};
|
||||
|
@ -69,45 +69,6 @@ const ProjectCard = ({ projectData, recall }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// const handleFormSubmit = (updatedProject) => {
|
||||
// if (projectInfo?.id) {
|
||||
// ProjectRepository.updateProject(projectInfo.id, updatedProject)
|
||||
// .then((response) => {
|
||||
// const updatedProjectData = {
|
||||
// ...projectInfo,
|
||||
// ...response.data,
|
||||
// building: projectDetails?.building,
|
||||
// };
|
||||
|
||||
// setProjectInfo(updatedProject);
|
||||
|
||||
// if (getCachedData(`projectinfo-${projectInfo.id}`)) {
|
||||
// cacheData(`projectinfo-${projectInfo.id}`, updatedProjectData);
|
||||
// }
|
||||
|
||||
// const projects_list = getCachedData("projectslist");
|
||||
// if (projects_list) {
|
||||
// const updatedProjectsList = projects_list.map((project) =>
|
||||
// project.id === projectInfo.id
|
||||
// ? {
|
||||
// ...project,
|
||||
// ...response.data,
|
||||
// // tenant: project.tenant
|
||||
// }
|
||||
// : project
|
||||
// );
|
||||
// cacheData("projectslist", updatedProjectsList);
|
||||
// }
|
||||
// recall(getCachedData("projectslist"));
|
||||
// showToast("Project updated successfully.", "success");
|
||||
// setShowModal(false);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// showToast(error.message, "error");
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {useState,useEffect} from "react"
|
||||
import {useState,useEffect, useCallback} from "react"
|
||||
import { MasterRespository } from "../../repositories/MastersRepository";
|
||||
import { cacheData,getCachedData } from "../../slices/apiDataManager";
|
||||
import { useSelector } from "react-redux";
|
||||
@ -344,14 +344,14 @@ const fetchMasterData = async (masterType) => {
|
||||
|
||||
const useMaster = () => {
|
||||
const selectedMaster = useSelector((store) => store.localVariables.selectedMaster);
|
||||
|
||||
const queryFn = useCallback(() => fetchMasterData(selectedMaster), [selectedMaster]);
|
||||
const {
|
||||
data = [],
|
||||
isLoading,
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ["masterData", selectedMaster],
|
||||
queryFn: () => fetchMasterData(selectedMaster),
|
||||
queryFn,
|
||||
enabled: !!selectedMaster,
|
||||
staleTime: 1000 * 60 * 10,
|
||||
refetchOnWindowFocus: false,
|
||||
|
@ -10,260 +10,11 @@ import {store} from "../store/store";
|
||||
import {queryClient} from "../layouts/AuthLayout";
|
||||
|
||||
|
||||
// export const useAllEmployees = (showInactive) => {
|
||||
// const [employeesList, setEmployeeList] = useState([]);
|
||||
// const [loading, setLoading] = useState(false);
|
||||
// const [error, setError] = useState();
|
||||
|
||||
// const fetchData = async () => {
|
||||
// try {
|
||||
// let EmployeeList_cached = getCachedData("AllEmployees");
|
||||
// if (!EmployeeList_cached) {
|
||||
// setLoading(true);
|
||||
// const response = await EmployeeRepository.getAllEmployeeList(showInactive);
|
||||
// cacheData("AllEmployees", response.data);
|
||||
// setEmployeeList(response.data);
|
||||
// setLoading(false);
|
||||
// } else {
|
||||
// setEmployeeList(EmployeeList_cached);
|
||||
// setLoading(false);
|
||||
// }
|
||||
// } catch (error) {
|
||||
// setError("Failed to fetch data.");
|
||||
// setLoading(false);
|
||||
// }
|
||||
// };
|
||||
|
||||
// useEffect(() => {
|
||||
// fetchData();
|
||||
// }, []);
|
||||
// return { employeesList, loading, error };
|
||||
// };
|
||||
|
||||
|
||||
|
||||
// export const useEmployees = (selectedProject) => {
|
||||
// const [employees, setEmployeeList] = useState([]);
|
||||
// const [loading, setLoading] = useState(true);
|
||||
// const [projects, setProjects] = useState([]);
|
||||
|
||||
// const fetchData = async (projectid) => {
|
||||
// try {
|
||||
// let EmployeeByProject_Cache = getCachedData("employeeListByProject");
|
||||
// if (
|
||||
// !EmployeeByProject_Cache ||
|
||||
// !EmployeeByProject_Cache.projectId === projectid
|
||||
// ) {
|
||||
// EmployeeRepository.getEmployeeListByproject(projectid)
|
||||
// .then((response) => {
|
||||
// setEmployeeList(response);
|
||||
// cacheData("employeeListByProject", {
|
||||
// data: response,
|
||||
// projectId: projectid,
|
||||
// });
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// setError("Failed to fetch data.");
|
||||
// });
|
||||
// } else {
|
||||
// setEmployeeList(EmployeeByProject_Cache.data);
|
||||
// }
|
||||
// setLoading(false);
|
||||
// } catch (err) {
|
||||
// setError("Failed to fetch data.");
|
||||
// setLoading(false);
|
||||
// }
|
||||
// };
|
||||
|
||||
// useEffect(() => {
|
||||
// if (selectedProject) {
|
||||
// fetchData(selectedProject);
|
||||
// }
|
||||
// }, [selectedProject]);
|
||||
|
||||
// return { employees, loading, projects, reCallAllEmployee };
|
||||
// };
|
||||
|
||||
// export const useEmployeeRoles = (employeeId) => {
|
||||
// const [loading, setLoading] = useState(true);
|
||||
// const [error, setError] = useState();
|
||||
// const [employeeRoles, setEmployeeRoles] = useState([]);
|
||||
// const fetchData = async (employeeid) => {
|
||||
// try {
|
||||
// let response = await RolesRepository.getEmployeeRoles(employeeid);
|
||||
// setEmployeeRoles(response.data);
|
||||
// cacheData("employeelist", response.data);
|
||||
// } catch (err) {
|
||||
// setError("Failed to fetch data.");
|
||||
// setEmployeeRoles([]);
|
||||
// } finally {
|
||||
// setLoading(false);
|
||||
// }
|
||||
// };
|
||||
|
||||
// useEffect(() => {
|
||||
// if (employeeId) {
|
||||
// fetchData(employeeId);
|
||||
// }
|
||||
// }, [employeeId]);
|
||||
|
||||
// return { employeeRoles, loading, error };
|
||||
// };
|
||||
|
||||
// export const useEmployeesByProject = (projectId) => {
|
||||
// const [loading, setLoading] = useState(false);
|
||||
// const [error, setError] = useState();
|
||||
// const [employees, setEmployees] = useState([]);
|
||||
|
||||
// const fetchData = async () => {
|
||||
// const Employees_cache = getCachedData("employeeListByProject");
|
||||
// if (!Employees_cache || Employees_cache.projectId !== projectId) {
|
||||
// setEmployees(true);
|
||||
// ProjectRepository.getEmployeesByProject(projectId)
|
||||
// .then((response) => {
|
||||
// setEmployees(response.data);
|
||||
// cacheData("employeeListByProject", {
|
||||
// data: response.data,
|
||||
// projectId,
|
||||
// });
|
||||
// setLoading(false);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// setError("Failed to fetch data.");
|
||||
// setLoading(false);
|
||||
// });
|
||||
// } else {
|
||||
// setEmployees(Employees_cache.data);
|
||||
// setLoading(false);
|
||||
// }
|
||||
// };
|
||||
|
||||
// useEffect(() => {
|
||||
// fetchData(projectId);
|
||||
// }, [projectId]);
|
||||
|
||||
// return { employees, loading, error, recallProjectEmplloyee: fetchData };
|
||||
// };
|
||||
|
||||
|
||||
|
||||
// export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
||||
// const [employees, setEmployees] = useState([]);
|
||||
// const [loading, setLoading] = useState(false);
|
||||
// const [error, setError] = useState(null);
|
||||
|
||||
// const fetchData = async (showInactive) => {
|
||||
// if ( projectId )
|
||||
// {
|
||||
// const Employees_cache = getCachedData("employeeListByProject");
|
||||
// if (!Employees_cache || Employees_cache.projectId !== projectId) {
|
||||
// setLoading(true);
|
||||
// setError(null);
|
||||
// try {
|
||||
// const response = await ProjectRepository.getEmployeesByProject(
|
||||
// projectId
|
||||
// );
|
||||
// setEmployees(response.data);
|
||||
// cacheData("employeeListByProject", {
|
||||
// data: response.data,
|
||||
// projectId,
|
||||
// });
|
||||
// setLoading(false);
|
||||
// } catch (err) {
|
||||
// setError("Failed to fetch data.");
|
||||
// setLoading(false);
|
||||
// }
|
||||
// } else {
|
||||
// setEmployees(Employees_cache.data);
|
||||
// setLoading(false);
|
||||
// }
|
||||
// } else
|
||||
// {
|
||||
// const cacheKey = showInactive
|
||||
// ? "allInactiveEmployeeList"
|
||||
// : "allEmployeeList";
|
||||
|
||||
// try {
|
||||
// const response = await EmployeeRepository.getAllEmployeeList(
|
||||
// showInactive
|
||||
// );
|
||||
// setEmployees(response.data);
|
||||
// cacheData(cacheKey, { data: response.data });
|
||||
// setLoading(false);
|
||||
// } catch (err) {
|
||||
// setError("Failed to fetch data.");
|
||||
// setLoading(false);
|
||||
// }
|
||||
|
||||
// }
|
||||
// };
|
||||
|
||||
// useEffect(() => {
|
||||
// fetchData(showInactive); // Fetch data when the component mounts or projectId changes
|
||||
// }, [projectId]); // Re-fetch when projectId changes
|
||||
|
||||
// return {
|
||||
// employees,
|
||||
// loading,
|
||||
// error,
|
||||
// recallEmployeeData: fetchData,
|
||||
// };
|
||||
// };
|
||||
|
||||
|
||||
|
||||
|
||||
// export const useEmployeeProfile = (employeeId) => {
|
||||
// const [loading, setLoading] = useState(true);
|
||||
// const [error, setError] = useState();
|
||||
// const [employee, setEmployees] = useState(null);
|
||||
|
||||
// const fetchData = async () => {
|
||||
// if (!employeeId) {
|
||||
// // Reset the state if no employeeId (e.g., opening for 'add' mode)
|
||||
// setEmployees(null);
|
||||
// setLoading(false);
|
||||
// return;
|
||||
// }
|
||||
// const Employee_cache = getCachedData("employeeProfile");
|
||||
// if (!Employee_cache || Employee_cache.employeeId !== employeeId) {
|
||||
// EmployeeRepository.getEmployeeProfile(employeeId)
|
||||
// .then((response) => {
|
||||
// setEmployees(response.data);
|
||||
// cacheData("employeeProfile", { data: response.data, employeeId });
|
||||
// setLoading(false);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// setError("Failed to fetch data.");
|
||||
// setLoading(false);
|
||||
// });
|
||||
// } else {
|
||||
// setEmployees(Employee_cache.data);
|
||||
// setLoading(false);
|
||||
// }
|
||||
// };
|
||||
|
||||
// useEffect(() => {
|
||||
// fetchData();
|
||||
// }, [employeeId]);
|
||||
|
||||
// return { employee, loading, error };
|
||||
// };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Query ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export const useAllEmployees = ( showInactive ) =>
|
||||
{
|
||||
const {
|
||||
@ -413,12 +164,7 @@ export const useEmployeeProfile = ( employeeId ) =>
|
||||
const res = await EmployeeRepository.getEmployeeProfile(employeeId);
|
||||
return res.data;
|
||||
},
|
||||
enabled: isEnabled,
|
||||
// initialData: () => {
|
||||
// if (!queryClient) return null;
|
||||
// return queryClient.getQueryData(['employeeProfile', employeeId]) || null;
|
||||
// },
|
||||
|
||||
enabled: isEnabled,
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -393,7 +393,8 @@ export const useUpdateProject = ({ onSuccessCallback }) => {
|
||||
return await ProjectRepository.updateProject(projectId, updatedData);
|
||||
},
|
||||
|
||||
onSuccess: (data, variables) => {
|
||||
onSuccess: ( data, variables ) =>
|
||||
{
|
||||
const { projectId } = variables;
|
||||
|
||||
queryClient.invalidateQueries(["ProjectsList"]);
|
||||
@ -497,7 +498,7 @@ export const useManageTask = ({onSuccessCallback}) =>
|
||||
mutationFn: async ( payload ) => await ProjectRepository.manageProjectTasks( payload ),
|
||||
onSuccess: ( data, variables ) =>
|
||||
{
|
||||
debugger
|
||||
|
||||
if ( variables[ 0 ]?.id )
|
||||
{
|
||||
showToast( 'Activity Updated Successfully', 'success' );
|
||||
@ -518,3 +519,27 @@ export const useManageTask = ({onSuccessCallback}) =>
|
||||
})
|
||||
}
|
||||
|
||||
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([ "WorkItems",variables.workAreaId]);
|
||||
if (onSuccessCallback) onSuccessCallback();
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(
|
||||
error?.response?.data?.message || error.message || "Failed to delete task",
|
||||
"error"
|
||||
);
|
||||
if (onSuccessCallback) onSuccessCallback();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -239,11 +239,15 @@ export const useSubmitTaskComment = ({ actionAllow, onSuccessCallback }) => {
|
||||
return response.data;
|
||||
},
|
||||
|
||||
onSuccess: ( data ) =>
|
||||
onSuccess: ( data,variables ) =>
|
||||
{
|
||||
|
||||
const workAreaId = variables?.commentsData?.workItem?.workArea?.id;
|
||||
queryClient.invalidateQueries({ queryKey: ["taskList"] });
|
||||
if (actionAllow) {
|
||||
showToast("Review submitted successfully.", "success");
|
||||
showToast( "Review submitted successfully.", "success" );
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: [ "WorkItems", workAreaId ] });
|
||||
} else
|
||||
{
|
||||
showToast("Comment sent successfully.", "success");
|
||||
@ -270,7 +274,7 @@ export const useCreateTask = ( {onSuccessCallback, onErrorCallback} = {} ) =>
|
||||
},
|
||||
onSuccess: ( _, variables ) =>
|
||||
{
|
||||
queryClient.invalidateQueries({ queryKey: ["taskList"] });
|
||||
queryClient.invalidateQueries(["taskList"]);
|
||||
showToast("Task Assigned Successfully.", "success");
|
||||
if (onSuccessCallback) onSuccessCallback(variables);
|
||||
},
|
||||
|
@ -4,7 +4,6 @@ import ManageProjectInfo from "../../components/Project/ManageProjectInfo";
|
||||
import Breadcrumb from "../../components/common/Breadcrumb";
|
||||
import ProjectRepository from "../../repositories/ProjectRepository";
|
||||
import { useProjects, useCreateProject } from "../../hooks/useProjects";
|
||||
import { useDispatch } from "react-redux";
|
||||
import showToast from "../../services/toastService";
|
||||
// import {
|
||||
// getCachedData,
|
||||
@ -32,7 +31,6 @@ const ProjectList = () => {
|
||||
const [HasManageProject, setHasManageProject] = useState(
|
||||
HasManageProjectPermission
|
||||
);
|
||||
const dispatch = useDispatch();
|
||||
const { mutate: createProject } = useCreateProject({
|
||||
onSuccessCallback: () => {
|
||||
setShowModal(false);
|
||||
@ -82,24 +80,7 @@ const ProjectList = () => {
|
||||
}
|
||||
}, [loginUser, HasManageProjectPermission]);
|
||||
|
||||
// const handleSubmitForm = (newProject, setloading, reset) => {
|
||||
// ProjectRepository.manageProject(newProject)
|
||||
// .then((response) => {
|
||||
// const cachedProjects = getCachedData("projectslist") || [];
|
||||
// const updatedProjects = [...cachedProjects, response.data];
|
||||
// cacheData("projectslist", updatedProjects);
|
||||
// setProjectList((prev) => [...prev, response.data]);
|
||||
// setloading(false);
|
||||
// reset();
|
||||
// sortingProject(getCachedData("projectslist"));
|
||||
// showToast("Project Created successfully.", "success");
|
||||
// setShowModal(false);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// showToast(error.message, "error");
|
||||
// setShowModal(false);
|
||||
// });
|
||||
// };
|
||||
|
||||
|
||||
const handleSubmitForm = (newProject, setloading, reset) => {
|
||||
setloading(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user