import React, { useState, useEffect, useReducer, useContext } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom';
import { Button, Container, Checkbox, Dimmer, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import { apiUrl, statusColor, BasicTable, staticUrl, requester } from './utils.js';
import { NotFound } from './Misc.js';
function ResetForm() {
const [input, setInput] = useState({});
const [error, setError] = useState({});
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
const handleChange = (e) => handleValues(e, e.currentTarget);
const handleSubmit = (e) => {
if (loading) return;
setLoading(true);
requester('/password/reset/', 'POST', '', input)
.then(res => {
setLoading(false);
setSuccess(true);
setError({});
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
return (
{error.email == 'Not found.' &&
}
{error.email == 'Not on Spaceport.' &&
Please sign up to the new portal here:
Spaceport Registration
>
}
/>
}
Submit
{loading && Give me like 30 seconds...
}
{success && Success! Be sure to check your spam folder.
}
);
};
function ConfirmForm() {
const { uid, token } = useParams();
const [input, setInput] = useState({ uid: uid, token: token });
const [error, setError] = useState({});
const [progress, setProgress] = useState([]);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const history = useHistory();
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
const handleChange = (e) => handleValues(e, e.currentTarget);
const handleSubmit = (e) => {
if (loading) return;
setLoading(true);
const request_id = token.slice(-10);
const getStatus = () => {
requester('/stats/progress/?request_id='+request_id, 'GET')
.then(res => {
setProgress(res);
})
.catch(err => {
console.log(err);
});
};
const interval = setInterval(getStatus, 500);
requester('/password/reset/confirm/', 'POST', '', input)
.then(res => {
clearInterval(interval);
setLoading(false);
setSuccess(true);
setError({});
history.push('/');
window.scrollTo(0, 0);
})
.catch(err => {
clearInterval(interval);
setLoading(false);
console.log(err);
setError(err.data);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
return (
{(error.token || error.uid) && Error: Invalid password reset URL! Try doing another reset.
}
{progress.map(x => <>{x}
>)}
Submit
{success && Success!
}
);
};
export function PasswordReset() {
return (
Enter your email and we will send you a password reset link.
);
};
export function ConfirmReset() {
return (
Choose a new password.
);
};