import React, { useState } from 'react'; import { Grid, Button, TextField, Typography, Link, makeStyles, Snackbar, } from '@material-ui/core'; import { useHistory } from 'react-router-dom'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import LoginLayout from './LoginLayout'; import { useTranslation } from '../LocalizationProvider'; import useQuery from '../common/util/useQuery'; import { snackBarDurationShortMs } from '../common/util/duration'; const useStyles = makeStyles((theme) => ({ title: { fontSize: theme.spacing(3), fontWeight: 500, marginLeft: theme.spacing(2), textTransform: 'uppercase', }, link: { fontSize: theme.spacing(3), fontWeight: 500, marginTop: theme.spacing(0.5), cursor: 'pointer', }, })); const ResetPasswordPage = () => { const classes = useStyles(); const history = useHistory(); const t = useTranslation(); const query = useQuery(); const token = query.get('passwordReset'); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [snackbarOpen, setSnackbarOpen] = useState(false); const handleSubmit = async (event) => { event.preventDefault(); let response; if (!token) { response = await fetch('/api/password/reset', { method: 'POST', body: new URLSearchParams(`email=${encodeURIComponent(email)}`), }); } else { response = await fetch('/api/password/update', { method: 'POST', body: new URLSearchParams(`token=${encodeURIComponent(token)}&password=${encodeURIComponent(password)}`), }); } if (response.ok) { setSnackbarOpen(true); } }; return ( history.push('/login')} autoHideDuration={snackBarDurationShortMs} message={!token ? t('loginResetSuccess') : t('loginUpdateSuccess')} /> history.push('/login')}> {t('loginReset')} {!token ? ( setEmail(event.target.value)} variant="filled" /> ) : ( setPassword(event.target.value)} variant="filled" /> )} ); }; export default ResetPasswordPage;