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}/`, `http://127.0.0.1:5000/api/coordinator/students/${index}/`,
) )
export const downloadStudents = () => export const downloadStudents = (mode: boolean) =>
axiosInstance.post( 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', responseType: 'blob',
}, },

View File

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

View File

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