Skip to content

Added logic to hide error msg in login and signup form #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: xcosblocks
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions blocks/eda-frontend/src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ let url = ''

export default function SignIn (props) {
const classes = useStyles()
const errors = useSelector(state => state.auth.errors)

const authErrors = useSelector(state => state.auth.errors)
const [errors, setErrors] = useState(authErrors || '')

const dispatch = useDispatch()
const homeURL = `${window.location.origin}/#/`

useEffect(() => {
setErrors(authErrors || '')
}, [authErrors])

useEffect(() => {
document.title = 'Login - ' + process.env.REACT_APP_NAME
if (props.location.search !== '') {
Expand Down Expand Up @@ -115,9 +120,11 @@ export default function SignIn (props) {
</Typography>

{/* Display's error messages while logging in */}
<Typography variant='body1' align='center' style={{ marginTop: '10px' }} color='error'>
{errors}
</Typography>
{authErrors && (
<Typography variant='body1' align='center' style={{ marginTop: '10px' }} color='error'>
{errors}
</Typography>
)}

<form className={classes.form} noValidate>
<TextField
Expand All @@ -131,7 +138,7 @@ export default function SignIn (props) {
autoComplete='email'
value={username}
onChange={e => setUsername(e.target.value)}
autoFocus
onFocus={() => setErrors('')}
/>
<TextField
variant='outlined'
Expand All @@ -149,7 +156,7 @@ export default function SignIn (props) {
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{showPassword ? <Visibility fontSize='small' /> : <VisibilityOff fontSize='small' />} {/* Handle password visibility */}
{showPassword ? <Visibility fontSize='small' /> : <VisibilityOff fontSize='small' />}
</IconButton>
</InputAdornment>
)
Expand All @@ -158,6 +165,7 @@ export default function SignIn (props) {
id='password'
value={password}
onChange={e => setPassword(e.target.value)}
onFocus={() => setErrors('')}
autoComplete='current-password'
/>
<FormControlLabel
Expand Down
29 changes: 24 additions & 5 deletions blocks/eda-frontend/src/pages/signUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@ export default function SignUp () {

const isRegistered = useSelector(state => state.auth.isRegistered)
const regErrors = useSelector(state => state.auth.regErrors)
const [errors, setErrors] = useState(regErrors || '')
const [isSignupSuccess, setIsSignupSuccess] = useState(false)

useEffect(() => {
if (isRegistered) {
setIsSignupSuccess(true)
}
}, [isRegistered])

const dispatch = useDispatch()
const homeURL = `${window.location.origin}/#/`

useEffect(() => {
setErrors(regErrors || '')
}, [regErrors])

useEffect(() => {
document.title = 'Sign Up - ' + process.env.REACT_APP_NAME

Expand Down Expand Up @@ -99,9 +111,11 @@ export default function SignUp () {
</Typography>

{/* Display's error messages while signing in */}
<Typography variant='body1' align='center' style={{ marginTop: '10px' }} color={isRegistered ? 'secondary' : 'error'}>
{regErrors}
</Typography>
{regErrors && (
<Typography variant='body1' align='center' style={{ marginTop: '10px' }} color={isRegistered ? 'secondary' : 'error'}>
{errors}
</Typography>
)}

<form className={classes.form} noValidate>
<TextField
Expand All @@ -116,7 +130,8 @@ export default function SignUp () {
autoComplete='email'
value={email}
onChange={e => setEmail(e.target.value)}
autoFocus
onFocus={() => setErrors('')}
disabled={isSignupSuccess}
/>
<TextField
variant='outlined'
Expand All @@ -143,7 +158,9 @@ export default function SignUp () {
id='password'
value={password}
onChange={e => setPassword(e.target.value)}
onFocus={() => setErrors('')}
autoComplete='current-password'
disabled={isSignupSuccess}
/>
<TextField
variant='outlined'
Expand All @@ -170,10 +187,12 @@ export default function SignUp () {
id='reenterPassword'
value={reenterPassword}
onChange={e => setReenterPassword(e.target.value)}
onFocus={() => setErrors('')}
autoComplete='current-password'
disabled={isSignupSuccess}
/>
<FormControlLabel
control={<Checkbox checked={accept} onChange={e => setAccept(e.target.checked)} color='primary' />}
control={<Checkbox checked={accept} onChange={e => setAccept(e.target.checked)} color='primary' disabled={isSignupSuccess} />}
label='I accept the Terms of Use & Privacy Policy'
/>
<Button
Expand Down