Files
portfolio-site/frontend/src/components/LoginDialog.tsx
2025-10-20 06:32:14 -04:00

60 lines
2.1 KiB
TypeScript

import {useState} from 'react';
import {Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle} from '@/components/ui/dialog';
import {Input} from '@/components/ui/input';
import {Button} from '@/components/ui/button';
interface LoginDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onLogin: (email: string, password: string) => boolean;
}
export const LoginDialog = ({open, onOpenChange, onLogin}: LoginDialogProps) => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
setError('');
const success = onLogin(email, password);
if (success) {
setEmail('');
setPassword('');
onOpenChange(false);
} else {
setError('Invalid credentials. Please try again.');
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Artist Login</DialogTitle>
<DialogDescription>Enter your credentials to manage your portfolio</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4 mt-4">
<div className="space-y-2">
<label htmlFor="email" className="text-sm font-medium">
Email
</label>
<Input id="email" type="email" placeholder="artist@example.com" value={email} onChange={e => setEmail(e.target.value)} required />
</div>
<div className="space-y-2">
<label htmlFor="password" className="text-sm font-medium">
Password
</label>
<Input id="password" type="password" placeholder="••••••••" value={password} onChange={e => setPassword(e.target.value)} required />
</div>
{error && <p className="text-sm text-destructive">{error}</p>}
<Button type="submit" className="w-full">
Login
</Button>
</form>
</DialogContent>
</Dialog>
);
};