refactor: refactored filters
This commit is contained in:
@ -1,10 +1,9 @@
|
||||
import { isEqual } from "lodash";
|
||||
import { useForm, UseFormReturnType } from "@mantine/form";
|
||||
import { useDebouncedValue } from "@mantine/hooks";
|
||||
import { BoardSchema, SortDir, StatusSchema } from "@/lib/client";
|
||||
|
||||
export type DealsFiltersForm = {
|
||||
id?: number;
|
||||
id: number | null;
|
||||
name: string;
|
||||
board: BoardSchema | null;
|
||||
status: StatusSchema | null;
|
||||
@ -13,15 +12,13 @@ export type DealsFiltersForm = {
|
||||
};
|
||||
|
||||
type ReturnType = {
|
||||
debouncedId: number | undefined;
|
||||
debouncedName: string;
|
||||
form: UseFormReturnType<DealsFiltersForm>;
|
||||
isChangedFilters: boolean;
|
||||
};
|
||||
|
||||
const useDealsFilters = (): ReturnType => {
|
||||
const initialValues = {
|
||||
id: undefined,
|
||||
id: null,
|
||||
board: null,
|
||||
status: null,
|
||||
name: "",
|
||||
@ -35,12 +32,7 @@ const useDealsFilters = (): ReturnType => {
|
||||
|
||||
const isChangedFilters = !isEqual(form.values, initialValues);
|
||||
|
||||
const [debouncedId] = useDebouncedValue(form.values.id, 300);
|
||||
const [debouncedName] = useDebouncedValue(form.values.name, 300);
|
||||
|
||||
return {
|
||||
debouncedId,
|
||||
debouncedName,
|
||||
form,
|
||||
isChangedFilters,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user