import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom';
import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.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 { BasicTable, staticUrl, requester } from './utils.js';
function InstructorCourseEditor(props) {
const { input, setInput, error } = props;
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
const handleUpload = (e, v) => setInput({ ...input, [v.name]: e.target.files[0] });
const handleChange = (e) => handleValues(e, e.currentTarget);
const handleCheck = (e, v) => setInput({ ...input, [v.name]: v.checked });
const handleQuill = (v, d, s, e) => s === 'user' && setInput({
...input,
description: v === '
' ? '' : v,
});
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
const modules = {
toolbar: [
[{ 'header': [3, false] }],
['bold', 'italic', 'underline', 'code'],
[{'list': 'ordered'}, {'list': 'bullet'}],
['link'],
['clean']
],
};
return (
{error.description &&
}
);
}
function InstructorCourseDetail(props) {
const [input, setInput] = useState({ ...props.card });
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const id = props.card.id;
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
const handleUpload = (e, v) => setInput({ ...input, [v.name]: e.target.files[0] });
const handleChange = (e) => handleValues(e, e.currentTarget);
const handleCheck = (e, v) => setInput({ ...input, [v.name]: v.checked });
const handleSubmit = (e) => {
setLoading(true);
setSuccess(false);
const data = { ...input, member_id: props.result.member.id };
requester('/cards/'+id+'/', 'PUT', props.token, data)
.then(res => {
setLoading(false);
setSuccess(true);
setError(false);
setInput(res);
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const handleDelete = (e) => {
e.preventDefault();
requester('/cards/'+id+'/', 'DELETE', props.token)
.then(res => {
setInput(false);
})
.catch(err => {
console.log(err);
});
};
const statusOptions = [
{ key: '0', text: 'Card Active', value: 'card_active' },
{ key: '1', text: 'Card Blocked', value: 'card_blocked' },
{ key: '2', text: 'Card Inactive', value: 'card_inactive' },
{ key: '3', text: 'Card Member Blocked', value: 'card_member_blocked' },
];
return (
input ?
{success ? 'Saved.' : 'Save'}
Delete
Notes: {input.notes || 'None'}
:
Deleted card: {props.card.card_number}
);
};
export function InstructorCourseList(props) {
const { courses, setCourses, token } = props;
const [open, setOpen] = useState(false);
const [input, setInput] = useState({});
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const handleSubmit = (e) => {
setLoading(true);
setSuccess(false);
const data = { ...input, is_old: false };
requester('/courses/', 'POST', props.token, data)
.then(res => {
setSuccess(res.id);
setInput({});
setLoading(false);
setError(false);
setOpen(false);
props.setCourses([ ...courses, res ]);
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
return (
{success &&
Added to bottom of course list! View the course.
}
{open ?
Submit
:
}
);
};