Skip to content

Commit 55f3c39

Browse files
fix: cast search params numbers properly on the group search page (#3880)
Co-authored-by: Flora Thiebaut <[email protected]>
1 parent cd9705c commit 55f3c39

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

client/src/features/groupsV2/search/GroupSearchResults.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ export default function GroupSearchResults() {
4646
const [searchParams] = useSearchParams();
4747
const { data } = useGroupSearch();
4848

49+
const currentPage = useMemo(() => {
50+
const defaultValue = FILTER_PAGE.defaultValue as number;
51+
const pageParam = searchParams.get(FILTER_PAGE.name);
52+
if (!pageParam) return defaultValue;
53+
try {
54+
const page = parseInt(pageParam, 10);
55+
return page > 0 ? page : defaultValue;
56+
} catch {
57+
return defaultValue;
58+
}
59+
}, [searchParams]);
60+
61+
const currentPerPage = useMemo(() => {
62+
const defaultValue = FILTER_PER_PAGE.defaultValue as number;
63+
const perPageParam = searchParams.get(FILTER_PER_PAGE.name);
64+
if (!perPageParam) return defaultValue;
65+
try {
66+
const perPage = parseInt(perPageParam, 10);
67+
return perPage > 0 ? perPage : defaultValue;
68+
} catch {
69+
return defaultValue;
70+
}
71+
}, [searchParams]);
72+
4973
return (
5074
<div>
5175
<h4 className={cx("d-block", "d-sm-none")}>Results</h4>
@@ -63,14 +87,8 @@ export default function GroupSearchResults() {
6387
})}
6488
</ListGroup>
6589
<Pagination
66-
currentPage={
67-
(searchParams.get(FILTER_PAGE.name) ??
68-
FILTER_PAGE.defaultValue) as number
69-
}
70-
perPage={
71-
(searchParams.get(FILTER_PER_PAGE.name) ??
72-
FILTER_PER_PAGE.defaultValue) as number
73-
}
90+
currentPage={currentPage}
91+
perPage={currentPerPage}
7492
totalItems={data?.pagingInfo.totalResult ?? 0}
7593
pageQueryParam="page"
7694
showDescription={true}

0 commit comments

Comments
 (0)