import React, { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { toast } from '@/hooks/use-toast'; import { Lock } from 'lucide-react'; interface LoginPageProps { onLogin: (token: string) => void; } const LoginPage = ({ onLogin }: LoginPageProps) => { const [password, setPassword] = useState(''); const [isLoading, setIsLoading] = useState(false); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); if (!password.trim()) { toast({ title: "Error", description: "Please enter a password", variant: "destructive", }); return; } setIsLoading(true); try { const response = await fetch('/admin/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ Password: password }), }); const data = await response.json(); if (response.ok && data.token) { toast({ title: "Success", description: data.message || "Login successful", }); onLogin(data.token); } else { toast({ title: "Error", description: data.message || "Login failed", variant: "destructive", }); } } catch (error) { toast({ title: "Error", description: "Network error. Please try again.", variant: "destructive", }); } finally { setIsLoading(false); } }; return (
Admin Login
setPassword(e.target.value)} className="h-12" disabled={isLoading} />
); }; export default LoginPage;