diff --git a/app/actions/CompanyActions.ts b/app/actions/CompanyActions.ts index d300a684e2..e1a2ccd34e 100644 --- a/app/actions/CompanyActions.ts +++ b/app/actions/CompanyActions.ts @@ -35,7 +35,7 @@ export const fetchAll = ({ fetchMore }: { fetchMore: boolean }) => { }); }; -export function fetchAllAdmin(semesterId: EntityId, fetchMore: boolean) { +export function fetchAllAdmin(query, next: boolean) { return callAPI({ types: Company.FETCH, endpoint: `/bdb/`, @@ -44,11 +44,9 @@ export function fetchAllAdmin(semesterId: EntityId, fetchMore: boolean) { errorMessage: 'Henting av bedrifter feilet', }, propagateError: true, - query: { - semester_id: semesterId, - }, + query: query, pagination: { - fetchNext: fetchMore, + fetchNext: next, }, }); } diff --git a/app/routes/bdb/components/BdbPage.tsx b/app/routes/bdb/components/BdbPage.tsx index 4f2247289c..22afc30037 100644 --- a/app/routes/bdb/components/BdbPage.tsx +++ b/app/routes/bdb/components/BdbPage.tsx @@ -57,13 +57,13 @@ const BdbPage = () => { [companySemesters, query.semester], ); - console.log(currentCompanySemester); const { pagination } = useAppSelector( selectPaginationNext({ endpoint: '/bdb/', entity: EntityType.Companies, query: { - semester_id: currentCompanySemester?.id, + ...query, + semester_id: String(currentCompanySemester?.id), }, }), ); @@ -80,18 +80,32 @@ const BdbPage = () => { async () => { if (!companySemesters.length) { const action = await dispatch(fetchSemesters()); - const companySemesterEntities = - action.payload.entities.companySemesters; - const companySemesters = Object.values(companySemesterEntities).filter( - (companySemester) => companySemester !== undefined, - ); + const companySemesters = Object.values( + action.payload.entities.companySemesters, + ).filter((companySemester) => companySemester !== undefined); const semester = resolveCurrentSemester( query.semester, companySemesters, ); - return dispatch(fetchAllAdmin(semester!.id, false)); + return dispatch( + fetchAllAdmin( + { + ...query, + semester_id: semester!.id, + }, + false, + ), + ); } - return dispatch(fetchAllAdmin(currentCompanySemester!.id, false)); + return dispatch( + fetchAllAdmin( + { + ...query, + semester_id: currentCompanySemester!.id, + }, + false, + ), + ); }, [query.semester, currentCompanySemester, companySemesters], ); @@ -175,7 +189,7 @@ const BdbPage = () => { (b.semester === 'autumn' ? 1 : -1)) + .sort((_, b) => (b.semester === 'autumn' ? 1 : -1)) .sort((a, b) => b.year - a.year) .map((semester) => ({ label: semesterToHumanReadable( @@ -206,12 +220,21 @@ const BdbPage = () => { { - dispatch(fetchAllAdmin(currentCompanySemester?.id, true)); + currentCompanySemester?.id && + dispatch( + fetchAllAdmin( + { + ...query, + semester_id: currentCompanySemester.id, + }, + true, + ), + ); }} hasMore={pagination.hasMore} />