From ce2b31e3f9901e705a3efb0bbf5fa1fbee9339e5 Mon Sep 17 00:00:00 2001 From: KarimAldeen Date: Wed, 27 Mar 2024 10:44:47 +0300 Subject: [PATCH] #23 --- src/Hooks/WithDrawer.tsx | 2 +- src/Layout/Dashboard/SelectField.tsx | 52 ++++++++++++++++++++++++++++ src/Layout/app/Header.tsx | 2 +- src/Layout/app/WithDrawer.tsx | 5 ++- src/Pages/Products/ProductsPage.tsx | 17 +++++++-- src/Styles/Layout/Layout.scss | 29 ++++++++++++++-- src/api/helper/ueGetPagination.tsx | 50 ++++++++++++++------------ src/api/helper/useGetWithFillter.ts | 22 ++++++++++++ src/api/product.ts | 2 +- 9 files changed, 147 insertions(+), 34 deletions(-) create mode 100644 src/Layout/Dashboard/SelectField.tsx create mode 100644 src/api/helper/useGetWithFillter.ts 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 ( +
+