import React, { useState, useEffect } from 'react'; import { BrowserRouter as Router, Switch, Route, Link, useParams } from 'react-router-dom'; import './light.css'; import { Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react'; import moment from 'moment'; import { isInstructor, BasicTable, requester } from './utils.js'; import { NotFound, PleaseLogin } from './Misc.js'; import { InstructorClassDetail } from './InstructorClasses.js'; function ClassTable(props) { const { classes } = props; return ( Name Date Time Instructor Cost Students {classes.length ? classes.map((x, i) => {x.course_name} {moment.utc(x.datetime).local().format('ll')} {x.is_cancelled ? 'Cancelled' : moment.utc(x.datetime).local().format('LT')} {x.instructor_name} {x.cost === '0.00' ? 'Free' : '$'+x.cost} {x.student_count} {x.max_students && '/ '+x.max_students} ) :

None

}
); }; export function Classes(props) { const [classes, setClasses] = useState(false); const { token } = props; useEffect(() => { requester('/sessions/', 'GET', token) .then(res => { setClasses(res.results); }) .catch(err => { console.log(err); }); }, []); const now = new Date().toISOString(); return (
Class List
Upcoming
{classes ? x.datetime > now)} /> :

Loading...

}
Recent
{classes ? x.datetime < now)} /> :

Loading...

}
); }; export function ClassDetail(props) { const [clazz, setClass] = useState(false); const [error, setError] = useState(false); const { token, user } = props; const { id } = useParams(); useEffect(() => { requester('/sessions/'+id+'/', 'GET', token) .then(res => { setClass(res); }) .catch(err => { console.log(err); setError(true); }); }, []); return ( {!error ? clazz ?
Class Details
{isInstructor(user) && } Name: {clazz.course_name} Date: {moment.utc(clazz.datetime).local().format('ll')} Time: {clazz.is_cancelled ? 'Cancelled' : moment.utc(clazz.datetime).local().format('LT')} Instructor: {clazz.instructor_name} Cost: {clazz.cost === '0.00' ? 'Free' : '$'+clazz.cost} Students: {clazz.student_count} {clazz.max_students && '/ '+clazz.max_students}
Attendance
:

Loading...

: }
); };