From 9af21acb90ed1b83c7b95092ee94924a1f8f250a Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sun, 4 Jan 2026 12:04:03 +0330 Subject: [PATCH] restaurant list fix + pager --- src/pages/dmenu/hooks/useIconData.ts | 6 +++--- src/pages/dmenu/restaurant/List.tsx | 18 +++++++++++++++--- src/pages/dmenu/service/IconService.ts | 9 +++++++-- src/pages/dmenu/types/Types.ts | 20 +++++++++++++++++--- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/pages/dmenu/hooks/useIconData.ts b/src/pages/dmenu/hooks/useIconData.ts index 5672ba3..e5468c0 100644 --- a/src/pages/dmenu/hooks/useIconData.ts +++ b/src/pages/dmenu/hooks/useIconData.ts @@ -52,10 +52,10 @@ export const useGetReports = () => { }); }; -export const useGetRestaurants = () => { +export const useGetRestaurants = (page: number = 1, limit: number = 10) => { return useQuery({ - queryKey: ["restaurants"], - queryFn: api.getRestaurants, + queryKey: ["restaurants", page, limit], + queryFn: () => api.getRestaurants(page, limit), }); }; diff --git a/src/pages/dmenu/restaurant/List.tsx b/src/pages/dmenu/restaurant/List.tsx index d9bdf7c..b309a97 100644 --- a/src/pages/dmenu/restaurant/List.tsx +++ b/src/pages/dmenu/restaurant/List.tsx @@ -3,21 +3,25 @@ import { useTranslation } from 'react-i18next' import { useGetRestaurants } from '../hooks/useIconData' import PageLoading from '../../../components/PageLoading' import Td from '../../../components/Td' -import { RestaurantType } from '../types/Types' +import { RestaurantType, RestaurantsResponse } from '../types/Types' import moment from 'moment-jalaali' import { Copy } from 'iconsax-react' import { toast } from 'react-toastify' import Button from '../../../components/Button' import RestaurantAdminsModal from './components/RestaurantAdminsModal' +import Pagination from '../../../components/Pagination' const RestaurantsList: FC = () => { const { t } = useTranslation('global') - const { data: restaurants, isLoading } = useGetRestaurants() + const [page, setPage] = useState(1) + const limit = 10 + const { data: restaurants, isLoading } = useGetRestaurants(page, limit) const [selectedRestaurantId, setSelectedRestaurantId] = useState('') const [isAdminsModalOpen, setIsAdminsModalOpen] = useState(false) - const restaurantsList = (restaurants as { data?: RestaurantType[] })?.data || [] + const restaurantsList = (restaurants as RestaurantsResponse | undefined)?.data?.restaurants || [] + const totalPages = (restaurants as RestaurantsResponse | undefined)?.data?.pager?.totalPages || 1 const handleOpenAdminsModal = (restaurantId: string) => { setSelectedRestaurantId(restaurantId) @@ -117,6 +121,14 @@ const RestaurantsList: FC = () => { } + + {totalPages > 1 && ( + + )} } diff --git a/src/pages/dmenu/service/IconService.ts b/src/pages/dmenu/service/IconService.ts index 610f819..2e8d8df 100644 --- a/src/pages/dmenu/service/IconService.ts +++ b/src/pages/dmenu/service/IconService.ts @@ -47,8 +47,13 @@ export const getReports = async (): Promise => { return data; }; -export const getRestaurants = async (): Promise => { - const { data } = await axios.get("/admin/dmenu/restaurants"); +export const getRestaurants = async ( + page: number = 1, + limit: number = 10 +): Promise => { + const { data } = await axios.get( + `/admin/dmenu/restaurants?page=${page}&limit=${limit}` + ); return data; }; diff --git a/src/pages/dmenu/types/Types.ts b/src/pages/dmenu/types/Types.ts index a13e9a9..7f880a0 100644 --- a/src/pages/dmenu/types/Types.ts +++ b/src/pages/dmenu/types/Types.ts @@ -77,7 +77,7 @@ export type RestaurantType = { deletedAt: string | null; name: string; slug: string; - logo: string; + logo: string | null; address: string | null; menuColor: string | null; latitude: number | null; @@ -96,14 +96,28 @@ export type RestaurantType = { images: string | null; vat: number; domain: string; - score: ScoreType; + score: ScoreType | null; plan: string; subscriptionId: string; subscriptionEndDate: string; subscriptionStartDate: string; }; -export interface RestaurantsResponse extends IResponse { +export type PagerType = { + page: number; + limit: number; + totalItems: number; + totalPages: number; + prevPage: boolean; + nextPage: string | false; +}; + +export type RestaurantsData = { + pager: PagerType; + restaurants: RestaurantType[]; +}; + +export interface RestaurantsResponse extends IResponse { statusCode: number; }