|
@@ -5,10 +5,17 @@ import { connect } from 'react-redux';
|
|
|
import { Link } from 'react-router-dom';
|
|
|
import { history } from '../../App';
|
|
|
|
|
|
-const RegisterForm = ({ onRegister }) => {
|
|
|
+const RegisterForm = ({ onRegister, regData }) => {
|
|
|
let [login, setLogin] = useState()
|
|
|
let [password, setPassword] = useState()
|
|
|
let [password2, setPassword2] = useState()
|
|
|
+ let [data, setData] = useState()
|
|
|
+ let [isReg, setIsReg] = useState(false)
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ setData(regData)
|
|
|
+ }, [regData, data])
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
<h1>Web-player</h1>
|
|
@@ -23,18 +30,19 @@ const RegisterForm = ({ onRegister }) => {
|
|
|
/>
|
|
|
<small style={{ color: 'red' }}>{password2 && password2 !== password ? 'Passwords do not match' : ''}</small>
|
|
|
<br />
|
|
|
- <button
|
|
|
- className='forms__button highlightYellow'
|
|
|
- disabled={!password || !login || password2 !== password}
|
|
|
- onClick={() => onRegister(login, password)}
|
|
|
- >Register</button>
|
|
|
+ {data?.payload && isReg? <small className='highlightGreen'>User {data.payload.login} successfully registered!</small> :
|
|
|
+ <button
|
|
|
+ className='forms__button highlightYellow'
|
|
|
+ disabled={!password || !login || password2 !== password}
|
|
|
+ onClick={() => {onRegister(login, password); setIsReg(true)}}
|
|
|
+ >Register</button>}
|
|
|
<br />
|
|
|
<Link className='sidebar__link highlightYellow' to="/login">Back to log-in page</Link>
|
|
|
</div>
|
|
|
</>
|
|
|
)
|
|
|
}
|
|
|
-export const RegisterFormConnect = connect(null, { onRegister: action.actionRegister })(RegisterForm)
|
|
|
+export const RegisterFormConnect = connect(state => ({regData: state.promise.registration || {}}), { onRegister: action.actionRegister })(RegisterForm)
|
|
|
|
|
|
const LoginForm = ({ loged, onLogin }) => {
|
|
|
let [login, setLogin] = useState()
|