-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added pagination in Transaction
- Loading branch information
Mayur
committed
Nov 29, 2024
1 parent
c3f2a03
commit 819f698
Showing
7 changed files
with
116 additions
and
28 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
apps/api/src/app/user/usecases/get-transaction-history/get-transaction-command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { PaginationCommand } from '@shared/commands/pagination.command'; | ||
import { IsString } from 'class-validator'; | ||
|
||
export class GetTransactionHistoryCommand extends PaginationCommand { | ||
@IsString() | ||
projectId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
import { useState } from 'react'; | ||
import { commonApi } from '@libs/api'; | ||
import { IErrorObject } from '@impler/shared'; | ||
import { IErrorObject, IPaginationData } from '@impler/shared'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { API_KEYS } from '@config'; | ||
import { API_KEYS, VARIABLES } from '@config'; | ||
|
||
export function useTransactionHistory() { | ||
const [page, setPage] = useState<number>(); | ||
const [limit, setLimit] = useState<number>(VARIABLES.TEN); | ||
const { | ||
data: transactions, | ||
refetch: refetchTransactions, | ||
isLoading: isTransactionsLoading, | ||
isFetched: isTransactionsFetched, | ||
} = useQuery<unknown, IErrorObject, ITransactionHistory[], [string]>([API_KEYS.TRANSACTION_HISTORY], () => | ||
commonApi<ITransactionHistory[]>(API_KEYS.TRANSACTION_HISTORY as any, {}) | ||
} = useQuery<unknown, IErrorObject, IPaginationData<ITransactionHistory>, [string, number, number | undefined]>( | ||
[API_KEYS.TRANSACTION_HISTORY, limit, page], | ||
() => | ||
commonApi<IPaginationData<ITransactionHistory[]>>(API_KEYS.TRANSACTION_HISTORY as any, { | ||
query: { | ||
limit, | ||
page, | ||
}, | ||
}) | ||
); | ||
|
||
function onLimitChange(newLimit: number) { | ||
setLimit(newLimit); | ||
} | ||
|
||
return { | ||
transactions, | ||
refetchTransactions, | ||
isTransactionsLoading, | ||
isTransactionsFetched, | ||
onLimitChange, | ||
onPageChange: setPage, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.