From 4e48478fbc081e82d7fd1eb6ca2212a1b64b8ab3 Mon Sep 17 00:00:00 2001 From: "pramod.mahajan" Date: Tue, 30 Sep 2025 19:31:24 +0530 Subject: [PATCH] update attendnace and expense --- .../Activities/CheckCheckOutForm.jsx | 4 +- src/components/Dashboard/Attendance.jsx | 2 +- src/components/Expenses/ActiveFilters.jsx | 50 ++++++++++++++ src/components/Expenses/ExpenseList.jsx | 36 +++++----- src/components/Layout/Header.jsx | 4 +- .../master/Services/ServicesGroups.jsx | 1 - src/hooks/useAttendance.js | 67 ++----------------- src/pages/Activities/AttendancePage.jsx | 4 +- src/pages/employee/EmployeeList.jsx | 8 ++- src/pages/project/ProjectPage.jsx | 4 +- 10 files changed, 90 insertions(+), 90 deletions(-) create mode 100644 src/components/Expenses/ActiveFilters.jsx diff --git a/src/components/Activities/CheckCheckOutForm.jsx b/src/components/Activities/CheckCheckOutForm.jsx index 40eb0a75..1473f746 100644 --- a/src/components/Activities/CheckCheckOutForm.jsx +++ b/src/components/Activities/CheckCheckOutForm.jsx @@ -33,7 +33,7 @@ const createSchema = (modeldata) => { const checkOut = new Date(checkIn); checkOut.setHours(hour, minute, 0, 0); - return checkOut > checkIn; + return checkOut >= checkIn; } return true; }, { @@ -83,7 +83,7 @@ const CheckInCheckOut = ({ modeldata, closeModal, handleSubmitForm }) => { Id: modeldata?.id || null, comment: data.description, employeeID: modeldata.employeeId, - projectId: projectId, + // projectId: projectId, date: new Date().toISOString(), markTime: data.markTime, latitude: coords.latitude.toString(), diff --git a/src/components/Dashboard/Attendance.jsx b/src/components/Dashboard/Attendance.jsx index 5d010acc..96e5d9dc 100644 --- a/src/components/Dashboard/Attendance.jsx +++ b/src/components/Dashboard/Attendance.jsx @@ -2,7 +2,7 @@ import React, { useState, useMemo } from "react"; import ApexChart from "../Charts/Circle"; import { useProjects } from "../../hooks/useProjects"; import { useDashboard_AttendanceData } from "../../hooks/useDashboard_Data"; -import { useSelectedProject } from "../../hooks/useSelectedProject"; // ✅ your custom hook +import { useSelectedProject } from "../../hooks/useSelectedProject"; const Attendance = () => { const { projects } = useProjects(); diff --git a/src/components/Expenses/ActiveFilters.jsx b/src/components/Expenses/ActiveFilters.jsx new file mode 100644 index 00000000..ebd8639d --- /dev/null +++ b/src/components/Expenses/ActiveFilters.jsx @@ -0,0 +1,50 @@ +const ActiveFilters = ({ filters, optionsLookup = {}, onRemove }) => { + const entries = Object.entries(filters || {}); + + return ( +
+ {entries.map(([key, value]) => { + if (!value || (Array.isArray(value) && value.length === 0)) return null; + + if (Array.isArray(value)) { + return value.map((v) => { + const label = optionsLookup[key]?.[v] || v; + return ( + onRemove(key, v)} + > + {label} + + ); + }); + } + + if (typeof value === "boolean") { + return ( + onRemove(key)} + > + {key}: {value ? "Yes" : "No"} + + ); + } + + return ( + + {data?.startDate && data?.endDate + ? `${formatUTCToLocalTime( + data.startDate + )} - ${formatUTCToLocalTime(data.endDate)}` + : "No dates"} + + ); + })} +
+ ); +}; + +export default ActiveFilters; diff --git a/src/components/Expenses/ExpenseList.jsx b/src/components/Expenses/ExpenseList.jsx index c18d2650..35085588 100644 --- a/src/components/Expenses/ExpenseList.jsx +++ b/src/components/Expenses/ExpenseList.jsx @@ -61,33 +61,33 @@ const ExpenseList = ({ filters, groupBy = "transactionDate", searchText }) => { let key; switch (field) { case "transactionDate": - key = item.transactionDate?.split("T")[0]; + key = item?.transactionDate?.split("T")[0]; break; case "status": - key = item.status?.displayName || "Unknown"; + key = item?.status?.displayName || "Unknown"; break; case "submittedBy": - key = `${item.createdBy?.firstName ?? ""} ${ + key = `${item?.createdBy?.firstName ?? ""} ${ item.createdBy?.lastName ?? "" }`.trim(); break; case "project": - key = item.project?.name || "Unknown Project"; + key = item?.project?.name || "Unknown Project"; break; case "paymentMode": - key = item.paymentMode?.name || "Unknown Mode"; + key = item?.paymentMode?.name || "Unknown Mode"; break; case "expensesType": - key = item.expensesType?.name || "Unknown Type"; + key = item?.expensesType?.name || "Unknown Type"; break; case "createdAt": - key = item.createdAt?.split("T")[0] || "Unknown Type"; + key = item?.createdAt?.split("T")[0] || "Unknown Type"; break; default: key = "Others"; } if (!acc[key]) acc[key] = []; - acc[key].push(item); + acc[key]?.push(item); return acc; }, {}); }; @@ -163,23 +163,23 @@ const ExpenseList = ({ filters, groupBy = "transactionDate", searchText }) => { ]; if (isInitialLoading) return ; - if (isError) return
{error.message}
; + if (isError) return
{error?.message}
; const grouped = groupBy ? groupByField(data?.data ?? [], groupBy) : { All: data?.data ?? [] }; - const IsGroupedByDate = ["transactionDate", "createdAt"].includes(groupBy); + 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 + (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 + expense?.status?.id === EXPENSE_DRAFT && expense?.createdBy?.id === SelfId ); }; @@ -198,7 +198,7 @@ const ExpenseList = ({ filters, groupBy = "transactionDate", searchText }) => { /> )} -
+
{ )) ) : ( - - No Expense Found + +
+

No Expense Found

+
)} diff --git a/src/components/Layout/Header.jsx b/src/components/Layout/Header.jsx index 5128c7fc..970e6003 100644 --- a/src/components/Layout/Header.jsx +++ b/src/components/Layout/Header.jsx @@ -296,13 +296,13 @@ const Header = () => {
  • -
  • onOpen()}> + {/*
  • onOpen()}> {" "} Switch Workspace -
  • + */}
  • {
    -

    Manage Service

    {/* Service Header */} diff --git a/src/hooks/useAttendance.js b/src/hooks/useAttendance.js index a334c0c6..cbee0b8f 100644 --- a/src/hooks/useAttendance.js +++ b/src/hooks/useAttendance.js @@ -12,38 +12,9 @@ import { setDefaultDateRange } from "../slices/localVariablesSlice"; // ----------------------------Query----------------------------- -// export const useAttendance = (projectId) => { -// const dispatch = useDispatch() -// const { -// data: attendance = [], -// isLoading: loading, -// error, -// refetch: recall, -// isFetching -// } = useQuery({ -// queryKey: ["attendance", projectId], -// queryFn: async () => { -// const response = await AttendanceRepository.getAttendance(projectId); -// return response.data; -// }, -// enabled: !!projectId, -// onError: (error) => { -// showToast(error.message || "Error while fetching Attendance", "error"); -// }, -// }); - -// return { -// attendance, -// loading, -// error, -// recall, -// isFetching -// }; -// }; - export const useAttendance = (projectId, organizationId, includeInactive = false, date = null) => { const dispatch = useDispatch(); - +// queryKey: ["attendance", projectId, organizationId, includeInactive, date], const { data: attendance = [], isLoading: loading, @@ -51,7 +22,7 @@ export const useAttendance = (projectId, organizationId, includeInactive = false refetch: recall, isFetching, } = useQuery({ - queryKey: ["attendance", projectId, organizationId, includeInactive, date], // include filters in cache key + queryKey: ["attendance", projectId ], queryFn: async () => { const response = await AttendanceRepository.getAttendance( projectId, @@ -61,7 +32,7 @@ export const useAttendance = (projectId, organizationId, includeInactive = false ); return response.data; }, - enabled: !!projectId, // only run if projectId exists + enabled: !!projectId, onError: (error) => { showToast(error.message || "Error while fetching Attendance", "error"); }, @@ -142,31 +113,6 @@ export const useAttendanceByEmployee = (employeeId, fromDate, toDate) => { }); }; -// export const useRegularizationRequests = (projectId) => { -// const { -// data: regularizes = [], -// isLoading: loading, -// error, -// refetch, -// } = useQuery({ -// queryKey: ["regularizedList", projectId], -// queryFn: async () => { -// const response = await AttendanceRepository.getRegularizeList(projectId); -// return response.data; -// }, -// enabled: !!projectId, -// onError: (error) => { -// showToast(error.message || "Error while fetching Regularization Requests", "error"); -// }, -// }); - -// return { -// regularizes, -// loading, -// error, -// refetch, -// }; -// }; export const useRegularizationRequests = (projectId, organizationId, IncludeInActive = false) => { const dispatch = useDispatch(); @@ -218,10 +164,11 @@ export const useMarkAttendance = () => { emp.employeeId === data.employeeId ? { ...emp, ...data } : emp ); }); + // queryClient.invalidateQueries({queryKey:["attendance"]}) }else if(variables.forWhichTab == 2){ - // queryClient.invalidateQueries({ - // queryKey: ["attendanceLogs"], - // }); + queryClient.invalidateQueries({ + queryKey: ["attendanceLogs"], + }); queryClient.setQueryData(["attendanceLogs",selectedProject,selectedDateRange.startDate,selectedDateRange.endDate], (oldData) => { if (!oldData) return oldData; return oldData.map((record) => diff --git a/src/pages/Activities/AttendancePage.jsx b/src/pages/Activities/AttendancePage.jsx index 4cd5956a..36414fe5 100644 --- a/src/pages/Activities/AttendancePage.jsx +++ b/src/pages/Activities/AttendancePage.jsx @@ -174,7 +174,7 @@ const AttendancePage = () => { {/* Search + Organization filter */}
    {/* Organization Dropdown */} - + */} {/* Search Input */} { {ViewTeamMember ? ( //
    -
    +
    { - No Data Found +
    + No Employeee Found +
    ) : null} diff --git a/src/pages/project/ProjectPage.jsx b/src/pages/project/ProjectPage.jsx index 4fdccc30..6d534c59 100644 --- a/src/pages/project/ProjectPage.jsx +++ b/src/pages/project/ProjectPage.jsx @@ -181,7 +181,7 @@ const ProjectPage = () => {
    - {HasManageProject && ( )} + )} */}