@davoodmehraban89 / Aram-1 / commits / 87b1929
Fork 0

feat(ui): notes/mappings manager (edit/delete) wired to the editing API

NotesManager lists notes (inline title edit + delete) and mappings (delete), refreshing after each change. eslint/tsc/vitest/build pass. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>

davoodmehraban89 committed Dec 3, 2026 at 12:47 UTC 87b192979f23ed166968ea0b0620f622167b2a63
4 files changed +187
frontend/src/App.test.tsx
+5
@@ -21,6 +21,11 @@ vi.mock('./api/client', async () => {
21 exportMappingsUrl: (id: number) => `/api/v1/years/${id}/mappings/export`,
22 exportStatementsUrl: (id: number, format: string) =>
23 `/api/v1/years/${id}/statements/export?format=${format}`,
24 + listNotes: vi.fn().mockResolvedValue({ notes: [] }),
25 + listMappings: vi.fn().mockResolvedValue({ mappings: [] }),
26 + updateNote: vi.fn(),
27 + deleteNote: vi.fn(),
28 + deleteMapping: vi.fn(),
29 login: vi.fn(),
30 createUser: vi.fn(),
31 auditVerify: vi.fn(),
frontend/src/App.tsx
+2
@@ -5,6 +5,7 @@ import ApprovalPanel from './components/ApprovalPanel'
5 import CompanySetup from './components/CompanySetup'
6 import LedgerUpload from './components/LedgerUpload'
7 import MappingPanel from './components/MappingPanel'
8 +import NotesManager from './components/NotesManager'
9 import StatementView from './components/StatementView'
10 import { faNumber } from './lib/format'
11
@@ -34,6 +35,7 @@ export default function App() {
35 <>
36 <LedgerUpload yearId={company.year_id} onImported={() => setStatementRefresh((k) => k + 1)} />
37 <MappingPanel yearId={company.year_id} />
38 + <NotesManager yearId={company.year_id} refreshKey={statementRefresh} />
39 <StatementView yearId={company.year_id} refreshKey={statementRefresh} />
40 <ApprovalPanel yearId={company.year_id} />
41 <AdminPanel yearId={company.year_id} />
frontend/src/api/client.ts
+23
@@ -87,6 +87,29 @@ export const api = {
87 exportStatementsUrl: (yearId: number, format: 'xlsx' | 'json') =>
88 `${BASE}/years/${yearId}/statements/export?format=${format}`,
89
90 + listNotes: (yearId: number) =>
91 + request<{ notes: { note_id: number; note_number: string; title: string; statement: string; section: string }[] }>(
92 + `/years/${yearId}/notes`,
93 + ),
94 +
95 + listMappings: (yearId: number) =>
96 + request<{ mappings: { mapping_id: number; account_code: string; target_note_id: number; mapping_type: string }[] }>(
97 + `/years/${yearId}/mappings`,
98 + ),
99 +
100 + updateNote: (yearId: number, noteId: number, patch: { title?: string; note_number?: string; statement?: string; section?: string }) =>
101 + request<{ note_id: number; note_number: string; title: string }>(`/years/${yearId}/notes/${noteId}`, {
102 + method: 'PUT',
103 + headers: { 'Content-Type': 'application/json' },
104 + body: JSON.stringify(patch),
105 + }),
106 +
107 + deleteNote: (yearId: number, noteId: number) =>
108 + request<{ deleted: number }>(`/years/${yearId}/notes/${noteId}`, { method: 'DELETE' }),
109 +
110 + deleteMapping: (yearId: number, mappingId: number) =>
111 + request<{ deleted: number }>(`/years/${yearId}/mappings/${mappingId}`, { method: 'DELETE' }),
112 +
113 login: (username: string, password: string) =>
114 request<{ username: string; display_name: string; role: string }>('/auth/login', json({ username, password })),
115
frontend/src/components/NotesManager.tsx new
+157
@@ -0,0 +1,157 @@
1 +import { useCallback, useEffect, useState } from 'react'
2 +import { api, ApiError } from '../api/client'
3 +import { faNumber } from '../lib/format'
4 +
5 +interface Props {
6 + yearId: number
7 + refreshKey: number
8 +}
9 +
10 +interface NoteRow {
11 + note_id: number
12 + note_number: string
13 + title: string
14 + statement: string
15 + section: string
16 +}
17 +
18 +interface MappingRow {
19 + mapping_id: number
20 + account_code: string
21 + target_note_id: number
22 + mapping_type: string
23 +}
24 +
25 +export default function NotesManager({ yearId, refreshKey }: Props) {
26 + const [notes, setNotes] = useState<NoteRow[]>([])
27 + const [mappings, setMappings] = useState<MappingRow[]>([])
28 + const [edits, setEdits] = useState<Record<number, string>>({})
29 + const [error, setError] = useState<string | null>(null)
30 + const [message, setMessage] = useState<string | null>(null)
31 +
32 + const load = useCallback(async () => {
33 + try {
34 + const [n, m] = await Promise.all([api.listNotes(yearId), api.listMappings(yearId)])
35 + setNotes(n.notes)
36 + setMappings(m.mappings)
37 + } catch (err) {
38 + setError(err instanceof ApiError ? err.message : String(err))
39 + }
40 + }, [yearId])
41 +
42 + useEffect(() => {
43 + void load()
44 + }, [load, refreshKey])
45 +
46 + async function act(fn: () => Promise<unknown>, ok: string) {
47 + setError(null)
48 + setMessage(null)
49 + try {
50 + await fn()
51 + setMessage(ok)
52 + await load()
53 + } catch (err) {
54 + setError(err instanceof ApiError ? err.message : String(err))
55 + }
56 + }
57 +
58 + const noteNumber = (id: number) => notes.find((n) => n.note_id === id)?.note_number ?? String(id)
59 +
60 + return (
61 + <section className="card">
62 + <h2>مدیریت یادداشت‌ها و نگاشت‌ها</h2>
63 + {message && <p className="ok">{message}</p>}
64 + {error && <p className="error">{error}</p>}
65 +
66 + <h3>یادداشت‌ها ({faNumber(notes.length)})</h3>
67 + <table>
68 + <thead>
69 + <tr>
70 + <th>شماره</th>
71 + <th>عنوان</th>
72 + <th>صورت/بخش</th>
73 + <th>عملیات</th>
74 + </tr>
75 + </thead>
76 + <tbody>
77 + {notes.map((n) => (
78 + <tr key={n.note_id}>
79 + <td className="mono">{n.note_number}</td>
80 + <td>
81 + <input
82 + value={edits[n.note_id] ?? n.title}
83 + onChange={(e) => setEdits((s) => ({ ...s, [n.note_id]: e.target.value }))}
84 + />
85 + </td>
86 + <td className="muted">
87 + {n.statement}/{n.section}
88 + </td>
89 + <td>
90 + <button
91 + type="button"
92 + onClick={() =>
93 + act(
94 + () => api.updateNote(yearId, n.note_id, { title: edits[n.note_id] ?? n.title }),
95 + 'عنوان یادداشت به‌روز شد.',
96 + )
97 + }
98 + >
99 + ذخیره
100 + </button>{' '}
101 + <button
102 + type="button"
103 + onClick={() => act(() => api.deleteNote(yearId, n.note_id), 'یادداشت حذف شد.')}
104 + >
105 + حذف
106 + </button>
107 + </td>
108 + </tr>
109 + ))}
110 + {notes.length === 0 && (
111 + <tr>
112 + <td colSpan={4} className="muted">
113 + یادداشتی وجود ندارد.
114 + </td>
115 + </tr>
116 + )}
117 + </tbody>
118 + </table>
119 +
120 + <h3>نگاشت‌ها ({faNumber(mappings.length)})</h3>
121 + <table>
122 + <thead>
123 + <tr>
124 + <th>کد حساب</th>
125 + <th>یادداشت مقصد</th>
126 + <th>نوع</th>
127 + <th>عملیات</th>
128 + </tr>
129 + </thead>
130 + <tbody>
131 + {mappings.map((m) => (
132 + <tr key={m.mapping_id}>
133 + <td className="mono">{m.account_code}</td>
134 + <td>{noteNumber(m.target_note_id)}</td>
135 + <td className="muted">{m.mapping_type}</td>
136 + <td>
137 + <button
138 + type="button"
139 + onClick={() => act(() => api.deleteMapping(yearId, m.mapping_id), 'نگاشت حذف شد.')}
140 + >
141 + حذف
142 + </button>
143 + </td>
144 + </tr>
145 + ))}
146 + {mappings.length === 0 && (
147 + <tr>
148 + <td colSpan={4} className="muted">
149 + نگاشتی وجود ندارد.
150 + </td>
151 + </tr>
152 + )}
153 + </tbody>
154 + </table>
155 + </section>
156 + )
157 +}