revert changed from July_4W

This commit is contained in:
pramod mahajan 2025-08-02 16:43:57 +05:30
parent 74f532799a
commit 01ce4c92b6

View File

@ -16,6 +16,7 @@ import { useCreateTask } from "../../hooks/useTasks";
const AssignTask = ({ assignData, onClose, setAssigned }) => {
const maxPlanned =
assignData?.workItem?.plannedWork - assignData?.workItem?.completedWork;
const schema = z.object({
selectedEmployees: z
.array(z.string())
@ -48,9 +49,6 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
const infoRef = useRef(null);
const infoRef1 = useRef(null);
// State for search term
const [searchTerm, setSearchTerm] = useState("");
useEffect(() => {
if (typeof bootstrap !== "undefined") {
if (infoRef.current) {
@ -83,13 +81,9 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
recallEmployeeData,
} = useEmployeesAllOrByProjectId(false, selectedProject, false);
const dispatch = useDispatch();
const { loading } = useMaster();
const { data: jobRoleData } = useMaster();
const { data: jobRoleData, loading } = useMaster();
// Changed to an array to hold multiple selected roles
const [selectedRoles, setSelectedRoles] = useState(["all"]);
// Changed to an array to hold multiple selected roles
// const [selectedRoles, setSelectedRoles] = useState(["all"]);
const [selectedRole, setSelectedRole] = useState("all");
const [displayedSelection, setDisplayedSelection] = useState("");
const {
handleSubmit,
@ -127,80 +121,21 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
useEffect(() => {
dispatch(changeMaster("Job Role"));
// Initial state should reflect "All Roles" selected
setSelectedRoles(["all"]);
return () => setSelectedRole("all");
}, [dispatch]);
// Modified handleRoleChange to handle multiple selections
const handleRoleChange = (event, roleId) => {
// If 'all' is selected, clear other selections
if (roleId === "all") {
setSelectedRoles(["all"]);
} else {
setSelectedRoles((prevSelectedRoles) => {
// If "all" was previously selected, remove it
const newRoles = prevSelectedRoles.filter((role) => role !== "all");
if (newRoles.includes(roleId)) {
// If role is already selected, unselect it
return newRoles.filter((id) => id !== roleId);
} else {
// If role is not selected, add it
return [...newRoles, roleId];
}
});
}
const handleRoleChange = (event) => {
setSelectedRole(event.target.value);
};
useEffect(() => {
// Update displayedSelection based on selectedRoles
if (selectedRoles.includes("all")) {
setDisplayedSelection("All Roles");
} else if (selectedRoles.length > 0) {
const selectedRoleNames = selectedRoles.map(roleId => {
const role = jobRoleData?.find(r => String(r.id) === roleId);
return role ? role.name : '';
}).filter(Boolean); // Filter out empty strings for roles not found
setDisplayedSelection(selectedRoleNames.join(', '));
} else {
setDisplayedSelection("Select Roles");
}
}, [selectedRoles, jobRoleData]);
const handleSearchChange = (event) => {
setSearchTerm(event.target.value);
};
// Filter employees first by role, then by search term AND job role name
const filteredEmployees = employees?.filter((emp) => {
const matchesRole =
selectedRoles.includes("all") || selectedRoles.includes(String(emp.jobRoleId));
// Convert both first and last names and job role name to lowercase for case-insensitive matching
const fullName = `${emp.firstName} ${emp.lastName}`.toLowerCase();
const jobRoleName = jobRoleData?.find((role) => role.id === emp.jobRoleId)?.name?.toLowerCase() || "";
const searchLower = searchTerm.toLowerCase();
// Check if the full name OR job role name includes the search term
const matchesSearch = fullName.includes(searchLower) || jobRoleName.includes(searchLower);
return matchesRole && matchesSearch;
});
// Determine unique job role IDs from the filtered employees (for dropdown options)
const uniqueJobRoleIdsInFilteredEmployees = new Set(
employees?.map(emp => emp.jobRoleId).filter(Boolean)
const filteredEmployees =
selectedRole === "all"
? employees
: employees?.filter(
(emp) => String(emp.jobRoleId || "") === selectedRole
);
// Filter jobRoleData to only include roles present in the uniqueJobRoleIdsInFilteredEmployees
const jobRolesForDropdown = jobRoleData?.filter(role =>
uniqueJobRoleIdsInFilteredEmployees.has(role.id)
);
// Calculate the count of selected roles for display
const selectedRolesCount = selectedRoles.includes("all")
? 0 // "All Roles" doesn't contribute to a specific count
: selectedRoles.length;
const onSubmit = (data) => {
const selectedEmployeeIds = data.selectedEmployees;
@ -224,7 +159,6 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
reset();
onClose();
};
return (
<div className="fs-5 text-dark text-center d-flex align-items-center justify-content-center flex-wrap">
<p className="align-items-center flex-wrap m-0 ">Assign Task</p>
@ -232,7 +166,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
<div className="mb-1">
<p className="mb-0">
<span className="text-dark text-start d-flex align-items-center flex-wrap form-text">
<span className="me-2 m-0 fw-bold">Work Location :</span> {/* Changed font-bold to fw-bold */}
<span className="me-2 m-0 font-bold">Work Location :</span>
{[
assignData?.building?.buildingName,
assignData?.floor?.floorName,
@ -258,92 +192,50 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
<div className="form-text text-start">
<div className="d-flex align-items-center form-text fs-7">
<span className="text-dark">Select Team</span>
<div className="dropdown position-relative d-inline-block">
<div className="me-2">{displayedSelection}</div>
<a
className={`dropdown-toggle hide-arrow cursor-pointer ${
selectedRoles.includes("all") || selectedRoles.length === 0
? "text-secondary"
: "text-primary"
}`}
className="dropdown-toggle hide-arrow cursor-pointer"
data-bs-toggle="dropdown"
role="button"
aria-expanded="false"
>
<i className="bx bx-slider-alt ms-2"></i>
<i className="bx bx-filter bx-lg text-primary"></i>
</a>
{/* Badge */}
{selectedRolesCount > 0 && (
<span
className="position-absolute top-0 start-100 translate-middle badge rounded-circle bg-warning text-white"
style={{
fontSize: "0.65rem",
minWidth: "18px",
height: "18px",
padding: "0",
lineHeight: "18px",
textAlign: "center",
zIndex: 10,
}}
<ul className="dropdown-menu p-2 text-capitalize">
<li key="all">
<button
type="button"
className="dropdown-item py-1"
onClick={() =>
handleRoleChange({
target: { value: "all" },
})
}
>
{selectedRolesCount}
</span>
)}
{/* Dropdown Menu - Corrected: Removed duplicate ul block */}
<ul className="dropdown-menu p-2 text-capitalize" style={{ maxHeight: "300px", overflowY: "auto" }}>
<li> {/* Changed key="all" to a unique key if possible, or keep it if "all" is a unique identifier */}
<div className="form-check dropdown-item py-0">
<input
className="form-check-input"
type="checkbox"
id="checkboxAllRoles" // Unique ID
value="all"
checked={selectedRoles.includes("all")}
onChange={(e) => handleRoleChange(e, e.target.value)}
/>
<label className="form-check-label ms-2" htmlFor="checkboxAllRoles">
All Roles
</label>
</div>
</button>
</li>
{jobRolesForDropdown?.map((role) => (
<li key={role.id}>
<div className="form-check dropdown-item py-0">
<input
className="form-check-input"
type="checkbox"
id={`checkboxRole-${role.id}`} // Unique ID
value={role.id}
checked={selectedRoles.includes(String(role.id))}
onChange={(e) => handleRoleChange(e, e.target.value)}
/>
<label className="form-check-label ms-2" htmlFor={`checkboxRole-${role.id}`}>
{role.name}
</label>
</div>
{jobRoleData?.map((user) => (
<li key={user.id}>
<button
type="button"
className="dropdown-item py-1"
value={user.id}
onClick={handleRoleChange}
>
{user.name}
</button>
</li>
))}
</ul>
</div>
<input
type="text"
className="form-control form-control-sm ms-auto mb-2 mt-2"
placeholder="Search employees or roles..."
value={searchTerm}
onChange={handleSearchChange}
style={{ maxWidth: "200px" }}
/>
</div>
</div>
</div>
</div>
<div
className="col-12 mt-2"
style={{ maxHeight: "280px", overflowY: "auto", overflowX: "hidden" }}
>
{selectedRoles?.length > 0 && (
<div className="row">
<div className="col-12 h-sm-25 overflow-auto mt-2" style={{height:"300px"}}>
{selectedRole !== "" && (
<div className="row">
{employeeLoading ? (
<div className="col-12">
@ -369,7 +261,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
{...field}
className="form-check-input me-1 mt-1"
type="checkbox"
id={`employee-${emp?.id}`} // Unique ID
id={`employee-${emp?.id}`}
value={emp.id}
checked={field.value?.includes(emp.id)}
onChange={(e) => {
@ -405,13 +297,14 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
) : (
<div className="col-12">
<p className="text-center">
No employees found for the selected role(s).
No employees found for the selected role.
</p>
</div>
)}
</div>
)}
</div>
</div>
<div
className="col-12 h-25 overflow-auto"
@ -429,11 +322,10 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
className="badge rounded-pill bg-label-primary d-inline-flex align-items-center me-1 mb-1"
>
{emp.firstName} {emp.lastName}
{/* Changed p tag to button for semantic correctness and accessibility */}
<button
<p
type="button"
className="btn-close btn-close-white ms-1" // Added ms-1 for spacing, removed p-0 m-0
aria-label="Remove employee" // More descriptive aria-label
className=" btn-close-white p-0 m-0"
aria-label="Close"
onClick={() => {
const updatedSelected = watch(
"selectedEmployees"
@ -446,7 +338,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
}}
>
<i className="icon-base bx bx-x icon-md "></i>
</button>
</p>
</span>
)
);
@ -466,12 +358,12 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
<div className="form-check form-check-inline mt-3 px-1">
<label
className="form-text text-dark align-items-center d-flex"
htmlFor="inlineCheckbox1" // This htmlFor isn't linked to a checkbox in this context
htmlFor="inlineCheckbox1"
>
Pending Task of Activity :
<label
className="form-check-label fs-7 ms-4"
htmlFor="inlineCheckbox1" // This htmlFor isn't linked to a checkbox in this context
htmlFor="inlineCheckbox1"
>
<strong>
{assignData?.workItem?.plannedWork -
@ -495,18 +387,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
data-bs-html="true"
style={{ cursor: "pointer" }}
>
&nbsp;
<svg
xmlns="http://www.w3.org/2000/svg"
width="13"
height="13"
fill="currentColor"
className="bi bi-info-circle"
viewBox="0 0 16 16"
>
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.547 1.11l1.91-2.011c.241-.256.384-.592.287-.984-.172-.439-.58-.827-1.13-.967a.664.664 0 0 1-.58-.309l-.15-.241-.002-.002zM8 4c-.535 0-.943.372-.943.836 0 .464.408.836.943.836.535 0 .943-.372.943-.836 0-.464-.408-.836-.943-.836z" />
</svg>
<i class='bx bx-info-circle bx-xs m-0 text-secondary'></i>
</div>
</div>
</label>
@ -518,7 +399,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
<div className="form-check form-check-inline mt-2 px-1 mb-2 text-start">
<label
className="text-dark text-start d-flex align-items-center flex-wrap form-text"
htmlFor="targetForTodayInput" // Added a unique htmlFor for clarity
htmlFor="inlineCheckbox1"
>
<span>Target for Today</span>&nbsp;
<span style={{ marginLeft: "46px" }}>:</span>
@ -537,46 +418,28 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
type="text"
className="form-control form-control-sm"
{...field}
id="defaultFormControlInput" // Consider a more descriptive ID if used elsewhere
id="defaultFormControlInput"
aria-describedby="defaultFormControlHelp"
/>
<span style={{ paddingLeft: "6px", whiteSpace: "nowrap" }}>
<u>
{" "}
<span style={{ paddingLeft: "6px" }}>
{
assignData?.workItem?.activityMaster
assignData?.workItem?.workItem?.activityMaster
?.unitOfMeasurement
}
</u>
</span>
<div
style={{
display: "flex",
alignItems: "center",
}}
className="flex align-items-center"
>
<div
ref={infoRef1}
tabIndex="0"
className="d-flex align-items-center avatar-group justify-content-center ms-2"
className="d-flex align-items-center avatar-group justify-content-center ms-2 cursor-pointer"
data-bs-toggle="popover"
data-bs-trigger="focus"
data-bs-placement="right"
data-bs-html="true"
style={{ cursor: "pointer" }}
>
&nbsp;
<svg
xmlns="http://www.w3.org/2000/svg"
width="13"
height="13"
fill="currentColor"
className="bi bi-info-circle"
viewBox="0 0 16 16"
>
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.547 1.11l1.91-2.011c.241-.256.384-.592.287-.984-.172-.439-.58-.827-1.13-.967a.664.664 0 0 1-.58-.309l-.15-.241-.002-.002zM8 4c-.535 0-.943.372-.943.836 0 .464.408.836.943.836.535 0 .943-.372.943-.836 0-.464-.408-.836-.943-.836z" />
</svg>
<i class='bx bx-info-circle bx-xs m-0 text-secondary'></i>
</div>
</div>
</div>
@ -595,6 +458,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
className="position-absolute bg-white border p-2 rounded shadow"
style={{ zIndex: 10, marginLeft: "10px" }}
>
{/* Add your help content here */}
<p className="mb-0">
Enter the target value for today's task.
</p>
@ -603,8 +467,8 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
</div>
<label
className="form-text fs-7 m-1 text-dark" // Removed duplicate htmlFor and text-lg
htmlFor="descriptionTextarea"
className="form-text fs-7 m-1 text-lg text-dark"
htmlFor="descriptionTextarea" // Changed htmlFor for better accessibility
>
Description
</label>
@ -615,7 +479,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
<textarea
{...field}
className="form-control"
id="descriptionTextarea" // Unique ID
id="descriptionTextarea" // Changed id for better accessibility
rows="2"
/>
)}
@ -625,6 +489,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
)}
</div>
{/* Submit and Cancel buttons */}
<div className="col-12 d-flex justify-content-center align-items-center gap-sm-6 gap-8 text-center mt-1">
<button
type="submit"
@ -647,7 +512,8 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
</form>
</div>
</div>
</div> );
</div>
);
};
export default AssignTask;