restaurant list fix + pager
This commit is contained in:
@@ -52,10 +52,10 @@ export const useGetReports = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetRestaurants = () => {
|
export const useGetRestaurants = (page: number = 1, limit: number = 10) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["restaurants"],
|
queryKey: ["restaurants", page, limit],
|
||||||
queryFn: api.getRestaurants,
|
queryFn: () => api.getRestaurants(page, limit),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,21 +3,25 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import { useGetRestaurants } from '../hooks/useIconData'
|
import { useGetRestaurants } from '../hooks/useIconData'
|
||||||
import PageLoading from '../../../components/PageLoading'
|
import PageLoading from '../../../components/PageLoading'
|
||||||
import Td from '../../../components/Td'
|
import Td from '../../../components/Td'
|
||||||
import { RestaurantType } from '../types/Types'
|
import { RestaurantType, RestaurantsResponse } from '../types/Types'
|
||||||
import moment from 'moment-jalaali'
|
import moment from 'moment-jalaali'
|
||||||
import { Copy } from 'iconsax-react'
|
import { Copy } from 'iconsax-react'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import Button from '../../../components/Button'
|
import Button from '../../../components/Button'
|
||||||
import RestaurantAdminsModal from './components/RestaurantAdminsModal'
|
import RestaurantAdminsModal from './components/RestaurantAdminsModal'
|
||||||
|
import Pagination from '../../../components/Pagination'
|
||||||
|
|
||||||
const RestaurantsList: FC = () => {
|
const RestaurantsList: FC = () => {
|
||||||
|
|
||||||
const { t } = useTranslation('global')
|
const { t } = useTranslation('global')
|
||||||
const { data: restaurants, isLoading } = useGetRestaurants()
|
const [page, setPage] = useState<number>(1)
|
||||||
|
const limit = 10
|
||||||
|
const { data: restaurants, isLoading } = useGetRestaurants(page, limit)
|
||||||
const [selectedRestaurantId, setSelectedRestaurantId] = useState<string>('')
|
const [selectedRestaurantId, setSelectedRestaurantId] = useState<string>('')
|
||||||
const [isAdminsModalOpen, setIsAdminsModalOpen] = useState<boolean>(false)
|
const [isAdminsModalOpen, setIsAdminsModalOpen] = useState<boolean>(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) => {
|
const handleOpenAdminsModal = (restaurantId: string) => {
|
||||||
setSelectedRestaurantId(restaurantId)
|
setSelectedRestaurantId(restaurantId)
|
||||||
@@ -117,6 +121,14 @@ const RestaurantsList: FC = () => {
|
|||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
{totalPages > 1 && (
|
||||||
|
<Pagination
|
||||||
|
currentPage={page}
|
||||||
|
totalPages={totalPages}
|
||||||
|
onPageChange={setPage}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,13 @@ export const getReports = async (): Promise<ReportsResponse> => {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getRestaurants = async (): Promise<RestaurantsResponse> => {
|
export const getRestaurants = async (
|
||||||
const { data } = await axios.get("/admin/dmenu/restaurants");
|
page: number = 1,
|
||||||
|
limit: number = 10
|
||||||
|
): Promise<RestaurantsResponse> => {
|
||||||
|
const { data } = await axios.get(
|
||||||
|
`/admin/dmenu/restaurants?page=${page}&limit=${limit}`
|
||||||
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export type RestaurantType = {
|
|||||||
deletedAt: string | null;
|
deletedAt: string | null;
|
||||||
name: string;
|
name: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
logo: string;
|
logo: string | null;
|
||||||
address: string | null;
|
address: string | null;
|
||||||
menuColor: string | null;
|
menuColor: string | null;
|
||||||
latitude: number | null;
|
latitude: number | null;
|
||||||
@@ -96,14 +96,28 @@ export type RestaurantType = {
|
|||||||
images: string | null;
|
images: string | null;
|
||||||
vat: number;
|
vat: number;
|
||||||
domain: string;
|
domain: string;
|
||||||
score: ScoreType;
|
score: ScoreType | null;
|
||||||
plan: string;
|
plan: string;
|
||||||
subscriptionId: string;
|
subscriptionId: string;
|
||||||
subscriptionEndDate: string;
|
subscriptionEndDate: string;
|
||||||
subscriptionStartDate: string;
|
subscriptionStartDate: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface RestaurantsResponse extends IResponse<RestaurantType[]> {
|
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<RestaurantsData> {
|
||||||
statusCode: number;
|
statusCode: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user