diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-02-01 10:58:11 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2021-02-01 10:58:11 -0800 |
commit | 65af8bad51851ff7f15319d5ce14ff24697aaded (patch) | |
tree | 935830fdad9a4d01cf4b1e9182e7542bdcca3262 /modern | |
parent | 05c3cd4e7bb395970b395c719c1e6a671574c75b (diff) | |
download | trackermap-web-65af8bad51851ff7f15319d5ce14ff24697aaded.tar.gz trackermap-web-65af8bad51851ff7f15319d5ce14ff24697aaded.tar.bz2 trackermap-web-65af8bad51851ff7f15319d5ce14ff24697aaded.zip |
Registration flow updatesv4.12
Diffstat (limited to 'modern')
-rw-r--r-- | modern/src/LoginPage.js | 4 | ||||
-rw-r--r-- | modern/src/RegisterDialog.js | 28 |
2 files changed, 11 insertions, 21 deletions
diff --git a/modern/src/LoginPage.js b/modern/src/LoginPage.js index 14960f82..d3be3978 100644 --- a/modern/src/LoginPage.js +++ b/modern/src/LoginPage.js @@ -54,7 +54,7 @@ const LoginPage = () => { const classes = useStyles(); const history = useHistory(); - const registrationPref = useSelector(state => state.session.server ? state.session.server['registration'] : false); + const registrationEnabled = useSelector(state => state.session.server ? state.session.server['registration'] : false); const handleEmailChange = (event) => { setEmail(event.target.value); @@ -118,7 +118,7 @@ const LoginPage = () => { <FormControl fullWidth margin='normal'> <div className={classes.buttons}> - <Button type='button' variant='contained' onClick={handleRegister} disabled={!registrationPref}> + <Button type='button' variant='contained' onClick={handleRegister} disabled={!registrationEnabled}> {t('loginRegister')} </Button> <Button type='submit' variant='contained' color='primary' disabled={!email || !password}> diff --git a/modern/src/RegisterDialog.js b/modern/src/RegisterDialog.js index 53174360..c640c515 100644 --- a/modern/src/RegisterDialog.js +++ b/modern/src/RegisterDialog.js @@ -14,24 +14,11 @@ const RegisterDialog = ({ showDialog, onResult }) => { const [password, setPassword] = useState(''); const [snackbarOpen, setSnackbarOpen] = useState(false); - const handleNameChange = (event) => { - setName(event.target.value); - } - - const handleEmailChange = (event) => { - setEmail(event.target.value); - } - - const handlePasswordChange = (event) => { - setPassword(event.target.value); - } - const submitDisabled = () => { - return (!name || !/(.+)@(.+)\.(.{2,})/.test(email) || !password); + return !name || !/(.+)@(.+)\.(.{2,})/.test(email) || !password; } - const handleRegister = async (event) => { - + const handleRegister = async () => { const response = await fetch('/api/users', { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -45,6 +32,7 @@ const RegisterDialog = ({ showDialog, onResult }) => { } if (snackbarOpen) { + return ( <Snackbar anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} @@ -53,7 +41,9 @@ const RegisterDialog = ({ showDialog, onResult }) => { onClose={() => { onResult(true) }} message={t('loginCreated')} /> ); + } else if (showDialog) { + return ( <Dialog open={true} @@ -69,7 +59,7 @@ const RegisterDialog = ({ showDialog, onResult }) => { value={name || ''} autoComplete='name' autoFocus - onChange={handleNameChange} /> + onChange={event => setName(event.target.value)} /> <TextField margin='normal' required @@ -79,7 +69,7 @@ const RegisterDialog = ({ showDialog, onResult }) => { name='email' value={email || ''} autoComplete='email' - onChange={handleEmailChange} /> + onChange={event => setEmail(event.target.value)} /> <TextField margin='normal' required @@ -89,7 +79,7 @@ const RegisterDialog = ({ showDialog, onResult }) => { value={password || ''} type='password' autoComplete='current-password' - onChange={handlePasswordChange} /> + onChange={event => setPassword(event.target.value)} /> </DialogContent> <DialogActions> <Button color="primary" onClick={handleRegister} disabled={submitDisabled()}>{t('loginRegister')}</Button> @@ -97,8 +87,8 @@ const RegisterDialog = ({ showDialog, onResult }) => { </DialogActions> </Dialog> ) - } else return null; + } }; export default RegisterDialog; |