2020-01-18 01:27:56 +00:00
|
|
|
import React, { useState, useEffect, useReducer } from 'react';
|
2022-07-13 04:18:33 +00:00
|
|
|
import { Link, useParams } from 'react-router-dom';
|
2020-01-10 06:24:37 +00:00
|
|
|
import './light.css';
|
2022-09-06 21:56:51 +00:00
|
|
|
import { Label, Button, Container, Dropdown, Form, Header, Icon, Input, Segment, Table } from 'semantic-ui-react';
|
2020-02-24 04:07:18 +00:00
|
|
|
import moment from 'moment-timezone';
|
2022-07-13 04:18:33 +00:00
|
|
|
import { apiUrl, isAdmin, getInstructor, BasicTable, requester, useIsMobile } from './utils.js';
|
|
|
|
import { NotFound } from './Misc.js';
|
2020-01-16 09:09:45 +00:00
|
|
|
import { InstructorClassDetail, InstructorClassAttendance } from './InstructorClasses.js';
|
2020-02-21 06:10:52 +00:00
|
|
|
import { PayPalPayNow } from './PayPal.js';
|
2022-01-28 07:47:25 +00:00
|
|
|
import { tags } from './Courses.js';
|
2020-01-10 06:24:37 +00:00
|
|
|
|
2020-01-10 07:39:05 +00:00
|
|
|
function ClassTable(props) {
|
|
|
|
const { classes } = props;
|
2022-04-26 21:26:13 +00:00
|
|
|
const isMobile = useIsMobile();
|
2020-01-10 07:39:05 +00:00
|
|
|
|
2022-01-27 22:46:10 +00:00
|
|
|
const now = new Date().toISOString();
|
|
|
|
|
2022-04-26 21:26:13 +00:00
|
|
|
return (isMobile ?
|
|
|
|
<Table basic='very'>
|
|
|
|
<Table.Body>
|
|
|
|
{classes.length ?
|
|
|
|
classes.map(x =>
|
|
|
|
<Table.Row key={x.id} active={x.datetime < now || x.is_cancelled}>
|
|
|
|
<Table.Cell>{x.course_data.name}</Table.Cell>
|
|
|
|
<Table.Cell>
|
|
|
|
Date: <Link to={'/classes/'+x.id}>
|
|
|
|
{moment.utc(x.datetime).tz('America/Edmonton').format('ll')}
|
|
|
|
</Link>
|
|
|
|
<span style={{float: 'right'}}>
|
|
|
|
Time: {x.is_cancelled ? 'Cancelled' : moment.utc(x.datetime).tz('America/Edmonton').format('LT')}
|
|
|
|
</span>
|
|
|
|
</Table.Cell>
|
|
|
|
<Table.Cell>
|
|
|
|
Cost: {x.cost === '0.00' ? 'Free' : '$'+x.cost}
|
|
|
|
<span style={{float: 'right'}}>
|
|
|
|
Students: {!!x.max_students ?
|
|
|
|
x.max_students <= x.student_count ?
|
|
|
|
'Full'
|
|
|
|
:
|
|
|
|
x.student_count + ' / ' + x.max_students
|
|
|
|
:
|
|
|
|
x.student_count
|
|
|
|
}
|
|
|
|
</span>
|
|
|
|
</Table.Cell>
|
|
|
|
<Table.Cell>Instructor: {getInstructor(x)}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
)
|
|
|
|
:
|
|
|
|
<Table.Row>None</Table.Row>
|
|
|
|
}
|
|
|
|
</Table.Body>
|
|
|
|
</Table>
|
|
|
|
:
|
2020-01-10 07:39:05 +00:00
|
|
|
<Table basic='very'>
|
|
|
|
<Table.Header>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.HeaderCell>Name</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Date</Table.HeaderCell>
|
2020-01-10 23:56:10 +00:00
|
|
|
<Table.HeaderCell>Time</Table.HeaderCell>
|
2020-01-10 07:39:05 +00:00
|
|
|
<Table.HeaderCell>Instructor</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Cost</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Students</Table.HeaderCell>
|
|
|
|
</Table.Row>
|
|
|
|
</Table.Header>
|
|
|
|
|
|
|
|
<Table.Body>
|
|
|
|
{classes.length ?
|
2020-01-18 01:36:53 +00:00
|
|
|
classes.map(x =>
|
2022-01-27 22:46:10 +00:00
|
|
|
<Table.Row key={x.id} active={x.datetime < now || x.is_cancelled}>
|
|
|
|
<Table.Cell> {x.course_data.name}</Table.Cell>
|
2020-01-10 07:39:05 +00:00
|
|
|
<Table.Cell>
|
|
|
|
<Link to={'/classes/'+x.id}>
|
2020-02-24 04:07:18 +00:00
|
|
|
{moment.utc(x.datetime).tz('America/Edmonton').format('ll')}
|
2020-01-10 07:39:05 +00:00
|
|
|
</Link>
|
|
|
|
</Table.Cell>
|
2020-02-24 04:07:18 +00:00
|
|
|
<Table.Cell>{x.is_cancelled ? 'Cancelled' : moment.utc(x.datetime).tz('America/Edmonton').format('LT')}</Table.Cell>
|
2020-07-18 22:15:53 +00:00
|
|
|
<Table.Cell>{getInstructor(x)}</Table.Cell>
|
2020-01-10 07:39:05 +00:00
|
|
|
<Table.Cell>{x.cost === '0.00' ? 'Free' : '$'+x.cost}</Table.Cell>
|
2022-01-27 22:46:10 +00:00
|
|
|
<Table.Cell>
|
|
|
|
{!!x.max_students ?
|
|
|
|
x.max_students <= x.student_count ?
|
|
|
|
'Full'
|
|
|
|
:
|
|
|
|
x.student_count + ' / ' + x.max_students
|
|
|
|
:
|
|
|
|
x.student_count
|
|
|
|
}
|
|
|
|
</Table.Cell>
|
2020-01-10 07:39:05 +00:00
|
|
|
</Table.Row>
|
|
|
|
)
|
|
|
|
:
|
2020-01-19 08:59:16 +00:00
|
|
|
<Table.Row><Table.Cell>None</Table.Cell></Table.Row>
|
2020-01-10 07:39:05 +00:00
|
|
|
}
|
|
|
|
</Table.Body>
|
|
|
|
</Table>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-04 01:27:50 +00:00
|
|
|
function NewClassTableCourse(props) {
|
|
|
|
const {course, classes, token, user, refreshUser} = props;
|
|
|
|
const [error, setError] = useState(false);
|
|
|
|
const [loading, setLoading] = useState(false);
|
2022-09-05 21:32:56 +00:00
|
|
|
const [interested, setInterested] = useState(course.num_interested || 0);
|
2022-05-04 01:27:50 +00:00
|
|
|
|
|
|
|
const handleInterest = () => {
|
|
|
|
if (loading) return;
|
|
|
|
setLoading(true);
|
|
|
|
const data = { course: course.id };
|
|
|
|
requester('/interest/', 'POST', token, data)
|
|
|
|
.then(res => {
|
|
|
|
setError(false);
|
|
|
|
refreshUser();
|
2022-09-05 21:32:56 +00:00
|
|
|
setInterested(interested+1);
|
2022-05-04 01:27:50 +00:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
setError(true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const now = new Date().toISOString();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Segment style={{ margin: '1rem 1rem 0 0', width: '22rem' }}>
|
|
|
|
<Header size='small'>
|
|
|
|
<Link to={'/courses/'+course.id}>
|
|
|
|
{course.name}
|
|
|
|
</Link>
|
|
|
|
</Header>
|
|
|
|
|
|
|
|
<div className='byline'>
|
|
|
|
<div className='tags'>
|
|
|
|
{!!course.tags && course.tags.split(',').map(name =>
|
2022-05-07 06:28:33 +00:00
|
|
|
<Label key={name} color={tags[name]} tag size='small'>
|
2022-05-04 01:27:50 +00:00
|
|
|
{name}
|
|
|
|
</Label>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{user &&
|
|
|
|
<div className='interest'>
|
2022-05-05 20:26:56 +00:00
|
|
|
{user.interests.filter(x => !x.satisfied_by).map(x => x.course).includes(course.id) ?
|
2022-09-05 21:32:56 +00:00
|
|
|
<Button
|
|
|
|
size='tiny'
|
|
|
|
color='green'
|
|
|
|
>
|
|
|
|
{interested} interested
|
|
|
|
</Button>
|
2022-05-04 01:27:50 +00:00
|
|
|
:
|
|
|
|
<Button
|
|
|
|
size='tiny'
|
|
|
|
loading={loading}
|
|
|
|
onClick={handleInterest}
|
|
|
|
>
|
2022-09-05 21:32:56 +00:00
|
|
|
{interested} interested
|
2022-05-04 01:27:50 +00:00
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{error && <p>Error.</p>}
|
|
|
|
|
|
|
|
{classes ?
|
|
|
|
<Table compact unstackable singleLine basic='very'>
|
|
|
|
<Table.Header>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.HeaderCell>Date</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Cost</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Students</Table.HeaderCell>
|
|
|
|
</Table.Row>
|
|
|
|
</Table.Header>
|
|
|
|
|
|
|
|
<Table.Body>
|
|
|
|
{classes.map(x =>
|
|
|
|
<Table.Row key={x.id} active={x.datetime < now || x.is_cancelled}>
|
|
|
|
<Table.Cell>
|
|
|
|
<Link to={'/classes/'+x.id}>
|
|
|
|
{moment.utc(x.datetime).tz('America/Edmonton').format(' MMM Do')}
|
|
|
|
</Link>
|
|
|
|
{' - '}{x.is_cancelled ? 'Cancelled' : moment.utc(x.datetime).tz('America/Edmonton').format('LT')}
|
|
|
|
</Table.Cell>
|
|
|
|
|
2022-09-05 22:14:58 +00:00
|
|
|
<Table.Cell>{x.cost === '0.00' ? 'Free' : '$'+x.cost.slice(0,-3)}</Table.Cell>
|
2022-05-04 01:27:50 +00:00
|
|
|
|
|
|
|
<Table.Cell>
|
|
|
|
{!!x.max_students ?
|
|
|
|
x.max_students <= x.student_count ?
|
|
|
|
'Full'
|
|
|
|
:
|
|
|
|
x.student_count + ' / ' + x.max_students
|
|
|
|
:
|
|
|
|
x.student_count
|
|
|
|
}
|
|
|
|
</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
)}
|
|
|
|
</Table.Body>
|
|
|
|
</Table>
|
|
|
|
:
|
|
|
|
<>
|
|
|
|
<p/>
|
|
|
|
<p>No upcoming classes.</p>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
</Segment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-27 22:46:10 +00:00
|
|
|
function NewClassTable(props) {
|
2022-05-04 01:27:50 +00:00
|
|
|
const { classes, courses, token, user, refreshUser } = props;
|
2022-01-27 22:46:10 +00:00
|
|
|
|
|
|
|
let sortedClasses = [];
|
2022-04-26 03:06:51 +00:00
|
|
|
let seenCourseIds = [];
|
2022-09-05 21:32:56 +00:00
|
|
|
if (classes.length && courses.length) {
|
2022-01-27 22:46:10 +00:00
|
|
|
for (const clazz of classes) {
|
|
|
|
const course_data = clazz.course_data;
|
|
|
|
const course = sortedClasses.find(x => x?.course?.id === course_data?.id);
|
|
|
|
|
|
|
|
if (course) {
|
|
|
|
course.classes.push(clazz);
|
|
|
|
} else {
|
|
|
|
sortedClasses.push({
|
2022-09-05 21:32:56 +00:00
|
|
|
course: courses.find(x => x.id === course_data.id),
|
2022-01-27 22:46:10 +00:00
|
|
|
classes: [clazz],
|
|
|
|
});
|
2022-04-26 03:06:51 +00:00
|
|
|
seenCourseIds.push(
|
|
|
|
course_data.id
|
|
|
|
);
|
2022-01-27 22:46:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-04-26 03:06:51 +00:00
|
|
|
<div className='newclasstable'>
|
2022-01-27 22:46:10 +00:00
|
|
|
{sortedClasses.map(x =>
|
2022-05-07 06:28:33 +00:00
|
|
|
<NewClassTableCourse
|
|
|
|
key={x.course.id}
|
|
|
|
course={x.course}
|
|
|
|
classes={x.classes}
|
|
|
|
token={token}
|
|
|
|
user={user}
|
|
|
|
refreshUser={refreshUser}
|
|
|
|
/>
|
2022-01-27 22:46:10 +00:00
|
|
|
)}
|
2022-04-26 03:06:51 +00:00
|
|
|
|
|
|
|
{courses.filter(x => !seenCourseIds.includes(x.id)).map(x =>
|
2022-05-07 06:28:33 +00:00
|
|
|
<NewClassTableCourse
|
|
|
|
key={x.id}
|
|
|
|
course={x}
|
|
|
|
classes={false}
|
|
|
|
token={token}
|
|
|
|
user={user}
|
|
|
|
refreshUser={refreshUser}
|
|
|
|
/>
|
2022-04-26 03:06:51 +00:00
|
|
|
)}
|
2022-01-27 22:46:10 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-02-17 00:19:44 +00:00
|
|
|
let classesCache = false;
|
2022-01-27 22:46:10 +00:00
|
|
|
let sortCache = true;
|
2022-01-28 07:47:25 +00:00
|
|
|
let tagFilterCache = false;
|
2020-02-17 00:19:44 +00:00
|
|
|
|
2022-01-26 04:21:47 +00:00
|
|
|
export function ClassFeed(props) {
|
|
|
|
const [classes, setClasses] = useState(classesCache);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const get = async() => {
|
|
|
|
requester('/sessions/', 'GET', '')
|
|
|
|
.then(res => {
|
|
|
|
setClasses(res.results);
|
|
|
|
classesCache = res.results;
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
get();
|
|
|
|
const interval = setInterval(get, 60000);
|
|
|
|
return () => clearInterval(interval);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const now = new Date().toISOString();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<p/>
|
|
|
|
|
|
|
|
<Header size='large'>Upcoming Protospace Classes</Header>
|
|
|
|
|
|
|
|
{classes ?
|
|
|
|
<ClassTable classes={classes.filter(x => x.datetime > now).sort((a, b) => a.datetime > b.datetime ? 1 : -1)} />
|
|
|
|
:
|
|
|
|
<p>Loading...</p>
|
|
|
|
}
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-01-10 06:24:37 +00:00
|
|
|
export function Classes(props) {
|
2020-02-17 00:19:44 +00:00
|
|
|
const [classes, setClasses] = useState(classesCache);
|
2022-05-07 06:28:33 +00:00
|
|
|
const [courses, setCourses] = useState(false);
|
2022-09-06 21:56:51 +00:00
|
|
|
const [search, setSearch] = useState('');
|
2022-01-27 22:46:10 +00:00
|
|
|
const [sortByCourse, setSortByCourse] = useState(sortCache);
|
2022-01-28 07:47:25 +00:00
|
|
|
const [tagFilter, setTagFilter] = useState(tagFilterCache);
|
2022-05-04 01:27:50 +00:00
|
|
|
const { token, user, refreshUser } = props;
|
2020-01-10 06:24:37 +00:00
|
|
|
|
2022-04-26 03:06:51 +00:00
|
|
|
useEffect(() => {
|
|
|
|
requester('/courses/', 'GET', token)
|
|
|
|
.then(res => {
|
|
|
|
setCourses(res.results);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
2020-01-10 06:24:37 +00:00
|
|
|
useEffect(() => {
|
|
|
|
requester('/sessions/', 'GET', token)
|
|
|
|
.then(res => {
|
|
|
|
setClasses(res.results);
|
2020-02-17 00:19:44 +00:00
|
|
|
classesCache = res.results;
|
2020-01-10 06:24:37 +00:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
2022-01-28 07:47:25 +00:00
|
|
|
const byTeaching = (x) => x.instructor_id === user.member.id;
|
|
|
|
const byDate = (a, b) => a.datetime > b.datetime ? 1 : -1;
|
2022-04-26 03:06:51 +00:00
|
|
|
const classesByTag = (x) => tagFilter ? x.course_data.tags.includes(tagFilter) : true;
|
|
|
|
const coursesByTag = (x) => tagFilter ? x.tags.includes(tagFilter) : true;
|
2022-09-06 21:56:51 +00:00
|
|
|
const classesBySearch = (x) => search ? x.course_data.name.toLowerCase().includes(search.toLowerCase()) : true;
|
|
|
|
const coursesBySearch = (x) => search ? x.name.toLowerCase().includes(search.toLowerCase()) : true;
|
2022-01-28 07:47:25 +00:00
|
|
|
|
2020-01-10 06:24:37 +00:00
|
|
|
return (
|
|
|
|
<Container>
|
2020-01-10 07:39:05 +00:00
|
|
|
<Header size='large'>Class List</Header>
|
2020-01-18 01:27:56 +00:00
|
|
|
|
2021-09-18 20:33:40 +00:00
|
|
|
<p><Link to={'/courses'}>Click here to view the list of all courses.</Link></p>
|
|
|
|
|
2022-01-28 07:47:25 +00:00
|
|
|
{!!user && !!classes.length && !!classes.filter(byTeaching).length &&
|
2022-01-27 22:46:10 +00:00
|
|
|
<>
|
|
|
|
<Header size='medium'>Classes You're Teaching</Header>
|
2022-01-28 07:47:25 +00:00
|
|
|
<ClassTable classes={classes.slice().filter(byTeaching).sort(byDate)} />
|
2022-01-27 22:46:10 +00:00
|
|
|
</>
|
2020-01-10 07:39:05 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 07:47:25 +00:00
|
|
|
<p>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
setSortByCourse(true);
|
|
|
|
sortCache = true;
|
|
|
|
}}
|
|
|
|
active={sortByCourse}
|
|
|
|
>
|
|
|
|
Sort by course
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
setSortByCourse(false);
|
|
|
|
sortCache = false;
|
|
|
|
}}
|
|
|
|
active={!sortByCourse}
|
|
|
|
>
|
|
|
|
Sort by date
|
|
|
|
</Button>
|
2022-09-06 21:56:51 +00:00
|
|
|
|
|
|
|
<Input focus icon='search'
|
|
|
|
placeholder='Search...'
|
|
|
|
value={search}
|
|
|
|
onChange={(event) => setSearch(event.target.value)}
|
|
|
|
aria-label='search products'
|
|
|
|
style={{ margin: '0.5rem 0.5rem 0.5rem 0' }}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{!!search.length &&
|
|
|
|
<Button
|
|
|
|
content='Clear'
|
|
|
|
onClick={() => setSearch('')}
|
|
|
|
/>
|
|
|
|
}
|
2022-01-28 07:47:25 +00:00
|
|
|
</p>
|
|
|
|
|
2022-05-07 06:28:33 +00:00
|
|
|
<p>Filter by tag:</p>
|
|
|
|
|
|
|
|
<div className='coursetags'>
|
|
|
|
<div
|
|
|
|
className='labelbox'
|
|
|
|
style={{borderColor: tagFilter === false ? 'black' : 'transparent'}}
|
|
|
|
>
|
|
|
|
<Label
|
|
|
|
onClick={() => {
|
|
|
|
setTagFilter(false);
|
|
|
|
tagFilterCache = false;
|
|
|
|
}}
|
|
|
|
as='a'
|
|
|
|
tag
|
|
|
|
>
|
|
|
|
No Filter
|
|
|
|
</Label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{Object.entries(tags).map(([name, color]) =>
|
2022-04-26 20:27:26 +00:00
|
|
|
<div
|
2022-05-07 06:28:33 +00:00
|
|
|
key={name}
|
2022-04-26 20:27:26 +00:00
|
|
|
className='labelbox'
|
2022-05-07 06:28:33 +00:00
|
|
|
style={{borderColor: tagFilter === name ? 'black' : 'transparent'}}
|
2022-04-26 20:27:26 +00:00
|
|
|
>
|
2022-01-28 07:47:25 +00:00
|
|
|
<Label
|
|
|
|
onClick={() => {
|
2022-05-07 06:28:33 +00:00
|
|
|
setTagFilter(name);
|
|
|
|
tagFilterCache = name;
|
2022-01-28 07:47:25 +00:00
|
|
|
}}
|
|
|
|
as='a'
|
2022-05-07 06:28:33 +00:00
|
|
|
color={color}
|
2022-01-28 07:47:25 +00:00
|
|
|
tag
|
|
|
|
>
|
2022-05-07 06:28:33 +00:00
|
|
|
{name}
|
2022-01-28 07:47:25 +00:00
|
|
|
</Label>
|
2022-04-26 20:27:26 +00:00
|
|
|
</div>
|
2022-05-07 06:28:33 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2020-09-21 20:01:47 +00:00
|
|
|
|
2022-04-26 03:06:51 +00:00
|
|
|
{classes.length && courses.length ?
|
2022-01-27 22:46:10 +00:00
|
|
|
sortByCourse ?
|
2022-04-26 03:06:51 +00:00
|
|
|
<NewClassTable
|
2022-09-06 21:56:51 +00:00
|
|
|
classes={classes.filter(classesByTag).filter(classesBySearch)}
|
|
|
|
courses={courses.filter(coursesByTag).filter(coursesBySearch)}
|
2022-05-04 01:27:50 +00:00
|
|
|
token={token}
|
|
|
|
user={user}
|
|
|
|
refreshUser={refreshUser}
|
2022-04-26 03:06:51 +00:00
|
|
|
/>
|
2022-01-27 22:46:10 +00:00
|
|
|
:
|
2022-09-06 21:56:51 +00:00
|
|
|
<ClassTable classes={classes.slice().filter(classesByTag).filter(classesBySearch).sort(byDate)} />
|
2020-01-10 06:24:37 +00:00
|
|
|
:
|
|
|
|
<p>Loading...</p>
|
|
|
|
}
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-04-07 21:39:38 +00:00
|
|
|
|
|
|
|
export function ICalButtons(props) {
|
|
|
|
const { token, clazz } = props;
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [success, setSuccess] = useState(false);
|
2022-07-14 21:56:38 +00:00
|
|
|
const [error, setError] = useState(false);
|
2022-04-07 21:39:38 +00:00
|
|
|
|
|
|
|
const handleDownload = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
window.location = apiUrl + '/sessions/' + clazz.id + '/download_ical/';
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleEmail = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
if (loading) return;
|
|
|
|
setLoading(true);
|
|
|
|
setSuccess(false);
|
|
|
|
requester('/sessions/' + clazz.id + '/email_ical/', 'POST', token, {})
|
|
|
|
.then(res => {
|
|
|
|
setLoading(false);
|
|
|
|
setSuccess(true);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
setLoading(false);
|
|
|
|
console.log(err);
|
|
|
|
setError(true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-07-10 15:02:22 +00:00
|
|
|
const addToGoogleCalendar = (e) => {
|
|
|
|
e.preventDefault();
|
2022-07-10 18:14:53 +00:00
|
|
|
|
|
|
|
// construct and set the dates format that google calendar links require
|
|
|
|
let starttime = moment(clazz.datetime);
|
|
|
|
let endtime = starttime.clone().add(1, 'hour');
|
|
|
|
const datestringfmt = 'YYYYMMDDTkkmmss';
|
|
|
|
let dates = `${starttime.format(datestringfmt)}/${endtime.format(datestringfmt)}`
|
|
|
|
|
|
|
|
// send user to google calendar
|
|
|
|
window.location = `https://www.google.com/calendar/render?action=TEMPLATE&text=${clazz.course_data.name}&dates=${dates}`;
|
2022-07-10 15:02:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const options = [
|
2022-07-11 07:33:52 +00:00
|
|
|
{ key: 'email', icon: 'mail outline', text: 'Email ICS Event', value: 'Email', action: handleEmail },
|
|
|
|
{ key: 'download', icon: 'download', text: 'Download ICS Event', value: 'Download', action: handleDownload },
|
|
|
|
{ key: 'google', icon: 'google', text: 'Add to Google Calendar', value: 'Google', action: addToGoogleCalendar },
|
2022-07-10 15:02:22 +00:00
|
|
|
];
|
2022-07-10 18:14:53 +00:00
|
|
|
|
|
|
|
// get default option from local storage or default to first item in options list
|
2022-07-11 07:53:16 +00:00
|
|
|
const calendarValue = localStorage.getItem('calendarPreference') || 'Email';
|
|
|
|
const defaultOption = options.find(x => x.value === calendarValue);
|
2022-07-10 18:14:53 +00:00
|
|
|
|
2022-07-11 07:53:16 +00:00
|
|
|
const [selectedOption, setOption] = useState(defaultOption);
|
2022-07-10 15:02:22 +00:00
|
|
|
|
2022-07-11 07:53:16 +00:00
|
|
|
const onChange = (e, data) => {
|
|
|
|
const newOption = options.find(x => x.value === data.value);
|
2022-07-10 17:07:30 +00:00
|
|
|
setOption(newOption);
|
2022-07-10 18:14:53 +00:00
|
|
|
|
|
|
|
// set the option as users preference
|
2022-07-11 07:53:16 +00:00
|
|
|
localStorage.setItem('calendarPreference', newOption.value);
|
2022-07-10 15:02:22 +00:00
|
|
|
};
|
|
|
|
|
2022-04-07 21:39:38 +00:00
|
|
|
return (
|
2022-07-10 18:14:53 +00:00
|
|
|
<>
|
|
|
|
{success ?
|
2022-07-12 03:46:28 +00:00
|
|
|
<span>Sent!</span>
|
2022-07-10 18:14:53 +00:00
|
|
|
:
|
|
|
|
<Button.Group>
|
|
|
|
<Button
|
|
|
|
loading={loading}
|
2022-07-11 07:31:33 +00:00
|
|
|
onClick={selectedOption.action}
|
|
|
|
>
|
2022-07-11 07:33:52 +00:00
|
|
|
<Icon name={selectedOption.icon} />{selectedOption.value}
|
2022-04-07 21:39:38 +00:00
|
|
|
</Button>
|
2022-07-10 18:14:53 +00:00
|
|
|
<Dropdown
|
|
|
|
className='button icon'
|
|
|
|
floating
|
2022-07-11 07:53:16 +00:00
|
|
|
onChange={onChange}
|
2022-07-10 18:14:53 +00:00
|
|
|
options={options}
|
|
|
|
trigger={<></>}
|
2022-07-11 08:09:37 +00:00
|
|
|
selectOnBlur={false}
|
2022-07-10 18:14:53 +00:00
|
|
|
/>
|
|
|
|
</Button.Group>
|
|
|
|
}
|
2022-07-14 21:56:38 +00:00
|
|
|
{error && <p>Error.</p>}
|
2022-07-10 18:14:53 +00:00
|
|
|
</>
|
2022-04-07 21:39:38 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-01-10 06:24:37 +00:00
|
|
|
export function ClassDetail(props) {
|
|
|
|
const [clazz, setClass] = useState(false);
|
2020-01-18 01:27:56 +00:00
|
|
|
const [refreshCount, refreshClass] = useReducer(x => x + 1, 0);
|
2020-01-10 06:24:37 +00:00
|
|
|
const [error, setError] = useState(false);
|
2020-09-15 19:40:29 +00:00
|
|
|
const [loading, setLoading] = useState(false);
|
2022-05-23 21:44:09 +00:00
|
|
|
const [override, setOverride] = useState(false);
|
2020-01-18 01:27:56 +00:00
|
|
|
const { token, user, refreshUser } = props;
|
2020-01-10 06:24:37 +00:00
|
|
|
const { id } = useParams();
|
2022-07-13 04:18:33 +00:00
|
|
|
const userTraining = clazz && clazz.students.find(x => x.user === user.id);
|
2020-01-10 06:24:37 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
requester('/sessions/'+id+'/', 'GET', token)
|
|
|
|
.then(res => {
|
|
|
|
setClass(res);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
setError(true);
|
|
|
|
});
|
2020-01-18 01:27:56 +00:00
|
|
|
}, [refreshCount]);
|
2020-01-10 06:24:37 +00:00
|
|
|
|
2020-01-16 09:09:45 +00:00
|
|
|
const handleSignup = () => {
|
2020-09-15 19:42:09 +00:00
|
|
|
if (loading) return;
|
2020-09-15 19:40:29 +00:00
|
|
|
setLoading(true);
|
2020-02-07 01:11:09 +00:00
|
|
|
const data = { attendance_status: 'Waiting for payment', session: id };
|
2020-01-16 09:09:45 +00:00
|
|
|
requester('/training/', 'POST', token, data)
|
|
|
|
.then(res => {
|
2020-01-18 01:27:56 +00:00
|
|
|
refreshClass();
|
|
|
|
refreshUser();
|
2020-01-16 09:09:45 +00:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleToggle = (newStatus) => {
|
2020-09-15 19:42:09 +00:00
|
|
|
if (loading) return;
|
2020-09-15 19:40:29 +00:00
|
|
|
setLoading(true);
|
2020-01-16 09:09:45 +00:00
|
|
|
const data = { attendance_status: newStatus, session: id };
|
|
|
|
requester('/training/'+userTraining.id+'/', 'PUT', token, data)
|
|
|
|
.then(res => {
|
2020-01-18 01:27:56 +00:00
|
|
|
refreshClass();
|
|
|
|
refreshUser();
|
2020-01-16 09:09:45 +00:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
setError(true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-09-15 19:40:29 +00:00
|
|
|
useEffect(() => {
|
|
|
|
setLoading(false);
|
|
|
|
}, [userTraining]);
|
|
|
|
|
2022-05-23 21:44:09 +00:00
|
|
|
const now = new Date().toISOString();
|
|
|
|
const signupDisabled = clazz && clazz.datetime < now && !override;
|
2020-01-16 09:09:45 +00:00
|
|
|
|
2020-01-10 06:24:37 +00:00
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
{!error ?
|
|
|
|
clazz ?
|
|
|
|
<div>
|
2020-01-10 07:39:05 +00:00
|
|
|
<Header size='large'>Class Details</Header>
|
2020-01-10 06:24:37 +00:00
|
|
|
|
2020-02-16 07:17:44 +00:00
|
|
|
{(isAdmin(user) || clazz.instructor === user.id) &&
|
|
|
|
<Segment padded>
|
|
|
|
<InstructorClassDetail clazz={clazz} setClass={setClass} {...props} />
|
|
|
|
</Segment>
|
|
|
|
}
|
2020-01-16 01:32:52 +00:00
|
|
|
|
2020-01-11 23:53:42 +00:00
|
|
|
<BasicTable>
|
2020-01-10 06:24:37 +00:00
|
|
|
<Table.Body>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Name:</Table.Cell>
|
|
|
|
<Table.Cell>
|
2020-01-15 07:51:00 +00:00
|
|
|
<Link to={'/courses/'+clazz.course}>
|
2021-10-23 07:28:34 +00:00
|
|
|
{clazz.course_data.name}
|
2020-01-10 06:24:37 +00:00
|
|
|
</Link>
|
|
|
|
</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Date:</Table.Cell>
|
|
|
|
<Table.Cell>
|
2020-02-24 04:07:18 +00:00
|
|
|
{moment.utc(clazz.datetime).tz('America/Edmonton').format('ll')}
|
2020-01-10 06:24:37 +00:00
|
|
|
</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Time:</Table.Cell>
|
|
|
|
<Table.Cell>
|
2020-02-24 04:07:18 +00:00
|
|
|
{clazz.is_cancelled ? 'Cancelled' : moment.utc(clazz.datetime).tz('America/Edmonton').format('LT')}
|
2020-01-10 06:24:37 +00:00
|
|
|
</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Instructor:</Table.Cell>
|
2020-07-18 22:15:53 +00:00
|
|
|
<Table.Cell>{getInstructor(clazz)}</Table.Cell>
|
2020-01-10 06:24:37 +00:00
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Cost:</Table.Cell>
|
|
|
|
<Table.Cell>{clazz.cost === '0.00' ? 'Free' : '$'+clazz.cost}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Students:</Table.Cell>
|
2020-02-14 22:35:24 +00:00
|
|
|
<Table.Cell>{clazz.student_count} {!!clazz.max_students && '/ '+clazz.max_students}</Table.Cell>
|
2020-01-10 06:24:37 +00:00
|
|
|
</Table.Row>
|
2022-04-07 21:39:38 +00:00
|
|
|
<Table.Row>
|
2022-07-12 03:48:01 +00:00
|
|
|
<Table.Cell>Event:</Table.Cell>
|
2022-04-07 21:39:38 +00:00
|
|
|
<Table.Cell><ICalButtons token={token} clazz={clazz} /></Table.Cell>
|
|
|
|
</Table.Row>
|
2020-01-10 06:24:37 +00:00
|
|
|
</Table.Body>
|
2020-01-11 23:53:42 +00:00
|
|
|
</BasicTable>
|
2020-01-10 06:24:37 +00:00
|
|
|
|
2021-10-23 07:28:34 +00:00
|
|
|
<Header size='medium'>Course Description</Header>
|
|
|
|
{clazz.course_data.is_old ?
|
|
|
|
clazz.course_data.description.split('\n').map((x, i) =>
|
|
|
|
<p key={i}>{x}</p>
|
|
|
|
)
|
|
|
|
:
|
|
|
|
<div dangerouslySetInnerHTML={{__html: clazz.course_data.description}} />
|
|
|
|
}
|
|
|
|
|
2020-01-10 06:24:37 +00:00
|
|
|
<Header size='medium'>Attendance</Header>
|
2020-01-16 09:09:45 +00:00
|
|
|
|
|
|
|
{(isAdmin(user) || clazz.instructor === user.id) &&
|
|
|
|
<Segment padded>
|
2020-01-18 01:36:53 +00:00
|
|
|
<InstructorClassAttendance clazz={clazz} refreshClass={refreshClass} {...props} />
|
2020-01-16 09:09:45 +00:00
|
|
|
</Segment>
|
|
|
|
}
|
|
|
|
|
2022-07-13 04:18:33 +00:00
|
|
|
{clazz.instructor !== user.id &&
|
2020-01-16 09:09:45 +00:00
|
|
|
(userTraining ?
|
|
|
|
<div>
|
|
|
|
<p>Status: {userTraining.attendance_status}</p>
|
2020-02-09 06:59:22 +00:00
|
|
|
<p>
|
|
|
|
{userTraining.attendance_status === 'Withdrawn' ?
|
2020-09-15 19:40:29 +00:00
|
|
|
<Button loading={loading} onClick={() => handleToggle('Waiting for payment')}>
|
2020-02-09 06:59:22 +00:00
|
|
|
Sign back up
|
|
|
|
</Button>
|
|
|
|
:
|
2020-09-15 19:40:29 +00:00
|
|
|
<Button loading={loading} onClick={() => handleToggle('Withdrawn')}>
|
2020-02-09 06:59:22 +00:00
|
|
|
Withdraw from Class
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
</p>
|
|
|
|
|
2022-07-13 04:18:33 +00:00
|
|
|
{clazz.cost !== '0.00' && !userTraining.paid_date && userTraining.attendance_status !== 'Withdrawn' &&
|
2020-02-09 06:59:22 +00:00
|
|
|
<div>
|
2022-05-12 06:15:49 +00:00
|
|
|
{userTraining.attendance_status === 'Waiting for payment' ?
|
|
|
|
<p>Please pay the course fee of ${clazz.cost} to confirm your attendance:</p>
|
|
|
|
:
|
|
|
|
<p>In case you haven't paid the course fee of ${clazz.cost} yet, you can do that here:</p>
|
|
|
|
}
|
2020-02-21 06:10:52 +00:00
|
|
|
<PayPalPayNow
|
2020-02-09 06:59:22 +00:00
|
|
|
amount={clazz.cost}
|
2021-10-23 07:28:34 +00:00
|
|
|
name={clazz.course_data.name}
|
2020-02-09 06:59:22 +00:00
|
|
|
custom={JSON.stringify({ training: userTraining.id })}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-01-16 09:09:45 +00:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
:
|
2020-03-08 01:12:44 +00:00
|
|
|
(clazz.is_cancelled ?
|
|
|
|
<p>The class is cancelled.</p>
|
2020-01-16 09:09:45 +00:00
|
|
|
:
|
2020-03-08 01:12:44 +00:00
|
|
|
((clazz.max_students && clazz.student_count >= clazz.max_students) ?
|
|
|
|
<p>The class is full.</p>
|
|
|
|
:
|
2022-05-23 21:44:09 +00:00
|
|
|
<>
|
|
|
|
{clazz.datetime < now &&
|
|
|
|
<>
|
|
|
|
<p>This class has already ran.</p>
|
|
|
|
<p>
|
|
|
|
<Form.Checkbox
|
|
|
|
name='override'
|
|
|
|
value={override}
|
|
|
|
label='Let me sign up anyway'
|
|
|
|
required
|
|
|
|
onChange={(e, v) => setOverride(v.checked)}
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
|
|
|
|
<Button loading={loading} onClick={handleSignup} disabled={signupDisabled}>
|
|
|
|
Sign me up!
|
|
|
|
</Button>
|
|
|
|
</>
|
2020-03-08 01:12:44 +00:00
|
|
|
)
|
2020-01-16 09:09:45 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2020-01-10 06:24:37 +00:00
|
|
|
</div>
|
|
|
|
:
|
|
|
|
<p>Loading...</p>
|
|
|
|
:
|
|
|
|
<NotFound />
|
|
|
|
}
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|