chore: add client/src/pages/admin/login.tsx
This commit is contained in:
parent
a248dc559b
commit
e122466c8d
1 changed files with 63 additions and 0 deletions
63
client/src/pages/admin/login.tsx
Normal file
63
client/src/pages/admin/login.tsx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { useState } from "react";
|
||||
import { useLocation } from "wouter";
|
||||
import { queryClient, apiRequest } from "../../lib/queryClient";
|
||||
import { toast } from "../../hooks/use-toast";
|
||||
import { ShoppingBag } from "lucide-react";
|
||||
|
||||
export default function AdminLogin() {
|
||||
const [, setLocation] = useLocation();
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
try {
|
||||
await apiRequest("POST", "/api/admin/login", { email, password });
|
||||
await queryClient.invalidateQueries({ queryKey: ["/api/admin/me"] });
|
||||
setLocation("/admin");
|
||||
} catch (err: any) {
|
||||
toast({ title: "Sign in failed", description: err.message, variant: "destructive" });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center px-4 bg-muted/20">
|
||||
<div className="w-full max-w-sm">
|
||||
<div className="text-center mb-8">
|
||||
<ShoppingBag size={32} className="mx-auto mb-3 text-primary" />
|
||||
<h1 className="text-2xl font-bold">Admin Login</h1>
|
||||
<p className="text-sm text-muted-foreground mt-1">NoShop Store Management</p>
|
||||
</div>
|
||||
<div className="bg-card border border-border rounded-xl p-6 shadow-sm">
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-muted-foreground mb-1">Email</label>
|
||||
<input
|
||||
type="email" value={email} onChange={(e) => setEmail(e.target.value)} required
|
||||
className="w-full px-3 py-2 border border-border rounded-md text-sm bg-background focus:outline-none focus:ring-2 focus:ring-primary/30"
|
||||
data-testid="input-admin-email"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-muted-foreground mb-1">Password</label>
|
||||
<input
|
||||
type="password" value={password} onChange={(e) => setPassword(e.target.value)} required
|
||||
className="w-full px-3 py-2 border border-border rounded-md text-sm bg-background focus:outline-none focus:ring-2 focus:ring-primary/30"
|
||||
data-testid="input-admin-password"
|
||||
/>
|
||||
</div>
|
||||
<button type="submit" disabled={loading}
|
||||
className="w-full bg-primary text-primary-foreground py-2.5 rounded-md font-semibold text-sm hover:bg-primary/90 transition-colors disabled:opacity-60"
|
||||
data-testid="button-admin-login">
|
||||
{loading ? "Signing in..." : "Sign in"}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue