restaurant list fix + pager
This commit is contained in:
@@ -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<number>(1)
|
||||
const limit = 10
|
||||
const { data: restaurants, isLoading } = useGetRestaurants(page, limit)
|
||||
const [selectedRestaurantId, setSelectedRestaurantId] = useState<string>('')
|
||||
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) => {
|
||||
setSelectedRestaurantId(restaurantId)
|
||||
@@ -117,6 +121,14 @@ const RestaurantsList: FC = () => {
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{totalPages > 1 && (
|
||||
<Pagination
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user