Skip to content

Commit

Permalink
sort bank transaction by desc transactionDate
Browse files Browse the repository at this point in the history
  • Loading branch information
dphilipov committed Sep 18, 2023
1 parent f703daf commit 4b27285
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/common/hooks/bank-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import { useSession } from 'next-auth/react'
import { useQuery } from '@tanstack/react-query'

import { endpoints } from 'service/apiEndpoints'
import { PaginationData, FilterData } from 'gql/types'
import { PaginationData, FilterData, SortData } from 'gql/types'
import { authQueryFnFactory } from 'service/restRequests'

export function useBankTransactionsList(
paginationData?: PaginationData,
filterData?: FilterData,
sort?: SortData,
searchData?: string,
) {
const { data: session } = useSession()
return useQuery<BankTransactionsHistoryResponse>(
[endpoints.bankTransactions.transactionsList(paginationData, filterData, searchData).url],
[endpoints.bankTransactions.transactionsList(paginationData, filterData, sort, searchData).url],
{
queryFn: authQueryFnFactory(session?.accessToken),
},
Expand Down
14 changes: 8 additions & 6 deletions src/components/admin/bank-transactions/grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { money } from 'common/util/money'
import { useStores } from '../../../../common/hooks/useStores'
import { BankTransactionsHistoryResponse } from 'gql/bank-transactions'
import { useBankTransactionsList } from 'common/hooks/bank-transactions'
import { SortData } from 'gql/types'
import RenderBankDonationStatusCell from './RenderEditBankDonationStatusCell'

interface RenderCellProps {
Expand All @@ -22,9 +23,14 @@ export default observer(function Grid() {
const { bankTransactionsStore } = useStores()
const [paginationModel, setPaginationModel] = useState({
page: 0,
pageSize: 20,
pageSize: 5,
})

const defaultSort: SortData = {
sortBy: 'transactionDate',
sortOrder: 'desc',
}

const { t } = useTranslation()

const {
Expand All @@ -34,6 +40,7 @@ export default observer(function Grid() {
}: UseQueryResult<BankTransactionsHistoryResponse> = useBankTransactionsList(
{ pageIndex: paginationModel.page, pageSize: paginationModel.pageSize },
bankTransactionsStore.bankTransactionsFilter,
defaultSort,
bankTransactionsStore.bankTransactionSearch,
)

Expand Down Expand Up @@ -151,11 +158,6 @@ export default observer(function Grid() {
rowCount={all_rows}
disableRowSelectionOnClick
isCellEditable={() => true}
initialState={{
sorting: {
sortModel: [{ field: 'transactionDate', sort: 'desc' }],
},
}}
/>
</Box>
</>
Expand Down
4 changes: 3 additions & 1 deletion src/service/apiEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,16 @@ export const endpoints = {
transactionsList: (
paginationData?: PaginationData,
filterData?: FilterData,
sort?: SortData,
searchData?: string,
) => {
const { pageIndex, pageSize } = (paginationData as PaginationData) || {}
const { status, date } = (filterData as FilterData) || {}
const { sortBy, sortOrder } = (sort as SortData) || {}
const { from, to } = date || {}

return <Endpoint>{
url: `/bank-transaction/list?pageindex=${pageIndex}&pagesize=${pageSize}&status=${status}&from=${from}&to=${to}&search=${searchData}`,
url: `/bank-transaction/list?pageindex=${pageIndex}&pagesize=${pageSize}&status=${status}&from=${from}&to=${to}&search=${searchData}&sortBy=${sortBy}&sortOrder=${sortOrder}`,
method: 'GET',
}
},
Expand Down

0 comments on commit 4b27285

Please sign in to comment.