All files / src/utils/hooks useOrganization.js

100% Statements 7/7
100% Branches 21/21
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24    74x     5x 74x 74x 128x     74x                        
import { useSelector } from "react-redux";
 
const resolveUserType = (userType) => (userType === "student" ? "student" : "teacher");
 
/** School + district organization data from `/features/organization`. */
export const useOrganization = (userType = "teacher") => {
    const scopedUserType = resolveUserType(userType);
    const state = useSelector((rootState) =>
        scopedUserType === "student" ? rootState.StudentFeatureFlags : rootState.TeacherFeatureFlags
    );
 
    return {
        organization: state?.organization ?? null,
        loading: state?.organizationLoading ?? false,
        error: state?.organizationError ?? null,
        school: state?.organization?.school ?? null,
        district: state?.organization?.district ?? null,
        currentPlan: state?.organization?.current_plan ?? state?.currentPlan ?? null,
        planName: state?.organization?.plan_name ?? state?.planName ?? null,
    };
};
 
export default useOrganization;