feat: major platform upgrade — AI extraction pipeline, responsive UI, admin chatbot enhancements
CRITICAL FIXES - Fix blank pages: useCallback declared after useEffect in all 5 pages - Fix showToast undefined everywhere (ToastContext exported addToast not showToast) - Fix admin doc upload always 422 (missing doc_key + doc_label form fields) - Fix audit log wrong field names (log.details -> log.detail, remove user_agent) - Fix SPA catch-all missing in main.py (direct URL access was 404) - Fix chatbot using broken nvidia free model -> llama-3.3-70b AI EXTRACTION PIPELINE - 3-stage pipeline: Stage1 native text (free) -> Stage2 Tesseract OCR (free CPU) -> Stage3 Qwen vision (paid) - Tesseract installed with eng+hin bilingual support, psm6, 2.5x DPI - Scanned PDF fallback via PyMuPDF page render - Blank template fallback: returns form_type/purpose/tax_year instead of empty - Improved prompt: extracts actual document field names, no predefined terms - Auto-poll UI: shows Processing spinner when extraction is running - backfill_extraction.py: re-process all docs, fixed empty-dict-as-None bug ADMIN DASHBOARD - Pending docs split into Pending Personal + Pending Business stat cards - User cards show typed badges: N personal / N business instead of generic N pending - Backend returns pending_personal, pending_business, pending_docs per user ADMIN USER DETAIL - Doc count chips in user info bar: personal / business / returns / total - Doc name bold 15px, date with calendar icon + TY chip, status as colored badges - Responsive layout: doc-review-layout CSS classes replace inline flex styles - Filing Timeline sidebar stacks above doc list on mobile - AI Summary: bold labels and values, blank template shows metadata CHATBOT ENHANCEMENTS - Ask anything free-text input on menu screen (both admin and user chatbots) - Admin: live context with latest uploads by date, new users today - Admin: per-user activity lookup by name/email (docs + audit log) - New endpoint: /api/chatbot/admin-user-context - ExpandableSummaryBlock + ExpandableValue: bold navy field labels and values RESPONSIVENESS - components.css: 480px/640px/768px breakpoints for all pages - Admin table, stat cards, tabs, toasts, FAB all properly responsive - Auth shell stacks on mobile correctly
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState, useRef } from 'react';
|
||||
import { useEffect, useState, useRef, useCallback } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
@@ -13,11 +13,7 @@ export default function UploadBusiness() {
|
||||
const fileInputRefs = useRef({});
|
||||
const extraFileRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetchTemplatesAndDocs();
|
||||
}, [taxYear]);
|
||||
|
||||
const fetchTemplatesAndDocs = async () => {
|
||||
const fetchTemplatesAndDocs = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const tplRes = await authFetch(`/api/upload/templates?category=business&tax_year=${taxYear}`);
|
||||
@@ -34,9 +30,13 @@ export default function UploadBusiness() {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
}, [authFetch, taxYear]);
|
||||
|
||||
const uploadFile = async (file, docType) => {
|
||||
useEffect(() => {
|
||||
fetchTemplatesAndDocs();
|
||||
}, [taxYear, fetchTemplatesAndDocs]);
|
||||
|
||||
const uploadFile = async (file, docType, skipFetch = false) => {
|
||||
if (file.size > 10 * 1024 * 1024) {
|
||||
showToast("File size exceeds 10MB limit", "error");
|
||||
return;
|
||||
@@ -52,7 +52,7 @@ export default function UploadBusiness() {
|
||||
});
|
||||
if (res.ok) {
|
||||
showToast("Document uploaded successfully", "success");
|
||||
fetchTemplatesAndDocs();
|
||||
if (!skipFetch) fetchTemplatesAndDocs();
|
||||
} else {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
showToast(data.detail || "Upload failed", "error");
|
||||
@@ -93,12 +93,20 @@ export default function UploadBusiness() {
|
||||
|
||||
const handleExtraUpload = async (e) => {
|
||||
const files = Array.from(e.target.files);
|
||||
const validFiles = [];
|
||||
for (let file of files) {
|
||||
if (file.size > 10 * 1024 * 1024) {
|
||||
showToast(`File ${file.name} exceeds 10MB limit`, "error");
|
||||
continue;
|
||||
}
|
||||
await uploadFile(file, "other");
|
||||
validFiles.push(file);
|
||||
}
|
||||
|
||||
if (validFiles.length > 0) {
|
||||
await Promise.all(validFiles.map((file, idx) =>
|
||||
uploadFile(file, `other_${Date.now()}_${idx}`, true)
|
||||
));
|
||||
fetchTemplatesAndDocs();
|
||||
}
|
||||
e.target.value = "";
|
||||
};
|
||||
@@ -172,7 +180,12 @@ export default function UploadBusiness() {
|
||||
hidden
|
||||
accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx,.xls,.xlsx"
|
||||
ref={el => fileInputRefs.current[dt.name] = el}
|
||||
onChange={(e) => e.target.files[0] && uploadFile(e.target.files[0], dt.name)}
|
||||
onChange={(e) => {
|
||||
if (e.target.files[0]) {
|
||||
uploadFile(e.target.files[0], dt.name);
|
||||
e.target.value = null;
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<div style={{display: 'flex', gap: '8px', alignItems: 'center'}}>
|
||||
{dt.download && (
|
||||
@@ -185,9 +198,11 @@ export default function UploadBusiness() {
|
||||
)}
|
||||
</div>
|
||||
{uploaded.map(doc => (
|
||||
<div key={doc.id} style={{display:'flex', gap:'8px'}}>
|
||||
<button className="btn btn-secondary btn-xs" style={{borderRadius:'var(--radius-sm)'}} onClick={() => viewDoc(doc.storage_key)}>View</button>
|
||||
<button className="btn btn-danger btn-xs" style={{borderRadius:'var(--radius-sm)'}} onClick={() => deleteDoc(doc.id)}>Delete</button>
|
||||
<div key={doc.id} style={{display:'flex', flexDirection:'column', gap:'8px', alignItems:'flex-end'}}>
|
||||
<div style={{display:'flex', gap:'8px'}}>
|
||||
<button className="btn btn-secondary btn-xs" style={{borderRadius:'var(--radius-sm)'}} onClick={() => viewDoc(doc.storage_key)}>View</button>
|
||||
<button className="btn btn-danger btn-xs" style={{borderRadius:'var(--radius-sm)'}} onClick={() => deleteDoc(doc.id)}>Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -203,30 +218,53 @@ export default function UploadBusiness() {
|
||||
<h3>Additional Documents</h3>
|
||||
<p className="text-sm" style={{marginTop:'2px'}}>Upload any supplementary business documents</p>
|
||||
</div>
|
||||
<label className="btn btn-secondary btn-sm" style={{borderRadius:'var(--radius-sm)', cursor:'pointer'}}>
|
||||
<label
|
||||
className="btn btn-secondary btn-sm"
|
||||
style={{borderRadius:'var(--radius-sm)', cursor:'pointer'}}
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
extraFileRef.current?.click();
|
||||
}
|
||||
}}
|
||||
>
|
||||
+ Choose Files
|
||||
<input type="file" multiple hidden accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx,.xls,.xlsx" onChange={handleExtraUpload} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="drop-area" style={{ border:'2px dashed #b8cfdf', borderRadius:'var(--radius-md)', padding:'28px 20px', textAlign:'center', cursor:'pointer', background:'var(--card)' }} onClick={() => extraFileRef.current?.click()}>
|
||||
<div className="da-icon"><span className="material-symbols-outlined" style={{color: '#ffca28', fontSize: '32px'}}>folder</span></div>
|
||||
<div
|
||||
className="drop-area"
|
||||
style={{ border:'2px dashed #cfc7ad', borderRadius:'var(--radius-md)', padding:'28px 20px', textAlign:'center', cursor:'pointer', background:'var(--card)' }}
|
||||
onClick={() => extraFileRef.current?.click()}
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
extraFileRef.current?.click();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="da-icon"><span className="material-symbols-outlined" style={{color: 'var(--brass)', fontSize: '32px'}}>folder</span></div>
|
||||
<div className="da-title" style={{fontWeight: 600, color: 'var(--navy)', fontSize: '14px'}}>Drag & drop files here</div>
|
||||
<div className="da-hint" style={{fontSize: '12px', color: 'var(--muted)'}}>or click to browse · PDF, JPG, PNG, WEBP, DOC, EXCEL · Max 10MB</div>
|
||||
</div>
|
||||
<input type="file" multiple hidden ref={extraFileRef} onChange={handleExtraUpload} />
|
||||
|
||||
<div className="upload-track mt-12">
|
||||
{docs.filter(d => d.doc_type === "other").map(doc => (
|
||||
<div key={doc.id} className="upload-track-item" style={{display:'flex', alignItems:'center', gap:'10px', padding:'8px 12px', borderRadius:'var(--radius-sm)', background:'#f5f8fb', fontSize:'13px', marginBottom:'6px'}}>
|
||||
<span className="material-symbols-outlined" style={{color:'var(--green)', fontSize:'18px'}}>check_circle</span>
|
||||
<div className="uti-name" style={{flex:1}}>{doc.filename}</div>
|
||||
<button className="btn btn-secondary btn-sm" style={{padding:'4px'}} onClick={() => viewDoc(doc.storage_key)}>
|
||||
<span className="material-symbols-outlined" style={{fontSize:'16px'}}>visibility</span>
|
||||
</button>
|
||||
<button className="btn btn-danger btn-sm" style={{padding:'4px'}} onClick={() => deleteDoc(doc.id)}>
|
||||
<span className="material-symbols-outlined" style={{fontSize:'16px'}}>delete</span>
|
||||
</button>
|
||||
{docs.filter(d => d.doc_type.startsWith("other")).map(doc => (
|
||||
<div key={doc.id} style={{marginBottom:'6px'}}>
|
||||
<div className="upload-track-item" style={{display:'flex', alignItems:'center', gap:'10px', padding:'8px 12px', borderRadius:'var(--radius-sm)', background:'var(--paper)', fontSize:'13px'}}>
|
||||
<span className="material-symbols-outlined" style={{color:'var(--green)', fontSize:'18px'}}>check_circle</span>
|
||||
<div className="uti-name" style={{flex:1}}>{doc.filename}</div>
|
||||
<button className="btn btn-secondary btn-sm" style={{padding:'4px'}} onClick={() => viewDoc(doc.storage_key)}>
|
||||
<span className="material-symbols-outlined" style={{fontSize:'16px'}}>visibility</span>
|
||||
</button>
|
||||
<button className="btn btn-danger btn-sm" style={{padding:'4px'}} onClick={() => deleteDoc(doc.id)}>
|
||||
<span className="material-symbols-outlined" style={{fontSize:'16px'}}>delete</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user