From 4290739f81aaed0a56fc5f575f558e5339b2ccf9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 Jan 2023 17:37:20 -0800 Subject: Remove default admin --- modern/src/App.js | 3 +++ modern/src/login/RegisterPage.js | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/modern/src/App.js b/modern/src/App.js index e21cf1bf..62f0d749 100644 --- a/modern/src/App.js +++ b/modern/src/App.js @@ -27,6 +27,7 @@ const App = () => { const desktop = useMediaQuery(theme.breakpoints.up('md')); + const newServer = useSelector((state) => state.session.server.newServer); const initialized = useSelector((state) => !!state.session.user); useEffectAsync(async () => { @@ -34,6 +35,8 @@ const App = () => { const response = await fetch('/api/session'); if (response.ok) { dispatch(sessionActions.updateUser(await response.json())); + } else if (newServer) { + navigate('/register'); } else { navigate('/login'); } diff --git a/modern/src/login/RegisterPage.js b/modern/src/login/RegisterPage.js index 08ff3e8f..6dfe40a4 100644 --- a/modern/src/login/RegisterPage.js +++ b/modern/src/login/RegisterPage.js @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; import { Button, TextField, Typography, Snackbar, IconButton, } from '@mui/material'; @@ -9,6 +10,7 @@ import LoginLayout from './LoginLayout'; import { useTranslation } from '../common/components/LocalizationProvider'; import { snackBarDurationShortMs } from '../common/util/duration'; import { useCatch } from '../reactHelper'; +import { sessionActions } from '../store'; const useStyles = makeStyles((theme) => ({ container: { @@ -30,9 +32,12 @@ const useStyles = makeStyles((theme) => ({ const RegisterPage = () => { const classes = useStyles(); + const dispatch = useDispatch(); const navigate = useNavigate(); const t = useTranslation(); + const server = useSelector((state) => state.session.server); + const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); @@ -55,9 +60,11 @@ const RegisterPage = () => {
- navigate('/login')}> - - + {!server.newServer && ( + navigate('/login')}> + + + )} {t('loginRegister')} @@ -93,7 +100,7 @@ const RegisterPage = () => { variant="contained" color="secondary" onClick={handleSubmit} - disabled={!name || !/(.+)@(.+)\.(.{2,})/.test(email) || !password} + disabled={!name || !password || !(server.newServer || /(.+)@(.+)\.(.{2,})/.test(email))} fullWidth > {t('loginRegister')} @@ -101,7 +108,10 @@ const RegisterPage = () => {
navigate('/login')} + onClose={() => { + dispatch(sessionActions.updateServer({ ...server, newServer: false })); + navigate('/login'); + }} autoHideDuration={snackBarDurationShortMs} message={t('loginCreated')} /> -- cgit v1.2.3