Rework the login and register forms for the split-screen layout

This commit is contained in:
Aaron Po
2026-10-08 23:10:48 -04:00
parent 9968f4458a
commit 9af8b968a8
2 changed files with 113 additions and 99 deletions

View File

@@ -1,8 +1,9 @@
import { BaseSyntheticEvent } from 'react'; import { BaseSyntheticEvent, useState } from 'react';
import { FormState, UseFormRegister } from 'react-hook-form'; import { FormState, UseFormRegister } from 'react-hook-form';
import FormField from '../../../components/ui/forms/FormField'; import FormField from '../../../components/ui/forms/FormField';
import SubmitButton from '../../../components/ui/forms/SubmitButton'; import SubmitButton from '../../../components/ui/forms/SubmitButton';
import type { LoginSchema } from '../schemas'; import type { LoginSchema } from '../schemas';
import ShowPasswordToggle from './ShowPasswordToggle';
interface LoginFormProps { interface LoginFormProps {
onSubmit: (e?: BaseSyntheticEvent) => Promise<Awaited<void> | undefined>; onSubmit: (e?: BaseSyntheticEvent) => Promise<Awaited<void> | undefined>;
@@ -11,13 +12,15 @@ interface LoginFormProps {
submitting: boolean; submitting: boolean;
} }
const LoginForm = (props: LoginFormProps) => ( const LoginForm = (props: LoginFormProps) => {
<form onSubmit={props.onSubmit} className="space-y-3"> const [showPassword, setShowPassword] = useState(false);
return (
<form onSubmit={props.onSubmit} className="flex flex-col gap-4">
<FormField <FormField
id="username" id="username"
type="text" type="text"
autoComplete="username" autoComplete="username"
placeholder="your_username"
label="Username" label="Username"
error={props.formState.errors.username?.message} error={props.formState.errors.username?.message}
{...props.register('username')} {...props.register('username')}
@@ -25,20 +28,26 @@ const LoginForm = (props: LoginFormProps) => (
<FormField <FormField
id="password" id="password"
type="password" type={showPassword ? 'text' : 'password'}
autoComplete="current-password" autoComplete="current-password"
placeholder="••••••••"
label="Password" label="Password"
error={props.formState.errors.password?.message} error={props.formState.errors.password?.message}
{...props.register('password')} {...props.register('password')}
/> />
<ShowPasswordToggle
shown={showPassword}
onToggle={() => setShowPassword((shown) => !shown)}
/>
<SubmitButton <SubmitButton
isSubmitting={props.submitting} isSubmitting={props.submitting}
idleText="Sign In" idleText="Sign in"
submittingText="Signing in..." submittingText="Signing in…"
className="btn btn-primary min-h-12 w-full"
/> />
</form> </form>
); );
};
export default LoginForm; export default LoginForm;

View File

@@ -1,8 +1,9 @@
import { BaseSyntheticEvent } from 'react'; import { BaseSyntheticEvent, useState } from 'react';
import { FormState, UseFormRegister } from 'react-hook-form'; import { FormState, UseFormRegister } from 'react-hook-form';
import FormField from '../../../components/ui/forms/FormField'; import FormField from '../../../components/ui/forms/FormField';
import SubmitButton from '../../../components/ui/forms/SubmitButton'; import SubmitButton from '../../../components/ui/forms/SubmitButton';
import type { RegisterSchema } from '../schemas'; import type { RegisterSchema } from '../schemas';
import ShowPasswordToggle from './ShowPasswordToggle';
interface RegisterFormProps { interface RegisterFormProps {
onSubmit: (e?: BaseSyntheticEvent) => Promise<Awaited<void> | undefined>; onSubmit: (e?: BaseSyntheticEvent) => Promise<Awaited<void> | undefined>;
@@ -11,26 +12,17 @@ interface RegisterFormProps {
submitting: boolean; submitting: boolean;
} }
const RegisterForm = (props: RegisterFormProps) => ( const RegisterForm = (props: RegisterFormProps) => {
<form onSubmit={props.onSubmit} className="space-y-3"> const [showPassword, setShowPassword] = useState(false);
<FormField
id="username"
type="text"
autoComplete="username"
placeholder="your_username"
label="Username"
hint="3-64 characters, alphanumeric and . _ -"
error={props.formState.errors.username?.message}
{...props.register('username')}
/>
<div className="grid grid-cols-2 gap-3"> return (
<form onSubmit={props.onSubmit} className="flex flex-col gap-4">
<div className="grid grid-cols-1 gap-3.5 min-[420px]:grid-cols-2">
<FormField <FormField
id="firstName" id="firstName"
type="text" type="text"
autoComplete="given-name" autoComplete="given-name"
placeholder="Jane" label="First name"
label="First Name"
error={props.formState.errors.firstName?.message} error={props.formState.errors.firstName?.message}
{...props.register('firstName')} {...props.register('firstName')}
/> />
@@ -39,18 +31,26 @@ const RegisterForm = (props: RegisterFormProps) => (
id="lastName" id="lastName"
type="text" type="text"
autoComplete="family-name" autoComplete="family-name"
placeholder="Doe" label="Last name"
label="Last Name"
error={props.formState.errors.lastName?.message} error={props.formState.errors.lastName?.message}
{...props.register('lastName')} {...props.register('lastName')}
/> />
</div> </div>
<FormField
id="username"
type="text"
autoComplete="username"
label="Username"
hint="3-64 characters, alphanumeric and . _ -"
error={props.formState.errors.username?.message}
{...props.register('username')}
/>
<FormField <FormField
id="email" id="email"
type="email" type="email"
autoComplete="email" autoComplete="email"
placeholder="jane@example.com"
label="Email" label="Email"
error={props.formState.errors.email?.message} error={props.formState.errors.email?.message}
{...props.register('email')} {...props.register('email')}
@@ -59,17 +59,16 @@ const RegisterForm = (props: RegisterFormProps) => (
<FormField <FormField
id="dateOfBirth" id="dateOfBirth"
type="date" type="date"
label="Date of Birth" label="Date of birth"
hint="Must be 19 years or older" hint="Must be 19 years or older."
error={props.formState.errors.dateOfBirth?.message} error={props.formState.errors.dateOfBirth?.message}
{...props.register('dateOfBirth')} {...props.register('dateOfBirth')}
/> />
<FormField <FormField
id="password" id="password"
type="password" type={showPassword ? 'text' : 'password'}
autoComplete="new-password" autoComplete="new-password"
placeholder="••••••••"
label="Password" label="Password"
hint="8+ chars: uppercase, lowercase, digit, special character" hint="8+ chars: uppercase, lowercase, digit, special character"
error={props.formState.errors.password?.message} error={props.formState.errors.password?.message}
@@ -78,20 +77,26 @@ const RegisterForm = (props: RegisterFormProps) => (
<FormField <FormField
id="confirmPassword" id="confirmPassword"
type="password" type={showPassword ? 'text' : 'password'}
autoComplete="new-password" autoComplete="new-password"
placeholder="••••••••" label="Confirm password"
label="Confirm Password"
error={props.formState.errors.confirmPassword?.message} error={props.formState.errors.confirmPassword?.message}
{...props.register('confirmPassword')} {...props.register('confirmPassword')}
/> />
<ShowPasswordToggle
shown={showPassword}
onToggle={() => setShowPassword((shown) => !shown)}
/>
<SubmitButton <SubmitButton
isSubmitting={props.submitting} isSubmitting={props.submitting}
idleText="Create Account" idleText="Create account"
submittingText="Creating account..." submittingText="Creating account…"
className="btn btn-primary min-h-12 w-full"
/> />
</form> </form>
); );
};
export default RegisterForm; export default RegisterForm;