Add loading & LinearProgress to Koneksyon component
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
InputAdornment,
|
InputAdornment,
|
||||||
InputLabel,
|
InputLabel,
|
||||||
|
LinearProgress,
|
||||||
Snackbar,
|
Snackbar,
|
||||||
Typography
|
Typography
|
||||||
} from '@material-ui/core'
|
} from '@material-ui/core'
|
||||||
@@ -22,6 +23,7 @@ function Koneksyon() {
|
|||||||
const [loginError, setError] = useState('')
|
const [loginError, setError] = useState('')
|
||||||
const [credentials, setCredentials] = useState({username: '', password: ''})
|
const [credentials, setCredentials] = useState({username: '', password: ''})
|
||||||
const [showPassword, setShowPassword] = useState(false)
|
const [showPassword, setShowPassword] = useState(false)
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
const [open, setOpen] = useState(true)
|
const [open, setOpen] = useState(true)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -30,13 +32,16 @@ function Koneksyon() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleClick = async () => {
|
const handleClick = async () => {
|
||||||
|
setLoading(true)
|
||||||
const response = await signIn('credentials', {
|
const response = await signIn('credentials', {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
...credentials
|
...credentials
|
||||||
})
|
})
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
setError(response.error)
|
setError(response.error)
|
||||||
|
setLoading(false)
|
||||||
} else if (response.ok) {
|
} else if (response.ok) {
|
||||||
|
setLoading(false)
|
||||||
router.push('/kont')
|
router.push('/kont')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +106,7 @@ function Koneksyon() {
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
fullWidth
|
fullWidth
|
||||||
disabled={!validateEmail(credentials.username) || credentials.password === ''}
|
disabled={loading || !validateEmail(credentials.username) || credentials.password === ''}
|
||||||
style={{marginTop: 50}}
|
style={{marginTop: 50}}
|
||||||
variant='contained'
|
variant='contained'
|
||||||
color='primary'
|
color='primary'
|
||||||
@@ -112,6 +117,8 @@ function Koneksyon() {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
{loading && <LinearProgress size={24} style={{width: '100%', marginTop: '1em'}} />}
|
||||||
|
|
||||||
{loginError && (
|
{loginError && (
|
||||||
<Snackbar
|
<Snackbar
|
||||||
open={open}
|
open={open}
|
||||||
|
|||||||
Reference in New Issue
Block a user