import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom';
import './light.css';
import { Button, Container, Checkbox, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import { BasicTable, staticUrl, requester } from './utils.js';
import { LoginForm, SignupForm } from './LoginSignup.js';
function LogoutEverywhere(props) {
const { token } = props;
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [yousure, setYousure] = useState(false);
const history = useHistory();
const handleClick = () => {
if (yousure) {
if (loading) return;
setLoading(true);
requester('/rest-auth/logout/', 'POST', token, {})
.then(res => {
setYousure(false);
history.push('/');
window.scrollTo(0, 0);
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
} else {
setYousure(true);
}
};
return (
Use this to log out from all sessions on all computers.
{error &&
Error, something went wrong.
}
);
};
function ChangePasswordForm(props) {
const { token } = props;
const [input, setInput] = useState({});
const [error, setError] = useState({});
const [loading, setLoading] = useState(false);
const history = useHistory();
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 handleSubmit = (e) => {
if (loading) return;
setLoading(true);
requester('/password/change/', 'POST', token, input)
.then(res => {
setError({});
history.push('/');
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
return (
Submit
);
};
export function AccountForm(props) {
const { token, user, refreshUser } = props;
const member = user.member;
const [input, setInput] = useState({ ...member, set_details: true });
const [error, setError] = useState({});
const [loading, setLoading] = useState(false);
const history = useHistory();
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) => {
if (loading) return;
setLoading(true);
requester('/members/' + member.id + '/', 'PATCH', token, input)
.then(res => {
setError({});
refreshUser();
history.push('/');
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
...(input[name] ? {} : {icon: 'edit'}),
});
return (
{input.is_minor && }
{input.is_minor && }
Submit
);
};
export function Account(props) {
return (
);
};