Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions client/src/components/ApproveFullDays.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
useDataProvider,
useNotify,
useRefresh,
SimpleForm,
TextInput,
DateInput,
required,
maxLength,
} from 'react-admin';
import { ActionOrDialogButton } from '@shared/components/crudContainers/ActionOrDialogButton';
import CommonReferenceInput from '@shared/components/fields/CommonReferenceInput';
import { filterByUserIdAndYear } from '@shared/components/fields/CommonReferenceInputFilter';
import { handleActionSuccess, handleError } from '@shared/utils/notifyUtil';
import { defaultYearFilter } from '@shared/utils/yearFilter';

export const ApproveFullDays = ({ label }) => {
const dataProvider = useDataProvider();
const refresh = useRefresh();
const notify = useNotify();

const handleSave = async (values, onClose) => {
const row = {
studentReferenceId: values.studentReferenceId,
klassReferenceId: values.klassReferenceId,
fromDate: values.fromDate,
toDate: values.toDate,
};
try {
const response = await dataProvider.action(
'known_absence',
'approveByStudentDates',
{},
{ rows: [row], reason: values.reason, senderName: values.senderName, comment: values.comment },
);
handleActionSuccess(notify)(response);
refresh();
onClose?.();
} catch (err) {
handleError(notify)(err);
}
};

return (
<ActionOrDialogButton
label={label}
name="approveFullDays"
title="אישור ימים מלאים לתלמידה"
dialogContent={({ onClose }) => (
<SimpleForm onSubmit={(values) => handleSave(values, onClose)}>
<CommonReferenceInput
source="studentReferenceId"
reference="student_by_year"
validate={required()}
label="תלמידה"
filter={defaultYearFilter}
/>
<DateInput source="fromDate" validate={required()} label="מתאריך" />
<DateInput source="toDate" label="עד תאריך" helperText="ריק = יום אחד" />
<CommonReferenceInput
source="klassReferenceId"
reference="klass"
dynamicFilter={filterByUserIdAndYear}
label="כיתה (לא חובה)"
/>
<TextInput source="reason" validate={maxLength(500)} label="סיבה" />
<TextInput source="senderName" validate={maxLength(100)} label="שולחת" />
<TextInput source="comment" validate={maxLength(500)} label="הערה" />
</SimpleForm>
)}
/>
);
};
80 changes: 47 additions & 33 deletions client/src/components/ApprovedAbsencesUpload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Stack from '@mui/material/Stack';
import Box from '@mui/material/Box';
import Divider from '@mui/material/Divider';
import Typography from '@mui/material/Typography';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';

// React-Admin
import { usePermissions } from 'react-admin';
Expand All @@ -17,13 +19,15 @@ import PreviewSummary from './ApprovedAbsencesUpload/PreviewSummary';
import PreviewTable from './ApprovedAbsencesUpload/PreviewTable';
import ConfigurationForm from './ApprovedAbsencesUpload/ConfigurationForm';
import ActionButtons from './ApprovedAbsencesUpload/ActionButtons';
import StudentDatesUpload from './ApprovedAbsencesUpload/StudentDatesUpload';

// Custom Hooks
import { useFileProcessor } from './ApprovedAbsencesUpload/useFileProcessor';
import { useApplyAction } from './ApprovedAbsencesUpload/useApplyAction';

const ApprovedAbsencesUpload = () => {
const { permissions } = usePermissions();
const [mode, setMode] = useState('klass');
const [loading, setLoading] = useState(false);
const [previewData, setPreviewData] = useState(null);
const [fileName, setFileName] = useState('');
Expand Down Expand Up @@ -67,48 +71,58 @@ const ApprovedAbsencesUpload = () => {
העלאת חיסורים מאושרים
</Typography>
<Typography variant="body2" color="text.secondary">
העלאת קובץ Excel להוספת חיסורים מאושרים עבור כיתות שלמות
העלאת קובץ Excel להוספת חיסורים מאושרים עבור כיתות שלמות או תלמידות
</Typography>
</Box>

<Divider />
<Tabs value={mode} onChange={(e, value) => setMode(value)}>
<Tab value="klass" label="לפי כיתה" />
<Tab value="student" label="לפי תלמידה" />
</Tabs>

{/* File Upload Section */}
<FileUploadSection
fileInputRef={fileInputRef}
fileName={fileName}
loading={loading}
onFileSelect={handleFileSelect}
onDataParsed={handleFileUpload}
/>

{/* Preview Section */}
{previewData && !loading && (
{mode === 'student' && <StudentDatesUpload />}
{mode === 'klass' && (
<>
<Divider />

{/* Summary Statistics */}
<PreviewSummary previewData={previewData} />

{/* Preview Table */}
{previewData.details && previewData.details.length > 0 && (
<Box>
<PreviewTable data={previewData.details} />
</Box>
)}

<Divider />

{/* Configuration Form */}
<ConfigurationForm configValues={configValues} onChange={setConfigValues} />

{/* Action Buttons */}
<ActionButtons
{/* File Upload Section */}
<FileUploadSection
fileInputRef={fileInputRef}
fileName={fileName}
loading={loading}
matchedCount={previewData.matched}
onCancel={handleCancel}
onApply={handleApply}
onFileSelect={handleFileSelect}
onDataParsed={handleFileUpload}
/>

{/* Preview Section */}
{previewData && !loading && (
<>
<Divider />

{/* Summary Statistics */}
<PreviewSummary previewData={previewData} />

{/* Preview Table */}
{previewData.details && previewData.details.length > 0 && (
<Box>
<PreviewTable data={previewData.details} />
</Box>
)}

<Divider />

{/* Configuration Form */}
<ConfigurationForm configValues={configValues} onChange={setConfigValues} />

{/* Action Buttons */}
<ActionButtons
loading={loading}
matchedCount={previewData.matched}
onCancel={handleCancel}
onApply={handleApply}
/>
</>
)}
</>
)}
</Stack>
Expand Down
38 changes: 25 additions & 13 deletions client/src/components/ApprovedAbsencesUpload/ConfigurationForm.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
import { Form, TextInput } from 'react-admin';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import Typography from '@mui/material/Typography';

const ConfigurationForm = ({ configValues, onChange }) => {
const handleFormChange = (values) => {
onChange(values);
const handleChange = (event) => {
onChange({ ...configValues, [event.target.name]: event.target.value });
};

return (
<Box>
<Typography variant="h6" gutterBottom>
שלב 2: הגדרות
</Typography>
<Form record={configValues} onSubmit={() => {}} onChange={handleFormChange}>
<Stack spacing={2} sx={{ maxWidth: 600 }}>
<TextInput source="reason" label="סיבה" fullWidth />
<TextInput source="senderName" label="שם השולח" fullWidth />
<TextInput source="comment" label="הערה" multiline rows={3} fullWidth />
<Typography variant="caption" color="text.secondary">
הערה: תאריך ומספר חיסורים יילקחו מהדיווח המקורי
</Typography>
</Stack>
</Form>
<Stack spacing={2} sx={{ maxWidth: 600 }}>
<TextField name="reason" label="סיבה" value={configValues.reason} onChange={handleChange} fullWidth />
<TextField
name="senderName"
label="שם השולח"
value={configValues.senderName}
onChange={handleChange}
fullWidth
/>
<TextField
name="comment"
label="הערה"
value={configValues.comment}
onChange={handleChange}
multiline
rows={3}
fullWidth
/>
<Typography variant="caption" color="text.secondary">
הערה: תאריך ומספר חיסורים יילקחו מהדיווח המקורי
</Typography>
</Stack>
</Box>
);
};
Expand Down
Loading
Loading