Skip to content

Commit

Permalink
fix: payments table
Browse files Browse the repository at this point in the history
  • Loading branch information
baynt1 committed Sep 26, 2024
1 parent 9051016 commit ca69b3d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/entities/dashboard/payment-data/payment-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { IPostsResponse } from 'entities/settings/posts-table/model/interface'
import { useEffect, useState } from 'react'
import { getAxiosInstance } from 'shared/api/api-query/api-query'
import { setPaymentsState } from 'shared/redux/dashboard/dashboard-slice'
import { useAppDispatch } from 'shared/redux/store'
import { useAppDispatch, useAppSelector } from 'shared/redux/store'

export const usePaymentData = () => {
const { openNotification } = useNotify()
const dispatch = useAppDispatch()
const currentPage = useAppSelector((state) => state.dashboard.pagination.current)
const pageSize = useAppSelector((state) => state.dashboard.pagination.pageSize)

const [postSelect, setPostSelect] = useState([])

const fetchPosts = async () => {
Expand All @@ -27,7 +30,9 @@ export const usePaymentData = () => {
const fetchData = async () => {
try {
const axiosInstance = await getAxiosInstance()
const res = await axiosInstance.get('/payments')
const res = await axiosInstance.get('/payments', {
params: { take: pageSize, skip: (currentPage - 1) * pageSize },
})
dispatch(setPaymentsState(res.data))
} catch (error) {
openNotification('Произошла ошибка при загрузке данных о платежах')
Expand All @@ -37,7 +42,7 @@ export const usePaymentData = () => {
useEffect(() => {
fetchData()
fetchPosts()
}, [])
}, [pageSize, currentPage])

return { fetchData, postSelect }
}
16 changes: 15 additions & 1 deletion src/pages/dashboard/ui/dashboard-payment/dashboard-payment.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { Table } from 'antd'
import { Table, TablePaginationConfig } from 'antd'
import { IDashboardPaymentProps } from 'pages/dashboard/ui/dashboard-payment/model/interface'
import React, { FC } from 'react'
import { setPaginationPayment } from 'shared/redux/dashboard/dashboard-slice'
import { useAppDispatch, useAppSelector } from 'shared/redux/store'

export const DashboardPayment: FC<IDashboardPaymentProps> = ({ total, sum, columns, rows }) => {
const dispatch = useAppDispatch()
const currentPage = useAppSelector((state) => state.dashboard.pagination.current)
const pageSize = useAppSelector((state) => state.dashboard.pagination.pageSize)

const handleTableChange = (pagination: TablePaginationConfig) => {
dispatch(setPaginationPayment({ current: pagination.current, pageSize: pagination.pageSize }))
}

return (
<>
<Table
Expand All @@ -11,8 +21,12 @@ export const DashboardPayment: FC<IDashboardPaymentProps> = ({ total, sum, colum
bordered={true}
showHeader={true}
tableLayout={'fixed'}
onChange={handleTableChange}
pagination={{
total: total,
current: currentPage,
pageSize: pageSize,
showSizeChanger: true,
}}
scroll={{
x: 'max-content',
Expand Down
13 changes: 11 additions & 2 deletions src/shared/redux/dashboard/dashboard-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const initialState = {
posts: undefined,
typeDate: 1,
selectedDates: { start: undefined, end: undefined },
pagination: { current: 1, pageSize: 10 },
}

export const DashboardSlice = createSlice({
Expand All @@ -23,10 +24,18 @@ export const DashboardSlice = createSlice({
setPaymentsSelectedDates: (state, action) => {
state.selectedDates = action.payload
},
setPaginationPayment: (state, action) => {
state.pagination = action.payload
},
},
})

export const { setPaymentsState, setPaymentsPost, setPaymentsSelectedDates, setPaymentsTypeDate } =
DashboardSlice.actions
export const {
setPaymentsState,
setPaymentsPost,
setPaginationPayment,
setPaymentsSelectedDates,
setPaymentsTypeDate,
} = DashboardSlice.actions

export default DashboardSlice.reducer

0 comments on commit ca69b3d

Please sign in to comment.