Skip to content

Commit

Permalink
fix: instution selected admin role
Browse files Browse the repository at this point in the history
  • Loading branch information
AuraAlba committed Aug 6, 2024
1 parent c389d26 commit 70c00ae
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/features/Main/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Switch,
Route,
Redirect,
useLocation, useHistory,
} from 'react-router-dom';

import { getConfig } from '@edx/frontend-platform';
Expand All @@ -30,22 +31,36 @@ import ManageInstructors from 'features/Instructors/ManageInstructors';
import InstitutionSelector from 'features/Main/InstitutionSelector';

import { fetchInstitutionData } from 'features/Main/data/thunks';
import { updateSelectedInstitution } from 'features/Main/data/slice';

import { useInstitutionIdQueryParam } from 'hooks';

import { cookieText } from 'features/constants';
import { cookieText, INSTITUTION_QUERY_ID } from 'features/constants';

import './index.scss';

const Main = () => {
const history = useHistory();
const location = useLocation();
const dispatch = useDispatch();
const institutions = useSelector((state) => state.main.institution.data);
const addQueryParam = useInstitutionIdQueryParam();

const searchParams = new URLSearchParams(location.search);

useEffect(() => {
dispatch(fetchInstitutionData());
}, [dispatch]);

useEffect(() => {
if (institutions.length === 1) {
searchParams.set(INSTITUTION_QUERY_ID, institutions[0].id);
history.push({ search: searchParams.toString() });

dispatch(updateSelectedInstitution(institutions[0]));
}
}, [institutions, dispatch]); // eslint-disable-line react-hooks/exhaustive-deps

const routes = [
{ path: '/dashboard', component: DashboardPage, exact: true },
{ path: '/students', component: StudentsPage, exact: true },
Expand Down

0 comments on commit 70c00ae

Please sign in to comment.