Add loading spinners to buttons

This commit is contained in:
2020-09-15 19:40:29 +00:00
parent faf6969f7e
commit 3b8e0097a1
2 changed files with 17 additions and 3 deletions
+7
View File
@@ -68,8 +68,10 @@ class AttendanceSheet extends React.Component {
function AttendanceRow(props) {
const { student, token, refreshClass } = props;
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const handleMark = (newStatus) => {
setLoading(newStatus);
const data = { ...student, attendance_status: newStatus };
requester('/training/'+student.id+'/', 'PATCH', token, data)
.then(res => {
@@ -86,8 +88,13 @@ function AttendanceRow(props) {
onClick: () => handleMark(name),
toggle: true,
active: student.attendance_status === name,
loading: loading === name,
});
useEffect(() => {
setLoading(false);
}, [student.attendance_status]);
return (
<div className='attendance-row'>
<p>{student.student_name}{student.attendance_status === 'Waiting for payment' && ' (Waiting for payment)'}:</p>