From f19b9037e7a5b27520a23e724f0c512b03b78361 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Fri, 7 Nov 2025 12:56:20 +0530 Subject: [PATCH] When document filter is now auto closed at we are go to next tab or component. --- .../Documents/DocumentFilterPanel.jsx | 420 +++++++++--------- 1 file changed, 213 insertions(+), 207 deletions(-) diff --git a/src/components/Documents/DocumentFilterPanel.jsx b/src/components/Documents/DocumentFilterPanel.jsx index edc613e1..04f54956 100644 --- a/src/components/Documents/DocumentFilterPanel.jsx +++ b/src/components/Documents/DocumentFilterPanel.jsx @@ -13,230 +13,236 @@ import { useParams } from "react-router-dom"; const DocumentFilterPanel = forwardRef( ({ entityTypeId, onApply, setFilterdata }, ref) => { - const [resetKey, setResetKey] = useState(0); - const { status } = useParams(); + const [resetKey, setResetKey] = useState(0); + const { status } = useParams(); - const { data, isError, isLoading, error } = - useDocumentFilterEntities(entityTypeId); + const { data, isError, isLoading, error } = + useDocumentFilterEntities(entityTypeId); - //changes + useEffect(() => { + return () => { + closePanel(); + }; + }, []); - const dynamicDocumentFilterDefaultValues = useMemo(() => { - return { - ...DocumentFilterDefaultValues, - uploadedByIds: DocumentFilterDefaultValues.uploadedByIds || [], - documentCategoryIds: DocumentFilterDefaultValues.documentCategoryIds || [], - documentTypeIds: DocumentFilterDefaultValues.documentTypeIds || [], - documentTagIds: DocumentFilterDefaultValues.documentTagIds || [], - startDate: DocumentFilterDefaultValues.startDate, - endDate: DocumentFilterDefaultValues.endDate, + //changes + + const dynamicDocumentFilterDefaultValues = useMemo(() => { + return { + ...DocumentFilterDefaultValues, + uploadedByIds: DocumentFilterDefaultValues.uploadedByIds || [], + documentCategoryIds: DocumentFilterDefaultValues.documentCategoryIds || [], + documentTypeIds: DocumentFilterDefaultValues.documentTypeIds || [], + documentTagIds: DocumentFilterDefaultValues.documentTagIds || [], + startDate: DocumentFilterDefaultValues.startDate, + endDate: DocumentFilterDefaultValues.endDate, + }; + + }, [status]); + + const methods = useForm({ + resolver: zodResolver(DocumentFilterSchema), + defaultValues: dynamicDocumentFilterDefaultValues, + }); + + const { handleSubmit, reset, setValue, watch } = methods; + + // Watch values from form + const isUploadedAt = watch("isUploadedAt"); + const isVerified = watch("isVerified"); + + // Close the offcanvas (bootstrap specific) + const closePanel = () => { + document.querySelector(".offcanvas.show .btn-close")?.click(); }; - }, [status]); + useImperativeHandle(ref, () => ({ + resetFieldValue: (name, value) => { + if (value !== undefined) { + setValue(name, value); + } else { + reset({ ...methods.getValues(), [name]: DocumentFilterDefaultValues[name] }); + } + }, + getValues: methods.getValues, // optional, to read current filter state + })); - const methods = useForm({ - resolver: zodResolver(DocumentFilterSchema), - defaultValues: dynamicDocumentFilterDefaultValues, - }); - - const { handleSubmit, reset, setValue, watch } = methods; - - // Watch values from form - const isUploadedAt = watch("isUploadedAt"); - const isVerified = watch("isVerified"); - - // Close the offcanvas (bootstrap specific) - const closePanel = () => { - document.querySelector(".offcanvas.show .btn-close")?.click(); - }; - - useImperativeHandle(ref, () => ({ - resetFieldValue: (name, value) => { - if (value !== undefined) { - setValue(name, value); - } else { - reset({ ...methods.getValues(), [name]: DocumentFilterDefaultValues[name] }); + //changes + useEffect(() => { + if (data && setFilterdata) { + setFilterdata(data); } - }, - getValues: methods.getValues, // optional, to read current filter state - })); + }, [data, setFilterdata]); - //changes - useEffect(() => { - if (data && setFilterdata) { - setFilterdata(data); - } - }, [data, setFilterdata]); + const onSubmit = (values) => { + onApply({ + ...values, + startDate: values.startDate + ? moment.utc(values.startDate, "DD-MM-YYYY").toISOString() + : null, + endDate: values.endDate + ? moment.utc(values.endDate, "DD-MM-YYYY").toISOString() + : null, + }); + // closePanel(); + }; - const onSubmit = (values) => { - onApply({ - ...values, - startDate: values.startDate - ? moment.utc(values.startDate, "DD-MM-YYYY").toISOString() - : null, - endDate: values.endDate - ? moment.utc(values.endDate, "DD-MM-YYYY").toISOString() - : null, - }); - // closePanel(); - }; + const onClear = () => { + reset(DocumentFilterDefaultValues); + setResetKey((prev) => prev + 1); + onApply(DocumentFilterDefaultValues); + // closePanel(); + }; - const onClear = () => { - reset(DocumentFilterDefaultValues); - setResetKey((prev) => prev + 1); - onApply(DocumentFilterDefaultValues); - // closePanel(); - }; + if (isLoading) return
Loading...
; + if (isError) + return
Error: {error?.message || "Something went wrong!"}
; - if (isLoading) return
Loading...
; - if (isError) - return
Error: {error?.message || "Something went wrong!"}
; - - const { - uploadedBy = [], - documentCategory = [], - documentType = [], - documentTag = [], - } = data?.data || {}; + const { + uploadedBy = [], + documentCategory = [], + documentType = [], + documentTag = [], + } = data?.data || {}; - return ( - -
- {/* Date Range Section */} -
-
- -
- - + return ( + + + {/* Date Range Section */} +
+
+ +
+ + +
+
+ + +
+ + {/* Dropdown Filters */} +
+ + + + +
+ + {/* Status Filter */} +
+ +
+ + + + +
- -
- - {/* Dropdown Filters */} -
- - - - -
- - {/* Status Filter */} -
- -
- - - - - + {/* Footer Buttons */} +
+ +
-
- - {/* Footer Buttons */} -
- - -
- - - ); -}); + + + ); + }); export default DocumentFilterPanel;