import React, {useState} from 'react'; import {Link} from 'react-router-dom'; import { actionAuthLogin } from '../store/authReducer'; import { store } from '../store/store'; import { connect } from 'react-redux'; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faEyeSlash, faEye} from "@fortawesome/free-solid-svg-icons"; import { Button, Form, InputGroup } from 'react-bootstrap'; export async function sendForm (url, data) { let error = await fetch(`http://player-api/api/${url}`, { method: 'POST', body: data }).then(res => res.json()) .then(data => { if(data.token) { store.dispatch(actionAuthLogin(data.token, data.user)); return data } else { console.log(data); return data.login[0]; } }) return error; } export const RegisterForm = ({authState}) => { const [login, setLogin] = useState(''); const [password, setPassword] = useState(''); const [name, setName] = useState(''); const [passwordConfirm, setPasswordConfirm] = useState(''); const [textModal, setTextModal] = useState(''); const [showPass, setShowPass] = useState(false); const [showConfPass, setShowConfPass] = useState(false); const postForm = async (event) =>{ event.preventDefault(); const data = new FormData(); data.append("login", login); data.append("password", password); data.append("name", name); setTextModal(( typeof(await sendForm('register', data))==='string')? (await sendForm('register', data)) : ''); } return (

Sign Up


*Login setLogin(e.target.value)} /> *Full Name setName(e.target.value)} /> *Password (8+ symbols) setPassword(e.target.value)} /> showPass? setShowPass(false) : setShowPass(true)}/> *Confirm password setPasswordConfirm(e.target.value)} /> showConfPass? setShowConfPass(false) : setShowConfPass(true)}/>

{textModal ? ('*' + textModal) : ''}

Already a member? Log in
) } export const CRegisterForm = connect(state => ({ authState: state.auth?.token }))(RegisterForm);