ifixkart-admin/app/(auth)/login/page.tsx

132 lines
4.8 KiB
TypeScript

'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { Wrench, Eye, EyeOff, Loader2 } from 'lucide-react';
import { authService } from '@/services/api/authService';
import { toast } from 'sonner';
export default function LoginPage() {
const router = useRouter();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [showPassword, setShowPassword] = useState(false);
const [loading, setLoading] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!email || !password) {
toast.error('Enter your email and password');
return;
}
setLoading(true);
try {
await authService.login({ email, password });
toast.success('Signed in successfully');
router.push('/dashboard');
} catch (err: unknown) {
const message = err instanceof Error ? err.message : 'Login failed';
toast.error(message);
} finally {
setLoading(false);
}
};
return (
<div className="min-h-screen flex items-center justify-center px-4 bg-background">
<div className="w-full max-w-[420px]">
{/* Logo */}
<div className="flex flex-col items-center mb-8">
<div className="w-14 h-14 rounded-2xl flex items-center justify-center mb-4 bg-primary">
<Wrench className="w-7 h-7 text-white" />
</div>
<h1 className="text-2xl font-bold text-foreground">
iFixKart
</h1>
<p className="text-sm mt-1 text-muted-foreground">
Enterprise ERP Platform
</p>
</div>
{/* Login Card */}
<div className="bg-card rounded-[5px] shadow-sm border border-border p-5 sm:p-8">
<h2 className="text-lg font-bold mb-1 text-foreground">
Sign In
</h2>
<p className="text-xs mb-6 text-muted-foreground">
Enter your credentials to access the admin panel
</p>
<form onSubmit={handleSubmit} className="flex flex-col gap-4">
{/* Email */}
<div className="flex flex-col gap-1.5">
<label htmlFor="email" className="text-xs font-semibold text-foreground">
Email Address
</label>
<input
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="admin@ifixkart.com"
className="w-full px-3.5 py-2.5 rounded-lg border border-border bg-muted text-sm text-foreground outline-hidden transition-colors focus:ring-2 focus:ring-primary/20 focus:border-primary"
autoComplete="email"
/>
</div>
{/* Password */}
<div className="flex flex-col gap-1.5">
<label htmlFor="password" className="text-xs font-semibold text-foreground">
Password
</label>
<div className="relative">
<input
id="password"
type={showPassword ? 'text' : 'password'}
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Enter your password"
className="w-full px-3.5 py-2.5 rounded-lg border border-border bg-muted text-sm text-foreground outline-hidden transition-colors focus:ring-2 focus:ring-primary/20 focus:border-primary pr-10"
autoComplete="current-password"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 cursor-pointer text-muted-foreground"
tabIndex={-1}
>
{showPassword ? (
<EyeOff className="w-4 h-4" />
) : (
<Eye className="w-4 h-4" />
)}
</button>
</div>
</div>
{/* Submit */}
<button
type="submit"
disabled={loading}
className="w-full py-2.5 rounded-lg text-sm font-semibold text-white bg-primary cursor-pointer transition-opacity disabled:opacity-70 flex items-center justify-center gap-2 min-h-[44px] mt-2"
>
{loading ? (
<>
<Loader2 className="w-4 h-4 animate-spin" />
<span>Signing in...</span>
</>
) : (
<span>Sign In</span>
)}
</button>
</form>
</div>
<p className="text-center text-[11px] mt-6 text-muted-foreground">
© 2026 iFixKart. All rights reserved.
</p>
</div>
</div>
);
}