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 StartPage from '../../StartPage'; import { useTranslation } from '../../LocalizationProvider'; import useQuery from '../../common/useQuery'; 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 ResetPasswordForm = () => { 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={6000} 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 ResetPasswordForm;