diff --git a/src/Hooks/WithDrawer.tsx b/src/Hooks/WithDrawer.tsx index 0d81ba9..4373fe1 100644 --- a/src/Hooks/WithDrawer.tsx +++ b/src/Hooks/WithDrawer.tsx @@ -19,7 +19,7 @@ const WithDrawer: React.FC = ({ children,title ="Basic Drawer", return ( <> setOpen(false)} diff --git a/src/Layout/Dashboard/SelectField.tsx b/src/Layout/Dashboard/SelectField.tsx new file mode 100644 index 0000000..65df8cb --- /dev/null +++ b/src/Layout/Dashboard/SelectField.tsx @@ -0,0 +1,52 @@ +import { Select } from 'antd'; +import React, { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { useLocation, useNavigate } from 'react-router-dom'; + +const SelectField = ({ selectBy, submiteBy, lebel, option }: any) => { + const [searchQuery, setSearchQuery] = useState(''); + const location = useLocation(); + const navigate = useNavigate(); + const [t] = useTranslation(); + + useEffect(() => { + const searchParams = new URLSearchParams(location.search); + setSearchQuery(searchParams.get('search') || ''); + }, []); + + const handleSearchChange = (value: any) => { + if (value || value !== "") { + navigate(`${location.pathname}?${selectBy}=${value}`, { replace: true }); + } else { + const params = new URLSearchParams(location.search); + params.delete(selectBy ?? "search"); + navigate(`${location.pathname}?${params.toString()}`, { replace: true }); + } + }; + + const handleSelectChange = (value: any) => { + if (value) { + console.log(`${location.pathname}?${submiteBy}=${value}`); + + navigate(`${location.pathname}?${submiteBy}=${value}`, { replace: true }); + } +} + + return ( +
+