Add available supervisor filter

This commit is contained in:
adam-skowronek 2022-06-13 21:24:17 +02:00
parent 5a49e87a63
commit 1459df0c6a
3 changed files with 48 additions and 17 deletions

View File

@ -5,6 +5,7 @@ export const getEnrollmentList = (
page: number page: number
per_page: number per_page: number
name: string name: string
mode: boolean
}>, }>,
) => ) =>
axiosInstance.get<{ axiosInstance.get<{

View File

@ -104,9 +104,9 @@ const Leaders = () => {
<td>{limit_group}</td> <td>{limit_group}</td>
<td>{count_groups}</td> <td>{count_groups}</td>
<td> <td>
{mode == 0 {mode === 0
? 'Stacjonarny' ? 'Stacjonarny'
: mode == 1 : mode === 1
? 'Niestacjonarny' ? 'Niestacjonarny'
: 'Nie/stacjonarny'} : 'Nie/stacjonarny'}
</td> </td>

View File

@ -1,17 +1,43 @@
import { useState } from 'react'
import { useQuery } from 'react-query' import { useQuery } from 'react-query'
import { getEnrollmentList } from '../../api/enrollment' import { getEnrollmentList } from '../../api/enrollment'
const Enrollment = () => { const Enrollment = () => {
const { isLoading, data: enrollmentData } = useQuery(['enrollment'], () => const [showAvailable, setShowAvailable] = useState(false)
getEnrollmentList({ per_page: 1000 }), const [mode, setMode] = useState(true)
const { isLoading, data: enrollmentData } = useQuery(
['enrollment', mode],
() => getEnrollmentList({ per_page: 1000, mode }),
) )
if (isLoading) { if (isLoading) {
return <div>Ładowanie</div> return <div>Ładowanie</div>
} }
return ( return (
<div> <div>
<div className="flex items-center"></div> <div className="flex items-center justify-between">
<h2>Opiekunowie</h2> <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>
<input
type="checkbox"
className="checkbox checkbox-xs md:checkbox-md"
onChange={() => setMode(!mode)}
checked={mode}
/>
</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)}
/>
</label>
</div>
</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 table table-compact"> <table className="min-w-full table table-compact">
<thead> <thead>
@ -24,7 +50,11 @@ const Enrollment = () => {
</tr> </tr>
</thead> </thead>
<tbody className="divide-y divide-gray-100"> <tbody className="divide-y divide-gray-100">
{enrollmentData?.data?.project_supervisors?.map( {enrollmentData?.data?.project_supervisors
?.filter(
({ available_groups }) => available_groups || !showAvailable,
)
.map(
({ first_name, last_name, email, mode, available_groups }) => ( ({ first_name, last_name, email, mode, available_groups }) => (
<tr key={email}> <tr key={email}>
<td>{first_name}</td> <td>{first_name}</td>