diff --git a/client/src/components/BulkApproveAbsences.jsx b/client/src/components/BulkApproveAbsences.jsx new file mode 100644 index 00000000..2b57705d --- /dev/null +++ b/client/src/components/BulkApproveAbsences.jsx @@ -0,0 +1,58 @@ +import { useDataProvider, useNotify, useResourceContext, useRefresh, SimpleForm, TextInput, NumberInput, BooleanInput, DateInput, required, maxLength, ArrayInput, SimpleFormIterator } from 'react-admin'; +import { ActionOrDialogButton } from '@shared/components/crudContainers/ActionOrDialogButton'; +import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput'; +import { handleActionSuccess, handleError } from '@shared/utils/notifyUtil'; +import { isApprovedAbsencesBulk } from 'src/utils/appPermissions'; + +export const BulkApproveAbsences = ({ label, name, permissions }) => { + const dataProvider = useDataProvider(); + const resource = useResourceContext(); + const refresh = useRefresh(); + const notify = useNotify(); + if (!isApprovedAbsencesBulk(permissions)) return null; + + const handleSave = async (values, onClose) => { + const payload = values.approvedAbsences.map(row => ({ + studentReferenceId: values.studentReferenceId, + reportDate: values.reportDate, + absnceCode: values.absnceCode || null, + senderName: values.senderName || null, + reason: values.reason || null, + comment: values.comment || null, + isApproved: values.isApproved, + klassReferenceId: row.klassReferenceId, + lessonReferenceId: row.lessonReferenceId || null, + absnceCount: row.absnceCount, + })); + try { + const response = await dataProvider.createMany(resource, payload); + handleActionSuccess(notify)(response); + refresh(); + onClose?.(); + } + catch (err) { + handleError(notify)(err); + } + }; + + return ( + ( + handleSave(values, onClose)}> + + + + + + + + + + + + + + + + )} /> + ); +}; diff --git a/client/src/entities/known-absence.jsx b/client/src/entities/known-absence.jsx index a0dd05ce..5d02c746 100644 --- a/client/src/entities/known-absence.jsx +++ b/client/src/entities/known-absence.jsx @@ -7,6 +7,7 @@ import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput import { defaultYearFilter, yearChoices } from '@shared/utils/yearFilter'; import CommonAutocompleteInput from '@shared/components/fields/CommonAutocompleteInput'; import { CommonHebrewDateField } from '@shared/components/fields/CommonHebrewDateField'; +import { BulkApproveAbsences } from 'src/components/BulkApproveAbsences'; const filters = [ ({ isAdmin }) => isAdmin && , @@ -82,12 +83,21 @@ const importer = { fields: ['studentTz', 'klassId', 'lessonId', 'reportDate', 'absnceCount', 'absnceCode', 'senderName', 'reason', 'comment', 'isApproved'], } +const additionalListActions = [ + , +]; + const entity = { Datagrid, Inputs, filters, importer, filterDefaultValues, + additionalListActions, }; export default getResourceComponents(entity); diff --git a/client/src/utils/appPermissions.js b/client/src/utils/appPermissions.js index 2e941ea8..b98c9168 100644 --- a/client/src/utils/appPermissions.js +++ b/client/src/utils/appPermissions.js @@ -8,6 +8,7 @@ export const appPermissions = { inLessonReportStartWithTeacher: 'inLessonReport.startWithTeacher', absCountEffect: 'absCountEffect', lessonSignature: 'lessonSignature', + approvedAbsencesBulk:'approvedAbsencesBulk' }; export const isScannerUpload = (permissions) => hasPermissionLogic(permissions, appPermissions.scannerUpload); @@ -30,3 +31,6 @@ export const useIsAbsCountEffect = () => useHasPermission(appPermissions.absCoun export const isLessonSignature = (permissions) => isAdmin(permissions) || hasPermissionLogic(permissions, appPermissions.lessonSignature); export const useIsLessonSignature = () => useHasPermission(appPermissions.lessonSignature); + +export const isApprovedAbsencesBulk = (permissions) => isAdmin(permissions) || hasPermissionLogic(permissions, appPermissions.approvedAbsencesBulk); +export const useIsApprovedAbsencesBulk = () => useHasPermission(appPermissions.approvedAbsencesBulk); \ No newline at end of file