From d75296ffe80ff6c3f51f19d25b4f2402aec0d814 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Mon, 13 Oct 2025 14:51:47 +0530 Subject: [PATCH] Filter Sidebar Should Auto-Close When Navigating to Another Page --- .../Documents/DocumentFilterPanel.jsx | 23 +++++++++++++------ src/pages/Directory/ContactFilterPanel.jsx | 19 ++++++++++++--- src/pages/Directory/NoteFilterPanel.jsx | 11 +++++++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/components/Documents/DocumentFilterPanel.jsx b/src/components/Documents/DocumentFilterPanel.jsx index 15a2cbf1..581277e8 100644 --- a/src/components/Documents/DocumentFilterPanel.jsx +++ b/src/components/Documents/DocumentFilterPanel.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import { useDocumentFilterEntities } from "../../hooks/useDocument"; import { FormProvider, useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -9,9 +9,11 @@ import { import { DateRangePicker1 } from "../common/DateRangePicker"; import SelectMultiple from "../common/SelectMultiple"; import moment from "moment"; +import { useLocation } from "react-router-dom"; const DocumentFilterPanel = ({ entityTypeId, onApply }) => { const [resetKey, setResetKey] = useState(0); + const location = useLocation(); const { data, isError, isLoading, error } = useDocumentFilterEntities(entityTypeId); @@ -52,6 +54,13 @@ const DocumentFilterPanel = ({ entityTypeId, onApply }) => { closePanel(); }; + // Close popup when navigating to another component + useEffect(() => { + return () => { + closePanel(); + }; + }, []); + if (isLoading) return
Loading...
; if (isError) return
Error: {error?.message || "Something went wrong!"}
; @@ -63,6 +72,8 @@ const DocumentFilterPanel = ({ entityTypeId, onApply }) => { documentTag = [], } = data?.data || {}; + + return (
@@ -73,18 +84,16 @@ const DocumentFilterPanel = ({ entityTypeId, onApply }) => {