Skip to content

Commit 796cac8

Browse files
Hdm 21 (#2640)
* fix(dashboard/ui-2024/transactions-table): disable next page button if last page * fix(dashboard/ui-2024/transactions-table): display correct items count in pagination
1 parent 8771512 commit 796cac8

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

packages/apps/dashboard/ui-2024/src/pages/SearchResults/RoleDetails/RoleDetailsEscrows/RoleDetailsEscrowsTable.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Table from '@mui/material/Table';
77
import { EscrowsTableBody } from '@pages/SearchResults/RoleDetails/RoleDetailsEscrows/tableComponents/EscrowsTableBody';
88
import TablePagination from '@mui/material/TablePagination';
99
import { useEscrowDetailsDto } from '@utils/hooks/use-escrows-details-dto';
10+
import { useEscrowDetails } from '@services/api/use-escrows-details';
1011
import TableHead from '@mui/material/TableHead';
1112
import TableRow from '@mui/material/TableRow';
1213
import { Stack } from '@mui/material';
@@ -16,6 +17,7 @@ export const RoleDetailsEscrowsTable = ({
1617
}: {
1718
role: AddressDetailsLeader['role'];
1819
}) => {
20+
const { data } = useEscrowDetails({ role });
1921
const {
2022
pagination: { page, pageSize, lastPageIndex },
2123
setPageSize,
@@ -76,7 +78,10 @@ export const RoleDetailsEscrowsTable = ({
7678
}}
7779
rowsPerPageOptions={[5, 10]}
7880
labelDisplayedRows={({ from, to }) => {
79-
return `${from}${to}`;
81+
const effectiveTo = data?.results
82+
? from + data.results.length - 1
83+
: to;
84+
return `${from}${effectiveTo}`;
8085
}}
8186
component="div"
8287
slotProps={{

packages/apps/dashboard/ui-2024/src/pages/SearchResults/WalletAddress/WalletAddressTransactions/WalletAddressTransactionsTable.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import { TransactionsTableHead } from '@pages/SearchResults/WalletAddress/Wallet
88
import { TransactionsTableBody } from '@pages/SearchResults/WalletAddress/WalletAddressTransactions/tableComponents/TransactionsTableBody';
99
import { useTransactionDetailsDto } from '@utils/hooks/use-transactions-details-dto';
1010
import { TableFooter } from '@mui/material';
11+
import { useTransactionDetails } from '@services/api/use-transaction-details';
1112

1213
export const WalletAddressTransactionsTable = () => {
14+
const { data } = useTransactionDetails();
1315
const {
1416
pagination: { page, pageSize, lastPageIndex },
1517
setPageSize,
@@ -57,7 +59,10 @@ export const WalletAddressTransactionsTable = () => {
5759
}}
5860
rowsPerPageOptions={[5, 10]}
5961
labelDisplayedRows={({ from, to }) => {
60-
return `${from}${to}`;
62+
const effectiveTo = data?.results
63+
? from + data.results.length - 1
64+
: to;
65+
return `${from}${effectiveTo}`;
6166
}}
6267
slotProps={{
6368
actions: {

packages/apps/dashboard/ui-2024/src/services/api/use-escrows-details.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ export function useEscrowDetails({
4242
role: AddressDetailsLeader['role'];
4343
}) {
4444
const { filterParams } = useWalletSearch();
45-
const { params } = useEscrowDetailsDto();
45+
const {
46+
setLastPageIndex,
47+
pagination: { page, lastPageIndex },
48+
params,
49+
} = useEscrowDetailsDto();
4650

4751
const dto: PaginatedEscrowsDetailsDto = {
4852
chainId: filterParams.chainId,
@@ -65,6 +69,28 @@ export function useEscrowDetails({
6569
paginatedEscrowsDetailsSuccessResponseSchema
6670
);
6771

72+
// check if last page
73+
if (lastPageIndex === undefined) {
74+
const { data: lastPageCheckData } = await httpService.get(
75+
`${apiPaths.escrowDetails.path}/${filterParams.address}`,
76+
{
77+
params: {
78+
...dto,
79+
skip: dto.skip + validResponse.results.length,
80+
first: 1,
81+
},
82+
}
83+
);
84+
const validLastPageCheckData = validateResponse(
85+
lastPageCheckData,
86+
paginatedEscrowsDetailsSuccessResponseSchema
87+
);
88+
89+
if (validLastPageCheckData.results.length === 0) {
90+
setLastPageIndex(page + 1);
91+
}
92+
}
93+
6894
return validResponse;
6995
},
7096
queryKey: ['useEscrowDetails', filterParams.address, dto],

packages/apps/dashboard/ui-2024/src/services/api/use-transaction-details.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ export interface PaginatedTransactionDetailsDto {
3939

4040
export function useTransactionDetails() {
4141
const { filterParams } = useWalletSearch();
42-
const { params } = useTransactionDetailsDto();
42+
const {
43+
params,
44+
pagination: { lastPageIndex, page },
45+
setLastPageIndex,
46+
} = useTransactionDetailsDto();
4347

4448
const dto: PaginatedTransactionDetailsDto = {
4549
chainId: filterParams.chainId,
@@ -61,6 +65,28 @@ export function useTransactionDetails() {
6165
paginatedTransactionDetailsSuccessResponseSchema
6266
);
6367

68+
// check if last page
69+
if (lastPageIndex === undefined) {
70+
const { data: lastPageCheckData } = await httpService.get(
71+
`${apiPaths.transactionDetails.path}/${filterParams.address}`,
72+
{
73+
params: {
74+
...dto,
75+
skip: dto.skip + validResponse.results.length,
76+
first: 1,
77+
},
78+
}
79+
);
80+
const validLastPageCheckData = validateResponse(
81+
lastPageCheckData,
82+
paginatedTransactionDetailsSuccessResponseSchema
83+
);
84+
85+
if (validLastPageCheckData.results.length === 0) {
86+
setLastPageIndex(page + 1);
87+
}
88+
}
89+
6490
return validResponse;
6591
},
6692
queryKey: ['useTransactionDetails', filterParams.address, dto],

0 commit comments

Comments
 (0)