Skip to content
Snippets Groups Projects
Commit 7ec8047e authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

fix: returns to first page when search changes

parent 276f0e01
No related branches found
No related tags found
1 merge request!88Resolve "[1] [SGE - Backoffice] Amélioration distinction consentement expirés/valides"
Pipeline #53348 passed
...@@ -153,25 +153,28 @@ const Consents: React.FC = () => { ...@@ -153,25 +153,28 @@ const Consents: React.FC = () => {
} }
}, [gridApi, selectedNodes]) }, [gridApi, selectedNodes])
const handleSearchChange = useCallback( const searchConsents = async () => {
async (newSearch: string) => { if (user) {
setSearch(newSearch) const consentPagination = await consentService.searchConsents(
if (user) { search,
const consentPagination = await consentService.searchConsents( rowsPerPage,
newSearch, page,
rowsPerPage, getAxiosXSRFHeader(user.xsrftoken)
page, )
getAxiosXSRFHeader(user.xsrftoken) if (consentPagination) {
) setConsents(consentPagination.rows)
if (consentPagination) { checkSelectedNodes()
setConsents(consentPagination.rows) setTotalRows(consentPagination.totalRows)
checkSelectedNodes() console.log(search)
setTotalRows(consentPagination.totalRows) console.log(consentPagination)
}
} }
}, }
[user, consentService, rowsPerPage, page, checkSelectedNodes] }
)
const handleSearchChange = (newSearch: string) => {
setSearch(newSearch)
setPage(0)
}
const resetSelection = useCallback(() => { const resetSelection = useCallback(() => {
if (gridApi) { if (gridApi) {
...@@ -252,12 +255,12 @@ const Consents: React.FC = () => { ...@@ -252,12 +255,12 @@ const Consents: React.FC = () => {
} }
}, [gridApi]) }, [gridApi])
/** Trigger search when page loads or when admin changes pagination */ /** Trigger search when page loads or when admin changes input or pagination */
useEffect(() => { useEffect(() => {
handleSearchChange(search) searchConsents()
// /!\ Do not change dependencies or effect will not trigger when pagination changes // /!\ Do not change dependencies or effect will not trigger when pagination changes
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [rowsPerPage, page]) }, [rowsPerPage, page, search])
return ( return (
<> <>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment