Add UI for signing up members to classes
This commit is contained in:
parent
be6375566e
commit
a757534061
|
@ -138,9 +138,11 @@ export function ClassDetail(props) {
|
||||||
<div>
|
<div>
|
||||||
<Header size='large'>Class Details</Header>
|
<Header size='large'>Class Details</Header>
|
||||||
|
|
||||||
{isInstructor(user) && <Segment padded>
|
{(isAdmin(user) || clazz.instructor === user.id) &&
|
||||||
<InstructorClassDetail clazz={clazz} setClass={setClass} {...props} />
|
<Segment padded>
|
||||||
</Segment>}
|
<InstructorClassDetail clazz={clazz} setClass={setClass} {...props} />
|
||||||
|
</Segment>
|
||||||
|
}
|
||||||
|
|
||||||
<BasicTable>
|
<BasicTable>
|
||||||
<Table.Body>
|
<Table.Body>
|
||||||
|
|
|
@ -6,6 +6,7 @@ import moment from 'moment';
|
||||||
import './light.css';
|
import './light.css';
|
||||||
import { Button, Container, Checkbox, Divider, Dropdown, Form, Grid, Header, Icon, Image, Label, Menu, Message, Segment, Table } from 'semantic-ui-react';
|
import { Button, Container, Checkbox, Divider, Dropdown, Form, Grid, Header, Icon, Image, Label, Menu, Message, Segment, Table } from 'semantic-ui-react';
|
||||||
import { BasicTable, staticUrl, requester } from './utils.js';
|
import { BasicTable, staticUrl, requester } from './utils.js';
|
||||||
|
import { MembersDropdown } from './Members.js';
|
||||||
|
|
||||||
function AttendanceRow(props) {
|
function AttendanceRow(props) {
|
||||||
const { student, token, refreshClass } = props;
|
const { student, token, refreshClass } = props;
|
||||||
|
@ -61,8 +62,29 @@ function AttendanceRow(props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function InstructorClassAttendance(props) {
|
export function InstructorClassAttendance(props) {
|
||||||
const { clazz, token } = props;
|
const { clazz, token, refreshClass } = props;
|
||||||
|
const [input, setInput] = useState({});
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
|
||||||
|
|
||||||
|
const handleSubmit = (e) => {
|
||||||
|
if (loading) return;
|
||||||
|
setLoading(true);
|
||||||
|
const data = { ...input, attendance_status: 'Attended', session: clazz.id };
|
||||||
|
requester('/training/', 'POST', token, data)
|
||||||
|
.then(res => {
|
||||||
|
setLoading(false);
|
||||||
|
setError(false);
|
||||||
|
refreshClass();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
setLoading(false);
|
||||||
|
console.log(err);
|
||||||
|
setError(err.data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -77,6 +99,24 @@ export function InstructorClassAttendance(props) {
|
||||||
:
|
:
|
||||||
<p>No students yet.</p>
|
<p>No students yet.</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<Header size='small'>Add Student</Header>
|
||||||
|
|
||||||
|
<Form onSubmit={handleSubmit}>
|
||||||
|
<Form.Field error={error.member_id}>
|
||||||
|
<MembersDropdown
|
||||||
|
name='member_id'
|
||||||
|
value={input.member_id}
|
||||||
|
token={token}
|
||||||
|
onChange={handleValues}
|
||||||
|
initial='Find a member'
|
||||||
|
/>
|
||||||
|
</Form.Field>
|
||||||
|
|
||||||
|
<Form.Button loading={loading} error={error.non_field_errors}>
|
||||||
|
Submit
|
||||||
|
</Form.Button>
|
||||||
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user