55 lines
2.8 KiB
TypeScript
55 lines
2.8 KiB
TypeScript
import { KeyRound, ShieldCheck } from "lucide-react";
|
||
import { useState, type FormEvent } from "react";
|
||
import { useDeploymentProfile } from "../deployment/DeploymentProfileContext";
|
||
import { apiOrigin } from "../lib/api";
|
||
|
||
export function ActivationPage() {
|
||
const { profile, refreshProfile } = useDeploymentProfile();
|
||
const [code, setCode] = useState("");
|
||
const [busy, setBusy] = useState(false);
|
||
const [error, setError] = useState("");
|
||
|
||
async function submit(event: FormEvent) {
|
||
event.preventDefault();
|
||
setBusy(true); setError("");
|
||
try {
|
||
const response = await fetch(`${apiOrigin}/api/v1/deployment/activation`, {
|
||
method: "POST", credentials: "include",
|
||
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
||
body: JSON.stringify({ activationCode: code.trim() })
|
||
});
|
||
if (!response.ok) {
|
||
throw new Error("مشکلی پیش آمده است. لطفاً با پشتیبانی تماس بگیرید.");
|
||
}
|
||
await refreshProfile();
|
||
} catch {
|
||
setError("مشکلی پیش آمده است. لطفاً با پشتیبانی تماس بگیرید.");
|
||
} finally { setBusy(false); }
|
||
}
|
||
|
||
return <main className="activation-page">
|
||
<section className="activation-card">
|
||
<div className="activation-brand">
|
||
<img src="/product-logo.svg" alt=""/>
|
||
<div><h1>{profile.branding.applicationTitle}</h1><p>{profile.company.displayName}</p></div>
|
||
</div>
|
||
<div className="activation-heading"><span><KeyRound/></span><div><h2>فعالسازی سامانه</h2><p>این نسخه تا زمان ثبت کد معتبر قابل استفاده نیست.</p></div></div>
|
||
<div className="fingerprint-box">
|
||
<div><strong>شناسه ۶۴ کاراکتری سرور</strong><span>{profile.activation.fingerprintLength} / 64</span></div>
|
||
<code>{profile.activation.serverFingerprint}</code>
|
||
<button type="button" onClick={() => void navigator.clipboard.writeText(profile.activation.serverFingerprint)}>کپی شناسه</button>
|
||
</div>
|
||
{error && <div className="error-banner" role="alert">{error}</div>}
|
||
<form className="form-stack" onSubmit={submit}>
|
||
<label className="field"><span>کد فعالسازی امضاشده</span>
|
||
<textarea className="input textarea activation-code-input latin" rows={5} value={code} onChange={event => setCode(event.target.value)} required spellCheck={false}/>
|
||
<small>کد فقط یکبار ثبت میشود و پس از تأیید قابل جایگزینی نیست.</small>
|
||
</label>
|
||
<button className="button activation-submit" disabled={busy || !code.trim()}><ShieldCheck size={18}/>{busy ? "در حال بررسی…" : "ثبت و فعالسازی"}</button>
|
||
</form>
|
||
</section>
|
||
</main>;
|
||
}
|
||
|
||
|