Compare commits
4 Commits
491e3a88bd
...
08bd2d245d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08bd2d245d | ||
|
|
089160a4ae | ||
|
|
d56c4a06bf | ||
|
|
1eccab7434 |
|
|
@ -1,7 +1,8 @@
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
interface FilterState {
|
interface FilterState {
|
||||||
filterState: any[];
|
filterState: {};
|
||||||
|
InitialValue: {};
|
||||||
setFilterState: (data: any) => void;
|
setFilterState: (data: any) => void;
|
||||||
clearFilterState: () => void;
|
clearFilterState: () => void;
|
||||||
setWithOldValue: (data: any) => void;
|
setWithOldValue: (data: any) => void;
|
||||||
|
|
@ -9,15 +10,14 @@ interface FilterState {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useFilterState = create<FilterState>((set, get) => ({
|
export const useFilterState = create<FilterState>((set, get) => ({
|
||||||
filterState: [],
|
filterState: {},
|
||||||
|
InitialValue:{name:""},
|
||||||
setFilterState: (data) => set(() => ({ filterState: data })),
|
setFilterState: (data) => set(() => ({ filterState: data })),
|
||||||
clearFilterState: () => set(() => ({ filterState: [] })),
|
clearFilterState: () => set(() => ({ filterState: [] })),
|
||||||
setWithOldValue: (data) =>
|
setWithOldValue: (data) =>
|
||||||
set((state) => ({ filterState: [...state.filterState, data] })),
|
set((state) => ({ filterState: {...state.filterState, data} })),
|
||||||
setInitialValue: (data) => {
|
setInitialValue: (data) => {
|
||||||
if (get().filterState.length < 1) {
|
set(() => ({ InitialValue: data }));
|
||||||
set(() => ({ filterState: data }));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { ReactNode, useEffect, useState } from "react";
|
import React, { ReactNode, useEffect, useState } from "react";
|
||||||
import { FaFilter } from "react-icons/fa";
|
import { FaFilter } from "react-icons/fa";
|
||||||
import { Form, Formik, FormikConfig, FormikHelpers } from "formik";
|
import { Form, Formik, FormikConfig, FormikHelpers, useFormikContext } from "formik";
|
||||||
import { Button, ButtonProps, Divider, Modal } from "antd";
|
import { Button, ButtonProps, Divider, Modal } from "antd";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useModalState } from "./Modal";
|
import { useModalState } from "./Modal";
|
||||||
|
|
@ -8,7 +8,6 @@ import { useFilterState } from "./FilterState";
|
||||||
import { ModalEnum } from "../../../enums/Model";
|
import { ModalEnum } from "../../../enums/Model";
|
||||||
import { QueryStatusEnum } from "../../../enums/QueryStatus";
|
import { QueryStatusEnum } from "../../../enums/QueryStatus";
|
||||||
import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
|
import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
|
||||||
import FormikForm from "../../../Layout/Dashboard/FormikForm";
|
|
||||||
import SpinContainer from "../../Layout/SpinContainer";
|
import SpinContainer from "../../Layout/SpinContainer";
|
||||||
import { TbFlagCancel } from "react-icons/tb";
|
import { TbFlagCancel } from "react-icons/tb";
|
||||||
import { XFilled } from "@ant-design/icons";
|
import { XFilled } from "@ant-design/icons";
|
||||||
|
|
@ -36,12 +35,14 @@ interface SubmitButtonProps extends Omit<ButtonProps, "loading"> {}
|
||||||
|
|
||||||
const useFilter = () => {
|
const useFilter = () => {
|
||||||
const { setIsOpen, isOpen } = useModalState((state) => state);
|
const { setIsOpen, isOpen } = useModalState((state) => state);
|
||||||
const { filterState, setFilterState, clearFilterState } = useFilterState();
|
const { filterState, setFilterState, clearFilterState ,InitialValue} = useFilterState();
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const [formValues, setFormValues] = useState({});
|
const [formValues, setFormValues] = useState({});
|
||||||
|
const formik = useFormikContext()
|
||||||
// Define the type for the callback
|
// Define the type for the callback
|
||||||
type SubmitCallback = () => void;
|
type SubmitCallback = () => void;
|
||||||
|
// console.log(formik?.values);
|
||||||
|
// console.log(InitialValue);
|
||||||
|
|
||||||
const FilterButton = () => {
|
const FilterButton = () => {
|
||||||
const handleState = () => {
|
const handleState = () => {
|
||||||
|
|
@ -66,6 +67,9 @@ const useFilter = () => {
|
||||||
setFilterState({})
|
setFilterState({})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const FilterBody = ({
|
const FilterBody = ({
|
||||||
onSubmit,
|
onSubmit,
|
||||||
children,
|
children,
|
||||||
|
|
@ -100,6 +104,7 @@ const useFilter = () => {
|
||||||
setFormValues({});
|
setFormValues({});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOpen = () => {
|
const handleOpen = () => {
|
||||||
setIsOpen(true);
|
setIsOpen(true);
|
||||||
// setObjectToEdit({});
|
// setObjectToEdit({});
|
||||||
|
|
@ -122,11 +127,15 @@ const useFilter = () => {
|
||||||
<Formik
|
<Formik
|
||||||
enableReinitialize={true}
|
enableReinitialize={true}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
initialValues={formValues}
|
initialValues={{}}
|
||||||
onReset={handleCancel}
|
onReset={handleCancel}
|
||||||
{...formikProps}
|
{...formikProps}
|
||||||
>
|
>
|
||||||
|
{(formik) => {
|
||||||
|
|
||||||
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<header> {t("models.filter")} <FaXmark onClick={()=>handleCancel(true)} /> </header>
|
<header> {t("models.filter")} <FaXmark onClick={()=>handleCancel(true)} /> </header>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
@ -136,6 +145,9 @@ const useFilter = () => {
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
|
||||||
</Formik>
|
</Formik>
|
||||||
</Modal>
|
</Modal>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import useFormField from "../../../Hooks/useFormField";
|
||||||
import { Field } from "formik";
|
import { Field } from "formik";
|
||||||
import { ValidationFieldLabel } from "../components/ValidationFieldLabel";
|
import { ValidationFieldLabel } from "../components/ValidationFieldLabel";
|
||||||
import { ValidationFieldContainer } from "../components/ValidationFieldContainer";
|
import { ValidationFieldContainer } from "../components/ValidationFieldContainer";
|
||||||
import { FieldProps } from "../utils/types";
|
|
||||||
|
|
||||||
const Default = ({
|
const Default = ({
|
||||||
name,
|
name,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import { translateOptions } from "../../utils/translatedOptions";
|
||||||
import { search_array } from "../../Routes";
|
import { search_array } from "../../Routes";
|
||||||
import PaginationColumn from "../../Components/Filter/PaginationColumn";
|
import PaginationColumn from "../../Components/Filter/PaginationColumn";
|
||||||
import OrderBySelect from "../../Components/Filter/OrderBySelect";
|
import OrderBySelect from "../../Components/Filter/OrderBySelect";
|
||||||
import LayoutFilterModal from "./LayoutFilterModal";
|
|
||||||
import { BiFilterAlt } from "react-icons/bi";
|
import { BiFilterAlt } from "react-icons/bi";
|
||||||
import { MdKeyboardArrowDown } from "react-icons/md";
|
import { MdKeyboardArrowDown } from "react-icons/md";
|
||||||
import SearchField from "../../Components/DataTable/SearchField";
|
import SearchField from "../../Components/DataTable/SearchField";
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ interface FormValues {
|
||||||
interface FormikFormProps {
|
interface FormikFormProps {
|
||||||
handleSubmit: (values: any) => void;
|
handleSubmit: (values: any) => void;
|
||||||
initialValues: FormValues;
|
initialValues: FormValues;
|
||||||
validationSchema: any;
|
validationSchema?: any;
|
||||||
title?: string;
|
title?: string;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
ButtonName?: string;
|
ButtonName?: string;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import ValidationField from "../../../../Components/ValidationField/ValidationField";
|
import ValidationField from "../../../../Components/ValidationField/ValidationField";
|
||||||
import { Col, Row } from "reactstrap";
|
import { Col, Row } from "reactstrap";
|
||||||
|
import { useFormikContext } from "formik";
|
||||||
|
|
||||||
const FilterForm = () => {
|
const FilterForm = () => {
|
||||||
|
const formik = useFormikContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Row>
|
<Row>
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ interface ModelState {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useObjectToEdit = create<ModelState>((set) => ({
|
export const useObjectToEdit = create<ModelState>((set) => ({
|
||||||
objectToEdit: null,
|
c: null,
|
||||||
setObjectToEdit: (data) => set(() => ({ objectToEdit: data })),
|
setObjectToEdit: (data) => set(() => ({ objectToEdit: data })),
|
||||||
OldObjectToEdit: null,
|
OldObjectToEdit: null,
|
||||||
setOldObjectToEdit: (data) => set(() => ({ OldObjectToEdit: data })),
|
setOldObjectToEdit: (data) => set(() => ({ OldObjectToEdit: data })),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user