@davoodmehraban89 / Aram-2 Mirror · read-only
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 4, 03:00 UTC

source-data-cleanup
add-index-html-10623938925177053894 arena/094f314c-aram chatgpt-phase1b2-autopilot codex/adr-future-connectors-pi-v1 codex/aram-account-note-source-trace-20261031 codex/aram-actions-node24-maintenance-20261031 codex/aram-analyst-review-workbook-20261031 codex/aram-bs-candidate-statement-20261031 codex/aram-cash-flow-direct-candidate-20261031 codex/aram-clean-reference-year-integrity-20261030 codex/aram-cross-statement-controls-20261031 codex/aram-equity-changes-candidate-20261031 codex/aram-five-statement-cli-20261031 codex/aram-five-statement-integration-20261031 codex/aram-five-statement-orchestrator-20261031 codex/aram-gate3-coverage-target-guard-20261030 codex/aram-gate3-hidden-xlsx-guard-20261030 codex/aram-gate3-integration-validation-20261030 codex/aram-gate3-mapping-change-preview-20261030 codex/aram-gate3-stale-note-guard-20261030 codex/aram-income-statement-candidate-20261031 codex/aram-manifest-referential-integrity-20261031 codex/aram-mapping-source-parser-20261101 codex/aram-multidimensional-mapping-20261101 codex/aram-multistatement-mapping-20261031 codex/aram-pipeline-manifest-schema-20261031 codex/aram-readonly-mapping-coverage-20261031 codex/aram-reconciliation-review-gate-20261031 codex/aram-same-flush-fiscal-lock-20261030 codex/aram-synthetic-windows-demo-20261031 codex/aram-trial-balance-diagnostic-20261031 codex/aram-windows-background-detail-search-20261031 codex/aram-windows-detail-review-20261031 codex/aram-windows-five-statement-pilot-20261031 codex/aram-windows-statement-figures-20261031 codex/gate-2a-pilot-workbook codex/gate-2a-pilot-workbook-6864754244772568979 codex/gate3-authenticated-principal-boundary-20261030 codex/gate3-authored-draft-staging-20261030 codex/gate3-carry-forward-preview-20261023 codex/gate3-draft-staging-audit-20261030 codex/gate3-mapping-batch-freshness-20261030 codex/gate3-mapping-batch-review-20261030 codex/gate3-mapping-core codex/gate3-mapping-coverage-20261023 codex/gate3-mapping-excel-20261023 codex/gate3-note-mapping-review-20261023 codex/gate3-signed-year-scope-20261030 codex/gate3-unapproved-proposal-storage-20261030 codex/payvast-mapping-discovery-20261023 codex/phase-2a-backend-foundation codex/phase-2b-post-merge-record codex/phase-2b-source-registration codex/phase-2b-source-registration-12955190277775369594 codex/post-gate2a-control-reconciliation codex/post-pr18-acceptance-record codex/project-control-foundation codex/t1-repo-hygiene-20261023 codex/t2-ci-hardening-20261023 codex/t3-explicit-migrations-20261023 codex/t6a-readonly-diagnostics-20261023 codex/v1-01-safety-gate-hardening codex/v1-year-isolation-followup-20261023 codex/windows-native-pilot-shell-20261030 docs/aram-master-control-plan-20261111 docs/aram-roadmap-dashboard-20261030 docs/financial-statement-reconciliation-1402-1404-20261110 feat/gate3-governed-mapping-20261101 feat/gate3-package9-1-security-20261103 feat/gate3-package9-isolated-20261103 fix/password-unicode-validation-20261111 governance/aram-5-1-3-controls-20261030 governance/role-based-operating-model jules-1168663913887856558-73b8a885 jules-gate-2b-mapping-workflow-foundation-4137724387867065330 phase-1b1-audit-report-7365389436990903239 phase-2a-backend-foundation-10237597358138521261 phase1b2-postmerge-metadata-fix refactor/drg-parent-year-id-15088443704684163304 source-data-cleanup
tsx 178 lines 5.51 KB
Raw
1 import { useState } from 'react'
2 import { api, ApiError } from '../api/client'
3
4 interface Props {
5 yearId: number
6 }
7
8 interface Session {
9 username: string
10 role: string
11 }
12
13 export default function AdminPanel({ yearId }: Props) {
14 const [session, setSession] = useState<Session | null>(null)
15 const [username, setUsername] = useState('')
16 const [password, setPassword] = useState('')
17 const [message, setMessage] = useState<string | null>(null)
18 const [error, setError] = useState<string | null>(null)
19 const [busy, setBusy] = useState(false)
20 const [backupDest, setBackupDest] = useState('')
21 const [reopenReason, setReopenReason] = useState('')
22 const [lastRequestId, setLastRequestId] = useState<number | null>(null)
23
24 async function run(fn: () => Promise<string>) {
25 setBusy(true)
26 setError(null)
27 setMessage(null)
28 try {
29 setMessage(await fn())
30 } catch (err) {
31 setError(err instanceof ApiError ? err.message : String(err))
32 } finally {
33 setBusy(false)
34 }
35 }
36
37 async function login(e: React.FormEvent) {
38 e.preventDefault()
39 setBusy(true)
40 setError(null)
41 try {
42 const res = await api.login(username.trim(), password)
43 setSession({ username: res.username, role: res.role })
44 setPassword('')
45 } catch (err) {
46 setError(err instanceof ApiError ? err.message : String(err))
47 } finally {
48 setBusy(false)
49 }
50 }
51
52 const actor = session?.username ?? ''
53
54 return (
55 <section className="card">
56 <h2>مدیریت، ممیزی و پشتیبان‌گیری</h2>
57
58 {!session ? (
59 <form className="row" onSubmit={login}>
60 <label>
61 نام کاربری
62 <input value={username} onChange={(e) => setUsername(e.target.value)} required />
63 </label>
64 <label>
65 گذرواژه
66 <input
67 type="password"
68 value={password}
69 onChange={(e) => setPassword(e.target.value)}
70 required
71 />
72 </label>
73 <button type="submit" disabled={busy}>
74 ورود
75 </button>
76 </form>
77 ) : (
78 <p className="ok">
79 وارد شده: {session.username} ({session.role})
80 </p>
81 )}
82
83 {session && (
84 <>
85 <div className="row">
86 <button
87 type="button"
88 disabled={busy}
89 onClick={() =>
90 run(async () => {
91 const r = await api.auditVerify()
92 return r.chain_valid ? 'زنجیرهٔ ممیزی سالم است.' : 'زنجیرهٔ ممیزی مخدوش است!'
93 })
94 }
95 >
96 بررسی زنجیرهٔ ممیزی
97 </button>
98 <button
99 type="button"
100 disabled={busy}
101 onClick={() => run(async () => `سال قفل شد: ${(await api.lockYear(yearId, actor)).status}`)}
102 >
103 قفل سال
104 </button>
105 </div>
106
107 <div className="row">
108 <label>
109 دلیل بازگشایی
110 <input value={reopenReason} onChange={(e) => setReopenReason(e.target.value)} />
111 </label>
112 <button
113 type="button"
114 disabled={busy || !reopenReason}
115 onClick={() =>
116 run(async () => {
117 const r = await api.requestReopen(yearId, reopenReason, actor)
118 setLastRequestId(r.request_id)
119 return `درخواست بازگشایی ثبت شد (${r.request_id}).`
120 })
121 }
122 >
123 درخواست بازگشایی
124 </button>
125 <button
126 type="button"
127 disabled={busy || lastRequestId === null}
128 onClick={() =>
129 run(async () => {
130 if (lastRequestId === null) return ''
131 await api.approveReopen(lastRequestId, actor)
132 const r = await api.reopenYear(yearId, actor)
133 return `سال بازگشایی شد: ${r.status}`
134 })
135 }
136 >
137 تصویب و بازگشایی
138 </button>
139 </div>
140
141 <div className="row">
142 <label>
143 مسیر پشتیبان
144 <input value={backupDest} onChange={(e) => setBackupDest(e.target.value)} />
145 </label>
146 <button
147 type="button"
148 disabled={busy || !backupDest}
149 onClick={() =>
150 run(async () => {
151 const r = await api.backup(backupDest, actor)
152 return `پشتیبان ساخته شد (زنجیرهٔ ممیزی: ${r.manifest.audit_chain_valid ? 'سالم' : 'مخدوش'}).`
153 })
154 }
155 >
156 پشتیبان‌گیری
157 </button>
158 <button
159 type="button"
160 disabled={busy || !backupDest}
161 onClick={() =>
162 run(async () => {
163 const r = await api.verifyBackup(backupDest, actor)
164 return `پشتیبان ${r.valid ? 'سالم' : 'مخدوش'} است (${r.source_files} فایل، ${r.audit_entries} ممیزی).`
165 })
166 }
167 >
168 بررسی پشتیبان
169 </button>
170 </div>
171 </>
172 )}
173
174 {message && <p className="ok">{message}</p>}
175 {error && <p className="error">{error}</p>}
176 </section>
177 )
178 }