Compare commits
No commits in common. "74f532799adf7ce7af75c9a23a83dc1027844e9b" and "d3f21f33b669b82d8a3dad938b304bf67642a236" have entirely different histories.
74f532799a
...
d3f21f33b6
@ -6,27 +6,34 @@ import RenderAttendanceStatus from "./RenderAttendanceStatus";
|
|||||||
import usePagination from "../../hooks/usePagination";
|
import usePagination from "../../hooks/usePagination";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
||||||
import { useAttendance } from "../../hooks/useAttendance"; // This hook is already providing data
|
import { useAttendance } from "../../hooks/useAttendance";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import eventBus from "../../services/eventBus";
|
import eventBus from "../../services/eventBus";
|
||||||
|
|
||||||
const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedAttendanceFromParent, showOnlyCheckout, setshowOnlyCheckout }) => {
|
const Attendance = ({ getRole, handleModalData }) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [todayDate, setTodayDate] = useState(new Date());
|
const [todayDate, setTodayDate] = useState(new Date());
|
||||||
|
const [ShowPending, setShowPending] = useState(false);
|
||||||
const selectedProject = useSelector(
|
const selectedProject = useSelector(
|
||||||
(store) => store.localVariables.projectId
|
(store) => store.localVariables.projectId
|
||||||
);
|
);
|
||||||
const {
|
const {
|
||||||
|
attendance,
|
||||||
loading: attLoading,
|
loading: attLoading,
|
||||||
recall: attrecall,
|
recall: attrecall,
|
||||||
isFetching
|
isFetching
|
||||||
} = useAttendance(selectedProject); // Keep this hook to manage recall and fetching status
|
} = useAttendance(selectedProject);
|
||||||
|
const filteredAttendance = ShowPending
|
||||||
|
? attendance?.filter(
|
||||||
|
(att) => att?.checkInTime !== null && att?.checkOutTime === null
|
||||||
|
)
|
||||||
|
: attendance;
|
||||||
|
|
||||||
const attendanceList = Array.isArray(filteredAndSearchedAttendanceFromParent)
|
const attendanceList = Array.isArray(filteredAttendance)
|
||||||
? filteredAndSearchedAttendanceFromParent
|
? filteredAttendance
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const sortByName = (a, b) => {
|
const sortByName = (a, b) => {
|
||||||
@ -34,7 +41,6 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
const nameB = (b.firstName + b.lastName).toLowerCase();
|
const nameB = (b.firstName + b.lastName).toLowerCase();
|
||||||
return nameA?.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
};
|
};
|
||||||
|
|
||||||
const group1 = attendanceList
|
const group1 = attendanceList
|
||||||
.filter((d) => d.activity === 1 || d.activity === 4)
|
.filter((d) => d.activity === 1 || d.activity === 4)
|
||||||
.sort(sortByName);
|
.sort(sortByName);
|
||||||
@ -42,39 +48,41 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
.filter((d) => d.activity === 0)
|
.filter((d) => d.activity === 0)
|
||||||
.sort(sortByName);
|
.sort(sortByName);
|
||||||
|
|
||||||
const finalFilteredDataForPagination = [...group1, ...group2];
|
const filteredData = [...group1, ...group2];
|
||||||
|
|
||||||
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
||||||
finalFilteredDataForPagination, // Use the data that's already been searched and grouped
|
filteredData,
|
||||||
ITEMS_PER_PAGE
|
ITEMS_PER_PAGE
|
||||||
);
|
);
|
||||||
|
|
||||||
const handler = useCallback(
|
const handler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
if (selectedProject === msg.projectId) {
|
if (selectedProject == msg.projectId) {
|
||||||
|
// const updatedAttendance = attendances.map((item) =>
|
||||||
|
// item.employeeId === msg.response.employeeId
|
||||||
|
// ? { ...item, ...msg.response }
|
||||||
|
// : item
|
||||||
|
// );
|
||||||
queryClient.setQueryData(["attendance", selectedProject], (oldData) => {
|
queryClient.setQueryData(["attendance", selectedProject], (oldData) => {
|
||||||
if (!oldData) {
|
if (!oldData) {
|
||||||
queryClient.invalidateQueries({ queryKey: ["attendance"] });
|
queryClient.invalidateQueries({queryKey:["attendance"]})
|
||||||
return; // Exit to avoid mapping on undefined oldData
|
};
|
||||||
}
|
|
||||||
return oldData.map((record) =>
|
return oldData.map((record) =>
|
||||||
record.employeeId === msg.response.employeeId ? { ...record, ...msg.response } : record
|
record.employeeId === msg.response.employeeId ? { ...record, ...msg.response } : record
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[selectedProject, queryClient] // Added queryClient to dependencies
|
[selectedProject, attrecall]
|
||||||
);
|
);
|
||||||
|
|
||||||
const employeeHandler = useCallback(
|
const employeeHandler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
if (attrecall) { // Check if attrecall function exists
|
if (attendances.some((item) => item.employeeId == msg.employeeId)) {
|
||||||
attrecall();
|
attrecall();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[attrecall] // Dependency should be attrecall, not `selectedProject` or `attendance` here
|
[selectedProject, attendance]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
eventBus.on("attendance", handler);
|
eventBus.on("attendance", handler);
|
||||||
return () => eventBus.off("attendance", handler);
|
return () => eventBus.off("attendance", handler);
|
||||||
@ -97,14 +105,13 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
role="switch"
|
role="switch"
|
||||||
id="inactiveEmployeesCheckbox"
|
id="inactiveEmployeesCheckbox"
|
||||||
disabled={isFetching}
|
disabled={isFetching}
|
||||||
checked={showOnlyCheckout} // Use prop for checked state
|
checked={ShowPending}
|
||||||
onChange={(e) => setshowOnlyCheckout(e.target.checked)} // Use prop for onChange
|
onChange={(e) => setShowPending(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
<label className="form-check-label ms-0">Show Pending</label>
|
<label className="form-check-label ms-0">Show Pending</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* Use `filteredAndSearchedAttendanceFromParent` for the initial check of data presence */}
|
{Array.isArray(attendance) && attendance.length > 0 ? (
|
||||||
{Array.isArray(filteredAndSearchedAttendanceFromParent) && filteredAndSearchedAttendanceFromParent.length > 0 ? (
|
|
||||||
<>
|
<>
|
||||||
<table className="table ">
|
<table className="table ">
|
||||||
<thead>
|
<thead>
|
||||||
@ -122,7 +129,7 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="table-border-bottom-0 ">
|
<tbody className="table-border-bottom-0 ">
|
||||||
{currentItems && currentItems.length > 0 ? ( // Check currentItems length before mapping
|
{currentItems &&
|
||||||
currentItems
|
currentItems
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
const checkInA = a?.checkInTime
|
const checkInA = a?.checkInTime
|
||||||
@ -179,18 +186,14 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))
|
))}
|
||||||
) : (
|
{!attendance && (
|
||||||
<tr>
|
<span className="text-secondary m-4">No employees assigned to the project!</span>
|
||||||
<td colSpan="6" className="text-center text-muted py-4">
|
|
||||||
No matching records found.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{!attLoading && finalFilteredDataForPagination.length > ITEMS_PER_PAGE && ( // Use the data before pagination for total count check
|
{!loading && filteredData.length > 20 && (
|
||||||
<nav aria-label="Page ">
|
<nav aria-label="Page ">
|
||||||
<ul className="pagination pagination-sm justify-content-end py-1">
|
<ul className="pagination pagination-sm justify-content-end py-1">
|
||||||
<li
|
<li
|
||||||
@ -240,16 +243,14 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
<div>Loading...</div>
|
<div>Loading...</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="text-muted">
|
<div className="text-muted">
|
||||||
{/* Check the actual prop passed for initial data presence */}
|
{Array.isArray(attendance)
|
||||||
{Array.isArray(filteredAndSearchedAttendanceFromParent) && filteredAndSearchedAttendanceFromParent.length === 0
|
? "No employees assigned to the project"
|
||||||
? ""
|
: "Attendance data unavailable"}
|
||||||
: "Attendance data unavailable."}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* This condition should check `currentItems` or `finalFilteredDataForPagination` */}
|
{currentItems?.length == 0 && attendance.length > 0 && (
|
||||||
{currentItems?.length === 0 && finalFilteredDataForPagination.length > 0 && showOnlyCheckout && (
|
<div className="my-4"><span className="text-secondary">No Pending Record Available !</span></div>
|
||||||
<div className="my-4"><span className="text-secondary">No Pending Record Available for your search!</span></div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -4,31 +4,24 @@ import Avatar from "../common/Avatar";
|
|||||||
import { convertShortTime } from "../../utils/dateUtils";
|
import { convertShortTime } from "../../utils/dateUtils";
|
||||||
import RenderAttendanceStatus from "./RenderAttendanceStatus";
|
import RenderAttendanceStatus from "./RenderAttendanceStatus";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { fetchAttendanceData, setAttendanceData } from "../../slices/apiSlice/attedanceLogsSlice";
|
import { fetchAttendanceData } from "../../slices/apiSlice/attedanceLogsSlice";
|
||||||
import DateRangePicker from "../common/DateRangePicker";
|
import DateRangePicker from "../common/DateRangePicker";
|
||||||
|
import { clearCacheKey, getCachedData } from "../../slices/apiDataManager";
|
||||||
import eventBus from "../../services/eventBus";
|
import eventBus from "../../services/eventBus";
|
||||||
|
import AttendanceRepository from "../../repositories/AttendanceRepository";
|
||||||
|
import { useAttendancesLogs } from "../../hooks/useAttendance";
|
||||||
|
import { queryClient } from "../../layouts/AuthLayout";
|
||||||
|
|
||||||
const usePagination = (data, itemsPerPage) => {
|
const usePagination = (data, itemsPerPage) => {
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const totalItems = Array.isArray(data) ? data.length : 0;
|
const maxPage = Math.ceil(data.length / itemsPerPage);
|
||||||
const maxPage = Math.ceil(totalItems / itemsPerPage);
|
|
||||||
|
|
||||||
const currentItems = useMemo(() => {
|
const currentItems = useMemo(() => {
|
||||||
if (!Array.isArray(data) || data.length === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const startIndex = (currentPage - 1) * itemsPerPage;
|
const startIndex = (currentPage - 1) * itemsPerPage;
|
||||||
const endIndex = startIndex + itemsPerPage;
|
const endIndex = startIndex + itemsPerPage;
|
||||||
return data.slice(startIndex, endIndex);
|
return data.slice(startIndex, endIndex);
|
||||||
}, [data, currentPage, itemsPerPage]);
|
}, [data, currentPage, itemsPerPage]);
|
||||||
|
|
||||||
const paginate = useCallback((pageNumber) => {
|
const paginate = useCallback((pageNumber) => setCurrentPage(pageNumber), []);
|
||||||
if (pageNumber > 0 && pageNumber <= maxPage) {
|
|
||||||
setCurrentPage(pageNumber);
|
|
||||||
}
|
|
||||||
}, [maxPage]);
|
|
||||||
|
|
||||||
// Ensure resetPage is returned by the hook
|
|
||||||
const resetPage = useCallback(() => setCurrentPage(1), []);
|
const resetPage = useCallback(() => setCurrentPage(1), []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -42,91 +35,60 @@ const usePagination = (data, itemsPerPage) => {
|
|||||||
|
|
||||||
const AttendanceLog = ({
|
const AttendanceLog = ({
|
||||||
handleModalData,
|
handleModalData,
|
||||||
projectId,
|
|
||||||
setshowOnlyCheckout,
|
|
||||||
showOnlyCheckout,
|
|
||||||
searchQuery, // Prop for search query
|
|
||||||
}) => {
|
}) => {
|
||||||
|
const selectedProject = useSelector(
|
||||||
|
(store) => store.localVariables.projectId
|
||||||
|
);
|
||||||
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
|
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { data, loading, error } = useSelector((store) => store.attendanceLogs);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [showPending,setShowPending] = useState(false)
|
||||||
|
|
||||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||||
|
const [processedData, setProcessedData] = useState([]);
|
||||||
|
|
||||||
const today = useMemo(() => {
|
const today = new Date();
|
||||||
const d = new Date();
|
today.setHours(0, 0, 0, 0);
|
||||||
d.setHours(0, 0, 0, 0);
|
|
||||||
return d;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const yesterday = useMemo(() => {
|
const yesterday = new Date();
|
||||||
const d = new Date();
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
d.setDate(d.getDate() - 1);
|
|
||||||
return d;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const isSameDay = useCallback((dateStr) => {
|
const isSameDay = (dateStr) => {
|
||||||
if (!dateStr) return false;
|
if (!dateStr) return false;
|
||||||
const d = new Date(dateStr);
|
const d = new Date(dateStr);
|
||||||
d.setHours(0, 0, 0, 0);
|
d.setHours(0, 0, 0, 0);
|
||||||
return d.getTime() === today.getTime();
|
return d.getTime() === today.getTime();
|
||||||
}, [today]);
|
};
|
||||||
|
|
||||||
const isBeforeToday = useCallback((dateStr) => {
|
const isBeforeToday = (dateStr) => {
|
||||||
if (!dateStr) return false;
|
if (!dateStr) return false;
|
||||||
const d = new Date(dateStr);
|
const d = new Date(dateStr);
|
||||||
d.setHours(0, 0, 0, 0);
|
d.setHours(0, 0, 0, 0);
|
||||||
return d.getTime() < today.getTime();
|
return d.getTime() < today.getTime();
|
||||||
}, [today]);
|
};
|
||||||
|
|
||||||
const sortByName = useCallback((a, b) => {
|
const sortByName = (a, b) => {
|
||||||
const nameA = `${a.firstName || ""} ${a.lastName || ""}`.toLowerCase();
|
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
||||||
const nameB = `${b.firstName || ""} ${b.lastName || ""}`.toLowerCase();
|
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
}, []);
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const {
|
||||||
const { startDate, endDate } = dateRange;
|
data = [],
|
||||||
dispatch(
|
isLoading,
|
||||||
fetchAttendanceData({
|
error,
|
||||||
projectId,
|
refetch,
|
||||||
fromDate: startDate,
|
isFetching,
|
||||||
toDate: endDate,
|
} = useAttendancesLogs(
|
||||||
})
|
selectedProject,
|
||||||
|
dateRange.startDate,
|
||||||
|
dateRange.endDate
|
||||||
);
|
);
|
||||||
setIsRefreshing(false);
|
const filtering = (data) => {
|
||||||
}, [dateRange, projectId, dispatch, isRefreshing]);
|
const filteredData = showPending
|
||||||
|
|
||||||
const processedData = useMemo(() => {
|
|
||||||
let filteredData = showOnlyCheckout
|
|
||||||
? data.filter((item) => item.checkOutTime === null)
|
? data.filter((item) => item.checkOutTime === null)
|
||||||
: data;
|
: data;
|
||||||
|
|
||||||
// Apply search query filter
|
|
||||||
if (searchQuery) {
|
|
||||||
const lowerCaseSearchQuery = searchQuery.toLowerCase().trim(); // Trim whitespace
|
|
||||||
|
|
||||||
filteredData = filteredData.filter((att) => {
|
|
||||||
// Option 1: Combine firstName, middleName, lastName
|
|
||||||
const fullName = [att.firstName, att.middleName, att.lastName]
|
|
||||||
.filter(Boolean) // This removes null, undefined, or empty string parts
|
|
||||||
.join(" ")
|
|
||||||
.toLowerCase();
|
|
||||||
|
|
||||||
// Option 2: Check `employeeName` if it exists and is reliable
|
|
||||||
const employeeName = att.employeeName?.toLowerCase() || "";
|
|
||||||
|
|
||||||
// Option 3: Check `employeeId`
|
|
||||||
const employeeId = att.employeeId?.toLowerCase() || "";
|
|
||||||
|
|
||||||
// Check if the search query is included in any of the relevant fields
|
|
||||||
return (
|
|
||||||
fullName.includes(lowerCaseSearchQuery) ||
|
|
||||||
employeeName.includes(lowerCaseSearchQuery) ||
|
|
||||||
employeeId.includes(lowerCaseSearchQuery)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const group1 = filteredData
|
const group1 = filteredData
|
||||||
.filter((d) => d.activity === 1 && isSameDay(d.checkInTime))
|
.filter((d) => d.activity === 1 && isSameDay(d.checkInTime))
|
||||||
.sort(sortByName);
|
.sort(sortByName);
|
||||||
@ -165,46 +127,53 @@ const AttendanceLog = ({
|
|||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
// Sort dates in descending order
|
|
||||||
const sortedDates = Object.keys(groupedByDate).sort(
|
const sortedDates = Object.keys(groupedByDate).sort(
|
||||||
(a, b) => new Date(b) - new Date(a)
|
(a, b) => new Date(b) - new Date(a)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create the final sorted array
|
const finalData = sortedDates.flatMap((date) => groupedByDate[date]);
|
||||||
return sortedDates.flatMap((date) => groupedByDate[date]);
|
setProcessedData(finalData);
|
||||||
}, [data, showOnlyCheckout, searchQuery, isSameDay, isBeforeToday, sortByName]);
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
filtering(data);
|
||||||
|
}, [data, showPending]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
currentPage,
|
currentPage,
|
||||||
totalPages,
|
totalPages,
|
||||||
currentItems: paginatedAttendances,
|
currentItems: paginatedAttendances,
|
||||||
paginate,
|
paginate,
|
||||||
resetPage, // Destructure resetPage here
|
resetPage,
|
||||||
} = usePagination(processedData, 20);
|
} = usePagination(processedData, 20);
|
||||||
|
|
||||||
// Effect to reset pagination when search query changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resetPage();
|
resetPage();
|
||||||
}, [searchQuery, resetPage]); // Add resetPage to dependencies
|
}, [processedData, resetPage]);
|
||||||
|
|
||||||
const handler = useCallback(
|
const handler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const { startDate, endDate } = dateRange;
|
const { startDate, endDate } = dateRange;
|
||||||
const checkIn = msg.response.checkInTime.substring(0, 10);
|
const checkIn = msg.response.checkInTime.substring(0, 10);
|
||||||
if (
|
if (
|
||||||
projectId === msg.projectId &&
|
selectedProject === msg.projectId &&
|
||||||
startDate <= checkIn &&
|
startDate <= checkIn &&
|
||||||
checkIn <= endDate
|
checkIn <= endDate
|
||||||
) {
|
) {
|
||||||
const updatedAttendance = data.map((item) =>
|
queryClient.setQueriesData(["attendanceLogs"],(oldData)=>{
|
||||||
item.id === msg.response.id
|
if(!oldData) {
|
||||||
? { ...item, ...msg.response }
|
queryClient.invalidateQueries({queryKey:["attendanceLogs"]})
|
||||||
: item
|
}
|
||||||
|
return oldData.map((record) =>
|
||||||
|
record.id === msg.response.id ? { ...record, ...msg.response } : record
|
||||||
);
|
);
|
||||||
dispatch(setAttendanceData(updatedAttendance)); // Update Redux store
|
})
|
||||||
|
|
||||||
|
filtering(updatedAttendance);
|
||||||
|
resetPage();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[projectId, dateRange, data, dispatch]
|
[selectedProject, dateRange, data, filtering, resetPage]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -215,15 +184,19 @@ const AttendanceLog = ({
|
|||||||
const employeeHandler = useCallback(
|
const employeeHandler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const { startDate, endDate } = dateRange;
|
const { startDate, endDate } = dateRange;
|
||||||
dispatch(
|
if (data.some((item) => item.employeeId == msg.employeeId)) {
|
||||||
fetchAttendanceData({
|
// dispatch(
|
||||||
projectId,
|
// fetchAttendanceData({
|
||||||
fromDate: startDate,
|
// ,
|
||||||
toDate: endDate,
|
// fromDate: startDate,
|
||||||
})
|
// toDate: endDate,
|
||||||
);
|
// })
|
||||||
|
// );
|
||||||
|
|
||||||
|
refetch()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[projectId, dateRange, dispatch]
|
[selectedProject, dateRange, data]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -247,27 +220,28 @@ const AttendanceLog = ({
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="form-check-input"
|
className="form-check-input"
|
||||||
role="switch"
|
role="switch"
|
||||||
|
disabled={isFetching}
|
||||||
id="inactiveEmployeesCheckbox"
|
id="inactiveEmployeesCheckbox"
|
||||||
checked={showOnlyCheckout}
|
checked={showPending}
|
||||||
onChange={(e) => setshowOnlyCheckout(e.target.checked)}
|
onChange={(e) => setShowPending(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
<label className="form-check-label ms-0">Show Pending</label>
|
<label className="form-check-label ms-0">Show Pending</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-md-2 m-0 text-end">
|
<div className="col-md-2 m-0 text-end">
|
||||||
<i
|
<i
|
||||||
className={`bx bx-refresh cursor-pointer fs-4 ${loading || isRefreshing ? "spin" : ""
|
className={`bx bx-refresh cursor-pointer fs-4 ${
|
||||||
|
isFetching ? "spin" : ""
|
||||||
}`}
|
}`}
|
||||||
title="Refresh"
|
title="Refresh"
|
||||||
onClick={() => setIsRefreshing(true)}
|
onClick={() => refetch()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div className="table-responsive text-nowrap">
|
||||||
className="table-responsive text-nowrap"
|
{isLoading ? (
|
||||||
style={{ minHeight: "200px", display: 'flex' }}
|
<div><p className="text-secondary">Loading...</p></div>
|
||||||
>
|
) : data?.length > 0 ? (
|
||||||
{processedData && processedData.length > 0 ? (
|
|
||||||
<table className="table mb-0">
|
<table className="table mb-0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -286,14 +260,7 @@ const AttendanceLog = ({
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{(loading || isRefreshing) && (
|
{paginatedAttendances.reduce((acc, attendance, index, arr) => {
|
||||||
<tr>
|
|
||||||
<td colSpan={6}>Loading...</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
{!loading &&
|
|
||||||
!isRefreshing &&
|
|
||||||
paginatedAttendances.reduce((acc, attendance, index, arr) => {
|
|
||||||
const currentDate = moment(
|
const currentDate = moment(
|
||||||
attendance.checkInTime || attendance.checkOutTime
|
attendance.checkInTime || attendance.checkOutTime
|
||||||
).format("YYYY-MM-DD");
|
).format("YYYY-MM-DD");
|
||||||
@ -320,7 +287,7 @@ const AttendanceLog = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
acc.push(
|
acc.push(
|
||||||
<tr key={attendance.id || index}>
|
<tr key={index}>
|
||||||
<td colSpan={2}>
|
<td colSpan={2}>
|
||||||
<div className="d-flex justify-content-start align-items-center">
|
<div className="d-flex justify-content-start align-items-center">
|
||||||
<Avatar
|
<Avatar
|
||||||
@ -362,20 +329,13 @@ const AttendanceLog = ({
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
) : (
|
) : (
|
||||||
!loading &&
|
<div className="my-4"><span className="text-secondary">No Record Available !</span></div>
|
||||||
!isRefreshing && (
|
|
||||||
<div
|
|
||||||
className="d-flex justify-content-center align-items-center text-muted"
|
|
||||||
style={{
|
|
||||||
width: "100%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
No employee logs.
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!loading && !isRefreshing && processedData.length > 20 && (
|
{paginatedAttendances?.length == 0 && data?.length > 0 && (
|
||||||
|
<div className="my-4"><span className="text-secondary">No Pending Record Available !</span></div>
|
||||||
|
)}
|
||||||
|
{processedData.length > 10 && (
|
||||||
<nav aria-label="Page ">
|
<nav aria-label="Page ">
|
||||||
<ul className="pagination pagination-sm justify-content-end py-1">
|
<ul className="pagination pagination-sm justify-content-end py-1">
|
||||||
<li className={`page-item ${currentPage === 1 ? "disabled" : ""}`}>
|
<li className={`page-item ${currentPage === 1 ? "disabled" : ""}`}>
|
||||||
@ -390,7 +350,8 @@ const AttendanceLog = ({
|
|||||||
(pageNumber) => (
|
(pageNumber) => (
|
||||||
<li
|
<li
|
||||||
key={pageNumber}
|
key={pageNumber}
|
||||||
className={`page-item ${currentPage === pageNumber ? "active" : ""
|
className={`page-item ${
|
||||||
|
currentPage === pageNumber ? "active" : ""
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@ -403,7 +364,8 @@ const AttendanceLog = ({
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${currentPage === totalPages ? "disabled" : ""
|
className={`page-item ${
|
||||||
|
currentPage === totalPages ? "disabled" : ""
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@ -11,43 +11,10 @@ import { checkIfCurrentDate } from "../../utils/dateUtils";
|
|||||||
import { useMarkAttendance } from "../../hooks/useAttendance";
|
import { useMarkAttendance } from "../../hooks/useAttendance";
|
||||||
|
|
||||||
|
|
||||||
// const schema = z.object({
|
const schema = z.object({
|
||||||
// markTime: z.string().nonempty({ message: "Time is required" }),
|
|
||||||
// description: z.string().max(200, "description should less than 200 chracters").optional()
|
|
||||||
// });
|
|
||||||
|
|
||||||
const createSchema = (modeldata) => {
|
|
||||||
return z
|
|
||||||
.object({
|
|
||||||
markTime: z.string().nonempty({ message: "Time is required" }),
|
markTime: z.string().nonempty({ message: "Time is required" }),
|
||||||
description: z
|
description: z.string().max(200, "description should less than 200 chracters").optional()
|
||||||
.string()
|
|
||||||
.max(200, "Description should be less than 200 characters")
|
|
||||||
.optional(),
|
|
||||||
})
|
|
||||||
.refine((data) => {
|
|
||||||
if (modeldata?.checkInTime && !modeldata?.checkOutTime) {
|
|
||||||
const checkIn = new Date(modeldata.checkInTime);
|
|
||||||
const [time, modifier] = data.markTime.split(" ");
|
|
||||||
const [hourStr, minuteStr] = time.split(":");
|
|
||||||
let hour = parseInt(hourStr, 10);
|
|
||||||
const minute = parseInt(minuteStr, 10);
|
|
||||||
|
|
||||||
if (modifier === "PM" && hour !== 12) hour += 12;
|
|
||||||
if (modifier === "AM" && hour === 12) hour = 0;
|
|
||||||
|
|
||||||
const checkOut = new Date(checkIn);
|
|
||||||
checkOut.setHours(hour, minute, 0, 0);
|
|
||||||
|
|
||||||
return checkOut > checkIn;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}, {
|
|
||||||
message: "Checkout time must be later than check-in time",
|
|
||||||
path: ["markTime"],
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
||||||
|
|
||||||
@ -66,17 +33,6 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
return `${day}-${month}-${year}`;
|
return `${day}-${month}-${year}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// const {
|
|
||||||
// register,
|
|
||||||
// handleSubmit,
|
|
||||||
// formState: { errors },
|
|
||||||
// reset,
|
|
||||||
// setValue,
|
|
||||||
// } = useForm({
|
|
||||||
// resolver: zodResolver(schema),
|
|
||||||
// mode: "onChange"
|
|
||||||
// });
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -84,20 +40,31 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
reset,
|
reset,
|
||||||
setValue,
|
setValue,
|
||||||
} = useForm({
|
} = useForm({
|
||||||
resolver: zodResolver(createSchema(modeldata)),
|
resolver: zodResolver(schema),
|
||||||
mode: "onChange",
|
mode: "onChange"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
const onSubmit = (data) => {
|
||||||
let record = { ...data, date: new Date().toLocaleDateString(), latitude: coords.latitude, longitude: coords.longitude, employeeId: modeldata.employeeId, action: modeldata.action, id: modeldata?.id || null }
|
let record = { ...data, date: new Date().toLocaleDateString(), latitude: coords.latitude, longitude: coords.longitude, employeeId: modeldata.employeeId, action: modeldata.action, id: modeldata?.id || null }
|
||||||
if (modeldata.forWhichTab === 1) {
|
// if (modeldata.forWhichTab === 1 || modeldata.forWhichTab === 2) {
|
||||||
handleSubmitForm(record)
|
// handleSubmitForm(record)
|
||||||
} else {
|
const payload = {
|
||||||
|
Id: modeldata?.id || null,
|
||||||
dispatch(markAttendance(record))
|
comment: data.description,
|
||||||
.unwrap()
|
employeeID: modeldata.employeeId,
|
||||||
.then((data) => {
|
projectId: projectId,
|
||||||
|
date: new Date().toISOString(),
|
||||||
|
markTime: data.markTime,
|
||||||
|
latitude: coords.latitude.toString(),
|
||||||
|
longitude: coords.longitude.toString(),
|
||||||
|
action: modeldata.action,
|
||||||
|
image: null,
|
||||||
|
};
|
||||||
|
MarkAttendance({payload,forWhichTab:modeldata.forWhichTab})
|
||||||
|
// } else {
|
||||||
|
// dispatch(markAttendance(record))
|
||||||
|
// .unwrap()
|
||||||
|
// .then((data) => {
|
||||||
|
|
||||||
// showToast("Attendance Marked Successfully", "success");
|
// showToast("Attendance Marked Successfully", "success");
|
||||||
// })
|
// })
|
||||||
@ -105,8 +72,8 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
|
|
||||||
// showToast(error, "error");
|
// showToast(error, "error");
|
||||||
|
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
closeModal()
|
closeModal()
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,37 +7,63 @@ import { useRegularizationRequests } from "../../hooks/useAttendance";
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import usePagination from "../../hooks/usePagination";
|
import usePagination from "../../hooks/usePagination";
|
||||||
import eventBus from "../../services/eventBus";
|
import eventBus from "../../services/eventBus";
|
||||||
import { cacheData } from "../../slices/apiDataManager";
|
import { cacheData, clearCacheKey } from "../../slices/apiDataManager";
|
||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
const Regularization = ({ handleRequest, searchQuery }) => {
|
const Regularization = ({ handleRequest }) => {
|
||||||
const selectedProject = useSelector((store) => store.localVariables.projectId);
|
const queryClient = useQueryClient();
|
||||||
const [regularizesList, setRegularizedList] = useState([]);
|
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||||
const { regularizes, loading, refetch } = useRegularizationRequests(selectedProject);
|
const [regularizesList, setregularizedList] = useState([]);
|
||||||
|
const { regularizes, loading, error, refetch } =
|
||||||
|
useRegularizationRequests(selectedProject);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setRegularizedList(regularizes);
|
setregularizedList(regularizes);
|
||||||
}, [regularizes]);
|
}, [regularizes]);
|
||||||
|
|
||||||
const sortByName = (a, b) => {
|
const sortByName = (a, b) => {
|
||||||
const nameA = (a.firstName + a.lastName).toLowerCase();
|
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
||||||
const nameB = (b.firstName + b.lastName).toLowerCase();
|
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handler = useCallback(
|
const handler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
if (selectedProject == msg.projectId) {
|
if (selectedProject == msg.projectId) {
|
||||||
const updatedAttendance = regularizes?.filter(item => item.id !== msg.response.id);
|
// const updatedAttendance = regularizes?.filter(
|
||||||
cacheData("regularizedList", {
|
// (item) => item.id !== msg.response.id
|
||||||
data: updatedAttendance,
|
// );
|
||||||
projectId: selectedProject,
|
// cacheData("regularizedList", {
|
||||||
});
|
// data: updatedAttendance,
|
||||||
refetch();
|
// projectId: selectedProject,
|
||||||
|
// });
|
||||||
|
// refetch();
|
||||||
|
|
||||||
|
queryClient.setQueryData(
|
||||||
|
["regularizedList", selectedProject],
|
||||||
|
(oldData) => {
|
||||||
|
if (!oldData) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["regularizedList"] });
|
||||||
|
}
|
||||||
|
return oldData.filter((record) => record.id !== msg.response.id);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["attendanceLogs"] });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[selectedProject, regularizes]
|
[selectedProject, regularizes]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const filteredData = [...regularizesList]?.sort(sortByName);
|
||||||
|
|
||||||
|
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
||||||
|
filteredData,
|
||||||
|
20
|
||||||
|
);
|
||||||
|
useEffect(() => {
|
||||||
|
eventBus.on("regularization", handler);
|
||||||
|
return () => eventBus.off("regularization", handler);
|
||||||
|
}, [handler]);
|
||||||
|
|
||||||
const employeeHandler = useCallback(
|
const employeeHandler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
@ -48,36 +74,18 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
|||||||
[regularizes]
|
[regularizes]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
eventBus.on("regularization", handler);
|
|
||||||
return () => eventBus.off("regularization", handler);
|
|
||||||
}, [handler]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
eventBus.on("employee", employeeHandler);
|
eventBus.on("employee", employeeHandler);
|
||||||
return () => eventBus.off("employee", employeeHandler);
|
return () => eventBus.off("employee", employeeHandler);
|
||||||
}, [employeeHandler]);
|
}, [employeeHandler]);
|
||||||
|
|
||||||
// ✅ Search filter logic added here
|
|
||||||
const filteredData = [...regularizesList]
|
|
||||||
?.filter((item) => {
|
|
||||||
if (!searchQuery) return true;
|
|
||||||
const lowerSearch = searchQuery.toLowerCase();
|
|
||||||
const fullName = `${item.firstName || ""} ${item.lastName || ""}`.toLowerCase();
|
|
||||||
|
|
||||||
return (
|
|
||||||
item.firstName?.toLowerCase().includes(lowerSearch) ||
|
|
||||||
item.lastName?.toLowerCase().includes(lowerSearch) ||
|
|
||||||
fullName.includes(lowerSearch) ||
|
|
||||||
item.employeeId?.toLowerCase().includes(lowerSearch)
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.sort(sortByName);
|
|
||||||
|
|
||||||
const { currentPage, totalPages, currentItems, paginate } = usePagination(filteredData, 20);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="table-responsive text-nowrap pb-4">
|
<div className="table-responsive text-nowrap pb-4">
|
||||||
|
{loading ? (
|
||||||
|
<div className="my-2">
|
||||||
|
<p className="text-secondary">Loading...</p>
|
||||||
|
</div>
|
||||||
|
) : currentItems?.length > 0 ? (
|
||||||
<table className="table mb-0">
|
<table className="table mb-0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -93,12 +101,14 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{!loading && currentItems?.length > 0 ? (
|
{currentItems?.map((att, index) => (
|
||||||
currentItems.map((att, index) => (
|
|
||||||
<tr key={index}>
|
<tr key={index}>
|
||||||
<td colSpan={2}>
|
<td colSpan={2}>
|
||||||
<div className="d-flex justify-content-start align-items-center">
|
<div className="d-flex justify-content-start align-items-center">
|
||||||
<Avatar firstName={att.firstName} lastName={att.lastName} />
|
<Avatar
|
||||||
|
firstName={att.firstName}
|
||||||
|
lastName={att.lastName}
|
||||||
|
></Avatar>
|
||||||
<div className="d-flex flex-column">
|
<div className="d-flex flex-column">
|
||||||
<a href="#" className="text-heading text-truncate">
|
<a href="#" className="text-heading text-truncate">
|
||||||
<span className="fw-normal">
|
<span className="fw-normal">
|
||||||
@ -119,27 +129,18 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
|||||||
handleRequest={handleRequest}
|
handleRequest={handleRequest}
|
||||||
refresh={refetch}
|
refresh={refetch}
|
||||||
/>
|
/>
|
||||||
|
{/* </div> */}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))
|
))}
|
||||||
) : (
|
|
||||||
<tr>
|
|
||||||
<td
|
|
||||||
colSpan={6}
|
|
||||||
className="text-center"
|
|
||||||
style={{
|
|
||||||
height: "200px",
|
|
||||||
verticalAlign: "middle",
|
|
||||||
borderBottom: "none",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? "Loading..." : "No Record Found"}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
) : (
|
||||||
|
<div className="my-4">
|
||||||
|
{" "}
|
||||||
|
<span className="text-secondary">No Requests Found !</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{!loading && totalPages > 1 && (
|
{!loading && totalPages > 1 && (
|
||||||
<nav aria-label="Page ">
|
<nav aria-label="Page ">
|
||||||
<ul className="pagination pagination-sm justify-content-end py-1 mt-3">
|
<ul className="pagination pagination-sm justify-content-end py-1 mt-3">
|
||||||
@ -154,15 +155,22 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
|||||||
{[...Array(totalPages)].map((_, index) => (
|
{[...Array(totalPages)].map((_, index) => (
|
||||||
<li
|
<li
|
||||||
key={index}
|
key={index}
|
||||||
className={`page-item ${currentPage === index + 1 ? "active" : ""}`}
|
className={`page-item ${
|
||||||
|
currentPage === index + 1 ? "active" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
className="page-link "
|
||||||
|
onClick={() => paginate(index + 1)}
|
||||||
>
|
>
|
||||||
<button className="page-link" onClick={() => paginate(index + 1)}>
|
|
||||||
{index + 1}
|
{index + 1}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${currentPage === totalPages ? "disabled" : ""}`}
|
className={`page-item ${
|
||||||
|
currentPage === totalPages ? "disabled" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link "
|
className="page-link "
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { useDashboardTasksCardData } from "../../hooks/useDashboard_Data";
|
|||||||
const TasksCard = () => {
|
const TasksCard = () => {
|
||||||
const projectId = useSelector((store) => store.localVariables?.projectId);
|
const projectId = useSelector((store) => store.localVariables?.projectId);
|
||||||
const { tasksCardData, loading, error } = useDashboardTasksCardData(projectId);
|
const { tasksCardData, loading, error } = useDashboardTasksCardData(projectId);
|
||||||
|
console.log(tasksCardData);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="card p-3 h-100 text-center d-flex justify-content-between">
|
<div className="card p-3 h-100 text-center d-flex justify-content-between">
|
||||||
|
|||||||
@ -107,13 +107,13 @@ const CardViewDirectory = ({
|
|||||||
{/* <li className="list-inline-item me-1 small">
|
{/* <li className="list-inline-item me-1 small">
|
||||||
<i className="fa-solid fa-briefcase me-2"></i>
|
<i className="fa-solid fa-briefcase me-2"></i>
|
||||||
</li> */}
|
</li> */}
|
||||||
<li className="list-inline-item text-break small px-1 ms-5">
|
<li className="list-inline-item text-break small ms-5">
|
||||||
{contact.organization}
|
{contact.organization}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={`card-footer text-start px-9 py-1 ${IsActive && "cursor-pointer"
|
className={`card-footer text-start px-1 py-1 ${IsActive && "cursor-pointer"
|
||||||
}`}
|
}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (IsActive) {
|
if (IsActive) {
|
||||||
@ -123,16 +123,6 @@ const CardViewDirectory = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<hr className="my-0" />
|
<hr className="my-0" />
|
||||||
{contact.designation && (
|
|
||||||
<ul className="list-unstyled my-1 d-flex align-items-start ms-2">
|
|
||||||
<li className="me-2">
|
|
||||||
<i class="fa-solid fa-id-badge ms-1"></i>
|
|
||||||
</li>
|
|
||||||
<li className="flex-grow-1 text-break small">
|
|
||||||
{contact.designation}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
)}
|
|
||||||
{contact.contactEmails[0] && (
|
{contact.contactEmails[0] && (
|
||||||
<ul className="list-unstyled my-1 d-flex align-items-start ms-2">
|
<ul className="list-unstyled my-1 d-flex align-items-start ms-2">
|
||||||
<li className="me-2">
|
<li className="me-2">
|
||||||
|
|||||||
@ -6,7 +6,6 @@ export const ContactSchema = z
|
|||||||
contactCategoryId: z.string().nullable().optional(),
|
contactCategoryId: z.string().nullable().optional(),
|
||||||
address: z.string().optional(),
|
address: z.string().optional(),
|
||||||
description: z.string().min(1, { message: "Description is required" }),
|
description: z.string().min(1, { message: "Description is required" }),
|
||||||
designation: z.string().min(1, {message:"Designation is requried"}),
|
|
||||||
projectIds: z.array(z.string()).nullable().optional(), // min(1, "Project is required")
|
projectIds: z.array(z.string()).nullable().optional(), // min(1, "Project is required")
|
||||||
contactEmails: z
|
contactEmails: z
|
||||||
.array(
|
.array(
|
||||||
|
|||||||
@ -15,10 +15,6 @@ const ListViewDirectory = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { dirActions, setDirActions } = useDir();
|
const { dirActions, setDirActions } = useDir();
|
||||||
|
|
||||||
// Get the first email and phone number if they exist
|
|
||||||
const firstEmail = contact.contactEmails?.[0];
|
|
||||||
const firstPhone = contact.contactPhones?.[0];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr className={!IsActive ? "bg-light" : ""}>
|
<tr className={!IsActive ? "bg-light" : ""}>
|
||||||
<td
|
<td
|
||||||
@ -51,38 +47,36 @@ const ListViewDirectory = ({
|
|||||||
|
|
||||||
<td className="px-2" style={{ width: "20%" }}>
|
<td className="px-2" style={{ width: "20%" }}>
|
||||||
<div className="d-flex flex-column align-items-start text-truncate">
|
<div className="d-flex flex-column align-items-start text-truncate">
|
||||||
{firstEmail ? (
|
{contact.contactEmails.length > 0 ? (contact.contactEmails?.map((email, index) => (
|
||||||
<span key={firstEmail.id} className="text-truncate">
|
<span key={email.id} className="text-truncate">
|
||||||
<i
|
<i
|
||||||
className={getEmailIcon(firstEmail.label)}
|
className={getEmailIcon(email.label)}
|
||||||
style={{ fontSize: "12px" }}
|
style={{ fontSize: "12px" }}
|
||||||
></i>
|
></i>
|
||||||
<a
|
<a
|
||||||
href={`mailto:${firstEmail.emailAddress}`}
|
href={`mailto:${email.emailAddress}`}
|
||||||
className="text-decoration-none ms-1"
|
className="text-decoration-none ms-1"
|
||||||
>
|
>
|
||||||
{firstEmail.emailAddress}
|
{email.emailAddress}
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
) : (
|
))):(<span className="small-text m-0 px-2">NA</span>)}
|
||||||
<span className="small-text m-0 px-2">NA</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td className="px-2" style={{ width: "20%" }}>
|
<td className="px-2" style={{ width: "20%" }}>
|
||||||
<div className="d-flex flex-column align-items-start text-truncate">
|
<div className="d-flex flex-column align-items-start text-truncate">
|
||||||
{firstPhone ? (
|
{contact.contactPhones?.length > 0 ? (
|
||||||
<span key={firstPhone.id}>
|
contact.contactPhones?.map((phone, index) => (
|
||||||
|
<span key={phone.id}>
|
||||||
<i
|
<i
|
||||||
className={getPhoneIcon(firstPhone.label)}
|
className={getPhoneIcon(phone.label)}
|
||||||
style={{ fontSize: "12px" }}
|
style={{ fontSize: "12px" }}
|
||||||
></i>
|
></i>
|
||||||
<span className="ms-1">{firstPhone.phoneNumber}</span>
|
<span className="ms-1">{phone.phoneNumber}</span>
|
||||||
</span>
|
</span>
|
||||||
) : (
|
))
|
||||||
<span className="text-small m-0 px-2">NA</span>
|
):(<span className="text-small m-0 px-2">NA</span>)}
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
@ -94,6 +88,12 @@ const ListViewDirectory = ({
|
|||||||
{contact.organization}
|
{contact.organization}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
{/* <td className="px-2" style={{ width: "10%" }}>
|
||||||
|
<span className="badge badge-outline-secondary">
|
||||||
|
{contact?.contactCategory?.name || "Other"}
|
||||||
|
</span>
|
||||||
|
</td> */}
|
||||||
|
|
||||||
<td className="px-2" style={{ width: "10%" }}>
|
<td className="px-2" style={{ width: "10%" }}>
|
||||||
<span className="text-truncate">
|
<span className="text-truncate">
|
||||||
{contact?.contactCategory?.name || "Other"}
|
{contact?.contactCategory?.name || "Other"}
|
||||||
@ -119,8 +119,7 @@ const ListViewDirectory = ({
|
|||||||
{!IsActive && (
|
{!IsActive && (
|
||||||
<i
|
<i
|
||||||
className={`bx ${
|
className={`bx ${
|
||||||
dirActions.action && dirActions.id === contact.id
|
dirActions.action && dirActions.id === contact.id ? "bx-loader-alt bx-spin"
|
||||||
? "bx-loader-alt bx-spin"
|
|
||||||
: "bx-recycle"
|
: "bx-recycle"
|
||||||
} me-1 text-primary cursor-pointer`}
|
} me-1 text-primary cursor-pointer`}
|
||||||
title="Restore"
|
title="Restore"
|
||||||
|
|||||||
@ -14,11 +14,7 @@ import useMaster, {
|
|||||||
} from "../../hooks/masterHook/useMaster";
|
} from "../../hooks/masterHook/useMaster";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { changeMaster } from "../../slices/localVariablesSlice";
|
import { changeMaster } from "../../slices/localVariablesSlice";
|
||||||
import {
|
import { useBuckets, useOrganization } from "../../hooks/useDirectory";
|
||||||
useBuckets,
|
|
||||||
useDesignation,
|
|
||||||
useOrganization,
|
|
||||||
} from "../../hooks/useDirectory";
|
|
||||||
import { useProjects } from "../../hooks/useProjects";
|
import { useProjects } from "../../hooks/useProjects";
|
||||||
import SelectMultiple from "../common/SelectMultiple";
|
import SelectMultiple from "../common/SelectMultiple";
|
||||||
import { ContactSchema } from "./DirectorySchema";
|
import { ContactSchema } from "./DirectorySchema";
|
||||||
@ -37,11 +33,8 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
|
|||||||
const { contactCategory, loading: contactCategoryLoading } =
|
const { contactCategory, loading: contactCategoryLoading } =
|
||||||
useContactCategory();
|
useContactCategory();
|
||||||
const { organizationList, loading: orgLoading } = useOrganization();
|
const { organizationList, loading: orgLoading } = useOrganization();
|
||||||
const { designationList, loading: designloading } = useDesignation();
|
|
||||||
const { contactTags, loading: Tagloading } = useContactTags();
|
const { contactTags, loading: Tagloading } = useContactTags();
|
||||||
const [IsSubmitting, setSubmitting] = useState(false);
|
const [IsSubmitting, setSubmitting] = useState(false);
|
||||||
const [showSuggestions,setShowSuggestions] = useState(false);
|
|
||||||
const [filteredDesignationList, setFilteredDesignationList] = useState([]);
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const methods = useForm({
|
const methods = useForm({
|
||||||
@ -52,7 +45,6 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
|
|||||||
contactCategoryId: null,
|
contactCategoryId: null,
|
||||||
address: "",
|
address: "",
|
||||||
description: "",
|
description: "",
|
||||||
designation: "",
|
|
||||||
projectIds: [],
|
projectIds: [],
|
||||||
contactEmails: [],
|
contactEmails: [],
|
||||||
contactPhones: [],
|
contactPhones: [],
|
||||||
@ -114,25 +106,6 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
|
|||||||
|
|
||||||
const watchBucketIds = watch("bucketIds");
|
const watchBucketIds = watch("bucketIds");
|
||||||
|
|
||||||
// handle logic when input of desgination is changed
|
|
||||||
const handleDesignationChange = (e) => {
|
|
||||||
const val = e.target.value;
|
|
||||||
|
|
||||||
const matches = designationList.filter((org) =>
|
|
||||||
org.toLowerCase().includes(val.toLowerCase())
|
|
||||||
);
|
|
||||||
setFilteredDesignationList(matches);
|
|
||||||
setShowSuggestions(true);
|
|
||||||
setTimeout(() => setShowSuggestions(false), 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
// handle logic when designation is selected
|
|
||||||
const handleSelectDesignation = (val) => {
|
|
||||||
setShowSuggestions(false);
|
|
||||||
setValue("designation", val);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const toggleBucketId = (id) => {
|
const toggleBucketId = (id) => {
|
||||||
const updated = watchBucketIds?.includes(id)
|
const updated = watchBucketIds?.includes(id)
|
||||||
? watchBucketIds.filter((val) => val !== id)
|
? watchBucketIds.filter((val) => val !== id)
|
||||||
@ -195,55 +168,6 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="row mt-1">
|
|
||||||
<div className="col-md-6 text-start">
|
|
||||||
<label className="form-label">Designation</label>
|
|
||||||
<input
|
|
||||||
className="form-control form-control-sm"
|
|
||||||
{...register("designation")}
|
|
||||||
onChange={handleDesignationChange}
|
|
||||||
/>
|
|
||||||
{showSuggestions && filteredDesignationList.length > 0 && (
|
|
||||||
<ul
|
|
||||||
className="list-group shadow-sm position-absolute bg-white border w-50 zindex-tooltip"
|
|
||||||
style={{
|
|
||||||
maxHeight: "180px",
|
|
||||||
overflowY: "auto",
|
|
||||||
marginTop: "2px",
|
|
||||||
zIndex: 1000,
|
|
||||||
borderRadius: "0px",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{filteredDesignationList.map((designation) => (
|
|
||||||
<li
|
|
||||||
key={designation}
|
|
||||||
className="list-group-item list-group-item-action border-none "
|
|
||||||
style={{
|
|
||||||
cursor: "pointer",
|
|
||||||
padding: "5px 12px",
|
|
||||||
fontSize: "14px",
|
|
||||||
transition: "background-color 0.2s",
|
|
||||||
}}
|
|
||||||
onMouseDown={() => handleSelectDesignation(designation)}
|
|
||||||
onMouseEnter={(e) =>
|
|
||||||
(e.currentTarget.style.backgroundColor = "#f8f9fa")
|
|
||||||
}
|
|
||||||
onMouseLeave={(e) =>
|
|
||||||
(e.currentTarget.style.backgroundColor = "transparent")
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{designation}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
)}
|
|
||||||
{errors.designation && (
|
|
||||||
<small className="danger-text">
|
|
||||||
{errors.designation.message}
|
|
||||||
</small>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="row mt-1">
|
<div className="row mt-1">
|
||||||
<div className="col-md-6">
|
<div className="col-md-6">
|
||||||
{emailFields.map((field, index) => (
|
{emailFields.map((field, index) => (
|
||||||
@ -457,6 +381,7 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
{errors.bucketIds && (
|
{errors.bucketIds && (
|
||||||
<small className="danger-text mt-0">
|
<small className="danger-text mt-0">
|
||||||
|
|||||||
@ -153,7 +153,7 @@ const NoteCardDirectoryEditable = ({
|
|||||||
.utc(noteItem?.createdAt)
|
.utc(noteItem?.createdAt)
|
||||||
.add(5, "hours")
|
.add(5, "hours")
|
||||||
.add(30, "minutes")
|
.add(30, "minutes")
|
||||||
.format("DD MMMM, YYYY [at] hh:mm A")}
|
.format("MMMM DD, YYYY [at] hh:mm A")}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import Avatar from "../common/Avatar";
|
|||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { showText } from "pdf-lib";
|
||||||
import { DirectoryRepository } from "../../repositories/DirectoryRepository";
|
import { DirectoryRepository } from "../../repositories/DirectoryRepository";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { cacheData, getCachedData } from "../../slices/apiDataManager";
|
import { cacheData, getCachedData } from "../../slices/apiDataManager";
|
||||||
@ -18,17 +19,15 @@ const schema = z.object({
|
|||||||
const NotesDirectory = ({
|
const NotesDirectory = ({
|
||||||
refetchProfile,
|
refetchProfile,
|
||||||
isLoading,
|
isLoading,
|
||||||
contactProfile, // This contactProfile now reliably includes firstName, middleName, lastName, and fullName
|
contactProfile,
|
||||||
setProfileContact,
|
setProfileContact,
|
||||||
}) => {
|
}) => {
|
||||||
const [IsActive, setIsActive] = useState(true);
|
const [IsActive, setIsActive] = useState(true);
|
||||||
const { contactNotes, refetch } = useContactNotes(
|
const { contactNotes, refetch } = useContactNotes(contactProfile?.id, true);
|
||||||
contactProfile?.id,
|
|
||||||
IsActive
|
|
||||||
);
|
|
||||||
|
|
||||||
|
const [NotesData, setNotesData] = useState();
|
||||||
const [IsSubmitting, setIsSubmitting] = useState(false);
|
const [IsSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [showEditor, setShowEditor] = useState(false);
|
const [addNote, setAddNote] = useState(true);
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -68,78 +67,61 @@ const NotesDirectory = ({
|
|||||||
) {
|
) {
|
||||||
const updatedProfile = {
|
const updatedProfile = {
|
||||||
...cached_contactProfile.data,
|
...cached_contactProfile.data,
|
||||||
notes: [...(cached_contactProfile.data.notes || []), createdNote],
|
notes: [...(cached_contactProfile.notes || []), createdNote],
|
||||||
};
|
};
|
||||||
cacheData("Contact Profile", {
|
cacheData("Contact Profile", updatedProfile);
|
||||||
contactId: contactProfile?.id,
|
|
||||||
data: updatedProfile,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue("note", "");
|
setValue("note", "");
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
showToast("Note added successfully!", "success");
|
showToast("Note added successfully!", "success");
|
||||||
setShowEditor(false);
|
setAddNote(true);
|
||||||
setIsActive(true);
|
setIsActive(true);
|
||||||
refetch(contactProfile?.id, true);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
const msg =
|
const msg =
|
||||||
error.response?.data?.message ||
|
error.response.data.message ||
|
||||||
error.message ||
|
error.message ||
|
||||||
"Error occurred during API calling";
|
"Error occured during API calling";
|
||||||
showToast(msg, "error");
|
showToast(msg, "error");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCancel = () => {
|
const onCancel = () => {
|
||||||
setValue( "note", "" );
|
setValue( "note", "" );
|
||||||
setShowEditor(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
};
|
||||||
const handleSwitch = () => {
|
const handleSwitch = () => {
|
||||||
setIsActive((prevIsActive) => {
|
setIsActive(!IsActive);
|
||||||
const newState = !prevIsActive;
|
if (IsActive) {
|
||||||
refetch(contactProfile?.id, newState);
|
refetch(contactProfile?.id, false);
|
||||||
return newState;
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Use the fullName from contactProfile, which now includes middle and last names if available
|
|
||||||
const contactName =
|
|
||||||
contactProfile?.fullName || contactProfile?.firstName || "Contact";
|
|
||||||
const noNotesMessage = `Be the first to share your insights! ${contactName} currently has no notes.`;
|
|
||||||
|
|
||||||
const notesToDisplay = IsActive
|
|
||||||
? contactProfile?.notes || []
|
|
||||||
: contactNotes || [];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="text-start mt-10">
|
<div className="text-start">
|
||||||
<div className="d-flex align-items-center justify-content-between">
|
<div className="d-flex align-items-center justify-content-between">
|
||||||
<div className="row w-100 align-items-center">
|
<p className="fw-semibold m-0">Notes :</p>
|
||||||
<div className="col col-2">
|
|
||||||
<p className="fw-semibold m-0 ms-3">Notes :</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="col d-flex justify-content-end gap-2 pe-0">
|
<div className="d-flex align-items-center justify-content-between mb-5">
|
||||||
{" "}
|
<div className="m-0 d-flex align-items-center">
|
||||||
<div className="d-flex align-items-center justify-content-between">
|
{contactNotes?.length > 0 ? (
|
||||||
<label
|
<label className="switch switch-primary">
|
||||||
className="switch switch-primary"
|
|
||||||
style={{
|
|
||||||
visibility:
|
|
||||||
contactProfile?.notes?.length > 0 ||
|
|
||||||
contactNotes?.length > 0
|
|
||||||
? "visible"
|
|
||||||
: "hidden",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="switch-input"
|
className="switch-input"
|
||||||
onChange={() => handleSwitch(!IsActive)}
|
onChange={() => handleSwitch(!IsActive)}
|
||||||
value={IsActive}
|
value={IsActive}
|
||||||
/>
|
/>
|
||||||
|
<span className="switch-toggle-slider">
|
||||||
|
<span className="switch-on"></span>
|
||||||
|
<span className="switch-off"></span>
|
||||||
|
</span>
|
||||||
|
<span className="switch-label">Include Deleted Notes</span>
|
||||||
|
</label>
|
||||||
|
) : (
|
||||||
|
<div style={{ visibility: "hidden" }}>
|
||||||
|
<label className="switch switch-primary">
|
||||||
<input type="checkbox" className="switch-input" />
|
<input type="checkbox" className="switch-input" />
|
||||||
<span className="switch-toggle-slider">
|
<span className="switch-toggle-slider">
|
||||||
<span className="switch-on"></span>
|
<span className="switch-on"></span>
|
||||||
@ -147,43 +129,40 @@ const NotesDirectory = ({
|
|||||||
</span>
|
</span>
|
||||||
<span className="switch-label">Include Deleted Notes</span>
|
<span className="switch-label">Include Deleted Notes</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
{!showEditor && (
|
|
||||||
<div className="d-flex justify-content-end">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="btn btn-sm d-flex align-items-center"
|
|
||||||
onClick={() => setShowEditor(true)}
|
|
||||||
style={{
|
|
||||||
color: "#6c757d",
|
|
||||||
backgroundColor: "transparent",
|
|
||||||
boxShadow: "none",
|
|
||||||
border: "none",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<i
|
|
||||||
className="bx bx-plus-circle me-0 text-primary"
|
|
||||||
style={{ fontSize: "1.5rem", color: "#6c757d" }}
|
|
||||||
></i>
|
|
||||||
Add a Note
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
<div className="d-flex justify-content-end">
|
||||||
|
<span
|
||||||
|
className={`btn btn-sm ${addNote ? "btn-secondary" : "btn-primary"}`}
|
||||||
|
onClick={() => setAddNote(!addNote)}
|
||||||
|
>
|
||||||
|
{addNote ? "Hide Editor" : "Add a Note"}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{showEditor && (
|
|
||||||
<div className="card m-2 mb-5 position-relative">
|
{addNote && (
|
||||||
<span
|
<div className="card m-2 mb-5">
|
||||||
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="position-absolute top-0 end-0 mt-3 bg-secondary rounded-circle"
|
class="btn btn-close btn-secondary position-absolute top-0 end-0 m-2 mt-3 rounded-circle"
|
||||||
aria-label="Close"
|
aria-label="Close"
|
||||||
onClick={() => setShowEditor(false)}
|
style={{ backgroundColor: "#eee", color: "white" }}
|
||||||
|
onClick={() => setAddNote(!addNote)}
|
||||||
|
></button>
|
||||||
|
{/* <div className="d-flex justify-content-end px-2">
|
||||||
|
<span
|
||||||
|
className={`btn btn-sm ${
|
||||||
|
addNote ? "btn-danger" : "btn-primary"
|
||||||
|
}`}
|
||||||
|
onClick={() => setAddNote(!addNote)}
|
||||||
>
|
>
|
||||||
<i className="bx bx-x fs-5 p-1 text-white"></i>
|
{addNote ? "Hide Editor" : "Add Note"}
|
||||||
</span>
|
</span>
|
||||||
|
</div> */}
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<Editor
|
<Editor
|
||||||
value={noteValue}
|
value={noteValue}
|
||||||
@ -192,7 +171,7 @@ const NotesDirectory = ({
|
|||||||
onCancel={onCancel}
|
onCancel={onCancel}
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
/>
|
/>
|
||||||
{errors.note && (
|
{errors.notes && (
|
||||||
<p className="text-danger small mt-1">{errors.note.message}</p>
|
<p className="text-danger small mt-1">{errors.note.message}</p>
|
||||||
)}
|
)}
|
||||||
</form>
|
</form>
|
||||||
@ -206,9 +185,8 @@ const NotesDirectory = ({
|
|||||||
<p>Loading...</p>{" "}
|
<p>Loading...</p>{" "}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!isLoading && notesToDisplay.length > 0
|
{!isLoading &&
|
||||||
? notesToDisplay
|
[...(IsActive ? contactProfile?.notes || [] : contactNotes || [])]
|
||||||
.slice()
|
|
||||||
.reverse()
|
.reverse()
|
||||||
.map((noteItem) => (
|
.map((noteItem) => (
|
||||||
<NoteCardDirectory
|
<NoteCardDirectory
|
||||||
@ -220,10 +198,21 @@ const NotesDirectory = ({
|
|||||||
setProfileContact={setProfileContact}
|
setProfileContact={setProfileContact}
|
||||||
key={noteItem.id}
|
key={noteItem.id}
|
||||||
/>
|
/>
|
||||||
))
|
))}
|
||||||
: !isLoading &&
|
|
||||||
!showEditor && (
|
{IsActive && (
|
||||||
<div className="text-center mt-5">{noNotesMessage}</div>
|
<div>
|
||||||
|
{!isLoading && contactProfile?.notes.length == 0 && !addNote && (
|
||||||
|
<div className="text-center mt-5">No Notes Found</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{!IsActive && (
|
||||||
|
<div>
|
||||||
|
{!isLoading && contactNotes.length == 0 && !addNote && (
|
||||||
|
<div className="text-center mt-5">No Notes Found</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -8,10 +8,9 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
const { contactProfile, loading, refetch } = useContactProfile(contact?.id);
|
const { contactProfile, loading, refetch } = useContactProfile(contact?.id);
|
||||||
const [copiedIndex, setCopiedIndex] = useState(null);
|
const [copiedIndex, setCopiedIndex] = useState(null);
|
||||||
|
|
||||||
const [profileContactState, setProfileContactState] = useState(null);
|
const [profileContact, setProfileContact] = useState();
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
|
const description = contactProfile?.description || "";
|
||||||
const description = profileContactState?.description || "";
|
|
||||||
const limit = 500;
|
const limit = 500;
|
||||||
|
|
||||||
const toggleReadMore = () => setExpanded(!expanded);
|
const toggleReadMore = () => setExpanded(!expanded);
|
||||||
@ -20,51 +19,14 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
const displayText = expanded
|
const displayText = expanded
|
||||||
? description
|
? description
|
||||||
: description.slice(0, limit) + (isLong ? "..." : "");
|
: description.slice(0, limit) + (isLong ? "..." : "");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (contactProfile) {
|
setProfileContact(contactProfile);
|
||||||
const names = (contact?.name || "").trim().split(" ");
|
}, [contactProfile]);
|
||||||
let firstName = "";
|
|
||||||
let middleName = "";
|
|
||||||
let lastName = "";
|
|
||||||
let fullName = contact?.name || "";
|
|
||||||
|
|
||||||
// Logic to determine first, middle, and last names
|
|
||||||
if (names.length === 1) {
|
|
||||||
firstName = names[0];
|
|
||||||
} else if (names.length === 2) {
|
|
||||||
firstName = names[0];
|
|
||||||
lastName = names[1];
|
|
||||||
} else if (names.length >= 3) {
|
|
||||||
firstName = names[0];
|
|
||||||
middleName = names[1]; // This was an error in the original prompt, corrected to names[1]
|
|
||||||
lastName = names[names.length - 1];
|
|
||||||
// Reconstruct full name to be precise with spacing
|
|
||||||
fullName = `${firstName} ${middleName ? middleName + ' ' : ''}${lastName}`;
|
|
||||||
} else {
|
|
||||||
// Fallback if no names or empty string
|
|
||||||
firstName = "Contact";
|
|
||||||
fullName = "Contact";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
setProfileContactState({
|
|
||||||
...contactProfile,
|
|
||||||
firstName: contactProfile.firstName || firstName,
|
|
||||||
// Adding middleName and lastName to the state for potential future use or more granular access
|
|
||||||
middleName: contactProfile.middleName || middleName,
|
|
||||||
lastName: contactProfile.lastName || lastName,
|
|
||||||
fullName: contactProfile.fullName || fullName, // Prioritize fetched fullName, fallback to derived
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [contactProfile, contact?.name]);
|
|
||||||
|
|
||||||
const handleCopy = (email, index) => {
|
const handleCopy = (email, index) => {
|
||||||
navigator.clipboard.writeText(email);
|
navigator.clipboard.writeText(email);
|
||||||
setCopiedIndex(index);
|
setCopiedIndex(index);
|
||||||
setTimeout(() => setCopiedIndex(null), 2000);
|
setTimeout(() => setCopiedIndex(null), 2000); // Reset after 2 seconds
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-1">
|
<div className="p-1">
|
||||||
<div className="text-center m-0 p-0">
|
<div className="text-center m-0 p-0">
|
||||||
@ -85,34 +47,30 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
<div className="d-flex flex-column text-start ms-1">
|
<div className="d-flex flex-column text-start ms-1">
|
||||||
<span className="m-0 fw-semibold">{contact?.name}</span>
|
<span className="m-0 fw-semibold">{contact?.name}</span>
|
||||||
<small className="text-secondary small-text">
|
<small className="text-secondary small-text">
|
||||||
{profileContactState?.designation}
|
{contactProfile?.tags?.map((tag) => tag.name).join(" | ")}
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="row ms-9">
|
<div className="row">
|
||||||
<div className="col-12 col-md-6 d-flex flex-column text-start">
|
<div className="col-12 col-md-6 d-flex flex-column text-start">
|
||||||
{profileContactState?.contactEmails?.length > 0 && (
|
{contactProfile?.contactEmails?.length > 0 && (
|
||||||
<div className="d-flex mb-2 align-items-start">
|
<div className="d-flex mb-2">
|
||||||
<div
|
<div style={{ width: "100px", minWidth: "100px" }}>
|
||||||
className="d-flex align-items-start"
|
<p className="m-0">Email:</p>
|
||||||
style={{ width: "100px", minWidth: "130px" }}
|
|
||||||
>
|
|
||||||
<span className="d-flex">
|
|
||||||
<i className="bx bx-envelope bx-xs me-2 mt-1"></i>
|
|
||||||
<span>Email</span>
|
|
||||||
</span>
|
|
||||||
<span style={{ marginLeft: "45px" }}>:</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style={{ flex: 1 }}>
|
<div style={{ flex: 1 }}>
|
||||||
<ul className="list-unstyled mb-0">
|
<ul className="list-unstyled mb-0">
|
||||||
{profileContactState.contactEmails.map((email, idx) => (
|
{contactProfile.contactEmails.map((email, idx) => (
|
||||||
<li className="d-flex align-items-center mb-1" key={idx}>
|
<li className="d-flex align-items-center mb-1" key={idx}>
|
||||||
<span className="me-1 text-break overflow-wrap">
|
<i className="bx bx-envelope bx-xs me-1 mt-1"></i>
|
||||||
|
<span className="me-1 flex-grow text-break overflow-wrap">
|
||||||
{email.emailAddress}
|
{email.emailAddress}
|
||||||
</span>
|
</span>
|
||||||
<i
|
<i
|
||||||
className={`bx bx-copy-alt cursor-pointer bx-xs text-start ${copiedIndex === idx ? "text-secondary" : "text-primary"
|
className={`bx bx-copy-alt cursor-pointer bx-xs text-start ${
|
||||||
|
copiedIndex === idx
|
||||||
|
? "text-secondary"
|
||||||
|
: "text-primary"
|
||||||
}`}
|
}`}
|
||||||
title={copiedIndex === idx ? "Copied!" : "Copy Email"}
|
title={copiedIndex === idx ? "Copied!" : "Copy Email"}
|
||||||
style={{ flexShrink: 0 }}
|
style={{ flexShrink: 0 }}
|
||||||
@ -125,22 +83,17 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{profileContactState?.contactPhones?.length > 0 && (
|
{contactProfile?.contactPhones?.length > 0 && (
|
||||||
<div className="d-flex mb-2 align-items-start">
|
<div className="d-flex mb-2">
|
||||||
<div className="d-flex" style={{ minWidth: "130px" }}>
|
<div style={{ width: "100px", minWidth: "100px" }}>
|
||||||
<span className="d-flex align-items-center">
|
<p className="m-0">Phone : </p>
|
||||||
<i className="bx bx-phone bx-xs me-2"></i>
|
|
||||||
<span>Phone</span>
|
|
||||||
</span>
|
|
||||||
<span style={{ marginLeft: "40px" }}>:</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<ul className="list-inline mb-0">
|
<ul className="list-inline mb-0">
|
||||||
{profileContactState.contactPhones.map((phone, idx) => (
|
{contactProfile?.contactPhones.map((phone, idx) => (
|
||||||
<li className="list-inline-item me-1" key={idx}>
|
<li className="list-inline-item me-3" key={idx}>
|
||||||
|
<i className="bx bx-phone bx-xs me-1"></i>
|
||||||
{phone.phoneNumber}
|
{phone.phoneNumber}
|
||||||
{idx < profileContactState.contactPhones.length - 1 && ","}
|
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
@ -148,93 +101,74 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{profileContactState?.createdAt && (
|
{contactProfile?.createdAt && (
|
||||||
<div className="d-flex mb-2 align-items-start">
|
<div className="d-flex mb-2">
|
||||||
<div className="d-flex" style={{ minWidth: "130px" }}>
|
<div style={{ width: "100px", minWidth: "100px" }}>
|
||||||
<span className="d-flex align-items-center">
|
<p className="m-0">Created : </p>
|
||||||
<i className="bx bx-calendar-week bx-xs me-2"></i>
|
|
||||||
<span>Created</span>
|
|
||||||
</span>
|
|
||||||
<span style={{ marginLeft: "30px" }}>:</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="d-flex align-items-center">
|
<div className="d-flex align-items-center">
|
||||||
<span>
|
<li className="list-inline-item">
|
||||||
{moment(profileContactState.createdAt).format("DD MMMM, YYYY")}
|
<i className="bx bx-calendar-week bx-xs me-1"></i>
|
||||||
</span>
|
{moment(contactProfile.createdAt).format("MMMM, DD YYYY")}
|
||||||
|
</li>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{contactProfile?.address && (
|
||||||
{profileContactState?.address && (
|
<div className="d-flex mb-2">
|
||||||
<div className="d-flex mb-2 align-items-start">
|
<div style={{ width: "100px", minWidth: "100px" }}>
|
||||||
<div className="d-flex" style={{ minWidth: "130px" }}>
|
<p className="m-0">Location:</p>
|
||||||
<span className="d-flex align-items-start">
|
|
||||||
<i className="bx bx-map bx-xs me-2 mt-1"></i>
|
|
||||||
<span>Location</span>
|
|
||||||
</span>
|
|
||||||
<span style={{ marginLeft: "26px" }}>:</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div className="d-flex align-items-center">
|
||||||
<span className="text-break small">{profileContactState.address}</span>
|
<i className="bx bx-map bx-xs me-1 "></i>
|
||||||
|
<span className="text-break small">
|
||||||
|
{contactProfile.address}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-12 col-md-6 d-flex flex-column text-start">
|
<div className="col-12 col-md-6 d-flex flex-column text-start">
|
||||||
{profileContactState?.organization && (
|
{contactProfile?.organization && (
|
||||||
<div className="d-flex mb-2 align-items-start">
|
<div className="d-flex mb-2">
|
||||||
<div className="d-flex" style={{ minWidth: "130px" }}>
|
<div style={{ width: "100px", minWidth: "100px" }}>
|
||||||
<span className="d-flex align-items-center">
|
<p className="m-0">Orgnization : </p>
|
||||||
<i className="fa-solid fa-briefcase me-2"></i>
|
|
||||||
<span>Organization</span>
|
|
||||||
</span>
|
|
||||||
<span className="ms-2">:</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="d-flex align-items-center">
|
<div className="d-flex align-items-center">
|
||||||
|
<i className="fa-solid fa-briefcase me-2"></i>
|
||||||
|
|
||||||
<span style={{ wordBreak: "break-word" }}>
|
<span style={{ wordBreak: "break-word" }}>
|
||||||
{profileContactState.organization}
|
{contactProfile.organization}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{contactProfile?.contactCategory && (
|
||||||
{profileContactState?.contactCategory && (
|
<div className="d-flex mb-2">
|
||||||
<div className="d-flex mb-2 align-items-start">
|
<div style={{ width: "100px", minWidth: "100px" }}>
|
||||||
<div className="d-flex" style={{ minWidth: "130px" }}>
|
<p className="m-0">Category : </p>
|
||||||
<span className="d-flex align-items-center">
|
|
||||||
<i className="bx bx-user bx-xs me-2"></i>
|
|
||||||
<span>Category</span>
|
|
||||||
</span>
|
|
||||||
<span style={{ marginLeft: "28px" }}>:</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<ul className="list-inline mb-0">
|
<ul className="list-inline mb-0">
|
||||||
<li className="list-inline-item">
|
<li className="list-inline-item">
|
||||||
{profileContactState.contactCategory.name}
|
<i className="bx bx-user bx-xs me-1"></i>
|
||||||
|
{contactProfile.contactCategory.name}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{contactProfile?.tags?.length > 0 && (
|
||||||
{profileContactState?.tags?.length > 0 && (
|
<div className="d-flex mb-2">
|
||||||
<div className="d-flex mb-2 align-items-start">
|
<div style={{ width: "100px", minWidth: "100px" }}>
|
||||||
<div className="d-flex" style={{ minWidth: "130px" }}>
|
<p className="m-0">Tags : </p>
|
||||||
<span className="d-flex align-items-center">
|
|
||||||
<i className="fa-solid fa-tag me-2"></i>
|
|
||||||
<span>Tags</span>
|
|
||||||
</span>
|
|
||||||
<span style={{ marginLeft: "60px" }}>:</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<ul className="list-inline mb-0">
|
<ul className="list-inline mb-0">
|
||||||
{profileContactState.tags.map((tag, index) => (
|
{contactProfile.tags.map((tag, index) => (
|
||||||
<li key={index} className="list-inline-item">
|
<li key={index} className="list-inline-item">
|
||||||
|
<i className="fa-solid fa-tag me-1"></i>
|
||||||
{tag.name}
|
{tag.name}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
@ -243,19 +177,16 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{profileContactState?.buckets?.length > 0 && (
|
{contactProfile?.buckets?.length > 0 && (
|
||||||
<div className="d-flex mb-2 align-items-start">
|
<div className="d-flex ">
|
||||||
<div className="d-flex" style={{ minWidth: "130px" }}>
|
{contactProfile?.contactEmails?.length > 0 && (
|
||||||
<span className="d-flex align-items-center">
|
<div className="d-flex mb-2 align-items-center">
|
||||||
<i className="bx bx-layer me-1"></i>
|
<div style={{ width: "100px", minWidth: "100px" }}>
|
||||||
<span>Buckets</span>
|
<p className="m-0">Buckets : </p>
|
||||||
</span>
|
|
||||||
<span style={{ marginLeft: "35px" }}>:</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<ul className="list-inline mb-0">
|
<ul className="list-inline mb-0">
|
||||||
{profileContactState.buckets.map((bucket) => (
|
{contactProfile.buckets.map((bucket) => (
|
||||||
<li className="list-inline-item me-2" key={bucket.id}>
|
<li className="list-inline-item me-2" key={bucket.id}>
|
||||||
<span className="badge bg-label-primary my-1">
|
<span className="badge bg-label-primary my-1">
|
||||||
{bucket.name}
|
{bucket.name}
|
||||||
@ -267,63 +198,50 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
{profileContactState?.projects?.length > 0 && (
|
</div>
|
||||||
<div className="d-flex mb-2 align-items-start">
|
</div>
|
||||||
<div className="d-flex" style={{ minWidth: "130px" }}>
|
{contactProfile?.projects?.length > 0 && (
|
||||||
<span className="d-flex align-items-center">
|
<div className="d-flex mb-2 align-items-start">
|
||||||
<i className="bx bx-building-house me-1"></i>
|
<div style={{ minWidth: "100px" }}>
|
||||||
<span>Projects</span>
|
<p className="m-0 text-start">Projects :</p>
|
||||||
</span>
|
|
||||||
<span style={{ marginLeft: "28px" }}>:</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="text-start">
|
<div className="text-start">
|
||||||
<ul className="list-inline mb-0">
|
<ul className="list-inline mb-0">
|
||||||
{profileContactState.projects.map((project, index) => (
|
{contactProfile.projects.map((project, index) => (
|
||||||
<li className="list-inline-item me-2" key={project.id}>
|
<li className="list-inline-item me-2" key={project.id}>
|
||||||
{project.name}
|
{project.name}
|
||||||
{index < profileContactState.projects.length - 1 && ","}
|
{index < contactProfile.projects.length - 1 && ","}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="d-flex mb-2 align-items-start" style={{ marginLeft: "3rem" }}>
|
<div className="d-flex mb-2 align-items-start">
|
||||||
<div className="d-flex" style={{ minWidth: "130px" }}>
|
<div style={{ minWidth: "100px" }}>
|
||||||
<span className="d-flex align-items-start">
|
<p className="m-0 text-start">Description :</p>
|
||||||
<i className="bx bx-book me-1"></i>
|
|
||||||
<span>Description</span>
|
|
||||||
</span>
|
|
||||||
<span style={{ marginLeft: "10px" }}>:</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="text-start">
|
<div className="text-start">
|
||||||
{displayText}
|
{displayText}
|
||||||
{isLong && (
|
{isLong && (
|
||||||
<>
|
|
||||||
<br />
|
|
||||||
<span
|
<span
|
||||||
onClick={toggleReadMore}
|
onClick={toggleReadMore}
|
||||||
className="text-primary mx-1 cursor-pointer"
|
className="text-primary mx-1 cursor-pointer"
|
||||||
>
|
>
|
||||||
{expanded ? "Read less" : "Read more"}
|
{expanded ? "Read less" : "Read more"}
|
||||||
</span>
|
</span>
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<hr className="my-1" />
|
<hr className="my-1" />
|
||||||
<NotesDirectory
|
<NotesDirectory
|
||||||
refetchProfile={refetch}
|
refetchProfile={refetch}
|
||||||
isLoading={loading}
|
isLoading={loading}
|
||||||
contactProfile={profileContactState}
|
contactProfile={profileContact}
|
||||||
setProfileContact={setProfileContactState}
|
setProfileContact={setProfileContact}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -14,11 +14,7 @@ import useMaster, {
|
|||||||
} from "../../hooks/masterHook/useMaster";
|
} from "../../hooks/masterHook/useMaster";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { changeMaster } from "../../slices/localVariablesSlice";
|
import { changeMaster } from "../../slices/localVariablesSlice";
|
||||||
import {
|
import { useBuckets, useOrganization } from "../../hooks/useDirectory";
|
||||||
useBuckets,
|
|
||||||
useDesignation,
|
|
||||||
useOrganization,
|
|
||||||
} from "../../hooks/useDirectory";
|
|
||||||
import { useProjects } from "../../hooks/useProjects";
|
import { useProjects } from "../../hooks/useProjects";
|
||||||
import SelectMultiple from "../common/SelectMultiple";
|
import SelectMultiple from "../common/SelectMultiple";
|
||||||
import { ContactSchema } from "./DirectorySchema";
|
import { ContactSchema } from "./DirectorySchema";
|
||||||
@ -39,10 +35,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
const [ IsSubmitting, setSubmitting ] = useState( false );
|
const [ IsSubmitting, setSubmitting ] = useState( false );
|
||||||
const [isInitialized, setIsInitialized] = useState(false);
|
const [isInitialized, setIsInitialized] = useState(false);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { organizationList } = useOrganization();
|
const {organizationList} = useOrganization()
|
||||||
const { designationList } = useDesignation();
|
|
||||||
const [showSuggestions, setShowSuggestions] = useState(false);
|
|
||||||
const [filteredDesignationList, setFilteredDesignationList] = useState([]);
|
|
||||||
|
|
||||||
const methods = useForm({
|
const methods = useForm({
|
||||||
resolver: zodResolver(ContactSchema),
|
resolver: zodResolver(ContactSchema),
|
||||||
@ -52,7 +45,6 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
contactCategoryId: null,
|
contactCategoryId: null,
|
||||||
address: "",
|
address: "",
|
||||||
description: "",
|
description: "",
|
||||||
designation: "",
|
|
||||||
projectIds: [],
|
projectIds: [],
|
||||||
contactEmails: [],
|
contactEmails: [],
|
||||||
contactPhones: [],
|
contactPhones: [],
|
||||||
@ -103,24 +95,6 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// handle logic when input of desgination is changed
|
|
||||||
const handleDesignationChange = (e) => {
|
|
||||||
const val = e.target.value;
|
|
||||||
|
|
||||||
const matches = designationList.filter((org) =>
|
|
||||||
org.toLowerCase().includes(val.toLowerCase())
|
|
||||||
);
|
|
||||||
setFilteredDesignationList(matches);
|
|
||||||
setShowSuggestions(true);
|
|
||||||
setTimeout(() => setShowSuggestions(false), 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
// handle logic when designation is selected
|
|
||||||
const handleSelectDesignation = (val) => {
|
|
||||||
setShowSuggestions(false);
|
|
||||||
setValue("designation", val);
|
|
||||||
};
|
|
||||||
|
|
||||||
const watchBucketIds = watch("bucketIds");
|
const watchBucketIds = watch("bucketIds");
|
||||||
|
|
||||||
const toggleBucketId = (id) => {
|
const toggleBucketId = (id) => {
|
||||||
@ -145,13 +119,17 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
.filter((e) => e.emailAddress?.trim() !== "")
|
.filter((e) => e.emailAddress?.trim() !== "")
|
||||||
.map((email, index) => {
|
.map((email, index) => {
|
||||||
const existingEmail = existingContact.contactEmails?.[index];
|
const existingEmail = existingContact.contactEmails?.[index];
|
||||||
return existingEmail ? { ...email, id: existingEmail.id } : email;
|
return existingEmail
|
||||||
|
? { ...email, id: existingEmail.id }
|
||||||
|
: email;
|
||||||
}),
|
}),
|
||||||
contactPhones: (data.contactPhones || [])
|
contactPhones: (data.contactPhones || [])
|
||||||
.filter((p) => p.phoneNumber?.trim() !== "")
|
.filter((p) => p.phoneNumber?.trim() !== "")
|
||||||
.map((phone, index) => {
|
.map((phone, index) => {
|
||||||
const existingPhone = existingContact.contactPhones?.[index];
|
const existingPhone = existingContact.contactPhones?.[index];
|
||||||
return existingPhone ? { ...phone, id: existingPhone.id } : phone;
|
return existingPhone
|
||||||
|
? { ...phone, id: existingPhone.id }
|
||||||
|
: phone;
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -159,8 +137,9 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
await submitContact({ ...cleaned, id: existingContact.id });
|
await submitContact({ ...cleaned, id: existingContact.id });
|
||||||
|
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
|
||||||
};
|
};
|
||||||
const orgValue = watch("organization");
|
const orgValue = watch("organization")
|
||||||
const handleClosed = () => {
|
const handleClosed = () => {
|
||||||
onCLosed();
|
onCLosed();
|
||||||
};
|
};
|
||||||
@ -179,31 +158,25 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
contactCategoryId: existingContact.contactCategory?.id || null,
|
contactCategoryId: existingContact.contactCategory?.id || null,
|
||||||
address: existingContact.address || "",
|
address: existingContact.address || "",
|
||||||
description: existingContact.description || "",
|
description: existingContact.description || "",
|
||||||
designation: existingContact.designation || "",
|
|
||||||
projectIds: existingContact.projectIds || null,
|
projectIds: existingContact.projectIds || null,
|
||||||
tags: existingContact.tags || [],
|
tags: existingContact.tags || [],
|
||||||
bucketIds: existingContact.bucketIds || [],
|
bucketIds: existingContact.bucketIds || [],
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if (
|
if (!existingContact.contactPhones || existingContact.contactPhones.length === 0) {
|
||||||
!existingContact.contactPhones ||
|
|
||||||
existingContact.contactPhones.length === 0
|
|
||||||
) {
|
|
||||||
appendPhone({ label: "Office", phoneNumber: "" });
|
appendPhone({ label: "Office", phoneNumber: "" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!existingContact.contactEmails || existingContact.contactEmails.length === 0) {
|
||||||
!existingContact.contactEmails ||
|
|
||||||
existingContact.contactEmails.length === 0
|
|
||||||
) {
|
|
||||||
appendEmail({ label: "Work", emailAddress: "" });
|
appendEmail({ label: "Work", emailAddress: "" });
|
||||||
}
|
}
|
||||||
setIsInitialized(true);
|
setIsInitialized(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// return()=> reset()
|
// return()=> reset()
|
||||||
}, [ existingContact, buckets, projects ] );
|
}, [ existingContact, buckets, projects ] );
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<form className="p-2 p-sm-0" onSubmit={handleSubmit(onSubmit)}>
|
<form className="p-2 p-sm-0" onSubmit={handleSubmit(onSubmit)}>
|
||||||
@ -222,6 +195,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div className="col-md-6 text-start">
|
<div className="col-md-6 text-start">
|
||||||
<label className="form-label">Organization</label>
|
<label className="form-label">Organization</label>
|
||||||
<InputSuggestions
|
<InputSuggestions
|
||||||
@ -237,55 +211,6 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="row mt-1">
|
|
||||||
<div className="col-md-6 text-start">
|
|
||||||
<label className="form-label">Designation</label>
|
|
||||||
<input
|
|
||||||
className="form-control form-control-sm"
|
|
||||||
{...register("designation")}
|
|
||||||
onChange={handleDesignationChange}
|
|
||||||
/>
|
|
||||||
{showSuggestions && filteredDesignationList.length > 0 && (
|
|
||||||
<ul
|
|
||||||
className="list-group shadow-sm position-absolute w-50 bg-white border zindex-tooltip"
|
|
||||||
style={{
|
|
||||||
maxHeight: "180px",
|
|
||||||
overflowY: "auto",
|
|
||||||
marginTop: "2px",
|
|
||||||
zIndex: 1000,
|
|
||||||
borderRadius: "0px",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{filteredDesignationList.map((designation) => (
|
|
||||||
<li
|
|
||||||
key={designation}
|
|
||||||
className="list-group-item list-group-item-action border-none "
|
|
||||||
style={{
|
|
||||||
cursor: "pointer",
|
|
||||||
padding: "5px 12px",
|
|
||||||
fontSize: "14px",
|
|
||||||
transition: "background-color 0.2s",
|
|
||||||
}}
|
|
||||||
onMouseDown={() => handleSelectDesignation(designation)}
|
|
||||||
onMouseEnter={(e) =>
|
|
||||||
(e.currentTarget.style.backgroundColor = "#f8f9fa")
|
|
||||||
}
|
|
||||||
onMouseLeave={(e) =>
|
|
||||||
(e.currentTarget.style.backgroundColor = "transparent")
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{designation}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
)}
|
|
||||||
{errors.designation && (
|
|
||||||
<small className="danger-text">
|
|
||||||
{errors.designation.message}
|
|
||||||
</small>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="row mt-1">
|
<div className="row mt-1">
|
||||||
<div className="col-md-6">
|
<div className="col-md-6">
|
||||||
{emailFields.map((field, index) => (
|
{emailFields.map((field, index) => (
|
||||||
@ -325,10 +250,8 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
|
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i
|
<i className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary" onClick={handleAddEmail}/>
|
||||||
className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary"
|
|
||||||
onClick={handleAddEmail}
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
// <button
|
// <button
|
||||||
// type="button"
|
// type="button"
|
||||||
@ -336,10 +259,8 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
// onClick={() => removeEmail(index)}
|
// onClick={() => removeEmail(index)}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i
|
<i className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-danger" onClick={() => removeEmail(index)}/>
|
||||||
className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-danger"
|
|
||||||
onClick={() => removeEmail(index)}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{errors.contactEmails?.[index]?.emailAddress && (
|
{errors.contactEmails?.[index]?.emailAddress && (
|
||||||
@ -389,10 +310,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
// onClick={handleAddPhone}
|
// onClick={handleAddPhone}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i
|
<i className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary" onClick={handleAddPhone} />
|
||||||
className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary"
|
|
||||||
onClick={handleAddPhone}
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
// <button
|
// <button
|
||||||
// type="button"
|
// type="button"
|
||||||
@ -400,10 +318,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
// onClick={() => removePhone(index)}
|
// onClick={() => removePhone(index)}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i
|
<i className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-danger" onClick={() => removePhone(index)} />
|
||||||
className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-danger"
|
|
||||||
onClick={() => removePhone(index)}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{errors.contactPhones?.[index]?.phoneNumber && (
|
{errors.contactPhones?.[index]?.phoneNumber && (
|
||||||
@ -530,11 +445,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="d-flex justify-content-center gap-1 py-2">
|
<div className="d-flex justify-content-center gap-1 py-2">
|
||||||
<button
|
<button className="btn btn-sm btn-primary" type="submit" disabled={IsSubmitting}>
|
||||||
className="btn btn-sm btn-primary"
|
|
||||||
type="submit"
|
|
||||||
disabled={IsSubmitting}
|
|
||||||
>
|
|
||||||
{IsSubmitting ? "Please Wait..." : "Update"}
|
{IsSubmitting ? "Please Wait..." : "Update"}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@ -469,7 +469,7 @@ const { mutate: updateEmployee, isPending } = useUpdateEmployee();
|
|||||||
</div>
|
</div>
|
||||||
<div className="row mb-3">
|
<div className="row mb-3">
|
||||||
<div className="col-sm-4">
|
<div className="col-sm-4">
|
||||||
<div className="form-text text-start">Official Designation</div>
|
<div className="form-text text-start">Role</div>
|
||||||
<div className="input-group input-group-merge ">
|
<div className="input-group input-group-merge ">
|
||||||
<select
|
<select
|
||||||
className="form-select form-select-sm"
|
className="form-select form-select-sm"
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
import getGreetingMessage from "../../utils/greetingHandler";
|
import getGreetingMessage from "../../utils/greetingHandler";
|
||||||
import {
|
import {
|
||||||
cacheData,
|
cacheData,
|
||||||
clearAllCache,
|
clearAllCache,
|
||||||
getCachedData,
|
getCachedData,
|
||||||
useSelectedproject,
|
|
||||||
} from "../../slices/apiDataManager";
|
} from "../../slices/apiDataManager";
|
||||||
import AuthRepository from "../../repositories/AuthRepository";
|
import AuthRepository from "../../repositories/AuthRepository";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
@ -30,15 +30,7 @@ const Header = () => {
|
|||||||
|
|
||||||
const isDirectoryPath = /^\/directory$/.test(location.pathname);
|
const isDirectoryPath = /^\/directory$/.test(location.pathname);
|
||||||
const isProjectPath = /^\/projects$/.test(location.pathname);
|
const isProjectPath = /^\/projects$/.test(location.pathname);
|
||||||
const isDashboard =
|
const isDashboard = /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname) ;
|
||||||
/^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname);
|
|
||||||
|
|
||||||
const allowedProjectStatusIds = [
|
|
||||||
"603e994b-a27f-4e5d-a251-f3d69b0498ba",
|
|
||||||
"cdad86aa-8a56-4ff4-b633-9c629057dfef",
|
|
||||||
"b74da4c2-d07e-46f2-9919-e75e49b12731",
|
|
||||||
];
|
|
||||||
|
|
||||||
const getRole = (roles, joRoleId) => {
|
const getRole = (roles, joRoleId) => {
|
||||||
if (!Array.isArray(roles)) return "User";
|
if (!Array.isArray(roles)) return "User";
|
||||||
let role = roles.find((role) => role.id === joRoleId);
|
let role = roles.find((role) => role.id === joRoleId);
|
||||||
@ -57,7 +49,7 @@ const Header = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
AuthRepository.logout(data)
|
AuthRepository.logout(data)
|
||||||
.then(() => {
|
.then((response) => {
|
||||||
localStorage.removeItem("jwtToken");
|
localStorage.removeItem("jwtToken");
|
||||||
localStorage.removeItem("refreshToken");
|
localStorage.removeItem("refreshToken");
|
||||||
localStorage.removeItem("user");
|
localStorage.removeItem("user");
|
||||||
@ -65,11 +57,11 @@ const Header = () => {
|
|||||||
clearAllCache();
|
clearAllCache();
|
||||||
window.location.href = "/auth/login";
|
window.location.href = "/auth/login";
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((error) => {
|
||||||
|
// Even if logout API fails, clear local storage and redirect
|
||||||
localStorage.removeItem("jwtToken");
|
localStorage.removeItem("jwtToken");
|
||||||
localStorage.removeItem("refreshToken");
|
localStorage.removeItem("refreshToken");
|
||||||
localStorage.removeItem("user");
|
localStorage.removeItem("user");
|
||||||
localStorage.clear();
|
|
||||||
clearAllCache();
|
clearAllCache();
|
||||||
window.location.href = "/auth/login";
|
window.location.href = "/auth/login";
|
||||||
});
|
});
|
||||||
@ -87,30 +79,22 @@ const Header = () => {
|
|||||||
|
|
||||||
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
||||||
|
|
||||||
const selectedProject = useSelectedproject();
|
const selectedProject = useSelector(
|
||||||
|
(store) => store.localVariables.projectId
|
||||||
const projectsForDropdown = isDashboard
|
|
||||||
? projectNames
|
|
||||||
: projectNames?.filter(project =>
|
|
||||||
allowedProjectStatusIds.includes(project.projectStatusId)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let currentProjectDisplayName;
|
// Determine the display text for the project dropdown
|
||||||
if (projectLoading) {
|
let displayText = "All Projects";
|
||||||
currentProjectDisplayName = "Loading...";
|
|
||||||
} else if (!projectNames || projectNames.length === 0) {
|
|
||||||
currentProjectDisplayName = "No Projects Assigned";
|
|
||||||
} else if (projectNames.length === 1) {
|
|
||||||
currentProjectDisplayName = projectNames[0].name;
|
|
||||||
} else {
|
|
||||||
if (selectedProject === null) {
|
if (selectedProject === null) {
|
||||||
currentProjectDisplayName = "All Projects";
|
displayText = "All Projects";
|
||||||
} else {
|
} else if (selectedProject) {
|
||||||
const selectedProjectObj = projectNames.find(
|
const selectedProjectObj = projectNames?.find(
|
||||||
(p) => p?.id === selectedProject
|
(p) => p?.id === selectedProject
|
||||||
);
|
);
|
||||||
currentProjectDisplayName = selectedProjectObj ? selectedProjectObj.name : "All Projects";
|
// Fallback to selectedProject ID if name not found during loading or mismatch
|
||||||
}
|
displayText = selectedProjectObj ? selectedProjectObj.name : selectedProject;
|
||||||
|
} else if (projectLoading) {
|
||||||
|
displayText = "Loading...";
|
||||||
}
|
}
|
||||||
|
|
||||||
const { openChangePassword } = useChangePassword();
|
const { openChangePassword } = useChangePassword();
|
||||||
@ -122,18 +106,17 @@ const Header = () => {
|
|||||||
selectedProject === undefined &&
|
selectedProject === undefined &&
|
||||||
!getCachedData("hasReceived")
|
!getCachedData("hasReceived")
|
||||||
) {
|
) {
|
||||||
if (projectNames.length === 1) {
|
|
||||||
dispatch(setProjectId(projectNames[0]?.id || null));
|
|
||||||
} else {
|
|
||||||
if(isDashboard){
|
if(isDashboard){
|
||||||
dispatch(setProjectId(null));
|
dispatch(setProjectId(null));
|
||||||
}else{
|
}else{
|
||||||
const firstAllowedProject = projectNames.find(project => allowedProjectStatusIds.includes(project.projectStatusId));
|
dispatch(setProjectId(projectNames[0]?.id));
|
||||||
dispatch(setProjectId(firstAllowedProject?.id || null));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}, [projectNames, selectedProject, dispatch]);
|
||||||
}, [projectNames, selectedProject, dispatch, isDashboard]);
|
|
||||||
|
|
||||||
|
/** Check if current page is project details page or directory page */
|
||||||
|
// const isProjectPath = /^\/projects\/[a-f0-9-]{36}$/.test(location.pathname);
|
||||||
|
|
||||||
|
|
||||||
const handler = useCallback(
|
const handler = useCallback(
|
||||||
@ -178,14 +161,13 @@ const Header = () => {
|
|||||||
}, [handler, newProjectHandler]);
|
}, [handler, newProjectHandler]);
|
||||||
|
|
||||||
const handleProjectChange =(project)=>{
|
const handleProjectChange =(project)=>{
|
||||||
dispatch(setProjectId(project));
|
if(isProjectPath){
|
||||||
|
dispatch(setProjectId(project))
|
||||||
if (isProjectPath && project !== null) {
|
navigate("/projects/details")
|
||||||
navigate("/projects/details");
|
} else{
|
||||||
|
dispatch(setProjectId(project))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const shouldShowDropdown = projectNames && projectNames.length > 1;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav
|
<nav
|
||||||
@ -208,37 +190,33 @@ const Header = () => {
|
|||||||
<div className="align-items-center">
|
<div className="align-items-center">
|
||||||
<i className="rounded-circle bx bx-building-house bx-sm-lg bx-md me-2"></i>
|
<i className="rounded-circle bx bx-building-house bx-sm-lg bx-md me-2"></i>
|
||||||
<div className="btn-group">
|
<div className="btn-group">
|
||||||
{shouldShowDropdown ? (
|
|
||||||
<button
|
<button
|
||||||
className={`btn btn-sm-sm btn-xl dropdown-toggle px-1`}
|
className={`btn btn-sm-sm btn-xl ${projectNames.length > 0 ? "dropdown-toggle" : ""
|
||||||
|
} px-1`}
|
||||||
type="button"
|
type="button"
|
||||||
data-bs-toggle="dropdown"
|
data-bs-toggle="dropdown"
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
>
|
>
|
||||||
{currentProjectDisplayName}
|
{displayText}
|
||||||
</button>
|
</button>
|
||||||
) : (
|
|
||||||
<span className="btn btn-sm-sm btn-xl px-1">
|
|
||||||
{currentProjectDisplayName}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{shouldShowDropdown && projectsForDropdown && projectsForDropdown.length > 0 && (
|
{projectNames.length > 0 && (
|
||||||
<ul
|
<ul
|
||||||
className="dropdown-menu"
|
className="dropdown-menu"
|
||||||
style={{ overflow: "auto", maxHeight: "300px" }}
|
style={{ overflow: "auto", maxHeight: "300px" }}
|
||||||
>
|
>
|
||||||
|
|
||||||
{isDashboard && (
|
{isDashboard && (
|
||||||
<li>
|
<li>
|
||||||
<button
|
<button
|
||||||
className="dropdown-item"
|
className="dropdown-item"
|
||||||
onClick={() => handleProjectChange(null)}
|
onClick={() => dispatch(setProjectId(null))}
|
||||||
>
|
>
|
||||||
All Projects
|
All Projects
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
)}
|
)}
|
||||||
{[...projectsForDropdown]
|
{[...projectNames]
|
||||||
.sort((a, b) => a?.name?.localeCompare(b.name))
|
.sort((a, b) => a?.name?.localeCompare(b.name))
|
||||||
.map((project) => (
|
.map((project) => (
|
||||||
<li key={project?.id}>
|
<li key={project?.id}>
|
||||||
@ -261,6 +239,7 @@ const Header = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
<ul className="navbar-nav flex-row align-items-center ms-md-auto">
|
<ul className="navbar-nav flex-row align-items-center ms-md-auto">
|
||||||
<li className="nav-item dropdown-shortcuts navbar-dropdown dropdown me-2 me-xl-0">
|
<li className="nav-item dropdown-shortcuts navbar-dropdown dropdown me-2 me-xl-0">
|
||||||
<a
|
<a
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import { MANAGE_PROJECT } from "../../utils/constants";
|
|||||||
import GlobalModel from "../common/GlobalModel";
|
import GlobalModel from "../common/GlobalModel";
|
||||||
import ManageProjectInfo from "./ManageProjectInfo";
|
import ManageProjectInfo from "./ManageProjectInfo";
|
||||||
import {useQueryClient} from "@tanstack/react-query";
|
import {useQueryClient} from "@tanstack/react-query";
|
||||||
import { useSelectedproject } from "../../slices/apiDataManager";
|
|
||||||
|
|
||||||
const AboutProject = () => {
|
const AboutProject = () => {
|
||||||
const [IsOpenModal, setIsOpenModal] = useState(false);
|
const [IsOpenModal, setIsOpenModal] = useState(false);
|
||||||
@ -20,8 +19,7 @@ const AboutProject = () => {
|
|||||||
const ClientQuery = useQueryClient();
|
const ClientQuery = useQueryClient();
|
||||||
|
|
||||||
// *** MODIFIED LINE: Get projectId from Redux store using useSelector ***
|
// *** MODIFIED LINE: Get projectId from Redux store using useSelector ***
|
||||||
// const projectId = useSelector((store) => store.localVariables.projectId);
|
const projectId = useSelector((store) => store.localVariables.projectId);
|
||||||
const projectId = useSelectedproject();
|
|
||||||
|
|
||||||
const manageProject = useHasUserPermission(MANAGE_PROJECT);
|
const manageProject = useHasUserPermission(MANAGE_PROJECT);
|
||||||
const {projects_Details, isLoading, error,refetch} = useProjectDetails( projectId ); // Pass projectId from useSelector
|
const {projects_Details, isLoading, error,refetch} = useProjectDetails( projectId ); // Pass projectId from useSelector
|
||||||
@ -53,84 +51,71 @@ const AboutProject = () => {
|
|||||||
<>
|
<>
|
||||||
<div className="card mb-6">
|
<div className="card mb-6">
|
||||||
<div className="card-header text-start">
|
<div className="card-header text-start">
|
||||||
<h6 className="card-action-title mb-0 ps-1">
|
<h6 className="card-action-title mb-0">
|
||||||
{" "}
|
{" "}
|
||||||
<i className="fa fa-building rounded-circle text-primary"></i>
|
<i className="fa fa-building rounded-circle text-primary"></i>
|
||||||
<span className="ms-2">Project Profile</span>
|
<span className="ms-2">Project Profile</span>
|
||||||
</h6>
|
</h6>
|
||||||
</div>
|
</div>
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<ul className="list-unstyled my-3 ps-0">
|
<ul className="list-unstyled my-3 ps-2">
|
||||||
<li className="d-flex mb-3">
|
<li className="d-flex align-items-center mb-3">
|
||||||
<div className="d-flex align-items-center" style={{ width: '120px' }}> {/* Adjust width as needed for alignment */}
|
|
||||||
<i className="bx bx-cog"></i>
|
<i className="bx bx-cog"></i>
|
||||||
<span className="fw-medium mx-2">Name:</span>
|
<span className="fw-medium mx-2">Name:</span>{" "}
|
||||||
</div>
|
|
||||||
<span>{projects_Details.name}</span>
|
<span>{projects_Details.name}</span>
|
||||||
</li>
|
</li>
|
||||||
<li className="d-flex mb-3">
|
<li className="d-flex align-items-center mb-3">
|
||||||
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
|
||||||
<i className="bx bx-fingerprint"></i>
|
<i className="bx bx-fingerprint"></i>
|
||||||
<span className="fw-medium mx-2">Nick Name:</span>
|
<span className="fw-medium mx-2">Nick Name:</span>{" "}
|
||||||
</div>
|
|
||||||
<span> {projects_Details.shortName} </span>
|
<span> {projects_Details.shortName} </span>
|
||||||
</li>
|
</li>
|
||||||
<li className="d-flex mb-3">
|
<li className="d-flex align-items-center mb-3">
|
||||||
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
|
||||||
<i className="bx bx-check"></i>
|
<i className="bx bx-check"></i>
|
||||||
<span className="fw-medium mx-2">Start Date:</span>
|
<span className="fw-medium mx-2">Start Date:</span>{" "}
|
||||||
</div>
|
|
||||||
<span>
|
<span>
|
||||||
{projects_Details.startDate
|
{projects_Details.startDate
|
||||||
? moment(projects_Details.startDate).format("DD-MMM-YYYY")
|
? moment(projects_Details.startDate).format("DD-MMM-YYYY")
|
||||||
: "N/A"}
|
: "N/A"}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<li className="d-flex mb-3">
|
<li className="d-flex align-items-center mb-3">
|
||||||
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
<i className="bx bx-stop-circle"></i>{" "}
|
||||||
<i className="bx bx-stop-circle"></i>
|
<span className="fw-medium mx-2">End Date:</span>{" "}
|
||||||
<span className="fw-medium mx-2">End Date:</span>
|
|
||||||
</div>
|
|
||||||
<span>
|
<span>
|
||||||
{projects_Details.endDate
|
{projects_Details.endDate
|
||||||
? moment(projects_Details.endDate).format("DD-MMM-YYYY")
|
? moment(projects_Details.endDate).format("DD-MMM-YYYY")
|
||||||
: "N/A"}
|
: "N/A"}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<li className="d-flex mb-3">
|
<li className="d-flex align-items-center mb-3">
|
||||||
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
|
||||||
<i className="bx bx-trophy"></i>
|
<i className="bx bx-trophy"></i>
|
||||||
<span className="fw-medium mx-2">Status:</span>
|
<span className="fw-medium mx-2">Status:</span>{" "}
|
||||||
</div>
|
<span>{projects_Details?.projectStatus?.status}</span>
|
||||||
<span>{projects_Details?.projectStatus?.status.replace(/\s/g, '')}</span>
|
|
||||||
</li>
|
</li>
|
||||||
<li className="d-flex mb-3">
|
<li className="d-flex align-items-center mb-3">
|
||||||
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
|
||||||
<i className="bx bx-user"></i>
|
<i className="bx bx-user"></i>
|
||||||
<span className="fw-medium mx-2">Contact:</span>
|
<span className="fw-medium mx-2">Contact:</span>{" "}
|
||||||
</div>
|
|
||||||
<span>{projects_Details.contactPerson}</span>
|
<span>{projects_Details.contactPerson}</span>
|
||||||
</li>
|
</li>
|
||||||
<li className="d-flex mb-3">
|
<li className="d-flex flex-column align-items-start mb-3">
|
||||||
{/* Label section with icon */}
|
<div className="d-flex align-items-center">
|
||||||
<div className="d-flex align-items-start" style={{ minWidth: "120px" }}>
|
<i className="bx bx-flag"></i>
|
||||||
<i className="bx bx-flag mt-1"></i>
|
<span className="fw-medium mx-2">Address:</span>
|
||||||
<span className="fw-medium mx-2 text-nowrap">Address:</span>
|
{projects_Details.projectAddress?.length <= 20 && (
|
||||||
</div>
|
<span>{projects_Details.projectAddress}</span>
|
||||||
|
)}
|
||||||
{/* Content section that wraps nicely */}
|
|
||||||
<div className="flex-grow-1 text-start text-wrap">
|
|
||||||
{projects_Details.projectAddress}
|
|
||||||
</div>
|
</div>
|
||||||
|
{projects_Details.projectAddress?.length > 20 && (
|
||||||
|
<div className="ms-4 text-start">{projects_Details.projectAddress}</div>
|
||||||
|
)}
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li className="d-flex justify-content-center mb-3">
|
||||||
|
|
||||||
<li className="d-flex justify-content-center mt-4"> {/* Added mt-4 for some top margin */}
|
|
||||||
{manageProject && (
|
{manageProject && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`btn btn-sm btn-primary ${!manageProject && "d-none"
|
className={`btn btn-sm btn-primary ${
|
||||||
|
!manageProject && "d-none"
|
||||||
}`}
|
}`}
|
||||||
data-bs-toggle="modal"
|
data-bs-toggle="modal"
|
||||||
data-bs-target="#edit-project-modal"
|
data-bs-target="#edit-project-modal"
|
||||||
@ -141,10 +126,8 @@ const AboutProject = () => {
|
|||||||
)}
|
)}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@ -48,9 +48,6 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
const infoRef = useRef(null);
|
const infoRef = useRef(null);
|
||||||
const infoRef1 = useRef(null);
|
const infoRef1 = useRef(null);
|
||||||
|
|
||||||
// State for search term
|
|
||||||
const [searchTerm, setSearchTerm] = useState("");
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof bootstrap !== "undefined") {
|
if (typeof bootstrap !== "undefined") {
|
||||||
if (infoRef.current) {
|
if (infoRef.current) {
|
||||||
@ -86,10 +83,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
const { loading } = useMaster();
|
const { loading } = useMaster();
|
||||||
const { data: jobRoleData } = useMaster();
|
const { data: jobRoleData } = useMaster();
|
||||||
|
|
||||||
// Changed to an array to hold multiple selected roles
|
const [selectedRole, setSelectedRole] = useState("all");
|
||||||
const [selectedRoles, setSelectedRoles] = useState(["all"]);
|
|
||||||
// Changed to an array to hold multiple selected roles
|
|
||||||
// const [selectedRoles, setSelectedRoles] = useState(["all"]);
|
|
||||||
const [displayedSelection, setDisplayedSelection] = useState("");
|
const [displayedSelection, setDisplayedSelection] = useState("");
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -127,80 +121,21 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(changeMaster("Job Role"));
|
dispatch(changeMaster("Job Role"));
|
||||||
// Initial state should reflect "All Roles" selected
|
|
||||||
setSelectedRoles(["all"]);
|
return () => setSelectedRole("all");
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
// Modified handleRoleChange to handle multiple selections
|
const handleRoleChange = (event) => {
|
||||||
const handleRoleChange = (event, roleId) => {
|
setSelectedRole(event.target.value);
|
||||||
// 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];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const filteredEmployees =
|
||||||
// Update displayedSelection based on selectedRoles
|
selectedRole === "all"
|
||||||
if (selectedRoles.includes("all")) {
|
? employees
|
||||||
setDisplayedSelection("All Roles");
|
: employees?.filter(
|
||||||
} else if (selectedRoles.length > 0) {
|
(emp) => String(emp.jobRoleId || "") === selectedRole
|
||||||
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)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// 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 onSubmit = (data) => {
|
||||||
const selectedEmployeeIds = data.selectedEmployees;
|
const selectedEmployeeIds = data.selectedEmployees;
|
||||||
|
|
||||||
@ -224,7 +159,6 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
reset();
|
reset();
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fs-5 text-dark text-center d-flex align-items-center justify-content-center flex-wrap">
|
<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>
|
<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">
|
<div className="mb-1">
|
||||||
<p className="mb-0">
|
<p className="mb-0">
|
||||||
<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 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?.building?.buildingName,
|
||||||
assignData?.floor?.floorName,
|
assignData?.floor?.floorName,
|
||||||
@ -258,92 +192,50 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
<div className="form-text text-start">
|
<div className="form-text text-start">
|
||||||
<div className="d-flex align-items-center form-text fs-7">
|
<div className="d-flex align-items-center form-text fs-7">
|
||||||
<span className="text-dark">Select Team</span>
|
<span className="text-dark">Select Team</span>
|
||||||
<div className="dropdown position-relative d-inline-block">
|
<div className="me-2">{displayedSelection}</div>
|
||||||
<a
|
<a
|
||||||
className={`dropdown-toggle hide-arrow cursor-pointer ${
|
className="dropdown-toggle hide-arrow cursor-pointer"
|
||||||
selectedRoles.includes("all") || selectedRoles.length === 0
|
|
||||||
? "text-secondary"
|
|
||||||
: "text-primary"
|
|
||||||
}`}
|
|
||||||
data-bs-toggle="dropdown"
|
data-bs-toggle="dropdown"
|
||||||
role="button"
|
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
>
|
>
|
||||||
<i className="bx bx-slider-alt ms-2"></i>
|
<i className="bx bx-filter bx-lg text-primary"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{/* Badge */}
|
<ul className="dropdown-menu p-2 text-capitalize">
|
||||||
{selectedRolesCount > 0 && (
|
<li key="all">
|
||||||
<span
|
<button
|
||||||
className="position-absolute top-0 start-100 translate-middle badge rounded-circle bg-warning text-white"
|
type="button"
|
||||||
style={{
|
className="dropdown-item py-1"
|
||||||
fontSize: "0.65rem",
|
onClick={() =>
|
||||||
minWidth: "18px",
|
handleRoleChange({
|
||||||
height: "18px",
|
target: { value: "all" },
|
||||||
padding: "0",
|
})
|
||||||
lineHeight: "18px",
|
}
|
||||||
textAlign: "center",
|
|
||||||
zIndex: 10,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{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
|
All Roles
|
||||||
</label>
|
</button>
|
||||||
</div>
|
|
||||||
</li>
|
</li>
|
||||||
|
{jobRoleData?.map((user) => (
|
||||||
{jobRolesForDropdown?.map((role) => (
|
<li key={user.id}>
|
||||||
<li key={role.id}>
|
<button
|
||||||
<div className="form-check dropdown-item py-0">
|
type="button"
|
||||||
<input
|
className="dropdown-item py-1"
|
||||||
className="form-check-input"
|
value={user.id}
|
||||||
type="checkbox"
|
onClick={handleRoleChange}
|
||||||
id={`checkboxRole-${role.id}`} // Unique ID
|
>
|
||||||
value={role.id}
|
{user.name}
|
||||||
checked={selectedRoles.includes(String(role.id))}
|
</button>
|
||||||
onChange={(e) => handleRoleChange(e, e.target.value)}
|
|
||||||
/>
|
|
||||||
<label className="form-check-label ms-2" htmlFor={`checkboxRole-${role.id}`}>
|
|
||||||
{role.name}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</div>
|
|
||||||
<div
|
<div className="row">
|
||||||
className="col-12 mt-2"
|
<div className="col-12 h-sm-25 overflow-auto mt-2">
|
||||||
style={{ maxHeight: "280px", overflowY: "auto", overflowX: "hidden" }}
|
{selectedRole !== "" && (
|
||||||
>
|
|
||||||
{selectedRoles?.length > 0 && (
|
|
||||||
<div className="row">
|
<div className="row">
|
||||||
{employeeLoading ? (
|
{employeeLoading ? (
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
@ -369,7 +261,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
{...field}
|
{...field}
|
||||||
className="form-check-input me-1 mt-1"
|
className="form-check-input me-1 mt-1"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id={`employee-${emp?.id}`} // Unique ID
|
id={`employee-${emp?.id}`}
|
||||||
value={emp.id}
|
value={emp.id}
|
||||||
checked={field.value?.includes(emp.id)}
|
checked={field.value?.includes(emp.id)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
@ -405,13 +297,14 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
) : (
|
) : (
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<p className="text-center">
|
<p className="text-center">
|
||||||
No employees found for the selected role(s).
|
No employees found for the selected role.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className="col-12 h-25 overflow-auto"
|
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"
|
className="badge rounded-pill bg-label-primary d-inline-flex align-items-center me-1 mb-1"
|
||||||
>
|
>
|
||||||
{emp.firstName} {emp.lastName}
|
{emp.firstName} {emp.lastName}
|
||||||
{/* Changed p tag to button for semantic correctness and accessibility */}
|
<p
|
||||||
<button
|
|
||||||
type="button"
|
type="button"
|
||||||
className="btn-close btn-close-white ms-1" // Added ms-1 for spacing, removed p-0 m-0
|
className=" btn-close-white p-0 m-0"
|
||||||
aria-label="Remove employee" // More descriptive aria-label
|
aria-label="Close"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const updatedSelected = watch(
|
const updatedSelected = watch(
|
||||||
"selectedEmployees"
|
"selectedEmployees"
|
||||||
@ -446,7 +338,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<i className="icon-base bx bx-x icon-md "></i>
|
<i className="icon-base bx bx-x icon-md "></i>
|
||||||
</button>
|
</p>
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -466,12 +358,12 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
<div className="form-check form-check-inline mt-3 px-1">
|
<div className="form-check form-check-inline mt-3 px-1">
|
||||||
<label
|
<label
|
||||||
className="form-text text-dark align-items-center d-flex"
|
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 :
|
Pending Task of Activity :
|
||||||
<label
|
<label
|
||||||
className="form-check-label fs-7 ms-4"
|
className="form-check-label fs-7 ms-4"
|
||||||
htmlFor="inlineCheckbox1" // This htmlFor isn't linked to a checkbox in this context
|
htmlFor="inlineCheckbox1"
|
||||||
>
|
>
|
||||||
<strong>
|
<strong>
|
||||||
{assignData?.workItem?.plannedWork -
|
{assignData?.workItem?.plannedWork -
|
||||||
@ -518,7 +410,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
<div className="form-check form-check-inline mt-2 px-1 mb-2 text-start">
|
<div className="form-check form-check-inline mt-2 px-1 mb-2 text-start">
|
||||||
<label
|
<label
|
||||||
className="text-dark text-start d-flex align-items-center flex-wrap form-text"
|
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>
|
<span>Target for Today</span>
|
||||||
<span style={{ marginLeft: "46px" }}>:</span>
|
<span style={{ marginLeft: "46px" }}>:</span>
|
||||||
@ -537,17 +429,14 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
type="text"
|
type="text"
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control-sm"
|
||||||
{...field}
|
{...field}
|
||||||
id="defaultFormControlInput" // Consider a more descriptive ID if used elsewhere
|
id="defaultFormControlInput"
|
||||||
aria-describedby="defaultFormControlHelp"
|
aria-describedby="defaultFormControlHelp"
|
||||||
/>
|
/>
|
||||||
<span style={{ paddingLeft: "6px", whiteSpace: "nowrap" }}>
|
<span style={{ paddingLeft: "6px" }}>
|
||||||
<u>
|
|
||||||
{" "}
|
|
||||||
{
|
{
|
||||||
assignData?.workItem?.activityMaster
|
assignData?.workItem?.workItem?.activityMaster
|
||||||
?.unitOfMeasurement
|
?.unitOfMeasurement
|
||||||
}
|
}
|
||||||
</u>
|
|
||||||
</span>
|
</span>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@ -595,6 +484,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
className="position-absolute bg-white border p-2 rounded shadow"
|
className="position-absolute bg-white border p-2 rounded shadow"
|
||||||
style={{ zIndex: 10, marginLeft: "10px" }}
|
style={{ zIndex: 10, marginLeft: "10px" }}
|
||||||
>
|
>
|
||||||
|
{/* Add your help content here */}
|
||||||
<p className="mb-0">
|
<p className="mb-0">
|
||||||
Enter the target value for today's task.
|
Enter the target value for today's task.
|
||||||
</p>
|
</p>
|
||||||
@ -603,8 +493,8 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
className="form-text fs-7 m-1 text-dark" // Removed duplicate htmlFor and text-lg
|
className="form-text fs-7 m-1 text-lg text-dark"
|
||||||
htmlFor="descriptionTextarea"
|
htmlFor="descriptionTextarea" // Changed htmlFor for better accessibility
|
||||||
>
|
>
|
||||||
Description
|
Description
|
||||||
</label>
|
</label>
|
||||||
@ -615,7 +505,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
<textarea
|
<textarea
|
||||||
{...field}
|
{...field}
|
||||||
className="form-control"
|
className="form-control"
|
||||||
id="descriptionTextarea" // Unique ID
|
id="descriptionTextarea" // Changed id for better accessibility
|
||||||
rows="2"
|
rows="2"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@ -625,6 +515,7 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</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">
|
<div className="col-12 d-flex justify-content-center align-items-center gap-sm-6 gap-8 text-center mt-1">
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
@ -647,7 +538,8 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div> );
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AssignTask;
|
export default AssignTask;
|
||||||
@ -15,7 +15,6 @@ import {
|
|||||||
cacheData,
|
cacheData,
|
||||||
clearCacheKey,
|
clearCacheKey,
|
||||||
getCachedData,
|
getCachedData,
|
||||||
useSelectedproject,
|
|
||||||
} from "../../slices/apiDataManager";
|
} from "../../slices/apiDataManager";
|
||||||
import { useProjectDetails, useProjectInfra } from "../../hooks/useProjects";
|
import { useProjectDetails, useProjectInfra } from "../../hooks/useProjects";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
@ -26,8 +25,7 @@ import GlobalModel from "../common/GlobalModel";
|
|||||||
|
|
||||||
const ProjectInfra = ( {data, onDataChange, eachSiteEngineer} ) =>
|
const ProjectInfra = ( {data, onDataChange, eachSiteEngineer} ) =>
|
||||||
{
|
{
|
||||||
// const projectId = useSelector((store)=>store.localVariables.projectId)
|
const projectId = useSelector((store)=>store.localVariables.projectId)
|
||||||
const projectId = useSelectedproject();
|
|
||||||
const reloadedData = useSelector((store) => store.localVariables.reload);
|
const reloadedData = useSelector((store) => store.localVariables.reload);
|
||||||
const [ expandedBuildings, setExpandedBuildings ] = useState( [] );
|
const [ expandedBuildings, setExpandedBuildings ] = useState( [] );
|
||||||
const {projectInfra,isLoading,error} = useProjectInfra(projectId)
|
const {projectInfra,isLoading,error} = useProjectInfra(projectId)
|
||||||
|
|||||||
@ -49,21 +49,6 @@ const ProjectNav = ({ onPillClick, activePill }) => {
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|
||||||
{(DirAdmin || DireManager || DirUser) && (
|
|
||||||
<li className="nav-item">
|
|
||||||
<a
|
|
||||||
className={`nav-link ${activePill === "directory" ? "active" : ""} fs-6`}
|
|
||||||
href="#"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.preventDefault(); // Prevent page reload
|
|
||||||
onPillClick("directory");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<i className='bx bxs-contact bx-sm me-1_5'></i> <span className="d-none d-md-inline">Directory</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
<li className="nav-item">
|
<li className="nav-item">
|
||||||
<a
|
<a
|
||||||
className={`nav-link ${
|
className={`nav-link ${
|
||||||
@ -78,6 +63,20 @@ const ProjectNav = ({ onPillClick, activePill }) => {
|
|||||||
<i className='bx bxs-cog bx-sm me-1_5'></i> <span className="d-none d-md-inline">project Setup</span>
|
<i className='bx bxs-cog bx-sm me-1_5'></i> <span className="d-none d-md-inline">project Setup</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{(DirAdmin || DireManager || DirUser) && (
|
||||||
|
<li className="nav-item">
|
||||||
|
<a
|
||||||
|
className={`nav-link ${activePill === "directory" ? "active" : ""} fs-6`}
|
||||||
|
href="#"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault(); // Prevent page reload
|
||||||
|
onPillClick("directory");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<i className='bx bxs-contact bx-sm me-1_5'></i> <span className="d-none d-md-inline">Directory</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -15,13 +15,11 @@ import { ASSIGN_TO_PROJECT } from "../../utils/constants";
|
|||||||
import ConfirmModal from "../common/ConfirmModal";
|
import ConfirmModal from "../common/ConfirmModal";
|
||||||
import eventBus from "../../services/eventBus";
|
import eventBus from "../../services/eventBus";
|
||||||
import {useEmployeesByProjectAllocated, useManageProjectAllocation} from "../../hooks/useProjects";
|
import {useEmployeesByProjectAllocated, useManageProjectAllocation} from "../../hooks/useProjects";
|
||||||
import { useSelectedproject } from "../../slices/apiDataManager";
|
|
||||||
|
|
||||||
const Teams = () =>
|
const Teams = () =>
|
||||||
{
|
{
|
||||||
// const {projectId} = useParams()
|
// const {projectId} = useParams()
|
||||||
// const projectId = useSelector((store)=>store.localVariables.projectId)
|
const projectId = useSelector((store)=>store.localVariables.projectId)
|
||||||
const projectId = useSelectedproject();
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const { data, loading } = useMaster();
|
const { data, loading } = useMaster();
|
||||||
@ -295,7 +293,7 @@ const {
|
|||||||
<div className="d-flex flex-column">
|
<div className="d-flex flex-column">
|
||||||
<a
|
<a
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(`/employee/${item.employeeId}?for=attendance`)
|
navigate(`/employee/${item.employeeId}?for=account`)
|
||||||
}
|
}
|
||||||
className="text-heading text-truncate cursor-pointer"
|
className="text-heading text-truncate cursor-pointer"
|
||||||
>
|
>
|
||||||
|
|||||||
@ -141,58 +141,54 @@ const CreateRole = ({ modalType, onClose }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div className="col-12 col-md-12 border">
|
||||||
className="border rounded px-3"
|
|
||||||
style={{
|
|
||||||
maxHeight: "350px",
|
|
||||||
overflowY: "auto",
|
|
||||||
overflowX: "hidden", // Prevent bottom scrollbar
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{masterFeatures.map((feature, featureIndex) => (
|
{masterFeatures.map((feature, featureIndex) => (
|
||||||
<React.Fragment key={feature.id}>
|
<React.Fragment key={feature.id}>
|
||||||
<div className="row my-1">
|
<div
|
||||||
{/* Feature Title */}
|
className="row my-1"
|
||||||
<div className="col-12 text-start fw-semibold mb-2">
|
key={feature.id}
|
||||||
{feature.name}
|
style={{ marginLeft: "0px" }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="col-12 col-md-3 d-flex text-start align-items-start"
|
||||||
|
style={{ wordWrap: "break-word" }}
|
||||||
|
>
|
||||||
|
<span className="fs">{feature.name}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Permissions Grid */}
|
<div className="col-12 col-md-1"></div>
|
||||||
<div className="col-12">
|
|
||||||
<div className="row">
|
<div className="col-12 col-md-8 d-flex justify-content-start align-items-center flex-wrap">
|
||||||
{feature.featurePermissions.map((perm, permIndex) => {
|
{feature.featurePermissions.map((perm, permIndex) => {
|
||||||
const refIndex = featureIndex * 100 + permIndex;
|
const refIndex = featureIndex * 10 + permIndex;
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="d-flex me-3 mb-2" key={perm.id}>
|
||||||
className="col-12 col-sm-6 col-md-4 mb-3"
|
<label className="form-check-label" htmlFor={perm.id}>
|
||||||
key={perm.id}
|
|
||||||
>
|
|
||||||
<div className="d-flex align-items-start">
|
|
||||||
<label
|
|
||||||
className="form-check-label d-flex align-items-center"
|
|
||||||
htmlFor={perm.id}
|
|
||||||
>
|
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="form-check-input me-2"
|
className="form-check-input mx-2"
|
||||||
id={perm.id}
|
id={perm.id}
|
||||||
value={perm.id}
|
value={perm.id}
|
||||||
{...register("selectedPermissions")}
|
{...register("selectedPermissions")}
|
||||||
/>
|
/>
|
||||||
{perm.name}
|
{perm.name}
|
||||||
</label>
|
</label>
|
||||||
|
<div style={{ display: "flex", alignItems: "center" }}>
|
||||||
{/* Info icon */}
|
|
||||||
<div className="ms-1 d-flex align-items-center">
|
|
||||||
<div
|
<div
|
||||||
|
key={refIndex}
|
||||||
ref={(el) => (popoverRefs.current[refIndex] = el)}
|
ref={(el) => (popoverRefs.current[refIndex] = el)}
|
||||||
tabIndex="0"
|
tabIndex="0"
|
||||||
className="d-flex align-items-center justify-content-center"
|
className="d-flex align-items-center avatar-group justify-content-center"
|
||||||
data-bs-toggle="popover"
|
data-bs-toggle="popover"
|
||||||
|
refIndex
|
||||||
data-bs-trigger="focus"
|
data-bs-trigger="focus"
|
||||||
data-bs-placement="right"
|
data-bs-placement="right"
|
||||||
data-bs-html="true"
|
data-bs-html="true"
|
||||||
data-bs-content={`<div class="border border-secondary rounded custom-popover p-2 px-3">${perm.description}</div>`}
|
data-bs-content={`
|
||||||
|
<div class="border border-secondary rounded custom-popover p-2 px-3">
|
||||||
|
${perm.description}
|
||||||
|
</div>
|
||||||
|
`}
|
||||||
>
|
>
|
||||||
|
|
||||||
<svg
|
<svg
|
||||||
@ -209,24 +205,19 @@ const CreateRole = ({ modalType, onClose }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<hr className="hr my-1 py-1" />
|
||||||
|
|
||||||
<hr className="my-2" />
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{errors.selectedPermissions && (
|
{errors.selectedPermissions && (
|
||||||
<p className="text-danger">{errors.selectedPermissions.message}</p>
|
<p className="text-danger">{errors.selectedPermissions.message}</p>
|
||||||
)}
|
)}
|
||||||
{!masterFeatures && <p>Loading...</p>}
|
{!masterFeatures && <p>Loading...</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{masterFeatures && (
|
{masterFeatures && (
|
||||||
<div className="col-12 text-center">
|
<div className="col-12 text-center">
|
||||||
<button type="submit" className="btn btn-sm btn-primary me-3">
|
<button type="submit" className="btn btn-sm btn-primary me-3">
|
||||||
|
|||||||
@ -9,6 +9,13 @@ import { cacheData, getCachedData } from "../../slices/apiDataManager";
|
|||||||
import showToast from "../../services/toastService";
|
import showToast from "../../services/toastService";
|
||||||
import {useUpdateApplicationRole} from "../../hooks/masterHook/useMaster";
|
import {useUpdateApplicationRole} from "../../hooks/masterHook/useMaster";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const updateSchema = z.object({
|
const updateSchema = z.object({
|
||||||
role: z.string().min(1, { message: "Role is required" }),
|
role: z.string().min(1, { message: "Role is required" }),
|
||||||
description: z.string().min(1, { message: "Description is required" })
|
description: z.string().min(1, { message: "Description is required" })
|
||||||
@ -18,6 +25,8 @@ const updateSchema = z.object({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const EditMaster = ({ master, onClose }) => {
|
const EditMaster = ({ master, onClose }) => {
|
||||||
const maxDescriptionLength = 255;
|
const maxDescriptionLength = 255;
|
||||||
const popoverRefs = useRef([]);
|
const popoverRefs = useRef([]);
|
||||||
@ -190,91 +199,77 @@ const EditMaster = ({ master, onClose }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-12 text-start">
|
<div className="col-12 col-md-12 mx-2s" >
|
||||||
{/* Scrollable Container with Border */}
|
|
||||||
<div
|
|
||||||
className="border rounded p-3"
|
|
||||||
style={{
|
|
||||||
maxHeight: "350px",
|
|
||||||
overflowY: "auto",
|
|
||||||
overflowX: "hidden", // Prevent horizontal scrollbar
|
|
||||||
paddingRight: "10px",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{masterFeatures.map((feature, featureIndex) => (
|
|
||||||
<div key={feature.id} className="mb-3">
|
|
||||||
{/* Feature Group Title */}
|
|
||||||
<div className="fw-semibold mb-2">{feature.name}</div>
|
|
||||||
|
|
||||||
{/* Permissions Grid */}
|
{masterFeatures.map((feature, featureIndex) => (
|
||||||
<div className="row">
|
<div className="row my-1" key={feature.id} style={{ marginLeft: "0px" }}>
|
||||||
|
|
||||||
|
<div className="col-12 col-md-3 d-flex text-start align-items-center" style={{ wordWrap: 'break-word' }}>
|
||||||
|
<span className="fs">{feature.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-1">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-8 d-flex justify-content-start align-items-center flex-wrap ">
|
||||||
{feature.featurePermissions.map((perm, permIndex) => {
|
{feature.featurePermissions.map((perm, permIndex) => {
|
||||||
const refIndex = featureIndex * 10 + permIndex;
|
const refIndex = (featureIndex * 10) + permIndex;
|
||||||
return (
|
return (
|
||||||
<div
|
|
||||||
key={perm.id}
|
<div className="d-flex me-3 mb-2" key={perm.id}>
|
||||||
className="col-12 col-sm-6 col-md-4 mb-3 d-flex align-items-start"
|
|
||||||
>
|
<label className="form-check-label" htmlFor={perm.id}>
|
||||||
<label
|
|
||||||
className="form-check-label d-flex align-items-center"
|
|
||||||
htmlFor={perm.id}
|
|
||||||
>
|
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="form-check-input me-2"
|
className="form-check-input mx-2"
|
||||||
id={perm.id}
|
id={perm.id}
|
||||||
{...register(`permissions.${perm.id}`, {
|
{...register(`permissions.${perm.id}`, {
|
||||||
value: initialPermissions[perm.id] || false,
|
value: initialPermissions[perm.id] || false
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{perm.name}
|
{perm.name}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
{/* Info Icon */}
|
|
||||||
<div style={{ display: "flex", alignItems: "center" }}>
|
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
<div
|
<div
|
||||||
ref={(el) => (popoverRefs.current[refIndex] = el)}
|
key={refIndex}
|
||||||
|
ref={(el) =>
|
||||||
|
(popoverRefs.current[refIndex] = el)
|
||||||
|
}
|
||||||
tabIndex="0"
|
tabIndex="0"
|
||||||
className="d-flex align-items-center justify-content-center"
|
className="d-flex align-items-center avatar-group justify-content-center"
|
||||||
data-bs-toggle="popover"
|
data-bs-toggle="popover" refIndex
|
||||||
data-bs-trigger="focus"
|
data-bs-trigger="focus"
|
||||||
data-bs-placement="right"
|
data-bs-placement="right"
|
||||||
data-bs-html="true"
|
data-bs-html="true"
|
||||||
data-bs-content={`<div class="border border-secondary rounded custom-popover p-2 px-3">${perm.description}</div>`}
|
data-bs-content={`
|
||||||
|
<div class="border border-secondary rounded custom-popover p-2 px-3">
|
||||||
|
${perm.description}
|
||||||
|
</div>
|
||||||
|
`}
|
||||||
>
|
>
|
||||||
|
|
||||||
<svg
|
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" fill="currentColor" className="bi bi-info-circle" viewBox="0 0 16 16">
|
||||||
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 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" />
|
<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>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
})}
|
})}
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr className="my-2" />
|
|
||||||
|
</div>
|
||||||
|
<hr className="hr my-1 py-1" />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Error Display */}
|
|
||||||
{errors.permissions && (
|
{errors.permissions && (
|
||||||
<p className="text-danger">{errors.permissions.message}</p>
|
<p className="text-danger">{errors.permissions.message}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div className="col-12 text-center">
|
<div className="col-12 text-center">
|
||||||
<button type="submit" className="btn btn-sm btn-primary me-3"> {isLoading ? "Please Wait..." : "Submit"}</button>
|
<button type="submit" className="btn btn-sm btn-primary me-3"> {isLoading ? "Please Wait..." : "Submit"}</button>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@ -104,15 +104,17 @@ export const useDashboardTeamsCardData = (projectId) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchTeamsData = async () => {
|
const fetchTeamsData = async () => {
|
||||||
|
if (!projectId) return; // ✅ Skip if projectId is not provided
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError("");
|
setError("");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await GlobalRepository.getDashboardTeamsCardData(projectId);
|
const response = await GlobalRepository.getDashboardTeamsCardData(projectId);
|
||||||
setTeamsData(response.data || {});
|
setTeamsData(response.data); // ✅ Handle undefined/null
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError("Failed to fetch teams card data.");
|
setError("Failed to fetch teams card data.");
|
||||||
console.error("Error fetching teams card data:", err);
|
console.error(err);
|
||||||
setTeamsData({});
|
setTeamsData({});
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@ -177,36 +177,3 @@ export const useOrganization = () => {
|
|||||||
|
|
||||||
return { organizationList, loading, error };
|
return { organizationList, loading, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useDesignation = () => {
|
|
||||||
const [designationList, setDesignationList] = useState([]);
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [error, setError] = useState("");
|
|
||||||
|
|
||||||
const fetchOrg = async () => {
|
|
||||||
const cacheOrg = getCachedData("designation");
|
|
||||||
if (cacheOrg?.length != 0) {
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const resp = await DirectoryRepository.GetDesignations();
|
|
||||||
cacheData("designation", resp.data);
|
|
||||||
setDesignationList(resp.data);
|
|
||||||
setLoading(false);
|
|
||||||
} catch (error) {
|
|
||||||
const msg =
|
|
||||||
error?.response?.data?.message ||
|
|
||||||
error?.message ||
|
|
||||||
"Something went wrong";
|
|
||||||
setError(msg);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setDesignationList(cacheOrg);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchOrg();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return { designationList, loading, error };
|
|
||||||
};
|
|
||||||
|
|||||||
@ -8,35 +8,42 @@ import {
|
|||||||
import Breadcrumb from "../../components/common/Breadcrumb";
|
import Breadcrumb from "../../components/common/Breadcrumb";
|
||||||
import AttendanceLog from "../../components/Activities/AttendcesLogs";
|
import AttendanceLog from "../../components/Activities/AttendcesLogs";
|
||||||
import Attendance from "../../components/Activities/Attendance";
|
import Attendance from "../../components/Activities/Attendance";
|
||||||
import AttendanceModel from "../../components/Activities/AttendanceModel";
|
// import AttendanceModel from "../../components/Activities/AttendanceModel";
|
||||||
import showToast from "../../services/toastService";
|
import showToast from "../../services/toastService";
|
||||||
|
// import { useProjects } from "../../hooks/useProjects";
|
||||||
import Regularization from "../../components/Activities/Regularization";
|
import Regularization from "../../components/Activities/Regularization";
|
||||||
import { useAttendance } from "../../hooks/useAttendance";
|
import { useAttendance } from "../../hooks/useAttendance";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { setProjectId } from "../../slices/localVariablesSlice";
|
import { setProjectId } from "../../slices/localVariablesSlice";
|
||||||
import { markCurrentAttendance } from "../../slices/apiSlice/attendanceAllSlice";
|
// import { markCurrentAttendance } from "../../slices/apiSlice/attendanceAllSlice";
|
||||||
|
import { hasUserPermission } from "../../utils/authUtils";
|
||||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
import { REGULARIZE_ATTENDANCE } from "../../utils/constants";
|
import { REGULARIZE_ATTENDANCE } from "../../utils/constants";
|
||||||
import eventBus from "../../services/eventBus";
|
import eventBus from "../../services/eventBus";
|
||||||
import AttendanceRepository from "../../repositories/AttendanceRepository";
|
// import AttendanceRepository from "../../repositories/AttendanceRepository";
|
||||||
import { useProjectName } from "../../hooks/useProjects";
|
import { useProjectName } from "../../hooks/useProjects";
|
||||||
|
import GlobalModel from "../../components/common/GlobalModel";
|
||||||
|
import CheckCheckOutmodel from "../../components/Activities/CheckCheckOutForm";
|
||||||
|
import AttendLogs from "../../components/Activities/AttendLogs";
|
||||||
|
// import Confirmation from "../../components/Activities/Confirmation";
|
||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
const AttendancePage = () => {
|
const AttendancePage = () => {
|
||||||
const [activeTab, setActiveTab] = useState("all");
|
const [activeTab, setActiveTab] = useState("all");
|
||||||
const [showPending, setShowPending] = useState(false);
|
const [ShowPending, setShowPending] = useState(false);
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const queryClient = useQueryClient();
|
||||||
const loginUser = getCachedProfileData();
|
const loginUser = getCachedProfileData();
|
||||||
const selectedProject = useSelector((store) => store.localVariables.projectId);
|
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const {
|
// const {
|
||||||
attendance,
|
// attendance,
|
||||||
loading: attLoading,
|
// loading: attLoading,
|
||||||
recall: attrecall,
|
// recall: attrecall,
|
||||||
} = useAttendance(selectedProject);
|
// } = useAttendance(selectedProject);
|
||||||
const [attendances, setAttendances] = useState();
|
const [attendances, setAttendances] = useState();
|
||||||
const [empRoles, setEmpRoles] = useState(null);
|
const [empRoles, setEmpRoles] = useState(null);
|
||||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||||
const [modelConfig, setModelConfig] = useState(null); // Initialize as null
|
const [modelConfig, setModelConfig] = useState();
|
||||||
const DoRegularized = useHasUserPermission(REGULARIZE_ATTENDANCE);
|
const DoRegularized = useHasUserPermission(REGULARIZE_ATTENDANCE);
|
||||||
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
||||||
|
|
||||||
@ -46,163 +53,86 @@ const AttendancePage = () => {
|
|||||||
date: new Date().toLocaleDateString(),
|
date: new Date().toLocaleDateString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const handler = useCallback(
|
// const handler = useCallback(
|
||||||
(msg) => {
|
// (msg) => {
|
||||||
if (selectedProject === msg.projectId) {
|
// if (selectedProject == msg.projectId) {
|
||||||
const updatedAttendance = attendances
|
// const updatedAttendance = attendances.map((item) =>
|
||||||
? attendances.map((item) =>
|
// item.employeeId === msg.response.employeeId
|
||||||
item.employeeId === msg.response.employeeId
|
// ? { ...item, ...msg.response }
|
||||||
? { ...item, ...msg.response }
|
// : item
|
||||||
: item
|
// );
|
||||||
)
|
// queryClient.setQueryData(["attendance", selectedProject], (oldData) => {
|
||||||
: [msg.response];
|
// if (!oldData) return oldData;
|
||||||
|
// return oldData.map((emp) =>
|
||||||
|
// emp.employeeId === data.employeeId ? { ...emp, ...data } : emp
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// [selectedProject, attrecall]
|
||||||
|
// );
|
||||||
|
|
||||||
cacheData("Attendance", {
|
// const employeeHandler = useCallback(
|
||||||
data: updatedAttendance,
|
// (msg) => {
|
||||||
projectId: selectedProject,
|
// if (attendances.some((item) => item.employeeId == msg.employeeId)) {
|
||||||
});
|
// attrecall();
|
||||||
setAttendances(updatedAttendance);
|
// }
|
||||||
|
// },
|
||||||
|
// [selectedProject, attendances]
|
||||||
|
// );
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedProject == null) {
|
||||||
|
dispatch(setProjectId(projectNames[0]?.id));
|
||||||
}
|
}
|
||||||
},
|
}, []);
|
||||||
[selectedProject, attendances]
|
|
||||||
);
|
|
||||||
|
|
||||||
const employeeHandler = useCallback(
|
|
||||||
(msg) => {
|
|
||||||
// This logic seems fine for refetching if an employee ID exists in current attendances
|
|
||||||
if (attendances?.some((item) => item.employeeId === msg.employeeId)) {
|
|
||||||
AttendanceRepository.getAttendance(selectedProject)
|
|
||||||
.then((response) => {
|
|
||||||
cacheData("Attendance", { data: response.data, selectedProject });
|
|
||||||
setAttendances(response.data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[selectedProject, attendances]
|
|
||||||
);
|
|
||||||
|
|
||||||
const getRole = (roleId) => {
|
const getRole = (roleId) => {
|
||||||
if (!empRoles) return "Unassigned";
|
if (!empRoles) return "Unassigned";
|
||||||
if (!roleId) return "Unassigned";
|
if (!roleId) return "Unassigned";
|
||||||
const role = empRoles.find((b) => b.id === roleId);
|
const role = empRoles.find((b) => b.id == roleId);
|
||||||
return role ? role.role : "Unassigned";
|
return role ? role.role : "Unassigned";
|
||||||
};
|
};
|
||||||
|
|
||||||
// Simplified and moved modal opening logic
|
const openModel = () => {
|
||||||
const handleModalData = useCallback((employee) => {
|
setIsCreateModalOpen(true);
|
||||||
setModelConfig(employee);
|
|
||||||
setIsCreateModalOpen(true); // Open the modal directly when data is set
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const closeModal = useCallback(() => {
|
|
||||||
setModelConfig(null);
|
|
||||||
setIsCreateModalOpen(false);
|
|
||||||
// Directly manipulating the DOM is generally not recommended in React.
|
|
||||||
// React handles modal visibility via state. If you must, ensure it's
|
|
||||||
// for external libraries or for very specific, controlled reasons.
|
|
||||||
// For a typical Bootstrap modal, just setting `isCreateModalOpen` to false
|
|
||||||
// should be enough if the modal component itself handles the Bootstrap classes.
|
|
||||||
const modalElement = document.getElementById("check-Out-modal");
|
|
||||||
if (modalElement) {
|
|
||||||
modalElement.classList.remove("show");
|
|
||||||
modalElement.style.display = "none";
|
|
||||||
document.body.classList.remove("modal-open");
|
|
||||||
const modalBackdrop = document.querySelector(".modal-backdrop");
|
|
||||||
if (modalBackdrop) {
|
|
||||||
modalBackdrop.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleSubmit = useCallback((formData) => {
|
|
||||||
dispatch(markCurrentAttendance(formData))
|
|
||||||
.then((action) => {
|
|
||||||
if (action.payload && action.payload.employeeId) {
|
|
||||||
const updatedAttendance = attendances
|
|
||||||
? attendances.map((item) =>
|
|
||||||
item.employeeId === action.payload.employeeId
|
|
||||||
? { ...item, ...action.payload }
|
|
||||||
: item
|
|
||||||
)
|
|
||||||
: [action.payload];
|
|
||||||
|
|
||||||
cacheData("Attendance", {
|
|
||||||
data: updatedAttendance,
|
|
||||||
projectId: selectedProject,
|
|
||||||
});
|
|
||||||
setAttendances(updatedAttendance);
|
|
||||||
showToast("Attendance Marked Successfully", "success");
|
|
||||||
} else {
|
|
||||||
showToast("Failed to mark attendance: Invalid response", "error");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
showToast(error.message, "error");
|
|
||||||
});
|
|
||||||
}, [dispatch, attendances, selectedProject]);
|
|
||||||
|
|
||||||
|
|
||||||
const handleToggle = (event) => {
|
|
||||||
setShowPending(event.target.checked);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleModalData = (employee) => {
|
||||||
|
setModelConfig(employee);
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeModal = () => {
|
||||||
|
setModelConfig(null);
|
||||||
|
setIsCreateModalOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToggle = (event) => {
|
||||||
|
setShowOnlyCheckout(event.target.checked);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedProject === null && projectNames.length > 0) {
|
if (modelConfig !== null) {
|
||||||
dispatch(setProjectId(projectNames[0]?.id));
|
openModel();
|
||||||
}
|
}
|
||||||
}, [selectedProject, projectNames, dispatch]);
|
}, [modelConfig, isCreateModalOpen]);
|
||||||
|
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
setAttendances(attendance);
|
// eventBus.on("attendance", handler);
|
||||||
}, [attendance]);
|
// return () => eventBus.off("attendance", handler);
|
||||||
|
// }, [handler]);
|
||||||
const filteredAndSearchedTodayAttendance = useCallback(() => {
|
|
||||||
let currentData = attendances;
|
|
||||||
|
|
||||||
if (showPending) {
|
|
||||||
currentData = currentData?.filter(
|
|
||||||
(att) => att?.checkInTime !== null && att?.checkOutTime === null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (searchQuery) {
|
|
||||||
const lowerCaseSearchQuery = searchQuery.toLowerCase();
|
|
||||||
currentData = currentData?.filter((att) => {
|
|
||||||
const fullName = [att.firstName, att.middleName, att.lastName]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(" ")
|
|
||||||
.toLowerCase();
|
|
||||||
|
|
||||||
return (
|
|
||||||
att.employeeName?.toLowerCase().includes(lowerCaseSearchQuery) ||
|
|
||||||
att.employeeId?.toLowerCase().includes(lowerCaseSearchQuery) ||
|
|
||||||
fullName.includes(lowerCaseSearchQuery)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return currentData;
|
|
||||||
}, [attendances, showPending, searchQuery]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
eventBus.on("attendance", handler);
|
|
||||||
return () => eventBus.off("attendance", handler);
|
|
||||||
}, [handler]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
eventBus.on("employee", employeeHandler);
|
|
||||||
return () => eventBus.off("employee", employeeHandler);
|
|
||||||
}, [employeeHandler]);
|
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// eventBus.on("employee", employeeHandler);
|
||||||
|
// return () => eventBus.off("employee", employeeHandler);
|
||||||
|
// }, [employeeHandler]);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isCreateModalOpen && modelConfig && (
|
{/* {isCreateModalOpen && modelConfig && (
|
||||||
<div
|
<div
|
||||||
className="modal fade show"
|
className="modal fade show"
|
||||||
style={{ display: "block" }}
|
style={{ display: "block" }}
|
||||||
id="check-Out-modal"
|
id="check-Out-modalg"
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
>
|
>
|
||||||
@ -212,6 +142,29 @@ const AttendancePage = () => {
|
|||||||
handleSubmitForm={handleSubmit}
|
handleSubmitForm={handleSubmit}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)} */}
|
||||||
|
{isCreateModalOpen && modelConfig && (
|
||||||
|
<GlobalModel
|
||||||
|
isOpen={isCreateModalOpen}
|
||||||
|
size={modelConfig?.action === 6 && "lg"}
|
||||||
|
closeModal={closeModal}
|
||||||
|
>
|
||||||
|
{(modelConfig?.action === 0 ||
|
||||||
|
modelConfig?.action === 1 ||
|
||||||
|
modelConfig?.action === 2) && (
|
||||||
|
<CheckCheckOutmodel
|
||||||
|
modeldata={modelConfig}
|
||||||
|
closeModal={closeModal}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{/* For view logs */}
|
||||||
|
{modelConfig?.action === 6 && (
|
||||||
|
<AttendLogs Id={modelConfig?.id} closeModal={closeModal} />
|
||||||
|
)}
|
||||||
|
{modelConfig?.action === 7 && (
|
||||||
|
<Confirmation closeModal={closeModal} />
|
||||||
|
)}
|
||||||
|
</GlobalModel>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="container-fluid">
|
<div className="container-fluid">
|
||||||
@ -222,15 +175,13 @@ const AttendancePage = () => {
|
|||||||
]}
|
]}
|
||||||
></Breadcrumb>
|
></Breadcrumb>
|
||||||
<div className="nav-align-top nav-tabs-shadow" >
|
<div className="nav-align-top nav-tabs-shadow" >
|
||||||
<ul
|
<ul className="nav nav-tabs" role="tablist">
|
||||||
className="nav nav-tabs d-flex justify-content-between align-items-center"
|
|
||||||
role="tablist"
|
|
||||||
>
|
|
||||||
<div className="d-flex">
|
|
||||||
<li className="nav-item">
|
<li className="nav-item">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`nav-link ${activeTab === "all" ? "active" : ""} fs-6`}
|
className={`nav-link ${
|
||||||
|
activeTab === "all" ? "active" : ""
|
||||||
|
} fs-6`}
|
||||||
onClick={() => setActiveTab("all")}
|
onClick={() => setActiveTab("all")}
|
||||||
data-bs-toggle="tab"
|
data-bs-toggle="tab"
|
||||||
data-bs-target="#navs-top-home"
|
data-bs-target="#navs-top-home"
|
||||||
@ -241,7 +192,9 @@ const AttendancePage = () => {
|
|||||||
<li className="nav-item">
|
<li className="nav-item">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`nav-link ${activeTab === "logs" ? "active" : ""} fs-6`}
|
className={`nav-link ${
|
||||||
|
activeTab === "logs" ? "active" : ""
|
||||||
|
} fs-6`}
|
||||||
onClick={() => setActiveTab("logs")}
|
onClick={() => setActiveTab("logs")}
|
||||||
data-bs-toggle="tab"
|
data-bs-toggle="tab"
|
||||||
data-bs-target="#navs-top-profile"
|
data-bs-target="#navs-top-profile"
|
||||||
@ -262,65 +215,28 @@ const AttendancePage = () => {
|
|||||||
Regularization
|
Regularization
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
|
||||||
<div className="p-2">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="form-control form-control-sm"
|
|
||||||
placeholder="Search employee..."
|
|
||||||
value={searchQuery}
|
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</ul>
|
</ul>
|
||||||
<div className="tab-content attedanceTabs py-0 px-1 px-sm-3" >
|
<div className="tab-content attedanceTabs py-0 px-1 px-sm-3" >
|
||||||
{activeTab === "all" && (
|
{activeTab === "all" && (
|
||||||
<>
|
|
||||||
{!attLoading && (
|
|
||||||
<div className="tab-pane fade show active py-0">
|
<div className="tab-pane fade show active py-0">
|
||||||
<Attendance
|
<Attendance
|
||||||
attendance={filteredAndSearchedTodayAttendance()}
|
|
||||||
handleModalData={handleModalData}
|
handleModalData={handleModalData}
|
||||||
getRole={getRole}
|
getRole={getRole}
|
||||||
setshowOnlyCheckout={setShowPending}
|
|
||||||
showOnlyCheckout={showPending}
|
|
||||||
searchQuery={searchQuery}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!attLoading && filteredAndSearchedTodayAttendance()?.length === 0 && (
|
|
||||||
<p>
|
|
||||||
{" "}
|
|
||||||
{showPending
|
|
||||||
? "No Pending Available"
|
|
||||||
: "No Employee assigned yet."}{" "}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{activeTab === "logs" && (
|
{activeTab === "logs" && (
|
||||||
<div className="tab-pane fade show active py-0">
|
<div className="tab-pane fade show active py-0">
|
||||||
<AttendanceLog
|
<AttendanceLog
|
||||||
handleModalData={handleModalData}
|
handleModalData={handleModalData}
|
||||||
projectId={selectedProject}
|
|
||||||
setshowOnlyCheckout={setShowPending}
|
|
||||||
showOnlyCheckout={showPending}
|
|
||||||
searchQuery={searchQuery}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{activeTab === "regularization" && DoRegularized && (
|
{activeTab === "regularization" && DoRegularized && (
|
||||||
<div className="tab-pane fade show active py-0">
|
<div className="tab-pane fade show active py-0">
|
||||||
<Regularization
|
<Regularization />
|
||||||
handleRequest={handleSubmit}
|
|
||||||
searchQuery={searchQuery}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!attLoading && !attendances && <span>Not Found</span>}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -257,7 +257,7 @@ const DirectoryPageHeader = ({
|
|||||||
<ul className="nav nav-tabs mb-0" role="tablist">
|
<ul className="nav nav-tabs mb-0" role="tablist">
|
||||||
<li className="nav-item" role="presentation">
|
<li className="nav-item" role="presentation">
|
||||||
<button
|
<button
|
||||||
className={`nav-link ${viewType === "notes" ? "active" : ""} fs-6`}
|
className={`nav-link ${viewType === "notes" ? "active" : ""}`}
|
||||||
onClick={() => setViewType("notes")}
|
onClick={() => setViewType("notes")}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
@ -266,9 +266,8 @@ const DirectoryPageHeader = ({
|
|||||||
</li>
|
</li>
|
||||||
<li className="nav-item" role="presentation">
|
<li className="nav-item" role="presentation">
|
||||||
<button
|
<button
|
||||||
// Corrected: Apply 'active' if viewType is either 'card' or 'list'
|
className={`nav-link ${viewType === "card" ? "active" : ""}`}
|
||||||
className={`nav-link ${viewType === "card" || viewType === "list" ? "active" : ""} fs-6`}
|
onClick={() => setViewType("card")}
|
||||||
onClick={() => setViewType("card")} // You might want to default to 'card' when switching to contacts
|
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<i className="bx bx-user me-1"></i> Contacts
|
<i className="bx bx-user me-1"></i> Contacts
|
||||||
@ -280,7 +279,7 @@ const DirectoryPageHeader = ({
|
|||||||
<hr className="my-0 mb-2" style={{ borderTop: "1px solid #dee2e6" }} />
|
<hr className="my-0 mb-2" style={{ borderTop: "1px solid #dee2e6" }} />
|
||||||
|
|
||||||
<div className="row mx-0 px-0 align-items-center mt-2">
|
<div className="row mx-0 px-0 align-items-center mt-2">
|
||||||
<div className="col-12 col-md-6 mb-2 px-1 d-flex align-items-center gap-2">
|
<div className="col-12 col-md-6 mb-2 px-5 d-flex align-items-center gap-4">
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="search"
|
type="search"
|
||||||
@ -299,7 +298,7 @@ const DirectoryPageHeader = ({
|
|||||||
data-bs-toggle="dropdown"
|
data-bs-toggle="dropdown"
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
>
|
>
|
||||||
<i className={`bx bx-slider-alt ${notesFilterCount > 0 ? "text-primary" : "text-muted"}`}></i>
|
<i className={`fa-solid fa-filter ms-1 fs-5 ${notesFilterCount > 0 ? "text-primary" : "text-muted"}`}></i>
|
||||||
{notesFilterCount > 0 && (
|
{notesFilterCount > 0 && (
|
||||||
<span className="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-warning" style={{ fontSize: "0.4rem" }}>
|
<span className="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-warning" style={{ fontSize: "0.4rem" }}>
|
||||||
{notesFilterCount}
|
{notesFilterCount}
|
||||||
@ -405,17 +404,17 @@ const DirectoryPageHeader = ({
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`btn btn-sm p-1 ${viewType === "card" ? "btn-primary" : "btn-outline-primary"}`}
|
className={`btn btn-xs ${viewType === "card" ? "btn-primary" : "btn-outline-primary"}`}
|
||||||
onClick={() => setViewType("card")}
|
onClick={() => setViewType("card")}
|
||||||
>
|
>
|
||||||
<i className="bx bx-grid-alt"></i>
|
<i className="bx bx-grid-alt"></i>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`btn btn-sm p-1 ${viewType === "list" ? "btn-primary" : "btn-outline-primary"}`}
|
className={`btn btn-xs ${viewType === "list" ? "btn-primary" : "btn-outline-primary"}`}
|
||||||
onClick={() => setViewType("list")}
|
onClick={() => setViewType("list")}
|
||||||
>
|
>
|
||||||
<i className="bx bx-list-ul"></i>
|
<i className="bx bx-list-ul me-1"></i>
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -423,13 +422,13 @@ const DirectoryPageHeader = ({
|
|||||||
|
|
||||||
{/* Filter by funnel icon for Contacts view (retains numerical badge) */}
|
{/* Filter by funnel icon for Contacts view (retains numerical badge) */}
|
||||||
{viewType !== "notes" && (
|
{viewType !== "notes" && (
|
||||||
<div className="dropdown" style={{ width: "fit-content" }}>
|
<div className="dropdown-center" style={{ width: "fit-content" }}>
|
||||||
<a
|
<a
|
||||||
className="dropdown-toggle hide-arrow cursor-pointer d-flex align-items-center position-relative"
|
className="dropdown-toggle hide-arrow cursor-pointer d-flex align-items-center position-relative"
|
||||||
data-bs-toggle="dropdown"
|
data-bs-toggle="dropdown"
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
>
|
>
|
||||||
<i className={`bx bx-slider-alt ${filtered > 0 ? "text-primary" : "text-muted"}`}></i>
|
<i className={`fa-solid fa-filter ms-1 fs-5 ${filtered > 0 ? "text-primary" : "text-muted"}`}></i>
|
||||||
{filtered > 0 && (
|
{filtered > 0 && (
|
||||||
<span className="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-warning" style={{ fontSize: "0.4rem" }}>
|
<span className="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-warning" style={{ fontSize: "0.4rem" }}>
|
||||||
{filtered}
|
{filtered}
|
||||||
|
|||||||
@ -320,7 +320,7 @@ useEffect(() => {
|
|||||||
{isFilterPanelOpen ? (
|
{isFilterPanelOpen ? (
|
||||||
<i className="fa-solid fa-times fs-5" />
|
<i className="fa-solid fa-times fs-5" />
|
||||||
) : (
|
) : (
|
||||||
<i className="bx bx-slider-alt ms-1" />
|
<i className="fa-solid fa-filter ms-1 fs-5" />
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
<div className="activity-section">
|
<div className="activity-section">
|
||||||
@ -394,7 +394,7 @@ useEffect(() => {
|
|||||||
>
|
>
|
||||||
{batch.documents.map((d, i) => {
|
{batch.documents.map((d, i) => {
|
||||||
const hoverDate = moment(d.uploadedAt).format(
|
const hoverDate = moment(d.uploadedAt).format(
|
||||||
"DD MMMM, YYYY"
|
"DD-MM-YYYY"
|
||||||
);
|
);
|
||||||
const hoverTime = moment(d.uploadedAt).format(
|
const hoverTime = moment(d.uploadedAt).format(
|
||||||
"hh:mm A"
|
"hh:mm A"
|
||||||
|
|||||||
@ -480,7 +480,7 @@ const EmployeeList = () => {
|
|||||||
aria-label="User: activate to sort column ascending"
|
aria-label="User: activate to sort column ascending"
|
||||||
aria-sort="descending"
|
aria-sort="descending"
|
||||||
>
|
>
|
||||||
<div className="text-start ms-5">Official Designation</div>
|
<div className="text-start ms-5">Role</div>
|
||||||
</th>
|
</th>
|
||||||
|
|
||||||
<th
|
<th
|
||||||
|
|||||||
@ -146,7 +146,7 @@ const EmployeeProfile = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="fw-medium text-start text-nowrap">
|
<td className="fw-medium text-start">
|
||||||
Phone Number:
|
Phone Number:
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
@ -154,21 +154,26 @@ const EmployeeProfile = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="fw-medium text-start" style={{ width: '120px' }}>
|
<td className="fw-medium text-start">
|
||||||
Emergency Contact Person:
|
Emergency Contact Person:
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start align-bottom">
|
<td className="text-start">
|
||||||
{currentEmployee?.emergencyContactPerson || <em>NA</em>}
|
{currentEmployee?.emergencyContactPerson || (
|
||||||
|
<em>NA</em>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="fw-medium text-start">
|
<td className="fw-medium text-start">
|
||||||
Emergency Contact Number:
|
Emergency Contact Number:
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start align-bottom">
|
<td className="text-start">
|
||||||
{currentEmployee?.emergencyPhoneNumber || <em>NA</em>}
|
{currentEmployee?.emergencyPhoneNumber || (
|
||||||
|
<em>NA</em>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td className="fw-medium text-start">
|
<td className="fw-medium text-start">
|
||||||
Gender:
|
Gender:
|
||||||
@ -215,14 +220,15 @@ const EmployeeProfile = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="fw-medium text-start align-top" >
|
<td className="fw-medium text-start">
|
||||||
Address:
|
Address:
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
{currentEmployee?.currentAddress || <em>NA</em>}
|
{currentEmployee?.currentAddress || (
|
||||||
|
<em>NA</em>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import {
|
|||||||
cacheData,
|
cacheData,
|
||||||
clearCacheKey,
|
clearCacheKey,
|
||||||
getCachedData,
|
getCachedData,
|
||||||
useSelectedproject,
|
|
||||||
} from "../../slices/apiDataManager";
|
} from "../../slices/apiDataManager";
|
||||||
import "./ProjectDetails.css";
|
import "./ProjectDetails.css";
|
||||||
import {
|
import {
|
||||||
@ -29,7 +28,8 @@ import { setProjectId } from "../../slices/localVariablesSlice";
|
|||||||
|
|
||||||
const ProjectDetails = () => {
|
const ProjectDetails = () => {
|
||||||
|
|
||||||
const projectId = useSelectedproject()
|
|
||||||
|
const projectId = useSelector((store) => store.localVariables.projectId);
|
||||||
|
|
||||||
const { projectNames, fetchData } = useProjectName();
|
const { projectNames, fetchData } = useProjectName();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
@ -47,10 +47,9 @@ const ProjectDetails = () => {
|
|||||||
refetch,
|
refetch,
|
||||||
} = useProjectDetails(projectId);
|
} = useProjectDetails(projectId);
|
||||||
|
|
||||||
// const [activePill, setActivePill] = useState("profile");
|
const [activePill, setActivePill] = useState("profile");
|
||||||
const [activePill, setActivePill] = useState(() => {
|
|
||||||
return localStorage.getItem("lastActiveProjectTab") || "profile";
|
|
||||||
});
|
|
||||||
|
|
||||||
const handler = useCallback(
|
const handler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
@ -68,10 +67,8 @@ const ProjectDetails = () => {
|
|||||||
|
|
||||||
const handlePillClick = (pillKey) => {
|
const handlePillClick = (pillKey) => {
|
||||||
setActivePill(pillKey);
|
setActivePill(pillKey);
|
||||||
localStorage.setItem("lastActiveProjectTab", pillKey); // ✅ Save to localStorage
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const renderContent = () => {
|
const renderContent = () => {
|
||||||
if (projectLoading || !projects_Details) return <Loader />;
|
if (projectLoading || !projects_Details) return <Loader />;
|
||||||
|
|
||||||
|
|||||||
@ -192,7 +192,7 @@ const ProjectList = () => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="dropdown mt-1">
|
<div className="dropdown ms-3 mt-1">
|
||||||
<a
|
<a
|
||||||
className="dropdown-toggle hide-arrow cursor-pointer p-1 mt-3 "
|
className="dropdown-toggle hide-arrow cursor-pointer p-1 mt-3 "
|
||||||
data-bs-toggle="dropdown"
|
data-bs-toggle="dropdown"
|
||||||
@ -200,7 +200,7 @@ const ProjectList = () => {
|
|||||||
data-bs-custom-class="tooltip"
|
data-bs-custom-class="tooltip"
|
||||||
title="Filter"
|
title="Filter"
|
||||||
>
|
>
|
||||||
<i className="bx bx-slider-alt ms-1"></i>
|
<i className="fa-solid fa-filter fs-4"></i>
|
||||||
</a>
|
</a>
|
||||||
<ul className="dropdown-menu p-2 text-capitalize">
|
<ul className="dropdown-menu p-2 text-capitalize">
|
||||||
{[
|
{[
|
||||||
@ -269,10 +269,10 @@ const ProjectList = () => {
|
|||||||
<div className="card cursor-pointer">
|
<div className="card cursor-pointer">
|
||||||
<div className="card-body p-2">
|
<div className="card-body p-2">
|
||||||
<div
|
<div
|
||||||
className="table-responsive text-nowrap py-2 mx-2"
|
className="table-responsive text-nowrap py-2 "
|
||||||
style={{ minHeight: "200px" }}
|
style={{ minHeight: "400px" }}
|
||||||
>
|
>
|
||||||
<table className="table m-0">
|
<table className="table m-3">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th className="text-start" colSpan={5}>
|
<th className="text-start" colSpan={5}>
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { api } from "../utils/axiosClient";
|
|||||||
|
|
||||||
export const DirectoryRepository = {
|
export const DirectoryRepository = {
|
||||||
GetOrganizations: () => api.get("/api/directory/organization"),
|
GetOrganizations: () => api.get("/api/directory/organization"),
|
||||||
GetDesignations: () => api.get("/api/directory/designations"),
|
|
||||||
GetContacts: (isActive, projectId) => {
|
GetContacts: (isActive, projectId) => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.append("active", isActive);
|
params.append("active", isActive);
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import {
|
|||||||
flushApiCache,
|
flushApiCache,
|
||||||
} from "../slices/apiCacheSlice";
|
} from "../slices/apiCacheSlice";
|
||||||
import {setLoginUserPermmisions} from "./globalVariablesSlice";
|
import {setLoginUserPermmisions} from "./globalVariablesSlice";
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
|
|
||||||
|
|
||||||
// Cache data
|
// Cache data
|
||||||
@ -38,16 +37,3 @@ export const cacheProfileData = ( data) => {
|
|||||||
export const getCachedProfileData = () => {
|
export const getCachedProfileData = () => {
|
||||||
return store.getState().globalVariables.loginUser;
|
return store.getState().globalVariables.loginUser;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSelectedproject = () => {
|
|
||||||
const selectedProject = useSelector((store)=> store.localVariables.projectId);
|
|
||||||
var project = localStorage.getItem("project");
|
|
||||||
if(project){
|
|
||||||
return project
|
|
||||||
} else{
|
|
||||||
return selectedProject
|
|
||||||
}
|
|
||||||
// return project ? selectedProject
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
@ -21,9 +21,7 @@ const localVariablesSlice = createSlice({
|
|||||||
state.regularizationCount = action.payload;
|
state.regularizationCount = action.payload;
|
||||||
},
|
},
|
||||||
setProjectId: (state, action) => {
|
setProjectId: (state, action) => {
|
||||||
localStorage.setItem("project",null)
|
|
||||||
state.projectId = action.payload;
|
state.projectId = action.payload;
|
||||||
localStorage.setItem("project",state.projectId)
|
|
||||||
},
|
},
|
||||||
refreshData: ( state, action ) =>
|
refreshData: ( state, action ) =>
|
||||||
{
|
{
|
||||||
|
|||||||
@ -68,7 +68,7 @@ export const formatNumber = (num) => {
|
|||||||
return Number.isInteger(num) ? num : num.toFixed(2);
|
return Number.isInteger(num) ? num : num.toFixed(2);
|
||||||
};
|
};
|
||||||
export const formatUTCToLocalTime = (datetime) =>{
|
export const formatUTCToLocalTime = (datetime) =>{
|
||||||
return moment.utc(datetime).local().format("DD MMMM, YYYY [at] hh:mm A");
|
return moment.utc(datetime).local().format("MMMM DD, YYYY [at] hh:mm A");
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getCompletionPercentage = (completedWork, plannedWork)=> {
|
export const getCompletionPercentage = (completedWork, plannedWork)=> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user