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="align-items-center">
|
||||||
<div className="row ">
|
<div className="row ">
|
||||||
{isLoading && ( <p>Loading...</p> )}
|
{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}/>)}
|
{(!isLoading && projectInfra?.length > 0) && (<InfraTable buildings={projectInfra} projectId={selectedProject}/>)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,7 +22,7 @@ const mobileNumberRegex = /^[0-9]\d{9}$/;
|
|||||||
|
|
||||||
const ManageEmployee = ({ employeeId, onClosed,IsAllEmployee }) => {
|
const ManageEmployee = ({ employeeId, onClosed,IsAllEmployee }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
const { mutate: updateEmployee, isPending } = useUpdateEmployee();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
employee,
|
employee,
|
||||||
@ -164,40 +164,6 @@ const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
|||||||
|
|
||||||
const AadharNumberValue = watch("aadharNumber") || "";
|
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) => {
|
const onSubmit = (data) => {
|
||||||
if (data.email === "") {
|
if (data.email === "") {
|
||||||
data.email = null;
|
data.email = null;
|
||||||
@ -240,7 +206,7 @@ const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
|||||||
phoneNumber: currentEmployee.phoneNumber || "",
|
phoneNumber: currentEmployee.phoneNumber || "",
|
||||||
jobRoleId: currentEmployee.jobRoleId?.toString() || "",
|
jobRoleId: currentEmployee.jobRoleId?.toString() || "",
|
||||||
}
|
}
|
||||||
: {} // Empty object resets the form
|
: {}
|
||||||
);
|
);
|
||||||
setCurrentAddressLength(currentEmployee?.currentAddress?.length || 0);
|
setCurrentAddressLength(currentEmployee?.currentAddress?.length || 0);
|
||||||
setPermanentAddressLength(currentEmployee?.permanentAddress?.length || 0);
|
setPermanentAddressLength(currentEmployee?.permanentAddress?.length || 0);
|
||||||
@ -625,9 +591,9 @@ const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
|||||||
aria-label="manage employee"
|
aria-label="manage employee"
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-sm btn-primary"
|
className="btn btn-sm btn-primary"
|
||||||
disabled={isloading}
|
disabled={isPending}
|
||||||
>
|
>
|
||||||
{isloading
|
{isPending
|
||||||
? "Please Wait..."
|
? "Please Wait..."
|
||||||
: employeeId
|
: employeeId
|
||||||
? "Update"
|
? "Update"
|
||||||
@ -638,7 +604,7 @@ const { mutate: updateEmployee, isLoading } = useUpdateEmployee();
|
|||||||
aria-label="manage employee"
|
aria-label="manage employee"
|
||||||
type="reset"
|
type="reset"
|
||||||
className="btn btn-sm btn-primary ms-2"
|
className="btn btn-sm btn-primary ms-2"
|
||||||
disabled={isloading}
|
disabled={isPending}
|
||||||
>
|
>
|
||||||
Clear
|
Clear
|
||||||
</button>
|
</button>
|
||||||
|
@ -22,7 +22,7 @@ import { MANAGE_PROJECT } from "../../utils/constants";
|
|||||||
const Header = () => {
|
const Header = () => {
|
||||||
const {profile} = useProfile();
|
const {profile} = useProfile();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const dispatch = useDispatch(changeMaster("Job Role"));
|
const dispatch = useDispatch();
|
||||||
const { data, loading } = useMaster();
|
const { data, loading } = useMaster();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
|
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
|
||||||
@ -145,7 +145,10 @@ const Header = () => {
|
|||||||
// return () => eventBus.off("project", newProjectHandler);
|
// return () => eventBus.off("project", newProjectHandler);
|
||||||
// }, [handler]);
|
// }, [handler]);
|
||||||
|
|
||||||
|
useDispatch( () =>
|
||||||
|
{
|
||||||
|
dispatch(changeMaster("Job Role"))
|
||||||
|
},[])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
eventBus.on("assign_project_one", handler);
|
eventBus.on("assign_project_one", handler);
|
||||||
eventBus.on("project", newProjectHandler);
|
eventBus.on("project", newProjectHandler);
|
||||||
|
@ -15,10 +15,8 @@ import { useCreateTask } from "../../hooks/useTasks";
|
|||||||
|
|
||||||
const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||||
const maxPlanned =
|
const maxPlanned =
|
||||||
assignData?.workItem?.workItem?.plannedWork -
|
assignData?.workItem?.plannedWork -
|
||||||
assignData?.workItem?.workItem?.completedWork;
|
assignData?.workItem?.completedWork;
|
||||||
|
|
||||||
// Zod schema for form validation
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
selectedEmployees: z
|
selectedEmployees: z
|
||||||
.array(z.string())
|
.array(z.string())
|
||||||
@ -51,9 +49,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
const infoRef = useRef(null);
|
const infoRef = useRef(null);
|
||||||
const infoRef1 = useRef(null);
|
const infoRef1 = useRef(null);
|
||||||
|
|
||||||
// Initialize Bootstrap Popovers on component mount
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Check if Bootstrap is available globally
|
|
||||||
if (typeof bootstrap !== "undefined") {
|
if (typeof bootstrap !== "undefined") {
|
||||||
if (infoRef.current) {
|
if (infoRef.current) {
|
||||||
new bootstrap.Popover(infoRef.current, {
|
new bootstrap.Popover(infoRef.current, {
|
||||||
@ -75,8 +71,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
} else {
|
} else {
|
||||||
console.warn("Bootstrap is not available. Popovers might not function.");
|
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(
|
const selectedProject = useSelector(
|
||||||
(store) => store.localVariables.projectId
|
(store) => store.localVariables.projectId
|
||||||
);
|
);
|
||||||
@ -86,14 +81,11 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
recallEmployeeData,
|
recallEmployeeData,
|
||||||
} = useEmployeesAllOrByProjectId(selectedProject, false);
|
} = useEmployeesAllOrByProjectId(selectedProject, false);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { loading } = useMaster(); // Assuming this is for jobRoleData loading
|
const { loading } = useMaster();
|
||||||
const jobRoleData = getCachedData("Job Role");
|
const {data:jobRoleData} = useMaster();
|
||||||
|
|
||||||
// Local component states
|
|
||||||
const [selectedRole, setSelectedRole] = useState("all");
|
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
|
const [displayedSelection, setDisplayedSelection] = useState("");
|
||||||
|
|
||||||
// React Hook Form setup
|
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
control,
|
control,
|
||||||
@ -101,50 +93,43 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
watch,
|
watch,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
reset,
|
reset,
|
||||||
trigger, // <--- IMPORTANT: Destructure 'trigger' here
|
trigger,
|
||||||
} = useForm({
|
} = useForm({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
selectedEmployees: [],
|
selectedEmployees: [],
|
||||||
description: "",
|
description: "",
|
||||||
plannedTask: "",
|
plannedTask: "",
|
||||||
},
|
},
|
||||||
resolver: zodResolver(schema), // Integrate Zod schema with react-hook-form
|
resolver: zodResolver(schema),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handler for employee checkbox changes
|
|
||||||
const handleCheckboxChange = (event, user) => {
|
const handleCheckboxChange = (event, user) => {
|
||||||
const isChecked = event.target.checked;
|
const isChecked = event.target.checked;
|
||||||
let updatedSelectedEmployees = watch("selectedEmployees") || []; // Get current selected employees from form state
|
let updatedSelectedEmployees = watch("selectedEmployees") || [];
|
||||||
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
// Add employee if checked and not already in the list
|
|
||||||
if (!updatedSelectedEmployees.includes(user.id)) {
|
if (!updatedSelectedEmployees.includes(user.id)) {
|
||||||
updatedSelectedEmployees = [...updatedSelectedEmployees, user.id];
|
updatedSelectedEmployees = [...updatedSelectedEmployees, user.id];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Remove employee if unchecked
|
updatedSelectedEmployees = updatedSelectedEmployees?.filter(
|
||||||
updatedSelectedEmployees = updatedSelectedEmployees.filter(
|
|
||||||
(id) => id !== user.id
|
(id) => id !== user.id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Update the form state with the new list of selected employees
|
|
||||||
setValue("selectedEmployees", updatedSelectedEmployees);
|
setValue("selectedEmployees", updatedSelectedEmployees);
|
||||||
trigger("selectedEmployees"); // <--- IMPORTANT: Trigger validation here
|
trigger("selectedEmployees");
|
||||||
};
|
};
|
||||||
|
|
||||||
// Effect to dispatch action for Job Role master data
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(changeMaster("Job Role"));
|
dispatch(changeMaster("Job Role"));
|
||||||
// Cleanup function to reset selected role when component unmounts or dispatch changes
|
|
||||||
return () => setSelectedRole("all");
|
return () => setSelectedRole("all");
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
// Handler for role filter change
|
|
||||||
const handleRoleChange = (event) => {
|
const handleRoleChange = (event) => {
|
||||||
setSelectedRole(event.target.value);
|
setSelectedRole(event.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Filter employees based on selected role
|
|
||||||
const filteredEmployees =
|
const filteredEmployees =
|
||||||
selectedRole === "all"
|
selectedRole === "all"
|
||||||
? employees
|
? employees
|
||||||
@ -152,36 +137,6 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
(emp) => String(emp.jobRoleId || "") === selectedRole
|
(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 onSubmit = (data) => {
|
||||||
const selectedEmployeeIds = data.selectedEmployees;
|
const selectedEmployeeIds = data.selectedEmployees;
|
||||||
@ -192,13 +147,12 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
plannedTask: data.plannedTask,
|
plannedTask: data.plannedTask,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
assignmentDate: new Date().toISOString(),
|
assignmentDate: new Date().toISOString(),
|
||||||
workItemId: assignData?.workItem?.workItem.id,
|
workItemId: assignData?.workItem.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
assignTask(formattedData);
|
assignTask(formattedData);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handler to close the modal and reset form
|
|
||||||
const closedModel = () => {
|
const closedModel = () => {
|
||||||
reset();
|
reset();
|
||||||
onClose();
|
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="text-dark text-start d-flex align-items-center flex-wrap form-text">
|
||||||
<span className="me-2 m-0 font-bold">Work Location :</span>
|
<span className="me-2 m-0 font-bold">Work Location :</span>
|
||||||
{[
|
{[
|
||||||
assignData?.building?.name,
|
assignData?.building?.buildingName,
|
||||||
assignData?.floor?.floorName,
|
assignData?.floor?.floorName,
|
||||||
assignData?.workArea?.areaName,
|
assignData?.workArea?.areaName,
|
||||||
assignData?.workItem?.workItem?.activityMaster?.activityName,
|
assignData?.workItem?.activityMaster?.activityName,
|
||||||
]
|
]
|
||||||
.filter(Boolean) // Filter out any undefined/null values
|
.filter(Boolean) // Filter out any undefined/null values
|
||||||
.map((item, index, array) => (
|
.map((item, index, array) => (
|
||||||
@ -378,7 +332,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
"selectedEmployees",
|
"selectedEmployees",
|
||||||
updatedSelected
|
updatedSelected
|
||||||
);
|
);
|
||||||
trigger("selectedEmployees"); // <--- IMPORTANT: Trigger validation on removing badge
|
trigger("selectedEmployees");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<i className="icon-base bx bx-x icon-md "></i>
|
<i className="icon-base bx bx-x icon-md "></i>
|
||||||
@ -395,11 +349,10 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
{!loading && errors.selectedEmployees && (
|
{!loading && errors.selectedEmployees && (
|
||||||
<div className="danger-text mt-1">
|
<div className="danger-text mt-1">
|
||||||
<p>{errors.selectedEmployees.message}</p>{" "}
|
<p>{errors.selectedEmployees.message}</p>{" "}
|
||||||
{/* Use message from Zod schema */}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Pending Task of Activity section */}
|
|
||||||
<div className="col-md text-start mx-0 px-0">
|
<div className="col-md text-start mx-0 px-0">
|
||||||
<div className="form-check form-check-inline mt-3 px-1">
|
<div className="form-check form-check-inline mt-3 px-1">
|
||||||
<label
|
<label
|
||||||
@ -412,12 +365,12 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
htmlFor="inlineCheckbox1"
|
htmlFor="inlineCheckbox1"
|
||||||
>
|
>
|
||||||
<strong>
|
<strong>
|
||||||
{assignData?.workItem?.workItem?.plannedWork -
|
{assignData?.workItem?.plannedWork -
|
||||||
assignData?.workItem?.workItem?.completedWork}
|
assignData?.workItem?.completedWork}
|
||||||
</strong>{" "}
|
</strong>{" "}
|
||||||
<u>
|
<u>
|
||||||
{
|
{
|
||||||
assignData?.workItem?.workItem?.activityMaster
|
assignData?.workItem?.activityMaster
|
||||||
?.unitOfMeasurement
|
?.unitOfMeasurement
|
||||||
}
|
}
|
||||||
</u>
|
</u>
|
||||||
|
@ -77,6 +77,8 @@ const { mutate: UpdateTask, isPending } = useManageTask({
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!workItem) return;
|
||||||
|
|
||||||
reset({
|
reset({
|
||||||
activityID: String(
|
activityID: String(
|
||||||
workItem?.workItem?.activityId || workItem?.activityId || ""
|
workItem?.workItem?.activityId || workItem?.activityId || ""
|
||||||
@ -90,7 +92,8 @@ const { mutate: UpdateTask, isPending } = useManageTask({
|
|||||||
workItem?.workItem?.completedWork || workItem?.completedWork || 0,
|
workItem?.workItem?.completedWork || workItem?.completedWork || 0,
|
||||||
comment: workItem?.workItem?.description || workItem?.description || "",
|
comment: workItem?.workItem?.description || workItem?.description || "",
|
||||||
});
|
});
|
||||||
}, [workItem, activities]);
|
}, [workItem?.id]);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const selected = activities?.find((a) => a.id === activityID);
|
const selected = activities?.find((a) => a.id === activityID);
|
||||||
|
@ -49,46 +49,6 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
|
|||||||
setWorkAreaStatus({ completed: totalCompleted, planned: totalPlanned });
|
setWorkAreaStatus({ completed: totalCompleted, planned: totalPlanned });
|
||||||
}, [ProjectTaskList]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
const collapseElement = document.getElementById(`collapse-${workArea.id}`);
|
const collapseElement = document.getElementById(`collapse-${workArea.id}`);
|
||||||
@ -190,14 +150,13 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="table-border-bottom-0">
|
<tbody className="table-border-bottom-0">
|
||||||
{ProjectTaskList.map((workItem) => (
|
{ProjectTaskList.map((workItem,index) => (
|
||||||
<WorkItem
|
<WorkItem
|
||||||
key={workItem.workItemId}
|
key={workItem.workItemId || `fallback-${index}`}
|
||||||
workItem={workItem}
|
workItem={workItem}
|
||||||
forBuilding={forBuilding}
|
forBuilding={forBuilding}
|
||||||
forFloor={floor}
|
forFloor={floor}
|
||||||
forWorkArea={workArea}
|
forWorkArea={workArea}
|
||||||
deleteHandleTask={HanldeDeleteActivity}
|
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -10,16 +10,16 @@ import {
|
|||||||
} from "../../../utils/constants";
|
} from "../../../utils/constants";
|
||||||
import ConfirmModal from "../../common/ConfirmModal";
|
import ConfirmModal from "../../common/ConfirmModal";
|
||||||
import ProjectRepository from "../../../repositories/ProjectRepository";
|
import ProjectRepository from "../../../repositories/ProjectRepository";
|
||||||
import { useProjectDetails } from "../../../hooks/useProjects";
|
import { useDeleteProjectTask, useProjectDetails } from "../../../hooks/useProjects";
|
||||||
import showToast from "../../../services/toastService";
|
import showToast from "../../../services/toastService";
|
||||||
import {
|
import {
|
||||||
cacheData,
|
cacheData,
|
||||||
clearCacheKey,
|
clearCacheKey,
|
||||||
getCachedData,
|
getCachedData,
|
||||||
} from "../../../slices/apiDataManager";
|
} from "../../../slices/apiDataManager";
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
import { refreshData } from "../../../slices/localVariablesSlice";
|
import { refreshData } from "../../../slices/localVariablesSlice";
|
||||||
import GlobalModel from "../../common/GlobalModel";
|
import GlobalModel from "../../common/GlobalModel";
|
||||||
|
import {useDeleteMasterItem} from "../../../hooks/masterHook/useMaster";
|
||||||
|
|
||||||
const WorkItem = ({
|
const WorkItem = ({
|
||||||
workItem,
|
workItem,
|
||||||
@ -39,18 +39,24 @@ const WorkItem = ({
|
|||||||
const ManageAndAssignTak = useHasUserPermission(ASSIGN_REPORT_TASK);
|
const ManageAndAssignTak = useHasUserPermission(ASSIGN_REPORT_TASK);
|
||||||
const [loadingDelete, setLoadingDelete] = useState(false);
|
const [loadingDelete, setLoadingDelete] = useState(false);
|
||||||
const project = getCachedData("projectInfo");
|
const project = getCachedData("projectInfo");
|
||||||
const dispatch = useDispatch();
|
|
||||||
|
|
||||||
const openModal = () => setIsModalOpen(true);
|
const openModal = () => setIsModalOpen(true);
|
||||||
const closeModal = () => setIsModalOpen( false );
|
const closeModal = () => setIsModalOpen( false );
|
||||||
|
|
||||||
|
const showModalDelete = () => setShowModal2(true);
|
||||||
|
const closeModalDelete = () => setShowModal2(false);
|
||||||
const getProgress = (planned, completed) => {
|
const getProgress = (planned, completed) => {
|
||||||
return (completed * 100) / planned + "%";
|
return (completed * 100) / planned + "%";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const {mutate:DeleteTask,isPending } = useDeleteProjectTask(() => {
|
||||||
|
closeModalDelete?.();
|
||||||
|
});
|
||||||
|
|
||||||
const handleAssignTask = () => {
|
const handleAssignTask = () => {
|
||||||
setItemName("");
|
setItemName("");
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setNewWorkItem(workItem);
|
setNewWorkItem(workItem);
|
||||||
}, [workItem]);
|
}, [workItem]);
|
||||||
@ -80,15 +86,14 @@ const WorkItem = ({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
const showModalDelete = () => setShowModal2(true);
|
|
||||||
const closeModalDelete = () => setShowModal2(false);
|
|
||||||
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
setLoadingDelete(true);
|
|
||||||
let WorkItemId = workItem.workItemId || workItem.id;
|
let WorkItemId = workItem.workItemId || workItem.id;
|
||||||
deleteHandleTask(WorkItemId);
|
DeleteTask({workItemId:WorkItemId,workAreaId:forWorkArea?.id})
|
||||||
setLoadingDelete(false);
|
|
||||||
closeModalDelete();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const PlannedWork =
|
const PlannedWork =
|
||||||
@ -197,7 +202,6 @@ const WorkItem = ({
|
|||||||
: "NA"}
|
: "NA"}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
{/* Progress Bar - always visible */}
|
|
||||||
<td className="text-center " style={{ width: "15%" }}>
|
<td className="text-center " style={{ width: "15%" }}>
|
||||||
<div className="progress p-0">
|
<div className="progress p-0">
|
||||||
<div
|
<div
|
||||||
@ -224,7 +228,6 @@ const WorkItem = ({
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
{/* Actions - always visible */}
|
|
||||||
{(ManageInfra ||
|
{(ManageInfra ||
|
||||||
(!projectId &&
|
(!projectId &&
|
||||||
ManageAndAssignTak &&
|
ManageAndAssignTak &&
|
||||||
|
@ -3,7 +3,6 @@ import { useForm, Controller } from "react-hook-form";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
// const currentDate = new Date().toISOString().split("T")[0];
|
|
||||||
const currentDate = new Date().toLocaleDateString('en-CA');
|
const currentDate = new Date().toLocaleDateString('en-CA');
|
||||||
const formatDate = (date) => {
|
const formatDate = (date) => {
|
||||||
if (!date) {
|
if (!date) {
|
||||||
@ -13,7 +12,6 @@ const formatDate = (date) => {
|
|||||||
if (isNaN(d.getTime())) {
|
if (isNaN(d.getTime())) {
|
||||||
return currentDate;
|
return currentDate;
|
||||||
}
|
}
|
||||||
// return d.toISOString().split("T")[0];
|
|
||||||
return d.toLocaleDateString('en-CA');
|
return d.toLocaleDateString('en-CA');
|
||||||
};
|
};
|
||||||
const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => {
|
const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => {
|
||||||
@ -95,7 +93,7 @@ const ManageProjectInfo = ({ project, handleSubmitForm, onClose }) => {
|
|||||||
projectAddress: project?.projectAddress || "",
|
projectAddress: project?.projectAddress || "",
|
||||||
startDate: formatDate(project?.startDate) || "",
|
startDate: formatDate(project?.startDate) || "",
|
||||||
endDate: formatDate(project?.endDate) || "",
|
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 || "",
|
projectAddress: project?.projectAddress || "",
|
||||||
startDate: formatDate(project?.startDate) || currentDate,
|
startDate: formatDate(project?.startDate) || currentDate,
|
||||||
endDate: formatDate(project?.endDate) || 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();
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {useState,useEffect} from "react"
|
import {useState,useEffect, useCallback} from "react"
|
||||||
import { MasterRespository } from "../../repositories/MastersRepository";
|
import { MasterRespository } from "../../repositories/MastersRepository";
|
||||||
import { cacheData,getCachedData } from "../../slices/apiDataManager";
|
import { cacheData,getCachedData } from "../../slices/apiDataManager";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
@ -344,14 +344,14 @@ const fetchMasterData = async (masterType) => {
|
|||||||
|
|
||||||
const useMaster = () => {
|
const useMaster = () => {
|
||||||
const selectedMaster = useSelector((store) => store.localVariables.selectedMaster);
|
const selectedMaster = useSelector((store) => store.localVariables.selectedMaster);
|
||||||
|
const queryFn = useCallback(() => fetchMasterData(selectedMaster), [selectedMaster]);
|
||||||
const {
|
const {
|
||||||
data = [],
|
data = [],
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["masterData", selectedMaster],
|
queryKey: ["masterData", selectedMaster],
|
||||||
queryFn: () => fetchMasterData(selectedMaster),
|
queryFn,
|
||||||
enabled: !!selectedMaster,
|
enabled: !!selectedMaster,
|
||||||
staleTime: 1000 * 60 * 10,
|
staleTime: 1000 * 60 * 10,
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
|
@ -10,260 +10,11 @@ import {store} from "../store/store";
|
|||||||
import {queryClient} from "../layouts/AuthLayout";
|
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 ---------------------------------------------------------------------------
|
// Query ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const useAllEmployees = ( showInactive ) =>
|
export const useAllEmployees = ( showInactive ) =>
|
||||||
{
|
{
|
||||||
const {
|
const {
|
||||||
@ -414,11 +165,6 @@ export const useEmployeeProfile = ( employeeId ) =>
|
|||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
enabled: isEnabled,
|
enabled: isEnabled,
|
||||||
// initialData: () => {
|
|
||||||
// if (!queryClient) return null;
|
|
||||||
// return queryClient.getQueryData(['employeeProfile', employeeId]) || null;
|
|
||||||
// },
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -393,7 +393,8 @@ export const useUpdateProject = ({ onSuccessCallback }) => {
|
|||||||
return await ProjectRepository.updateProject(projectId, updatedData);
|
return await ProjectRepository.updateProject(projectId, updatedData);
|
||||||
},
|
},
|
||||||
|
|
||||||
onSuccess: (data, variables) => {
|
onSuccess: ( data, variables ) =>
|
||||||
|
{
|
||||||
const { projectId } = variables;
|
const { projectId } = variables;
|
||||||
|
|
||||||
queryClient.invalidateQueries(["ProjectsList"]);
|
queryClient.invalidateQueries(["ProjectsList"]);
|
||||||
@ -497,7 +498,7 @@ export const useManageTask = ({onSuccessCallback}) =>
|
|||||||
mutationFn: async ( payload ) => await ProjectRepository.manageProjectTasks( payload ),
|
mutationFn: async ( payload ) => await ProjectRepository.manageProjectTasks( payload ),
|
||||||
onSuccess: ( data, variables ) =>
|
onSuccess: ( data, variables ) =>
|
||||||
{
|
{
|
||||||
debugger
|
|
||||||
if ( variables[ 0 ]?.id )
|
if ( variables[ 0 ]?.id )
|
||||||
{
|
{
|
||||||
showToast( 'Activity Updated Successfully', 'success' );
|
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;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
onSuccess: ( data ) =>
|
onSuccess: ( data,variables ) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const workAreaId = variables?.commentsData?.workItem?.workArea?.id;
|
||||||
queryClient.invalidateQueries({ queryKey: ["taskList"] });
|
queryClient.invalidateQueries({ queryKey: ["taskList"] });
|
||||||
if (actionAllow) {
|
if (actionAllow) {
|
||||||
showToast( "Review submitted successfully.", "success" );
|
showToast( "Review submitted successfully.", "success" );
|
||||||
|
|
||||||
|
queryClient.invalidateQueries({ queryKey: [ "WorkItems", workAreaId ] });
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
showToast("Comment sent successfully.", "success");
|
showToast("Comment sent successfully.", "success");
|
||||||
@ -270,7 +274,7 @@ export const useCreateTask = ( {onSuccessCallback, onErrorCallback} = {} ) =>
|
|||||||
},
|
},
|
||||||
onSuccess: ( _, variables ) =>
|
onSuccess: ( _, variables ) =>
|
||||||
{
|
{
|
||||||
queryClient.invalidateQueries({ queryKey: ["taskList"] });
|
queryClient.invalidateQueries(["taskList"]);
|
||||||
showToast("Task Assigned Successfully.", "success");
|
showToast("Task Assigned Successfully.", "success");
|
||||||
if (onSuccessCallback) onSuccessCallback(variables);
|
if (onSuccessCallback) onSuccessCallback(variables);
|
||||||
},
|
},
|
||||||
|
@ -4,7 +4,6 @@ import ManageProjectInfo from "../../components/Project/ManageProjectInfo";
|
|||||||
import Breadcrumb from "../../components/common/Breadcrumb";
|
import Breadcrumb from "../../components/common/Breadcrumb";
|
||||||
import ProjectRepository from "../../repositories/ProjectRepository";
|
import ProjectRepository from "../../repositories/ProjectRepository";
|
||||||
import { useProjects, useCreateProject } from "../../hooks/useProjects";
|
import { useProjects, useCreateProject } from "../../hooks/useProjects";
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
import showToast from "../../services/toastService";
|
import showToast from "../../services/toastService";
|
||||||
// import {
|
// import {
|
||||||
// getCachedData,
|
// getCachedData,
|
||||||
@ -32,7 +31,6 @@ const ProjectList = () => {
|
|||||||
const [HasManageProject, setHasManageProject] = useState(
|
const [HasManageProject, setHasManageProject] = useState(
|
||||||
HasManageProjectPermission
|
HasManageProjectPermission
|
||||||
);
|
);
|
||||||
const dispatch = useDispatch();
|
|
||||||
const { mutate: createProject } = useCreateProject({
|
const { mutate: createProject } = useCreateProject({
|
||||||
onSuccessCallback: () => {
|
onSuccessCallback: () => {
|
||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
@ -82,24 +80,7 @@ const ProjectList = () => {
|
|||||||
}
|
}
|
||||||
}, [loginUser, HasManageProjectPermission]);
|
}, [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) => {
|
const handleSubmitForm = (newProject, setloading, reset) => {
|
||||||
setloading(true);
|
setloading(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user