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:
Atharv1705
2026-08-05 11:41:06 +05:30
parent c2e22902c8
commit 9c7f25e06f
36 changed files with 3357 additions and 5279 deletions
+37 -38
View File
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '../context/AuthContext';
import { useToast } from '../context/ToastContext';
@@ -13,12 +13,9 @@ export default function UserDashboard() {
const [loadingDocs, setLoadingDocs] = useState(false);
const [docLoading, setDocLoading] = useState(false);
useEffect(() => {
checkEngagement();
loadAdminDocs();
}, []);
// ── declare callbacks BEFORE the effects that reference them ──
const checkEngagement = async () => {
const checkEngagement = useCallback(async () => {
try {
const res = await authFetch("/api/auth/me");
if (res.ok) {
@@ -31,16 +28,33 @@ export default function UserDashboard() {
} catch (err) {
console.error(err);
}
};
}, [authFetch]);
const loadAdminDocs = useCallback(async () => {
setLoadingDocs(true);
try {
const res = await authFetch("/api/upload/admin-documents");
if (res.ok) {
setAdminDocs(await res.json());
}
} catch (err) {
console.error(err);
} finally {
setLoadingDocs(false);
}
}, [authFetch]);
useEffect(() => {
checkEngagement();
loadAdminDocs();
}, [checkEngagement, loadAdminDocs]);
const handleEngagementChange = async (e) => {
const isChecked = e.target.checked;
if (!isChecked) {
// Don't allow unchecking
setEngagementChecked(true);
return;
}
try {
setEngagementChecked(true);
const res = await authFetch("/api/auth/acknowledge-engagement", { method: "POST" });
@@ -55,20 +69,6 @@ export default function UserDashboard() {
}
};
const loadAdminDocs = async () => {
setLoadingDocs(true);
try {
const res = await authFetch("/api/upload/admin-documents");
if (res.ok) {
setAdminDocs(await res.json());
}
} catch (err) {
console.error(err);
} finally {
setLoadingDocs(false);
}
};
const viewDoc = async (storageKey) => {
try {
const res = await authFetch(`/api/upload/view-url?key=${encodeURIComponent(storageKey)}`);
@@ -85,13 +85,11 @@ export default function UserDashboard() {
const respondDoc = async (docId, approved) => {
if (docLoading) return;
let reason = "";
if (!approved) {
reason = window.prompt("Reason for rejection:");
if (reason === null) return;
}
setDocLoading(true);
try {
const res = await authFetch("/api/review/admin-doc-response", {
@@ -123,22 +121,23 @@ export default function UserDashboard() {
<div className="card fade-up">
<h3 style={{marginBottom: '16px'}}>Engagement Letter</h3>
<p className="text-sm" style={{marginBottom: '16px'}}>Please acknowledge the engagement letter before uploading documents.</p>
<div style={{
<label style={{
display: 'flex', alignItems: 'center', gap: '12px', padding: '16px',
background: 'var(--bg)', borderRadius: 'var(--radius-sm)', border: '1px solid var(--border)'
background: 'var(--bg)', borderRadius: 'var(--radius-sm)', border: '1px solid var(--border)',
cursor: engagementDisabled ? 'not-allowed' : 'pointer'
}}>
<input
type="checkbox"
<input
type="checkbox"
checked={engagementChecked}
disabled={engagementDisabled}
onChange={handleEngagementChange}
style={{width:'20px', height:'20px', cursor: engagementDisabled ? 'not-allowed' : 'pointer'}}
style={{width:'20px', height:'20px', cursor: engagementDisabled ? 'not-allowed' : 'pointer'}}
/>
<div>
<div style={{fontWeight: 600, color: 'var(--navy)'}}>I acknowledge the Engagement Letter</div>
<div style={{fontSize: '13px', color: 'var(--muted)', marginTop: '2px'}}>By checking this, you agree to our terms of service for the current tax year.</div>
</div>
</div>
</label>
</div>
<div style={{display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))', gap: '20px', marginTop: '20px'}}>
@@ -148,23 +147,23 @@ export default function UserDashboard() {
<h3 style={{margin:0}}>Personal Documents</h3>
</div>
<p className="text-sm text-muted" style={{marginBottom: '20px', minHeight: '40px'}}>Upload your W-2s, 1099s, IDs, and other individual tax forms.</p>
<button
className="btn btn-primary w-full"
<button
className="btn btn-primary w-full"
disabled={!engagementChecked}
onClick={() => navigate('/upload-personal')}
>
Go to Personal Upload
</button>
</div>
<div className="card fade-up" style={{animationDelay: '0.2s'}}>
<div style={{display:'flex', alignItems:'center', gap:'12px', marginBottom: '12px'}}>
<span className="material-symbols-outlined" style={{color:'var(--orange)', fontSize:'28px'}}>business</span>
<h3 style={{margin:0}}>Business Documents</h3>
</div>
<p className="text-sm text-muted" style={{marginBottom: '20px', minHeight: '40px'}}>Upload corporate documents, bookkeeping ledgers, and business receipts.</p>
<button
className="btn btn-primary w-full"
<button
className="btn btn-primary w-full"
disabled={!engagementChecked}
onClick={() => navigate('/upload-business')}
>
@@ -176,7 +175,7 @@ export default function UserDashboard() {
<div className="card fade-up" style={{animationDelay: '0.3s', marginTop: '20px'}}>
<h3 style={{marginBottom: '16px'}}>Admin Returns / Documents</h3>
<p className="text-sm" style={{marginBottom: '16px'}}>Documents and tax returns finalized by the admin.</p>
{loadingDocs ? (
<div className="empty-state">Loading documents...</div>
) : adminDocs.length === 0 ? (
@@ -215,4 +214,4 @@ export default function UserDashboard() {
</div>
</div>
);
}
}