/** * Login Page Component * * Handles user authentication with: * - Username/password input * - Form validation * - Login state management * - Navigation to signup page * * Connects to Redux store for: * - Setting authentication state * - Storing username */ import React, { useState } from 'react'; import { IonHeader, IonToolbar, IonTitle, IonContent, IonPage, IonButtons, IonMenuButton, IonRow, IonCol, IonButton, IonList, IonItem, IonInput, IonText, } from '@ionic/react'; import './Login.scss'; import { setIsLoggedIn, setUsername } from '../../data/user/user.actions'; import { connect } from '../../data/connect'; import { RouteComponentProps } from 'react-router'; interface OwnProps extends RouteComponentProps {} interface DispatchProps { setIsLoggedIn: typeof setIsLoggedIn; setUsername: typeof setUsername; } interface LoginProps extends OwnProps, DispatchProps {} const Login: React.FC = ({ setIsLoggedIn, history, setUsername: setUsernameAction, }) => { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [formSubmitted, setFormSubmitted] = useState(false); const [usernameError, setUsernameError] = useState(false); const [passwordError, setPasswordError] = useState(false); const login = async (e: React.FormEvent) => { e.preventDefault(); setFormSubmitted(true); if (!username) { setUsernameError(true); } if (!password) { setPasswordError(true); } if (username && password) { await setIsLoggedIn(true); await setUsernameAction(username); history.push('/tabs/schedule', { direction: 'none' }); } }; return ( Example Login Page
Ionic logo
setUsername(e.detail.value as string)} required > {formSubmitted && usernameError && (

Username is required

)}
setPassword(e.detail.value as string)} > {formSubmitted && passwordError && (

Password is required

)}
Login Signup
); }; export default connect({ mapDispatchToProps: { setIsLoggedIn, setUsername, }, component: Login, });