Production ready: mobile responsive UI, ChromaDB persistence, Excel export, and Filing Deadlines

This commit is contained in:
Atharv1705
2026-09-05 17:42:08 +05:30
parent e0f6167d14
commit 46a340dc74
18 changed files with 899 additions and 40 deletions
@@ -1,3 +1,4 @@
import * as XLSX from 'xlsx';
import { useState } from 'react';
import ExpandableValue from './ExpandableValue';
@@ -62,39 +63,34 @@ export default function ExpandableSummaryBlock({ extractedData, onSave }) {
};
const handleExport = () => {
// Convert extracted data into a 2-column CSV (Field, Value)
// Export extracted AI data as a proper .xlsx file using SheetJS
const { _meta, ...dataFields } = extractedData || {};
const escapeCsv = (str) => {
const s = String(str);
if (s.includes(',') || s.includes('"') || s.includes('\n')) {
return `"${s.replace(/"/g, '""')}"`;
}
return s;
};
const csvRows = ['Field,Value'];
const rows = [['Field', 'Value']];
Object.entries(dataFields).forEach(([key, val]) => {
let valStr = val;
if (Array.isArray(val)) {
valStr = val.join('; ');
} else if (typeof val === 'object' && val !== null) {
valStr = JSON.stringify(val);
}
csvRows.push(`${escapeCsv(key)},${escapeCsv(valStr)}`);
if (Array.isArray(val)) valStr = val.join('; ');
else if (typeof val === 'object' && val !== null) valStr = JSON.stringify(val);
rows.push([String(key), String(valStr ?? '')]);
});
const csvContent = csvRows.join('\n');
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `extracted_data.csv`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
const ws = XLSX.utils.aoa_to_sheet(rows);
// Bold + green header
['A1', 'B1'].forEach(ref => {
if (ws[ref]) ws[ref].s = { font: { bold: true, color: { rgb: 'FFFFFF' } }, fill: { fgColor: { rgb: '2C7A5B' } } };
});
// Column widths
ws['!cols'] = [
{ wch: Math.max(10, ...Object.keys(dataFields).map(k => k.length + 2)) },
{ wch: 45 },
];
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Extracted Data');
XLSX.writeFile(wb, 'extracted_data.xlsx');
}
const showToggle = entries.length > 3;
const entriesToShow = expanded ? entries : entries.slice(0, 3);
@@ -160,8 +156,8 @@ export default function ExpandableSummaryBlock({ extractedData, onSave }) {
) : <div />}
<div style={{ display: 'flex', gap: '6px' }}>
<button onClick={handleExport} style={{ border: 'none', background: 'transparent', cursor: 'pointer', fontSize: '11px', color: 'var(--muted)', display: 'flex', alignItems: 'center', gap: '4px', padding: '2px' }} title="Export CSV">
<span className="material-symbols-outlined" style={{ fontSize: '14px' }}>download</span> Export CSV
<button onClick={handleExport} style={{ border: 'none', background: 'transparent', cursor: 'pointer', fontSize: '11px', color: 'var(--muted)', display: 'flex', alignItems: 'center', gap: '4px', padding: '2px' }} title="Export Excel">
<span className="material-symbols-outlined" style={{ fontSize: '14px' }}>download</span> Export Excel
</button>
<button onClick={handleEditClick} style={{ border: 'none', background: 'transparent', cursor: 'pointer', fontSize: '11px', color: 'var(--emerald)', display: 'flex', alignItems: 'center', gap: '4px', padding: '2px', fontWeight: 600 }} title="Edit Summary">
<span className="material-symbols-outlined" style={{ fontSize: '14px' }}>edit</span> Edit
+70
View File
@@ -23,9 +23,35 @@ export default function AdminUserDetail() {
const [personalTimeline, setPersonalTimeline] = useState(0);
const [businessTimeline, setBusinessTimeline] = useState(0);
// Export Excel Function
const exportToExcel = async () => {
try {
showToast("Preparing Excel export...", "info");
const res = await authFetch(`/api/upload/admin/users/${userId}/export`);
if (res.ok) {
const blob = await res.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `user_${userId}_documents.xlsx`;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
showToast("Excel export ready!", "success");
} else {
showToast("Failed to export Excel file", "error");
}
} catch (err) {
console.error(err);
showToast("Error exporting Excel file", "error");
}
};
// States for Audit Log
const [auditLog, setAuditLog] = useState([]);
const [auditLoaded, setAuditLoaded] = useState(false);
const [deadlines, setDeadlines] = useState([]);
const adminDocInputRef = useRef(null);
@@ -55,6 +81,12 @@ export default function AdminUserDetail() {
const allDocs = [...userDocs, ...adminDocs];
setDocuments(allDocs);
// Fetch filing deadlines
try {
const dlRes = await authFetch(`/api/review/deadlines/${userId}`);
if (dlRes.ok) setDeadlines(await dlRes.json());
} catch {}
} catch (err) {
console.error(err);
@@ -432,6 +464,25 @@ export default function AdminUserDetail() {
<div className="doc-review-sidebar">
<div className="card-flat" style={{display:'flex', flexDirection:'column', gap:'16px'}}>
<h3>Filing Timeline</h3>
{deadlines.filter(d => d.doc_type === 'personal').map(d => (
<div key="personal-dl" style={{
margin: '0 0 16px', padding: '12px 16px',
borderRadius: 'var(--radius-sm)',
background: d.is_overdue ? 'rgba(220,53,69,0.08)' : d.days_left <= 1 ? 'rgba(255,140,0,0.10)' : 'rgba(44,122,91,0.08)',
border: `1px solid ${d.is_overdue ? 'rgba(220,53,69,0.3)' : d.days_left <= 1 ? 'rgba(255,140,0,0.35)' : 'rgba(44,122,91,0.20)'}`,
display: 'flex', alignItems: 'center', gap: '10px'
}}>
<span className="material-symbols-outlined" style={{fontSize:'20px', color: d.is_overdue ? '#dc3545' : d.days_left <= 1 ? '#ff8c00' : 'var(--accent)'}}>
{d.is_overdue ? 'warning' : 'schedule'}
</span>
<div>
<div style={{fontWeight: 600, fontSize: '13px', color: d.is_overdue ? '#dc3545' : d.days_left <= 1 ? '#ff8c00' : 'var(--navy)'}}>
{d.is_overdue ? `OVERDUE by ${Math.abs(d.days_left)} day${Math.abs(d.days_left) !== 1 ? 's' : ''}` : `${d.days_left} day${d.days_left !== 1 ? 's' : ''} remaining`}
</div>
<div style={{fontSize: '11px', color: 'var(--muted)'}}>Deadline: {new Date(d.deadline_date).toLocaleDateString('en-US', {year:'numeric',month:'long',day:'numeric'})}</div>
</div>
</div>
))}
<div className="timeline-control">
<button className="tl-btn" onClick={() => setPersonalTimeline(Math.max(0, personalTimeline - 1))}>−</button>
<div>
@@ -510,6 +561,25 @@ export default function AdminUserDetail() {
<div className="doc-review-sidebar">
<div className="card-flat" style={{display:'flex', flexDirection:'column', gap:'16px'}}>
<h3>Filing Timeline</h3>
{deadlines.filter(d => d.doc_type === 'business').map(d => (
<div key="business-dl" style={{
margin: '0 0 16px', padding: '12px 16px',
borderRadius: 'var(--radius-sm)',
background: d.is_overdue ? 'rgba(220,53,69,0.08)' : d.days_left <= 1 ? 'rgba(255,140,0,0.10)' : 'rgba(44,122,91,0.08)',
border: `1px solid ${d.is_overdue ? 'rgba(220,53,69,0.3)' : d.days_left <= 1 ? 'rgba(255,140,0,0.35)' : 'rgba(44,122,91,0.20)'}`,
display: 'flex', alignItems: 'center', gap: '10px'
}}>
<span className="material-symbols-outlined" style={{fontSize:'20px', color: d.is_overdue ? '#dc3545' : d.days_left <= 1 ? '#ff8c00' : 'var(--accent)'}}>
{d.is_overdue ? 'warning' : 'schedule'}
</span>
<div>
<div style={{fontWeight: 600, fontSize: '13px', color: d.is_overdue ? '#dc3545' : d.days_left <= 1 ? '#ff8c00' : 'var(--navy)'}}>
{d.is_overdue ? `OVERDUE by ${Math.abs(d.days_left)} day${Math.abs(d.days_left) !== 1 ? 's' : ''}` : `${d.days_left} day${d.days_left !== 1 ? 's' : ''} remaining`}
</div>
<div style={{fontSize: '11px', color: 'var(--muted)'}}>Deadline: {new Date(d.deadline_date).toLocaleDateString('en-US', {year:'numeric',month:'long',day:'numeric'})}</div>
</div>
</div>
))}
<div className="timeline-control">
<button className="tl-btn" onClick={() => setBusinessTimeline(Math.max(0, businessTimeline - 1))}>−</button>
<div>
+23
View File
@@ -14,9 +14,32 @@ export default function UserDashboard() {
const [docLoading, setDocLoading] = useState(false);
// Track which doc rows have the AI summary panel open
const [expandedSummary, setExpandedSummary] = useState({});
const [searchQuery, setSearchQuery] = useState("");
const [searchResults, setSearchResults] = useState([]);
const [isSearching, setIsSearching] = useState(false);
// ── declare callbacks BEFORE the effects that reference them ──
const handleSearch = async (e) => {
e.preventDefault();
if (!searchQuery.trim()) return;
setIsSearching(true);
try {
const res = await authFetch(`/api/search/semantic?q=${encodeURIComponent(searchQuery)}`);
if (res.ok) {
setSearchResults(await res.json());
} else {
showToast("Search failed", "error");
}
} catch (err) {
console.error(err);
showToast("Search failed", "error");
} finally {
setIsSearching(false);
}
};
const checkEngagement = useCallback(async () => {
try {
const res = await authFetch("/api/auth/me");