go to the last page if page doesn't exist

This commit is contained in:
Fernando Chavez 2023-08-07 11:06:30 +02:00
parent a92367510f
commit 8dbc3c09ee

View File

@ -166,6 +166,22 @@ function ListView({
data: { results, pagination: paginationResult }, data: { results, pagination: paginationResult },
} = await fetchClient.get(endPoint, options); } = await fetchClient.get(endPoint, options);
// If user enters a page number that doesn't exist, redirect him to the last page
if (paginationResult.page > paginationResult.pageCount && paginationResult.pageCount > 0) {
const query = {
...params,
page: paginationResult.pageCount,
};
push({
pathname,
state: { from: pathname },
search: stringify(query),
});
return;
}
notifyStatus( notifyStatus(
formatMessage( formatMessage(
{ {
@ -205,7 +221,17 @@ function ListView({
}); });
} }
}, },
[formatMessage, getData, getDataSucceeded, notifyStatus, push, toggleNotification, fetchClient] [
formatMessage,
getData,
getDataSucceeded,
notifyStatus,
push,
toggleNotification,
fetchClient,
params,
pathname,
]
); );
const handleConfirmDeleteAllData = React.useCallback( const handleConfirmDeleteAllData = React.useCallback(