SP-9 Dodanie filtrowania studentów bez grypy

This commit is contained in:
Patryk Drzewiński 2022-06-03 23:09:19 +02:00
parent 79aac03500
commit b03e369b73

View File

@ -1,4 +1,4 @@
import React from 'react' import React, { useState } from 'react'
import { useMutation, useQuery } from 'react-query' import { useMutation, useQuery } from 'react-query'
import { getStudents, uploadStudents } from '../../api/students' import { getStudents, uploadStudents } from '../../api/students'
@ -30,11 +30,16 @@ const Students = () => {
mutateUpload(payload) mutateUpload(payload)
} }
const [state, setState] = useState({
showGroupless: false
});
if (isStudentsLoading) { if (isStudentsLoading) {
return <div>Ładowanie</div> return <div>Ładowanie</div>
} }
return ( return (
<div> <div>
<div className="flex items-center">
<button className="bg-green-400 p-3 rounded-lg text-white font-extrabold hover:bg-green-300"> <button className="bg-green-400 p-3 rounded-lg text-white font-extrabold hover:bg-green-300">
Dodaj nowego studenta Dodaj nowego studenta
</button> </button>
@ -52,6 +57,17 @@ const Students = () => {
className="hidden" className="hidden"
onChange={handleOnChange} onChange={handleOnChange}
/> />
<label className="ml-auto">
<span className="slider round">Tylko niezapisani</span>
<input type="checkbox"
className="m-2 checked: bg-black-400"
onChange={() => setState({
...state,
showGroupless: !state.showGroupless
})}
/>
</label>
</div>
<div className="flex mx-auto mt-5 overflow-hidden overflow-x-auto border border-gray-100 rounded"> <div className="flex mx-auto mt-5 overflow-hidden overflow-x-auto border border-gray-100 rounded">
<table className="min-w-full text-sm divide-y divide-gray-200"> <table className="min-w-full text-sm divide-y divide-gray-200">
@ -65,7 +81,9 @@ const Students = () => {
</tr> </tr>
</thead> </thead>
<tbody className="divide-y divide-gray-100"> <tbody className="divide-y divide-gray-100">
{students?.data?.students?.map( {students?.data?.students?.filter(
(st) => (st.group === null || !state.showGroupless)
).map(
({ first_name, last_name, index, group, mode }) => ( ({ first_name, last_name, index, group, mode }) => (
<tr key={index}> <tr key={index}>
<td className="px-4 py-2 font-medium text-gray-900 whitespace-nowrap"> <td className="px-4 py-2 font-medium text-gray-900 whitespace-nowrap">