Refactor leaders view

This commit is contained in:
adam-skowronek 2022-06-13 19:50:34 +02:00
parent a3dddd3751
commit 6779c66f86

View File

@ -36,6 +36,14 @@ const Leaders = () => {
getLeaders({ page, per_page: perPage }), getLeaders({ page, per_page: perPage }),
) )
const { mutate: mutateDelete } = useMutation(
'deleteLeader',
(index: number) => deleteLeader(index),
{
onSuccess: () => refetchLeaders(),
},
)
useEffect(() => { useEffect(() => {
setPage(1) setPage(1)
}, [perPage]) }, [perPage])
@ -79,18 +87,35 @@ const Leaders = () => {
</tr> </tr>
</thead> </thead>
<tbody className="divide-y divide-gray-100"> <tbody className="divide-y divide-gray-100">
{leaders?.data?.project_supervisors {leaders?.data?.project_supervisors.map(
.map(({ id, first_name, last_name, email, limit_group, count_group, mode }) => ( ({
id,
first_name,
last_name,
email,
limit_group,
count_groups,
mode,
}) => (
<tr key={id}> <tr key={id}>
<td>{first_name}</td> <td>{first_name}</td>
<td>{last_name}</td> <td>{last_name}</td>
<td>{email}</td> <td>{email}</td>
<td>{limit_group}</td> <td>{limit_group}</td>
<td>{count_group}</td> <td>{count_groups}</td>
<td>{mode==0 ? "Stacjonarny" : mode==1 ? "Niestacjonarny" : "Nie/stacjonarny"}</td> <td>
<td><button onClick={() => deleteLeader(id).then(() => refetchLeaders())}>X</button></td> {mode == 0
? 'Stacjonarny'
: mode == 1
? 'Niestacjonarny'
: 'Nie/stacjonarny'}
</td>
<td>
<button onClick={() => mutateDelete(id)}>X</button>
</td>
</tr> </tr>
))} ),
)}
</tbody> </tbody>
</table> </table>
</div> </div>
@ -135,4 +160,4 @@ const Leaders = () => {
) )
} }
export default Leaders; export default Leaders