Skip to content

Commit

Permalink
Fix redirection to all facilities page for multi facility admins
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVelezLl committed Feb 19, 2025
1 parent 5e3fc4f commit 080c930
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion kolibri/plugins/coach/assets/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,26 @@ export default [
path: '/:facility_id?/classes/:subtopicName?',
component: CoachClassListPage,
props: true,
handler(toRoute) {
async handler(toRoute) {
// loading state is handled locally
store.dispatch('notLoading');
// if user only has access to one facility, facility_id will not be accessible from URL,
// but always defaulting to userFacilityId would cause problems for multi-facility admins
const { userFacilityId } = useUser();
const { facilities, getFacilities, userIsMultiFacilityAdmin } = useFacilities();
const facilityId = toRoute.params.facility_id || get(userFacilityId);

if (facilities.value.length === 0) {
await getFacilities();
}

if (userIsMultiFacilityAdmin.value && !toRoute.params.facility_id) {
return router.replace({
name: 'AllFacilitiesPage',
params: { subtopicName: toRoute.params.subtopicName },
});
}

store.dispatch('setClassList', facilityId).then(
() => {
if (!store.getters.classListPageEnabled) {
Expand Down

0 comments on commit 080c930

Please sign in to comment.