Refactor_Expenses #321
@ -27,6 +27,7 @@
|
|||||||
<link rel="stylesheet" href="/assets/vendor/css/theme-default.css" class="template-customizer-theme-css" />
|
<link rel="stylesheet" href="/assets/vendor/css/theme-default.css" class="template-customizer-theme-css" />
|
||||||
<link rel="stylesheet" href="/assets/css/core-extend.css" />
|
<link rel="stylesheet" href="/assets/css/core-extend.css" />
|
||||||
<link rel="stylesheet" href="/assets/css/default.css" />
|
<link rel="stylesheet" href="/assets/css/default.css" />
|
||||||
|
<link rel="stylesheet" href="/assets/css/skeleton.css" />
|
||||||
|
|
||||||
<link rel="stylesheet" href="/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />
|
<link rel="stylesheet" href="/assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />
|
||||||
|
|
||||||
|
|||||||
32
public/assets/css/skeleton.css
vendored
Normal file
32
public/assets/css/skeleton.css
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* skeleton.css */
|
||||||
|
.skeleton {
|
||||||
|
background-color: #e2e8f0; /* Tailwind's gray-300 */
|
||||||
|
border-radius: 0.25rem; /* Tailwind's rounded */
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skeleton::after {
|
||||||
|
content: '';
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 0; left: -150px;
|
||||||
|
height: 100%;
|
||||||
|
width: 150px;
|
||||||
|
background: linear-gradient(
|
||||||
|
90deg,
|
||||||
|
transparent,
|
||||||
|
rgba(255, 255, 255, 0.4),
|
||||||
|
transparent
|
||||||
|
);
|
||||||
|
animation: pulse 1.5s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse {
|
||||||
|
0% {
|
||||||
|
left: -150px;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
left: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,9 +4,30 @@ const FabContext = createContext();
|
|||||||
|
|
||||||
export const FabProvider = ({ children }) => {
|
export const FabProvider = ({ children }) => {
|
||||||
const [actions, setActions] = useState([]);
|
const [actions, setActions] = useState([]);
|
||||||
|
const [showTrigger, setShowTrigger] = useState(true);
|
||||||
|
const [isOffcanvasOpen, setIsOffcanvasOpen] = useState(false);
|
||||||
|
const [offcanvas, setOffcanvas] = useState({
|
||||||
|
isOpen: false,
|
||||||
|
title: "",
|
||||||
|
content: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const openOffcanvas = (title, content) => {
|
||||||
|
setOffcanvas({ isOpen: true, title, content });
|
||||||
|
setTimeout(() => {
|
||||||
|
const offcanvasElement = document.getElementById("globalOffcanvas");
|
||||||
|
if (offcanvasElement) {
|
||||||
|
const bsOffcanvas = new window.bootstrap.Offcanvas(offcanvasElement);
|
||||||
|
bsOffcanvas.show();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
};
|
||||||
|
const setOffcanvasContent = (title, content) => {
|
||||||
|
setOffcanvas(prev => ({ ...prev, title, content }));
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FabContext.Provider value={{ actions, setActions }}>
|
<FabContext.Provider value={{ actions, setActions, offcanvas, openOffcanvas, showTrigger, setShowTrigger,isOffcanvasOpen, setIsOffcanvasOpen, setOffcanvasContent, }}>
|
||||||
{children}
|
{children}
|
||||||
</FabContext.Provider>
|
</FabContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -6,34 +6,27 @@ 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";
|
import { useAttendance } from "../../hooks/useAttendance"; // This hook is already providing data
|
||||||
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 }) => {
|
const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedAttendanceFromParent, showOnlyCheckout, setshowOnlyCheckout }) => {
|
||||||
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);
|
} = useAttendance(selectedProject); // Keep this hook to manage recall and fetching status
|
||||||
const filteredAttendance = ShowPending
|
|
||||||
? attendance?.filter(
|
|
||||||
(att) => att?.checkInTime !== null && att?.checkOutTime === null
|
|
||||||
)
|
|
||||||
: attendance;
|
|
||||||
|
|
||||||
const attendanceList = Array.isArray(filteredAttendance)
|
const attendanceList = Array.isArray(filteredAndSearchedAttendanceFromParent)
|
||||||
? filteredAttendance
|
? filteredAndSearchedAttendanceFromParent
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const sortByName = (a, b) => {
|
const sortByName = (a, b) => {
|
||||||
@ -41,6 +34,7 @@ const Attendance = ({ getRole, handleModalData }) => {
|
|||||||
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);
|
||||||
@ -48,41 +42,39 @@ const Attendance = ({ getRole, handleModalData }) => {
|
|||||||
.filter((d) => d.activity === 0)
|
.filter((d) => d.activity === 0)
|
||||||
.sort(sortByName);
|
.sort(sortByName);
|
||||||
|
|
||||||
const filteredData = [...group1, ...group2];
|
const finalFilteredDataForPagination = [...group1, ...group2];
|
||||||
|
|
||||||
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
||||||
filteredData,
|
finalFilteredDataForPagination, // Use the data that's already been searched and grouped
|
||||||
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, attrecall]
|
[selectedProject, queryClient] // Added queryClient to dependencies
|
||||||
);
|
);
|
||||||
|
|
||||||
const employeeHandler = useCallback(
|
const employeeHandler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
if (attendances.some((item) => item.employeeId == msg.employeeId)) {
|
if (attrecall) { // Check if attrecall function exists
|
||||||
attrecall();
|
attrecall();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[selectedProject, attendance]
|
[attrecall] // Dependency should be attrecall, not `selectedProject` or `attendance` here
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
eventBus.on("attendance", handler);
|
eventBus.on("attendance", handler);
|
||||||
return () => eventBus.off("attendance", handler);
|
return () => eventBus.off("attendance", handler);
|
||||||
@ -105,13 +97,14 @@ const Attendance = ({ getRole, handleModalData }) => {
|
|||||||
role="switch"
|
role="switch"
|
||||||
id="inactiveEmployeesCheckbox"
|
id="inactiveEmployeesCheckbox"
|
||||||
disabled={isFetching}
|
disabled={isFetching}
|
||||||
checked={ShowPending}
|
checked={showOnlyCheckout} // Use prop for checked state
|
||||||
onChange={(e) => setShowPending(e.target.checked)}
|
onChange={(e) => setshowOnlyCheckout(e.target.checked)} // Use prop for onChange
|
||||||
/>
|
/>
|
||||||
<label className="form-check-label ms-0">Show Pending</label>
|
<label className="form-check-label ms-0">Show Pending</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{Array.isArray(attendance) && attendance.length > 0 ? (
|
{/* Use `filteredAndSearchedAttendanceFromParent` for the initial check of data presence */}
|
||||||
|
{Array.isArray(filteredAndSearchedAttendanceFromParent) && filteredAndSearchedAttendanceFromParent.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
<table className="table ">
|
<table className="table ">
|
||||||
<thead>
|
<thead>
|
||||||
@ -129,7 +122,7 @@ const Attendance = ({ getRole, handleModalData }) => {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="table-border-bottom-0 ">
|
<tbody className="table-border-bottom-0 ">
|
||||||
{currentItems &&
|
{currentItems && currentItems.length > 0 ? ( // Check currentItems length before mapping
|
||||||
currentItems
|
currentItems
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
const checkInA = a?.checkInTime
|
const checkInA = a?.checkInTime
|
||||||
@ -186,18 +179,22 @@ const Attendance = ({ getRole, handleModalData }) => {
|
|||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))
|
||||||
{!attendance && (
|
) : (
|
||||||
<span className="text-secondary m-4">No employees assigned to the project!</span>
|
<tr>
|
||||||
|
<td colSpan="6" className="text-center text-muted py-4">
|
||||||
|
No matching records found.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{!loading && filteredData.length > 20 && (
|
{!attLoading && finalFilteredDataForPagination.length > ITEMS_PER_PAGE && ( // Use the data before pagination for total count check
|
||||||
<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
|
||||||
className={`page-item ${
|
className={`page-item ${
|
||||||
currentPage === 1 ? "disabled" : ""
|
currentPage === 1 ? "disabled" : ""
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
@ -243,14 +240,16 @@ const Attendance = ({ getRole, handleModalData }) => {
|
|||||||
<div>Loading...</div>
|
<div>Loading...</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="text-muted">
|
<div className="text-muted">
|
||||||
{Array.isArray(attendance)
|
{/* Check the actual prop passed for initial data presence */}
|
||||||
? "No employees assigned to the project"
|
{Array.isArray(filteredAndSearchedAttendanceFromParent) && filteredAndSearchedAttendanceFromParent.length === 0
|
||||||
: "Attendance data unavailable"}
|
? ""
|
||||||
|
: "Attendance data unavailable."}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{currentItems?.length == 0 && attendance.length > 0 && (
|
{/* This condition should check `currentItems` or `finalFilteredDataForPagination` */}
|
||||||
<div className="my-4"><span className="text-secondary">No Pending Record Available !</span></div>
|
{currentItems?.length === 0 && finalFilteredDataForPagination.length > 0 && showOnlyCheckout && (
|
||||||
|
<div className="my-4"><span className="text-secondary">No Pending Record Available for your search!</span></div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -4,24 +4,31 @@ 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 } from "../../slices/apiSlice/attedanceLogsSlice";
|
import { fetchAttendanceData, setAttendanceData } 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 maxPage = Math.ceil(data.length / itemsPerPage);
|
const totalItems = Array.isArray(data) ? data.length : 0;
|
||||||
|
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) => setCurrentPage(pageNumber), []);
|
const paginate = useCallback((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 {
|
||||||
@ -35,60 +42,91 @@ 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 [loading, setLoading] = useState(false);
|
const { data, loading, error } = useSelector((store) => store.attendanceLogs);
|
||||||
const [showPending,setShowPending] = useState(false)
|
|
||||||
|
|
||||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||||
const [processedData, setProcessedData] = useState([]);
|
|
||||||
|
|
||||||
const today = new Date();
|
const today = useMemo(() => {
|
||||||
today.setHours(0, 0, 0, 0);
|
const d = new Date();
|
||||||
|
d.setHours(0, 0, 0, 0);
|
||||||
|
return d;
|
||||||
|
}, []);
|
||||||
|
|
||||||
const yesterday = new Date();
|
const yesterday = useMemo(() => {
|
||||||
yesterday.setDate(yesterday.getDate() - 1);
|
const d = new Date();
|
||||||
|
d.setDate(d.getDate() - 1);
|
||||||
|
return d;
|
||||||
|
}, []);
|
||||||
|
|
||||||
const isSameDay = (dateStr) => {
|
const isSameDay = useCallback((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 = (dateStr) => {
|
const isBeforeToday = useCallback((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 = (a, b) => {
|
const sortByName = useCallback((a, b) => {
|
||||||
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
const nameA = `${a.firstName || ""} ${a.lastName || ""}`.toLowerCase();
|
||||||
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
const nameB = `${b.firstName || ""} ${b.lastName || ""}`.toLowerCase();
|
||||||
return nameA?.localeCompare(nameB);
|
return nameA.localeCompare(nameB);
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
const {
|
useEffect(() => {
|
||||||
data = [],
|
const { startDate, endDate } = dateRange;
|
||||||
isLoading,
|
dispatch(
|
||||||
error,
|
fetchAttendanceData({
|
||||||
refetch,
|
projectId,
|
||||||
isFetching,
|
fromDate: startDate,
|
||||||
} = useAttendancesLogs(
|
toDate: endDate,
|
||||||
selectedProject,
|
})
|
||||||
dateRange.startDate,
|
);
|
||||||
dateRange.endDate
|
setIsRefreshing(false);
|
||||||
);
|
}, [dateRange, projectId, dispatch, isRefreshing]);
|
||||||
const filtering = (data) => {
|
|
||||||
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);
|
||||||
@ -127,53 +165,46 @@ 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)
|
||||||
);
|
);
|
||||||
|
|
||||||
const finalData = sortedDates.flatMap((date) => groupedByDate[date]);
|
// Create the final sorted array
|
||||||
setProcessedData(finalData);
|
return sortedDates.flatMap((date) => groupedByDate[date]);
|
||||||
};
|
}, [data, showOnlyCheckout, searchQuery, isSameDay, isBeforeToday, sortByName]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
filtering(data);
|
|
||||||
}, [data, showPending]);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
currentPage,
|
currentPage,
|
||||||
totalPages,
|
totalPages,
|
||||||
currentItems: paginatedAttendances,
|
currentItems: paginatedAttendances,
|
||||||
paginate,
|
paginate,
|
||||||
resetPage,
|
resetPage, // Destructure resetPage here
|
||||||
} = usePagination(processedData, 20);
|
} = usePagination(processedData, 20);
|
||||||
|
|
||||||
|
// Effect to reset pagination when search query changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resetPage();
|
resetPage();
|
||||||
}, [processedData, resetPage]);
|
}, [searchQuery, resetPage]); // Add resetPage to dependencies
|
||||||
|
|
||||||
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 (
|
||||||
selectedProject === msg.projectId &&
|
projectId === msg.projectId &&
|
||||||
startDate <= checkIn &&
|
startDate <= checkIn &&
|
||||||
checkIn <= endDate
|
checkIn <= endDate
|
||||||
) {
|
) {
|
||||||
queryClient.setQueriesData(["attendanceLogs"],(oldData)=>{
|
const updatedAttendance = data.map((item) =>
|
||||||
if(!oldData) {
|
item.id === msg.response.id
|
||||||
queryClient.invalidateQueries({queryKey:["attendanceLogs"]})
|
? { ...item, ...msg.response }
|
||||||
}
|
: item
|
||||||
return oldData.map((record) =>
|
|
||||||
record.id === msg.response.id ? { ...record, ...msg.response } : record
|
|
||||||
);
|
);
|
||||||
})
|
dispatch(setAttendanceData(updatedAttendance)); // Update Redux store
|
||||||
|
|
||||||
filtering(updatedAttendance);
|
|
||||||
resetPage();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[selectedProject, dateRange, data, filtering, resetPage]
|
[projectId, dateRange, data, dispatch]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -184,19 +215,15 @@ const AttendanceLog = ({
|
|||||||
const employeeHandler = useCallback(
|
const employeeHandler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const { startDate, endDate } = dateRange;
|
const { startDate, endDate } = dateRange;
|
||||||
if (data.some((item) => item.employeeId == msg.employeeId)) {
|
dispatch(
|
||||||
// dispatch(
|
fetchAttendanceData({
|
||||||
// fetchAttendanceData({
|
projectId,
|
||||||
// ,
|
fromDate: startDate,
|
||||||
// fromDate: startDate,
|
toDate: endDate,
|
||||||
// toDate: endDate,
|
})
|
||||||
// })
|
);
|
||||||
// );
|
|
||||||
|
|
||||||
refetch()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[selectedProject, dateRange, data]
|
[projectId, dateRange, dispatch]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -220,28 +247,27 @@ 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={showPending}
|
checked={showOnlyCheckout}
|
||||||
onChange={(e) => setShowPending(e.target.checked)}
|
onChange={(e) => setshowOnlyCheckout(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 ${
|
className={`bx bx-refresh cursor-pointer fs-4 ${loading || isRefreshing ? "spin" : ""
|
||||||
isFetching ? "spin" : ""
|
}`}
|
||||||
}`}
|
|
||||||
title="Refresh"
|
title="Refresh"
|
||||||
onClick={() => refetch()}
|
onClick={() => setIsRefreshing(true)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="table-responsive text-nowrap">
|
<div
|
||||||
{isLoading ? (
|
className="table-responsive text-nowrap"
|
||||||
<div><p className="text-secondary">Loading...</p></div>
|
style={{ minHeight: "200px", display: 'flex' }}
|
||||||
) : data?.length > 0 ? (
|
>
|
||||||
|
{processedData && processedData.length > 0 ? (
|
||||||
<table className="table mb-0">
|
<table className="table mb-0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -260,82 +286,96 @@ const AttendanceLog = ({
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{paginatedAttendances.reduce((acc, attendance, index, arr) => {
|
{(loading || isRefreshing) && (
|
||||||
const currentDate = moment(
|
<tr>
|
||||||
attendance.checkInTime || attendance.checkOutTime
|
<td colSpan={6}>Loading...</td>
|
||||||
).format("YYYY-MM-DD");
|
</tr>
|
||||||
const previousAttendance = arr[index - 1];
|
)}
|
||||||
const previousDate = previousAttendance
|
{!loading &&
|
||||||
? moment(
|
!isRefreshing &&
|
||||||
|
paginatedAttendances.reduce((acc, attendance, index, arr) => {
|
||||||
|
const currentDate = moment(
|
||||||
|
attendance.checkInTime || attendance.checkOutTime
|
||||||
|
).format("YYYY-MM-DD");
|
||||||
|
const previousAttendance = arr[index - 1];
|
||||||
|
const previousDate = previousAttendance
|
||||||
|
? moment(
|
||||||
previousAttendance.checkInTime ||
|
previousAttendance.checkInTime ||
|
||||||
previousAttendance.checkOutTime
|
previousAttendance.checkOutTime
|
||||||
).format("YYYY-MM-DD")
|
).format("YYYY-MM-DD")
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (!previousDate || currentDate !== previousDate) {
|
if (!previousDate || currentDate !== previousDate) {
|
||||||
|
acc.push(
|
||||||
|
<tr
|
||||||
|
key={`header-${currentDate}`}
|
||||||
|
className="table-row-header"
|
||||||
|
>
|
||||||
|
<td colSpan={6} className="text-start">
|
||||||
|
<strong>
|
||||||
|
{moment(currentDate).format("DD-MM-YYYY")}
|
||||||
|
</strong>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
}
|
||||||
acc.push(
|
acc.push(
|
||||||
<tr
|
<tr key={attendance.id || index}>
|
||||||
key={`header-${currentDate}`}
|
<td colSpan={2}>
|
||||||
className="table-row-header"
|
<div className="d-flex justify-content-start align-items-center">
|
||||||
>
|
<Avatar
|
||||||
<td colSpan={6} className="text-start">
|
firstName={attendance.firstName}
|
||||||
<strong>
|
lastName={attendance.lastName}
|
||||||
{moment(currentDate).format("DD-MM-YYYY")}
|
/>
|
||||||
</strong>
|
<div className="d-flex flex-column">
|
||||||
|
<a href="#" className="text-heading text-truncate">
|
||||||
|
<span className="fw-normal">
|
||||||
|
{attendance.firstName} {attendance.lastName}
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{moment(
|
||||||
|
attendance.checkInTime || attendance.checkOutTime
|
||||||
|
).format("DD-MMM-YYYY")}
|
||||||
|
</td>
|
||||||
|
<td>{convertShortTime(attendance.checkInTime)}</td>
|
||||||
|
<td>
|
||||||
|
{attendance.checkOutTime
|
||||||
|
? convertShortTime(attendance.checkOutTime)
|
||||||
|
: "--"}
|
||||||
|
</td>
|
||||||
|
<td className="text-center">
|
||||||
|
<RenderAttendanceStatus
|
||||||
|
attendanceData={attendance}
|
||||||
|
handleModalData={handleModalData}
|
||||||
|
Tab={2}
|
||||||
|
currentDate={today.toLocaleDateString("en-CA")}
|
||||||
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
return acc;
|
||||||
acc.push(
|
}, [])}
|
||||||
<tr key={index}>
|
|
||||||
<td colSpan={2}>
|
|
||||||
<div className="d-flex justify-content-start align-items-center">
|
|
||||||
<Avatar
|
|
||||||
firstName={attendance.firstName}
|
|
||||||
lastName={attendance.lastName}
|
|
||||||
/>
|
|
||||||
<div className="d-flex flex-column">
|
|
||||||
<a href="#" className="text-heading text-truncate">
|
|
||||||
<span className="fw-normal">
|
|
||||||
{attendance.firstName} {attendance.lastName}
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{moment(
|
|
||||||
attendance.checkInTime || attendance.checkOutTime
|
|
||||||
).format("DD-MMM-YYYY")}
|
|
||||||
</td>
|
|
||||||
<td>{convertShortTime(attendance.checkInTime)}</td>
|
|
||||||
<td>
|
|
||||||
{attendance.checkOutTime
|
|
||||||
? convertShortTime(attendance.checkOutTime)
|
|
||||||
: "--"}
|
|
||||||
</td>
|
|
||||||
<td className="text-center">
|
|
||||||
<RenderAttendanceStatus
|
|
||||||
attendanceData={attendance}
|
|
||||||
handleModalData={handleModalData}
|
|
||||||
Tab={2}
|
|
||||||
currentDate={today.toLocaleDateString("en-CA")}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
return acc;
|
|
||||||
}, [])}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
) : (
|
) : (
|
||||||
<div className="my-4"><span className="text-secondary">No Record Available !</span></div>
|
!loading &&
|
||||||
|
!isRefreshing && (
|
||||||
|
<div
|
||||||
|
className="d-flex justify-content-center align-items-center text-muted"
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
No employee logs.
|
||||||
|
</div>
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{paginatedAttendances?.length == 0 && data?.length > 0 && (
|
{!loading && !isRefreshing && processedData.length > 20 && (
|
||||||
<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" : ""}`}>
|
||||||
@ -350,9 +390,8 @@ const AttendanceLog = ({
|
|||||||
(pageNumber) => (
|
(pageNumber) => (
|
||||||
<li
|
<li
|
||||||
key={pageNumber}
|
key={pageNumber}
|
||||||
className={`page-item ${
|
className={`page-item ${currentPage === pageNumber ? "active" : ""
|
||||||
currentPage === pageNumber ? "active" : ""
|
}`}
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link"
|
className="page-link"
|
||||||
@ -364,9 +403,8 @@ const AttendanceLog = ({
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${
|
className={`page-item ${currentPage === totalPages ? "disabled" : ""
|
||||||
currentPage === totalPages ? "disabled" : ""
|
}`}
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link"
|
className="page-link"
|
||||||
|
|||||||
@ -11,10 +11,43 @@ 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" }),
|
// markTime: z.string().nonempty({ message: "Time is required" }),
|
||||||
description: z.string().max(200, "description should less than 200 chracters").optional()
|
// 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" }),
|
||||||
|
description: z
|
||||||
|
.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, }) => {
|
||||||
|
|
||||||
@ -33,38 +66,38 @@ 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,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
reset,
|
reset,
|
||||||
setValue,
|
setValue,
|
||||||
} = useForm({
|
} = useForm({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(createSchema(modeldata)),
|
||||||
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 || modeldata.forWhichTab === 2) {
|
if (modeldata.forWhichTab === 1) {
|
||||||
// handleSubmitForm(record)
|
handleSubmitForm(record)
|
||||||
const payload = {
|
} else {
|
||||||
Id: modeldata?.id || null,
|
|
||||||
comment: data.description,
|
dispatch(markAttendance(record))
|
||||||
employeeID: modeldata.employeeId,
|
.unwrap()
|
||||||
projectId: projectId,
|
.then((data) => {
|
||||||
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");
|
||||||
// })
|
// })
|
||||||
@ -72,8 +105,8 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
|
|
||||||
// showToast(error, "error");
|
// showToast(error, "error");
|
||||||
|
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
closeModal()
|
closeModal()
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,63 +7,37 @@ 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, clearCacheKey } from "../../slices/apiDataManager";
|
import { cacheData } from "../../slices/apiDataManager";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
|
||||||
|
|
||||||
const Regularization = ({ handleRequest }) => {
|
const Regularization = ({ handleRequest, searchQuery }) => {
|
||||||
const queryClient = useQueryClient();
|
const selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||||
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
const [regularizesList, setRegularizedList] = useState([]);
|
||||||
const [regularizesList, setregularizedList] = useState([]);
|
const { regularizes, loading, refetch } = useRegularizationRequests(selectedProject);
|
||||||
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.toLowerCase() + a.lastName.toLowerCase();
|
const nameA = (a.firstName + a.lastName).toLowerCase();
|
||||||
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
const nameB = (b.firstName + 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(
|
const updatedAttendance = regularizes?.filter(item => item.id !== msg.response.id);
|
||||||
// (item) => item.id !== msg.response.id
|
cacheData("regularizedList", {
|
||||||
// );
|
data: updatedAttendance,
|
||||||
// cacheData("regularizedList", {
|
projectId: selectedProject,
|
||||||
// data: updatedAttendance,
|
});
|
||||||
// projectId: selectedProject,
|
refetch();
|
||||||
// });
|
|
||||||
// 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) => {
|
||||||
@ -74,41 +48,57 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
[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 ? (
|
<table className="table mb-0">
|
||||||
<div className="my-2">
|
<thead>
|
||||||
<p className="text-secondary">Loading...</p>
|
<tr>
|
||||||
</div>
|
<th colSpan={2}>Name</th>
|
||||||
) : currentItems?.length > 0 ? (
|
<th>Date</th>
|
||||||
<table className="table mb-0">
|
<th>
|
||||||
<thead>
|
<i className="bx bxs-down-arrow-alt text-success"></i>Check-In
|
||||||
<tr>
|
</th>
|
||||||
<th colSpan={2}>Name</th>
|
<th>
|
||||||
<th>Date</th>
|
<i className="bx bxs-up-arrow-alt text-danger"></i>Check-Out
|
||||||
<th>
|
</th>
|
||||||
<i className="bx bxs-down-arrow-alt text-success"></i>Check-In
|
<th>Action</th>
|
||||||
</th>
|
</tr>
|
||||||
<th>
|
</thead>
|
||||||
<i className="bx bxs-up-arrow-alt text-danger"></i>Check-Out
|
<tbody>
|
||||||
</th>
|
{!loading && currentItems?.length > 0 ? (
|
||||||
<th>Action</th>
|
currentItems.map((att, index) => (
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{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
|
<Avatar firstName={att.firstName} lastName={att.lastName} />
|
||||||
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">
|
||||||
@ -123,24 +113,33 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
<td>
|
<td>
|
||||||
{att.checkOutTime ? convertShortTime(att.checkOutTime) : "--"}
|
{att.checkOutTime ? convertShortTime(att.checkOutTime) : "--"}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-center ">
|
<td className="text-center">
|
||||||
<RegularizationActions
|
<RegularizationActions
|
||||||
attendanceData={att}
|
attendanceData={att}
|
||||||
handleRequest={handleRequest}
|
handleRequest={handleRequest}
|
||||||
refresh={refetch}
|
refresh={refetch}
|
||||||
/>
|
/>
|
||||||
{/* </div> */}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))
|
||||||
</tbody>
|
) : (
|
||||||
</table>
|
<tr>
|
||||||
) : (
|
<td
|
||||||
<div className="my-4">
|
colSpan={6}
|
||||||
{" "}
|
className="text-center"
|
||||||
<span className="text-secondary">No Requests Found !</span>
|
style={{
|
||||||
</div>
|
height: "200px",
|
||||||
)}
|
verticalAlign: "middle",
|
||||||
|
borderBottom: "none",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loading ? "Loading..." : "No Record Found"}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
{!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">
|
||||||
@ -155,25 +154,18 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
{[...Array(totalPages)].map((_, index) => (
|
{[...Array(totalPages)].map((_, index) => (
|
||||||
<li
|
<li
|
||||||
key={index}
|
key={index}
|
||||||
className={`page-item ${
|
className={`page-item ${currentPage === index + 1 ? "active" : ""}`}
|
||||||
currentPage === index + 1 ? "active" : ""
|
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<button
|
<button className="page-link" onClick={() => paginate(index + 1)}>
|
||||||
className="page-link "
|
|
||||||
onClick={() => paginate(index + 1)}
|
|
||||||
>
|
|
||||||
{index + 1}
|
{index + 1}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${
|
className={`page-item ${currentPage === totalPages ? "disabled" : ""}`}
|
||||||
currentPage === totalPages ? "disabled" : ""
|
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link "
|
className="page-link"
|
||||||
onClick={() => paginate(currentPage + 1)}
|
onClick={() => paginate(currentPage + 1)}
|
||||||
>
|
>
|
||||||
»
|
»
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React,{useEffect} from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import {
|
import {
|
||||||
useDashboardProjectsCardData,
|
useDashboardProjectsCardData,
|
||||||
@ -14,16 +14,25 @@ import ProjectCompletionChart from "./ProjectCompletionChart";
|
|||||||
import ProjectProgressChart from "./ProjectProgressChart";
|
import ProjectProgressChart from "./ProjectProgressChart";
|
||||||
import ProjectOverview from "../Project/ProjectOverview";
|
import ProjectOverview from "../Project/ProjectOverview";
|
||||||
import AttendanceOverview from "./AttendanceChart";
|
import AttendanceOverview from "./AttendanceChart";
|
||||||
|
import { useFab } from "../../Context/FabContext";
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
const { projectsCardData } = useDashboardProjectsCardData();
|
const { projectsCardData } = useDashboardProjectsCardData();
|
||||||
const { teamsCardData } = useDashboardTeamsCardData();
|
const { teamsCardData } = useDashboardTeamsCardData();
|
||||||
const { tasksCardData } = useDashboardTasksCardData();
|
const { tasksCardData } = useDashboardTasksCardData();
|
||||||
|
const {setShowTrigger} = useFab()
|
||||||
|
|
||||||
// Get the selected project ID from Redux store
|
// Get the selected project ID from Redux store
|
||||||
const projectId = useSelector((store) => store.localVariables.projectId);
|
const projectId = useSelector((store) => store.localVariables.projectId);
|
||||||
const isAllProjectsSelected = projectId === null;
|
const isAllProjectsSelected = projectId === null;
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setShowTrigger(false);
|
||||||
|
console.log("OffCanvas")
|
||||||
|
return () => setShowTrigger(true);
|
||||||
|
}, [setShowTrigger])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container-fluid mt-5">
|
<div className="container-fluid mt-5">
|
||||||
<div className="row gy-4">
|
<div className="row gy-4">
|
||||||
|
|||||||
@ -5,7 +5,6 @@ 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 ms-5">
|
<li className="list-inline-item text-break small px-1 ms-5">
|
||||||
{contact.organization}
|
{contact.organization}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={`card-footer text-start px-1 py-1 ${IsActive && "cursor-pointer"
|
className={`card-footer text-start px-9 py-1 ${IsActive && "cursor-pointer"
|
||||||
}`}
|
}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (IsActive) {
|
if (IsActive) {
|
||||||
@ -123,6 +123,16 @@ 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,6 +6,7 @@ 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,6 +15,10 @@ 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
|
||||||
@ -47,36 +51,38 @@ 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">
|
||||||
{contact.contactEmails.length > 0 ? (contact.contactEmails?.map((email, index) => (
|
{firstEmail ? (
|
||||||
<span key={email.id} className="text-truncate">
|
<span key={firstEmail.id} className="text-truncate">
|
||||||
<i
|
<i
|
||||||
className={getEmailIcon(email.label)}
|
className={getEmailIcon(firstEmail.label)}
|
||||||
style={{ fontSize: "12px" }}
|
style={{ fontSize: "12px" }}
|
||||||
></i>
|
></i>
|
||||||
<a
|
<a
|
||||||
href={`mailto:${email.emailAddress}`}
|
href={`mailto:${firstEmail.emailAddress}`}
|
||||||
className="text-decoration-none ms-1"
|
className="text-decoration-none ms-1"
|
||||||
>
|
>
|
||||||
{email.emailAddress}
|
{firstEmail.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">
|
||||||
{contact.contactPhones?.length > 0 ? (
|
{firstPhone ? (
|
||||||
contact.contactPhones?.map((phone, index) => (
|
<span key={firstPhone.id}>
|
||||||
<span key={phone.id}>
|
|
||||||
<i
|
<i
|
||||||
className={getPhoneIcon(phone.label)}
|
className={getPhoneIcon(firstPhone.label)}
|
||||||
style={{ fontSize: "12px" }}
|
style={{ fontSize: "12px" }}
|
||||||
></i>
|
></i>
|
||||||
<span className="ms-1">{phone.phoneNumber}</span>
|
<span className="ms-1">{firstPhone.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>
|
||||||
|
|
||||||
@ -88,12 +94,6 @@ 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"}
|
||||||
@ -118,9 +118,10 @@ const ListViewDirectory = ({
|
|||||||
)}
|
)}
|
||||||
{!IsActive && (
|
{!IsActive && (
|
||||||
<i
|
<i
|
||||||
className={`bx ${
|
className={`bx ${
|
||||||
dirActions.action && dirActions.id === contact.id ? "bx-loader-alt bx-spin"
|
dirActions.action && dirActions.id === contact.id
|
||||||
: "bx-recycle"
|
? "bx-loader-alt bx-spin"
|
||||||
|
: "bx-recycle"
|
||||||
} me-1 text-primary cursor-pointer`}
|
} me-1 text-primary cursor-pointer`}
|
||||||
title="Restore"
|
title="Restore"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
@ -14,7 +14,11 @@ 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 { useBuckets, useOrganization } from "../../hooks/useDirectory";
|
import {
|
||||||
|
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";
|
||||||
@ -33,8 +37,11 @@ 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({
|
||||||
@ -45,6 +52,7 @@ const ManageDirectory = ({ submitContact, onCLosed }) => {
|
|||||||
contactCategoryId: null,
|
contactCategoryId: null,
|
||||||
address: "",
|
address: "",
|
||||||
description: "",
|
description: "",
|
||||||
|
designation: "",
|
||||||
projectIds: [],
|
projectIds: [],
|
||||||
contactEmails: [],
|
contactEmails: [],
|
||||||
contactPhones: [],
|
contactPhones: [],
|
||||||
@ -106,6 +114,25 @@ 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)
|
||||||
@ -168,6 +195,55 @@ 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) => (
|
||||||
@ -381,13 +457,12 @@ 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">
|
||||||
{errors.bucketIds.message}
|
{errors.bucketIds.message}
|
||||||
</small>
|
</small>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -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("MMMM DD, YYYY [at] hh:mm A")}
|
.format("DD MMMM, YYYY [at] hh:mm A")}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@ 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";
|
||||||
@ -19,15 +18,17 @@ const schema = z.object({
|
|||||||
const NotesDirectory = ({
|
const NotesDirectory = ({
|
||||||
refetchProfile,
|
refetchProfile,
|
||||||
isLoading,
|
isLoading,
|
||||||
contactProfile,
|
contactProfile, // This contactProfile now reliably includes firstName, middleName, lastName, and fullName
|
||||||
setProfileContact,
|
setProfileContact,
|
||||||
}) => {
|
}) => {
|
||||||
const [IsActive, setIsActive] = useState(true);
|
const [IsActive, setIsActive] = useState(true);
|
||||||
const { contactNotes, refetch } = useContactNotes(contactProfile?.id, true);
|
const { contactNotes, refetch } = useContactNotes(
|
||||||
|
contactProfile?.id,
|
||||||
|
IsActive
|
||||||
|
);
|
||||||
|
|
||||||
const [NotesData, setNotesData] = useState();
|
|
||||||
const [IsSubmitting, setIsSubmitting] = useState(false);
|
const [IsSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [addNote, setAddNote] = useState(true);
|
const [showEditor, setShowEditor] = useState(false);
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -67,102 +68,122 @@ const NotesDirectory = ({
|
|||||||
) {
|
) {
|
||||||
const updatedProfile = {
|
const updatedProfile = {
|
||||||
...cached_contactProfile.data,
|
...cached_contactProfile.data,
|
||||||
notes: [...(cached_contactProfile.notes || []), createdNote],
|
notes: [...(cached_contactProfile.data.notes || []), createdNote],
|
||||||
};
|
};
|
||||||
cacheData("Contact Profile", updatedProfile);
|
cacheData("Contact Profile", {
|
||||||
|
contactId: contactProfile?.id,
|
||||||
|
data: updatedProfile,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue("note", "");
|
setValue("note", "");
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
showToast("Note added successfully!", "success");
|
showToast("Note added successfully!", "success");
|
||||||
setAddNote(true);
|
setShowEditor(false);
|
||||||
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 occured during API calling";
|
"Error occurred during API calling";
|
||||||
showToast(msg, "error");
|
showToast(msg, "error");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCancel = () => {
|
const onCancel = () => {
|
||||||
setValue( "note", "" );
|
setValue("note", "");
|
||||||
|
setShowEditor(false);
|
||||||
|
};
|
||||||
|
|
||||||
};
|
|
||||||
const handleSwitch = () => {
|
const handleSwitch = () => {
|
||||||
setIsActive(!IsActive);
|
setIsActive((prevIsActive) => {
|
||||||
if (IsActive) {
|
const newState = !prevIsActive;
|
||||||
refetch(contactProfile?.id, false);
|
refetch(contactProfile?.id, newState);
|
||||||
}
|
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">
|
<div className="text-start mt-10">
|
||||||
<div className="d-flex align-items-center justify-content-between">
|
<div className="d-flex align-items-center justify-content-between">
|
||||||
<p className="fw-semibold m-0">Notes :</p>
|
<div className="row w-100 align-items-center">
|
||||||
|
<div className="col col-2">
|
||||||
|
<p className="fw-semibold m-0 ms-3">Notes :</p>
|
||||||
|
</div>
|
||||||
|
<div className="col d-flex justify-content-end gap-2 pe-0">
|
||||||
|
{" "}
|
||||||
|
<div className="d-flex align-items-center justify-content-between">
|
||||||
|
<label
|
||||||
|
className="switch switch-primary"
|
||||||
|
style={{
|
||||||
|
visibility:
|
||||||
|
contactProfile?.notes?.length > 0 ||
|
||||||
|
contactNotes?.length > 0
|
||||||
|
? "visible"
|
||||||
|
: "hidden",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="switch-input"
|
||||||
|
onChange={() => handleSwitch(!IsActive)}
|
||||||
|
value={IsActive}
|
||||||
|
/>
|
||||||
|
<input type="checkbox" className="switch-input" />
|
||||||
|
<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>
|
||||||
|
|
||||||
|
{!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>
|
||||||
<div className="d-flex align-items-center justify-content-between mb-5">
|
|
||||||
<div className="m-0 d-flex align-items-center">
|
|
||||||
{contactNotes?.length > 0 ? (
|
|
||||||
<label className="switch switch-primary">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
className="switch-input"
|
|
||||||
onChange={() => handleSwitch(!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" />
|
|
||||||
<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>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="d-flex justify-content-end">
|
{showEditor && (
|
||||||
<span
|
<div className="card m-2 mb-5 position-relative">
|
||||||
className={`btn btn-sm ${addNote ? "btn-secondary" : "btn-primary"}`}
|
<span
|
||||||
onClick={() => setAddNote(!addNote)}
|
|
||||||
>
|
|
||||||
{addNote ? "Hide Editor" : "Add a Note"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
{addNote && (
|
|
||||||
<div className="card m-2 mb-5">
|
|
||||||
<button
|
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-close btn-secondary position-absolute top-0 end-0 m-2 mt-3 rounded-circle"
|
className="position-absolute top-0 end-0 mt-3 bg-secondary rounded-circle"
|
||||||
aria-label="Close"
|
aria-label="Close"
|
||||||
style={{ backgroundColor: "#eee", color: "white" }}
|
onClick={() => setShowEditor(false)}
|
||||||
onClick={() => setAddNote(!addNote)}
|
>
|
||||||
></button>
|
<i className="bx bx-x fs-5 p-1 text-white"></i>
|
||||||
{/* <div className="d-flex justify-content-end px-2">
|
</span>
|
||||||
<span
|
|
||||||
className={`btn btn-sm ${
|
|
||||||
addNote ? "btn-danger" : "btn-primary"
|
|
||||||
}`}
|
|
||||||
onClick={() => setAddNote(!addNote)}
|
|
||||||
>
|
|
||||||
{addNote ? "Hide Editor" : "Add Note"}
|
|
||||||
</span>
|
|
||||||
</div> */}
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<Editor
|
<Editor
|
||||||
value={noteValue}
|
value={noteValue}
|
||||||
@ -171,49 +192,39 @@ const NotesDirectory = ({
|
|||||||
onCancel={onCancel}
|
onCancel={onCancel}
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
/>
|
/>
|
||||||
{errors.notes && (
|
{errors.note && (
|
||||||
<p className="text-danger small mt-1">{errors.note.message}</p>
|
<p className="text-danger small mt-1">{errors.note.message}</p>
|
||||||
)}
|
)}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className=" justify-content-start px-1 mt-1">
|
<div className=" justify-content-start px-1 mt-1">
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
{" "}
|
{" "}
|
||||||
<p>Loading...</p>{" "}
|
<p>Loading...</p>{" "}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!isLoading &&
|
{!isLoading && notesToDisplay.length > 0
|
||||||
[...(IsActive ? contactProfile?.notes || [] : contactNotes || [])]
|
? notesToDisplay
|
||||||
.reverse()
|
.slice()
|
||||||
.map((noteItem) => (
|
.reverse()
|
||||||
<NoteCardDirectory
|
.map((noteItem) => (
|
||||||
refetchProfile={refetchProfile}
|
<NoteCardDirectory
|
||||||
refetchNotes={refetch}
|
refetchProfile={refetchProfile}
|
||||||
refetchContact={refetch}
|
refetchNotes={refetch}
|
||||||
noteItem={noteItem}
|
refetchContact={refetch}
|
||||||
contactId={contactProfile?.id}
|
noteItem={noteItem}
|
||||||
setProfileContact={setProfileContact}
|
contactId={contactProfile?.id}
|
||||||
key={noteItem.id}
|
setProfileContact={setProfileContact}
|
||||||
/>
|
key={noteItem.id}
|
||||||
))}
|
/>
|
||||||
|
))
|
||||||
{IsActive && (
|
: !isLoading &&
|
||||||
<div>
|
!showEditor && (
|
||||||
{!isLoading && contactProfile?.notes.length == 0 && !addNote && (
|
<div className="text-center mt-5">{noNotesMessage}</div>
|
||||||
<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,9 +8,10 @@ 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 [profileContact, setProfileContact] = useState();
|
const [profileContactState, setProfileContactState] = useState(null);
|
||||||
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);
|
||||||
@ -19,14 +20,51 @@ 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(() => {
|
||||||
setProfileContact(contactProfile);
|
if (contactProfile) {
|
||||||
}, [contactProfile]);
|
const names = (contact?.name || "").trim().split(" ");
|
||||||
|
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); // Reset after 2 seconds
|
setTimeout(() => setCopiedIndex(null), 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
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">
|
||||||
@ -47,31 +85,35 @@ 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">
|
||||||
{contactProfile?.tags?.map((tag) => tag.name).join(" | ")}
|
{profileContactState?.designation}
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="row">
|
<div className="row ms-9">
|
||||||
<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">
|
||||||
{contactProfile?.contactEmails?.length > 0 && (
|
{profileContactState?.contactEmails?.length > 0 && (
|
||||||
<div className="d-flex mb-2">
|
<div className="d-flex mb-2 align-items-start">
|
||||||
<div style={{ width: "100px", minWidth: "100px" }}>
|
<div
|
||||||
<p className="m-0">Email:</p>
|
className="d-flex align-items-start"
|
||||||
|
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">
|
||||||
{contactProfile.contactEmails.map((email, idx) => (
|
{profileContactState.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}>
|
||||||
<i className="bx bx-envelope bx-xs me-1 mt-1"></i>
|
<span className="me-1 text-break overflow-wrap">
|
||||||
<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 ${
|
className={`bx bx-copy-alt cursor-pointer bx-xs text-start ${copiedIndex === idx ? "text-secondary" : "text-primary"
|
||||||
copiedIndex === idx
|
}`}
|
||||||
? "text-secondary"
|
|
||||||
: "text-primary"
|
|
||||||
}`}
|
|
||||||
title={copiedIndex === idx ? "Copied!" : "Copy Email"}
|
title={copiedIndex === idx ? "Copied!" : "Copy Email"}
|
||||||
style={{ flexShrink: 0 }}
|
style={{ flexShrink: 0 }}
|
||||||
onClick={() => handleCopy(email.emailAddress, idx)}
|
onClick={() => handleCopy(email.emailAddress, idx)}
|
||||||
@ -83,17 +125,22 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{contactProfile?.contactPhones?.length > 0 && (
|
{profileContactState?.contactPhones?.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">Phone : </p>
|
<span className="d-flex align-items-center">
|
||||||
|
<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">
|
||||||
{contactProfile?.contactPhones.map((phone, idx) => (
|
{profileContactState.contactPhones.map((phone, idx) => (
|
||||||
<li className="list-inline-item me-3" key={idx}>
|
<li className="list-inline-item me-1" 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>
|
||||||
@ -101,74 +148,93 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{contactProfile?.createdAt && (
|
{profileContactState?.createdAt && (
|
||||||
<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">Created : </p>
|
<span className="d-flex align-items-center">
|
||||||
|
<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">
|
||||||
<li className="list-inline-item">
|
<span>
|
||||||
<i className="bx bx-calendar-week bx-xs me-1"></i>
|
{moment(profileContactState.createdAt).format("DD MMMM, YYYY")}
|
||||||
{moment(contactProfile.createdAt).format("MMMM, DD YYYY")}
|
</span>
|
||||||
</li>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{contactProfile?.address && (
|
|
||||||
<div className="d-flex mb-2">
|
{profileContactState?.address && (
|
||||||
<div style={{ width: "100px", minWidth: "100px" }}>
|
<div className="d-flex mb-2 align-items-start">
|
||||||
<p className="m-0">Location:</p>
|
<div className="d-flex" style={{ minWidth: "130px" }}>
|
||||||
</div>
|
<span className="d-flex align-items-start">
|
||||||
<div className="d-flex align-items-center">
|
<i className="bx bx-map bx-xs me-2 mt-1"></i>
|
||||||
<i className="bx bx-map bx-xs me-1 "></i>
|
<span>Location</span>
|
||||||
<span className="text-break small">
|
|
||||||
{contactProfile.address}
|
|
||||||
</span>
|
</span>
|
||||||
|
<span style={{ marginLeft: "26px" }}>:</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span className="text-break small">{profileContactState.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">
|
||||||
{contactProfile?.organization && (
|
{profileContactState?.organization && (
|
||||||
<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">Orgnization : </p>
|
<span className="d-flex align-items-center">
|
||||||
|
<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">
|
|
||||||
<i className="fa-solid fa-briefcase me-2"></i>
|
|
||||||
|
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
<span style={{ wordBreak: "break-word" }}>
|
<span style={{ wordBreak: "break-word" }}>
|
||||||
{contactProfile.organization}
|
{profileContactState.organization}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{contactProfile?.contactCategory && (
|
|
||||||
<div className="d-flex mb-2">
|
{profileContactState?.contactCategory && (
|
||||||
<div style={{ width: "100px", minWidth: "100px" }}>
|
<div className="d-flex mb-2 align-items-start">
|
||||||
<p className="m-0">Category : </p>
|
<div className="d-flex" style={{ minWidth: "130px" }}>
|
||||||
|
<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">
|
||||||
<i className="bx bx-user bx-xs me-1"></i>
|
{profileContactState.contactCategory.name}
|
||||||
{contactProfile.contactCategory.name}
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{contactProfile?.tags?.length > 0 && (
|
|
||||||
<div className="d-flex mb-2">
|
{profileContactState?.tags?.length > 0 && (
|
||||||
<div style={{ width: "100px", minWidth: "100px" }}>
|
<div className="d-flex mb-2 align-items-start">
|
||||||
<p className="m-0">Tags : </p>
|
<div className="d-flex" style={{ minWidth: "130px" }}>
|
||||||
|
<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">
|
||||||
{contactProfile.tags.map((tag, index) => (
|
{profileContactState.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>
|
||||||
))}
|
))}
|
||||||
@ -177,71 +243,87 @@ const ProfileContactDirectory = ({ contact, setOpen_contact, closeModal }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{contactProfile?.buckets?.length > 0 && (
|
{profileContactState?.buckets?.length > 0 && (
|
||||||
<div className="d-flex ">
|
<div className="d-flex mb-2 align-items-start">
|
||||||
{contactProfile?.contactEmails?.length > 0 && (
|
<div className="d-flex" style={{ minWidth: "130px" }}>
|
||||||
<div className="d-flex mb-2 align-items-center">
|
<span className="d-flex align-items-center">
|
||||||
<div style={{ width: "100px", minWidth: "100px" }}>
|
<i className="bx bx-layer me-1"></i>
|
||||||
<p className="m-0">Buckets : </p>
|
<span>Buckets</span>
|
||||||
</div>
|
</span>
|
||||||
<div>
|
<span style={{ marginLeft: "35px" }}>:</span>
|
||||||
<ul className="list-inline mb-0">
|
</div>
|
||||||
{contactProfile.buckets.map((bucket) => (
|
|
||||||
<li className="list-inline-item me-2" key={bucket.id}>
|
<div>
|
||||||
<span className="badge bg-label-primary my-1">
|
<ul className="list-inline mb-0">
|
||||||
{bucket.name}
|
{profileContactState.buckets.map((bucket) => (
|
||||||
</span>
|
<li className="list-inline-item me-2" key={bucket.id}>
|
||||||
</li>
|
<span className="badge bg-label-primary my-1">
|
||||||
))}
|
{bucket.name}
|
||||||
</ul>
|
</span>
|
||||||
</div>
|
</li>
|
||||||
</div>
|
))}
|
||||||
)}
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{contactProfile?.projects?.length > 0 && (
|
|
||||||
<div className="d-flex mb-2 align-items-start">
|
|
||||||
<div style={{ minWidth: "100px" }}>
|
|
||||||
<p className="m-0 text-start">Projects :</p>
|
|
||||||
</div>
|
|
||||||
<div className="text-start">
|
|
||||||
<ul className="list-inline mb-0">
|
|
||||||
{contactProfile.projects.map((project, index) => (
|
|
||||||
<li className="list-inline-item me-2" key={project.id}>
|
|
||||||
{project.name}
|
|
||||||
{index < contactProfile.projects.length - 1 && ","}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="d-flex mb-2 align-items-start">
|
{profileContactState?.projects?.length > 0 && (
|
||||||
<div style={{ minWidth: "100px" }}>
|
<div className="d-flex mb-2 align-items-start">
|
||||||
<p className="m-0 text-start">Description :</p>
|
<div className="d-flex" style={{ minWidth: "130px" }}>
|
||||||
|
<span className="d-flex align-items-center">
|
||||||
|
<i className="bx bx-building-house me-1"></i>
|
||||||
|
<span>Projects</span>
|
||||||
|
</span>
|
||||||
|
<span style={{ marginLeft: "28px" }}>:</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-start">
|
||||||
|
<ul className="list-inline mb-0">
|
||||||
|
{profileContactState.projects.map((project, index) => (
|
||||||
|
<li className="list-inline-item me-2" key={project.id}>
|
||||||
|
{project.name}
|
||||||
|
{index < profileContactState.projects.length - 1 && ","}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="d-flex mb-2 align-items-start" style={{ marginLeft: "3rem" }}>
|
||||||
|
<div className="d-flex" style={{ minWidth: "130px" }}>
|
||||||
|
<span className="d-flex align-items-start">
|
||||||
|
<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 && (
|
||||||
<span
|
<>
|
||||||
onClick={toggleReadMore}
|
<br />
|
||||||
className="text-primary mx-1 cursor-pointer"
|
<span
|
||||||
>
|
onClick={toggleReadMore}
|
||||||
{expanded ? "Read less" : "Read more"}
|
className="text-primary mx-1 cursor-pointer"
|
||||||
</span>
|
>
|
||||||
|
{expanded ? "Read less" : "Read more"}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<hr className="my-1" />
|
<hr className="my-1" />
|
||||||
<NotesDirectory
|
<NotesDirectory
|
||||||
refetchProfile={refetch}
|
refetchProfile={refetch}
|
||||||
isLoading={loading}
|
isLoading={loading}
|
||||||
contactProfile={profileContact}
|
contactProfile={profileContactState}
|
||||||
setProfileContact={setProfileContact}
|
setProfileContact={setProfileContactState}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -14,7 +14,11 @@ 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 { useBuckets, useOrganization } from "../../hooks/useDirectory";
|
import {
|
||||||
|
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";
|
||||||
@ -32,10 +36,13 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
const { contactCategory, loading: contactCategoryLoading } =
|
const { contactCategory, loading: contactCategoryLoading } =
|
||||||
useContactCategory();
|
useContactCategory();
|
||||||
const { contactTags, loading: Tagloading } = useContactTags();
|
const { contactTags, loading: Tagloading } = useContactTags();
|
||||||
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),
|
||||||
@ -45,6 +52,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
contactCategoryId: null,
|
contactCategoryId: null,
|
||||||
address: "",
|
address: "",
|
||||||
description: "",
|
description: "",
|
||||||
|
designation: "",
|
||||||
projectIds: [],
|
projectIds: [],
|
||||||
contactEmails: [],
|
contactEmails: [],
|
||||||
contactPhones: [],
|
contactPhones: [],
|
||||||
@ -95,6 +103,24 @@ 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) => {
|
||||||
@ -113,33 +139,28 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const onSubmit = async (data) => {
|
||||||
const cleaned = {
|
const cleaned = {
|
||||||
...data,
|
...data,
|
||||||
contactEmails: (data.contactEmails || [])
|
contactEmails: (data.contactEmails || [])
|
||||||
.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
|
return existingEmail ? { ...email, id: existingEmail.id } : email;
|
||||||
? { ...email, id: existingEmail.id }
|
}),
|
||||||
: email;
|
contactPhones: (data.contactPhones || [])
|
||||||
}),
|
.filter((p) => p.phoneNumber?.trim() !== "")
|
||||||
contactPhones: (data.contactPhones || [])
|
.map((phone, index) => {
|
||||||
.filter((p) => p.phoneNumber?.trim() !== "")
|
const existingPhone = existingContact.contactPhones?.[index];
|
||||||
.map((phone, index) => {
|
return existingPhone ? { ...phone, id: existingPhone.id } : phone;
|
||||||
const existingPhone = existingContact.contactPhones?.[index];
|
}),
|
||||||
return existingPhone
|
};
|
||||||
? { ...phone, id: existingPhone.id }
|
|
||||||
: phone;
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
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();
|
||||||
};
|
};
|
||||||
@ -149,7 +170,7 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
typeof existingContact === "object" &&
|
typeof existingContact === "object" &&
|
||||||
!Array.isArray(existingContact);
|
!Array.isArray(existingContact);
|
||||||
|
|
||||||
if (!isInitialized &&isValidContact && TagsData) {
|
if (!isInitialized && isValidContact && TagsData) {
|
||||||
reset({
|
reset({
|
||||||
name: existingContact.name || "",
|
name: existingContact.name || "",
|
||||||
organization: existingContact.organization || "",
|
organization: existingContact.organization || "",
|
||||||
@ -158,24 +179,30 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
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 (!existingContact.contactPhones || existingContact.contactPhones.length === 0) {
|
if (
|
||||||
appendPhone({ label: "Office", phoneNumber: "" });
|
!existingContact.contactPhones ||
|
||||||
}
|
existingContact.contactPhones.length === 0
|
||||||
|
) {
|
||||||
if (!existingContact.contactEmails || existingContact.contactEmails.length === 0) {
|
appendPhone({ label: "Office", phoneNumber: "" });
|
||||||
appendEmail({ label: "Work", emailAddress: "" });
|
|
||||||
}
|
}
|
||||||
setIsInitialized(true)
|
|
||||||
|
if (
|
||||||
|
!existingContact.contactEmails ||
|
||||||
|
existingContact.contactEmails.length === 0
|
||||||
|
) {
|
||||||
|
appendEmail({ label: "Work", emailAddress: "" });
|
||||||
|
}
|
||||||
|
setIsInitialized(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return()=> reset()
|
// return()=> reset()
|
||||||
}, [ existingContact, buckets, projects ] );
|
}, [existingContact, buckets, projects]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
@ -195,15 +222,14 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
)}
|
)}
|
||||||
</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
|
||||||
organizationList={organizationList}
|
organizationList={organizationList}
|
||||||
value={getValues("organization") || ""}
|
value={getValues("organization") || ""}
|
||||||
onChange={(val) => setValue("organization", val)}
|
onChange={(val) => setValue("organization", val)}
|
||||||
error={errors.organization?.message}
|
error={errors.organization?.message}
|
||||||
/>
|
/>
|
||||||
{errors.organization && (
|
{errors.organization && (
|
||||||
<small className="danger-text">
|
<small className="danger-text">
|
||||||
{errors.organization.message}
|
{errors.organization.message}
|
||||||
@ -211,6 +237,55 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
)}
|
)}
|
||||||
</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) => (
|
||||||
@ -250,8 +325,10 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
|
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary" onClick={handleAddEmail}/>
|
<i
|
||||||
|
className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary"
|
||||||
|
onClick={handleAddEmail}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
// <button
|
// <button
|
||||||
// type="button"
|
// type="button"
|
||||||
@ -259,8 +336,10 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
// onClick={() => removeEmail(index)}
|
// onClick={() => removeEmail(index)}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-danger" onClick={() => removeEmail(index)}/>
|
<i
|
||||||
|
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 && (
|
||||||
@ -310,7 +389,10 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
// onClick={handleAddPhone}
|
// onClick={handleAddPhone}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary" onClick={handleAddPhone} />
|
<i
|
||||||
|
className="bx bx-plus-circle bx-xs ms-1 cursor-pointer text-primary"
|
||||||
|
onClick={handleAddPhone}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
// <button
|
// <button
|
||||||
// type="button"
|
// type="button"
|
||||||
@ -318,7 +400,10 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
// onClick={() => removePhone(index)}
|
// onClick={() => removePhone(index)}
|
||||||
// style={{ width: "24px", height: "24px" }}
|
// style={{ width: "24px", height: "24px" }}
|
||||||
// >
|
// >
|
||||||
<i className="bx bx-minus-circle bx-xs ms-1 cursor-pointer text-danger" onClick={() => removePhone(index)} />
|
<i
|
||||||
|
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 && (
|
||||||
@ -348,7 +433,7 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
</option>
|
</option>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<option disabled value="">
|
<option disabled value="">
|
||||||
Select Category
|
Select Category
|
||||||
</option>
|
</option>
|
||||||
{contactCategory?.map((cate) => (
|
{contactCategory?.map((cate) => (
|
||||||
@ -387,7 +472,7 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-md-12 mt-1 text-start">
|
<div className="col-md-12 mt-1 text-start">
|
||||||
<label className="form-label ">Select Label</label>
|
<label className="form-label ">Select Label</label>
|
||||||
|
|
||||||
<ul className="d-flex flex-wrap px-1 list-unstyled mb-0">
|
<ul className="d-flex flex-wrap px-1 list-unstyled mb-0">
|
||||||
@ -445,7 +530,11 @@ await submitContact({ ...cleaned, id: existingContact.id });
|
|||||||
</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 className="btn btn-sm btn-primary" type="submit" disabled={IsSubmitting}>
|
<button
|
||||||
|
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">Role</div>
|
<div className="form-text text-start">Official Designation</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"
|
||||||
|
|||||||
197
src/components/Expenses/ExpenseFilterPanel.jsx
Normal file
197
src/components/Expenses/ExpenseFilterPanel.jsx
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
import React, { useEffect, useState,useMemo } from "react";
|
||||||
|
import { FormProvider, useForm, Controller } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { defaultFilter, SearchSchema } from "./ExpenseSchema";
|
||||||
|
|
||||||
|
import DateRangePicker, { DateRangePicker1 } from "../common/DateRangePicker";
|
||||||
|
import SelectMultiple from "../common/SelectMultiple";
|
||||||
|
|
||||||
|
import { useProjectName } from "../../hooks/useProjects";
|
||||||
|
import { useExpenseStatus } from "../../hooks/masterHook/useMaster";
|
||||||
|
import { useEmployeesAllOrByProjectId } from "../../hooks/useEmployees";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import moment from "moment";
|
||||||
|
import { useExpenseFilter } from "../../hooks/useExpense";
|
||||||
|
import { ExpenseFilterSkeleton } from "./ExpenseSkeleton";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
||||||
|
const selectedProjectId = useSelector((store) => store.localVariables.projectId);
|
||||||
|
const { data, isLoading,isError,error,isFetching , isFetched} = useExpenseFilter();
|
||||||
|
|
||||||
|
const groupByList = useMemo(() => [
|
||||||
|
{ id: "transactionDate", name: "Transaction Date" },
|
||||||
|
{ id: "status", name: "Status" },
|
||||||
|
{ id: "paidBy", name: "Paid By" },
|
||||||
|
{ id: "project", name: "Project" },
|
||||||
|
{ id: "paymentMode", name: "Payment Mode" },
|
||||||
|
{ id: "expensesType", name: "Expense Type" },
|
||||||
|
{id: "createdAt",name:"Submitted"}
|
||||||
|
], []);
|
||||||
|
|
||||||
|
const [selectedGroup, setSelectedGroup] = useState(groupByList[0]);
|
||||||
|
const [resetKey, setResetKey] = useState(0);
|
||||||
|
|
||||||
|
const methods = useForm({
|
||||||
|
resolver: zodResolver(SearchSchema),
|
||||||
|
defaultValues: defaultFilter,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { control, register, handleSubmit, reset, watch } = methods;
|
||||||
|
const isTransactionDate = watch("isTransactionDate");
|
||||||
|
|
||||||
|
const closePanel = () => {
|
||||||
|
document.querySelector(".offcanvas.show .btn-close")?.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGroupChange = (e) => {
|
||||||
|
const group = groupByList.find((g) => g.id === e.target.value);
|
||||||
|
if (group) setSelectedGroup(group);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmit = (formData) => {
|
||||||
|
onApply({
|
||||||
|
...formData,
|
||||||
|
startDate: moment.utc(formData.startDate, "DD-MM-YYYY").toISOString(),
|
||||||
|
endDate: moment.utc(formData.endDate, "DD-MM-YYYY").toISOString(),
|
||||||
|
});
|
||||||
|
handleGroupBy(selectedGroup.id);
|
||||||
|
closePanel();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onClear = () => {
|
||||||
|
reset(defaultFilter);
|
||||||
|
setResetKey((prev) => prev + 1);
|
||||||
|
setSelectedGroup(groupByList[0]);
|
||||||
|
onApply(defaultFilter);
|
||||||
|
handleGroupBy(groupByList[0].id);
|
||||||
|
closePanel();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isLoading || isFetching) return <ExpenseFilterSkeleton />;
|
||||||
|
if(isError && isFetched) return <div>Something went wrong Here- {error.message} </div>
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
|
||||||
|
<FormProvider {...methods}>
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)} className="p-2 text-start">
|
||||||
|
<div className="mb-3 w-100">
|
||||||
|
<div className="d-flex align-items-center mb-2">
|
||||||
|
<label className="form-label me-2">Choose Date:</label>
|
||||||
|
<div className="form-check form-switch m-0">
|
||||||
|
<input
|
||||||
|
className="form-check-input"
|
||||||
|
type="checkbox"
|
||||||
|
id="switchOption1"
|
||||||
|
{...register("isTransactionDate")}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<label className="form-label mb-0 ms-2">
|
||||||
|
{isTransactionDate ? "Submitted": "Transaction" }
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DateRangePicker1
|
||||||
|
placeholder="DD-MM-YYYY To DD-MM-YYYY"
|
||||||
|
startField="startDate"
|
||||||
|
endField="endDate"
|
||||||
|
resetSignal={resetKey}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row g-2">
|
||||||
|
<SelectMultiple
|
||||||
|
name="projectIds"
|
||||||
|
label="Projects :"
|
||||||
|
options={data.projects}
|
||||||
|
labelKey="name"
|
||||||
|
valueKey="id"
|
||||||
|
/>
|
||||||
|
<SelectMultiple
|
||||||
|
name="createdByIds"
|
||||||
|
label="Submitted By :"
|
||||||
|
options={data.createdBy}
|
||||||
|
labelKey={(item) => item.name}
|
||||||
|
valueKey="id"
|
||||||
|
/>
|
||||||
|
<SelectMultiple
|
||||||
|
name="paidById"
|
||||||
|
label="Paid By :"
|
||||||
|
options={data.paidBy}
|
||||||
|
labelKey={(item) => item.name}
|
||||||
|
valueKey="id"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="mb-3">
|
||||||
|
<label className="form-label">Status :</label>
|
||||||
|
<div className="row flex-wrap">
|
||||||
|
{data?.status
|
||||||
|
?.slice()
|
||||||
|
.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
.map((status) => (
|
||||||
|
<div className="col-6" key={status.id}>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="statusIds"
|
||||||
|
render={({ field: { value = [], onChange } }) => (
|
||||||
|
<div className="d-flex align-items-center me-3 mb-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="form-check-input"
|
||||||
|
value={status.id}
|
||||||
|
checked={value.includes(status.id)}
|
||||||
|
onChange={(e) => {
|
||||||
|
const checked = e.target.checked;
|
||||||
|
onChange(
|
||||||
|
checked
|
||||||
|
? [...value, status.id]
|
||||||
|
: value.filter((v) => v !== status.id)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<label className="ms-2 mb-0">{status.name}</label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mb-2 text-start ">
|
||||||
|
<label htmlFor="groupBySelect" className="form-label">Group By :</label>
|
||||||
|
<select
|
||||||
|
id="groupBySelect"
|
||||||
|
className="form-select form-select-sm"
|
||||||
|
value={selectedGroup?.id || ""}
|
||||||
|
onChange={handleGroupChange}
|
||||||
|
>
|
||||||
|
{groupByList.map((group) => (
|
||||||
|
<option key={group.id} value={group.id}>
|
||||||
|
{group.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="d-flex justify-content-end py-3 gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-secondary btn-xs"
|
||||||
|
onClick={onClear}
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</button>
|
||||||
|
<button type="submit" className="btn btn-primary btn-xs">
|
||||||
|
Apply
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</FormProvider>
|
||||||
|
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ExpenseFilterPanel;
|
||||||
321
src/components/Expenses/ExpenseList.jsx
Normal file
321
src/components/Expenses/ExpenseList.jsx
Normal file
@ -0,0 +1,321 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
|
import { useDeleteExpense, useExpenseList } from "../../hooks/useExpense";
|
||||||
|
import Avatar from "../common/Avatar";
|
||||||
|
import { useExpenseContext } from "../../pages/Expense/ExpensePage";
|
||||||
|
import { formatDate, formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||||
|
import Pagination from "../common/Pagination";
|
||||||
|
import { APPROVE_EXPENSE, EXPENSE_DRAFT, EXPENSE_REJECTEDBY } from "../../utils/constants";
|
||||||
|
import { getColorNameFromHex, useDebounce } from "../../utils/appUtils";
|
||||||
|
import { ExpenseTableSkeleton } from "./ExpenseSkeleton";
|
||||||
|
import ConfirmModal from "../common/ConfirmModal";
|
||||||
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
|
const ExpenseList = ({ filters, groupBy = "transactionDate",searchText }) => {
|
||||||
|
const [deletingId, setDeletingId] = useState(null);
|
||||||
|
const [IsDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
|
const { setViewExpense, setManageExpenseModal } = useExpenseContext();
|
||||||
|
const IsExpenseEditable = useHasUserPermission();
|
||||||
|
const IsExpesneApprpve = useHasUserPermission(APPROVE_EXPENSE);
|
||||||
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
|
const pageSize = 20;
|
||||||
|
const debouncedSearch = useDebounce(searchText, 500);
|
||||||
|
|
||||||
|
const { mutate: DeleteExpense, isPending } = useDeleteExpense();
|
||||||
|
const { data, isLoading, isError, isInitialLoading, error } = useExpenseList(
|
||||||
|
pageSize,
|
||||||
|
currentPage,
|
||||||
|
filters,
|
||||||
|
debouncedSearch
|
||||||
|
);
|
||||||
|
|
||||||
|
const SelfId = useSelector(
|
||||||
|
(store) => store?.globalVariables?.loginUser?.employeeInfo?.id
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleDelete = (id) => {
|
||||||
|
setDeletingId(id);
|
||||||
|
DeleteExpense(
|
||||||
|
{ id },
|
||||||
|
{
|
||||||
|
onSettled: () => {
|
||||||
|
setDeletingId(null);
|
||||||
|
setIsDeleteModalOpen(false);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const paginate = (page) => {
|
||||||
|
if (page >= 1 && page <= (data?.totalPages ?? 1)) {
|
||||||
|
setCurrentPage(page);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const groupByField = (items, field) => {
|
||||||
|
return items.reduce((acc, item) => {
|
||||||
|
let key;
|
||||||
|
switch (field) {
|
||||||
|
case "transactionDate":
|
||||||
|
key = item.transactionDate?.split("T")[0];
|
||||||
|
break;
|
||||||
|
case "status":
|
||||||
|
key = item.status?.displayName || "Unknown";
|
||||||
|
break;
|
||||||
|
case "paidBy":
|
||||||
|
key = `${item.paidBy?.firstName ?? ""} ${
|
||||||
|
item.paidBy?.lastName ?? ""
|
||||||
|
}`.trim();
|
||||||
|
break;
|
||||||
|
case "project":
|
||||||
|
key = item.project?.name || "Unknown Project";
|
||||||
|
break;
|
||||||
|
case "paymentMode":
|
||||||
|
key = item.paymentMode?.name || "Unknown Mode";
|
||||||
|
break;
|
||||||
|
case "expensesType":
|
||||||
|
key = item.expensesType?.name || "Unknown Type";
|
||||||
|
break;
|
||||||
|
case "createdAt":
|
||||||
|
key = item.createdAt?.split("T")[0] || "Unknown Type";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
key = "Others";
|
||||||
|
}
|
||||||
|
if (!acc[key]) acc[key] = [];
|
||||||
|
acc[key].push(item);
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
|
||||||
|
const expenseColumns = [
|
||||||
|
{
|
||||||
|
key: "expensesType",
|
||||||
|
label: "Expense Type",
|
||||||
|
getValue: (e) => e.expensesType?.name || "N/A",
|
||||||
|
align: "text-start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "paymentMode",
|
||||||
|
label: "Payment Mode",
|
||||||
|
getValue: (e) => e.paymentMode?.name || "N/A",
|
||||||
|
align: "text-start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "paidBy",
|
||||||
|
label: "Paid By",
|
||||||
|
align: "text-start",
|
||||||
|
getValue: (e) =>
|
||||||
|
`${e.paidBy?.firstName ?? ""} ${e.paidBy?.lastName ?? ""}`.trim() ||
|
||||||
|
"N/A",
|
||||||
|
customRender: (e) => (
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<Avatar
|
||||||
|
size="xs"
|
||||||
|
classAvatar="m-0"
|
||||||
|
firstName={e.paidBy?.firstName}
|
||||||
|
lastName={e.paidBy?.lastName}
|
||||||
|
/>
|
||||||
|
<span>
|
||||||
|
{`${e.paidBy?.firstName ?? ""} ${
|
||||||
|
e.paidBy?.lastName ?? ""
|
||||||
|
}`.trim() || "N/A"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "submitted",
|
||||||
|
label: "Submitted",
|
||||||
|
getValue: (e) => formatUTCToLocalTime(e?.createdAt),
|
||||||
|
isAlwaysVisible: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "amount",
|
||||||
|
label: "Amount",
|
||||||
|
getValue: (e) => (
|
||||||
|
<>
|
||||||
|
<i className="bx bx-rupee b-xs"></i> {e?.amount}
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
isAlwaysVisible: true,
|
||||||
|
align: "text-end",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "status",
|
||||||
|
label: "Status",
|
||||||
|
align: "text-center",
|
||||||
|
getValue: (e) => (
|
||||||
|
<span
|
||||||
|
className={`badge bg-label-${
|
||||||
|
getColorNameFromHex(e?.status?.color) || "secondary"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{e.status?.name || "Unknown"}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isInitialLoading) return <ExpenseTableSkeleton />;
|
||||||
|
if (isError) return <div>{error}</div>;
|
||||||
|
|
||||||
|
const grouped = groupBy
|
||||||
|
? groupByField(data?.data ?? [], groupBy)
|
||||||
|
: { All: data?.data ?? [] };
|
||||||
|
const IsGroupedByDate = ["transactionDate", "createdAt"].includes(groupBy);
|
||||||
|
const canEditExpense = (expense) => {
|
||||||
|
return (
|
||||||
|
(expense.status.id === EXPENSE_DRAFT ||
|
||||||
|
EXPENSE_REJECTEDBY.includes(expense.status.id)) &&
|
||||||
|
expense.createdBy?.id === SelfId
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const canDetetExpense = (expense)=>{
|
||||||
|
return (expense.status.id === EXPENSE_DRAFT && expense.createdBy.id === SelfId )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{IsDeleteModalOpen && (
|
||||||
|
<div
|
||||||
|
className={`modal fade show`}
|
||||||
|
tabIndex="-1"
|
||||||
|
role="dialog"
|
||||||
|
style={{
|
||||||
|
display: "block",
|
||||||
|
backgroundColor: "rgba(0,0,0,0.5)",
|
||||||
|
}}
|
||||||
|
aria-hidden="false"
|
||||||
|
>
|
||||||
|
<ConfirmModal
|
||||||
|
type="delete"
|
||||||
|
header="Delete Expense"
|
||||||
|
message="Are you sure you want delete?"
|
||||||
|
onSubmit={handleDelete}
|
||||||
|
onClose={() => setIsDeleteModalOpen(false)}
|
||||||
|
loading={isPending}
|
||||||
|
paramData={deletingId}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="card">
|
||||||
|
<div
|
||||||
|
className="card-datatable table-responsive "
|
||||||
|
id="horizontal-example"
|
||||||
|
>
|
||||||
|
<div className="dataTables_wrapper no-footer px-2 ">
|
||||||
|
<table className="table border-top dataTable text-nowrap">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
{expenseColumns.map(
|
||||||
|
(col) =>
|
||||||
|
(col.isAlwaysVisible || groupBy !== col.key) && (
|
||||||
|
<th
|
||||||
|
key={col.key}
|
||||||
|
className={`sorting d-table-cell`}
|
||||||
|
aria-sort="descending"
|
||||||
|
>
|
||||||
|
<div className={`${col.align}`}>{col.label}</div>
|
||||||
|
</th>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
<th className="sticky-action-column bg-white text-center">
|
||||||
|
Action
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{Object.keys(grouped).length > 0 ? (
|
||||||
|
Object.entries(grouped).map(([group, expenses]) => (
|
||||||
|
<React.Fragment key={group}>
|
||||||
|
<tr className="tr-group text-dark">
|
||||||
|
<td colSpan={8} className="text-start">
|
||||||
|
<strong>
|
||||||
|
{IsGroupedByDate
|
||||||
|
? formatUTCToLocalTime(group)
|
||||||
|
: group}
|
||||||
|
</strong>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{expenses.map((expense) => (
|
||||||
|
<tr key={expense.id}>
|
||||||
|
{expenseColumns.map(
|
||||||
|
(col) =>
|
||||||
|
(col.isAlwaysVisible || groupBy !== col.key) && (
|
||||||
|
<td
|
||||||
|
key={col.key}
|
||||||
|
className={`d-table-cell ${col.align ?? ""}`}
|
||||||
|
>
|
||||||
|
{col.customRender
|
||||||
|
? col.customRender(expense)
|
||||||
|
: col.getValue(expense)}
|
||||||
|
</td>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
<td className="sticky-action-column bg-white">
|
||||||
|
<div className="d-flex justify-content-center gap-2">
|
||||||
|
<i
|
||||||
|
className="bx bx-show text-primary cursor-pointer"
|
||||||
|
onClick={() =>
|
||||||
|
setViewExpense({
|
||||||
|
expenseId: expense.id,
|
||||||
|
view: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
></i>
|
||||||
|
{canEditExpense(expense) && (
|
||||||
|
<i
|
||||||
|
className="bx bx-edit text-secondary cursor-pointer"
|
||||||
|
onClick={() =>
|
||||||
|
setManageExpenseModal({
|
||||||
|
IsOpen: true,
|
||||||
|
expenseId: expense.id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
></i>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{canDetetExpense(expense) && (
|
||||||
|
<i
|
||||||
|
className="bx bx-trash text-danger cursor-pointer"
|
||||||
|
onClick={() => {
|
||||||
|
setIsDeleteModalOpen(true);
|
||||||
|
setDeletingId(expense.id);
|
||||||
|
}}
|
||||||
|
></i>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</React.Fragment>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={8} className="text-center py-4">
|
||||||
|
No Expense Found
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{data?.data?.length > 0 && (
|
||||||
|
<Pagination
|
||||||
|
currentPage={currentPage}
|
||||||
|
totalPages={data.totalPages}
|
||||||
|
onPageChange={paginate}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ExpenseList;
|
||||||
164
src/components/Expenses/ExpenseSchema.js
Normal file
164
src/components/Expenses/ExpenseSchema.js
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
|
||||||
|
const ALLOWED_TYPES = [
|
||||||
|
"application/pdf",
|
||||||
|
"image/png",
|
||||||
|
"image/jpg",
|
||||||
|
"image/jpeg",
|
||||||
|
];
|
||||||
|
|
||||||
|
export const ExpenseSchema = (expenseTypes) => {
|
||||||
|
return z
|
||||||
|
.object({
|
||||||
|
projectId: z.string().min(1, { message: "Project is required" }),
|
||||||
|
expensesTypeId: z
|
||||||
|
.string()
|
||||||
|
.min(1, { message: "Expense type is required" }),
|
||||||
|
paymentModeId: z.string().min(1, { message: "Payment mode is required" }),
|
||||||
|
paidById: z.string().min(1, { message: "Employee name is required" }),
|
||||||
|
transactionDate: z
|
||||||
|
.string()
|
||||||
|
.min(1, { message: "Date is required" })
|
||||||
|
,
|
||||||
|
transactionId: z.string().optional(),
|
||||||
|
description: z.string().min(1, { message: "Description is required" }),
|
||||||
|
location: z.string().min(1, { message: "Location is required" }),
|
||||||
|
supplerName: z.string().min(1, { message: "Supplier name is required" }),
|
||||||
|
amount: z.coerce
|
||||||
|
.number({
|
||||||
|
invalid_type_error: "Amount is required and must be a number",
|
||||||
|
})
|
||||||
|
.min(1, "Amount must be Enter")
|
||||||
|
.refine((val) => /^\d+(\.\d{1,2})?$/.test(val.toString()), {
|
||||||
|
message: "Amount must have at most 2 decimal places",
|
||||||
|
}),
|
||||||
|
noOfPersons: z.coerce.number().optional(),
|
||||||
|
billAttachments: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
fileName: z.string().min(1, { message: "Filename is required" }),
|
||||||
|
base64Data: z.string().nullable(),
|
||||||
|
contentType: z
|
||||||
|
.string()
|
||||||
|
.refine((val) => ALLOWED_TYPES.includes(val), {
|
||||||
|
message: "Only PDF, PNG, JPG, or JPEG files are allowed",
|
||||||
|
}),
|
||||||
|
documentId: z.string().optional(),
|
||||||
|
fileSize: z.number().max(MAX_FILE_SIZE, {
|
||||||
|
message: "File size must be less than or equal to 5MB",
|
||||||
|
}),
|
||||||
|
description: z.string().optional(),
|
||||||
|
isActive: z.boolean().default(true),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.nonempty({ message: "At least one file attachment is required" }),
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
.refine(
|
||||||
|
(data) => {
|
||||||
|
return (
|
||||||
|
!data.projectId || (data.paidById && data.paidById.trim() !== "")
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
message: "Please select who paid (employee)",
|
||||||
|
path: ["paidById"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
const expenseType = expenseTypes.find((et) => et.id === data.expensesTypeId);
|
||||||
|
if (expenseType?.noOfPersonsRequired && (!data.noOfPersons || data.noOfPersons < 1)) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "No. of Persons is required and must be at least 1",
|
||||||
|
path: ["noOfPersons"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const defaultExpense = {
|
||||||
|
projectId: "",
|
||||||
|
expensesTypeId: "",
|
||||||
|
paymentModeId: "",
|
||||||
|
paidById: "",
|
||||||
|
transactionDate: "",
|
||||||
|
transactionId: "",
|
||||||
|
description: "",
|
||||||
|
location: "",
|
||||||
|
supplerName: "",
|
||||||
|
amount: "",
|
||||||
|
noOfPersons: "",
|
||||||
|
billAttachments: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const ExpenseActionScheam = (isReimbursement = false) => {
|
||||||
|
return z
|
||||||
|
.object({
|
||||||
|
comment: z.string().min(1, { message: "Please leave comment" }),
|
||||||
|
statusId: z.string().min(1, { message: "Please select a status" }),
|
||||||
|
reimburseTransactionId: z.string().nullable().optional(),
|
||||||
|
reimburseDate: z.string().nullable().optional(),
|
||||||
|
reimburseById: z.string().nullable().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (isReimbursement) {
|
||||||
|
if (!data.reimburseTransactionId?.trim()) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
path: ["reimburseTransactionId"],
|
||||||
|
message: "Reimburse Transaction ID is required",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!data.reimburseDate) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
path: ["reimburseDate"],
|
||||||
|
message: "Reimburse Date is required",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!data.reimburseById) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
path: ["reimburseById"],
|
||||||
|
message: "Reimburse By is required",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const defaultActionValues = {
|
||||||
|
comment: "",
|
||||||
|
statusId: "",
|
||||||
|
|
||||||
|
reimburseTransactionId: null,
|
||||||
|
reimburseDate: null,
|
||||||
|
reimburseById: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const SearchSchema = z.object({
|
||||||
|
projectIds: z.array(z.string()).optional(),
|
||||||
|
statusIds: z.array(z.string()).optional(),
|
||||||
|
createdByIds: z.array(z.string()).optional(),
|
||||||
|
paidById: z.array(z.string()).optional(),
|
||||||
|
startDate: z.string().optional(),
|
||||||
|
endDate: z.string().optional(),
|
||||||
|
isTransactionDate: z.boolean().default(true),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const defaultFilter = {
|
||||||
|
projectIds: [],
|
||||||
|
statusIds: [],
|
||||||
|
createdByIds: [],
|
||||||
|
paidById: [],
|
||||||
|
isTransactionDate: true,
|
||||||
|
startDate: null,
|
||||||
|
endDate: null,
|
||||||
|
};
|
||||||
|
|
||||||
283
src/components/Expenses/ExpenseSkeleton.jsx
Normal file
283
src/components/Expenses/ExpenseSkeleton.jsx
Normal file
@ -0,0 +1,283 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
|
||||||
|
const SkeletonLine = ({ height = 20, width = "100%", className = "" }) => (
|
||||||
|
<div
|
||||||
|
className={`skeleton mb-2 ${className}`}
|
||||||
|
style={{
|
||||||
|
height,
|
||||||
|
width,
|
||||||
|
}}
|
||||||
|
></div>
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
const ExpenseSkeleton = () => {
|
||||||
|
return (
|
||||||
|
<div className="container p-3">
|
||||||
|
<div className="d-flex justify-content-center">
|
||||||
|
<SkeletonLine height={20} width="200px" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{[...Array(5)].map((_, idx) => (
|
||||||
|
<div className="row my-2" key={idx}>
|
||||||
|
<div className="col-md-6">
|
||||||
|
<SkeletonLine />
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6">
|
||||||
|
<SkeletonLine />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
<div className="row my-2">
|
||||||
|
<div className="col-md-12">
|
||||||
|
<SkeletonLine height={60} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row my-2">
|
||||||
|
<div className="col-md-12">
|
||||||
|
<SkeletonLine height={120} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="d-flex justify-content-center gap-2 mt-3">
|
||||||
|
<SkeletonLine height={35} width="100px" />
|
||||||
|
<SkeletonLine height={35} width="100px" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ExpenseSkeleton;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const ExpenseDetailsSkeleton = () => {
|
||||||
|
return (
|
||||||
|
<div className="container px-3">
|
||||||
|
<div className="row mb-3">
|
||||||
|
<div className="d-flex justify-content-center mb-3">
|
||||||
|
<SkeletonLine height={20} width="180px" className="mb-2" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{[...Array(3)].map((_, i) => (
|
||||||
|
<div className="col-12 col-md-4 mb-3" key={`row-1-${i}`}>
|
||||||
|
<SkeletonLine height={14} className="mb-1" />
|
||||||
|
<SkeletonLine />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{[...Array(6)].map((_, i) => (
|
||||||
|
<div className="col-12 col-md-4 mb-3" key={`row-2-${i}`}>
|
||||||
|
<SkeletonLine height={14} className="mb-1" />
|
||||||
|
<SkeletonLine />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div className="col-12 my-2">
|
||||||
|
<SkeletonLine height={14} width="100px" className="mb-2" />
|
||||||
|
{[...Array(2)].map((_, i) => (
|
||||||
|
<div
|
||||||
|
className="list-group-item d-flex align-items-center mb-2"
|
||||||
|
key={i}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rounded me-2"
|
||||||
|
style={{
|
||||||
|
height: "50px",
|
||||||
|
width: "80px",
|
||||||
|
backgroundColor: "#dcdcdc",
|
||||||
|
borderRadius: "4px",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="w-100">
|
||||||
|
<SkeletonLine height={14} width="60%" className="mb-1" />
|
||||||
|
<SkeletonLine height={14} width="20%" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr className="divider my-1" />
|
||||||
|
|
||||||
|
<div className="col-12 mb-3">
|
||||||
|
<SkeletonLine height={14} width="80px" className="mb-1" />
|
||||||
|
<SkeletonLine height={60} className="mb-2" />
|
||||||
|
<div className="d-flex gap-2 flex-wrap">
|
||||||
|
{[...Array(2)].map((_, i) => (
|
||||||
|
<SkeletonLine
|
||||||
|
key={i}
|
||||||
|
height={30}
|
||||||
|
width="100px"
|
||||||
|
className="rounded"
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const SkeletonCell = ({ width = "100%", height = 20, className = "", style = {} }) => (
|
||||||
|
<div
|
||||||
|
className={`skeleton ${className}`}
|
||||||
|
style={{
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
borderRadius: 4,
|
||||||
|
...style,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
export const ExpenseTableSkeleton = ({ groups = 3, rowsPerGroup = 3 }) => {
|
||||||
|
return (
|
||||||
|
<div className="card px-2">
|
||||||
|
<table
|
||||||
|
className="card-body table border-top dataTable no-footer dtr-column text-nowrap"
|
||||||
|
aria-describedby="DataTables_Table_0_info"
|
||||||
|
id="horizontal-example"
|
||||||
|
>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th className="d-none d-sm-table-cell">
|
||||||
|
<div className="text-start ms-5">Expense Type</div>
|
||||||
|
</th>
|
||||||
|
<th className="d-none d-sm-table-cell">
|
||||||
|
<div className="text-start ms-5">Payment Mode</div>
|
||||||
|
</th>
|
||||||
|
<th className="d-none d-sm-table-cell">Paid By</th>
|
||||||
|
<th className="d-none d-md-table-cell">Amount</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
{[...Array(groups)].map((_, groupIdx) => (
|
||||||
|
<React.Fragment key={`group-${groupIdx}`}>
|
||||||
|
{/* Fake Date Group Header Row */}
|
||||||
|
<tr className="bg-light">
|
||||||
|
<td colSpan={8}>
|
||||||
|
<SkeletonCell width="150px" height={20} />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{/* Rows under this group */}
|
||||||
|
{[...Array(rowsPerGroup)].map((__, rowIdx) => (
|
||||||
|
<tr key={`row-${groupIdx}-${rowIdx}`} className={rowIdx % 2 === 0 ? "odd" : "even"}>
|
||||||
|
{/* Expense Type */}
|
||||||
|
<td className="text-start d-none d-sm-table-cell ms-5">
|
||||||
|
<SkeletonCell width="90px" height={16} />
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Payment Mode */}
|
||||||
|
<td className="text-start d-none d-sm-table-cell ms-5">
|
||||||
|
<SkeletonCell width="90px" height={16} />
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Paid By (Avatar + name) */}
|
||||||
|
<td className="text-start d-none d-sm-table-cell ms-5">
|
||||||
|
<div className="d-flex align-items-center gap-2">
|
||||||
|
<SkeletonCell width="30px" height={30} className="rounded-circle" />
|
||||||
|
<SkeletonCell width="80px" height={16} />
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Amount */}
|
||||||
|
<td className="d-none d-md-table-cell text-end">
|
||||||
|
<SkeletonCell width="60px" height={16} />
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Status */}
|
||||||
|
<td>
|
||||||
|
<SkeletonCell width="80px" height={22} className="rounded" />
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Action */}
|
||||||
|
<td>
|
||||||
|
<div className="d-flex justify-content-center align-items-center gap-2">
|
||||||
|
{[...Array(3)].map((__, i) => (
|
||||||
|
<SkeletonCell
|
||||||
|
key={i}
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
className="rounded"
|
||||||
|
style={{ display: "inline-block" }}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const ExpenseFilterSkeleton = () => {
|
||||||
|
return (
|
||||||
|
<div className="p-3 text-start">
|
||||||
|
{/* Created Date Label and Skeleton */}
|
||||||
|
<div className="mb-3 w-100">
|
||||||
|
<SkeletonLine height={14} width="120px" className="mb-1" />
|
||||||
|
<SkeletonLine height={36} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row g-2">
|
||||||
|
{/* Project Select */}
|
||||||
|
<div className="col-12 col-md-4 mb-3">
|
||||||
|
<SkeletonLine height={14} width="80px" className="mb-1" />
|
||||||
|
<SkeletonLine height={36} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Submitted By Select */}
|
||||||
|
<div className="col-12 col-md-4 mb-3">
|
||||||
|
<SkeletonLine height={14} width="100px" className="mb-1" />
|
||||||
|
<SkeletonLine height={36} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Paid By Select */}
|
||||||
|
<div className="col-12 col-md-4 mb-3">
|
||||||
|
<SkeletonLine height={14} width="70px" className="mb-1" />
|
||||||
|
<SkeletonLine height={36} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Status Checkboxes */}
|
||||||
|
<div className="col-12 mb-3">
|
||||||
|
<SkeletonLine height={14} width="80px" className="mb-2" />
|
||||||
|
<div className="d-flex flex-wrap">
|
||||||
|
{[...Array(3)].map((_, i) => (
|
||||||
|
<div className="d-flex align-items-center me-3 mb-2" key={i}>
|
||||||
|
<div
|
||||||
|
className="form-check-input bg-secondary me-2"
|
||||||
|
style={{
|
||||||
|
height: "16px",
|
||||||
|
width: "16px",
|
||||||
|
borderRadius: "3px",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<SkeletonLine height={14} width="60px" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Buttons */}
|
||||||
|
<div className="d-flex justify-content-end py-3 gap-2">
|
||||||
|
<SkeletonLine height={30} width="80px" className="rounded" />
|
||||||
|
<SkeletonLine height={30} width="80px" className="rounded" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
561
src/components/Expenses/ManageExpense.jsx
Normal file
561
src/components/Expenses/ManageExpense.jsx
Normal file
@ -0,0 +1,561 @@
|
|||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { defaultExpense, ExpenseSchema } from "./ExpenseSchema";
|
||||||
|
import { formatFileSize } from "../../utils/appUtils";
|
||||||
|
import { useProjectName } from "../../hooks/useProjects";
|
||||||
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
import { changeMaster } from "../../slices/localVariablesSlice";
|
||||||
|
import useMaster, {
|
||||||
|
useExpenseStatus,
|
||||||
|
useExpenseType,
|
||||||
|
usePaymentMode,
|
||||||
|
} from "../../hooks/masterHook/useMaster";
|
||||||
|
import {
|
||||||
|
useEmployeesAllOrByProjectId,
|
||||||
|
useEmployeesByProject,
|
||||||
|
} from "../../hooks/useEmployees";
|
||||||
|
import Avatar from "../common/Avatar";
|
||||||
|
import {
|
||||||
|
useCreateExpnse,
|
||||||
|
useExpense,
|
||||||
|
useUpdateExpense,
|
||||||
|
} from "../../hooks/useExpense";
|
||||||
|
import ExpenseSkeleton from "./ExpenseSkeleton";
|
||||||
|
import moment from "moment";
|
||||||
|
import DatePicker from "../common/DatePicker";
|
||||||
|
|
||||||
|
const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
isLoading,
|
||||||
|
error: ExpenseErrorLoad,
|
||||||
|
} = useExpense(expenseToEdit);
|
||||||
|
const [ExpenseType, setExpenseType] = useState();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const {
|
||||||
|
ExpenseTypes,
|
||||||
|
loading: ExpenseLoading,
|
||||||
|
error: ExpenseError,
|
||||||
|
} = useExpenseType();
|
||||||
|
const schema = ExpenseSchema(ExpenseTypes);
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
watch,
|
||||||
|
setValue,
|
||||||
|
reset,
|
||||||
|
control,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm({
|
||||||
|
resolver: zodResolver(schema),
|
||||||
|
defaultValues: defaultExpense,
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectedproject = watch("projectId");
|
||||||
|
const selectedProject = useSelector(
|
||||||
|
(store) => store.localVariables.projectId
|
||||||
|
);
|
||||||
|
const { projectNames, loading: projectLoading, error } = useProjectName();
|
||||||
|
debugger
|
||||||
|
const {
|
||||||
|
PaymentModes,
|
||||||
|
loading: PaymentModeLoading,
|
||||||
|
error: PaymentModeError,
|
||||||
|
} = usePaymentMode();
|
||||||
|
const {
|
||||||
|
ExpenseStatus,
|
||||||
|
loading: StatusLoadding,
|
||||||
|
error: stausError,
|
||||||
|
} = useExpenseStatus();
|
||||||
|
const {
|
||||||
|
employees,
|
||||||
|
loading: EmpLoading,
|
||||||
|
error: EmpError,
|
||||||
|
} = useEmployeesByProject(selectedproject);
|
||||||
|
|
||||||
|
const files = watch("billAttachments");
|
||||||
|
const onFileChange = async (e) => {
|
||||||
|
const newFiles = Array.from(e.target.files);
|
||||||
|
if (newFiles.length === 0) return;
|
||||||
|
|
||||||
|
const existingFiles = watch("billAttachments") || [];
|
||||||
|
|
||||||
|
const parsedFiles = await Promise.all(
|
||||||
|
newFiles.map(async (file) => {
|
||||||
|
const base64Data = await toBase64(file);
|
||||||
|
return {
|
||||||
|
fileName: file.name,
|
||||||
|
base64Data,
|
||||||
|
contentType: file.type,
|
||||||
|
fileSize: file.size,
|
||||||
|
description: "",
|
||||||
|
isActive:true
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const combinedFiles = [
|
||||||
|
...existingFiles,
|
||||||
|
...parsedFiles.filter(
|
||||||
|
(newFile) =>
|
||||||
|
!existingFiles.some(
|
||||||
|
(f) =>
|
||||||
|
f.fileName === newFile.fileName && f.fileSize === newFile.fileSize
|
||||||
|
)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
setValue("billAttachments", combinedFiles, {
|
||||||
|
shouldDirty: true,
|
||||||
|
shouldValidate: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const toBase64 = (file) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
reader.onload = () => resolve(reader.result.split(",")[1]);
|
||||||
|
reader.onerror = (error) => reject(error);
|
||||||
|
});
|
||||||
|
const removeFile = (index) => {
|
||||||
|
if (expenseToEdit) {
|
||||||
|
const newFiles = files.map((file, i) => {
|
||||||
|
if (file.documentId !== index) return file;
|
||||||
|
return {
|
||||||
|
...file,
|
||||||
|
isActive: false,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
setValue("billAttachments", newFiles, { shouldValidate: true });
|
||||||
|
} else {
|
||||||
|
const newFiles = files.filter((_, i) => i !== index);
|
||||||
|
setValue("billAttachments", newFiles, { shouldValidate: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (expenseToEdit && data && employees) {
|
||||||
|
reset({
|
||||||
|
projectId: data.project.id || "",
|
||||||
|
expensesTypeId: data.expensesType.id || "",
|
||||||
|
paymentModeId: data.paymentMode.id || "",
|
||||||
|
paidById: data.paidBy.id || "",
|
||||||
|
transactionDate: data.transactionDate?.slice(0, 10) || "",
|
||||||
|
transactionId: data.transactionId || "",
|
||||||
|
description: data.description || "",
|
||||||
|
location: data.location || "",
|
||||||
|
supplerName: data.supplerName || "",
|
||||||
|
amount: data.amount || "",
|
||||||
|
noOfPersons: data.noOfPersons || "",
|
||||||
|
billAttachments: data.documents
|
||||||
|
? data.documents.map((doc) => ({
|
||||||
|
fileName: doc.fileName,
|
||||||
|
base64Data: null,
|
||||||
|
contentType: doc.contentType,
|
||||||
|
documentId: doc.documentId,
|
||||||
|
fileSize: 0,
|
||||||
|
description: "",
|
||||||
|
preSignedUrl: doc.preSignedUrl,
|
||||||
|
isActive: doc.isActive ?? true,
|
||||||
|
}))
|
||||||
|
: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [data, reset, employees]);
|
||||||
|
const { mutate: ExpenseUpdate, isPending } = useUpdateExpense(() =>
|
||||||
|
handleClose()
|
||||||
|
);
|
||||||
|
const { mutate: CreateExpense, isPending: createPending } = useCreateExpnse(
|
||||||
|
() => {
|
||||||
|
handleClose();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const onSubmit = (fromdata) => {
|
||||||
|
let payload = {...fromdata,transactionDate: moment.utc(fromdata.transactionDate, 'DD-MM-YYYY').toISOString()}
|
||||||
|
if (expenseToEdit) {
|
||||||
|
const editPayload = { ...payload, id: data.id };
|
||||||
|
ExpenseUpdate({ id: data.id, payload: editPayload });
|
||||||
|
} else {
|
||||||
|
CreateExpense(payload);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const ExpenseTypeId = watch("expensesTypeId");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setExpenseType(ExpenseTypes?.find((type) => type.id === ExpenseTypeId));
|
||||||
|
}, [ExpenseTypeId]);
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
reset();
|
||||||
|
closeModal();
|
||||||
|
};
|
||||||
|
if (
|
||||||
|
StatusLoadding ||
|
||||||
|
projectLoading ||
|
||||||
|
ExpenseLoading ||
|
||||||
|
isLoading
|
||||||
|
)
|
||||||
|
return <ExpenseSkeleton />;
|
||||||
|
return (
|
||||||
|
<div className="container p-3">
|
||||||
|
<h5 className="m-0">
|
||||||
|
{expenseToEdit ? "Update Expense " : "Create New Expense"}
|
||||||
|
</h5>
|
||||||
|
<form id="expenseForm" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<div className="row my-2">
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label className="form-label">
|
||||||
|
Select Project
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
className="form-select form-select-sm"
|
||||||
|
{...register("projectId")}
|
||||||
|
>
|
||||||
|
<option value="">Select Project</option>
|
||||||
|
{projectLoading ? (
|
||||||
|
<option>Loading...</option>
|
||||||
|
) : (
|
||||||
|
projectNames?.map((project) => (
|
||||||
|
<option key={project.id} value={project.id}>
|
||||||
|
{project.name}
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
{errors.projectId && (
|
||||||
|
<small className="danger-text">{errors.projectId.message}</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label htmlFor="expensesTypeId" className="form-label ">
|
||||||
|
Expense Type
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
className="form-select form-select-sm"
|
||||||
|
id="expensesTypeId"
|
||||||
|
{...register("expensesTypeId")}
|
||||||
|
>
|
||||||
|
<option value="" disabled>
|
||||||
|
Select Type
|
||||||
|
</option>
|
||||||
|
{ExpenseLoading ? (
|
||||||
|
<option disabled>Loading...</option>
|
||||||
|
) : (
|
||||||
|
ExpenseTypes?.map((expense) => (
|
||||||
|
<option key={expense.id} value={expense.id}>
|
||||||
|
{expense.name}
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
{errors.expensesTypeId && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.expensesTypeId.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row my-2">
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label htmlFor="paymentModeId" className="form-label ">
|
||||||
|
Payment Mode
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
className="form-select form-select-sm"
|
||||||
|
id="paymentModeId"
|
||||||
|
{...register("paymentModeId")}
|
||||||
|
>
|
||||||
|
<option value="" disabled>
|
||||||
|
Select Mode
|
||||||
|
</option>
|
||||||
|
{PaymentModeLoading ? (
|
||||||
|
<option disabled>Loading...</option>
|
||||||
|
) : (
|
||||||
|
PaymentModes?.map((payment) => (
|
||||||
|
<option key={payment.id} value={payment.id}>
|
||||||
|
{payment.name}
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
{errors.paymentModeId && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.paymentModeId.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label htmlFor="paidById" className="form-label ">
|
||||||
|
Paid By
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
className="form-select form-select-sm"
|
||||||
|
id="paymentModeId"
|
||||||
|
{...register("paidById")}
|
||||||
|
disabled={!selectedproject}
|
||||||
|
>
|
||||||
|
<option value="" disabled>
|
||||||
|
Select Person
|
||||||
|
</option>
|
||||||
|
{EmpLoading ? (
|
||||||
|
<option disabled>Loading...</option>
|
||||||
|
) : (
|
||||||
|
employees?.map((emp) => (
|
||||||
|
<option key={emp.id} value={emp.id}>
|
||||||
|
{`${emp.firstName} ${emp.lastName} `}
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
{errors.paidById && (
|
||||||
|
<small className="danger-text">{errors.paidById.message}</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row my-2">
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label htmlFor="transactionDate" className="form-label ">
|
||||||
|
Transaction Date
|
||||||
|
</label>
|
||||||
|
{/* <input
|
||||||
|
type="date"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
placeholder="YYYY-MM-DD"
|
||||||
|
id="flatpickr-date"
|
||||||
|
{...register("transactionDate")}
|
||||||
|
/> */}
|
||||||
|
<DatePicker
|
||||||
|
name="transactionDate"
|
||||||
|
control={control}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{errors.transactionDate && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.transactionDate.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label htmlFor="amount" className="form-label ">
|
||||||
|
Amount
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="amount"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
min="1"
|
||||||
|
step="0.01"
|
||||||
|
inputMode="decimal"
|
||||||
|
{...register("amount", { valueAsNumber: true })}
|
||||||
|
/>
|
||||||
|
{errors.amount && (
|
||||||
|
<small className="danger-text">{errors.amount.message}</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row my-2">
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label htmlFor="supplerName" className="form-label ">
|
||||||
|
Supplier Name/Transporter Name/Other
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="supplerName"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("supplerName")}
|
||||||
|
/>
|
||||||
|
{errors.supplerName && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.supplerName.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label htmlFor="location" className="form-label ">
|
||||||
|
Location
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="location"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("location")}
|
||||||
|
/>
|
||||||
|
{errors.location && (
|
||||||
|
<small className="danger-text">{errors.location.message}</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="row my-2">
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label htmlFor="statusId" className="form-label ">
|
||||||
|
TransactionId
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="transactionId"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
min="1"
|
||||||
|
{...register("transactionId")}
|
||||||
|
/>
|
||||||
|
{errors.transactionId && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.transactionId.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{ExpenseType?.noOfPersonsRequired && (
|
||||||
|
<div className="col-md-6">
|
||||||
|
<label >
|
||||||
|
No. of Persons
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
id="noOfPersons"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("noOfPersons")}
|
||||||
|
inputMode="numeric"
|
||||||
|
/>
|
||||||
|
{errors.noOfPersons && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.noOfPersons.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row my-2">
|
||||||
|
<div className="col-md-12" >
|
||||||
|
<label htmlFor="description">Description</label>
|
||||||
|
<textarea
|
||||||
|
id="description"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("description")}
|
||||||
|
rows="2"
|
||||||
|
></textarea>
|
||||||
|
{errors.description && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.description.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row my-2">
|
||||||
|
<div className="col-md-12">
|
||||||
|
<label className="form-label ">Upload Bill </label>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className="border border-secondary border-dashed rounded p-4 text-center bg-textMuted position-relative"
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
|
onClick={() => document.getElementById("billAttachments").click()}
|
||||||
|
>
|
||||||
|
<i className="bx bx-cloud-upload d-block bx-lg"></i>
|
||||||
|
<span className="text-muted d-block">
|
||||||
|
Click to select or click here to browse
|
||||||
|
</span>
|
||||||
|
<small className="text-muted">(PDF, JPG, PNG, max 5MB)</small>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
id="billAttachments"
|
||||||
|
accept=".pdf,.jpg,.jpeg,.png"
|
||||||
|
multiple
|
||||||
|
style={{ display: "none" }}
|
||||||
|
{...register("billAttachments")}
|
||||||
|
onChange={(e) => {
|
||||||
|
onFileChange(e);
|
||||||
|
e.target.value = "";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{errors.billAttachments && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.billAttachments.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
{files.length > 0 && (
|
||||||
|
<div className="d-block">
|
||||||
|
{files
|
||||||
|
.filter((file) => {
|
||||||
|
if (expenseToEdit) {
|
||||||
|
return file.isActive;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.map((file, idx) => (
|
||||||
|
<a
|
||||||
|
key={idx}
|
||||||
|
className="d-flex justify-content-between text-start p-1"
|
||||||
|
href={file.preSignedUrl || "#"}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<span className="mb-0 text-secondary small d-block">
|
||||||
|
{file.fileName}
|
||||||
|
</span>
|
||||||
|
<span className="text-body-secondary small d-block">
|
||||||
|
{file.fileSize ? formatFileSize(file.fileSize) : ""}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<i
|
||||||
|
className="bx bx-trash bx-sm cursor-pointer text-danger"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
removeFile(expenseToEdit ? file.documentId : idx);
|
||||||
|
}}
|
||||||
|
></i>
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{Array.isArray(errors.billAttachments) &&
|
||||||
|
errors.billAttachments.map((fileError, index) => (
|
||||||
|
<div key={index} className="danger-text small mt-1">
|
||||||
|
{
|
||||||
|
(fileError?.fileSize?.message ||
|
||||||
|
fileError?.contentType?.message ||
|
||||||
|
fileError?.base64Data?.message,
|
||||||
|
fileError?.documentId?.message)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="d-flex justify-content-center gap-2">
|
||||||
|
{" "}
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-primary btn-sm mt-3"
|
||||||
|
disabled={isPending || createPending}
|
||||||
|
>
|
||||||
|
{isPending || createPending ? "Please Wait..." : expenseToEdit ? "Update" : "Submit"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="reset"
|
||||||
|
disabled={isPending || createPending}
|
||||||
|
onClick={handleClose}
|
||||||
|
className="btn btn-secondary btn-sm mt-3"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ManageExpense;
|
||||||
28
src/components/Expenses/PreviewDocument.jsx
Normal file
28
src/components/Expenses/PreviewDocument.jsx
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
const PreviewDocument = ({ imageUrl }) => {
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="d-flex justify-content-center align-items-center" style={{ minHeight: "50vh" }}>
|
||||||
|
{loading && (
|
||||||
|
<div className="text-secondary text-center mb-2">
|
||||||
|
Loading...
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<img
|
||||||
|
src={imageUrl}
|
||||||
|
alt="Full View"
|
||||||
|
className="img-fluid"
|
||||||
|
style={{
|
||||||
|
maxHeight: "100vh",
|
||||||
|
objectFit: "contain",
|
||||||
|
display: loading ? "none" : "block",
|
||||||
|
}}
|
||||||
|
onLoad={() => setLoading(false)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PreviewDocument;
|
||||||
547
src/components/Expenses/ViewExpense.jsx
Normal file
547
src/components/Expenses/ViewExpense.jsx
Normal file
@ -0,0 +1,547 @@
|
|||||||
|
import React, { useState, useMemo } from "react";
|
||||||
|
import {
|
||||||
|
useActionOnExpense,
|
||||||
|
useExpense,
|
||||||
|
useHasAnyPermission,
|
||||||
|
} from "../../hooks/useExpense";
|
||||||
|
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { defaultActionValues, ExpenseActionScheam } from "./ExpenseSchema";
|
||||||
|
import { useExpenseContext } from "../../pages/Expense/ExpensePage";
|
||||||
|
import { getColorNameFromHex } from "../../utils/appUtils";
|
||||||
|
import { ExpenseDetailsSkeleton } from "./ExpenseSkeleton";
|
||||||
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
|
import {
|
||||||
|
EXPENSE_REJECTEDBY,
|
||||||
|
PROCESS_EXPENSE,
|
||||||
|
REVIEW_EXPENSE,
|
||||||
|
} from "../../utils/constants";
|
||||||
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import Avatar from "../common/Avatar";
|
||||||
|
import Error from "../common/Error";
|
||||||
|
import DatePicker from "../common/DatePicker";
|
||||||
|
import { useEmployeeRoles, useEmployeesName } from "../../hooks/useEmployees";
|
||||||
|
import EmployeeSearchInput from "../common/EmployeeSearchInput";
|
||||||
|
import { z } from "zod";
|
||||||
|
import moment from "moment";
|
||||||
|
|
||||||
|
const ViewExpense = ({ ExpenseId }) => {
|
||||||
|
const { data, isLoading, isError, error } = useExpense(ExpenseId);
|
||||||
|
const [IsPaymentProcess, setIsPaymentProcess] = useState(false);
|
||||||
|
const [clickedStatusId, setClickedStatusId] = useState(null);
|
||||||
|
|
||||||
|
const IsReview = useHasUserPermission(REVIEW_EXPENSE);
|
||||||
|
const [imageLoaded, setImageLoaded] = useState({});
|
||||||
|
const { setDocumentView } = useExpenseContext();
|
||||||
|
const ActionSchema = ExpenseActionScheam(IsPaymentProcess) ?? z.object({});
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
setValue,
|
||||||
|
reset,
|
||||||
|
control,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm({
|
||||||
|
resolver: zodResolver(ActionSchema),
|
||||||
|
defaultValues: defaultActionValues,
|
||||||
|
});
|
||||||
|
|
||||||
|
const userPermissions = useSelector(
|
||||||
|
(state) => state?.globalVariables?.loginUser?.featurePermissions || []
|
||||||
|
);
|
||||||
|
const CurrentUser = useSelector(
|
||||||
|
(state) => state?.globalVariables?.loginUser?.employeeInfo
|
||||||
|
);
|
||||||
|
|
||||||
|
const nextStatusWithPermission = useMemo(() => {
|
||||||
|
if (!Array.isArray(data?.nextStatus)) return [];
|
||||||
|
|
||||||
|
return data.nextStatus.filter((status) => {
|
||||||
|
const permissionIds = Array.isArray(status?.permissionIds)
|
||||||
|
? status.permissionIds
|
||||||
|
: [];
|
||||||
|
|
||||||
|
if (permissionIds.length === 0) return true;
|
||||||
|
if (permissionIds.includes(PROCESS_EXPENSE)) {
|
||||||
|
setIsPaymentProcess(true);
|
||||||
|
}
|
||||||
|
return permissionIds.some((id) => userPermissions.includes(id));
|
||||||
|
});
|
||||||
|
}, [data, userPermissions]);
|
||||||
|
|
||||||
|
const IsRejectedExpense = useMemo(() => {
|
||||||
|
return EXPENSE_REJECTEDBY.includes(data?.status?.id);
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
const isCreatedBy = useMemo(() => {
|
||||||
|
return data?.createdBy.id === CurrentUser?.id;
|
||||||
|
}, [data, CurrentUser]);
|
||||||
|
|
||||||
|
const { mutate: MakeAction, isPending } = useActionOnExpense(() => {
|
||||||
|
setClickedStatusId(null);
|
||||||
|
reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
const onSubmit = (formData) => {
|
||||||
|
const Payload = {
|
||||||
|
...formData,
|
||||||
|
reimburseDate: moment
|
||||||
|
.utc(formData.reimburseDate, "DD-MM-YYYY")
|
||||||
|
.toISOString(),
|
||||||
|
expenseId: ExpenseId,
|
||||||
|
comment: formData.comment,
|
||||||
|
};
|
||||||
|
MakeAction(Payload);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isLoading) return <ExpenseDetailsSkeleton />;
|
||||||
|
if (isError) return <Error error={error} />;
|
||||||
|
const handleImageLoad = (id) => {
|
||||||
|
setImageLoaded((prev) => ({ ...prev, [id]: true }));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="container px-3" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<div className="row mb-3">
|
||||||
|
<div className="col-12 mb-3">
|
||||||
|
<h5 className="fw-semibold">Expense Details</h5>
|
||||||
|
<hr />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Row 1 */}
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Transaction Date :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">
|
||||||
|
{formatUTCToLocalTime(data?.transactionDate)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Expense Type :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">{data?.expensesType?.name}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Row 2 */}
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Supplier :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">{data?.supplerName}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Amount :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">₹ {data.amount}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Row 3 */}
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Payment Mode :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">{data?.paymentMode?.name}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Paid By :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">
|
||||||
|
{data?.paidBy?.firstName} {data?.paidBy?.lastName}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Row 4 */}
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Status :
|
||||||
|
</label>
|
||||||
|
<span
|
||||||
|
className={`badge bg-label-${
|
||||||
|
getColorNameFromHex(data?.status?.color) || "secondary"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{data?.status?.name}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Pre-Approved :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">{data.preApproved ? "Yes" : "No"}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Project :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">{data?.project?.name}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<div className="d-flex">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold text-start"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Created At :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">
|
||||||
|
{formatUTCToLocalTime(data?.createdAt, true)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Row 6 */}
|
||||||
|
{data.createdBy && (
|
||||||
|
<div className="col-md-6 mb-3 text-start">
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Created By :
|
||||||
|
</label>
|
||||||
|
<div className="d-flex align-items-center gap-1">
|
||||||
|
<Avatar
|
||||||
|
size="xs"
|
||||||
|
classAvatar="m-0"
|
||||||
|
firstName={data.createdBy?.firstName}
|
||||||
|
lastName={data.createdBy?.lastName}
|
||||||
|
/>
|
||||||
|
<span className="text-muted">
|
||||||
|
{`${data.createdBy?.firstName ?? ""} ${
|
||||||
|
data.createdBy?.lastName ?? ""
|
||||||
|
}`.trim() || "N/A"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{data.reviewedBy && (
|
||||||
|
<div className="col-md-6 mb-3 text-start">
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Reviewed By :
|
||||||
|
</label>
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<Avatar
|
||||||
|
size="xs"
|
||||||
|
classAvatar="m-0"
|
||||||
|
firstName={data.reviewedBy?.firstName}
|
||||||
|
lastName={data.reviewedBy?.lastName}
|
||||||
|
/>
|
||||||
|
<span className="text-muted">
|
||||||
|
{`${data.reviewedBy?.firstName ?? ""} ${
|
||||||
|
data.reviewedBy?.lastName ?? ""
|
||||||
|
}`.trim() || "N/A"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{data.approvedBy && (
|
||||||
|
<div className="col-md-6 mb-3 text-start">
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Approved By :{" "}
|
||||||
|
</label>
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<Avatar
|
||||||
|
size="xs"
|
||||||
|
classAvatar="m-0"
|
||||||
|
firstName={data.approvedBy?.firstName}
|
||||||
|
lastName={data.approvedBy?.lastName}
|
||||||
|
/>
|
||||||
|
<span className="text-muted">
|
||||||
|
{`${data.approvedBy?.firstName ?? ""} ${
|
||||||
|
data.approvedBy?.lastName ?? ""
|
||||||
|
}`.trim() || "N/A"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{data.processedBy && (
|
||||||
|
<div className="col-md-6 mb-3 text-start">
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<label
|
||||||
|
className="form-label me-2 mb-0 fw-semibold"
|
||||||
|
style={{ minWidth: "130px" }}
|
||||||
|
>
|
||||||
|
Processed By :{" "}
|
||||||
|
</label>
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
<Avatar
|
||||||
|
size="xs"
|
||||||
|
classAvatar="m-0"
|
||||||
|
firstName={data.processedBy?.firstName}
|
||||||
|
lastName={data.processedBy?.lastName}
|
||||||
|
/>
|
||||||
|
<span className="text-muted">
|
||||||
|
{`${data.processedBy?.firstName ?? ""} ${
|
||||||
|
data.processedBy?.lastName ?? ""
|
||||||
|
}`.trim() || "N/A"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{data.expensesReimburse && (
|
||||||
|
<div className="row text-start">
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<label className="form-label me-2 mb-0 fw-semibold">
|
||||||
|
Transaction ID :
|
||||||
|
</label>
|
||||||
|
{data.expensesReimburse.reimburseTransactionId || "N/A"}
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<label className="form-label me-2 mb-0 fw-semibold">
|
||||||
|
Reimburse Date :
|
||||||
|
</label>
|
||||||
|
{formatUTCToLocalTime(data.expensesReimburse.reimburseDate)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{data.expensesReimburse && (
|
||||||
|
<>
|
||||||
|
<div className="col-md-6 mb-3 d-flex align-items-center">
|
||||||
|
<label className="form-label me-2 mb-0 fw-semibold">
|
||||||
|
Reimburse By :
|
||||||
|
</label>
|
||||||
|
<Avatar
|
||||||
|
size="xs"
|
||||||
|
classAvatar="m-0 me-1"
|
||||||
|
firstName={data?.expensesReimburse?.reimburseBy?.firstName}
|
||||||
|
lastName={data?.expensesReimburse?.reimburseBy?.lastName}
|
||||||
|
/>
|
||||||
|
<span className="text-muted">
|
||||||
|
{`${data?.expensesReimburse?.reimburseBy?.firstName} ${data?.expensesReimburse?.reimburseBy?.lastName}`.trim()}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="col-md-6 mb-3">
|
||||||
|
<label className="form-label me-2 mb-0 fw-semibold"> Note :</label>{" "}
|
||||||
|
{data.expensesReimburse.reimburseNote}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="text-start">
|
||||||
|
<label className="form-label me-2 mb-0 fw-semibold">
|
||||||
|
Description :
|
||||||
|
</label>
|
||||||
|
<div className="text-muted">{data?.description}</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-12 my-2 text-start">
|
||||||
|
<label className="form-label me-2 mb-0 fw-semibold">Attachment :</label>
|
||||||
|
|
||||||
|
{data?.documents?.map((doc) => {
|
||||||
|
const getIconByType = (type) => {
|
||||||
|
if (!type) return "bx bx-file";
|
||||||
|
|
||||||
|
if (type.includes("pdf")) return "bxs-file-pdf";
|
||||||
|
if (type.includes("word")) return "bxs-file-doc";
|
||||||
|
if (type.includes("excel") || type.includes("spreadsheet"))
|
||||||
|
return "bxs-file-xls";
|
||||||
|
if (type.includes("image")) return "bxs-file-image";
|
||||||
|
if (type.includes("zip") || type.includes("rar"))
|
||||||
|
return "bxs-file-archive";
|
||||||
|
|
||||||
|
return "bx bx-file";
|
||||||
|
};
|
||||||
|
|
||||||
|
const isImage = doc.contentType?.includes("image");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="list-group-item list-group-item-action d-flex align-items-center"
|
||||||
|
key={doc.documentId}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="rounded me-1 d-flex align-items-center justify-content-center cursor-pointer"
|
||||||
|
style={{ height: "50px", width: "60px", position: "relative" }}
|
||||||
|
onClick={() => {
|
||||||
|
if (isImage) {
|
||||||
|
setDocumentView({
|
||||||
|
IsOpen: true,
|
||||||
|
Image: doc.preSignedUrl,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
className={`bx ${getIconByType(
|
||||||
|
doc.contentType
|
||||||
|
)} text-primary`}
|
||||||
|
style={{ fontSize: "35px" }}
|
||||||
|
></i>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="w-100">
|
||||||
|
<small className="mb-0 small">{doc.fileName}</small>
|
||||||
|
<div className="d">
|
||||||
|
<a
|
||||||
|
href={doc.preSignedUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="bx bx-cloud-download cursor-pointer"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr className="divider my-1" />
|
||||||
|
|
||||||
|
{Array.isArray(data?.nextStatus) && data.nextStatus.length > 0 && (
|
||||||
|
<>
|
||||||
|
{IsPaymentProcess && nextStatusWithPermission?.length > 0 && (
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-12 col-md-6 text-start">
|
||||||
|
<label className="form-label">Transaction Id </label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("reimburseTransactionId")}
|
||||||
|
/>
|
||||||
|
{errors.reimburseTransactionId && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.reimburseTransactionId.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-6 text-start">
|
||||||
|
<label className="form-label">Transaction Date </label>
|
||||||
|
<DatePicker
|
||||||
|
name="reimburseDate"
|
||||||
|
control={control}
|
||||||
|
minDate={data?.transactionDate}
|
||||||
|
/>
|
||||||
|
{errors.reimburseDate && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.reimburseDate.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-6 text-start">
|
||||||
|
<label className="form-label">Employeee </label>
|
||||||
|
<EmployeeSearchInput
|
||||||
|
control={control}
|
||||||
|
name="reimburseById"
|
||||||
|
projectId={null}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="col-12 mb-3 text-start">
|
||||||
|
{((nextStatusWithPermission.length > 0 && !IsRejectedExpense) ||
|
||||||
|
(IsRejectedExpense && isCreatedBy)) && (
|
||||||
|
<>
|
||||||
|
<label className="form-label me-2 mb-0">Comment:</label>
|
||||||
|
<textarea
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...register("comment")}
|
||||||
|
rows="2"
|
||||||
|
/>
|
||||||
|
{errors.comment && (
|
||||||
|
<small className="danger-text">
|
||||||
|
{errors.comment.message}
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{nextStatusWithPermission?.length > 0 &&
|
||||||
|
(!IsRejectedExpense || isCreatedBy) && (
|
||||||
|
<div className="text-center flex-wrap gap-2 my-2">
|
||||||
|
{nextStatusWithPermission.map((status, index) => (
|
||||||
|
<button
|
||||||
|
key={status.id || index}
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
setClickedStatusId(status.id);
|
||||||
|
setValue("statusId", status.id);
|
||||||
|
handleSubmit(onSubmit)();
|
||||||
|
}}
|
||||||
|
disabled={isPending}
|
||||||
|
className="btn btn-primary btn-sm cursor-pointer mx-2 border-0"
|
||||||
|
>
|
||||||
|
{isPending && clickedStatusId === status.id
|
||||||
|
? "Please Wait..."
|
||||||
|
: status.displayName || status.name}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ViewExpense;
|
||||||
@ -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";
|
||||||
@ -28,9 +28,17 @@ const Header = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
|
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
|
||||||
|
|
||||||
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 = /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname) ;
|
const isDashboard =
|
||||||
|
/^\/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);
|
||||||
@ -49,7 +57,7 @@ const Header = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
AuthRepository.logout(data)
|
AuthRepository.logout(data)
|
||||||
.then((response) => {
|
.then(() => {
|
||||||
localStorage.removeItem("jwtToken");
|
localStorage.removeItem("jwtToken");
|
||||||
localStorage.removeItem("refreshToken");
|
localStorage.removeItem("refreshToken");
|
||||||
localStorage.removeItem("user");
|
localStorage.removeItem("user");
|
||||||
@ -57,11 +65,11 @@ const Header = () => {
|
|||||||
clearAllCache();
|
clearAllCache();
|
||||||
window.location.href = "/auth/login";
|
window.location.href = "/auth/login";
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(() => {
|
||||||
// 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";
|
||||||
});
|
});
|
||||||
@ -79,22 +87,30 @@ const Header = () => {
|
|||||||
|
|
||||||
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
||||||
|
|
||||||
const selectedProject = useSelector(
|
const selectedProject = useSelectedproject();
|
||||||
(store) => store.localVariables.projectId
|
|
||||||
);
|
|
||||||
|
|
||||||
// Determine the display text for the project dropdown
|
const projectsForDropdown = isDashboard
|
||||||
let displayText = "All Projects";
|
? projectNames
|
||||||
if (selectedProject === null) {
|
: projectNames?.filter(project =>
|
||||||
displayText = "All Projects";
|
allowedProjectStatusIds.includes(project.projectStatusId)
|
||||||
} else if (selectedProject) {
|
);
|
||||||
const selectedProjectObj = projectNames?.find(
|
|
||||||
(p) => p?.id === selectedProject
|
let currentProjectDisplayName;
|
||||||
);
|
if (projectLoading) {
|
||||||
// Fallback to selectedProject ID if name not found during loading or mismatch
|
currentProjectDisplayName = "Loading...";
|
||||||
displayText = selectedProjectObj ? selectedProjectObj.name : selectedProject;
|
} else if (!projectNames || projectNames.length === 0) {
|
||||||
} else if (projectLoading) {
|
currentProjectDisplayName = "No Projects Assigned";
|
||||||
displayText = "Loading...";
|
} else if (projectNames.length === 1) {
|
||||||
|
currentProjectDisplayName = projectNames[0].name;
|
||||||
|
} else {
|
||||||
|
if (selectedProject === null) {
|
||||||
|
currentProjectDisplayName = "All Projects";
|
||||||
|
} else {
|
||||||
|
const selectedProjectObj = projectNames.find(
|
||||||
|
(p) => p?.id === selectedProject
|
||||||
|
);
|
||||||
|
currentProjectDisplayName = selectedProjectObj ? selectedProjectObj.name : "All Projects";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { openChangePassword } = useChangePassword();
|
const { openChangePassword } = useChangePassword();
|
||||||
@ -106,17 +122,18 @@ const Header = () => {
|
|||||||
selectedProject === undefined &&
|
selectedProject === undefined &&
|
||||||
!getCachedData("hasReceived")
|
!getCachedData("hasReceived")
|
||||||
) {
|
) {
|
||||||
if(isDashboard){
|
if (projectNames.length === 1) {
|
||||||
dispatch(setProjectId(null));
|
dispatch(setProjectId(projectNames[0]?.id || null));
|
||||||
}else{
|
} else {
|
||||||
dispatch(setProjectId(projectNames[0]?.id));
|
if (isDashboard) {
|
||||||
|
dispatch(setProjectId(null));
|
||||||
|
} else {
|
||||||
|
const firstAllowedProject = projectNames.find(project => allowedProjectStatusIds.includes(project.projectStatusId));
|
||||||
|
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(
|
||||||
@ -160,14 +177,15 @@ const Header = () => {
|
|||||||
};
|
};
|
||||||
}, [handler, newProjectHandler]);
|
}, [handler, newProjectHandler]);
|
||||||
|
|
||||||
const handleProjectChange =(project)=>{
|
const handleProjectChange = (project) => {
|
||||||
if(isProjectPath){
|
dispatch(setProjectId(project));
|
||||||
dispatch(setProjectId(project))
|
|
||||||
navigate("/projects/details")
|
if (isProjectPath && project !== null) {
|
||||||
} else{
|
navigate("/projects/details");
|
||||||
dispatch(setProjectId(project))
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const shouldShowDropdown = projectNames && projectNames.length > 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav
|
<nav
|
||||||
@ -190,39 +208,43 @@ 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">
|
||||||
<button
|
{shouldShowDropdown ? (
|
||||||
className={`btn btn-sm-sm btn-xl ${projectNames.length > 0 ? "dropdown-toggle" : ""
|
<button
|
||||||
} px-1`}
|
className={`btn btn-sm-sm btn-xl dropdown-toggle px-1`}
|
||||||
type="button"
|
type="button"
|
||||||
data-bs-toggle="dropdown"
|
data-bs-toggle="dropdown"
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
>
|
>
|
||||||
{displayText}
|
{currentProjectDisplayName}
|
||||||
</button>
|
</button>
|
||||||
|
) : (
|
||||||
|
<span className="btn btn-sm-sm btn-xl px-1">
|
||||||
|
{currentProjectDisplayName}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
{projectNames.length > 0 && (
|
{shouldShowDropdown && projectsForDropdown && projectsForDropdown.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={() => dispatch(setProjectId(null))}
|
onClick={() => handleProjectChange(null)}
|
||||||
>
|
>
|
||||||
All Projects
|
All Projects
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
)}
|
)}
|
||||||
{[...projectNames]
|
{[...projectsForDropdown]
|
||||||
.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}>
|
||||||
<button
|
<button
|
||||||
className="dropdown-item"
|
className="dropdown-item"
|
||||||
onClick={()=>handleProjectChange(project?.id)}
|
onClick={() => handleProjectChange(project?.id)}
|
||||||
>
|
>
|
||||||
{project?.name}
|
{project?.name}
|
||||||
{project?.shortName && (
|
{project?.shortName && (
|
||||||
@ -239,7 +261,6 @@ 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
|
||||||
|
|||||||
@ -1,17 +1,18 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { getProjectStatusName } from "../../utils/projectStatus";
|
import { getProjectStatusName } from "../../utils/projectStatus";
|
||||||
import {useProjectDetails, useUpdateProject} from "../../hooks/useProjects";
|
import { useProjectDetails, useUpdateProject } from "../../hooks/useProjects";
|
||||||
import { useSelector } from "react-redux"; // Import useSelector
|
import { useSelector } from "react-redux"; // Import useSelector
|
||||||
import {useHasUserPermission} from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
import {MANAGE_PROJECT} from "../../utils/constants";
|
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);
|
||||||
const {mutate: UpdateProjectDetails, isPending} = useUpdateProject({
|
const { mutate: UpdateProjectDetails, isPending } = useUpdateProject({
|
||||||
onSuccessCallback: () => {
|
onSuccessCallback: () => {
|
||||||
setIsOpenModal(false);
|
setIsOpenModal(false);
|
||||||
}
|
}
|
||||||
@ -19,14 +20,15 @@ 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
|
||||||
|
|
||||||
const handleFormSubmit = ( updatedProject ) => {
|
const handleFormSubmit = (updatedProject) => {
|
||||||
if ( projects_Details?.id ) {
|
if (projects_Details?.id) {
|
||||||
UpdateProjectDetails({ projectId: projects_Details?.id,updatedData: updatedProject });
|
UpdateProjectDetails({ projectId: projects_Details?.id, updatedData: updatedProject });
|
||||||
// The refetch here might be redundant or could be handled by react-query's invalidateQueries
|
// The refetch here might be redundant or could be handled by react-query's invalidateQueries
|
||||||
// if UpdateProjectDetails properly invalidates the 'projectDetails' query key.
|
// if UpdateProjectDetails properly invalidates the 'projectDetails' query key.
|
||||||
// If refetch is still needed, consider adding a delay or using onSuccess of UpdateProjectDetails.
|
// If refetch is still needed, consider adding a delay or using onSuccess of UpdateProjectDetails.
|
||||||
@ -38,98 +40,113 @@ const AboutProject = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{IsOpenModal && (
|
{IsOpenModal && (
|
||||||
<GlobalModel isOpen={IsOpenModal} closeModal={()=>setIsOpenModal(false)}>
|
<GlobalModel isOpen={IsOpenModal} closeModal={() => setIsOpenModal(false)}>
|
||||||
<ManageProjectInfo
|
<ManageProjectInfo
|
||||||
project={projects_Details}
|
project={projects_Details}
|
||||||
handleSubmitForm={handleFormSubmit}
|
handleSubmitForm={handleFormSubmit}
|
||||||
onClose={() => setIsOpenModal( false )}
|
onClose={() => setIsOpenModal(false)}
|
||||||
isPending={isPending}
|
isPending={isPending}
|
||||||
/>
|
/>
|
||||||
</GlobalModel>
|
</GlobalModel>
|
||||||
)}
|
)}
|
||||||
{projects_Details && (
|
{projects_Details && (
|
||||||
<>
|
<>
|
||||||
<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">
|
<h6 className="card-action-title mb-0 ps-1">
|
||||||
{" "}
|
{" "}
|
||||||
<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-2">
|
<ul className="list-unstyled my-3 ps-0">
|
||||||
<li className="d-flex align-items-center mb-3">
|
<li className="d-flex mb-3">
|
||||||
<i className="bx bx-cog"></i>
|
<div className="d-flex align-items-center" style={{ width: '120px' }}> {/* Adjust width as needed for alignment */}
|
||||||
<span className="fw-medium mx-2">Name:</span>{" "}
|
<i className="bx bx-cog"></i>
|
||||||
<span>{projects_Details.name}</span>
|
<span className="fw-medium mx-2">Name:</span>
|
||||||
</li>
|
</div>
|
||||||
<li className="d-flex align-items-center mb-3">
|
<span>{projects_Details.name}</span>
|
||||||
<i className="bx bx-fingerprint"></i>
|
</li>
|
||||||
<span className="fw-medium mx-2">Nick Name:</span>{" "}
|
<li className="d-flex mb-3">
|
||||||
<span> {projects_Details.shortName} </span>
|
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
||||||
</li>
|
<i className="bx bx-fingerprint"></i>
|
||||||
<li className="d-flex align-items-center mb-3">
|
<span className="fw-medium mx-2">Nick Name:</span>
|
||||||
<i className="bx bx-check"></i>
|
</div>
|
||||||
<span className="fw-medium mx-2">Start Date:</span>{" "}
|
<span>{projects_Details.shortName}</span>
|
||||||
<span>
|
</li>
|
||||||
{projects_Details.startDate
|
<li className="d-flex mb-3">
|
||||||
? moment(projects_Details.startDate).format("DD-MMM-YYYY")
|
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
||||||
: "N/A"}
|
<i className="bx bx-check"></i>
|
||||||
</span>
|
<span className="fw-medium mx-2">Start Date:</span>
|
||||||
</li>
|
</div>
|
||||||
<li className="d-flex align-items-center mb-3">
|
<span>
|
||||||
<i className="bx bx-stop-circle"></i>{" "}
|
{projects_Details.startDate
|
||||||
<span className="fw-medium mx-2">End Date:</span>{" "}
|
? moment(projects_Details.startDate).format("DD-MMM-YYYY")
|
||||||
<span>
|
: "N/A"}
|
||||||
{projects_Details.endDate
|
</span>
|
||||||
? moment(projects_Details.endDate).format("DD-MMM-YYYY")
|
</li>
|
||||||
: "N/A"}
|
<li className="d-flex mb-3">
|
||||||
</span>
|
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
||||||
</li>
|
<i className="bx bx-stop-circle"></i>
|
||||||
<li className="d-flex align-items-center mb-3">
|
<span className="fw-medium mx-2">End Date:</span>
|
||||||
<i className="bx bx-trophy"></i>
|
</div>
|
||||||
<span className="fw-medium mx-2">Status:</span>{" "}
|
<span>
|
||||||
<span>{projects_Details?.projectStatus?.status}</span>
|
{projects_Details.endDate
|
||||||
</li>
|
? moment(projects_Details.endDate).format("DD-MMM-YYYY")
|
||||||
<li className="d-flex align-items-center mb-3">
|
: "N/A"}
|
||||||
<i className="bx bx-user"></i>
|
</span>
|
||||||
<span className="fw-medium mx-2">Contact:</span>{" "}
|
</li>
|
||||||
<span>{projects_Details.contactPerson}</span>
|
<li className="d-flex mb-3">
|
||||||
</li>
|
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
||||||
<li className="d-flex flex-column align-items-start mb-3">
|
<i className="bx bx-trophy"></i>
|
||||||
<div className="d-flex align-items-center">
|
<span className="fw-medium mx-2">Status:</span>
|
||||||
<i className="bx bx-flag"></i>
|
</div>
|
||||||
<span className="fw-medium mx-2">Address:</span>
|
<span>{projects_Details?.projectStatus?.status.replace(/\s/g, '')}</span>
|
||||||
{projects_Details.projectAddress?.length <= 20 && (
|
</li>
|
||||||
<span>{projects_Details.projectAddress}</span>
|
<li className="d-flex mb-3">
|
||||||
)}
|
<div className="d-flex align-items-center" style={{ width: '120px' }}>
|
||||||
</div>
|
<i className="bx bx-user"></i>
|
||||||
{projects_Details.projectAddress?.length > 20 && (
|
<span className="fw-medium mx-2">Contact:</span>
|
||||||
<div className="ms-4 text-start">{projects_Details.projectAddress}</div>
|
</div>
|
||||||
)}
|
<span>{projects_Details.contactPerson}</span>
|
||||||
</li>
|
</li>
|
||||||
|
<li className="d-flex mb-3">
|
||||||
|
{/* Label section with icon */}
|
||||||
|
<div className="d-flex align-items-start" style={{ minWidth: "120px" }}>
|
||||||
|
<i className="bx bx-flag mt-1"></i>
|
||||||
|
<span className="fw-medium mx-2 text-nowrap">Address:</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<li className="d-flex justify-content-center mb-3">
|
{/* Content section that wraps nicely */}
|
||||||
{manageProject && (
|
<div className="flex-grow-1 text-start text-wrap">
|
||||||
<button
|
{projects_Details.projectAddress}
|
||||||
type="button"
|
</div>
|
||||||
className={`btn btn-sm btn-primary ${
|
</li>
|
||||||
!manageProject && "d-none"
|
|
||||||
}`}
|
|
||||||
data-bs-toggle="modal"
|
|
||||||
data-bs-target="#edit-project-modal"
|
<li className="d-flex justify-content-center mt-4"> {/* Added mt-4 for some top margin */}
|
||||||
onClick={()=>setIsOpenModal(true)}
|
{manageProject && (
|
||||||
>
|
<button
|
||||||
Modify Details
|
type="button"
|
||||||
</button>
|
className={`btn btn-sm btn-primary ${!manageProject && "d-none"
|
||||||
)}
|
}`}
|
||||||
</li>
|
data-bs-toggle="modal"
|
||||||
</ul>
|
data-bs-target="#edit-project-modal"
|
||||||
|
onClick={() => setIsOpenModal(true)}
|
||||||
|
>
|
||||||
|
Modify Details
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isLoading && <span>loading...</span>}
|
{isLoading && <span>loading...</span>}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -48,6 +48,9 @@ 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) {
|
||||||
@ -83,7 +86,10 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
const { loading } = useMaster();
|
const { loading } = useMaster();
|
||||||
const { data: jobRoleData } = useMaster();
|
const { data: jobRoleData } = useMaster();
|
||||||
|
|
||||||
const [selectedRole, setSelectedRole] = useState("all");
|
// Changed to an array to hold multiple selected roles
|
||||||
|
const [selectedRoles, setSelectedRoles] = useState(["all"]);
|
||||||
|
// Changed to an array to hold multiple selected roles
|
||||||
|
// const [selectedRoles, setSelectedRoles] = useState(["all"]);
|
||||||
const [displayedSelection, setDisplayedSelection] = useState("");
|
const [displayedSelection, setDisplayedSelection] = useState("");
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -121,20 +127,79 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(changeMaster("Job Role"));
|
dispatch(changeMaster("Job Role"));
|
||||||
|
// Initial state should reflect "All Roles" selected
|
||||||
return () => setSelectedRole("all");
|
setSelectedRoles(["all"]);
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
const handleRoleChange = (event) => {
|
// Modified handleRoleChange to handle multiple selections
|
||||||
setSelectedRole(event.target.value);
|
const handleRoleChange = (event, roleId) => {
|
||||||
|
// If 'all' is selected, clear other selections
|
||||||
|
if (roleId === "all") {
|
||||||
|
setSelectedRoles(["all"]);
|
||||||
|
} else {
|
||||||
|
setSelectedRoles((prevSelectedRoles) => {
|
||||||
|
// If "all" was previously selected, remove it
|
||||||
|
const newRoles = prevSelectedRoles.filter((role) => role !== "all");
|
||||||
|
if (newRoles.includes(roleId)) {
|
||||||
|
// If role is already selected, unselect it
|
||||||
|
return newRoles.filter((id) => id !== roleId);
|
||||||
|
} else {
|
||||||
|
// If role is not selected, add it
|
||||||
|
return [...newRoles, roleId];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const filteredEmployees =
|
useEffect(() => {
|
||||||
selectedRole === "all"
|
// Update displayedSelection based on selectedRoles
|
||||||
? employees
|
if (selectedRoles.includes("all")) {
|
||||||
: employees?.filter(
|
setDisplayedSelection("All Roles");
|
||||||
(emp) => String(emp.jobRoleId || "") === selectedRole
|
} else if (selectedRoles.length > 0) {
|
||||||
);
|
const selectedRoleNames = selectedRoles.map(roleId => {
|
||||||
|
const role = jobRoleData?.find(r => String(r.id) === roleId);
|
||||||
|
return role ? role.name : '';
|
||||||
|
}).filter(Boolean); // Filter out empty strings for roles not found
|
||||||
|
setDisplayedSelection(selectedRoleNames.join(', '));
|
||||||
|
} else {
|
||||||
|
setDisplayedSelection("Select Roles");
|
||||||
|
}
|
||||||
|
}, [selectedRoles, jobRoleData]);
|
||||||
|
|
||||||
|
|
||||||
|
const handleSearchChange = (event) => {
|
||||||
|
setSearchTerm(event.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Filter employees first by role, then by search term AND job role name
|
||||||
|
const filteredEmployees = employees?.filter((emp) => {
|
||||||
|
const matchesRole =
|
||||||
|
selectedRoles.includes("all") || selectedRoles.includes(String(emp.jobRoleId));
|
||||||
|
// Convert both first and last names and job role name to lowercase for case-insensitive matching
|
||||||
|
const fullName = `${emp.firstName} ${emp.lastName}`.toLowerCase();
|
||||||
|
|
||||||
|
const jobRoleName = jobRoleData?.find((role) => role.id === emp.jobRoleId)?.name?.toLowerCase() || "";
|
||||||
|
|
||||||
|
const searchLower = searchTerm.toLowerCase();
|
||||||
|
// Check if the full name OR job role name includes the search term
|
||||||
|
const matchesSearch = fullName.includes(searchLower) || jobRoleName.includes(searchLower);
|
||||||
|
return matchesRole && matchesSearch;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Determine unique job role IDs from the filtered employees (for dropdown options)
|
||||||
|
const uniqueJobRoleIdsInFilteredEmployees = new Set(
|
||||||
|
employees?.map(emp => emp.jobRoleId).filter(Boolean)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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;
|
||||||
@ -159,226 +224,339 @@ 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>
|
||||||
<div className="container my-3">
|
<div className="container my-3">
|
||||||
<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 font-bold">Work Location :</span>
|
<span className="me-2 m-0 fw-bold">Work Location :</span> {/* Changed font-bold to fw-bold */}
|
||||||
{[
|
{[
|
||||||
assignData?.building?.buildingName,
|
assignData?.building?.buildingName,
|
||||||
assignData?.floor?.floorName,
|
assignData?.floor?.floorName,
|
||||||
assignData?.workArea?.areaName,
|
assignData?.workArea?.areaName,
|
||||||
assignData?.workItem?.activityMaster?.activityName,
|
assignData?.workItem?.activityMaster?.activityName,
|
||||||
]
|
]
|
||||||
.filter(Boolean) // Filter out any undefined/null values
|
.filter(Boolean) // Filter out any undefined/null values
|
||||||
.map((item, index, array) => (
|
.map((item, index, array) => (
|
||||||
<span key={index} className="d-flex align-items-center">
|
<span key={index} className="d-flex align-items-center">
|
||||||
{item}
|
{item}
|
||||||
{index < array.length - 1 && (
|
{index < array.length - 1 && (
|
||||||
<i className="bx bx-chevron-right mx-2"></i>
|
<i className="bx bx-chevron-right mx-2"></i>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
))}
|
))}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<div className="form-label text-start">
|
<div className="form-label text-start">
|
||||||
<div className="row mb-1">
|
<div className="row mb-1">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<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="me-2">{displayedSelection}</div>
|
<div className="dropdown position-relative d-inline-block">
|
||||||
<a
|
<a
|
||||||
className="dropdown-toggle hide-arrow cursor-pointer"
|
className={`dropdown-toggle hide-arrow cursor-pointer ${
|
||||||
data-bs-toggle="dropdown"
|
selectedRoles.includes("all") || selectedRoles.length === 0
|
||||||
aria-expanded="false"
|
? "text-secondary"
|
||||||
|
: "text-primary"
|
||||||
|
}`}
|
||||||
|
data-bs-toggle="dropdown"
|
||||||
|
role="button"
|
||||||
|
aria-expanded="false"
|
||||||
|
>
|
||||||
|
<i className="bx bx-slider-alt ms-2"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{/* Badge */}
|
||||||
|
{selectedRolesCount > 0 && (
|
||||||
|
<span
|
||||||
|
className="position-absolute top-0 start-100 translate-middle badge rounded-circle bg-warning text-white"
|
||||||
|
style={{
|
||||||
|
fontSize: "0.65rem",
|
||||||
|
minWidth: "18px",
|
||||||
|
height: "18px",
|
||||||
|
padding: "0",
|
||||||
|
lineHeight: "18px",
|
||||||
|
textAlign: "center",
|
||||||
|
zIndex: 10,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<i className="bx bx-filter bx-lg text-primary"></i>
|
{selectedRolesCount}
|
||||||
</a>
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
<ul className="dropdown-menu p-2 text-capitalize">
|
{/* Dropdown Menu - Corrected: Removed duplicate ul block */}
|
||||||
<li key="all">
|
<ul className="dropdown-menu p-2 text-capitalize" style={{ maxHeight: "300px", overflowY: "auto" }}>
|
||||||
<button
|
<li> {/* Changed key="all" to a unique key if possible, or keep it if "all" is a unique identifier */}
|
||||||
type="button"
|
<div className="form-check dropdown-item py-0">
|
||||||
className="dropdown-item py-1"
|
<input
|
||||||
onClick={() =>
|
className="form-check-input"
|
||||||
handleRoleChange({
|
type="checkbox"
|
||||||
target: { value: "all" },
|
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
|
||||||
</button>
|
</label>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
{jobRolesForDropdown?.map((role) => (
|
||||||
|
<li key={role.id}>
|
||||||
|
<div className="form-check dropdown-item py-0">
|
||||||
|
<input
|
||||||
|
className="form-check-input"
|
||||||
|
type="checkbox"
|
||||||
|
id={`checkboxRole-${role.id}`} // Unique ID
|
||||||
|
value={role.id}
|
||||||
|
checked={selectedRoles.includes(String(role.id))}
|
||||||
|
onChange={(e) => handleRoleChange(e, e.target.value)}
|
||||||
|
/>
|
||||||
|
<label className="form-check-label ms-2" htmlFor={`checkboxRole-${role.id}`}>
|
||||||
|
{role.name}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{jobRoleData?.map((user) => (
|
))}
|
||||||
<li key={user.id}>
|
</ul>
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="dropdown-item py-1"
|
|
||||||
value={user.id}
|
|
||||||
onClick={handleRoleChange}
|
|
||||||
>
|
|
||||||
{user.name}
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</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
|
||||||
|
className="col-12 mt-2"
|
||||||
|
style={{ maxHeight: "280px", overflowY: "auto", overflowX: "hidden" }}
|
||||||
|
>
|
||||||
|
{selectedRoles?.length > 0 && (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-12 h-sm-25 overflow-auto mt-2">
|
{employeeLoading ? (
|
||||||
{selectedRole !== "" && (
|
<div className="col-12">
|
||||||
<div className="row">
|
<p className="text-center">Loading employees...</p>
|
||||||
{employeeLoading ? (
|
</div>
|
||||||
<div className="col-12">
|
) : filteredEmployees?.length > 0 ? (
|
||||||
<p className="text-center">Loading employees...</p>
|
filteredEmployees.map((emp) => {
|
||||||
</div>
|
const jobRole = jobRoleData?.find(
|
||||||
) : filteredEmployees?.length > 0 ? (
|
(role) => role?.id === emp?.jobRoleId
|
||||||
filteredEmployees.map((emp) => {
|
);
|
||||||
const jobRole = jobRoleData?.find(
|
|
||||||
(role) => role?.id === emp?.jobRoleId
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={emp.id}
|
key={emp.id}
|
||||||
className="col-6 col-md-4 col-lg-3 mb-3"
|
className="col-6 col-md-4 col-lg-3 mb-3"
|
||||||
>
|
>
|
||||||
<div className="form-check d-flex align-items-start">
|
<div className="form-check d-flex align-items-start">
|
||||||
<Controller
|
<Controller
|
||||||
name="selectedEmployees"
|
name="selectedEmployees"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<input
|
<input
|
||||||
{...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}`}
|
id={`employee-${emp?.id}`} // Unique ID
|
||||||
value={emp.id}
|
value={emp.id}
|
||||||
checked={field.value?.includes(emp.id)}
|
checked={field.value?.includes(emp.id)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
handleCheckboxChange(e, emp);
|
handleCheckboxChange(e, emp);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<div className="flex-grow-1">
|
<div className="flex-grow-1">
|
||||||
<p
|
<p
|
||||||
className="mb-0"
|
className="mb-0"
|
||||||
style={{ fontSize: "13px" }}
|
style={{ fontSize: "13px" }}
|
||||||
>
|
|
||||||
{emp.firstName} {emp.lastName}
|
|
||||||
</p>
|
|
||||||
<small
|
|
||||||
className="text-muted"
|
|
||||||
style={{ fontSize: "11px" }}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<span className="placeholder-glow">
|
|
||||||
<span className="placeholder col-6"></span>
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
jobRole?.name || "Unknown Role"
|
|
||||||
)}
|
|
||||||
</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})
|
|
||||||
) : (
|
|
||||||
<div className="col-12">
|
|
||||||
<p className="text-center">
|
|
||||||
No employees found for the selected role.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
className="col-12 h-25 overflow-auto"
|
|
||||||
style={{ maxHeight: "200px" }}
|
|
||||||
>
|
|
||||||
{watch("selectedEmployees")?.length > 0 && (
|
|
||||||
<div className="mt-1">
|
|
||||||
<div className="text-start px-2">
|
|
||||||
{watch("selectedEmployees")?.map((empId) => {
|
|
||||||
const emp = employees.find((emp) => emp.id === empId);
|
|
||||||
return (
|
|
||||||
emp && (
|
|
||||||
<span
|
|
||||||
key={empId}
|
|
||||||
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}
|
||||||
<p
|
</p>
|
||||||
type="button"
|
<small
|
||||||
className=" btn-close-white p-0 m-0"
|
className="text-muted"
|
||||||
aria-label="Close"
|
style={{ fontSize: "11px" }}
|
||||||
onClick={() => {
|
>
|
||||||
const updatedSelected = watch(
|
{loading ? (
|
||||||
"selectedEmployees"
|
<span className="placeholder-glow">
|
||||||
).filter((id) => id !== empId);
|
<span className="placeholder col-6"></span>
|
||||||
setValue(
|
</span>
|
||||||
"selectedEmployees",
|
) : (
|
||||||
updatedSelected
|
jobRole?.name || "Unknown Role"
|
||||||
);
|
)}
|
||||||
trigger("selectedEmployees");
|
</small>
|
||||||
}}
|
</div>
|
||||||
>
|
</div>
|
||||||
<i className="icon-base bx bx-x icon-md "></i>
|
</div>
|
||||||
</p>
|
);
|
||||||
</span>
|
})
|
||||||
)
|
) : (
|
||||||
);
|
<div className="col-12">
|
||||||
})}
|
<p className="text-center">
|
||||||
</div>
|
No employees found for the selected role(s).
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{!loading && errors.selectedEmployees && (
|
<div
|
||||||
<div className="danger-text mt-1">
|
className="col-12 h-25 overflow-auto"
|
||||||
<p>{errors.selectedEmployees.message}</p>{" "}
|
style={{ maxHeight: "200px" }}
|
||||||
|
>
|
||||||
|
{watch("selectedEmployees")?.length > 0 && (
|
||||||
|
<div className="mt-1">
|
||||||
|
<div className="text-start px-2">
|
||||||
|
{watch("selectedEmployees")?.map((empId) => {
|
||||||
|
const emp = employees.find((emp) => emp.id === empId);
|
||||||
|
return (
|
||||||
|
emp && (
|
||||||
|
<span
|
||||||
|
key={empId}
|
||||||
|
className="badge rounded-pill bg-label-primary d-inline-flex align-items-center me-1 mb-1"
|
||||||
|
>
|
||||||
|
{emp.firstName} {emp.lastName}
|
||||||
|
{/* Changed p tag to button for semantic correctness and accessibility */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn-close btn-close-white ms-1" // Added ms-1 for spacing, removed p-0 m-0
|
||||||
|
aria-label="Remove employee" // More descriptive aria-label
|
||||||
|
onClick={() => {
|
||||||
|
const updatedSelected = watch(
|
||||||
|
"selectedEmployees"
|
||||||
|
).filter((id) => id !== empId);
|
||||||
|
setValue(
|
||||||
|
"selectedEmployees",
|
||||||
|
updatedSelected
|
||||||
|
);
|
||||||
|
trigger("selectedEmployees");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<i className="icon-base bx bx-x icon-md"></i>
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="col-md text-start mx-0 px-0">
|
{!loading && errors.selectedEmployees && (
|
||||||
<div className="form-check form-check-inline mt-3 px-1">
|
<div className="danger-text mt-1">
|
||||||
<label
|
<p>{errors.selectedEmployees.message}</p>{" "}
|
||||||
className="form-text text-dark align-items-center d-flex"
|
</div>
|
||||||
htmlFor="inlineCheckbox1"
|
)}
|
||||||
|
|
||||||
|
<div className="col-md text-start mx-0 px-0">
|
||||||
|
<div className="form-check form-check-inline mt-3 px-1">
|
||||||
|
<label
|
||||||
|
className="form-text text-dark align-items-center d-flex"
|
||||||
|
htmlFor="inlineCheckbox1" // This htmlFor isn't linked to a checkbox in this context
|
||||||
|
>
|
||||||
|
Pending Task of Activity :
|
||||||
|
<label
|
||||||
|
className="form-check-label fs-7 ms-4"
|
||||||
|
htmlFor="inlineCheckbox1" // This htmlFor isn't linked to a checkbox in this context
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
{assignData?.workItem?.plannedWork -
|
||||||
|
assignData?.workItem?.completedWork}
|
||||||
|
</strong>{" "}
|
||||||
|
<u>
|
||||||
|
{
|
||||||
|
assignData?.workItem?.activityMaster
|
||||||
|
?.unitOfMeasurement
|
||||||
|
}
|
||||||
|
</u>
|
||||||
|
</label>
|
||||||
|
<div style={{ display: "flex", alignItems: "center" }}>
|
||||||
|
<div
|
||||||
|
ref={infoRef}
|
||||||
|
tabIndex="0"
|
||||||
|
className="d-flex align-items-center avatar-group justify-content-center ms-2"
|
||||||
|
data-bs-toggle="popover"
|
||||||
|
data-bs-trigger="focus"
|
||||||
|
data-bs-placement="right"
|
||||||
|
data-bs-html="true"
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
>
|
>
|
||||||
Pending Task of Activity :
|
|
||||||
<label
|
<svg
|
||||||
className="form-check-label fs-7 ms-4"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
htmlFor="inlineCheckbox1"
|
width="13"
|
||||||
|
height="13"
|
||||||
|
fill="currentColor"
|
||||||
|
className="bi bi-info-circle"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
>
|
>
|
||||||
<strong>
|
<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" />
|
||||||
{assignData?.workItem?.plannedWork -
|
<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" />
|
||||||
assignData?.workItem?.completedWork}
|
</svg>
|
||||||
</strong>{" "}
|
</div>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Target for Today input and validation */}
|
||||||
|
<div className="col-md text-start mx-0 px-0">
|
||||||
|
<div className="form-check form-check-inline mt-2 px-1 mb-2 text-start">
|
||||||
|
<label
|
||||||
|
className="text-dark text-start d-flex align-items-center flex-wrap form-text"
|
||||||
|
htmlFor="targetForTodayInput" // Added a unique htmlFor for clarity
|
||||||
|
>
|
||||||
|
<span>Target for Today</span>
|
||||||
|
<span style={{ marginLeft: "46px" }}>:</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="form-check form-check-inline col-sm-3 mt-2"
|
||||||
|
style={{ marginLeft: "-28px" }}
|
||||||
|
>
|
||||||
|
<Controller
|
||||||
|
name="plannedTask"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<div className="d-flex align-items-center gap-1 ">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...field}
|
||||||
|
id="defaultFormControlInput" // Consider a more descriptive ID if used elsewhere
|
||||||
|
aria-describedby="defaultFormControlHelp"
|
||||||
|
/>
|
||||||
|
<span style={{ paddingLeft: "6px", whiteSpace: "nowrap" }}>
|
||||||
<u>
|
<u>
|
||||||
|
{" "}
|
||||||
{
|
{
|
||||||
assignData?.workItem?.activityMaster
|
assignData?.workItem?.activityMaster
|
||||||
?.unitOfMeasurement
|
?.unitOfMeasurement
|
||||||
}
|
}
|
||||||
</u>
|
</u>
|
||||||
</label>
|
</span>
|
||||||
<div style={{ display: "flex", alignItems: "center" }}>
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
ref={infoRef}
|
ref={infoRef1}
|
||||||
tabIndex="0"
|
tabIndex="0"
|
||||||
className="d-flex align-items-center avatar-group justify-content-center ms-2"
|
className="d-flex align-items-center avatar-group justify-content-center ms-2"
|
||||||
data-bs-toggle="popover"
|
data-bs-toggle="popover"
|
||||||
@ -401,145 +579,75 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Target for Today input and validation */}
|
|
||||||
<div className="col-md text-start mx-0 px-0">
|
|
||||||
<div className="form-check form-check-inline mt-2 px-1 mb-2 text-start">
|
|
||||||
<label
|
|
||||||
className="text-dark text-start d-flex align-items-center flex-wrap form-text"
|
|
||||||
htmlFor="inlineCheckbox1"
|
|
||||||
>
|
|
||||||
<span>Target for Today</span>
|
|
||||||
<span style={{ marginLeft: "46px" }}>:</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className="form-check form-check-inline col-sm-3 mt-2"
|
|
||||||
style={{ marginLeft: "-28px" }}
|
|
||||||
>
|
|
||||||
<Controller
|
|
||||||
name="plannedTask"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<div className="d-flex align-items-center gap-1 ">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="form-control form-control-sm"
|
|
||||||
{...field}
|
|
||||||
id="defaultFormControlInput"
|
|
||||||
aria-describedby="defaultFormControlHelp"
|
|
||||||
/>
|
|
||||||
<span style={{ paddingLeft: "6px" }}>
|
|
||||||
{
|
|
||||||
assignData?.workItem?.workItem?.activityMaster
|
|
||||||
?.unitOfMeasurement
|
|
||||||
}
|
|
||||||
</span>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
ref={infoRef1}
|
|
||||||
tabIndex="0"
|
|
||||||
className="d-flex align-items-center avatar-group justify-content-center ms-2"
|
|
||||||
data-bs-toggle="popover"
|
|
||||||
data-bs-trigger="focus"
|
|
||||||
data-bs-placement="right"
|
|
||||||
data-bs-html="true"
|
|
||||||
style={{ cursor: "pointer" }}
|
|
||||||
>
|
|
||||||
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="13"
|
|
||||||
height="13"
|
|
||||||
fill="currentColor"
|
|
||||||
className="bi bi-info-circle"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
>
|
|
||||||
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
|
|
||||||
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.547 1.11l1.91-2.011c.241-.256.384-.592.287-.984-.172-.439-.58-.827-1.13-.967a.664.664 0 0 1-.58-.309l-.15-.241-.002-.002zM8 4c-.535 0-.943.372-.943.836 0 .464.408.836.943.836.535 0 .943-.372.943-.836 0-.464-.408-.836-.943-.836z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{errors.plannedTask && (
|
|
||||||
<div className="danger-text mt-1">
|
|
||||||
{errors.plannedTask.message}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isHelpVisible && (
|
|
||||||
<div
|
|
||||||
className="position-absolute bg-white border p-2 rounded shadow"
|
|
||||||
style={{ zIndex: 10, marginLeft: "10px" }}
|
|
||||||
>
|
|
||||||
{/* Add your help content here */}
|
|
||||||
<p className="mb-0">
|
|
||||||
Enter the target value for today's task.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<label
|
|
||||||
className="form-text fs-7 m-1 text-lg text-dark"
|
|
||||||
htmlFor="descriptionTextarea" // Changed htmlFor for better accessibility
|
|
||||||
>
|
|
||||||
Description
|
|
||||||
</label>
|
|
||||||
<Controller
|
|
||||||
name="description"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<textarea
|
|
||||||
{...field}
|
|
||||||
className="form-control"
|
|
||||||
id="descriptionTextarea" // Changed id for better accessibility
|
|
||||||
rows="2"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
{errors.description && (
|
|
||||||
<div className="danger-text">{errors.description.message}</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Submit and Cancel buttons */}
|
{errors.plannedTask && (
|
||||||
<div className="col-12 d-flex justify-content-center align-items-center gap-sm-6 gap-8 text-center mt-1">
|
<div className="danger-text mt-1">
|
||||||
<button
|
{errors.plannedTask.message}
|
||||||
type="submit"
|
</div>
|
||||||
className="btn btn-sm btn-primary "
|
)}
|
||||||
disabled={isSubmitting || loading}
|
|
||||||
|
{isHelpVisible && (
|
||||||
|
<div
|
||||||
|
className="position-absolute bg-white border p-2 rounded shadow"
|
||||||
|
style={{ zIndex: 10, marginLeft: "10px" }}
|
||||||
>
|
>
|
||||||
{isSubmitting ? "Please Wait" : "Submit"}
|
<p className="mb-0">
|
||||||
</button>
|
Enter the target value for today's task.
|
||||||
<button
|
</p>
|
||||||
type="reset"
|
</div>
|
||||||
className="btn btn-sm btn-label-secondary"
|
)}
|
||||||
data-bs-dismiss="modal"
|
</div>
|
||||||
aria-label="Close"
|
|
||||||
onClick={closedModel}
|
<label
|
||||||
disabled={isSubmitting || loading}
|
className="form-text fs-7 m-1 text-dark" // Removed duplicate htmlFor and text-lg
|
||||||
>
|
htmlFor="descriptionTextarea"
|
||||||
Cancel
|
>
|
||||||
</button>
|
Description
|
||||||
</div>
|
</label>
|
||||||
</form>
|
<Controller
|
||||||
|
name="description"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<textarea
|
||||||
|
{...field}
|
||||||
|
className="form-control"
|
||||||
|
id="descriptionTextarea" // Unique ID
|
||||||
|
rows="2"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{errors.description && (
|
||||||
|
<div className="danger-text">{errors.description.message}</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
<div className="col-12 d-flex justify-content-center align-items-center gap-sm-6 gap-8 text-center mt-1">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-sm btn-primary "
|
||||||
|
disabled={isSubmitting || loading}
|
||||||
|
>
|
||||||
|
{isSubmitting ? "Please Wait" : "Submit"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="reset"
|
||||||
|
className="btn btn-sm btn-label-secondary"
|
||||||
|
data-bs-dismiss="modal"
|
||||||
|
aria-label="Close"
|
||||||
|
onClick={closedModel}
|
||||||
|
disabled={isSubmitting || loading}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
</div>
|
||||||
|
</div> );
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AssignTask;
|
export default AssignTask;
|
||||||
@ -15,6 +15,7 @@ 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";
|
||||||
@ -25,7 +26,8 @@ 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,20 +49,7 @@ const ProjectNav = ({ onPillClick, activePill }) => {
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li className="nav-item">
|
|
||||||
<a
|
|
||||||
className={`nav-link ${
|
|
||||||
activePill === "imagegallary" ? "active" : ""
|
|
||||||
} fs-6`}
|
|
||||||
href="#"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.preventDefault(); // Prevent page reload
|
|
||||||
onPillClick("imagegallary");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<i className='bx bxs-cog bx-sm me-1_5'></i> <span className="d-none d-md-inline">project Setup</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
{(DirAdmin || DireManager || DirUser) && (
|
{(DirAdmin || DireManager || DirUser) && (
|
||||||
<li className="nav-item">
|
<li className="nav-item">
|
||||||
<a
|
<a
|
||||||
@ -77,6 +64,20 @@ const ProjectNav = ({ onPillClick, activePill }) => {
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
)}
|
)}
|
||||||
|
<li className="nav-item">
|
||||||
|
<a
|
||||||
|
className={`nav-link ${
|
||||||
|
activePill === "imagegallary" ? "active" : ""
|
||||||
|
} fs-6`}
|
||||||
|
href="#"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault(); // Prevent page reload
|
||||||
|
onPillClick("imagegallary");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<i className='bx bxs-cog bx-sm me-1_5'></i> <span className="d-none d-md-inline">project Setup</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -15,11 +15,13 @@ 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();
|
||||||
@ -293,7 +295,7 @@ const {
|
|||||||
<div className="d-flex flex-column">
|
<div className="d-flex flex-column">
|
||||||
<a
|
<a
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
navigate(`/employee/${item.employeeId}?for=account`)
|
navigate(`/employee/${item.employeeId}?for=attendance`)
|
||||||
}
|
}
|
||||||
className="text-heading text-truncate cursor-pointer"
|
className="text-heading text-truncate cursor-pointer"
|
||||||
>
|
>
|
||||||
|
|||||||
@ -1,39 +1,71 @@
|
|||||||
import React, { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
|
import { useController } from "react-hook-form";
|
||||||
|
|
||||||
const DatePicker = ({ onDateChange }) => {
|
|
||||||
|
const DatePicker = ({
|
||||||
|
name,
|
||||||
|
control,
|
||||||
|
placeholder = "DD-MM-YYYY",
|
||||||
|
className = "",
|
||||||
|
allowText = false,
|
||||||
|
maxDate=new Date(),
|
||||||
|
minDate,
|
||||||
|
...rest
|
||||||
|
}) => {
|
||||||
const inputRef = useRef(null);
|
const inputRef = useRef(null);
|
||||||
|
|
||||||
useEffect(() => {
|
const {
|
||||||
const fp = flatpickr(inputRef.current, {
|
field: { onChange, value, ref }
|
||||||
dateFormat: "Y-m-d",
|
} = useController({
|
||||||
defaultDate: new Date(),
|
name,
|
||||||
onChange: (selectedDates, dateStr) => {
|
control
|
||||||
if (onDateChange) {
|
});
|
||||||
onDateChange(dateStr); // Pass selected date to parent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
useEffect(() => {
|
||||||
// Cleanup flatpickr instance
|
if (inputRef.current) {
|
||||||
fp.destroy();
|
flatpickr(inputRef.current, {
|
||||||
};
|
dateFormat: "d-m-Y",
|
||||||
}, [onDateChange]);
|
allowInput: allowText,
|
||||||
|
defaultDate: value
|
||||||
|
? flatpickr.parseDate(value, "Y-m-d")
|
||||||
|
: null,
|
||||||
|
maxDate:maxDate,
|
||||||
|
minDate:new Date(minDate?.split("T")[0]) ?? undefined,
|
||||||
|
onChange: function (selectedDates, dateStr) {
|
||||||
|
onChange(dateStr);
|
||||||
|
},
|
||||||
|
...rest
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [inputRef]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container mt-3">
|
<div className={` position-relative ${className}`}>
|
||||||
<div className="mb-3">
|
<input
|
||||||
{/* <label htmlFor="flatpickr-single" className="form-label">
|
type="text"
|
||||||
Select Date
|
className="form-control form-control-sm "
|
||||||
</label> */}
|
placeholder={placeholder}
|
||||||
<input
|
defaultValue={
|
||||||
type="text"
|
value ? flatpickr.formatDate(flatpickr.parseDate(value, "Y-m-d"), "d-m-Y") : ""
|
||||||
id="flatpickr-single"
|
}
|
||||||
className="form-control"
|
ref={(el) => {
|
||||||
placeholder="YYYY-MM-DD"
|
inputRef.current = el;
|
||||||
ref={inputRef}
|
ref(el);
|
||||||
/>
|
}}
|
||||||
</div>
|
readOnly={!allowText}
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<span
|
||||||
|
className="position-absolute top-50 end-0 pe-1 translate-middle-y cursor-pointer"
|
||||||
|
onClick={() => {
|
||||||
|
if (inputRef.current && inputRef.current._flatpickr) {
|
||||||
|
inputRef.current._flatpickr.open();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<i className="bx bx-calendar bx-sm fs-5 text-muted"></i>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import React, { useEffect, useRef } from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
|
import { useController, useFormContext, useWatch } from "react-hook-form";
|
||||||
const DateRangePicker = ({
|
const DateRangePicker = ({
|
||||||
|
md,
|
||||||
|
sm,
|
||||||
onRangeChange,
|
onRangeChange,
|
||||||
DateDifference = 7,
|
DateDifference = 7,
|
||||||
endDateMode = "yesterday",
|
endDateMode = "yesterday",
|
||||||
@ -25,11 +27,12 @@ const DateRangePicker = ({
|
|||||||
altInput: true,
|
altInput: true,
|
||||||
altFormat: "d-m-Y",
|
altFormat: "d-m-Y",
|
||||||
defaultDate: [startDate, endDate],
|
defaultDate: [startDate, endDate],
|
||||||
static: true,
|
static: false,
|
||||||
|
// appendTo: document.body,
|
||||||
clickOpens: true,
|
clickOpens: true,
|
||||||
maxDate: endDate, // ✅ Disable future dates
|
maxDate: endDate,
|
||||||
onChange: (selectedDates, dateStr) => {
|
onChange: (selectedDates, dateStr) => {
|
||||||
const [startDateString, endDateString] = dateStr.split(" to ");
|
const [startDateString, endDateString] = dateStr.split(" To ");
|
||||||
onRangeChange?.({ startDate: startDateString, endDate: endDateString });
|
onRangeChange?.({ startDate: startDateString, endDate: endDateString });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -45,14 +48,129 @@ const DateRangePicker = ({
|
|||||||
}, [onRangeChange, DateDifference, endDateMode]);
|
}, [onRangeChange, DateDifference, endDateMode]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<div className={`col-${sm} col-sm-${md} px-1 position-relative`}>
|
||||||
type="text"
|
<input
|
||||||
className="form-control form-control-sm ms-1"
|
type="text"
|
||||||
placeholder="From to End"
|
className="form-control form-control-sm ps-2 pe-5 me-4"
|
||||||
id="flatpickr-range"
|
placeholder="From to End"
|
||||||
ref={inputRef}
|
id="flatpickr-range"
|
||||||
/>
|
ref={inputRef}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<i
|
||||||
|
className="bx bx-calendar calendar-icon cursor-pointer position-absolute top-50 translate-middle-y "
|
||||||
|
style={{ right: "12px" }}
|
||||||
|
></i>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DateRangePicker;
|
export default DateRangePicker;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const DateRangePicker1 = ({
|
||||||
|
startField = "startDate",
|
||||||
|
endField = "endDate",
|
||||||
|
placeholder = "Select date range",
|
||||||
|
className = "",
|
||||||
|
allowText = false,
|
||||||
|
resetSignal, // <- NEW prop
|
||||||
|
...rest
|
||||||
|
}) => {
|
||||||
|
const inputRef = useRef(null);
|
||||||
|
const { control, setValue, getValues } = useFormContext();
|
||||||
|
|
||||||
|
const {
|
||||||
|
field: { ref },
|
||||||
|
} = useController({ name: startField, control });
|
||||||
|
|
||||||
|
const applyDefaultDates = () => {
|
||||||
|
const today = new Date();
|
||||||
|
const past = new Date();
|
||||||
|
past.setDate(today.getDate() - 6);
|
||||||
|
|
||||||
|
const format = (d) => flatpickr.formatDate(d, "d-m-Y");
|
||||||
|
const formattedStart = format(past);
|
||||||
|
const formattedEnd = format(today);
|
||||||
|
|
||||||
|
setValue(startField, formattedStart, { shouldValidate: true });
|
||||||
|
setValue(endField, formattedEnd, { shouldValidate: true });
|
||||||
|
|
||||||
|
if (inputRef.current?._flatpickr) {
|
||||||
|
inputRef.current._flatpickr.setDate([past, today]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!inputRef.current || inputRef.current._flatpickr) return;
|
||||||
|
|
||||||
|
const instance = flatpickr(inputRef.current, {
|
||||||
|
mode: "range",
|
||||||
|
dateFormat: "d-m-Y",
|
||||||
|
allowInput: allowText,
|
||||||
|
onChange: (selectedDates) => {
|
||||||
|
if (selectedDates.length === 2) {
|
||||||
|
const [start, end] = selectedDates;
|
||||||
|
const format = (d) => flatpickr.formatDate(d, "d-m-Y");
|
||||||
|
setValue(startField, format(start), { shouldValidate: true });
|
||||||
|
setValue(endField, format(end), { shouldValidate: true });
|
||||||
|
} else {
|
||||||
|
setValue(startField, "", { shouldValidate: true });
|
||||||
|
setValue(endField, "", { shouldValidate: true });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
...rest,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Apply default if empty
|
||||||
|
const currentStart = getValues(startField);
|
||||||
|
const currentEnd = getValues(endField);
|
||||||
|
if (!currentStart && !currentEnd) {
|
||||||
|
applyDefaultDates();
|
||||||
|
} else if (currentStart && currentEnd) {
|
||||||
|
instance.setDate([
|
||||||
|
flatpickr.parseDate(currentStart, "d-m-Y"),
|
||||||
|
flatpickr.parseDate(currentEnd, "d-m-Y"),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => instance.destroy();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Reapply default range on resetSignal change
|
||||||
|
useEffect(() => {
|
||||||
|
if (resetSignal !== undefined) {
|
||||||
|
applyDefaultDates();
|
||||||
|
}
|
||||||
|
}, [resetSignal]);
|
||||||
|
|
||||||
|
const start = getValues(startField);
|
||||||
|
const end = getValues(endField);
|
||||||
|
const formattedValue = start && end ? `${start} To ${end}` : "";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`position-relative ${className}`}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
placeholder={placeholder}
|
||||||
|
defaultValue={formattedValue}
|
||||||
|
ref={(el) => {
|
||||||
|
inputRef.current = el;
|
||||||
|
ref(el);
|
||||||
|
}}
|
||||||
|
readOnly={!allowText}
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
className="position-absolute top-50 end-0 pe-1 translate-middle-y cursor-pointer"
|
||||||
|
onClick={() => inputRef.current?._flatpickr?.open()}
|
||||||
|
>
|
||||||
|
<i className="bx bx-calendar bx-sm fs-5 text-muted"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
85
src/components/common/EmployeeSearchInput.jsx
Normal file
85
src/components/common/EmployeeSearchInput.jsx
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useEmployeesName } from "../../hooks/useEmployees";
|
||||||
|
import { useDebounce } from "../../utils/appUtils";
|
||||||
|
import { useController } from "react-hook-form";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const EmployeeSearchInput = ({ control, name, projectId }) => {
|
||||||
|
const {
|
||||||
|
field: { onChange, value, ref },
|
||||||
|
fieldState: { error },
|
||||||
|
} = useController({ name, control });
|
||||||
|
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
const [showDropdown, setShowDropdown] = useState(false);
|
||||||
|
const debouncedSearch = useDebounce(search, 500);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: employees,
|
||||||
|
isLoading,
|
||||||
|
} = useEmployeesName(projectId, debouncedSearch);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (value && !search) {
|
||||||
|
const found = employees?.data?.find((emp) => emp.id === value);
|
||||||
|
if (found) setSearch(found.firstName + " " + found.lastName);
|
||||||
|
}
|
||||||
|
}, [value, employees]);
|
||||||
|
|
||||||
|
const handleSelect = (employee) => {
|
||||||
|
onChange(employee.id);
|
||||||
|
setSearch(employee.firstName + " " + employee.lastName);
|
||||||
|
setShowDropdown(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="position-relative">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
ref={ref}
|
||||||
|
className={`form-control form-control-sm`}
|
||||||
|
placeholder="Search employee..."
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => {
|
||||||
|
setSearch(e.target.value);
|
||||||
|
setShowDropdown(true);
|
||||||
|
onChange("");
|
||||||
|
}}
|
||||||
|
onFocus={() => {
|
||||||
|
if (search) setShowDropdown(true);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{showDropdown && (employees?.data?.length > 0 || isLoading) && (
|
||||||
|
<ul
|
||||||
|
className="list-group position-absolute bg-white w-100 shadow z-3 rounded-none"
|
||||||
|
style={{ maxHeight: 200, overflowY: "auto" }}
|
||||||
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<li className="list-group-item">
|
||||||
|
<a>Searching...</a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
) : (
|
||||||
|
employees?.data?.map((emp) => (
|
||||||
|
<li
|
||||||
|
key={emp.id}
|
||||||
|
className="list-group-item list-group-item-action"
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
|
onClick={() => handleSelect(emp)}
|
||||||
|
>
|
||||||
|
{emp.firstName} {emp.lastName}
|
||||||
|
</li>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{error && <small className="danger-text">{error.message}</small>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EmployeeSearchInput;
|
||||||
20
src/components/common/Error.jsx
Normal file
20
src/components/common/Error.jsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
const Error = ({error,close}) => {
|
||||||
|
console.log(error)
|
||||||
|
return (
|
||||||
|
<div className="container text-center py-5">
|
||||||
|
<h1 className="display-4 fw-bold text-danger">{error.statusCode || error?.response?.status
|
||||||
|
}</h1>
|
||||||
|
<h2 className="mb-3">Internal Server Error</h2>
|
||||||
|
<p className="lead">
|
||||||
|
{error.message}
|
||||||
|
</p>
|
||||||
|
<a href="/" className="btn btn-primary btn-sm mt-3" onClick={()=>close()}>
|
||||||
|
Go to Home
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Error
|
||||||
@ -68,6 +68,21 @@ useEffect(() => {
|
|||||||
backgroundColor: 'rgba(0,0,0,0.3)',
|
backgroundColor: 'rgba(0,0,0,0.3)',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getPositionClass = (type) => {
|
||||||
|
switch (type) {
|
||||||
|
case 'top':
|
||||||
|
return 'mt-3';
|
||||||
|
case 'bottom':
|
||||||
|
return 'mt-auto mb-0 d-flex flex-column';
|
||||||
|
case 'left':
|
||||||
|
return 'position-absolute top-50 start-0 translate-middle-y me-auto';
|
||||||
|
case 'right':
|
||||||
|
return 'position-absolute top-50 end-0 translate-middle-y ms-auto';
|
||||||
|
case 'center':
|
||||||
|
default:
|
||||||
|
return 'modal-dialog-centered';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -80,7 +95,7 @@ useEffect(() => {
|
|||||||
{...dataAttributesProps}
|
{...dataAttributesProps}
|
||||||
style={backdropStyle}
|
style={backdropStyle}
|
||||||
>
|
>
|
||||||
<div className={`modal-dialog ${dialogClass} ${modalSizeClass } mx-sm-auto mx-1`} role={role} >
|
<div className={`modal-dialog ${modalSizeClass} ${getPositionClass(modalType)} ${dialogClass} mx-sm-auto mx-1`} role={role}>
|
||||||
<div className="modal-content">
|
<div className="modal-content">
|
||||||
<div className="modal-header p-0">
|
<div className="modal-header p-0">
|
||||||
{/* Close button inside the modal header */}
|
{/* Close button inside the modal header */}
|
||||||
|
|||||||
52
src/components/common/GlobalOffcanvas .jsx
Normal file
52
src/components/common/GlobalOffcanvas .jsx
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import React, { useEffect, useRef } from "react";
|
||||||
|
import { useFab } from "../../Context/FabContext";
|
||||||
|
|
||||||
|
const GlobalOffcanvas = () => {
|
||||||
|
const { offcanvas, setIsOffcanvasOpen } = useFab();
|
||||||
|
const offcanvasRef = useRef();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const el = offcanvasRef.current;
|
||||||
|
const bsOffcanvas = new bootstrap.Offcanvas(el);
|
||||||
|
|
||||||
|
const handleShow = () => setIsOffcanvasOpen(true);
|
||||||
|
const handleHide = () => setIsOffcanvasOpen(false);
|
||||||
|
|
||||||
|
el.addEventListener("show.bs.offcanvas", handleShow);
|
||||||
|
el.addEventListener("hidden.bs.offcanvas", handleHide);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
el.removeEventListener("show.bs.offcanvas", handleShow);
|
||||||
|
el.removeEventListener("hidden.bs.offcanvas", handleHide);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="offcanvas offcanvas-end"
|
||||||
|
tabIndex="-1"
|
||||||
|
id="globalOffcanvas"
|
||||||
|
ref={offcanvasRef}
|
||||||
|
aria-labelledby="offcanvasLabel"
|
||||||
|
data-bs-backdrop="false"
|
||||||
|
data-bs-scroll="true"
|
||||||
|
>
|
||||||
|
<div className="offcanvas-header">
|
||||||
|
<h5 className="offcanvas-title" id="offcanvasLabel">
|
||||||
|
{offcanvas.title}
|
||||||
|
</h5>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn-close text-reset"
|
||||||
|
data-bs-dismiss="offcanvas"
|
||||||
|
aria-label="Close"
|
||||||
|
></button>
|
||||||
|
</div>
|
||||||
|
<div className="offcanvas-body mx-0 py-1 flex-grow-0">
|
||||||
|
{offcanvas.content || <p>No content</p>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default GlobalOffcanvas;
|
||||||
26
src/components/common/OffcanvasTrigger.jsx
Normal file
26
src/components/common/OffcanvasTrigger.jsx
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { createPortal } from "react-dom";
|
||||||
|
import { useFab } from "../../Context/FabContext";
|
||||||
|
|
||||||
|
const OffcanvasTrigger = () => {
|
||||||
|
const { openOffcanvas, offcanvas, showTrigger } = useFab();
|
||||||
|
|
||||||
|
if (!showTrigger || !offcanvas.content) return null;
|
||||||
|
|
||||||
|
const btn = (
|
||||||
|
<i
|
||||||
|
className="bx bx-slider-alt position-fixed p-2 bg-primary text-white rounded-start"
|
||||||
|
onClick={() => openOffcanvas(offcanvas.title, offcanvas.content)}
|
||||||
|
role="button"
|
||||||
|
style={{
|
||||||
|
top: "25%",
|
||||||
|
right: "0%",
|
||||||
|
cursor: "pointer",
|
||||||
|
zIndex: 1056,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
return createPortal(btn, document.body);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OffcanvasTrigger;
|
||||||
84
src/components/common/Pagination.jsx
Normal file
84
src/components/common/Pagination.jsx
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
const getPaginationRange = (currentPage, totalPages, delta = 1) => {
|
||||||
|
const range = [];
|
||||||
|
const rangeWithDots = [];
|
||||||
|
let l;
|
||||||
|
|
||||||
|
for (let i = 1; i <= totalPages; i++) {
|
||||||
|
if (
|
||||||
|
i === 1 ||
|
||||||
|
i === totalPages ||
|
||||||
|
(i >= currentPage - delta && i <= currentPage + delta)
|
||||||
|
) {
|
||||||
|
range.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i of range) {
|
||||||
|
if (l) {
|
||||||
|
if (i - l === 2) {
|
||||||
|
rangeWithDots.push(l + 1);
|
||||||
|
} else if (i - l !== 1) {
|
||||||
|
rangeWithDots.push("...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rangeWithDots.push(i);
|
||||||
|
l = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rangeWithDots;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Pagination = ({ currentPage, totalPages, onPageChange }) => {
|
||||||
|
if (totalPages <= 1) return null;
|
||||||
|
|
||||||
|
const paginationRange = getPaginationRange(currentPage, totalPages);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<nav aria-label="Page navigation">
|
||||||
|
<ul className="pagination pagination-sm justify-content-end py-1 mx-1">
|
||||||
|
<li className={`page-item ${currentPage === 1 ? "disabled" : ""}`}>
|
||||||
|
<button
|
||||||
|
className="page-link btn-xs"
|
||||||
|
onClick={() => onPageChange(currentPage - 1)}
|
||||||
|
>
|
||||||
|
«
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
{paginationRange.map((page, index) => (
|
||||||
|
<li
|
||||||
|
key={index}
|
||||||
|
className={`page-item ${
|
||||||
|
page === currentPage ? "active" : ""
|
||||||
|
} ${page === "..." ? "disabled" : ""}`}
|
||||||
|
>
|
||||||
|
{page === "..." ? (
|
||||||
|
<span className="page-link">…</span>
|
||||||
|
) : (
|
||||||
|
<button className="page-link" onClick={() => onPageChange(page)}>
|
||||||
|
{page}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
|
||||||
|
<li
|
||||||
|
className={`page-item ${
|
||||||
|
currentPage === totalPages ? "disabled" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
className="page-link"
|
||||||
|
onClick={() => onPageChange(currentPage + 1)}
|
||||||
|
>
|
||||||
|
»
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Pagination;
|
||||||
@ -1,12 +1,13 @@
|
|||||||
import React, { useState, useEffect, useRef } from "react";
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
import { useFormContext } from "react-hook-form";
|
import { useFormContext } from "react-hook-form";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
import "./MultiSelectDropdown.css";
|
import "./MultiSelectDropdown.css";
|
||||||
|
|
||||||
const SelectMultiple = ({
|
const SelectMultiple = ({
|
||||||
name,
|
name,
|
||||||
options = [],
|
options = [],
|
||||||
label = "Select options",
|
label = "Select options",
|
||||||
labelKey = "name",
|
labelKey = "name", // Can now be a function or a string
|
||||||
valueKey = "id",
|
valueKey = "id",
|
||||||
placeholder = "Please select...",
|
placeholder = "Please select...",
|
||||||
IsLoading = false,
|
IsLoading = false,
|
||||||
@ -16,11 +17,18 @@ const SelectMultiple = ({
|
|||||||
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
|
const containerRef = useRef(null);
|
||||||
const dropdownRef = useRef(null);
|
const dropdownRef = useRef(null);
|
||||||
|
|
||||||
|
const [dropdownStyles, setDropdownStyles] = useState({ top: 0, left: 0, width: 0 });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleClickOutside = (e) => {
|
const handleClickOutside = (e) => {
|
||||||
if (dropdownRef.current && !dropdownRef.current.contains(e.target)) {
|
if (
|
||||||
|
containerRef.current &&
|
||||||
|
!containerRef.current.contains(e.target) &&
|
||||||
|
(!dropdownRef.current || !dropdownRef.current.contains(e.target))
|
||||||
|
) {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -28,6 +36,21 @@ const SelectMultiple = ({
|
|||||||
return () => document.removeEventListener("mousedown", handleClickOutside);
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen && containerRef.current) {
|
||||||
|
const rect = containerRef.current.getBoundingClientRect();
|
||||||
|
setDropdownStyles({
|
||||||
|
top: rect.bottom + window.scrollY,
|
||||||
|
left: rect.left + window.scrollX,
|
||||||
|
width: rect.width,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
|
const getLabel = (item) => {
|
||||||
|
return typeof labelKey === "function" ? labelKey(item) : item[labelKey];
|
||||||
|
};
|
||||||
|
|
||||||
const handleCheckboxChange = (value) => {
|
const handleCheckboxChange = (value) => {
|
||||||
const updated = selectedValues.includes(value)
|
const updated = selectedValues.includes(value)
|
||||||
? selectedValues.filter((v) => v !== value)
|
? selectedValues.filter((v) => v !== value)
|
||||||
@ -36,96 +59,113 @@ const SelectMultiple = ({
|
|||||||
setValue(name, updated, { shouldValidate: true });
|
setValue(name, updated, { shouldValidate: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
const filteredOptions = options.filter((item) =>
|
const filteredOptions = options.filter((item) => {
|
||||||
item[labelKey]?.toLowerCase().includes(searchText.toLowerCase())
|
const label = getLabel(item);
|
||||||
);
|
return label?.toLowerCase().includes(searchText.toLowerCase());
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
const dropdownElement = (
|
||||||
<div ref={dropdownRef} className="multi-select-dropdown-container">
|
<div
|
||||||
<label className="form-label mb-1">{label}</label>
|
ref={dropdownRef}
|
||||||
|
className="multi-select-dropdown-options"
|
||||||
<div
|
style={{
|
||||||
className="multi-select-dropdown-header"
|
position: "absolute",
|
||||||
onClick={() => setIsOpen((prev) => !prev)}
|
top: dropdownStyles.top,
|
||||||
>
|
left: dropdownStyles.left,
|
||||||
<span
|
width: dropdownStyles.width,
|
||||||
className={
|
zIndex: 9999,
|
||||||
selectedValues.length > 0
|
backgroundColor: "white",
|
||||||
? "placeholder-style-selected"
|
boxShadow: "0 2px 8px rgba(0,0,0,0.15)",
|
||||||
: "placeholder-style"
|
borderRadius: 4,
|
||||||
}
|
maxHeight: 300,
|
||||||
>
|
overflowY: "auto",
|
||||||
<div className="selected-badges-container">
|
}}
|
||||||
{selectedValues.length > 0 ? (
|
>
|
||||||
selectedValues.map((val) => {
|
<div className="multi-select-dropdown-search" style={{ padding: 8 }}>
|
||||||
const found = options.find((opt) => opt[valueKey] === val);
|
<input
|
||||||
return (
|
type="text"
|
||||||
<span
|
placeholder="Search..."
|
||||||
key={val}
|
value={searchText}
|
||||||
className="badge badge-selected-item mx-1 mb-1"
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
>
|
className="multi-select-dropdown-search-input"
|
||||||
{found ? found[labelKey] : ""}
|
style={{ width: "100%", padding: 4 }}
|
||||||
</span>
|
/>
|
||||||
);
|
|
||||||
})
|
|
||||||
) : (
|
|
||||||
<span className="placeholder-text">{placeholder}</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</span>
|
|
||||||
<i className="bx bx-chevron-down"></i>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isOpen && (
|
{filteredOptions.map((item) => {
|
||||||
<div className="multi-select-dropdown-options">
|
const labelVal = getLabel(item);
|
||||||
<div className="multi-select-dropdown-search">
|
const valueVal = item[valueKey];
|
||||||
|
const isChecked = selectedValues.includes(valueVal);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={valueVal}
|
||||||
|
className={`multi-select-dropdown-option ${isChecked ? "selected" : ""}`}
|
||||||
|
style={{ display: "flex", alignItems: "center", padding: "4px 8px" }}
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="checkbox"
|
||||||
placeholder="Search..."
|
className="custom-checkbox form-check-input"
|
||||||
value={searchText}
|
checked={isChecked}
|
||||||
onChange={(e) => setSearchText(e.target.value)}
|
onChange={() => handleCheckboxChange(valueVal)}
|
||||||
className="multi-select-dropdown-search-input"
|
style={{ marginRight: 8 }}
|
||||||
/>
|
/>
|
||||||
|
<label className="text-secondary">{labelVal}</label>
|
||||||
</div>
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
{filteredOptions.map((item) => {
|
{!IsLoading && filteredOptions.length === 0 && (
|
||||||
const labelVal = item[labelKey];
|
<div className="multi-select-dropdown-Not-found" style={{ padding: 8 }}>
|
||||||
const valueVal = item[valueKey];
|
<label className="text-muted">Not Found {`'${searchText}'`}</label>
|
||||||
const isChecked = selectedValues.includes(valueVal);
|
</div>
|
||||||
|
)}
|
||||||
return (
|
{IsLoading && filteredOptions.length === 0 && (
|
||||||
<div
|
<div className="multi-select-dropdown-Not-found" style={{ padding: 8 }}>
|
||||||
key={valueVal}
|
<label className="text-muted">Loading...</label>
|
||||||
className={`multi-select-dropdown-option ${
|
|
||||||
isChecked ? "selected" : ""
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
className="custom-checkbox form-check-input"
|
|
||||||
checked={isChecked}
|
|
||||||
onChange={() => handleCheckboxChange(valueVal)}
|
|
||||||
/>
|
|
||||||
<label className="text-secondary">{labelVal}</label>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
{!IsLoading && filteredOptions.length === 0 && (
|
|
||||||
<div className="multi-select-dropdown-Not-found">
|
|
||||||
<label className="text-muted">
|
|
||||||
Not Found {`'${searchText}'`}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{IsLoading && filteredOptions.length === 0 && (
|
|
||||||
<div className="multi-select-dropdown-Not-found">
|
|
||||||
<label className="text-muted">Loading...</label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div ref={containerRef} className="multi-select-dropdown-container" style={{ position: "relative" }}>
|
||||||
|
<label className="form-label mb-1">{label}</label>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className="multi-select-dropdown-header"
|
||||||
|
onClick={() => setIsOpen((prev) => !prev)}
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
selectedValues.length > 0 ? "placeholder-style-selected" : "placeholder-style"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="selected-badges-container">
|
||||||
|
{selectedValues.length > 0 ? (
|
||||||
|
selectedValues.map((val) => {
|
||||||
|
const found = options.find((opt) => opt[valueKey] === val);
|
||||||
|
const label = found ? getLabel(found) : "";
|
||||||
|
return (
|
||||||
|
<span key={val} className="badge badge-selected-item mx-1 mb-1">
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<span className="placeholder-text">{placeholder}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
<i className="bx bx-chevron-down"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{isOpen && createPortal(dropdownElement, document.body)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SelectMultiple;
|
export default SelectMultiple;
|
||||||
|
|||||||
@ -141,83 +141,92 @@ const CreateRole = ({ modalType, onClose }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-12 col-md-12 border">
|
<div
|
||||||
|
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
|
<div className="row my-1">
|
||||||
className="row my-1"
|
{/* Feature Title */}
|
||||||
key={feature.id}
|
<div className="col-12 text-start fw-semibold mb-2">
|
||||||
style={{ marginLeft: "0px" }}
|
{feature.name}
|
||||||
>
|
|
||||||
<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>
|
||||||
|
|
||||||
<div className="col-12 col-md-1"></div>
|
{/* Permissions Grid */}
|
||||||
|
<div className="col-12">
|
||||||
<div className="col-12 col-md-8 d-flex justify-content-start align-items-center flex-wrap">
|
<div className="row">
|
||||||
{feature.featurePermissions.map((perm, permIndex) => {
|
{feature.featurePermissions.map((perm, permIndex) => {
|
||||||
const refIndex = featureIndex * 10 + permIndex;
|
const refIndex = featureIndex * 100 + permIndex;
|
||||||
return (
|
return (
|
||||||
<div className="d-flex me-3 mb-2" key={perm.id}>
|
<div
|
||||||
<label className="form-check-label" htmlFor={perm.id}>
|
className="col-12 col-sm-6 col-md-4 mb-3"
|
||||||
<input
|
key={perm.id}
|
||||||
type="checkbox"
|
>
|
||||||
className="form-check-input mx-2"
|
<div className="d-flex align-items-start">
|
||||||
id={perm.id}
|
<label
|
||||||
value={perm.id}
|
className="form-check-label d-flex align-items-center"
|
||||||
{...register("selectedPermissions")}
|
htmlFor={perm.id}
|
||||||
/>
|
|
||||||
{perm.name}
|
|
||||||
</label>
|
|
||||||
<div style={{ display: "flex", alignItems: "center" }}>
|
|
||||||
<div
|
|
||||||
key={refIndex}
|
|
||||||
ref={(el) => (popoverRefs.current[refIndex] = el)}
|
|
||||||
tabIndex="0"
|
|
||||||
className="d-flex align-items-center avatar-group justify-content-center"
|
|
||||||
data-bs-toggle="popover"
|
|
||||||
refIndex
|
|
||||||
data-bs-trigger="focus"
|
|
||||||
data-bs-placement="right"
|
|
||||||
data-bs-html="true"
|
|
||||||
data-bs-content={`
|
|
||||||
<div class="border border-secondary rounded custom-popover p-2 px-3">
|
|
||||||
${perm.description}
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
>
|
|
||||||
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="13"
|
|
||||||
height="13"
|
|
||||||
fill="currentColor"
|
|
||||||
className="bi bi-info-circle"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
>
|
>
|
||||||
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
|
<input
|
||||||
<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" />
|
type="checkbox"
|
||||||
</svg>
|
className="form-check-input me-2"
|
||||||
|
id={perm.id}
|
||||||
|
value={perm.id}
|
||||||
|
{...register("selectedPermissions")}
|
||||||
|
/>
|
||||||
|
{perm.name}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{/* Info icon */}
|
||||||
|
<div className="ms-1 d-flex align-items-center">
|
||||||
|
<div
|
||||||
|
ref={(el) => (popoverRefs.current[refIndex] = el)}
|
||||||
|
tabIndex="0"
|
||||||
|
className="d-flex align-items-center justify-content-center"
|
||||||
|
data-bs-toggle="popover"
|
||||||
|
data-bs-trigger="focus"
|
||||||
|
data-bs-placement="right"
|
||||||
|
data-bs-html="true"
|
||||||
|
data-bs-content={`<div class="border border-secondary rounded custom-popover p-2 px-3">${perm.description}</div>`}
|
||||||
|
>
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="13"
|
||||||
|
height="13"
|
||||||
|
fill="currentColor"
|
||||||
|
className="bi bi-info-circle"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
>
|
||||||
|
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
|
||||||
|
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.547 1.11l1.91-2.011c.241-.256.384-.592.287-.984-.172-.439-.58-.827-1.13-.967a.664.664 0 0 1-.58-.309l-.15-.241-.002-.002zM8 4c-.535 0-.943.372-.943.836 0 .464.408.836.943.836.535 0 .943-.372.943-.836 0-.464-.408-.836-.943-.836z" />
|
||||||
|
</svg>
|
||||||
|
</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">
|
||||||
|
|||||||
@ -7,14 +7,7 @@ import { useFeatures } from "../../hooks/useMasterRole";
|
|||||||
import { MasterRespository } from "../../repositories/MastersRepository";
|
import { MasterRespository } from "../../repositories/MastersRepository";
|
||||||
import { cacheData, getCachedData } from "../../slices/apiDataManager";
|
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" }),
|
||||||
@ -25,147 +18,145 @@ const updateSchema = z.object({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const EditMaster = ({ master, onClose }) => {
|
const EditMaster = ({ master, onClose }) => {
|
||||||
const maxDescriptionLength = 255;
|
const maxDescriptionLength = 255;
|
||||||
const popoverRefs = useRef([]);
|
const popoverRefs = useRef([]);
|
||||||
const { masterFeatures } = useFeatures();
|
const { masterFeatures } = useFeatures();
|
||||||
const { mutate: updateApplicationRole, isPending: isLoading } = useUpdateApplicationRole(() => onClose?.());
|
const { mutate: updateApplicationRole, isPending: isLoading } = useUpdateApplicationRole(() => onClose?.());
|
||||||
|
|
||||||
const buildDefaultPermissions = () => {
|
const buildDefaultPermissions = () => {
|
||||||
const defaults = {};
|
const defaults = {};
|
||||||
masterFeatures.forEach((feature) => {
|
masterFeatures.forEach((feature) => {
|
||||||
feature.featurePermissions.forEach((perm) => {
|
feature.featurePermissions.forEach((perm) => {
|
||||||
const existing = master?.item?.featurePermission?.find(p => p.id === perm.id);
|
const existing = master?.item?.featurePermission?.find(p => p.id === perm.id);
|
||||||
defaults[perm.id] = existing?.isEnabled || false;
|
defaults[perm.id] = existing?.isEnabled || false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
return defaults;
|
||||||
return defaults;
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialPermissions = buildDefaultPermissions();
|
|
||||||
|
|
||||||
const {
|
|
||||||
register,
|
|
||||||
handleSubmit,
|
|
||||||
formState: { errors, dirtyFields },
|
|
||||||
setError,
|
|
||||||
reset,
|
|
||||||
} = useForm({
|
|
||||||
resolver: zodResolver(updateSchema),
|
|
||||||
defaultValues: {
|
|
||||||
role: master?.item?.role || "",
|
|
||||||
description: master?.item?.description || "",
|
|
||||||
permissions: initialPermissions,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const [descriptionLength, setDescriptionLength] = useState(master?.item?.description?.length || 0);
|
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
|
||||||
const existingIds = new Set(master?.item?.featurePermission?.map(p => p.id));
|
|
||||||
|
|
||||||
const updatedPermissions = Object.entries(data.permissions)
|
|
||||||
.filter(([id, value]) => {
|
|
||||||
return existingIds.has(id) || value === true || (dirtyFields.permissions?.[id]);
|
|
||||||
})
|
|
||||||
.map(([id, value]) => ({ id, isEnabled: value }));
|
|
||||||
|
|
||||||
if (updatedPermissions.length === 0) {
|
|
||||||
setError("permissions", {
|
|
||||||
type: "manual",
|
|
||||||
message: "At least one permission must be selected.",
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const payload = {
|
|
||||||
id: master?.item?.id,
|
|
||||||
role: data.role,
|
|
||||||
description: data.description,
|
|
||||||
featuresPermission: updatedPermissions,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updateApplicationRole({ id: payload.id, payload });
|
const initialPermissions = buildDefaultPermissions();
|
||||||
};
|
|
||||||
// const onSubmit = (data) => {
|
|
||||||
// setIsLoading(true)
|
|
||||||
// const existingIds = new Set(
|
|
||||||
// master?.item?.featurePermission?.map((p) => p.id)
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
const {
|
||||||
// const updatedPermissions = Object.entries(data.permissions)
|
register,
|
||||||
// .filter(([id, value]) => {
|
handleSubmit,
|
||||||
// if (existingIds.has(id)) return true;
|
formState: { errors, dirtyFields },
|
||||||
|
setError,
|
||||||
// return (
|
reset,
|
||||||
// value === true ||
|
} = useForm({
|
||||||
// (dirtyFields.permissions && dirtyFields.permissions[id])
|
resolver: zodResolver(updateSchema),
|
||||||
// );
|
defaultValues: {
|
||||||
// })
|
role: master?.item?.role || "",
|
||||||
// .map(([id, value]) => ({ id, isEnabled: value }));
|
description: master?.item?.description || "",
|
||||||
|
permissions: initialPermissions,
|
||||||
|
},
|
||||||
// if (updatedPermissions.length === 0) {
|
|
||||||
// setError("permissions", {
|
|
||||||
// type: "manual",
|
|
||||||
// message: "At least one permission must be selected.",
|
|
||||||
// });
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const updatedRole = {
|
|
||||||
// id: master?.item?.id,
|
|
||||||
// role: data.role,
|
|
||||||
// description: data.description,
|
|
||||||
// featuresPermission: updatedPermissions,
|
|
||||||
// };
|
|
||||||
// MasterRespository.updateRoles(master?.item?.id, updatedRole).then((resp) => {
|
|
||||||
// setIsLoading(false)
|
|
||||||
|
|
||||||
|
|
||||||
// const cachedData = getCachedData("Application Role");
|
|
||||||
|
|
||||||
// if (cachedData) {
|
|
||||||
|
|
||||||
// const updatedData = cachedData.map((role) =>
|
|
||||||
// role.id === resp.data?.id ? { ...role, ...resp.data } : role
|
|
||||||
// );
|
|
||||||
|
|
||||||
// cacheData("Application Role", updatedData);
|
|
||||||
// }
|
|
||||||
// showToast("Application Role Updated successfully.", "success");
|
|
||||||
// setIsLoading(false)
|
|
||||||
// onClose()
|
|
||||||
// }).catch((Err) => {
|
|
||||||
// showToast(Err.message, "error");
|
|
||||||
// setIsLoading(false)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// };
|
|
||||||
useEffect(() => {
|
|
||||||
reset({
|
|
||||||
role: master?.item?.role || "",
|
|
||||||
description: master?.item?.description || "",
|
|
||||||
permissions: buildDefaultPermissions(),
|
|
||||||
});
|
});
|
||||||
setDescriptionLength(master?.item?.description?.length || 0);
|
|
||||||
}, [master, reset]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const [descriptionLength, setDescriptionLength] = useState(master?.item?.description?.length || 0);
|
||||||
popoverRefs.current.forEach((el) => {
|
|
||||||
if (el) {
|
const onSubmit = (data) => {
|
||||||
new bootstrap.Popover(el, {
|
const existingIds = new Set(master?.item?.featurePermission?.map(p => p.id));
|
||||||
trigger: "focus",
|
|
||||||
placement: "right",
|
const updatedPermissions = Object.entries(data.permissions)
|
||||||
html: true,
|
.filter(([id, value]) => {
|
||||||
content: el.getAttribute("data-bs-content"),
|
return existingIds.has(id) || value === true || (dirtyFields.permissions?.[id]);
|
||||||
|
})
|
||||||
|
.map(([id, value]) => ({ id, isEnabled: value }));
|
||||||
|
|
||||||
|
if (updatedPermissions.length === 0) {
|
||||||
|
setError("permissions", {
|
||||||
|
type: "manual",
|
||||||
|
message: "At least one permission must be selected.",
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}, [masterFeatures]);
|
const payload = {
|
||||||
|
id: master?.item?.id,
|
||||||
|
role: data.role,
|
||||||
|
description: data.description,
|
||||||
|
featuresPermission: updatedPermissions,
|
||||||
|
};
|
||||||
|
|
||||||
|
updateApplicationRole({ id: payload.id, payload });
|
||||||
|
};
|
||||||
|
// const onSubmit = (data) => {
|
||||||
|
// setIsLoading(true)
|
||||||
|
// const existingIds = new Set(
|
||||||
|
// master?.item?.featurePermission?.map((p) => p.id)
|
||||||
|
// );
|
||||||
|
|
||||||
|
|
||||||
|
// const updatedPermissions = Object.entries(data.permissions)
|
||||||
|
// .filter(([id, value]) => {
|
||||||
|
// if (existingIds.has(id)) return true;
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// value === true ||
|
||||||
|
// (dirtyFields.permissions && dirtyFields.permissions[id])
|
||||||
|
// );
|
||||||
|
// })
|
||||||
|
// .map(([id, value]) => ({ id, isEnabled: value }));
|
||||||
|
|
||||||
|
|
||||||
|
// if (updatedPermissions.length === 0) {
|
||||||
|
// setError("permissions", {
|
||||||
|
// type: "manual",
|
||||||
|
// message: "At least one permission must be selected.",
|
||||||
|
// });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const updatedRole = {
|
||||||
|
// id: master?.item?.id,
|
||||||
|
// role: data.role,
|
||||||
|
// description: data.description,
|
||||||
|
// featuresPermission: updatedPermissions,
|
||||||
|
// };
|
||||||
|
// MasterRespository.updateRoles(master?.item?.id, updatedRole).then((resp) => {
|
||||||
|
// setIsLoading(false)
|
||||||
|
|
||||||
|
|
||||||
|
// const cachedData = getCachedData("Application Role");
|
||||||
|
|
||||||
|
// if (cachedData) {
|
||||||
|
|
||||||
|
// const updatedData = cachedData.map((role) =>
|
||||||
|
// role.id === resp.data?.id ? { ...role, ...resp.data } : role
|
||||||
|
// );
|
||||||
|
|
||||||
|
// cacheData("Application Role", updatedData);
|
||||||
|
// }
|
||||||
|
// showToast("Application Role Updated successfully.", "success");
|
||||||
|
// setIsLoading(false)
|
||||||
|
// onClose()
|
||||||
|
// }).catch((Err) => {
|
||||||
|
// showToast(Err.message, "error");
|
||||||
|
// setIsLoading(false)
|
||||||
|
// })
|
||||||
|
|
||||||
|
// };
|
||||||
|
useEffect(() => {
|
||||||
|
reset({
|
||||||
|
role: master?.item?.role || "",
|
||||||
|
description: master?.item?.description || "",
|
||||||
|
permissions: buildDefaultPermissions(),
|
||||||
|
});
|
||||||
|
setDescriptionLength(master?.item?.description?.length || 0);
|
||||||
|
}, [master, reset]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
popoverRefs.current.forEach((el) => {
|
||||||
|
if (el) {
|
||||||
|
new bootstrap.Popover(el, {
|
||||||
|
trigger: "focus",
|
||||||
|
placement: "right",
|
||||||
|
html: true,
|
||||||
|
content: el.getAttribute("data-bs-content"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [masterFeatures]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -199,76 +190,90 @@ useEffect(() => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-12 col-md-12 mx-2s" >
|
<div className="col-12 text-start">
|
||||||
|
{/* 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>
|
||||||
|
|
||||||
{masterFeatures.map((feature, featureIndex) => (
|
{/* Permissions Grid */}
|
||||||
<div className="row my-1" key={feature.id} style={{ marginLeft: "0px" }}>
|
<div className="row">
|
||||||
|
{feature.featurePermissions.map((perm, permIndex) => {
|
||||||
|
const refIndex = featureIndex * 10 + permIndex;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={perm.id}
|
||||||
|
className="col-12 col-sm-6 col-md-4 mb-3 d-flex align-items-start"
|
||||||
|
>
|
||||||
|
<label
|
||||||
|
className="form-check-label d-flex align-items-center"
|
||||||
|
htmlFor={perm.id}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="form-check-input me-2"
|
||||||
|
id={perm.id}
|
||||||
|
{...register(`permissions.${perm.id}`, {
|
||||||
|
value: initialPermissions[perm.id] || false,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
{perm.name}
|
||||||
|
</label>
|
||||||
|
|
||||||
<div className="col-12 col-md-3 d-flex text-start align-items-center" style={{ wordWrap: 'break-word' }}>
|
{/* Info Icon */}
|
||||||
<span className="fs">{feature.name}</span>
|
<div style={{ display: "flex", alignItems: "center" }}>
|
||||||
</div>
|
<div
|
||||||
<div className="col-12 col-md-1">
|
ref={(el) => (popoverRefs.current[refIndex] = el)}
|
||||||
|
tabIndex="0"
|
||||||
</div>
|
className="d-flex align-items-center justify-content-center"
|
||||||
<div className="col-12 col-md-8 d-flex justify-content-start align-items-center flex-wrap ">
|
data-bs-toggle="popover"
|
||||||
{feature.featurePermissions.map((perm, permIndex) => {
|
data-bs-trigger="focus"
|
||||||
const refIndex = (featureIndex * 10) + permIndex;
|
data-bs-placement="right"
|
||||||
return (
|
data-bs-html="true"
|
||||||
|
data-bs-content={`<div class="border border-secondary rounded custom-popover p-2 px-3">${perm.description}</div>`}
|
||||||
<div className="d-flex me-3 mb-2" key={perm.id}>
|
>
|
||||||
|
|
||||||
<label className="form-check-label" htmlFor={perm.id}>
|
<svg
|
||||||
<input
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
type="checkbox"
|
width="13"
|
||||||
className="form-check-input mx-2"
|
height="13"
|
||||||
id={perm.id}
|
fill="currentColor"
|
||||||
{...register(`permissions.${perm.id}`, {
|
className="bi bi-info-circle"
|
||||||
value: initialPermissions[perm.id] || false
|
viewBox="0 0 16 16"
|
||||||
})}
|
>
|
||||||
/>
|
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
|
||||||
|
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.547 1.11l1.91-2.011c.241-.256.384-.592.287-.984-.172-.439-.58-.827-1.13-.967a.664.664 0 0 1-.58-.309l-.15-.241-.002-.002zM8 4c-.535 0-.943.372-.943.836 0 .464.408.836.943.836.535 0 .943-.372.943-.836 0-.464-.408-.836-.943-.836z" />
|
||||||
{perm.name}
|
</svg>
|
||||||
</label>
|
|
||||||
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
|
||||||
<div
|
|
||||||
key={refIndex}
|
|
||||||
ref={(el) =>
|
|
||||||
(popoverRefs.current[refIndex] = el)
|
|
||||||
}
|
|
||||||
tabIndex="0"
|
|
||||||
className="d-flex align-items-center avatar-group justify-content-center"
|
|
||||||
data-bs-toggle="popover" refIndex
|
|
||||||
data-bs-trigger="focus"
|
|
||||||
data-bs-placement="right"
|
|
||||||
data-bs-html="true"
|
|
||||||
data-bs-content={`
|
|
||||||
<div class="border border-secondary rounded custom-popover p-2 px-3">
|
|
||||||
${perm.description}
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
>
|
|
||||||
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" fill="currentColor" className="bi bi-info-circle" viewBox="0 0 16 16">
|
|
||||||
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
|
|
||||||
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.547 1.11l1.91-2.011c.241-.256.384-.592.287-.984-.172-.439-.58-.827-1.13-.967a.664.664 0 0 1-.58-.309l-.15-.241-.002-.002zM8 4c-.535 0-.943.372-.943.836 0 .464.408.836.943.836.535 0 .943-.372.943-.836 0-.464-.408-.836-.943-.836z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
</div>
|
||||||
})}
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr className="my-2" />
|
||||||
</div>
|
|
||||||
<hr className="hr my-1 py-1" />
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
{errors.permissions && (
|
|
||||||
<p className="text-danger">{errors.permissions.message}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Error Display */}
|
||||||
|
{errors.permissions && (
|
||||||
|
<p className="text-danger">{errors.permissions.message}</p>
|
||||||
|
)}
|
||||||
|
</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>
|
||||||
|
|||||||
165
src/components/master/ManageExpenseStatus.jsx
Normal file
165
src/components/master/ManageExpenseStatus.jsx
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
import React, { useEffect } from "react";
|
||||||
|
import {
|
||||||
|
useForm,
|
||||||
|
FormProvider,
|
||||||
|
} from "react-hook-form";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import SelectMultiple from "../common/SelectMultiple";
|
||||||
|
import { useFeatures } from "../../hooks/useMasterRole";
|
||||||
|
import { EXPENSE_MANAGEMENT } from "../../utils/constants";
|
||||||
|
import { useCreateExpenseStatus, useUpdateExpenseStatus } from "../../hooks/masterHook/useMaster";
|
||||||
|
import { displayName } from "react-quill";
|
||||||
|
import { AppColorconfig } from "../../utils/appUtils";
|
||||||
|
|
||||||
|
const ExpenseStatusSchema = z.object({
|
||||||
|
name: z.string().min(1, { message: "Name is required" }),
|
||||||
|
displayName: z.string().min(1, { message: "Display Name is required" }),
|
||||||
|
description: z.string().min(1, { message: "Description is required" }),
|
||||||
|
permissionIds: z.array(z.string()).min(1, {
|
||||||
|
message: "At least one permission is required",
|
||||||
|
}),
|
||||||
|
color: z
|
||||||
|
.string()
|
||||||
|
.regex(/^#([0-9A-F]{3}){1,2}$/i, { message: "Invalid hex color" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const ManageExpenseStatus = ({data, onClose }) => {
|
||||||
|
const methods = useForm({
|
||||||
|
resolver: zodResolver(ExpenseStatusSchema),
|
||||||
|
defaultValues: {
|
||||||
|
name: "",
|
||||||
|
displayName: "",
|
||||||
|
description: "",
|
||||||
|
permissionIds: [],
|
||||||
|
color: AppColorconfig.colors.primary,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
formState: { errors },
|
||||||
|
} = methods;
|
||||||
|
|
||||||
|
const { masterFeatures, loading } = useFeatures();
|
||||||
|
|
||||||
|
const ExpenseFeature = masterFeatures?.find(
|
||||||
|
(appfeature) => appfeature.id === EXPENSE_MANAGEMENT
|
||||||
|
);
|
||||||
|
const {mutate:CreateExpenseStatus,isPending:isPending} = useCreateExpenseStatus(()=>onClose?.())
|
||||||
|
const {mutate:UpdateExpenseStatus,isPending:Updating} = useUpdateExpenseStatus(()=>onClose?.());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const onSubmit = (payload) => {
|
||||||
|
if(data){
|
||||||
|
UpdateExpenseStatus({id:data.id,payload:{...payload,id:data.id}})
|
||||||
|
}else{
|
||||||
|
CreateExpenseStatus(payload)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
if(data){
|
||||||
|
reset({
|
||||||
|
name:data.name ?? "",
|
||||||
|
displayName:data.displayName ?? "",
|
||||||
|
description:data.description ?? "",
|
||||||
|
permissionIds:data.permissionIds ?? [],
|
||||||
|
color:data.color ?? AppColorconfig.colors.primary
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},[data])
|
||||||
|
return (
|
||||||
|
<FormProvider {...methods}>
|
||||||
|
{loading ? (
|
||||||
|
<div>Loading...</div>
|
||||||
|
) : (
|
||||||
|
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<div className="col-12">
|
||||||
|
<label className="form-label">Expense Status Name</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
{...register("name")}
|
||||||
|
className={`form-control ${errors.name ? "is-invalid" : ""}`}
|
||||||
|
/>
|
||||||
|
{errors.name && <p className="text-danger">{errors.name.message}</p>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-12">
|
||||||
|
<label className="form-label">Status Display Name</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
{...register("displayName")}
|
||||||
|
className={`form-control ${errors.displayName ? "is-invalid" : ""}`}
|
||||||
|
/>
|
||||||
|
{errors.displayName && (
|
||||||
|
<p className="text-danger">{errors.displayName.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-12">
|
||||||
|
<SelectMultiple
|
||||||
|
name="permissionIds"
|
||||||
|
label="Select Permissions"
|
||||||
|
options={ExpenseFeature?.featurePermissions || []}
|
||||||
|
labelKey="name"
|
||||||
|
valueKey="id"
|
||||||
|
IsLoading={loading}
|
||||||
|
/>
|
||||||
|
{errors.permissionIds && (
|
||||||
|
<p className="text-danger">{errors.permissionIds.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-12">
|
||||||
|
<label className="form-label">Select Color</label>
|
||||||
|
<input
|
||||||
|
type="color"
|
||||||
|
className={`form-control form-control ${errors.color ? "is-invalid" : ""}`}
|
||||||
|
{...register("color")}
|
||||||
|
/>
|
||||||
|
{errors.color && (
|
||||||
|
<p className="text-danger">{errors.color.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-12">
|
||||||
|
<label className="form-label">Description</label>
|
||||||
|
<textarea
|
||||||
|
rows="3"
|
||||||
|
{...register("description")}
|
||||||
|
className={`form-control ${errors.description ? "is-invalid" : ""}`}
|
||||||
|
/>
|
||||||
|
{errors.description && (
|
||||||
|
<p className="text-danger">{errors.description.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-12 text-center">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-sm btn-primary me-3"
|
||||||
|
disabled={isPending || Updating}
|
||||||
|
>
|
||||||
|
{isPending || Updating ? "Please Wait..." : Updating ? "Update" : "Submit"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-sm btn-secondary"
|
||||||
|
onClick={onClose}
|
||||||
|
disabled={isPending || Updating}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
|
</FormProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ManageExpenseStatus;
|
||||||
113
src/components/master/ManageExpenseType.jsx
Normal file
113
src/components/master/ManageExpenseType.jsx
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
import React, { useEffect } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import {
|
||||||
|
useCreateExpenseType,
|
||||||
|
useUpdateExpenseType,
|
||||||
|
} from "../../hooks/masterHook/useMaster";
|
||||||
|
|
||||||
|
const ExpnseSchema = z.object({
|
||||||
|
name: z.string().min(1, { message: "Name is required" }),
|
||||||
|
noOfPersonsRequired: z.boolean().default(false),
|
||||||
|
description: z.string().min(1, { message: "Description is required" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const ManageExpenseType = ({ data = null, onClose }) => {
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm({
|
||||||
|
resolver: zodResolver(ExpnseSchema),
|
||||||
|
defaultValues: { name: "", noOfPersonsRequired: false, description: "" },
|
||||||
|
});
|
||||||
|
const { mutate: UpdateExpenseType, isPending:isPendingUpdate } = useUpdateExpenseType(
|
||||||
|
() => onClose?.()
|
||||||
|
);
|
||||||
|
const { mutate: CreateExpenseType, isPending } = useCreateExpenseType(() =>
|
||||||
|
onClose?.()
|
||||||
|
);
|
||||||
|
|
||||||
|
const onSubmit = (payload) => {
|
||||||
|
if (data) {
|
||||||
|
UpdateExpenseType({
|
||||||
|
id: data.id,
|
||||||
|
payload: { ...payload, id: data.id },
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
CreateExpenseType(payload);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
reset({
|
||||||
|
name: data.name ?? "",
|
||||||
|
noOfPersonsRequired: data.noOfPersonsRequired ?? false,
|
||||||
|
description: data.description ?? "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [data]);
|
||||||
|
return (
|
||||||
|
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<div className="col-12 col-md-12">
|
||||||
|
<label className="form-label">Expesne Type Name</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
{...register("name")}
|
||||||
|
className={`form-control ${errors.name ? "is-invalids" : ""}`}
|
||||||
|
/>
|
||||||
|
{errors.name && <p className="danger-text">{errors.name.message}</p>}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-12">
|
||||||
|
<label className="form-label" htmlFor="description">
|
||||||
|
Description
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
rows="3"
|
||||||
|
{...register("description")}
|
||||||
|
className={`form-control ${errors.description ? "is-invalids" : ""}`}
|
||||||
|
></textarea>
|
||||||
|
|
||||||
|
{errors.description && (
|
||||||
|
<p className="danger-text">{errors.description.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-12 d-flex align-items-center">
|
||||||
|
<label className="from-label">No. of Persons Required </label>{" "}
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="form-check-input ms-2"
|
||||||
|
{...register("noOfPersonsRequired")}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-12 text-center">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-sm btn-primary me-3"
|
||||||
|
disabled={isPending || isPendingUpdate}
|
||||||
|
>
|
||||||
|
{isPending || isPendingUpdate
|
||||||
|
? "Please Wait..."
|
||||||
|
: data
|
||||||
|
? "Update"
|
||||||
|
: "Submit"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="reset"
|
||||||
|
className="btn btn-sm btn-label-secondary "
|
||||||
|
data-bs-dismiss="modal"
|
||||||
|
aria-label="Close"
|
||||||
|
disabled={isPending || isPendingUpdate}
|
||||||
|
onClick={()=>onClose()}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ManageExpenseType;
|
||||||
95
src/components/master/ManagePaymentMode.jsx
Normal file
95
src/components/master/ManagePaymentMode.jsx
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
import React, { useEffect } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useCreatePaymentMode, useUpdatePaymentMode } from "../../hooks/masterHook/useMaster";
|
||||||
|
|
||||||
|
const ExpnseSchema = z.object({
|
||||||
|
name: z.string().min(1, { message: "Name is required" }),
|
||||||
|
description: z.string().min(1, { message: "Description is required" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const ManagePaymentMode = ({ data = null, onClose }) => {
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm({
|
||||||
|
resolver: zodResolver(ExpnseSchema),
|
||||||
|
defaultValues: { name: "", description: "" },
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutate: CreatePaymentMode, isPending } = useCreatePaymentMode(() =>
|
||||||
|
onClose?.()
|
||||||
|
);
|
||||||
|
const {mutate:UpdatePaymentMode,isPending:Updating} = useUpdatePaymentMode(()=>onClose?.())
|
||||||
|
|
||||||
|
const onSubmit = (payload) => {
|
||||||
|
if(data){
|
||||||
|
UpdatePaymentMode({id:data.id,payload:{...payload,id:data.id}})
|
||||||
|
}else(
|
||||||
|
CreatePaymentMode(payload)
|
||||||
|
)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
if(data){
|
||||||
|
reset({
|
||||||
|
name:data.name ?? "",
|
||||||
|
description:data.description ?? ""
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},[data])
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<div className="col-12 col-md-12">
|
||||||
|
<label className="form-label">Payment Mode Name</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
{...register("name")}
|
||||||
|
className={`form-control ${errors.name ? "is-invalids" : ""}`}
|
||||||
|
/>
|
||||||
|
{errors.name && <p className="danger-text">{errors.name.message}</p>}
|
||||||
|
</div>
|
||||||
|
<div className="col-12 col-md-12">
|
||||||
|
<label className="form-label" htmlFor="description">
|
||||||
|
Description
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
rows="3"
|
||||||
|
{...register("description")}
|
||||||
|
className={`form-control ${errors.description ? "is-invalids" : ""}`}
|
||||||
|
></textarea>
|
||||||
|
|
||||||
|
{errors.description && (
|
||||||
|
<p className="danger-text">{errors.description.message}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-12 text-center">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-sm btn-primary me-3"
|
||||||
|
disabled={isPending || Updating}
|
||||||
|
>
|
||||||
|
{isPending || Updating? "Please Wait..." : Updating ? "Update" : "Submit"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="reset"
|
||||||
|
className="btn btn-sm btn-label-secondary "
|
||||||
|
data-bs-dismiss="modal"
|
||||||
|
aria-label="Close"
|
||||||
|
disabled={isPending || Updating}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ManagePaymentMode;
|
||||||
@ -1,5 +1,4 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
|
|
||||||
import CreateRole from "./CreateRole";
|
import CreateRole from "./CreateRole";
|
||||||
import DeleteMaster from "./DeleteMaster";
|
import DeleteMaster from "./DeleteMaster";
|
||||||
import EditRole from "./EditRole";
|
import EditRole from "./EditRole";
|
||||||
@ -18,67 +17,45 @@ import CreateContactTag from "./CreateContactTag";
|
|||||||
import EditContactCategory from "./EditContactCategory";
|
import EditContactCategory from "./EditContactCategory";
|
||||||
import EditContactTag from "./EditContactTag";
|
import EditContactTag from "./EditContactTag";
|
||||||
import { useDeleteMasterItem } from "../../hooks/masterHook/useMaster";
|
import { useDeleteMasterItem } from "../../hooks/masterHook/useMaster";
|
||||||
|
import ManageExpenseType from "./ManageExpenseType";
|
||||||
|
import ManagePaymentMode from "./ManagePaymentMode";
|
||||||
|
import ManageExpenseStatus from "./ManageExpenseStatus";
|
||||||
|
|
||||||
|
|
||||||
const MasterModal = ({ modaldata, closeModal }) => {
|
const MasterModal = ({ modaldata, closeModal }) => {
|
||||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
const { mutate: deleteMasterItem, isPending } = useDeleteMasterItem();
|
const { mutate: deleteMasterItem, isPending } = useDeleteMasterItem();
|
||||||
|
|
||||||
// const handleSelectedMasterDeleted = async () =>
|
|
||||||
// {
|
|
||||||
// debugger
|
|
||||||
// const deleteFn = MasterRespository[modaldata.masterType];
|
|
||||||
// if (!deleteFn) {
|
|
||||||
// showToast(`No delete strategy defined for master type`,"error");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// const response = await deleteFn( modaldata?.item?.id );
|
|
||||||
// const selected_cachedData = getCachedData( modaldata?.masterType );
|
|
||||||
// const updated_master = selected_cachedData?.filter(item => item.id !== modaldata?.item.id);
|
|
||||||
// cacheData( modaldata?.masterType, updated_master )
|
|
||||||
|
|
||||||
// showToast(`${modaldata?.masterType} is deleted successfully`, "success");
|
|
||||||
// handleCloseDeleteModal()
|
|
||||||
|
|
||||||
// } catch ( error )
|
|
||||||
// {
|
|
||||||
// const message = error.response.data.message || error.message || "Error occured api during call"
|
|
||||||
// showToast(message, "success");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
const handleSelectedMasterDeleted = () => {
|
const handleSelectedMasterDeleted = () => {
|
||||||
if (!modaldata?.masterType || !modaldata?.item?.id) {
|
const { masterType, item, validateFn } = modaldata || {};
|
||||||
|
if (!masterType || !item?.id) {
|
||||||
showToast("Missing master type or item", "error");
|
showToast("Missing master type or item", "error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteMasterItem(
|
deleteMasterItem(
|
||||||
{
|
{ masterType, item, validateFn },
|
||||||
masterType: modaldata.masterType,
|
{ onSuccess: handleCloseDeleteModal }
|
||||||
item: modaldata.item,
|
|
||||||
validateFn: modaldata.validateFn, // optional
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onSuccess: () => {
|
|
||||||
handleCloseDeleteModal();
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCloseDeleteModal = () => {
|
||||||
|
setIsDeleteModalOpen(false);
|
||||||
|
closeModal();
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (modaldata?.modalType === "delete") {
|
if (modaldata?.modalType === "delete") {
|
||||||
setIsDeleteModalOpen(true);
|
setIsDeleteModalOpen(true);
|
||||||
}
|
}
|
||||||
}, [modaldata]);
|
}, [modaldata]);
|
||||||
|
|
||||||
const handleCloseDeleteModal = () => {
|
if (!modaldata?.modalType) {
|
||||||
setIsDeleteModalOpen(false);
|
|
||||||
closeModal();
|
closeModal();
|
||||||
};
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (modaldata?.modalType === "delete" && isDeleteModalOpen) {
|
if (modaldata.modalType === "delete" && isDeleteModalOpen) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="modal fade show"
|
className="modal fade show"
|
||||||
@ -90,86 +67,69 @@ const MasterModal = ({ modaldata, closeModal }) => {
|
|||||||
<ConfirmModal
|
<ConfirmModal
|
||||||
type="delete"
|
type="delete"
|
||||||
header={`Delete ${modaldata.masterType}`}
|
header={`Delete ${modaldata.masterType}`}
|
||||||
message={"Are you sure you want delete?"}
|
message="Are you sure you want delete?"
|
||||||
onSubmit={handleSelectedMasterDeleted}
|
onSubmit={handleSelectedMasterDeleted}
|
||||||
onClose={handleCloseDeleteModal}
|
onClose={handleCloseDeleteModal}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const renderModalContent = () => {
|
||||||
|
const { modalType, item, masterType } = modaldata;
|
||||||
|
|
||||||
|
const modalComponents = {
|
||||||
|
"Application Role": <CreateRole masmodalType={masterType} onClose={closeModal} />,
|
||||||
|
"Edit-Application Role": <EditRole master={modaldata} onClose={closeModal} />,
|
||||||
|
"Job Role": <CreateJobRole onClose={closeModal} />,
|
||||||
|
"Edit-Job Role": <EditJobRole data={item} onClose={closeModal} />,
|
||||||
|
"Activity": <CreateActivity onClose={closeModal} />,
|
||||||
|
"Edit-Activity": <EditActivity activityData={item} onClose={closeModal} />,
|
||||||
|
"Work Category": <CreateWorkCategory onClose={closeModal} />,
|
||||||
|
"Edit-Work Category": <EditWorkCategory data={item} onClose={closeModal} />,
|
||||||
|
"Contact Category": <CreateCategory data={item} onClose={closeModal} />,
|
||||||
|
"Edit-Contact Category": <EditContactCategory data={item} onClose={closeModal} />,
|
||||||
|
"Contact Tag": <CreateContactTag data={item} onClose={closeModal} />,
|
||||||
|
"Edit-Contact Tag": <EditContactTag data={item} onClose={closeModal} />,
|
||||||
|
"Expense Type":<ManageExpenseType onClose={closeModal} />,
|
||||||
|
"Edit-Expense Type":<ManageExpenseType data={item} onClose={closeModal} />,
|
||||||
|
"Payment Mode":<ManagePaymentMode onClose={closeModal}/>,
|
||||||
|
"Edit-Payment Mode":<ManagePaymentMode data={item} onClose={closeModal}/>,
|
||||||
|
"Expense Status":<ManageExpenseStatus onClose={closeModal}/>,
|
||||||
|
"Edit-Expense Status":<ManageExpenseStatus data={item} onClose={closeModal}/>
|
||||||
|
};
|
||||||
|
|
||||||
|
return modalComponents[modalType] || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isLargeModal = ["Application Role", "Edit-Application Role"].includes(
|
||||||
|
modaldata.modalType
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="modal fade"
|
className="modal fade show"
|
||||||
id="master-modal"
|
id="master-modal"
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
aria-hidden="true"
|
|
||||||
role="dialog"
|
role="dialog"
|
||||||
|
aria-hidden="true"
|
||||||
aria-labelledby="modalToggleLabel"
|
aria-labelledby="modalToggleLabel"
|
||||||
|
style={{ display: "block" }}
|
||||||
>
|
>
|
||||||
<div
|
<div className={`modal-dialog mx-sm-auto mx-1 ${isLargeModal ? "modal-lg" : "modal-md"} modal-simple`}>
|
||||||
className={`modal-dialog mx-sm-auto mx-1 ${
|
|
||||||
["Application Role", "Edit-Application Role"].includes(
|
|
||||||
modaldata?.modalType
|
|
||||||
)
|
|
||||||
? "modal-lg"
|
|
||||||
: "modal-md"
|
|
||||||
} modal-simple`}
|
|
||||||
>
|
|
||||||
<div className="modal-content">
|
<div className="modal-content">
|
||||||
<div className="modal-body p-sm-4 p-0">
|
<div className="modal-body p-sm-4 p-0">
|
||||||
<div className="d-flex justify-content-between">
|
<div className="d-flex justify-content-between">
|
||||||
<h6>{`${modaldata?.modalType} `}</h6>
|
<h6>{modaldata?.modalType}</h6>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="btn-close"
|
className="btn-close"
|
||||||
data-bs-dismiss="modal"
|
data-bs-dismiss="modal"
|
||||||
aria-label="Close"
|
aria-label="Close"
|
||||||
onClick={closeModal}
|
onClick={closeModal}
|
||||||
></button>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{renderModalContent()}
|
||||||
{modaldata.modalType === "Application Role" && (
|
|
||||||
<CreateRole
|
|
||||||
masmodalType={modaldata.masterType}
|
|
||||||
onClose={closeModal}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Edit-Application Role" && (
|
|
||||||
<EditRole master={modaldata} onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Job Role" && (
|
|
||||||
<CreateJobRole onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Edit-Job Role" && (
|
|
||||||
<EditJobRole data={modaldata.item} onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Activity" && (
|
|
||||||
<CreateActivity onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Edit-Activity" && (
|
|
||||||
<EditActivity
|
|
||||||
activityData={modaldata.item}
|
|
||||||
onClose={closeModal}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Work Category" && (
|
|
||||||
<CreateWorkCategory onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Edit-Work Category" && (
|
|
||||||
<EditWorkCategory data={modaldata.item} onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Contact Category" && (
|
|
||||||
<CreateCategory data={modaldata.item} onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Edit-Contact Category" && (
|
|
||||||
<EditContactCategory data={modaldata.item} onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Contact Tag" && (
|
|
||||||
<CreateContactTag data={modaldata.item} onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
{modaldata.modalType === "Edit-Contact Tag" && (
|
|
||||||
<EditContactTag data={modaldata.item} onClose={closeModal} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,153 +1,157 @@
|
|||||||
// it important ------
|
// it important ------
|
||||||
export const mastersList = [ {id: 1, name: "Application Role"}, {id: 2, name: "Job Role"}, {id: 3, name: "Activity"},{id: 4, name:"Work Category"},{id:5,name:"Contact Category"},{id:6,name:"Contact Tag"}]
|
export const mastersList = [
|
||||||
|
{ id: 1, name: "Application Role" },
|
||||||
|
{ id: 2, name: "Job Role" },
|
||||||
|
{ id: 3, name: "Activity" },
|
||||||
|
{ id: 4, name: "Work Category" },
|
||||||
|
{ id: 5, name: "Contact Category" },
|
||||||
|
{ id: 6, name: "Contact Tag" },
|
||||||
|
{ id: 7, name: "Expense Type" },
|
||||||
|
{ id: 8, name: "Payment Mode" },
|
||||||
|
{ id: 9, name: "Expense Status" },
|
||||||
|
];
|
||||||
// -------------------
|
// -------------------
|
||||||
|
|
||||||
export const dailyTask = [
|
// export const dailyTask = [
|
||||||
{
|
// {
|
||||||
id:1,
|
// id:1,
|
||||||
project:{
|
// project:{
|
||||||
projectName:"Project Name1",
|
// projectName:"Project Name1",
|
||||||
building:"buildName1",
|
// building:"buildName1",
|
||||||
floor:"floorName1",
|
// floor:"floorName1",
|
||||||
workArea:"workarea1"
|
// workArea:"workarea1"
|
||||||
},
|
// },
|
||||||
target:80,
|
// target:80,
|
||||||
employees:[
|
// employees:[
|
||||||
{
|
// {
|
||||||
id:1,
|
// id:1,
|
||||||
name:"Vishal Patil",
|
// name:"Vishal Patil",
|
||||||
role:"helper"
|
// role:"helper"
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
id:202,
|
// id:202,
|
||||||
name:"Vishal Patil",
|
// name:"Vishal Patil",
|
||||||
role:"helper"
|
// role:"helper"
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
id:101,
|
// id:101,
|
||||||
name:"Kushal Patil",
|
// name:"Kushal Patil",
|
||||||
role:"Engineer"
|
// role:"Engineer"
|
||||||
}
|
// }
|
||||||
]
|
// ]
|
||||||
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:2,
|
|
||||||
project:{
|
|
||||||
projectName:"Project Name1",
|
|
||||||
building:"buildName1",
|
|
||||||
floor:"floorName1",
|
|
||||||
workArea:"workarea1"
|
|
||||||
},
|
|
||||||
target:90,
|
|
||||||
employees:[
|
|
||||||
{
|
|
||||||
id:1,
|
|
||||||
name:"Vishal Patil",
|
|
||||||
role:"welder"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:202,
|
|
||||||
name:"Vishal Patil",
|
|
||||||
role:"welder"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:101,
|
|
||||||
name:"Kushal Patil",
|
|
||||||
role:"Site Engineer"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const jobRoles =[
|
|
||||||
{
|
|
||||||
id:1,
|
|
||||||
name:"Project Manager"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:2,
|
|
||||||
name:"Software Developer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:3,
|
|
||||||
name:"Estimation Engineer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:4,
|
|
||||||
name:"Designer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:5,
|
|
||||||
name:"Site Engineer"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
export const employee =[
|
|
||||||
{
|
|
||||||
id:1,
|
|
||||||
FirtsName:"Pramod",
|
|
||||||
LastName:"Mahajan",
|
|
||||||
JobRoleId:2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:2,
|
|
||||||
FirtsName:"Akahsy",
|
|
||||||
LastName:"Patil",
|
|
||||||
JobRoleId:1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:3,
|
|
||||||
FirtsName:"janvi",
|
|
||||||
LastName:"Potdar",
|
|
||||||
JobRoleId:3,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:4,
|
|
||||||
FirtsName:"Aboli",
|
|
||||||
LastName:"Patil",
|
|
||||||
JobRoleId:2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:5,
|
|
||||||
FirtsName:"Shubham",
|
|
||||||
LastName:"Tamboli",
|
|
||||||
JobRoleId:1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:6,
|
|
||||||
FirtsName:"Alwin",
|
|
||||||
LastName:"Joy",
|
|
||||||
JobRoleId:4,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:7,
|
|
||||||
FirtsName:"John",
|
|
||||||
LastName:"kwel",
|
|
||||||
JobRoleId:4,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:8,
|
|
||||||
FirtsName:"Gita",
|
|
||||||
LastName:"shaha",
|
|
||||||
JobRoleId:1,
|
|
||||||
},{
|
|
||||||
id:9,
|
|
||||||
FirtsName:"Pratik",
|
|
||||||
LastName:"Joshi",
|
|
||||||
JobRoleId:5,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id:10,
|
|
||||||
FirtsName:"Nikil",
|
|
||||||
LastName:"Patil",
|
|
||||||
JobRoleId:5,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:2,
|
||||||
|
// project:{
|
||||||
|
// projectName:"Project Name1",
|
||||||
|
// building:"buildName1",
|
||||||
|
// floor:"floorName1",
|
||||||
|
// workArea:"workarea1"
|
||||||
|
// },
|
||||||
|
// target:90,
|
||||||
|
// employees:[
|
||||||
|
// {
|
||||||
|
// id:1,
|
||||||
|
// name:"Vishal Patil",
|
||||||
|
// role:"welder"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:202,
|
||||||
|
// name:"Vishal Patil",
|
||||||
|
// role:"welder"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:101,
|
||||||
|
// name:"Kushal Patil",
|
||||||
|
// role:"Site Engineer"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
|
||||||
|
// export const jobRoles =[
|
||||||
|
// {
|
||||||
|
// id:1,
|
||||||
|
// name:"Project Manager"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:2,
|
||||||
|
// name:"Software Developer"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:3,
|
||||||
|
// name:"Estimation Engineer"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:4,
|
||||||
|
// name:"Designer"
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:5,
|
||||||
|
// name:"Site Engineer"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
|
||||||
|
// export const employee =[
|
||||||
|
// {
|
||||||
|
// id:1,
|
||||||
|
// FirtsName:"Pramod",
|
||||||
|
// LastName:"Mahajan",
|
||||||
|
// JobRoleId:2,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:2,
|
||||||
|
// FirtsName:"Akahsy",
|
||||||
|
// LastName:"Patil",
|
||||||
|
// JobRoleId:1,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:3,
|
||||||
|
// FirtsName:"janvi",
|
||||||
|
// LastName:"Potdar",
|
||||||
|
// JobRoleId:3,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:4,
|
||||||
|
// FirtsName:"Aboli",
|
||||||
|
// LastName:"Patil",
|
||||||
|
// JobRoleId:2,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:5,
|
||||||
|
// FirtsName:"Shubham",
|
||||||
|
// LastName:"Tamboli",
|
||||||
|
// JobRoleId:1,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:6,
|
||||||
|
// FirtsName:"Alwin",
|
||||||
|
// LastName:"Joy",
|
||||||
|
// JobRoleId:4,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:7,
|
||||||
|
// FirtsName:"John",
|
||||||
|
// LastName:"kwel",
|
||||||
|
// JobRoleId:4,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:8,
|
||||||
|
// FirtsName:"Gita",
|
||||||
|
// LastName:"shaha",
|
||||||
|
// JobRoleId:1,
|
||||||
|
// },{
|
||||||
|
// id:9,
|
||||||
|
// FirtsName:"Pratik",
|
||||||
|
// LastName:"Joshi",
|
||||||
|
// JobRoleId:5,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id:10,
|
||||||
|
// FirtsName:"Nikil",
|
||||||
|
// LastName:"Patil",
|
||||||
|
// JobRoleId:5,
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
|||||||
@ -66,6 +66,12 @@
|
|||||||
"available": true,
|
"available": true,
|
||||||
"link": "/gallary"
|
"link": "/gallary"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"text": "Expense",
|
||||||
|
"icon": "bx bx-receipt",
|
||||||
|
"available": true,
|
||||||
|
"link": "/expenses"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"text": "Administration",
|
"text": "Administration",
|
||||||
"icon": "bx bx-box",
|
"icon": "bx bx-box",
|
||||||
|
|||||||
@ -12,213 +12,6 @@ import showToast from "../../services/toastService";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// const useMaster = () => {
|
|
||||||
|
|
||||||
// const selectedMaster = useSelector((store)=>store.localVariables.selectedMaster);
|
|
||||||
// const [data, setData] = useState([]);
|
|
||||||
// const [loading, setLoading] = useState(true);
|
|
||||||
// const [error, setError] = useState("");
|
|
||||||
// useEffect(() => {
|
|
||||||
// const fetchData = async () => {
|
|
||||||
// if (!selectedMaster) return;
|
|
||||||
// setLoading(true);
|
|
||||||
// try {
|
|
||||||
// const cachedData = getCachedData(selectedMaster);
|
|
||||||
// if (cachedData) {
|
|
||||||
|
|
||||||
// setData(cachedData);
|
|
||||||
|
|
||||||
// } else {
|
|
||||||
// let response;
|
|
||||||
// switch (selectedMaster) {
|
|
||||||
// case "Application Role":
|
|
||||||
// response = await MasterRespository.getRoles();
|
|
||||||
// response = response.data;
|
|
||||||
// break;
|
|
||||||
// case "Job Role":
|
|
||||||
// response = await MasterRespository.getJobRole();
|
|
||||||
// response = response.data
|
|
||||||
// break;
|
|
||||||
// case "Activity":
|
|
||||||
// response = await MasterRespository.getActivites();
|
|
||||||
// response = response.data
|
|
||||||
// break;
|
|
||||||
// case "Work Category":
|
|
||||||
// response = await MasterRespository.getWorkCategory();
|
|
||||||
// response = response.data
|
|
||||||
// break;
|
|
||||||
// case "Contact Category":
|
|
||||||
// response = await MasterRespository.getContactCategory();
|
|
||||||
// response = response.data
|
|
||||||
// break;
|
|
||||||
// case "Contact Tag":
|
|
||||||
// response = await MasterRespository.getContactTag();
|
|
||||||
// response = response.data
|
|
||||||
// break;
|
|
||||||
// case "Status":
|
|
||||||
// response = [{description: null,featurePermission: null,id: "02dd4761-363c-49ed-8851-3d2489a3e98d",status:"status 1"},{description: null,featurePermission: null,id: "03dy9761-363c-49ed-8851-3d2489a3e98d",status:"status 2"},{description: null,featurePermission: null,id: "03dy7761-263c-49ed-8851-3d2489a3e98d",status:"Status 3"}];
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// response = [];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (response) {
|
|
||||||
// setData(response);
|
|
||||||
// cacheData(selectedMaster, response);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } catch (err) {
|
|
||||||
// setError("Failed to fetch data.");
|
|
||||||
// } finally {
|
|
||||||
// setLoading(false);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// if ( selectedMaster )
|
|
||||||
// {
|
|
||||||
|
|
||||||
// fetchData();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }, [selectedMaster]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// return { data, loading, error }
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// export const useActivitiesMaster = () =>
|
|
||||||
// {
|
|
||||||
// const [ activities, setActivites ] = useState( [] )
|
|
||||||
// const [ loading, setloading ] = useState( false );
|
|
||||||
// const [ error, setError ] = useState()
|
|
||||||
// const fetchActivities =async () => {
|
|
||||||
// setloading(true);
|
|
||||||
// try {
|
|
||||||
// const response = await MasterRespository.getActivites();
|
|
||||||
// setActivites(response.data);
|
|
||||||
// cacheData( "ActivityMaster", response.data );
|
|
||||||
// setloading(false);
|
|
||||||
// } catch (err) {
|
|
||||||
// setError(err);
|
|
||||||
// setloading(false);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// useEffect( () =>
|
|
||||||
// {
|
|
||||||
// const cacheddata = getCachedData( "ActivityMaster" );
|
|
||||||
// if ( !cacheddata )
|
|
||||||
// {
|
|
||||||
// fetchActivities()
|
|
||||||
// } else
|
|
||||||
// {
|
|
||||||
// setActivites(cacheddata);
|
|
||||||
// }
|
|
||||||
// }, [] )
|
|
||||||
|
|
||||||
// return {activities,loading,error}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export const useWorkCategoriesMaster = () =>
|
|
||||||
// {
|
|
||||||
// const [ categories, setCategories ] = useState( [] )
|
|
||||||
// const [ categoryLoading, setloading ] = useState( false );
|
|
||||||
// const [ categoryError, setError ] = useState( "" )
|
|
||||||
|
|
||||||
// const fetchCategories =async () => {
|
|
||||||
// const cacheddata = getCachedData("Work Category");
|
|
||||||
|
|
||||||
// if (!cacheddata) {
|
|
||||||
// setloading(true);
|
|
||||||
// try {
|
|
||||||
// const response = await MasterRespository.getWorkCategory();
|
|
||||||
// setCategories(response.data);
|
|
||||||
// cacheData("Work Category", response.data);
|
|
||||||
// } catch (err) {
|
|
||||||
// setError(err);
|
|
||||||
// console.log(err);
|
|
||||||
// } finally {
|
|
||||||
// setloading(false);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// setCategories(cacheddata);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// useEffect( () =>
|
|
||||||
// {
|
|
||||||
// fetchCategories()
|
|
||||||
// }, [] )
|
|
||||||
|
|
||||||
// return {categories,categoryLoading,categoryError}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export const useContactCategory = () =>
|
|
||||||
// {
|
|
||||||
// const [ contactCategory, setContactCategory ] = useState( [] )
|
|
||||||
// const [ loading, setLoading ] = useState( false )
|
|
||||||
// const [ Error, setError ] = useState()
|
|
||||||
|
|
||||||
// const fetchConatctCategory = async() =>
|
|
||||||
// {
|
|
||||||
// const cache_Category = getCachedData( "Contact Category" );
|
|
||||||
// if ( !cache_Category )
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// let resp = await MasterRespository.getContactCategory();
|
|
||||||
// setContactCategory( resp.data );
|
|
||||||
// cacheData("Contact Category",resp.data)
|
|
||||||
// } catch ( error )
|
|
||||||
// {
|
|
||||||
// setError(error)
|
|
||||||
// }
|
|
||||||
// } else
|
|
||||||
// {
|
|
||||||
// setContactCategory(cache_Category)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// useEffect( () =>
|
|
||||||
// {
|
|
||||||
// fetchConatctCategory()
|
|
||||||
// }, [] )
|
|
||||||
// return { contactCategory,loading,Error}
|
|
||||||
// }
|
|
||||||
// export const useContactTags = () => {
|
|
||||||
// const [contactTags, setContactTags] = useState([]);
|
|
||||||
// const [loading, setLoading] = useState(false);
|
|
||||||
// const [error, setError] = useState(null);
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// const fetchContactTag = async () => {
|
|
||||||
// const cache_Tags = getCachedData("Contact Tag");
|
|
||||||
|
|
||||||
// if (!cache_Tags) {
|
|
||||||
// setLoading(true);
|
|
||||||
// try {
|
|
||||||
// const resp = await MasterRespository.getContactTag();
|
|
||||||
// setContactTags(resp.data);
|
|
||||||
// cacheData("Contact Tag", resp.data);
|
|
||||||
// } catch (err) {
|
|
||||||
// setError(err);
|
|
||||||
// } finally {
|
|
||||||
// setLoading(false);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// setContactTags(cache_Tags);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// fetchContactTag();
|
|
||||||
// }, []);
|
|
||||||
|
|
||||||
// return { contactTags, loading, error };
|
|
||||||
// };
|
|
||||||
|
|
||||||
// Separate matser-------------
|
|
||||||
|
|
||||||
export const useActivitiesMaster = () =>
|
export const useActivitiesMaster = () =>
|
||||||
{
|
{
|
||||||
@ -300,6 +93,76 @@ export const useContactTags = () => {
|
|||||||
return { contactTags, loading, error };
|
return { contactTags, loading, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const useExpenseType =()=>{
|
||||||
|
const {
|
||||||
|
data: ExpenseTypes = [],
|
||||||
|
isLoading: loading,
|
||||||
|
error,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["Expense Type"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await MasterRespository.getExpenseType()
|
||||||
|
return res.data;
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error?.response?.data?.message ||
|
||||||
|
error.message ||
|
||||||
|
"Failed to fetch Expense Type",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return { ExpenseTypes, loading, error };
|
||||||
|
}
|
||||||
|
export const usePaymentMode =()=>{
|
||||||
|
const {
|
||||||
|
data: PaymentModes = [],
|
||||||
|
isLoading: loading,
|
||||||
|
error,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["Payment Mode"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await MasterRespository.getPaymentMode()
|
||||||
|
return res.data;
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error?.response?.data?.message ||
|
||||||
|
error.message ||
|
||||||
|
"Failed to fetch Payment Mode",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return { PaymentModes, loading, error };
|
||||||
|
}
|
||||||
|
export const useExpenseStatus =()=>{
|
||||||
|
const {
|
||||||
|
data: ExpenseStatus = [],
|
||||||
|
isLoading: loading,
|
||||||
|
error,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["Expense Status"],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await MasterRespository.getExpenseStatus()
|
||||||
|
return res.data;
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error?.response?.data?.message ||
|
||||||
|
error.message ||
|
||||||
|
"Failed to fetch Expense Status",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return { ExpenseStatus, loading, error };
|
||||||
|
}
|
||||||
// ===Application Masters Query=================================================
|
// ===Application Masters Query=================================================
|
||||||
|
|
||||||
const fetchMasterData = async (masterType) => {
|
const fetchMasterData = async (masterType) => {
|
||||||
@ -316,6 +179,12 @@ const fetchMasterData = async (masterType) => {
|
|||||||
return (await MasterRespository.getContactCategory()).data;
|
return (await MasterRespository.getContactCategory()).data;
|
||||||
case "Contact Tag":
|
case "Contact Tag":
|
||||||
return (await MasterRespository.getContactTag()).data;
|
return (await MasterRespository.getContactTag()).data;
|
||||||
|
case "Expense Type":
|
||||||
|
return (await MasterRespository.getExpenseType()).data;
|
||||||
|
case "Payment Mode":
|
||||||
|
return (await MasterRespository.getPaymentMode()).data;
|
||||||
|
case "Expense Status":
|
||||||
|
return (await MasterRespository.getExpenseStatus()).data;
|
||||||
case "Status":
|
case "Status":
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@ -666,6 +535,140 @@ export const useUpdateContactTag = (onSuccessCallback) =>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------Expense Type------------------
|
||||||
|
export const useCreateExpenseType = (onSuccessCallback)=>{
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation( {
|
||||||
|
mutationFn: async ( payload ) =>
|
||||||
|
{
|
||||||
|
const resp = await MasterRespository.createExpenseType(payload);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
onSuccess: ( data ) =>
|
||||||
|
{
|
||||||
|
queryClient.invalidateQueries( {queryKey:[ "masterData", "Expense Type" ]} )
|
||||||
|
showToast( "Expense Type added successfully", "success" );
|
||||||
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
|
},
|
||||||
|
onError: ( error ) =>
|
||||||
|
{
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
export const useUpdateExpenseType = (onSuccessCallback) =>
|
||||||
|
{
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async ( {id, payload} ) =>
|
||||||
|
{
|
||||||
|
const response = await MasterRespository.updateExpenseType(id,payload);
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
onSuccess: (data, variables) => {
|
||||||
|
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["masterData", "Expense Type"],
|
||||||
|
});
|
||||||
|
showToast("Expense Type updated successfully.", "success");
|
||||||
|
|
||||||
|
if (onSuccessCallback) onSuccessCallback(data);
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------Payment Mode -------------
|
||||||
|
|
||||||
|
export const useCreatePaymentMode = (onSuccessCallback)=>{
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation( {
|
||||||
|
mutationFn: async ( payload ) =>
|
||||||
|
{
|
||||||
|
const resp = await MasterRespository.createPaymentMode(payload);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
onSuccess: ( data ) =>
|
||||||
|
{
|
||||||
|
queryClient.invalidateQueries( {queryKey:[ "masterData", "Payment Mode" ]} )
|
||||||
|
showToast( "Payment Mode added successfully", "success" );
|
||||||
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
|
},
|
||||||
|
onError: ( error ) =>
|
||||||
|
{
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
export const useUpdatePaymentMode = (onSuccessCallback)=>{
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation( {
|
||||||
|
mutationFn: async ( {id,payload} ) =>
|
||||||
|
{
|
||||||
|
const resp = await MasterRespository.updatePaymentMode(id,payload);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
onSuccess: ( data ) =>
|
||||||
|
{
|
||||||
|
queryClient.invalidateQueries( {queryKey:[ "masterData", "Payment Mode" ]} )
|
||||||
|
showToast( "Payment Mode Updated successfully", "success" );
|
||||||
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
|
},
|
||||||
|
onError: ( error ) =>
|
||||||
|
{
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// -------------------Expense Status----------------------------------
|
||||||
|
export const useCreateExpenseStatus =(onSuccessCallback)=>{
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation( {
|
||||||
|
mutationFn: async ( payload ) =>
|
||||||
|
{
|
||||||
|
const resp = await MasterRespository.createExpenseStatus(payload);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
onSuccess: ( data ) =>
|
||||||
|
{
|
||||||
|
queryClient.invalidateQueries( {queryKey:[ "masterData", "Expense Status" ]} )
|
||||||
|
showToast( "Expense Status added successfully", "success" );
|
||||||
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
|
},
|
||||||
|
onError: ( error ) =>
|
||||||
|
{
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
export const useUpdateExpenseStatus = (onSuccessCallback)=>{
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation( {
|
||||||
|
mutationFn: async ( {id,payload} ) =>
|
||||||
|
{
|
||||||
|
const resp = await MasterRespository.updateExepnseStatus(id,payload);
|
||||||
|
return resp.data;
|
||||||
|
},
|
||||||
|
onSuccess: ( data ) =>
|
||||||
|
{
|
||||||
|
queryClient.invalidateQueries( {queryKey:[ "masterData", "Expense Status" ]} )
|
||||||
|
showToast( "Expense Status Updated successfully", "success" );
|
||||||
|
if(onSuccessCallback) onSuccessCallback(data)
|
||||||
|
},
|
||||||
|
onError: ( error ) =>
|
||||||
|
{
|
||||||
|
showToast(error.message || "Something went wrong", "error");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
// -Delete Master --------
|
// -Delete Master --------
|
||||||
export const useDeleteMasterItem = () => {
|
export const useDeleteMasterItem = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|||||||
@ -104,17 +104,15 @@ 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); // ✅ Handle undefined/null
|
setTeamsData(response.data || {});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError("Failed to fetch teams card data.");
|
setError("Failed to fetch teams card data.");
|
||||||
console.error(err);
|
console.error("Error fetching teams card data:", err);
|
||||||
setTeamsData({});
|
setTeamsData({});
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@ -177,3 +177,36 @@ 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 };
|
||||||
|
};
|
||||||
|
|||||||
@ -3,27 +3,22 @@ import { cacheData, getCachedData } from "../slices/apiDataManager";
|
|||||||
import { RolesRepository } from "../repositories/MastersRepository";
|
import { RolesRepository } from "../repositories/MastersRepository";
|
||||||
import EmployeeRepository from "../repositories/EmployeeRepository";
|
import EmployeeRepository from "../repositories/EmployeeRepository";
|
||||||
import ProjectRepository from "../repositories/ProjectRepository";
|
import ProjectRepository from "../repositories/ProjectRepository";
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import showToast from "../services/toastService";
|
import showToast from "../services/toastService";
|
||||||
import {useSelector} from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import {store} from "../store/store";
|
import { store } from "../store/store";
|
||||||
import {queryClient} from "../layouts/AuthLayout";
|
import { queryClient } from "../layouts/AuthLayout";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Query ---------------------------------------------------------------------------
|
// Query ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export const useAllEmployees = (showInactive) => {
|
||||||
export const useAllEmployees = ( showInactive ) =>
|
|
||||||
{
|
|
||||||
const {
|
const {
|
||||||
data = [],
|
data = [],
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
refetch, // optional if you want recall functionality
|
refetch, // optional if you want recall functionality
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ['allEmployee', showInactive],
|
queryKey: ["allEmployee", showInactive],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await EmployeeRepository.getAllEmployeeList(showInactive);
|
const res = await EmployeeRepository.getAllEmployeeList(showInactive);
|
||||||
return res.data;
|
return res.data;
|
||||||
@ -39,9 +34,7 @@ export const useAllEmployees = ( showInactive ) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ManageBucket.jsx
|
// ManageBucket.jsx
|
||||||
export const useEmployees = ( selectedProject ) =>
|
export const useEmployees = (selectedProject) => {
|
||||||
{
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data = [],
|
data = [],
|
||||||
isLoading,
|
isLoading,
|
||||||
@ -50,7 +43,9 @@ export const useEmployees = ( selectedProject ) =>
|
|||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["employeeListByProject", selectedProject],
|
queryKey: ["employeeListByProject", selectedProject],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await EmployeeRepository.getEmployeeListByproject(selectedProject);
|
const res = await EmployeeRepository.getEmployeeListByproject(
|
||||||
|
selectedProject
|
||||||
|
);
|
||||||
return res.data || res;
|
return res.data || res;
|
||||||
},
|
},
|
||||||
enabled: !!selectedProject,
|
enabled: !!selectedProject,
|
||||||
@ -72,12 +67,12 @@ export const useEmployeeRoles = (employeeId) => {
|
|||||||
isLoading: loading,
|
isLoading: loading,
|
||||||
error,
|
error,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ['employeeRoles', employeeId],
|
queryKey: ["employeeRoles", employeeId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await RolesRepository.getEmployeeRoles(employeeId);
|
const res = await RolesRepository.getEmployeeRoles(employeeId);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
enabled: !!employeeId,
|
enabled: !!employeeId,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -95,7 +90,7 @@ export const useEmployeesByProject = (projectId) => {
|
|||||||
error,
|
error,
|
||||||
refetch: recallProjectEmplloyee,
|
refetch: recallProjectEmplloyee,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ['projectEmployees', projectId],
|
queryKey: ["projectEmployees", projectId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await ProjectRepository.getEmployeesByProject(projectId);
|
const res = await ProjectRepository.getEmployeesByProject(projectId);
|
||||||
return res.data;
|
return res.data;
|
||||||
@ -112,16 +107,17 @@ export const useEmployeesByProject = (projectId) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// EmployeeList.jsx
|
// EmployeeList.jsx
|
||||||
export const useEmployeesAllOrByProjectId = (showAllEmployees ,projectId,
|
export const useEmployeesAllOrByProjectId = (
|
||||||
showInactive) => {
|
showAllEmployees,
|
||||||
|
projectId,
|
||||||
|
showInactive
|
||||||
const queryKey = showAllEmployees
|
) => {
|
||||||
? ['allEmployees', showInactive]
|
const queryKey = showAllEmployees
|
||||||
: ['projectEmployees', projectId, showInactive];
|
? ["allEmployees", showInactive]
|
||||||
|
: ["projectEmployees", projectId, showInactive];
|
||||||
|
|
||||||
const queryFn = async () => {
|
const queryFn = async () => {
|
||||||
if (showAllEmployees) {
|
if (showAllEmployees) {
|
||||||
const res = await EmployeeRepository.getAllEmployeeList(showInactive);
|
const res = await EmployeeRepository.getAllEmployeeList(showInactive);
|
||||||
return res.data;
|
return res.data;
|
||||||
} else {
|
} else {
|
||||||
@ -139,7 +135,8 @@ export const useEmployeesAllOrByProjectId = (showAllEmployees ,projectId,
|
|||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey,
|
queryKey,
|
||||||
queryFn,
|
queryFn,
|
||||||
enabled:typeof showInactive === "boolean" && (showAllEmployees || !!projectId),
|
enabled:
|
||||||
|
typeof showInactive === "boolean" && (showAllEmployees || !!projectId),
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -151,16 +148,15 @@ export const useEmployeesAllOrByProjectId = (showAllEmployees ,projectId,
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ManageEmployee.jsx
|
// ManageEmployee.jsx
|
||||||
export const useEmployeeProfile = ( employeeId ) =>
|
export const useEmployeeProfile = (employeeId) => {
|
||||||
{
|
|
||||||
const isEnabled = !!employeeId;
|
const isEnabled = !!employeeId;
|
||||||
const {
|
const {
|
||||||
data = null,
|
data = null,
|
||||||
isLoading: loading,
|
isLoading: loading,
|
||||||
error,
|
error,
|
||||||
refetch
|
refetch,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ['employeeProfile', employeeId],
|
queryKey: ["employeeProfile", employeeId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (!employeeId) return null;
|
if (!employeeId) return null;
|
||||||
const res = await EmployeeRepository.getEmployeeProfile(employeeId);
|
const res = await EmployeeRepository.getEmployeeProfile(employeeId);
|
||||||
@ -173,47 +169,64 @@ export const useEmployeeProfile = ( employeeId ) =>
|
|||||||
employee: data,
|
employee: data,
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
refetch
|
refetch,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useEmployeesName = (projectId, search) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["employees", projectId, search],
|
||||||
|
queryFn: async() => await EmployeeRepository.getEmployeeName(projectId, search),
|
||||||
|
|
||||||
|
staleTime: 5 * 60 * 1000, // Optional: cache for 5 minutes
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Mutation------------------------------------------------------------------
|
// Mutation------------------------------------------------------------------
|
||||||
|
|
||||||
|
export const useUpdateEmployee = () => {
|
||||||
|
const selectedProject = useSelector(
|
||||||
export const useUpdateEmployee = () =>
|
(store) => store.localVariables.projectId
|
||||||
{
|
);
|
||||||
const selectedProject = useSelector((store)=>store.localVariables.projectId)
|
const queryClient = useQueryClient();
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (employeeData) => EmployeeRepository.manageEmployee(employeeData),
|
mutationFn: (employeeData) =>
|
||||||
|
EmployeeRepository.manageEmployee(employeeData),
|
||||||
onSuccess: (_, variables) => {
|
onSuccess: (_, variables) => {
|
||||||
const id = variables.id || variables.employeeId;
|
const id = variables.id || variables.employeeId;
|
||||||
const isAllEmployee = variables.IsAllEmployee;
|
const isAllEmployee = variables.IsAllEmployee;
|
||||||
|
|
||||||
// Cache invalidation
|
// Cache invalidation
|
||||||
queryClient.invalidateQueries( {queryKey:[ 'allEmployees'] });
|
queryClient.invalidateQueries({ queryKey: ["allEmployees"] });
|
||||||
// queryClient.invalidateQueries(['employeeProfile', id]);
|
// queryClient.invalidateQueries(['employeeProfile', id]);
|
||||||
queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
|
queryClient.invalidateQueries({ queryKey: ["projectEmployees"] });
|
||||||
queryClient.removeQueries( {queryKey: [ "empListByProjectAllocated" ]} );
|
queryClient.removeQueries({ queryKey: ["empListByProjectAllocated"] });
|
||||||
|
|
||||||
// queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject']} );
|
// queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject']} );
|
||||||
showToast( `Employee ${ id ? 'updated' : 'created' } successfully`, 'success' );
|
showToast(
|
||||||
|
`Employee ${id ? "updated" : "created"} successfully`,
|
||||||
|
"success"
|
||||||
|
);
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
const msg = error?.response?.data?.message || error.message || 'Something went wrong';
|
const msg =
|
||||||
showToast(msg, 'error');
|
error?.response?.data?.message ||
|
||||||
|
error.message ||
|
||||||
|
"Something went wrong";
|
||||||
|
showToast(msg, "error");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useSuspendEmployee = ({
|
||||||
|
setIsDeleteModalOpen,
|
||||||
export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing }) => {
|
setemployeeLodaing,
|
||||||
|
}) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const selectedProject = useSelector((store)=>store.localVariables.projectId)
|
const selectedProject = useSelector(
|
||||||
|
(store) => store.localVariables.projectId
|
||||||
|
);
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (id) => {
|
mutationFn: (id) => {
|
||||||
setemployeeLodaing(true);
|
setemployeeLodaing(true);
|
||||||
@ -221,12 +234,12 @@ export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing })
|
|||||||
},
|
},
|
||||||
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|
||||||
|
|
||||||
// queryClient.invalidateQueries( ['allEmployee',false]);
|
// queryClient.invalidateQueries( ['allEmployee',false]);
|
||||||
queryClient.invalidateQueries( {queryKey: [ 'projectEmployees' ]} );
|
queryClient.invalidateQueries({ queryKey: ["projectEmployees"] });
|
||||||
queryClient.invalidateQueries( {queryKey:[ 'employeeListByProject' ,selectedProject]} );
|
queryClient.invalidateQueries({
|
||||||
showToast("Employee deleted successfully.", "success");
|
queryKey: ["employeeListByProject", selectedProject],
|
||||||
|
});
|
||||||
|
showToast("Employee deleted successfully.", "success");
|
||||||
setIsDeleteModalOpen(false);
|
setIsDeleteModalOpen(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -247,8 +260,11 @@ export const useSuspendEmployee = ({ setIsDeleteModalOpen, setemployeeLodaing })
|
|||||||
|
|
||||||
// Manage Role
|
// Manage Role
|
||||||
|
|
||||||
|
export const useUpdateEmployeeRoles = ({
|
||||||
export const useUpdateEmployeeRoles = ({ onClose, resetForm, onSuccessCallback } = {}) => {
|
onClose,
|
||||||
|
resetForm,
|
||||||
|
onSuccessCallback,
|
||||||
|
} = {}) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
mutationFn: (updates) => RolesRepository.createEmployeeRoles(updates),
|
mutationFn: (updates) => RolesRepository.createEmployeeRoles(updates),
|
||||||
@ -259,12 +275,14 @@ export const useUpdateEmployeeRoles = ({ onClose, resetForm, onSuccessCallback }
|
|||||||
onClose?.();
|
onClose?.();
|
||||||
onSuccessCallback?.();
|
onSuccessCallback?.();
|
||||||
|
|
||||||
queryClient.invalidateQueries( {queryKey: [ "employeeRoles" ]} );
|
queryClient.invalidateQueries({ queryKey: ["employeeRoles"] });
|
||||||
queryClient.invalidateQueries( {queryKey: [ "profile" ]} );
|
queryClient.invalidateQueries({ queryKey: ["profile"] });
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
const message =
|
const message =
|
||||||
err?.response?.data?.message || err?.message || "Error occurred while updating roles";
|
err?.response?.data?.message ||
|
||||||
|
err?.message ||
|
||||||
|
"Error occurred while updating roles";
|
||||||
showToast(message, "error");
|
showToast(message, "error");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
254
src/hooks/useExpense.js
Normal file
254
src/hooks/useExpense.js
Normal file
@ -0,0 +1,254 @@
|
|||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import ExpenseRepository from "../repositories/ExpsenseRepository";
|
||||||
|
import showToast from "../services/toastService";
|
||||||
|
import { queryClient } from "../layouts/AuthLayout";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
|
// -------------------Query------------------------------------------------------
|
||||||
|
const cleanFilter = (filter) => {
|
||||||
|
const cleaned = { ...filter };
|
||||||
|
|
||||||
|
["projectIds", "statusIds", "createdByIds", "paidById"].forEach((key) => {
|
||||||
|
if (Array.isArray(cleaned[key]) && cleaned[key].length === 0) {
|
||||||
|
delete cleaned[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!cleaned.startDate) delete cleaned.startDate;
|
||||||
|
if (!cleaned.endDate) delete cleaned.endDate;
|
||||||
|
|
||||||
|
return cleaned;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useExpenseList = (
|
||||||
|
pageSize,
|
||||||
|
pageNumber,
|
||||||
|
filter,
|
||||||
|
searchString = ""
|
||||||
|
) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["Expenses", pageNumber, pageSize, filter, searchString],
|
||||||
|
queryFn: async () => {
|
||||||
|
const cleanedFilter = cleanFilter(filter);
|
||||||
|
const response = await ExpenseRepository.GetExpenseList(
|
||||||
|
pageSize,
|
||||||
|
pageNumber,
|
||||||
|
cleanedFilter,
|
||||||
|
searchString
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
keepPreviousData: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useExpense = (ExpenseId) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["Expense", ExpenseId],
|
||||||
|
queryFn: async () =>
|
||||||
|
await ExpenseRepository.GetExpenseDetails(ExpenseId).then(
|
||||||
|
(res) => res.data
|
||||||
|
),
|
||||||
|
enabled: !!ExpenseId,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useExpenseFilter = () => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["ExpenseFilter"],
|
||||||
|
queryFn: async () =>
|
||||||
|
await ExpenseRepository.GetExpenseFilter().then((res) => res.data),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---------------------------Mutation---------------------------------------------
|
||||||
|
|
||||||
|
export const useCreateExpnse = (onSuccessCallBack) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async (payload) => {
|
||||||
|
await ExpenseRepository.CreateExpense(payload);
|
||||||
|
},
|
||||||
|
onSuccess: (_, variables) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["Expenses"] });
|
||||||
|
showToast("Expense Created Successfully", "success");
|
||||||
|
if (onSuccessCallBack) onSuccessCallBack();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error.message || "Something went wrong please try again !",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useUpdateExpense = (onSuccessCallBack) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async ({ id, payload }) => {
|
||||||
|
const response = await ExpenseRepository.UpdateExpense(id, payload);
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
onSuccess: (updatedExpense, variables) => {
|
||||||
|
// queryClient.setQueriesData(
|
||||||
|
// {queryKey:['expenses'],exact:true},
|
||||||
|
// (oldData) => {
|
||||||
|
// if (!oldData || !oldData.data) return oldData;
|
||||||
|
|
||||||
|
// const updatedList = oldData.data.map((expense) => {
|
||||||
|
// if (expense.id !== variables.id) return expense;
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// ...expense,
|
||||||
|
// project:
|
||||||
|
// expense.project.id !== updatedExpense.project.id
|
||||||
|
// ? updatedExpense.project
|
||||||
|
// : expense.project,
|
||||||
|
// expensesType:
|
||||||
|
// expense.expensesType.id !== updatedExpense.expensesType.id
|
||||||
|
// ? updatedExpense.expensesType
|
||||||
|
// : expense.expensesType,
|
||||||
|
// paymentMode:
|
||||||
|
// expense.paymentMode.id !== updatedExpense.paymentMode.id
|
||||||
|
// ? updatedExpense.paymentMode
|
||||||
|
// : expense.paymentMode,
|
||||||
|
// paidBy:
|
||||||
|
// expense.paidBy.id !== updatedExpense.paidBy.id
|
||||||
|
// ? updatedExpense.paidBy
|
||||||
|
// : expense.paidBy,
|
||||||
|
// createdBy:
|
||||||
|
// expense.createdBy.id !== updatedExpense.createdBy.id
|
||||||
|
// ? updatedExpense.createdBy
|
||||||
|
// : expense.createdBy,
|
||||||
|
// createdAt: updatedExpense.createdAt,
|
||||||
|
// status: updatedExpense.status,
|
||||||
|
// nextStatus: updatedExpense.nextStatus,
|
||||||
|
// preApproved: updatedExpense.preApproved,
|
||||||
|
// transactionDate: updatedExpense.transactionDate,
|
||||||
|
// amount: updatedExpense.amount,
|
||||||
|
// };
|
||||||
|
// });
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// ...oldData,
|
||||||
|
// data: updatedList,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
queryClient.removeQueries({ queryKey: ["Expense", variables.id] });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["Expenses"] });
|
||||||
|
showToast("Expense updated Successfully", "success");
|
||||||
|
|
||||||
|
if (onSuccessCallBack) onSuccessCallBack();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast("Something went wrong.Please try again later.", "error");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useActionOnExpense = (onSuccessCallBack) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async (payload) => {
|
||||||
|
const response = await ExpenseRepository.ActionOnExpense(payload);
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
onSuccess: (updatedExpense, variables) => {
|
||||||
|
showToast("Request processed successfully.", "success");
|
||||||
|
|
||||||
|
queryClient.setQueriesData(
|
||||||
|
{
|
||||||
|
queryKey: ["Expenses"],
|
||||||
|
exact: false,
|
||||||
|
},
|
||||||
|
(oldData) => {
|
||||||
|
if (!oldData) return oldData;
|
||||||
|
return {
|
||||||
|
...oldData,
|
||||||
|
data: oldData.data.map((item) =>
|
||||||
|
item.id === updatedExpense.id
|
||||||
|
? {
|
||||||
|
...item,
|
||||||
|
nextStatus: updatedExpense.nextStatus,
|
||||||
|
status: updatedExpense.status,
|
||||||
|
}
|
||||||
|
: item
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// queryClient.setQueriesData(
|
||||||
|
// { queryKey: ["Expense", updatedExpense.id] },
|
||||||
|
// (oldData) => {
|
||||||
|
// return {
|
||||||
|
// ...oldData,
|
||||||
|
// nextStatus: updatedExpense.nextStatus,
|
||||||
|
// status: updatedExpense.status,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
queryClient.invalidateQueries({queryKey:["Expense",updatedExpense.id]})
|
||||||
|
|
||||||
|
if (onSuccessCallBack) onSuccessCallBack();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error.response.data.message ||
|
||||||
|
"Something went wrong.Please try again later.",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDeleteExpense = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async ({ id }) => {
|
||||||
|
const response = await ExpenseRepository.DeleteExpense(id);
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
onSuccess: (data, variables) => {
|
||||||
|
queryClient.setQueryData(["Expenses"], (oldData) => {
|
||||||
|
if (!oldData || !oldData.data)
|
||||||
|
return queryClient.invalidateQueries({ queryKey: ["Expenses"] });
|
||||||
|
|
||||||
|
const updatedList = oldData.data.filter(
|
||||||
|
(expense) => expense.id !== variables.id
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...oldData,
|
||||||
|
data: updatedList,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
showToast(data.message || "Expense deleted successfully", "success");
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
showToast(
|
||||||
|
error.message ||
|
||||||
|
error.response.message ||
|
||||||
|
"Something went wrong.Please try again later.",
|
||||||
|
"error"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useHasAnyPermission = (permissionIdsInput) => {
|
||||||
|
const permissions = useSelector((state) => state?.profile?.permissions || []);
|
||||||
|
|
||||||
|
const permissionIds = Array.isArray(permissionIdsInput)
|
||||||
|
? permissionIdsInput
|
||||||
|
: [];
|
||||||
|
|
||||||
|
// No permission needed
|
||||||
|
if (permissionIds.length === 0) return true;
|
||||||
|
|
||||||
|
return permissionIds.some((id) => permissions.includes(id));
|
||||||
|
};
|
||||||
@ -7,6 +7,8 @@ import Footer from "../components/Layout/Footer";
|
|||||||
import FloatingMenu from "../components/common/FloatingMenu";
|
import FloatingMenu from "../components/common/FloatingMenu";
|
||||||
import { FabProvider } from "../Context/FabContext";
|
import { FabProvider } from "../Context/FabContext";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
import OffcanvasTrigger from "../components/common/OffcanvasTrigger";
|
||||||
|
import GlobalOffcanvas from "../components/common/GlobalOffcanvas ";
|
||||||
|
|
||||||
const HomeLayout = () => {
|
const HomeLayout = () => {
|
||||||
const loggedUser = useSelector((store) => store.globalVariables.loginUser);
|
const loggedUser = useSelector((store) => store.globalVariables.loginUser);
|
||||||
@ -34,9 +36,11 @@ const HomeLayout = () => {
|
|||||||
<Footer />
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<OffcanvasTrigger />
|
||||||
<FloatingMenu />
|
<FloatingMenu />
|
||||||
<div className="layout-overlay layout-menu-toggle"></div>
|
<div className="layout-overlay layout-menu-toggle"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<GlobalOffcanvas />
|
||||||
</div>
|
</div>
|
||||||
</FabProvider>
|
</FabProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -8,42 +8,35 @@ 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 queryClient = useQueryClient();
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
const loginUser = getCachedProfileData();
|
const loginUser = getCachedProfileData();
|
||||||
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
const 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();
|
const [modelConfig, setModelConfig] = useState(null); // Initialize as null
|
||||||
const DoRegularized = useHasUserPermission(REGULARIZE_ATTENDANCE);
|
const DoRegularized = useHasUserPermission(REGULARIZE_ATTENDANCE);
|
||||||
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
||||||
|
|
||||||
@ -53,86 +46,163 @@ 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.map((item) =>
|
const updatedAttendance = attendances
|
||||||
// item.employeeId === msg.response.employeeId
|
? attendances.map((item) =>
|
||||||
// ? { ...item, ...msg.response }
|
item.employeeId === msg.response.employeeId
|
||||||
// : item
|
? { ...item, ...msg.response }
|
||||||
// );
|
: item
|
||||||
// queryClient.setQueryData(["attendance", selectedProject], (oldData) => {
|
)
|
||||||
// if (!oldData) return oldData;
|
: [msg.response];
|
||||||
// return oldData.map((emp) =>
|
|
||||||
// emp.employeeId === data.employeeId ? { ...emp, ...data } : emp
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// [selectedProject, attrecall]
|
|
||||||
// );
|
|
||||||
|
|
||||||
// const employeeHandler = useCallback(
|
cacheData("Attendance", {
|
||||||
// (msg) => {
|
data: updatedAttendance,
|
||||||
// if (attendances.some((item) => item.employeeId == msg.employeeId)) {
|
projectId: selectedProject,
|
||||||
// attrecall();
|
});
|
||||||
// }
|
setAttendances(updatedAttendance);
|
||||||
// },
|
}
|
||||||
// [selectedProject, attendances]
|
},
|
||||||
// );
|
[selectedProject, attendances]
|
||||||
useEffect(() => {
|
);
|
||||||
if (selectedProject == null) {
|
|
||||||
dispatch(setProjectId(projectNames[0]?.id));
|
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";
|
||||||
};
|
};
|
||||||
|
|
||||||
const openModel = () => {
|
// Simplified and moved modal opening logic
|
||||||
setIsCreateModalOpen(true);
|
const handleModalData = useCallback((employee) => {
|
||||||
};
|
|
||||||
|
|
||||||
const handleModalData = (employee) => {
|
|
||||||
setModelConfig(employee);
|
setModelConfig(employee);
|
||||||
};
|
setIsCreateModalOpen(true); // Open the modal directly when data is set
|
||||||
|
}, []);
|
||||||
|
|
||||||
const closeModal = () => {
|
const closeModal = useCallback(() => {
|
||||||
setModelConfig(null);
|
setModelConfig(null);
|
||||||
setIsCreateModalOpen(false);
|
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) => {
|
const handleToggle = (event) => {
|
||||||
setShowOnlyCheckout(event.target.checked);
|
setShowPending(event.target.checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedProject === null && projectNames.length > 0) {
|
||||||
|
dispatch(setProjectId(projectNames[0]?.id));
|
||||||
|
}
|
||||||
|
}, [selectedProject, projectNames, dispatch]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (modelConfig !== null) {
|
setAttendances(attendance);
|
||||||
openModel();
|
}, [attendance]);
|
||||||
|
|
||||||
|
const filteredAndSearchedTodayAttendance = useCallback(() => {
|
||||||
|
let currentData = attendances;
|
||||||
|
|
||||||
|
if (showPending) {
|
||||||
|
currentData = currentData?.filter(
|
||||||
|
(att) => att?.checkInTime !== null && att?.checkOutTime === null
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, [modelConfig, isCreateModalOpen]);
|
|
||||||
|
|
||||||
// useEffect(() => {
|
if (searchQuery) {
|
||||||
// eventBus.on("attendance", handler);
|
const lowerCaseSearchQuery = searchQuery.toLowerCase();
|
||||||
// return () => eventBus.off("attendance", handler);
|
currentData = currentData?.filter((att) => {
|
||||||
// }, [handler]);
|
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-modalg"
|
id="check-Out-modal"
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
>
|
>
|
||||||
@ -142,29 +212,6 @@ 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">
|
||||||
@ -174,69 +221,106 @@ const AttendancePage = () => {
|
|||||||
{ label: "Attendance", link: null },
|
{ label: "Attendance", link: null },
|
||||||
]}
|
]}
|
||||||
></Breadcrumb>
|
></Breadcrumb>
|
||||||
<div className="nav-align-top nav-tabs-shadow" >
|
<div className="nav-align-top nav-tabs-shadow">
|
||||||
<ul className="nav nav-tabs" role="tablist">
|
<ul
|
||||||
<li className="nav-item">
|
className="nav nav-tabs d-flex justify-content-between align-items-center"
|
||||||
<button
|
role="tablist"
|
||||||
type="button"
|
>
|
||||||
className={`nav-link ${
|
<div className="d-flex">
|
||||||
activeTab === "all" ? "active" : ""
|
<li className="nav-item">
|
||||||
} fs-6`}
|
<button
|
||||||
onClick={() => setActiveTab("all")}
|
type="button"
|
||||||
data-bs-toggle="tab"
|
className={`nav-link ${activeTab === "all" ? "active" : ""} fs-6`}
|
||||||
data-bs-target="#navs-top-home"
|
onClick={() => setActiveTab("all")}
|
||||||
>
|
data-bs-toggle="tab"
|
||||||
Today's
|
data-bs-target="#navs-top-home"
|
||||||
</button>
|
>
|
||||||
</li>
|
Today's
|
||||||
<li className="nav-item">
|
</button>
|
||||||
<button
|
</li>
|
||||||
type="button"
|
<li className="nav-item">
|
||||||
className={`nav-link ${
|
<button
|
||||||
activeTab === "logs" ? "active" : ""
|
type="button"
|
||||||
} 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"
|
||||||
>
|
>
|
||||||
Logs
|
Logs
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li className={`nav-item ${!DoRegularized && "d-none"}`}>
|
<li className={`nav-item ${!DoRegularized && "d-none"}`}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`nav-link ${
|
className={`nav-link ${
|
||||||
activeTab === "regularization" ? "active" : ""
|
activeTab === "regularization" ? "active" : ""
|
||||||
} fs-6`}
|
} fs-6`}
|
||||||
onClick={() => setActiveTab("regularization")}
|
onClick={() => setActiveTab("regularization")}
|
||||||
data-bs-toggle="tab"
|
data-bs-toggle="tab"
|
||||||
data-bs-target="#navs-top-messages"
|
data-bs-target="#navs-top-messages"
|
||||||
>
|
>
|
||||||
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" : ""}`}
|
className={`nav-link ${viewType === "notes" ? "active" : ""} fs-6`}
|
||||||
onClick={() => setViewType("notes")}
|
onClick={() => setViewType("notes")}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
@ -266,8 +266,9 @@ const DirectoryPageHeader = ({
|
|||||||
</li>
|
</li>
|
||||||
<li className="nav-item" role="presentation">
|
<li className="nav-item" role="presentation">
|
||||||
<button
|
<button
|
||||||
className={`nav-link ${viewType === "card" ? "active" : ""}`}
|
// Corrected: Apply 'active' if viewType is either 'card' or 'list'
|
||||||
onClick={() => setViewType("card")}
|
className={`nav-link ${viewType === "card" || viewType === "list" ? "active" : ""} fs-6`}
|
||||||
|
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
|
||||||
@ -279,7 +280,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-5 d-flex align-items-center gap-4">
|
<div className="col-12 col-md-6 mb-2 px-1 d-flex align-items-center gap-2">
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="search"
|
type="search"
|
||||||
@ -298,7 +299,7 @@ const DirectoryPageHeader = ({
|
|||||||
data-bs-toggle="dropdown"
|
data-bs-toggle="dropdown"
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
>
|
>
|
||||||
<i className={`fa-solid fa-filter ms-1 fs-5 ${notesFilterCount > 0 ? "text-primary" : "text-muted"}`}></i>
|
<i className={`bx bx-slider-alt ${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}
|
||||||
@ -341,7 +342,7 @@ const DirectoryPageHeader = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Organization */}
|
{/* Organization */}
|
||||||
<div style={{ maxHeight: "260px", overflowY: "auto",overflowX: "hidden", }}>
|
<div style={{ maxHeight: "260px", overflowY: "auto", overflowX: "hidden", }}>
|
||||||
<div style={{ position: "sticky", top: 0, background: "#fff", zIndex: 1 }}>
|
<div style={{ position: "sticky", top: 0, background: "#fff", zIndex: 1 }}>
|
||||||
<p className="text-muted mb-2 pt-2">Organization</p>
|
<p className="text-muted mb-2 pt-2">Organization</p>
|
||||||
</div>
|
</div>
|
||||||
@ -404,17 +405,17 @@ const DirectoryPageHeader = ({
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`btn btn-xs ${viewType === "card" ? "btn-primary" : "btn-outline-primary"}`}
|
className={`btn btn-sm p-1 ${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-xs ${viewType === "list" ? "btn-primary" : "btn-outline-primary"}`}
|
className={`btn btn-sm p-1 ${viewType === "list" ? "btn-primary" : "btn-outline-primary"}`}
|
||||||
onClick={() => setViewType("list")}
|
onClick={() => setViewType("list")}
|
||||||
>
|
>
|
||||||
<i className="bx bx-list-ul me-1"></i>
|
<i className="bx bx-list-ul"></i>
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -422,13 +423,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-center" style={{ width: "fit-content" }}>
|
<div className="dropdown" 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={`fa-solid fa-filter ms-1 fs-5 ${filtered > 0 ? "text-primary" : "text-muted"}`}></i>
|
<i className={`bx bx-slider-alt ${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}
|
||||||
|
|||||||
195
src/pages/Expense/ExpensePage.jsx
Normal file
195
src/pages/Expense/ExpensePage.jsx
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
import React, { createContext, useContext, useState, useEffect } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
|
// Components
|
||||||
|
import ExpenseList from "../../components/Expenses/ExpenseList";
|
||||||
|
import ViewExpense from "../../components/Expenses/ViewExpense";
|
||||||
|
import Breadcrumb from "../../components/common/Breadcrumb";
|
||||||
|
import GlobalModel from "../../components/common/GlobalModel";
|
||||||
|
import PreviewDocument from "../../components/Expenses/PreviewDocument";
|
||||||
|
import ManageExpense from "../../components/Expenses/ManageExpense";
|
||||||
|
import ExpenseFilterPanel from "../../components/Expenses/ExpenseFilterPanel";
|
||||||
|
|
||||||
|
// Context & Hooks
|
||||||
|
import { useFab } from "../../Context/FabContext";
|
||||||
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
|
import {
|
||||||
|
CREATE_EXEPENSE,
|
||||||
|
VIEW_ALL_EXPNESE,
|
||||||
|
VIEW_SELF_EXPENSE,
|
||||||
|
} from "../../utils/constants";
|
||||||
|
|
||||||
|
// Schema & Defaults
|
||||||
|
import {
|
||||||
|
defaultFilter,
|
||||||
|
SearchSchema,
|
||||||
|
} from "../../components/Expenses/ExpenseSchema";
|
||||||
|
|
||||||
|
// Context
|
||||||
|
export const ExpenseContext = createContext();
|
||||||
|
export const useExpenseContext = () => {
|
||||||
|
const context = useContext(ExpenseContext);
|
||||||
|
if (!context) {
|
||||||
|
throw new Error("useExpenseContext must be used within an ExpenseProvider");
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ExpensePage = () => {
|
||||||
|
const selectedProjectId = useSelector(
|
||||||
|
(store) => store.localVariables.projectId
|
||||||
|
);
|
||||||
|
|
||||||
|
const [filters, setFilter] = useState();
|
||||||
|
const [groupBy, setGroupBy] = useState("transactionDate");
|
||||||
|
const [searchText, setSearchText] = useState("");
|
||||||
|
|
||||||
|
const [ManageExpenseModal, setManageExpenseModal] = useState({
|
||||||
|
IsOpen: null,
|
||||||
|
expenseId: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [viewExpense, setViewExpense] = useState({
|
||||||
|
expenseId: null,
|
||||||
|
view: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [ViewDocument, setDocumentView] = useState({
|
||||||
|
IsOpen: false,
|
||||||
|
Image: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const IsCreatedAble = useHasUserPermission(CREATE_EXEPENSE);
|
||||||
|
const IsViewAll = useHasUserPermission(VIEW_ALL_EXPNESE);
|
||||||
|
const IsViewSelf = useHasUserPermission(VIEW_SELF_EXPENSE);
|
||||||
|
|
||||||
|
const { setOffcanvasContent, setShowTrigger } = useFab();
|
||||||
|
|
||||||
|
const methods = useForm({
|
||||||
|
resolver: zodResolver(SearchSchema),
|
||||||
|
defaultValues: defaultFilter,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { reset } = methods;
|
||||||
|
|
||||||
|
const clearFilter = () => {
|
||||||
|
setFilter(defaultFilter);
|
||||||
|
reset();
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setShowTrigger(true);
|
||||||
|
setOffcanvasContent(
|
||||||
|
"Expense Filters",
|
||||||
|
<ExpenseFilterPanel
|
||||||
|
onApply={setFilter}
|
||||||
|
handleGroupBy={setGroupBy}
|
||||||
|
clearFilter={clearFilter}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
setShowTrigger(false);
|
||||||
|
setOffcanvasContent("", null);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const contextValue = {
|
||||||
|
setViewExpense,
|
||||||
|
setManageExpenseModal,
|
||||||
|
setDocumentView,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ExpenseContext.Provider value={contextValue}>
|
||||||
|
<div className="container-fluid">
|
||||||
|
<Breadcrumb data={[{ label: "Home", link: "/" }, { label: "Expense" }]} />
|
||||||
|
|
||||||
|
{(IsViewAll || IsViewSelf) ? (
|
||||||
|
<>
|
||||||
|
<div className="card my-1">
|
||||||
|
<div className="card-body py-2 px-3">
|
||||||
|
<div className="row align-items-center">
|
||||||
|
<div className="col-sm-6 col-md-4">
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
className="form-control form-control-sm w-auto"
|
||||||
|
placeholder="Search Expense"
|
||||||
|
aria-describedby="search-label"
|
||||||
|
value={searchText}
|
||||||
|
onChange={(e) => setSearchText(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-sm-6 col-md-8 text-end mt-2 mt-sm-0">
|
||||||
|
{IsCreatedAble && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="p-1 me-2 bg-primary rounded-circle"
|
||||||
|
title="Add New Expense"
|
||||||
|
onClick={() => setManageExpenseModal({ IsOpen: true, expenseId: null })}
|
||||||
|
>
|
||||||
|
<i className="bx bx-plus fs-4 text-white"></i>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ExpenseList filters={filters} groupBy={groupBy} searchText={searchText} />
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div className="card text-center py-1">
|
||||||
|
<i className="fa-solid fa-triangle-exclamation fs-5" />
|
||||||
|
<p>Access Denied: You don't have permission to perform this action!</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Modals */}
|
||||||
|
{ManageExpenseModal.IsOpen && (
|
||||||
|
<GlobalModel
|
||||||
|
isOpen
|
||||||
|
size="lg"
|
||||||
|
closeModal={() => setManageExpenseModal({ IsOpen: null, expenseId: null })}
|
||||||
|
>
|
||||||
|
<ManageExpense
|
||||||
|
key={ManageExpenseModal.expenseId ?? "new"}
|
||||||
|
expenseToEdit={ManageExpenseModal.expenseId}
|
||||||
|
closeModal={() => setManageExpenseModal({ IsOpen: null, expenseId: null })}
|
||||||
|
/>
|
||||||
|
</GlobalModel>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{viewExpense.view && (
|
||||||
|
<GlobalModel
|
||||||
|
isOpen
|
||||||
|
size="lg"
|
||||||
|
modalType="top"
|
||||||
|
closeModal={() => setViewExpense({ expenseId: null, view: false })}
|
||||||
|
>
|
||||||
|
<ViewExpense ExpenseId={viewExpense.expenseId} />
|
||||||
|
</GlobalModel>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{ViewDocument.IsOpen && (
|
||||||
|
<GlobalModel
|
||||||
|
isOpen
|
||||||
|
size="lg"
|
||||||
|
key={ViewDocument.Image ?? "doc"}
|
||||||
|
closeModal={() => setDocumentView({ IsOpen: false, Image: null })}
|
||||||
|
>
|
||||||
|
<PreviewDocument imageUrl={ViewDocument.Image} />
|
||||||
|
</GlobalModel>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</ExpenseContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ExpensePage;
|
||||||
@ -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="fa-solid fa-filter ms-1 fs-5" />
|
<i className="bx bx-slider-alt ms-1" />
|
||||||
)}
|
)}
|
||||||
</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-MM-YYYY"
|
"DD MMMM, 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">Role</div>
|
<div className="text-start ms-5">Official Designation</div>
|
||||||
</th>
|
</th>
|
||||||
|
|
||||||
<th
|
<th
|
||||||
|
|||||||
@ -102,8 +102,8 @@ const EmployeeProfile = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{showModal && (
|
{showModal && (
|
||||||
<GlobalModel size="lg" isOpen={showModal} closeModal={()=>setShowModal(false)}>
|
<GlobalModel size="lg" isOpen={showModal} closeModal={() => setShowModal(false)}>
|
||||||
<ManageEmployee employeeId={employeeId} onClosed={()=>setShowModal(false)} />
|
<ManageEmployee employeeId={employeeId} onClosed={() => setShowModal(false)} />
|
||||||
</GlobalModel>
|
</GlobalModel>
|
||||||
)}
|
)}
|
||||||
<div className="container-fluid">
|
<div className="container-fluid">
|
||||||
@ -146,7 +146,7 @@ const EmployeeProfile = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="fw-medium text-start">
|
<td className="fw-medium text-start text-nowrap">
|
||||||
Phone Number:
|
Phone Number:
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
@ -154,26 +154,21 @@ const EmployeeProfile = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="fw-medium text-start">
|
<td className="fw-medium text-start" style={{ width: '120px' }}>
|
||||||
Emergency Contact Person:
|
Emergency Contact Person:
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start">
|
<td className="text-start align-bottom">
|
||||||
{currentEmployee?.emergencyContactPerson || (
|
{currentEmployee?.emergencyContactPerson || <em>NA</em>}
|
||||||
<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">
|
<td className="text-start align-bottom">
|
||||||
{currentEmployee?.emergencyPhoneNumber || (
|
{currentEmployee?.emergencyPhoneNumber || <em>NA</em>}
|
||||||
<em>NA</em>
|
|
||||||
)}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td className="fw-medium text-start">
|
<td className="fw-medium text-start">
|
||||||
Gender:
|
Gender:
|
||||||
@ -220,21 +215,20 @@ const EmployeeProfile = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="fw-medium text-start">
|
<td className="fw-medium text-start align-top" >
|
||||||
Address:
|
Address:
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
{currentEmployee?.currentAddress || (
|
{currentEmployee?.currentAddress || <em>NA</em>}
|
||||||
<em>NA</em>
|
|
||||||
)}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
className="btn btn-primary btn-block"
|
className="btn btn-primary btn-block"
|
||||||
onClick={()=>setShowModal(true)}
|
onClick={() => setShowModal(true)}
|
||||||
>
|
>
|
||||||
Edit Profile
|
Edit Profile
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@ -16,6 +16,11 @@ const MasterTable = ({ data, columns, loading, handleModalData }) => {
|
|||||||
"tenantId",
|
"tenantId",
|
||||||
"checkLists",
|
"checkLists",
|
||||||
"isSystem",
|
"isSystem",
|
||||||
|
"isActive",
|
||||||
|
"noOfPersonsRequired",
|
||||||
|
"color",
|
||||||
|
"displayName",
|
||||||
|
"permissionIds"
|
||||||
];
|
];
|
||||||
|
|
||||||
const safeData = Array.isArray(data) ? data : [];
|
const safeData = Array.isArray(data) ? data : [];
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import {
|
|||||||
cacheData,
|
cacheData,
|
||||||
clearCacheKey,
|
clearCacheKey,
|
||||||
getCachedData,
|
getCachedData,
|
||||||
|
useSelectedproject,
|
||||||
} from "../../slices/apiDataManager";
|
} from "../../slices/apiDataManager";
|
||||||
import "./ProjectDetails.css";
|
import "./ProjectDetails.css";
|
||||||
import {
|
import {
|
||||||
@ -28,8 +29,7 @@ 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,9 +47,10 @@ 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) => {
|
||||||
@ -65,9 +66,11 @@ const ProjectDetails = () => {
|
|||||||
return () => eventBus.off("project", handler);
|
return () => eventBus.off("project", handler);
|
||||||
}, [handler]);
|
}, [handler]);
|
||||||
|
|
||||||
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 ms-3 mt-1">
|
<div className="dropdown 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="fa-solid fa-filter fs-4"></i>
|
<i className="bx bx-slider-alt ms-1"></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 "
|
className="table-responsive text-nowrap py-2 mx-2"
|
||||||
style={{ minHeight: "400px" }}
|
style={{ minHeight: "200px" }}
|
||||||
>
|
>
|
||||||
<table className="table m-3">
|
<table className="table m-0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th className="text-start" colSpan={5}>
|
<th className="text-start" colSpan={5}>
|
||||||
|
|||||||
@ -2,6 +2,7 @@ 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);
|
||||||
|
|||||||
@ -1,17 +1,22 @@
|
|||||||
import { api } from "../utils/axiosClient";
|
import { api } from "../utils/axiosClient";
|
||||||
|
|
||||||
const EmployeeRepository = {
|
const EmployeeRepository = {
|
||||||
getAllEmployeeList:(showInactive)=>api.get(`api/employee/list?showInactive=${showInactive}`),
|
getAllEmployeeList: (showInactive) =>
|
||||||
|
api.get(`api/employee/list?showInactive=${showInactive}`),
|
||||||
getEmployeeListByproject: (projectid) =>
|
getEmployeeListByproject: (projectid) =>
|
||||||
api.get(`/api/employee/list/${projectid}`),
|
api.get(`/api/employee/list/${projectid}`),
|
||||||
searchEmployees: (query) =>
|
searchEmployees: (query) => api.get(`/api/employee/search/${query}`),
|
||||||
api.get(`/api/employee/search/${query}`),
|
manageEmployee: (data) => api.post("/api/employee/manage", data),
|
||||||
manageEmployee: (data) =>
|
|
||||||
api.post("/api/employee/manage", data),
|
|
||||||
updateEmployee: (id, data) => api.put(`/users/${id}`, data),
|
updateEmployee: (id, data) => api.put(`/users/${id}`, data),
|
||||||
// deleteEmployee: ( id ) => api.delete( `/users/${ id }` ),
|
// deleteEmployee: ( id ) => api.delete( `/users/${ id }` ),
|
||||||
getEmployeeProfile:(id)=>api.get(`/api/employee/profile/get/${id}`),
|
getEmployeeProfile: (id) => api.get(`/api/employee/profile/get/${id}`),
|
||||||
deleteEmployee:(id)=>api.delete(`/api/employee/${id}`)
|
deleteEmployee: (id) => api.delete(`/api/employee/${id}`),
|
||||||
|
getEmployeeName: (projectId, search) =>
|
||||||
|
api.get(
|
||||||
|
`/api/Employee/basic${projectId ? `?projectId=${projectId}` : ""}${
|
||||||
|
search ? `${projectId ? "&" : "?"}searchString=${search}` : ""
|
||||||
|
}`
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EmployeeRepository;
|
export default EmployeeRepository;
|
||||||
|
|||||||
24
src/repositories/ExpsenseRepository.jsx
Normal file
24
src/repositories/ExpsenseRepository.jsx
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { api } from "../utils/axiosClient";
|
||||||
|
|
||||||
|
|
||||||
|
const ExpenseRepository = {
|
||||||
|
GetExpenseList: ( pageSize, pageNumber, filter,searchString ) => {
|
||||||
|
const payloadJsonString = JSON.stringify(filter);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return api.get(`/api/expense/list?pageSize=${pageSize}&pageNumber=${pageNumber}&filter=${payloadJsonString}&searchString=${searchString}`);
|
||||||
|
},
|
||||||
|
|
||||||
|
GetExpenseDetails:(id)=>api.get(`/api/Expense/details/${id}`),
|
||||||
|
CreateExpense:(data)=>api.post("/api/Expense/create",data),
|
||||||
|
UpdateExpense:(id,data)=>api.put(`/api/Expense/edit/${id}`,data),
|
||||||
|
DeleteExpense:(id)=>api.delete(`/api/Expense/delete/${id}`),
|
||||||
|
|
||||||
|
ActionOnExpense:(data)=>api.post('/api/expense/action',data),
|
||||||
|
|
||||||
|
GetExpenseFilter:()=>api.get('/api/Expense/filter')
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ExpenseRepository;
|
||||||
@ -13,49 +13,70 @@ export const RolesRepository = {
|
|||||||
updateRoles: (id, data) => api.put(`/users/${id}`, data),
|
updateRoles: (id, data) => api.put(`/users/${id}`, data),
|
||||||
deleteRoles: (id) => api.delete(`/users/${id}`),
|
deleteRoles: (id) => api.delete(`/users/${id}`),
|
||||||
|
|
||||||
|
getEmployeeRoles: (id) => api.get(`/api/employee/roles/${id}`),
|
||||||
getEmployeeRoles:(id)=>api.get(`/api/employee/roles/${id}`),
|
createEmployeeRoles: (data) => api.post("/api/roles/assign-roles", data),
|
||||||
createEmployeeRoles:(data)=>api.post("/api/roles/assign-roles",data)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const MasterRespository = {
|
export const MasterRespository = {
|
||||||
getRoles: () => api.get("/api/roles"),
|
getRoles: () => api.get("/api/roles"),
|
||||||
createRole: (data) => api.post("/api/roles", data),
|
createRole: (data) => api.post("/api/roles", data),
|
||||||
updateRoles:(id,data) => api.put(`/api/roles/${id}`,data),
|
updateRoles: (id, data) => api.put(`/api/roles/${id}`, data),
|
||||||
getFeatures: () => api.get( `/api/feature` ),
|
getFeatures: () => api.get(`/api/feature`),
|
||||||
|
|
||||||
|
createJobRole: (data) => api.post("api/roles/jobrole", data),
|
||||||
|
getJobRole: () => api.get("/api/roles/jobrole"),
|
||||||
|
updateJobRole: (id, data) => api.put(`/api/roles/jobrole/${id}`, data),
|
||||||
|
|
||||||
createJobRole:(data)=>api.post('api/roles/jobrole',data),
|
getActivites: () => api.get("api/master/activities"),
|
||||||
getJobRole :()=>api.get("/api/roles/jobrole"),
|
createActivity: (data) => api.post("api/master/activity", data),
|
||||||
updateJobRole: ( id, data ) => api.put( `/api/roles/jobrole/${ id }`, data ),
|
updateActivity: (id, data) =>
|
||||||
|
api.post(`api/master/activity/edit/${id}`, data),
|
||||||
|
getIndustries: () => api.get("api/master/industries"),
|
||||||
getActivites: () => api.get( 'api/master/activities' ),
|
|
||||||
createActivity: (data) => api.post( 'api/master/activity',data ),
|
|
||||||
updateActivity:(id,data) =>api.post(`api/master/activity/edit/${id}`,data),
|
|
||||||
getIndustries: () => api.get( 'api/master/industries' ),
|
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
"Job Role": ( id ) => api.delete( `/api/roles/jobrole/${ id }` ),
|
"Job Role": (id) => api.delete(`/api/roles/jobrole/${id}`),
|
||||||
"Activity": ( id ) => api.delete( `/api/master/activity/delete/${ id }` ),
|
Activity: (id) => api.delete(`/api/master/activity/delete/${id}`),
|
||||||
"Application Role":(id)=>api.delete(`/api/roles/${id}`),
|
"Application Role": (id) => api.delete(`/api/roles/${id}`),
|
||||||
"Work Category": ( id ) => api.delete( `api/master/work-category/${ id }` ),
|
"Work Category": (id) => api.delete(`api/master/work-category/${id}`),
|
||||||
"Contact Category": ( id ) => api.delete( `/api/master/contact-category/${id}` ),
|
"Contact Category": (id) => api.delete(`/api/master/contact-category/${id}`),
|
||||||
"Contact Tag" :(id)=>api.delete(`/api/master/contact-tag/${id}`),
|
"Contact Tag": (id) => api.delete(`/api/master/contact-tag/${id}`),
|
||||||
|
"Expense Type": (id, isActive) =>
|
||||||
|
api.delete(`/api/Master/expenses-type/delete/${id}`, (isActive = false)),
|
||||||
|
"Payment Mode": (id, isActive) =>
|
||||||
|
api.delete(`/api/Master/payment-mode/delete/${id}`, (isActive = false)),
|
||||||
|
"Expense Status": (id, isActive) =>
|
||||||
|
api.delete(`/api/Master/expenses-status/delete/${id}`, (isActive = false)),
|
||||||
|
|
||||||
getWorkCategory:() => api.get(`/api/master/work-categories`),
|
getWorkCategory: () => api.get(`/api/master/work-categories`),
|
||||||
createWorkCategory: (data) => api.post(`/api/master/work-category`,data),
|
createWorkCategory: (data) => api.post(`/api/master/work-category`, data),
|
||||||
updateWorkCategory: ( id, data ) => api.post( `/api/master/work-category/edit/${ id }`, data ),
|
updateWorkCategory: (id, data) =>
|
||||||
|
api.post(`/api/master/work-category/edit/${id}`, data),
|
||||||
|
|
||||||
getContactCategory: () => api.get( `/api/master/contact-categories` ),
|
getContactCategory: () => api.get(`/api/master/contact-categories`),
|
||||||
createContactCategory: (data ) => api.post( `/api/master/contact-category`, data ),
|
createContactCategory: (data) =>
|
||||||
updateContactCategory: ( id, data ) => api.post( `/api/master/contact-category/edit/${ id }`, data ),
|
api.post(`/api/master/contact-category`, data),
|
||||||
|
updateContactCategory: (id, data) =>
|
||||||
|
api.post(`/api/master/contact-category/edit/${id}`, data),
|
||||||
|
|
||||||
getContactTag: () => api.get( `/api/master/contact-tags` ),
|
getContactTag: () => api.get(`/api/master/contact-tags`),
|
||||||
createContactTag: (data ) => api.post( `/api/master/contact-tag`, data ),
|
createContactTag: (data) => api.post(`/api/master/contact-tag`, data),
|
||||||
updateContactTag: ( id, data ) => api.post( `/api/master/contact-tag/edit/${ id }`, data ),
|
updateContactTag: (id, data) =>
|
||||||
|
api.post(`/api/master/contact-tag/edit/${id}`, data),
|
||||||
|
|
||||||
getAuditStatus:()=>api.get('/api/Master/work-status')
|
getAuditStatus: () => api.get("/api/Master/work-status"),
|
||||||
|
|
||||||
}
|
getExpenseType: () => api.get("/api/Master/expenses-types"),
|
||||||
|
createExpenseType: (data) => api.post("/api/Master/expenses-type", data),
|
||||||
|
updateExpenseType: (id, data) =>
|
||||||
|
api.put(`/api/Master/expenses-type/edit/${id}`, data),
|
||||||
|
|
||||||
|
getPaymentMode: () => api.get("/api/Master/payment-modes"),
|
||||||
|
createPaymentMode: (data) => api.post(`/api/Master/payment-mode`, data),
|
||||||
|
updatePaymentMode: (id, data) =>
|
||||||
|
api.put(`/api/Master/payment-mode/edit/${id}`, data),
|
||||||
|
|
||||||
|
getExpenseStatus: () => api.get("/api/Master/expenses-status"),
|
||||||
|
createExpenseStatus: (data) => api.post("/api/Master/expenses-status", data),
|
||||||
|
updateExepnseStatus: (id, data) =>
|
||||||
|
api.put(`/api/Master/expenses-status/edit/${id}`, data),
|
||||||
|
};
|
||||||
|
|||||||
@ -38,6 +38,7 @@ import LegalInfoCard from "../pages/TermsAndConditions/LegalInfoCard";
|
|||||||
import ProtectedRoute from "./ProtectedRoute";
|
import ProtectedRoute from "./ProtectedRoute";
|
||||||
import Directory from "../pages/Directory/Directory";
|
import Directory from "../pages/Directory/Directory";
|
||||||
import LoginWithOtp from "../pages/authentication/LoginWithOtp";
|
import LoginWithOtp from "../pages/authentication/LoginWithOtp";
|
||||||
|
import ExpensePage from "../pages/Expense/ExpensePage";
|
||||||
|
|
||||||
const router = createBrowserRouter(
|
const router = createBrowserRouter(
|
||||||
[
|
[
|
||||||
@ -76,6 +77,7 @@ const router = createBrowserRouter(
|
|||||||
{ path: "/activities/task", element: <TaskPlannng /> },
|
{ path: "/activities/task", element: <TaskPlannng /> },
|
||||||
{ path: "/activities/reports", element: <Reports /> },
|
{ path: "/activities/reports", element: <Reports /> },
|
||||||
{ path: "/gallary", element: <ImageGallary /> },
|
{ path: "/gallary", element: <ImageGallary /> },
|
||||||
|
{ path: "/expenses", element: <ExpensePage /> },
|
||||||
{ path: "/masters", element: <MasterPage /> },
|
{ path: "/masters", element: <MasterPage /> },
|
||||||
{ path: "/help/support", element: <Support /> },
|
{ path: "/help/support", element: <Support /> },
|
||||||
{ path: "/help/docs", element: <Documentation /> },
|
{ path: "/help/docs", element: <Documentation /> },
|
||||||
|
|||||||
@ -5,6 +5,7 @@ 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
|
||||||
@ -37,3 +38,16 @@ 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,7 +21,9 @@ 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 ) =>
|
||||||
{
|
{
|
||||||
|
|||||||
49
src/utils/appUtils.js
Normal file
49
src/utils/appUtils.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
export const formatFileSize=(bytes)=> {
|
||||||
|
if (bytes < 1024) return bytes + " B";
|
||||||
|
else if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + " KB";
|
||||||
|
else return (bytes / (1024 * 1024)).toFixed(2) + " MB";
|
||||||
|
}
|
||||||
|
export const AppColorconfig = {
|
||||||
|
colors: {
|
||||||
|
primary: '#696cff',
|
||||||
|
secondary: '#8592a3',
|
||||||
|
success: '#71dd37',
|
||||||
|
info: '#03c3ec',
|
||||||
|
warning: '#ffab00',
|
||||||
|
danger: '#ff3e1d',
|
||||||
|
dark: '#233446',
|
||||||
|
black: '#000',
|
||||||
|
white: '#fff',
|
||||||
|
cardColor: '#fff',
|
||||||
|
bodyBg: '#f5f5f9',
|
||||||
|
bodyColor: '#697a8d',
|
||||||
|
headingColor: '#566a7f',
|
||||||
|
textMuted: '#a1acb8',
|
||||||
|
borderColor: '#eceef1'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const getColorNameFromHex = (hex) => {
|
||||||
|
const normalizedHex = hex?.replace(/'/g, '').toLowerCase();
|
||||||
|
const colors = AppColorconfig.colors;
|
||||||
|
|
||||||
|
for (const [name, value] of Object.entries(colors)) {
|
||||||
|
if (value.toLowerCase() === normalizedHex) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; //
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDebounce = (value, delay = 500) => {
|
||||||
|
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setTimeout(() => setDebouncedValue(value), delay);
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}, [value, delay]);
|
||||||
|
|
||||||
|
return debouncedValue;
|
||||||
|
};
|
||||||
@ -44,7 +44,7 @@ axiosClient.interceptors.response.use(
|
|||||||
const originalRequest = error.config;
|
const originalRequest = error.config;
|
||||||
|
|
||||||
// Skip retry for public requests or already retried ones
|
// Skip retry for public requests or already retried ones
|
||||||
if (!originalRequest || originalRequest._retry || originalRequest.authRequired === false) {
|
if (!originalRequest && originalRequest._retry || originalRequest.authRequired === false) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,5 +41,28 @@ export const DIRECTORY_MANAGER = "62668630-13ce-4f52-a0f0-db38af2230c5"
|
|||||||
|
|
||||||
export const DIRECTORY_USER = "0f919170-92d4-4337-abd3-49b66fc871bb"
|
export const DIRECTORY_USER = "0f919170-92d4-4337-abd3-49b66fc871bb"
|
||||||
|
|
||||||
|
export const VIEW_SELF_EXPENSE = "385be49f-8fde-440e-bdbc-3dffeb8dd116"
|
||||||
|
|
||||||
|
export const VIEW_ALL_EXPNESE = "01e06444-9ca7-4df4-b900-8c3fa051b92f";
|
||||||
|
|
||||||
|
export const CREATE_EXEPENSE = "0f57885d-bcb2-4711-ac95-d841ace6d5a7";
|
||||||
|
|
||||||
|
export const REVIEW_EXPENSE = "1f4bda08-1873-449a-bb66-3e8222bd871b";
|
||||||
|
|
||||||
|
export const APPROVE_EXPENSE = "eaafdd76-8aac-45f9-a530-315589c6deca";
|
||||||
|
|
||||||
|
|
||||||
|
export const PROCESS_EXPENSE = "ea5a1529-4ee8-4828-80ea-0e23c9d4dd11"
|
||||||
|
|
||||||
|
export const EXPENSE_MANAGE = "ea5a1529-4ee8-4828-80ea-0e23c9d4dd11"
|
||||||
|
|
||||||
|
export const EXPENSE_REJECTEDBY = ["d1ee5eec-24b6-4364-8673-a8f859c60729","965eda62-7907-4963-b4a1-657fb0b2724b"]
|
||||||
|
|
||||||
|
export const EXPENSE_DRAFT = "297e0d8f-f668-41b5-bfea-e03b354251c8"
|
||||||
|
// -------------------Application Role------------------------------
|
||||||
|
|
||||||
|
// 1 - Expense Manage
|
||||||
|
export const EXPENSE_MANAGEMENT = "a4e25142-449b-4334-a6e5-22f70e4732d7"
|
||||||
|
|
||||||
export const BASE_URL = process.env.VITE_BASE_URL;
|
export const BASE_URL = process.env.VITE_BASE_URL;
|
||||||
// export const BASE_URL = "https://api.marcoaiot.com";
|
// export const BASE_URL = "https://api.marcoaiot.com";
|
||||||
@ -67,9 +67,13 @@ export const formatNumber = (num) => {
|
|||||||
if (num == null || isNaN(num)) return "NA";
|
if (num == null || isNaN(num)) return "NA";
|
||||||
return Number.isInteger(num) ? num : num.toFixed(2);
|
return Number.isInteger(num) ? num : num.toFixed(2);
|
||||||
};
|
};
|
||||||
export const formatUTCToLocalTime = (datetime) =>{
|
|
||||||
return moment.utc(datetime).local().format("MMMM DD, YYYY [at] hh:mm A");
|
|
||||||
}
|
export const formatUTCToLocalTime = (datetime, timeRequired = false) => {
|
||||||
|
return timeRequired
|
||||||
|
? moment.utc(datetime).local().format("DD MMMM YYYY hh:mm A")
|
||||||
|
: moment.utc(datetime).local().format("DD MMMM YYYY");
|
||||||
|
};
|
||||||
|
|
||||||
export const getCompletionPercentage = (completedWork, plannedWork)=> {
|
export const getCompletionPercentage = (completedWork, plannedWork)=> {
|
||||||
if (!plannedWork || plannedWork === 0) return 0;
|
if (!plannedWork || plannedWork === 0) return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user