import React, { useRef, useState } from 'react'; import Button from '@material-ui/core/Button'; import Typography from '@material-ui/core/Typography'; import Container from '@material-ui/core/Container'; import { EmptyLayout }from '../../../common/components/Layout/EmptyLayout'; import { resetPassword } from '../../reducers/auth/service'; // @ts-ignore import styles from './Auth.module.scss'; import OutlinedInput from '@material-ui/core/OutlinedInput'; import InputAdornment from '@material-ui/core/InputAdornment'; import IconButton from '@material-ui/core/IconButton'; import { Visibility, VisibilityOff } from '@material-ui/icons'; import { useTranslation } from "react-i18next"; interface Props { resetPassword: typeof resetPassword; token: string; completeAction: ()=>void; } export const ResetPassword = (props: Props): any => { const { resetPassword, token, completeAction } = props; const initialState = { password: '', isSubmitted:false }; const [state, setState] = useState(initialState); const { t } = useTranslation(); const handleInput = (e: any): void => { e.preventDefault(); setState({ ...state, [e.target.name]: e.target.value }); }; const handleReset = (e: any): void => { e.preventDefault(); resetPassword(token, state.password); setState({ ...state, isSubmitted: true }); }; const [values, setValues] = useState({showPassword:false, showPasswordConfirm: false}); const handleClickShowPassword = () => { setValues({ ...values, showPassword: !values.showPassword }); }; const handleClickShowPasswordConfirm = () => { setValues({ ...values, showPasswordConfirm: !values.showPasswordConfirm }); }; const handleMouseDownPassword = (event: React.MouseEvent) => { event.preventDefault(); }; const password = useRef(); const confirm_password = useRef(); function validatePassword(){ if(password.current.value != confirm_password.current.value) { confirm_password.current.setCustomValidity(t('user:auth.resetPassword.passwordNotMatch')); } else { confirm_password.current.setCustomValidity(''); } } return (
{state.isSubmitted ? <> Your password was successfully reset! You can now log into the your account. : (<> {t('user:auth.resetPassword.header')} {t('user:auth.resetPassword.description')}
handleReset(e)}> handleInput(e)} endAdornment={ {values.showPassword ? : } } /> handleInput(e)} onKeyUp={validatePassword} endAdornment={ {values.showPasswordConfirm ? : } } /> )}
); };