Merge pull request 'Filter Sidebar Should Auto-Close When Navigating to Another Page' (#478) from Kartik_Bug#1450 into Issues_Oct_main_2W
Reviewed-on: #478 merged
This commit is contained in:
commit
18a3b8a85b
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useDocumentFilterEntities } from "../../hooks/useDocument";
|
import { useDocumentFilterEntities } from "../../hooks/useDocument";
|
||||||
import { FormProvider, useForm } from "react-hook-form";
|
import { FormProvider, useForm } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
@ -9,9 +9,11 @@ import {
|
|||||||
import { DateRangePicker1 } from "../common/DateRangePicker";
|
import { DateRangePicker1 } from "../common/DateRangePicker";
|
||||||
import SelectMultiple from "../common/SelectMultiple";
|
import SelectMultiple from "../common/SelectMultiple";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
const DocumentFilterPanel = ({ entityTypeId, onApply }) => {
|
const DocumentFilterPanel = ({ entityTypeId, onApply }) => {
|
||||||
const [resetKey, setResetKey] = useState(0);
|
const [resetKey, setResetKey] = useState(0);
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const { data, isError, isLoading, error } =
|
const { data, isError, isLoading, error } =
|
||||||
useDocumentFilterEntities(entityTypeId);
|
useDocumentFilterEntities(entityTypeId);
|
||||||
@ -52,6 +54,13 @@ const DocumentFilterPanel = ({ entityTypeId, onApply }) => {
|
|||||||
closePanel();
|
closePanel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Close popup when navigating to another component
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
closePanel();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (isLoading) return <div>Loading...</div>;
|
if (isLoading) return <div>Loading...</div>;
|
||||||
if (isError)
|
if (isError)
|
||||||
return <div>Error: {error?.message || "Something went wrong!"}</div>;
|
return <div>Error: {error?.message || "Something went wrong!"}</div>;
|
||||||
@ -63,6 +72,8 @@ const DocumentFilterPanel = ({ entityTypeId, onApply }) => {
|
|||||||
documentTag = [],
|
documentTag = [],
|
||||||
} = data?.data || {};
|
} = data?.data || {};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
@ -73,18 +84,16 @@ const DocumentFilterPanel = ({ entityTypeId, onApply }) => {
|
|||||||
<div className="d-inline-flex border rounded-pill overflow-hidden shadow-none">
|
<div className="d-inline-flex border rounded-pill overflow-hidden shadow-none">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`btn px-2 py-1 rounded-0 text-tiny ${
|
className={`btn px-2 py-1 rounded-0 text-tiny ${isUploadedAt ? "active btn-secondary text-white" : ""
|
||||||
isUploadedAt ? "active btn-secondary text-white" : ""
|
}`}
|
||||||
}`}
|
|
||||||
onClick={() => setValue("isUploadedAt", true)}
|
onClick={() => setValue("isUploadedAt", true)}
|
||||||
>
|
>
|
||||||
Uploaded On
|
Uploaded On
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`btn px-2 py-1 rounded-0 text-tiny ${
|
className={`btn px-2 py-1 rounded-0 text-tiny ${!isUploadedAt ? "active btn-secondary text-white" : ""
|
||||||
!isUploadedAt ? "active btn-secondary text-white" : ""
|
}`}
|
||||||
}`}
|
|
||||||
onClick={() => setValue("isUploadedAt", false)}
|
onClick={() => setValue("isUploadedAt", false)}
|
||||||
>
|
>
|
||||||
Updated On
|
Updated On
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { FormProvider, useForm } from "react-hook-form";
|
import { FormProvider, useForm } from "react-hook-form";
|
||||||
import {
|
import {
|
||||||
contactsFilter,
|
contactsFilter,
|
||||||
@ -8,11 +8,14 @@ import {
|
|||||||
import { useContactFilter } from "../../hooks/useDirectory";
|
import { useContactFilter } from "../../hooks/useDirectory";
|
||||||
import { ExpenseFilterSkeleton } from "../../components/Expenses/ExpenseSkeleton";
|
import { ExpenseFilterSkeleton } from "../../components/Expenses/ExpenseSkeleton";
|
||||||
import SelectMultiple from "../../components/common/SelectMultiple";
|
import SelectMultiple from "../../components/common/SelectMultiple";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
const ContactFilterPanel = ({ onApply, clearFilter }) => {
|
const ContactFilterPanel = ({ onApply, clearFilter }) => {
|
||||||
const { data, isError, isLoading, error, isFetched, isFetching } =
|
const { data, isError, isLoading, error, isFetched, isFetching } =
|
||||||
useContactFilter();
|
useContactFilter();
|
||||||
|
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const methods = useForm({
|
const methods = useForm({
|
||||||
resolver: zodResolver(contactsFilter),
|
resolver: zodResolver(contactsFilter),
|
||||||
defaultValues: defaultContactFilter,
|
defaultValues: defaultContactFilter,
|
||||||
@ -30,14 +33,24 @@ const ContactFilterPanel = ({ onApply, clearFilter }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
reset(defaultContactFilter);
|
reset(defaultContactFilter);
|
||||||
onApply(defaultContactFilter);
|
onApply(defaultContactFilter);
|
||||||
closePanel();
|
closePanel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
closePanel();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (isLoading || isFetching) return <ExpenseFilterSkeleton />;
|
if (isLoading || isFetching) return <ExpenseFilterSkeleton />;
|
||||||
if (isError && isFetched)
|
if (isError && isFetched)
|
||||||
return <div>Something went wrong Here- {error.message} </div>;
|
return <div>Something went wrong Here- {error.message} </div>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<form onSubmit={handleSubmit(onSubmit)} className="p-2 text-start">
|
<form onSubmit={handleSubmit(onSubmit)} className="p-2 text-start">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { FormProvider, useForm } from "react-hook-form";
|
import { FormProvider, useForm } from "react-hook-form";
|
||||||
import {
|
import {
|
||||||
defaultNotesFilter,
|
defaultNotesFilter,
|
||||||
@ -8,11 +8,18 @@ import {
|
|||||||
import { useContactFilter, useNoteFilter } from "../../hooks/useDirectory";
|
import { useContactFilter, useNoteFilter } from "../../hooks/useDirectory";
|
||||||
import { ExpenseFilterSkeleton } from "../../components/Expenses/ExpenseSkeleton";
|
import { ExpenseFilterSkeleton } from "../../components/Expenses/ExpenseSkeleton";
|
||||||
import SelectMultiple from "../../components/common/SelectMultiple";
|
import SelectMultiple from "../../components/common/SelectMultiple";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
const NoteFilterPanel = ({ onApply, clearFilter }) => {
|
const NoteFilterPanel = ({ onApply, clearFilter }) => {
|
||||||
const { data, isError, isLoading, error, isFetched, isFetching } =
|
const { data, isError, isLoading, error, isFetched, isFetching } =
|
||||||
useNoteFilter();
|
useNoteFilter();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
closePanel();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
const methods = useForm({
|
const methods = useForm({
|
||||||
resolver: zodResolver(notesFilter),
|
resolver: zodResolver(notesFilter),
|
||||||
defaultValues: defaultNotesFilter,
|
defaultValues: defaultNotesFilter,
|
||||||
@ -31,7 +38,7 @@ const NoteFilterPanel = ({ onApply, clearFilter }) => {
|
|||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
reset(defaultNotesFilter);
|
reset(defaultNotesFilter);
|
||||||
onApply(defaultNotesFilter);
|
onApply(defaultNotesFilter);
|
||||||
closePanel();
|
closePanel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user