import t from './common/localization' import React, { useState } from 'react'; import Button from '@material-ui/core/Button'; import Dialog from '@material-ui/core/Dialog'; import DialogActions from '@material-ui/core/DialogActions'; import DialogContent from '@material-ui/core/DialogContent'; import DialogContentText from '@material-ui/core/DialogContentText'; import TextField from '@material-ui/core/TextField'; import Snackbar from '@material-ui/core/Snackbar'; const RegisterDialog = ({ showDialog, onResult }) => { 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) { showDialog = false; setSnackbarOpen(true); } } if (snackbarOpen) { return ( { onResult(true) }} message={t('loginCreated')} /> ); } else if (showDialog) { return ( { onResult(false) }}> {t('loginRegister')} setName(event.target.value)} /> setEmail(event.target.value)} /> setPassword(event.target.value)} /> ) } }; export default RegisterDialog;