|
@@ -5,10 +5,17 @@ import { connect } from 'react-redux';
|
|
import { Link } from 'react-router-dom';
|
|
import { Link } from 'react-router-dom';
|
|
import { history } from '../../App';
|
|
import { history } from '../../App';
|
|
|
|
|
|
-const RegisterForm = ({ onRegister }) => {
|
|
|
|
|
|
+const RegisterForm = ({ onRegister, regData }) => {
|
|
let [login, setLogin] = useState()
|
|
let [login, setLogin] = useState()
|
|
let [password, setPassword] = useState()
|
|
let [password, setPassword] = useState()
|
|
let [password2, setPassword2] = useState()
|
|
let [password2, setPassword2] = useState()
|
|
|
|
+ let [data, setData] = useState()
|
|
|
|
+ let [isReg, setIsReg] = useState(false)
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ setData(regData)
|
|
|
|
+ }, [regData, data])
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
<h1>Web-player</h1>
|
|
<h1>Web-player</h1>
|
|
@@ -23,18 +30,19 @@ const RegisterForm = ({ onRegister }) => {
|
|
/>
|
|
/>
|
|
<small style={{ color: 'red' }}>{password2 && password2 !== password ? 'Passwords do not match' : ''}</small>
|
|
<small style={{ color: 'red' }}>{password2 && password2 !== password ? 'Passwords do not match' : ''}</small>
|
|
<br />
|
|
<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 />
|
|
<br />
|
|
<Link className='sidebar__link highlightYellow' to="/login">Back to log-in page</Link>
|
|
<Link className='sidebar__link highlightYellow' to="/login">Back to log-in page</Link>
|
|
</div>
|
|
</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 }) => {
|
|
const LoginForm = ({ loged, onLogin }) => {
|
|
let [login, setLogin] = useState()
|
|
let [login, setLogin] = useState()
|