103 lines
3.1 KiB
JavaScript
103 lines
3.1 KiB
JavaScript
import React, { useState } from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { useAdmin } from '../../contexts/AdminContext.js';
|
|
import { Button } from '../ui/button.js';
|
|
import { Input } from '../ui/input.js';
|
|
|
|
export default function AdminLogin() {
|
|
const [username, setUsername] = useState('');
|
|
const [password, setPassword] = useState('');
|
|
const [loading, setLoading] = useState(false);
|
|
const [error, setError] = useState('');
|
|
const { login } = useAdmin();
|
|
const navigate = useNavigate();
|
|
|
|
const handleSubmit = async (e) => {
|
|
e.preventDefault();
|
|
setError('');
|
|
setLoading(true);
|
|
|
|
const result = await login(username, password);
|
|
|
|
if (result.success) {
|
|
navigate('/admin/dashboard');
|
|
} else {
|
|
setError(result.error);
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
|
<div className="max-w-md w-full space-y-8 p-8 bg-white rounded-lg shadow-md">
|
|
<div>
|
|
<h2 className="mt-6 text-center text-3xl font-bold text-gray-900">
|
|
Organization Admin Portal
|
|
</h2>
|
|
<p className="mt-2 text-center text-sm text-gray-600">
|
|
Sign in to manage your organization
|
|
</p>
|
|
</div>
|
|
|
|
<form className="mt-8 space-y-6" onSubmit={handleSubmit}>
|
|
{error && (
|
|
<div className="rounded-md bg-red-50 p-4">
|
|
<div className="text-sm text-red-700">{error}</div>
|
|
</div>
|
|
)}
|
|
|
|
<div className="rounded-md shadow-sm space-y-4">
|
|
<div>
|
|
<label htmlFor="username" className="block text-sm font-medium text-gray-700 mb-1">
|
|
Username
|
|
</label>
|
|
<Input
|
|
id="username"
|
|
name="username"
|
|
type="text"
|
|
autoComplete="username"
|
|
required
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
placeholder="Enter your username"
|
|
disabled={loading}
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label htmlFor="password" className="block text-sm font-medium text-gray-700 mb-1">
|
|
Password
|
|
</label>
|
|
<Input
|
|
id="password"
|
|
name="password"
|
|
type="password"
|
|
autoComplete="current-password"
|
|
required
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
placeholder="Enter your password"
|
|
disabled={loading}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<Button
|
|
type="submit"
|
|
className="w-full"
|
|
disabled={loading}
|
|
>
|
|
{loading ? 'Signing in...' : 'Sign in'}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
|
|
<div className="text-center text-xs text-gray-500">
|
|
© {new Date().getFullYear()} AptivaAI™ LLC
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|