Skip to content

Commit dbc11a9

Browse files
committed
Refactor AddStudentToTheBatchDialog in ResultBatch component
Moved the AddStudentToTheBatchDialog to the end of the ResultBatch component for improved user experience. Updated the term property to be converted to lowercase when creating term results for students. Enhanced the dialog with a button to open it, streamlining the process of adding new students.
1 parent 893e938 commit dbc11a9

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

app/src/components/resultBatch.tsx

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ function ResultBatch({ batch, term }: Props) {
5959

6060
return (
6161
<Box sx={{ margin: 4 }}>
62-
<AddStudentToTheBatchDialog term={term} batch={batch} />
6362
{Object.entries(grouped).map(([classKey, results]) => (
6463
<Box key={classKey} sx={{ marginBottom: 4 }}>
6564
<Accordion key={classKey}>
@@ -80,6 +79,7 @@ function ResultBatch({ batch, term }: Props) {
8079
</Accordion>
8180
</Box>
8281
))}
82+
<AddStudentToTheBatchDialog term={term} batch={batch} />
8383
</Box>
8484
);
8585
}
@@ -185,8 +185,8 @@ const AddStudentToTheBatchDialog = ({
185185
const handleAddStudent = async () => {
186186
const data: CreateTermResultForStudent = {
187187
admissionNo,
188-
term,
189-
batch,
188+
term: term.toLocaleLowerCase(),
189+
batch: batch,
190190
};
191191
const response = await handleCreateTermResultForStudent(data);
192192
if (response.success) {
@@ -201,19 +201,28 @@ const AddStudentToTheBatchDialog = ({
201201
}
202202
};
203203
return (
204-
<Dialog open={open} onClose={() => setOpen(false)}>
205-
<DialogTitle>Add Student to the Batch</DialogTitle>
206-
<DialogContent>
207-
<TextField
208-
label="Admission No"
209-
value={admissionNo}
210-
onChange={(e) => setAdmissionNo(e.target.value)}
211-
fullWidth
212-
/>
213-
<Button variant="contained" onClick={handleAddStudent}>
214-
Add
215-
</Button>
216-
</DialogContent>
217-
</Dialog>
204+
<>
205+
<Button
206+
variant="contained"
207+
sx={{ ml: "auto", mb: 2 }}
208+
onClick={() => setOpen(true)}
209+
>
210+
Add New Student
211+
</Button>
212+
<Dialog open={open} onClose={() => setOpen(false)}>
213+
<DialogTitle>Add Student to the Batch</DialogTitle>
214+
<DialogContent>
215+
<TextField
216+
label="Admission No"
217+
value={admissionNo}
218+
onChange={(e) => setAdmissionNo(e.target.value)}
219+
fullWidth
220+
/>
221+
<Button variant="contained" onClick={handleAddStudent}>
222+
Add
223+
</Button>
224+
</DialogContent>
225+
</Dialog>
226+
</>
218227
);
219228
};

0 commit comments

Comments
 (0)