From cb2a110ae59636daa19321bac912eebec8520636 Mon Sep 17 00:00:00 2001
From: Michael Hunteman <michael@huntm.net>
Date: Sat, 2 Mar 2024 10:33:48 -0800
Subject: Fix form validation

---
 src/features/auth/GuestLogin.tsx | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

(limited to 'src/features/auth/GuestLogin.tsx')

diff --git a/src/features/auth/GuestLogin.tsx b/src/features/auth/GuestLogin.tsx
index 1f228d8..cbab494 100644
--- a/src/features/auth/GuestLogin.tsx
+++ b/src/features/auth/GuestLogin.tsx
@@ -10,8 +10,7 @@ function GuestLogin() {
   const navigate = useNavigate();
   const [login] = useLoginMutation();
 
-  const { register, handleSubmit,
-  formState: { isDirty, isValid } } = useForm<LoginRequest>({
+  const { register, handleSubmit, formState: { errors } } = useForm<LoginRequest>({
     defaultValues: {
       firstName: '',
       lastName: ''
@@ -29,7 +28,12 @@ function GuestLogin() {
 
   return (
     <Container component="form" maxWidth="xs" onSubmit={handleSubmit(onSubmit)}>
-      <Box sx={{ mt: 8, display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
+      <Box 
+        sx={{ mt: 8, 
+        display: "flex", 
+        flexDirection: "column", 
+        alignItems: "center" }}
+      >
           <Typography variant="h6">
             Guest Login
           </Typography>
@@ -38,24 +42,26 @@ function GuestLogin() {
             variant="outlined"
             margin="normal"
             fullWidth
-            required
-            {...register("firstName", { required: true })}
+            error={!!errors.firstName}
+            helperText={errors.firstName?.message}
+            {...register("firstName", { required: "Please enter your first name" })}
           />
           <TextField
             label="Last Name"
             variant="outlined"
             margin="normal"
             fullWidth
-            required
-            {...register("lastName", { required: true })}
+            error={!!errors.lastName}
+            helperText={errors.lastName?.message}
+            {...register("lastName", { required: "Please enter your last name" })}
           />
           <Button 
             type="submit" 
             variant="contained" 
             fullWidth
             sx={{ mt: 2 }}
-            disabled={!isDirty || !isValid}>
-            Login
+          >
+            Log in
           </Button>
       </Box>
     </Container>
-- 
cgit v1.2.3

