diff --git a/client/src/App.jsx b/client/src/App.jsx
index 59d38419..34f08c16 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -100,6 +100,7 @@ import PermContactCalendarIcon from '@mui/icons-material/PermContactCalendar';
import MonetizationOnIcon from '@mui/icons-material/MonetizationOn';
import LocalAtmIcon from '@mui/icons-material/LocalAtm';
import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings';
+import { TeacherGuard } from './components/TeacherAccess';
const i18nProvider = getI18nProvider(domainTranslations);
@@ -131,8 +132,8 @@ const App = () => (
- } />
- } />
+ } />
+ } />
>
);
diff --git a/client/src/GeneralLayout.jsx b/client/src/GeneralLayout.jsx
index 50b628c5..1f76075e 100644
--- a/client/src/GeneralLayout.jsx
+++ b/client/src/GeneralLayout.jsx
@@ -20,29 +20,32 @@ import BaseDashboard from '@shared/components/views/Dashboard';
import { isInLessonReport, isScannerUpload, isOnlyInLessonReport, isTeacherView } from './utils/appPermissions';
import { useDashboardItems } from './settings/settingsUtil';
+const isStandardView = (permissions) => !isOnlyInLessonReport(permissions) && !isTeacherView(permissions);
+const shouldShowLessonReports = (permissions) => isInLessonReport(permissions) || isTeacherView(permissions);
+
const customMenuItems = [
// static items: render only when NOT restricted to lesson-report-only
- ({ permissions }) => !isOnlyInLessonReport(permissions) && !isTeacherView(permissions) && } />,
- ({ permissions }) => !isOnlyInLessonReport(permissions) && !isTeacherView(permissions) && } />,
+ ({ permissions }) => isStandardView(permissions) && } />,
+ ({ permissions }) => isStandardView(permissions) && } />,
// admin-only
- ({ isAdmin, permissions }) => !isOnlyInLessonReport(permissions) && !isTeacherView(permissions) && isAdmin && } />,
+ ({ isAdmin, permissions }) => isStandardView(permissions) && isAdmin && } />,
// permission-based items: show only when not restricted
- ({ permissions }) => !isOnlyInLessonReport(permissions) && !isTeacherView(permissions) && isScannerUpload(permissions) && } />,
+ ({ permissions }) => isStandardView(permissions) && isScannerUpload(permissions) && } />,
// lesson report links: show when user has lesson-report permission OR when they're in-only mode
- ({ permissions }) => ((isInLessonReport(permissions)) || (isTeacherView(permissions))) && } />,
- ({ permissions }) => ((isInLessonReport(permissions)) || (isTeacherView(permissions))) && } />,
- ({ permissions }) => !isOnlyInLessonReport(permissions) && !isTeacherView(permissions) && } />,
- ({ permissions }) => !isOnlyInLessonReport(permissions) && !isTeacherView(permissions) && } />,
- ({ permissions }) => !isOnlyInLessonReport(permissions) && !isTeacherView(permissions) && } />,
+ ({ permissions }) => (shouldShowLessonReports(permissions)) && } />,
+ ({ permissions }) => (shouldShowLessonReports(permissions)) && } />,
+ ({ permissions }) => isStandardView(permissions) && } />,
+ ({ permissions }) => isStandardView(permissions) && } />,
+ ({ permissions }) => isStandardView(permissions) && } />,
];
const menuGroups = [
- ({ permissions }) => (!isOnlyInLessonReport(permissions)) && (!isTeacherView(permissions)) && ({
+ ({ permissions }) => (isStandardView(permissions)) && ({
name: 'data', icon: , routes: [
} />
]
}),
- ({ permissions }) => (!isOnlyInLessonReport(permissions)) && (!isTeacherView(permissions)) && ({
+ ({ permissions }) => (isStandardView(permissions)) && ({
name: 'report', icon: , routes: [
} />,
} />,
diff --git a/client/src/RootDashboard.jsx b/client/src/RootDashboard.jsx
index e366cb9b..194425ff 100644
--- a/client/src/RootDashboard.jsx
+++ b/client/src/RootDashboard.jsx
@@ -1,9 +1,7 @@
import React from 'react';
-import { useDataProvider, SimpleForm, TextInput, useNotify, Toolbar, SaveButton } from 'react-admin';
-import { useObjectStore } from 'src/utils/storeUtil';
import { Dashboard } from 'src/GeneralLayout';
import { useIsTeacherView } from 'src/utils/appPermissions';
-import Button from '@mui/material/Button';
+import { TeacherGuard } from 'src/components/TeacherAccess';
export const RootDashboard = (props) => {
const isTeacherView = useIsTeacherView();
@@ -19,44 +17,3 @@ export const RootDashboard = (props) => {
return ;
}
}
-
-const TeacherGuard = ({ children }) => {
- const dataProvider = useDataProvider();
- const notify = useNotify();
- const { value: teacher, set: setTeacher, clear } = useObjectStore('teacher');
-
- if (teacher) {
- return
- שלום המורה {teacher.name}
-
- {children}
-
- }
-
- const handleSubmit = async (values) => {
- const { tz } = values;
- const result = await dataProvider.getList('teacher', {
- pagination: { page: 1, perPage: 1 },
- filter: { tz }
- });
- const teacher = result.data[0] || null;
-
- if (teacher) {
- setTeacher(teacher);
- }
- else {
- notify('Teacher not found', { type: 'warning' });
- }
- };
-
- return (
-
-
- }>
-
-
- );
-}
diff --git a/client/src/components/TeacherAccess.jsx b/client/src/components/TeacherAccess.jsx
new file mode 100644
index 00000000..2f690ce1
--- /dev/null
+++ b/client/src/components/TeacherAccess.jsx
@@ -0,0 +1,44 @@
+import { useDataProvider, SimpleForm, TextInput, useNotify, Toolbar, SaveButton } from 'react-admin';
+import { useObjectStore } from 'src/utils/storeUtil';
+import Button from '@mui/material/Button';
+
+export const TeacherGuard = ({ children }) => {
+ const dataProvider = useDataProvider();
+ const notify = useNotify();
+ const { value: teacher, set: setTeacher, clear } = useObjectStore('teacher');
+
+ if (teacher) {
+ return
+ שלום המורה {teacher.name}
+
+ {children}
+
+ }
+
+ const handleSubmit = async (values) => {
+ const { tz } = values;
+ const result = await dataProvider.getList('teacher', {
+ pagination: { page: 1, perPage: 1 },
+ filter: { tz }
+ });
+ const teacher = result.data[0] || null;
+
+ if (teacher) {
+ setTeacher(teacher);
+ }
+ else {
+ notify('Teacher not found', { type: 'warning' });
+ }
+ };
+
+ return (
+
+
+ }>
+
+
+ );
+}
\ No newline at end of file