Add export by mode, update checkboxes

This commit is contained in:
adam-skowronek 2022-06-22 21:12:14 +02:00
parent 24457a252a
commit e946ec41ac
3 changed files with 48 additions and 30 deletions

View File

@ -45,9 +45,11 @@ export const deleteStudent = (index: number) =>
`http://127.0.0.1:5000/api/coordinator/students/${index}/`,
)
export const downloadStudents = () =>
export const downloadStudents = (mode: boolean) =>
axiosInstance.post(
'http://127.0.0.1:5000/api/coordinator/students/download/',
`http://127.0.0.1:5000/api/coordinator/students/download/?mode=${Number(
mode,
)}`,
{
responseType: 'blob',
},

View File

@ -45,7 +45,7 @@ const Students = () => {
const { mutate: mutateDownload } = useMutation(
'downloadStudents',
() => downloadStudents(),
(mode: boolean) => downloadStudents(mode),
{
onSuccess: (res) => {
const url = window.URL.createObjectURL(new Blob([res.data]))
@ -111,12 +111,12 @@ const Students = () => {
/>
<button
className="btn btn-xs md:btn-md"
onClick={() => mutateDownload()}
onClick={() => mutateDownload(mode)}
>
Eksportuj
</button>
</div>
<div className="flex">
<div className="flex items-center">
<select className="select select-xs md:select-md select-bordered mr-3">
{perPageOptions.map(({ value, label }) => (
<option key={value} onClick={() => setPerPage(value)}>
@ -124,22 +124,31 @@ const Students = () => {
</option>
))}
</select>
<label className="label">
<span className="mr-2 text-xs md:text-base">Stacjonarni</span>
<label className="label justify-start gap-2">
<input
type="checkbox"
className="checkbox checkbox-xs md:checkbox-md"
onChange={() => setMode(!mode)}
type="radio"
className="radio radio-xs md:radio-md"
onChange={() => setMode(true)}
checked={mode}
/>
<span className="text-xs md:text-base">Stacjonarni</span>
</label>
<label className="label justify-start gap-2">
<input
type="radio"
className="radio radio-xs md:radio-md"
onChange={() => setMode(false)}
checked={!mode}
/>
<span className="text-xs md:text-base">Niestacjonarni</span>
</label>
<label className="label">
<span className="mr-2 text-xs md:text-base">Tylko niezapisani</span>
<input
type="checkbox"
className="checkbox checkbox-xs md:checkbox-md"
onChange={() => setShowGroupless(!showGroupless)}
/>
<span className="ml-2 text-xs md:text-base">Tylko niezapisani</span>
</label>
</div>
</div>

View File

@ -17,24 +17,33 @@ const Enrollment = () => {
<div className="flex items-center justify-between">
<h2 className="text-xl font-bold">Opiekunowie:</h2>
<div className="flex gap-3">
<label className="label">
<span className="mr-2 text-xs md:text-base">Stacjonarni</span>
<label className="label justify-start gap-2">
<input
type="checkbox"
className="checkbox checkbox-xs md:checkbox-md"
onChange={() => setMode(!mode)}
type="radio"
className="radio radio-xs md:radio-md"
onChange={() => setMode(true)}
checked={mode}
/>
<span className="text-xs md:text-base">Stacjonarni</span>
</label>
<label className="label justify-start gap-2">
<input
type="radio"
className="radio radio-xs md:radio-md"
onChange={() => setMode(false)}
checked={!mode}
/>
<span className="text-xs md:text-base">Niestacjonarni</span>
</label>
<label className="label">
<span className="mr-2 text-xs md:text-base">
Pokaż wolne miejsca
</span>
<input
type="checkbox"
className="checkbox checkbox-xs md:checkbox-md"
onChange={() => setShowAvailable(!showAvailable)}
/>
<span className="ml-2 text-xs md:text-base">
Pokaż wolne miejsca
</span>
</label>
</div>
</div>
@ -54,17 +63,15 @@ const Enrollment = () => {
?.filter(
({ available_groups }) => available_groups || !showAvailable,
)
.map(
({ first_name, last_name, email, available_groups }) => (
<tr key={email}>
<td>{first_name}</td>
<td>{last_name}</td>
<td>{email}</td>
<td>{mode ? 'Stacjonarny' : 'Niestacjonarny'}</td>
<td>{available_groups}</td>
</tr>
),
)}
.map(({ first_name, last_name, email, available_groups }) => (
<tr key={email}>
<td>{first_name}</td>
<td>{last_name}</td>
<td>{email}</td>
<td>{mode ? 'Stacjonarny' : 'Niestacjonarny'}</td>
<td>{available_groups}</td>
</tr>
))}
</tbody>
</table>
</div>