import { actionFullLogin, actionFullRegister, actionClearPromise} from '../actions' import React, { useState } from 'react' import { connect } from 'react-redux' import { Button, Input, Checkbox, Form } from 'antd' import { Link } from 'react-router-dom' import { actionClearUserData } from '../redux/saga' import { message } from 'antd' import { useEffect } from 'react' const LoginForm = ({ onLogin, children, auth,register, onClearPromise }) => { const [login, setLogin] = useState('') const [password, setPassword] = useState('') const [checked, setChecked] = useState(false) useEffect(() => { if (auth?.status === 'FULFILLED' && auth?.payload === null) { message.error({ content: 'You entered wrong login or password', style: { marginTop: '80px', }, }) } }, [auth]) useEffect(() => { if (register?.status === 'FULFILLED' && register?.payload === null) { message.error({ content: 'This login is already in the database', style: { marginTop: '80px', }, }) && onClearPromise('register') } }, [register]) const input = () => { onLogin(login, password) // && // onClearPromise('auth') } return ( <>

{children}

Login and password must be at least 5 characters

setLogin(e.target.value)} /> setPassword(e.target.value)} /> { setChecked(e.target.checked) }} size="large" > See the password
) } export const CLoginForm = connect( (state) => ({ children: `Sign In`, auth: state.promise?.auth, }), { onLogin: actionFullLogin, onClearPromise:actionClearPromise }, )(LoginForm) export const CRegisterForm = connect( (state) => ({ children: `Register`, register: state.promise?.register }), { onLogin: actionFullRegister, onClearPromise:actionClearPromise }, )(LoginForm) export const CLogout = connect( (state) => ({ children: `Logout`, }), { onClick: actionClearUserData }, )('a') export const InputForm = ({}) => { return ( <>

{' '} If you have account, click on Sign In,
else - click on Register

) } export const CInputForm = connect()(InputForm)