]> PHS Git Server - phs-admin.git/commitdiff
Cleaning up Login.jsx main views.
authorcharleswrayjr <charleswrayjr@gmail.com>
Sun, 14 Sep 2025 04:29:46 +0000 (23:29 -0500)
committercharleswrayjr <charleswrayjr@gmail.com>
Sun, 14 Sep 2025 04:29:46 +0000 (23:29 -0500)
src/app/views/Login/Login.jsx

index 4e909e96019d82d1b5fdfefbf7d0d513a8234603..d7f19fc33867520ba1f7a40b95cd8a8471c477e7 100755 (executable)
@@ -1,75 +1,76 @@
+// noinspection JSValidateTypes
+
 /**
  * @file Login view with an authentication form
  */
 
 import React, { useContext } from 'react';
-import { Container, TextField, Button, Typography, Box } from '@mui/material';
-import { useForm, Controller } from 'react-hook-form';
+import { Box, Button, Container, TextField, Typography } from '@mui/material';
+import { Controller, useForm } from 'react-hook-form';
 import { yupResolver } from '@hookform/resolvers/yup';
 import * as yup from 'yup';
 import { useSnackbar } from 'notistack';
 import { AuthContext } from '../../components/AuthContext';
 
-const schema = yup.object({
-  email: yup.string().email('Invalid email').required('Email is required'),
-  password: yup.string().required('Password is required'),
-}).required();
+const schema = yup.object( {
+  email:yup.string().email( 'Invalid email' ).required( 'Email is required' ),
+  password:yup.string().required( 'Password is required' ),
+} ).required();
 
 const Login = () => {
   const { enqueueSnackbar } = useSnackbar();
-  const { login } = useContext(AuthContext) || {};
-  const { control, handleSubmit, formState: { errors } } = useForm({
-    resolver: yupResolver(schema),
-  });
+  const { login } = useContext( AuthContext ) || {};
+  const { control, handleSubmit, formState:{ errors } } = useForm( {
+    resolver:yupResolver( schema ),
+  } );
 
-  const onSubmit = async (data) => {
-    const success = await login(data.email, data.password);
+  const onSubmit = async ( data ) => {
+    const success = await login( data.email, data.password );
     if (success) {
-      enqueueSnackbar('Login successful', { variant: 'success' });
+      enqueueSnackbar( 'Login successful', { variant:'success' } );
     } else {
-      enqueueSnackbar('Invalid credentials', { variant: 'error' });
+      enqueueSnackbar( 'Invalid credentials', { variant:'error' } );
     }
   };
 
   return (
-    <div>
-      <Container maxWidth="sm" className="container">
-        <Typography variant="h4" className="text-3xl font-bold mb-6 mt-4">
+    <div className="flex items-center justify-center min-h-screen bg-gray-100">
+      <Container maxWidth="sm"
+                 className="container">
+        <Typography variant="h4"
+                    className="text-3xl font-bold mb-6 mt-4">
           Login to PHS Admin
         </Typography>
-        <Box component="form" onSubmit={handleSubmit(onSubmit)} className="space-y-4">
-          <Controller
-            name="email"
-            control={control}
-            defaultValue=""
-            render={({ field }) => (
-              <TextField
-                {...field}
-                label="Email"
-                fullWidth
-                error={!!errors.email}
-                helperText={errors.email?.message}
-                className="mb-4"
-              />
-            )}
-          />
-          <Controller
-            name="password"
-            control={control}
-            defaultValue=""
-            render={({ field }) => (
-              <TextField
-                {...field}
-                label="Password"
-                type="password"
-                fullWidth
-                error={!!errors.password}
-                helperText={errors.password?.message}
-                className="mb-4"
-              />
-            )}
-          />
-          <Button type="submit" variant="contained" color="primary" fullWidth>
+        <Box component="form"
+             onSubmit={ handleSubmit( onSubmit ) }
+             className="space-y-4">
+          <Controller name="email"
+                      control={ control }
+                      defaultValue=""
+                      render={ ( { field } ) => (
+                        <TextField
+                          { ...field } label="Email"
+                          fullWidth
+                          error={ !!errors.email }
+                          helperText={ errors.email?.message }
+                          className="mb-4"/>
+                      ) }/>
+          <Controller name="password"
+                      control={ control }
+                      defaultValue=""
+                      render={ ( { field } ) => (
+                        <TextField
+                          { ...field } label="Password"
+                          type="password"
+                          fullWidth
+                          error={ !!errors.password }
+                          helperText={ errors.password?.message }
+                          className="mb-4"/>
+                      ) }/>
+          <Button type="submit"
+                  variant="contained"
+                  color="primary"
+                  fullWidth>
             Login
           </Button>
         </Box>