inogen/app/admin/pages/LoginPage.tsx

50 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { LockKeyhole } from "lucide-react";
import { useState, type FormEvent } from "react";
import { Navigate } from "react-router";
import { useAuth } from "../auth/AuthContext";
import { useDeploymentProfile } from "../deployment/DeploymentProfileContext";
import { ApiError } from "../lib/api";
import { Button, ErrorBanner, Field, Input } from "../components/Ui";
import { AdminCopyright } from "../components/AdminCopyright";
export function LoginPage() {
const { user, login } = useAuth();
const { profile, assetUrl } = useDeploymentProfile();
const [userName, setUserName] = useState("");
const [password, setPassword] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
if (user) return <Navigate to={profile.isConfigured ? "/admin" : "/admin/deployment-settings"} replace/>;
async function submit(event: FormEvent) {
event.preventDefault(); setBusy(true); setError("");
try { await login(userName, password); }
catch (reason) { setError(reason instanceof ApiError ? reason.message : "ورود امکان‌پذیر نبود."); }
finally { setBusy(false); }
}
return <div className="login-page">
<section className="login-story">
<div className="login-company-brand">
<img className="login-company-logo" src={assetUrl(profile.branding.adminLoginLogoAssetKey)} alt={profile.company.displayName}/>
<h1>{profile.company.displayName}</h1>
</div>
</section>
<section className="login-panel">
<div className="login-panel-content">
<form className="login-card" onSubmit={submit}>
<img className="login-product-logo" src="/product-logo.svg" alt={profile.branding.applicationTitle}/>
<div className="login-icon"><LockKeyhole/></div>
<h2>{profile.branding.adminTitle}</h2><p>برای ادامه، اطلاعات حساب سامانه را وارد کنید.</p>
{error && <ErrorBanner message={error}/>}
<Field label="نام کاربری"><Input autoComplete="username" value={userName} onChange={e => setUserName(e.target.value)} required/></Field>
<Field label="رمز عبور"><Input type="password" autoComplete="current-password" value={password} onChange={e => setPassword(e.target.value)} required/></Field>
<Button type="submit" disabled={busy}>{busy ? "در حال بررسی…" : "ورود به پنل"}</Button>
</form>
<AdminCopyright />
</div>
</section>
</div>;
}