import React, { useState } from 'react'; import { Grid, Button, TextField, Typography, Link, makeStyles, Snackbar } from '@material-ui/core'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import LoginForm from './LoginForm'; import t from './../common/localization'; const useStyles = makeStyles(theme => ({ register: { fontSize: theme.spacing(3), fontWeight: 500 }, link: { fontSize: theme.spacing(3), fontWeight: 500, marginTop: theme.spacing(0.5), cursor: 'pointer' } })); const forms = { login: () => LoginForm, }; const RegisterForm = ({ setCurrentForm }) => { const classes = useStyles(); const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [snackbarOpen, setSnackbarOpen] = useState(false); const submitDisabled = () => { return !name || !/(.+)@(.+)\.(.{2,})/.test(email) || !password; } const handleRegister = async () => { const response = await fetch('/api/users', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({name, email, password}) }); if (response.ok) { setSnackbarOpen(true); } } return ( <> setCurrentForm(forms.login)} autoHideDuration={6000} message={t('loginCreated')} /> setCurrentForm(forms.login)}> {t('loginRegister')} setName(event.target.value)} variant='filled' /> setEmail(event.target.value)} variant='filled' /> setPassword(event.target.value)} variant='filled' /> ) } export default RegisterForm;