From b23518f796f79b5f5e40a2cc7e6c82cefcf88275 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Wed, 15 Oct 2025 15:58:59 +0530 Subject: [PATCH] Changes in expense filter panel. --- .../Expenses/ExpenseFilterPanel.jsx | 13 +- src/components/Layout/Header.jsx | 138 +++++++++--------- src/router/AppRoutes.jsx | 1 + 3 files changed, 74 insertions(+), 78 deletions(-) diff --git a/src/components/Expenses/ExpenseFilterPanel.jsx b/src/components/Expenses/ExpenseFilterPanel.jsx index 0ec19ce6..3f0085c3 100644 --- a/src/components/Expenses/ExpenseFilterPanel.jsx +++ b/src/components/Expenses/ExpenseFilterPanel.jsx @@ -43,7 +43,7 @@ const ExpenseFilterPanel = forwardRef(({ onApply, handleGroupBy, setFilterdata } return { ...defaultFilter, statusIds: status ? [status] : defaultFilter.statusIds || [], - projectIds: selectedProjectId ? [selectedProjectId] : [], + projectIds: defaultFilter.projectIds || [], createdByIds: defaultFilter.createdByIds || [], paidById: defaultFilter.paidById || [], ExpenseTypeIds: defaultFilter.ExpenseTypeIds || [], @@ -51,7 +51,7 @@ const ExpenseFilterPanel = forwardRef(({ onApply, handleGroupBy, setFilterdata } startDate: defaultFilter.startDate, endDate: defaultFilter.endDate, }; - }, [status,selectedProjectId]); + }, [status]); const methods = useForm({ resolver: zodResolver(SearchSchema), @@ -119,12 +119,12 @@ const ExpenseFilterPanel = forwardRef(({ onApply, handleGroupBy, setFilterdata } const [appliedStatusId, setAppliedStatusId] = useState(null); useEffect(() => { - if (!status) return; + if (!status || !data) return; - if (status !== appliedStatusId && data) { + if (status !== appliedStatusId) { const filterWithStatus = { ...dynamicDefaultFilter, - projectIds: selectedProjectId ? [selectedProjectId] : [], // ✅ include project ID + projectIds: selectedProjectId ? [selectedProjectId] : dynamicDefaultFilter.projectIds || [], startDate: dynamicDefaultFilter.startDate ? moment.utc(dynamicDefaultFilter.startDate, "DD-MM-YYYY").toISOString() : undefined, @@ -135,7 +135,6 @@ const ExpenseFilterPanel = forwardRef(({ onApply, handleGroupBy, setFilterdata } onApply(filterWithStatus); handleGroupBy(selectedGroup.id); - setAppliedStatusId(status); } }, [ @@ -146,7 +145,7 @@ const ExpenseFilterPanel = forwardRef(({ onApply, handleGroupBy, setFilterdata } handleGroupBy, selectedGroup.id, appliedStatusId, - selectedProjectId, // ✅ added dependency + selectedProjectId, // ✅ Added dependency ]); diff --git a/src/components/Layout/Header.jsx b/src/components/Layout/Header.jsx index ae72921a..2a459b94 100644 --- a/src/components/Layout/Header.jsx +++ b/src/components/Layout/Header.jsx @@ -26,27 +26,23 @@ const Header = () => { const dispatch = useDispatch(); const { data, loading } = useMaster(); const navigate = useNavigate(); - const {onOpen} = useAuthModal() - const { onOpen:changePass } = useModal("ChangePassword"); + const { onOpen } = useAuthModal() + const { onOpen: changePass } = useModal("ChangePassword"); const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT); - const { mutate : logout,isPending:logouting} = useLogout() + const { mutate: logout, isPending: logouting } = useLogout() const isDashboardPath = /^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname); const isProjectPath = /^\/projects$/.test(location.pathname); const showProjectDropdown = (pathname) => { - const isDirectoryPath = /^\/directory$/.test(pathname); + // Paths where we DON'T want to show the project dropdown + const excludedPaths = ["/directory", "/expenses", "/employee"]; - // const isProfilePage = /^\/employee$/.test(location.pathname); - const isProfilePage = - /^\/employee\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test( - pathname - ); - const isExpensePage = /^\/expenses$/.test(pathname); - - return !(isDirectoryPath || isProfilePage || isExpensePage); + // Check if pathname starts with any of the excluded paths + return !excludedPaths.some((path) => pathname.startsWith(path)); }; + const allowedProjectStatusIds = [ "603e994b-a27f-4e5d-a251-f3d69b0498ba", "cdad86aa-8a56-4ff4-b633-9c629057dfef", @@ -59,9 +55,9 @@ const Header = () => { return role ? role.name : "User"; }; - - + + const handleProfilePage = () => { navigate(`/employee/${profile?.employeeInfo?.id}`); @@ -74,8 +70,8 @@ const Header = () => { const projectsForDropdown = isDashboardPath ? projectNames : projectNames?.filter((project) => - allowedProjectStatusIds.includes(project.projectStatusId) - ); + allowedProjectStatusIds.includes(project.projectStatusId) + ); let currentProjectDisplayName; if (projectLoading) { @@ -191,63 +187,63 @@ const Header = () => { >
{showProjectDropdown(location.pathname) && ( -
- -
- {shouldShowDropdown ? ( - - ) : ( - - {currentProjectDisplayName} - - )} - - {shouldShowDropdown && - projectsForDropdown && - projectsForDropdown.length > 0 && ( -
    + +
    + {shouldShowDropdown ? ( + - - )} - {[...projectsForDropdown] - .sort((a, b) => a?.name?.localeCompare(b.name)) - .map((project) => ( -
  • + {currentProjectDisplayName} + + ) : ( + + {currentProjectDisplayName} + + )} + + {shouldShowDropdown && + projectsForDropdown && + projectsForDropdown.length > 0 && ( +
      + {isDashboardPath && ( +
    • - ))} -
    - )} + )} + {[...projectsForDropdown] + .sort((a, b) => a?.name?.localeCompare(b.name)) + .map((project) => ( +
  • + +
  • + ))} +
+ )} +
-
- )} + )} diff --git a/src/router/AppRoutes.jsx b/src/router/AppRoutes.jsx index 025b05b8..37904f98 100644 --- a/src/router/AppRoutes.jsx +++ b/src/router/AppRoutes.jsx @@ -95,6 +95,7 @@ const router = createBrowserRouter( { path: "/activities/reports", element: }, { path: "/gallary", element: }, { path: "/expenses/:status?/:project?", element: }, + { path: "/expenses", element: }, { path: "/masters", element: }, { path: "/tenants", element: }, { path: "/tenants/new-tenant", element: },