import React, { useState } from 'react'; import { Link, useParams } from 'react-router-dom'; import { Container, Form, Grid, Header, Message } from 'semantic-ui-react'; import { requester } from './utils.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); }); }; return (
{error.email === 'Not found.' && } 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 handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); const handleChange = (e) => handleValues(e, e.currentTarget); const handleSubmit = (e) => { if (loading) return; setLoading(true); setProgress([]); 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({}); }) .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}
)}

{success ?

Return Home to log in.

: Submit } ); }; export function PasswordReset() { return (
Password Reset

Enter your email and we will send you a password reset link.

); }; export function ConfirmReset() { return (
Password Reset

Choose a new password.

); };