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,34 +12,42 @@ 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);
<FormField
id="username"
type="text"
autoComplete="username"
placeholder="your_username"
label="Username"
error={props.formState.errors.username?.message}
{...props.register('username')}
/>
<FormField return (
id="password" <form onSubmit={props.onSubmit} className="flex flex-col gap-4">
type="password" <FormField
autoComplete="current-password" id="username"
placeholder="••••••••" type="text"
label="Password" autoComplete="username"
error={props.formState.errors.password?.message} label="Username"
{...props.register('password')} error={props.formState.errors.username?.message}
/> {...props.register('username')}
/>
<SubmitButton <FormField
isSubmitting={props.submitting} id="password"
idleText="Sign In" type={showPassword ? 'text' : 'password'}
submittingText="Signing in..." autoComplete="current-password"
/> label="Password"
</form> error={props.formState.errors.password?.message}
); {...props.register('password')}
/>
<ShowPasswordToggle
shown={showPassword}
onToggle={() => setShowPassword((shown) => !shown)}
/>
<SubmitButton
isSubmitting={props.submitting}
idleText="Sign in"
submittingText="Signing in…"
className="btn btn-primary min-h-12 w-full"
/>
</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,87 +12,91 @@ 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" return (
type="text" <form onSubmit={props.onSubmit} className="flex flex-col gap-4">
autoComplete="username" <div className="grid grid-cols-1 gap-3.5 min-[420px]:grid-cols-2">
placeholder="your_username" <FormField
label="Username" id="firstName"
hint="3-64 characters, alphanumeric and . _ -" type="text"
error={props.formState.errors.username?.message} autoComplete="given-name"
{...props.register('username')} label="First name"
/> error={props.formState.errors.firstName?.message}
{...props.register('firstName')}
/>
<FormField
id="lastName"
type="text"
autoComplete="family-name"
label="Last name"
error={props.formState.errors.lastName?.message}
{...props.register('lastName')}
/>
</div>
<div className="grid grid-cols-2 gap-3">
<FormField <FormField
id="firstName" id="username"
type="text" type="text"
autoComplete="given-name" autoComplete="username"
placeholder="Jane" label="Username"
label="First Name" hint="3-64 characters, alphanumeric and . _ -"
error={props.formState.errors.firstName?.message} error={props.formState.errors.username?.message}
{...props.register('firstName')} {...props.register('username')}
/> />
<FormField <FormField
id="lastName" id="email"
type="text" type="email"
autoComplete="family-name" autoComplete="email"
placeholder="Doe" label="Email"
label="Last Name" error={props.formState.errors.email?.message}
error={props.formState.errors.lastName?.message} {...props.register('email')}
{...props.register('lastName')}
/> />
</div>
<FormField <FormField
id="email" id="dateOfBirth"
type="email" type="date"
autoComplete="email" label="Date of birth"
placeholder="jane@example.com" hint="Must be 19 years or older."
label="Email" error={props.formState.errors.dateOfBirth?.message}
error={props.formState.errors.email?.message} {...props.register('dateOfBirth')}
{...props.register('email')} />
/>
<FormField <FormField
id="dateOfBirth" id="password"
type="date" type={showPassword ? 'text' : 'password'}
label="Date of Birth" autoComplete="new-password"
hint="Must be 19 years or older" label="Password"
error={props.formState.errors.dateOfBirth?.message} hint="8+ chars: uppercase, lowercase, digit, special character"
{...props.register('dateOfBirth')} error={props.formState.errors.password?.message}
/> {...props.register('password')}
/>
<FormField <FormField
id="password" id="confirmPassword"
type="password" type={showPassword ? 'text' : 'password'}
autoComplete="new-password" autoComplete="new-password"
placeholder="••••••••" label="Confirm password"
label="Password" error={props.formState.errors.confirmPassword?.message}
hint="8+ chars: uppercase, lowercase, digit, special character" {...props.register('confirmPassword')}
error={props.formState.errors.password?.message} />
{...props.register('password')}
/>
<FormField <ShowPasswordToggle
id="confirmPassword" shown={showPassword}
type="password" onToggle={() => setShowPassword((shown) => !shown)}
autoComplete="new-password" />
placeholder="••••••••"
label="Confirm Password"
error={props.formState.errors.confirmPassword?.message}
{...props.register('confirmPassword')}
/>
<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;