@@ -13,7 +17,13 @@ export const RootDashboard = (props) => {
);
}
- else {
- return ;
+ else if (isStudentView) {
+ return (
+
+
+
+ );
}
+ else return ;
+
}
diff --git a/client/src/components/StudentView/StudentAccess.jsx b/client/src/components/StudentView/StudentAccess.jsx
new file mode 100644
index 00000000..bb1ccbfa
--- /dev/null
+++ b/client/src/components/StudentView/StudentAccess.jsx
@@ -0,0 +1,118 @@
+import React from "react";
+import { useDataProvider, SimpleForm, TextInput, useNotify, Toolbar, SaveButton, useResetStore } from "react-admin";
+import { useObjectStore } from "src/utils/storeUtil";
+import Button from "@mui/material/Button";
+import Card from "@mui/material/Card";
+import CardContent from "@mui/material/CardContent";
+import Box from "@mui/material/Box";
+import Typography from "@mui/material/Typography";
+import Avatar from "@mui/material/Avatar";
+import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
+import LogoutIcon from "@mui/icons-material/Logout";
+import Paper from "@mui/material/Paper";
+
+export const StudentGuard = ({ children }) => {
+ const dataProvider = useDataProvider();
+ const notify = useNotify();
+ const reset = useResetStore();
+ const { value: student, set: setStudent, clear } = useObjectStore("student");
+
+ const handleLogout = () => {
+ clear();
+ reset();
+ };
+
+ if (student) {
+ return (
+
+
+
+ שלום התלמידה {student.name}
+
+ }
+ >
+ התנתק
+
+
+ {children}
+
+ );
+ }
+
+ const handleSubmit = async (values) => {
+ const { tz } = values;
+ const result = await dataProvider.getList("student", {
+ pagination: { page: 1, perPage: 1 },
+ filter: { tz },
+ });
+ const student = result.data[0] || null;
+
+ if (student) {
+ setStudent(student);
+ } else {
+ notify("Student not found", { type: "warning" });
+ }
+ };
+
+ return (
+
+
+
+
+
+
+
+ כניסת תלמידה
+
+
+
+
+
+
+ }
+ >
+
+
+
+
+
+ );
+};
diff --git a/client/src/components/StudentView/student-event-report.jsx b/client/src/components/StudentView/student-event-report.jsx
new file mode 100644
index 00000000..79f1dfb0
--- /dev/null
+++ b/client/src/components/StudentView/student-event-report.jsx
@@ -0,0 +1,145 @@
+import React from 'react';
+import {
+ TextInput,
+ NumberInput,
+ DateInput,
+ BooleanInput,
+ required,
+ useNotify,
+ useResetStore,
+ useDataProvider,
+ useGetOne,
+ Create,
+ SimpleForm,
+ FormDataConsumer,
+ Loading,
+} from 'react-admin';
+import { filterByUserIdAndYear } from '@shared/components/fields/CommonReferenceInputFilter';
+import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput';
+import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter';
+import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput';
+import { handleActionSuccess, handleError } from '@shared/utils/notifyUtil';
+import { useObjectStore } from "src/utils/storeUtil";
+
+const DynamicFields = ({ absenceType, isLoading }) => {
+
+ if (isLoading) return ;
+ if (!absenceType?.requiredLabels?.length) return null;
+ return (
+
+ {absenceType.requiredLabels.map((label, index) => (
+
+ ))}
+
+ );
+};
+
+const formatPayload = (values, userId, studentId, absenceType) => {
+ const allowedLabels = absenceType?.requiredLabels || [];
+
+ const extraInfo = Object.keys(values)
+ .filter(key => {
+ if (!key.startsWith('dynamic_')) return false;
+ const label = key.replace('dynamic_', '');
+ return allowedLabels.includes(label) && values[key];
+ })
+ .map(key => {
+ const label = key.replace('dynamic_', '');
+ return `${label}: ${values[key]}`;
+ })
+ .join(' | ');
+
+ const cleanValues = { ...values };
+ Object.keys(cleanValues).forEach(key => {
+ if (key.startsWith('dynamic_')) delete cleanValues[key];
+ });
+
+ return {
+ ...cleanValues,
+ userId: userId,
+ studentReferenceId: studentId,
+ year: parseInt(defaultYearFilter.year),
+ reportDate: cleanValues.reportDate,
+ absnceCount: parseFloat(cleanValues.absnceCount) || 1,
+ isApproved: true,
+ reason: cleanValues.reason ? `${cleanValues.reason} [${extraInfo}]` : extraInfo,
+ };
+};
+
+const StudentEventReport = (props) => {
+ const dataProvider = useDataProvider();
+ const notify = useNotify();
+ const reset = useResetStore();
+ const { value: student, clear } = useObjectStore("student");
+ const [selectedAbsenceTypeId, setSelectedAbsenceTypeId] = React.useState(null);
+ const { data: absenceType, isLoading } = useGetOne(
+ 'absence_type',
+ { id: selectedAbsenceTypeId },
+ { enabled: !!selectedAbsenceTypeId }
+ );
+
+ const handleSave = async (values) => {
+ try {
+ const quota = absenceType?.quota;
+
+ if (quota) {
+ const { data: existingAbsences } = await dataProvider.getList('known_absence', {
+ pagination: { page: 1, perPage: 1000 },
+ filter: {
+ studentReferenceId: student.id,
+ absenceTypeId: values.absenceTypeId,
+ year: values.year
+ },
+ });
+
+ const currentTotal = existingAbsences.reduce((sum, item) => sum + (parseFloat(item.absnceCount) || 0), 0);
+ const requestedAmount = parseFloat(values.absnceCount || 1);
+
+ if (currentTotal + requestedAmount > quota) {
+ notify(
+ `חריגה מהמכסה! המכסה היא ${quota}. נוצלו ${currentTotal}, ניסיון להוסיף ${requestedAmount}.`,
+ { type: 'error', autoHideDuration: 10000 }
+ );
+ return;
+ }
+ }
+
+ const formattedData = formatPayload(values, student.userId, student.id, absenceType)
+ const response = await dataProvider.create('known_absence', { data: formattedData });
+ handleActionSuccess(notify)(response);
+ clear();
+ reset();
+ } catch (error) {
+ handleError(notify)(error);
+ }
+ };
+
+ return (
+
+
+
+ setSelectedAbsenceTypeId(e?.target?.value ?? e)} />
+
+ {() => (
+
+ )}
+
+
+
+
+
+
+
+
+
+ );
+};
+
+export default StudentEventReport;
\ No newline at end of file
diff --git a/client/src/domainTranslations.js b/client/src/domainTranslations.js
index 45972b2b..9f0cc81e 100644
--- a/client/src/domainTranslations.js
+++ b/client/src/domainTranslations.js
@@ -141,7 +141,7 @@ export default {
reason: 'סיבה',
comment: 'הערה',
isApproved: 'מאושר',
- absenceTypeId: 'סוג אירוע',
+ absenceTypeId: 'סוג אירוע',
}
},
lesson: {
@@ -213,6 +213,7 @@ export default {
name: 'אירוע |||| אירועים',
fields: {
...generalResourceFieldsTranslation,
+ absenceTypeId: 'סוג אירוע',
name: 'שם האירוע',
quota: 'מכסה שנתית',
requiredLabels: 'שדות חובה לדיווח',
diff --git a/client/src/utils/appPermissions.js b/client/src/utils/appPermissions.js
index c938a286..b7c25e46 100644
--- a/client/src/utils/appPermissions.js
+++ b/client/src/utils/appPermissions.js
@@ -12,6 +12,7 @@ export const appPermissions = {
teacherView: 'teacherView',
transportation: 'transportation',
absenceType: 'absenceType',
+ studentView: 'studentView',
};
export const isScannerUpload = (permissions) => hasPermissionLogic(permissions, appPermissions.scannerUpload);
@@ -45,5 +46,8 @@ export const isTransportation = (permissions) => hasPermissionLogic(permissions,
export const useIsTransportation = () => useHasPermission(appPermissions.transportation);
export const isAbsenceType = (permissions) => hasPermissionLogic(permissions, appPermissions.absenceType);
-export const useIsisAbsenceType = () => useHasPermission(appPermissions.absenceType);
+export const useIsAbsenceType = () => useHasPermission(appPermissions.absenceType);
+
+export const isStudentView = (permissions) => hasPermissionLogic(permissions, appPermissions.studentView);
+export const useIsStudentView = () => useHasPermission(appPermissions.studentView);