-
Notifications
You must be signed in to change notification settings - Fork 0
feat: classification review UI with bulk-accept guardrails #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,159 @@ | ||||||||||||||||
| import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; | ||||||||||||||||
| import { apiRequest } from '@/lib/queryClient'; | ||||||||||||||||
| import { useTenantId } from '@/contexts/TenantContext'; | ||||||||||||||||
|
|
||||||||||||||||
| // Matches database/system.schema.ts chartOfAccounts | ||||||||||||||||
| export interface ChartOfAccount { | ||||||||||||||||
| id: string; | ||||||||||||||||
| tenantId: string | null; // null = global default | ||||||||||||||||
| code: string; | ||||||||||||||||
| name: string; | ||||||||||||||||
| type: 'asset' | 'liability' | 'equity' | 'income' | 'expense'; | ||||||||||||||||
| subtype: string | null; | ||||||||||||||||
| description: string | null; | ||||||||||||||||
| scheduleELine: string | null; | ||||||||||||||||
| taxDeductible: boolean; | ||||||||||||||||
| parentCode: string | null; | ||||||||||||||||
| isActive: boolean; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Matches database/system.schema.ts transactions (classification columns) | ||||||||||||||||
| export interface UnclassifiedTransaction { | ||||||||||||||||
| id: string; | ||||||||||||||||
| tenantId: string; | ||||||||||||||||
| accountId: string; | ||||||||||||||||
| amount: string; | ||||||||||||||||
| type: string; | ||||||||||||||||
| category: string | null; | ||||||||||||||||
| description: string; | ||||||||||||||||
| date: string; | ||||||||||||||||
| payee: string | null; | ||||||||||||||||
| coaCode: string | null; | ||||||||||||||||
| suggestedCoaCode: string | null; | ||||||||||||||||
| classificationConfidence: string | null; | ||||||||||||||||
| classifiedBy: string | null; | ||||||||||||||||
| classifiedAt: string | null; | ||||||||||||||||
| reconciled: boolean; | ||||||||||||||||
| reconciledBy: string | null; | ||||||||||||||||
| reconciledAt: string | null; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| export interface ClassificationStats { | ||||||||||||||||
| total: number | string; | ||||||||||||||||
| classified: number | string; | ||||||||||||||||
| reconciled: number | string; | ||||||||||||||||
| suggested: number | string; | ||||||||||||||||
| unclassified: number; | ||||||||||||||||
| classifiedPct: number; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| export interface ClassificationAuditEntry { | ||||||||||||||||
| id: string; | ||||||||||||||||
| transactionId: string; | ||||||||||||||||
| tenantId: string; | ||||||||||||||||
| previousCoaCode: string | null; | ||||||||||||||||
| newCoaCode: string; | ||||||||||||||||
| action: string; // 'suggest' | 're-suggest' | 'classify' | 'reclassify' | 'reconcile' | ||||||||||||||||
| trustLevel: string; | ||||||||||||||||
| actorId: string; | ||||||||||||||||
| actorType: 'user' | 'agent' | 'system'; | ||||||||||||||||
| confidence: string | null; | ||||||||||||||||
| reason: string | null; | ||||||||||||||||
| createdAt: string; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // ── Queries ── | ||||||||||||||||
|
|
||||||||||||||||
| export function useChartOfAccounts() { | ||||||||||||||||
| const tenantId = useTenantId(); | ||||||||||||||||
| return useQuery<ChartOfAccount[]>({ | ||||||||||||||||
| queryKey: ['/api/coa', tenantId], | ||||||||||||||||
| enabled: !!tenantId, | ||||||||||||||||
| }); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| export function useClassificationStats() { | ||||||||||||||||
| const tenantId = useTenantId(); | ||||||||||||||||
| return useQuery<ClassificationStats>({ | ||||||||||||||||
| queryKey: ['/api/classification/stats', tenantId], | ||||||||||||||||
| enabled: !!tenantId, | ||||||||||||||||
| }); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| export function useUnclassifiedTransactions(limit = 50) { | ||||||||||||||||
| const tenantId = useTenantId(); | ||||||||||||||||
| return useQuery<UnclassifiedTransaction[]>({ | ||||||||||||||||
| queryKey: ['/api/classification/unclassified', tenantId, limit], | ||||||||||||||||
| enabled: !!tenantId, | ||||||||||||||||
| }); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| export function useClassificationAudit(transactionId: string | null) { | ||||||||||||||||
| return useQuery<ClassificationAuditEntry[]>({ | ||||||||||||||||
| queryKey: ['/api/classification/audit', transactionId], | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||||||||||||||||
| enabled: !!transactionId, | ||||||||||||||||
|
Comment on lines
+92
to
+94
|
||||||||||||||||
| return useQuery<ClassificationAuditEntry[]>({ | |
| queryKey: ['/api/classification/audit', transactionId], | |
| enabled: !!transactionId, | |
| const tenantId = useTenantId(); | |
| return useQuery<ClassificationAuditEntry[]>({ | |
| queryKey: ['/api/classification/audit', tenantId, transactionId], | |
| enabled: !!tenantId && !!transactionId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limitin unclassified fetch URLuseUnclassifiedTransactions(limit)never sendslimitto the backend because the default query function only requestsqueryKey[0]as the URL. Herelimitis only placed in the query key tuple, so calls likeuseUnclassifiedTransactions(100)still hit/api/classification/unclassifiedwithout?limit=100and silently fall back to the server default page size.Useful? React with 👍 / 👎.