import React, { useRef, useState } from 'react'; import Button from '@material-ui/core/Button'; import Grid from '@material-ui/core/Grid'; import Container from '@material-ui/core/Container'; import { connect } from 'react-redux'; import { bindActionCreators, Dispatch } from 'redux'; import { registerUserByEmail } 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"; const mapDispatchToProps = (dispatch: Dispatch): any => { return ({ registerUserByEmail: bindActionCreators(registerUserByEmail, dispatch), }); }; interface Props { registerUserByEmail: typeof registerUserByEmail; } const SignUp = (props: Props): any => { const { registerUserByEmail } = props; const initialState = { email: '', password: '', }; const [state, setState] = useState(initialState); const { t } = useTranslation(); const handleInput = (e: any): void => { e.preventDefault(); setState({ ...state, [e.target.name]: e.target.value }); }; const handleRegister = (e: any): void => { e.preventDefault(); console.log('handleRegister', { email: state.email, password: state.password }); registerUserByEmail({ email: state.email, password: state.password }); }; 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.register.passwordNotMatch')); } else { confirm_password.current.setCustomValidity(''); } } return (
handleRegister(e)}> handleInput(e)} /> handleInput(e)} endAdornment={ {values.showPassword ? : } } /> handleInput(e)} onKeyUp={validatePassword} endAdornment={ {values.showPasswordConfirm ? : } } />
); }; const SignUpWrapper = (props: any): any => ; export default connect(null, mapDispatchToProps)(SignUpWrapper);