Files
flyer-crawler.projectium.com/src/components/LoginPage.tsx
Torben Sorensen 24a1c61679
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 23s
move to using /src - still css issue work
2025-11-12 14:55:28 -08:00

118 lines
6.0 KiB
TypeScript

import React, { useState } from 'react';
import { ShoppingCartIcon } from './icons/ShoppingCartIcon';
import { LoadingSpinner } from './LoadingSpinner';
import { EyeIcon } from './icons/EyeIcon';
import { EyeSlashIcon } from './icons/EyeSlashIcon';
interface LoginPageProps {
onLogin: (email: string, pass: string) => void;
onClearError: () => void;
error: string | null;
}
export const LoginPage: React.FC<LoginPageProps> = ({ onLogin, onClearError, error }) => {
const [email, setEmail] = useState('test@test.com');
const [password, setPassword] = useState('pass123');
const [isLoading, setIsLoading] = useState(false);
const [showPassword, setShowPassword] = useState(false);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
setIsLoading(true);
// Simulate network delay
setTimeout(() => {
onLogin(email, password);
setIsLoading(false);
}, 500);
};
const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
// When the user starts typing, clear any previous login errors.
onClearError();
setEmail(e.target.value);
};
const handlePasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
// When the user starts typing, clear any previous login errors.
onClearError();
setPassword(e.target.value);
};
return (
<div className="flex min-h-screen flex-col justify-center items-center bg-gray-100 dark:bg-gray-950 px-6 py-12 lg:px-8">
<div className="sm:mx-auto sm:w-full sm:max-w-sm">
<div className="flex items-center justify-center">
<ShoppingCartIcon className="h-12 w-12 text-brand-primary" />
</div>
<h2 className="mt-6 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900 dark:text-white">
Sign in to Flyer Crawler
</h2>
<p className="mt-2 text-center text-sm text-gray-500 dark:text-gray-400">
Use <code className="bg-gray-200 dark:bg-gray-700 p-1 rounded">test@test.com</code> and <code className="bg-gray-200 dark:bg-gray-700 p-1 rounded">pass123</code>
</p>
</div>
<div className="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
<form className="space-y-6" onSubmit={handleSubmit}>
<div>
<label htmlFor="email" className="block text-sm font-medium leading-6 text-gray-900 dark:text-gray-200">
Email address
</label>
<div className="mt-2">
<input
id="email"
name="email"
type="email"
autoComplete="email"
required
value={email}
onChange={handleEmailChange}
className="block w-full rounded-md border-0 py-1.5 px-2 text-gray-900 dark:text-white bg-white dark:bg-gray-800 shadow-sm ring-1 ring-inset ring-gray-300 dark:ring-gray-700 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-brand-secondary sm:text-sm sm:leading-6"
/>
</div>
</div>
<div>
<div className="flex items-center justify-between">
<label htmlFor="password" className="block text-sm font-medium leading-6 text-gray-900 dark:text-gray-200">
Password
</label>
</div>
<div className="mt-2 relative">
<input
id="password"
name="password"
type={showPassword ? 'text' : 'password'}
autoComplete="current-password"
required
value={password}
onChange={handlePasswordChange}
className="block w-full rounded-md border-0 py-1.5 px-2 pr-10 text-gray-900 dark:text-white bg-white dark:bg-gray-800 shadow-sm ring-1 ring-inset ring-gray-300 dark:ring-gray-700 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-brand-secondary sm:text-sm sm:leading-6"
/>
<button type="button" onClick={() => setShowPassword(!showPassword)} className="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200" aria-label={showPassword ? 'Hide password' : 'Show password'}>
{showPassword ? <EyeSlashIcon className="h-5 w-5" /> : <EyeIcon className="h-5 w-5" />}
</button>
</div>
</div>
{error && (
<div className="text-center text-sm text-red-600 dark:text-red-400 bg-red-100 dark:bg-red-900/30 p-2 rounded-md">
{error}
</div>
)}
<div>
<button
type="submit"
disabled={isLoading}
className="flex w-full justify-center rounded-md bg-brand-primary px-3 py-2 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-brand-secondary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-dark disabled:bg-gray-400 disabled:cursor-not-allowed"
>
{isLoading ? <div className="w-5 h-5"><LoadingSpinner /></div> : 'Sign in'}
</button>
</div>
</form>
</div>
</div>
);
};