Added enter key listener on login page

This commit is contained in:
bourquecharles
2021-05-02 13:26:14 -04:00
parent f0537c35ef
commit e52a9f6de8

View File

@@ -23,6 +23,12 @@ const Login = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const [userId, setUsername] = useState(''); const [userId, setUsername] = useState('');
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const onKeyDown = (event) => {
if(event.code === 'Enter' && formValidation()){
SignIn({ userId, password });
}
};
const SignIn = (credentials) => { const SignIn = (credentials) => {
axiosInstance.post('/oauth2', credentials) axiosInstance.post('/oauth2', credentials)
@@ -33,7 +39,7 @@ const Login = () => {
.catch(error => { .catch(error => {
console.log(error.response); console.log(error.response);
}); });
} };
const formValidation = () => { const formValidation = () => {
if (userId.trim() === '' || password.trim() === ''){ if (userId.trim() === '' || password.trim() === ''){
@@ -50,7 +56,7 @@ const Login = () => {
<CCardGroup> <CCardGroup>
<CCard className="p-4"> <CCard className="p-4">
<CCardBody> <CCardBody>
<CForm> <CForm onKeyDown = { onKeyDown }>
<h1>Login</h1> <h1>Login</h1>
<p className="text-muted">Sign In to your account</p> <p className="text-muted">Sign In to your account</p>
<CInputGroup className="mb-3"> <CInputGroup className="mb-3">