Implement workflow improvements: admin document review, user email notifications, and engagement letter download

This commit is contained in:
Atharv1705
2026-09-30 16:37:33 +05:30
parent cb4d939c0b
commit 268c3d402b
22 changed files with 1193 additions and 330 deletions
+17
View File
@@ -9,6 +9,7 @@
"version": "0.0.0",
"dependencies": {
"axios": "^1.18.1",
"dompurify": "^3.4.16",
"lucide-react": "^1.24.0",
"react": "^19.2.7",
"react-dom": "^19.2.7",
@@ -1978,6 +1979,13 @@
"@types/react": "^19.2.0"
}
},
"node_modules/@types/trusted-types": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz",
"integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==",
"license": "MIT",
"optional": true
},
"node_modules/@vitejs/plugin-react": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-6.0.3.tgz",
@@ -2263,6 +2271,15 @@
"node": ">=8"
}
},
"node_modules/dompurify": {
"version": "3.4.16",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.16.tgz",
"integrity": "sha512-sqo+pNp3qRhCIpbgRi1y8Tgk27Bo2Ry7w0dC1NBeNTdZChWjz9Xb/KOoZbRP/R6pQZ80Qw8YhXw13hWWBbMRnQ==",
"license": "(MPL-2.0 OR Apache-2.0)",
"optionalDependencies": {
"@types/trusted-types": "^2.0.7"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
+1
View File
@@ -11,6 +11,7 @@
},
"dependencies": {
"axios": "^1.18.1",
"dompurify": "^3.4.16",
"lucide-react": "^1.24.0",
"react": "^19.2.7",
"react-dom": "^19.2.7",
+1 -1
View File
@@ -690,7 +690,7 @@
.aud-bar-actions {
display: flex;
gap: 10px;
align-items: center;
align-items: flex-end;
flex-wrap: wrap;
}
.aud-year-picker {
+18 -2
View File
@@ -21,12 +21,28 @@ const FAQ_DATA = {
const CATEGORY_ICONS = { "Document Review": "📑", "User Management": "👥", "Notifications": "🔔" };
const escapeHtml = (unsafe) => {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
};
const formatMessage = (text) => {
if (!text) return '';
return text
let safeText = escapeHtml(text);
return safeText
.replace(/\*\*(.*?)\*\*/g, '<b>$1</b>')
.replace(/\*(.*?)\*/g, '<i>$1</i>')
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer" style="color:var(--blue);text-decoration:underline">$1</a>')
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, text, url) => {
let decodedUrl = url.replace(/&#039;/g, "'").replace(/&quot;/g, '"').replace(/&amp;/g, '&');
if (decodedUrl.toLowerCase().trim().startsWith('javascript:')) {
return escapeHtml(match);
}
return `<a href="${url}" target="_blank" rel="noopener noreferrer" style="color:var(--blue);text-decoration:underline">${text}</a>`;
})
.replace(/\n/g, '<br/>');
};
+18 -2
View File
@@ -26,12 +26,28 @@ const FAQ_DATA = {
const CATEGORY_ICONS = { "Account": "👤", "Documents": "📄", "Tax Filing": "📋", "Security": "🔒" };
const escapeHtml = (unsafe) => {
return unsafe
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
};
const formatMessage = (text) => {
if (!text) return '';
return text
let safeText = escapeHtml(text);
return safeText
.replace(/\*\*(.*?)\*\*/g, '<b>$1</b>')
.replace(/\*(.*?)\*/g, '<i>$1</i>')
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" style="color:var(--blue);text-decoration:underline">$1</a>')
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, text, url) => {
let decodedUrl = url.replace(/&#039;/g, "'").replace(/&quot;/g, '"').replace(/&amp;/g, '&');
if (decodedUrl.toLowerCase().trim().startsWith('javascript:')) {
return escapeHtml(match);
}
return `<a href="${url}" style="color:var(--blue);text-decoration:underline">${text}</a>`;
})
.replace(/\n/g, '<br/>');
};
@@ -71,7 +71,15 @@ export default function ExpandableSummaryBlock({ extractedData, onSave }) {
let valStr = val;
if (Array.isArray(val)) valStr = val.join('; ');
else if (typeof val === 'object' && val !== null) valStr = JSON.stringify(val);
rows.push([String(key), String(valStr ?? '')]);
let finalKey = String(key);
let finalVal = String(valStr ?? '');
// Sanitize CSV/Excel Formula Injection
if (/^[=+\-@]/.test(finalKey)) finalKey = "'" + finalKey;
if (/^[=+\-@]/.test(finalVal)) finalVal = "'" + finalVal;
rows.push([finalKey, finalVal]);
});
const ws = XLSX.utils.aoa_to_sheet(rows);
+1 -1
View File
@@ -21,7 +21,7 @@ export default function DashboardLayout() {
</div>
</header>
<main className="page-main page-enter">
<main className={`${(user?.role === 'admin' || user?.role === 'super_admin') ? 'page-main-wide' : 'page-main'} page-enter`}>
<Outlet />
</main>
</div>
+73 -21
View File
@@ -1,12 +1,16 @@
import { useState, useEffect, useCallback } from 'react';
import { useAuth } from '../context/AuthContext';
import { useNavigate } from 'react-router-dom';
import DOMPurify from 'dompurify';
export default function AdminDashboard() {
const { authFetch } = useAuth();
const [stats, setStats] = useState({ total_users: 0, pending_personal: 0, pending_business: 0, admins: 0 });
const [users, setUsers] = useState([]);
const [search, setSearch] = useState("");
const [userFilter, setUserFilter] = useState("all");
const [userSort, setUserSort] = useState("newest");
const [filterYear, setFilterYear] = useState(new Date().getFullYear().toString());
const [tab, setTab] = useState("users");
const [loading, setLoading] = useState(true);
const navigate = useNavigate();
@@ -37,7 +41,7 @@ export default function AdminDashboard() {
const fetchAdminData = useCallback(async () => {
setLoading(true);
try {
const res = await authFetch("/api/auth/admin/users");
const res = await authFetch(`/api/auth/admin/users?tax_year=${filterYear}`);
if (res.ok) {
const payload = await res.json();
@@ -78,7 +82,7 @@ export default function AdminDashboard() {
useEffect(() => {
fetchAdminData();
}, [authFetch, fetchAdminData]);
}, [authFetch, fetchAdminData, filterYear]);
useEffect(() => {
if (tab === "templates") {
@@ -133,28 +137,76 @@ export default function AdminDashboard() {
const yearOptions = [currentYear - 1, currentYear, currentYear + 1];
const filteredUsers = users.filter(u => {
// Stat Card Filters
if (userFilter === 'pending_personal' && !(u.pending_personal > 0)) return false;
if (userFilter === 'pending_business' && !(u.pending_business > 0)) return false;
if (!search) return true;
const q = search.toLowerCase();
return (u.name?.toLowerCase().includes(q) || u.email?.toLowerCase().includes(q));
}).sort((a, b) => {
if (userSort === 'asc') return (a.name || '').localeCompare(b.name || '');
if (userSort === 'desc') return (b.name || '').localeCompare(a.name || '');
if (userSort === 'highest_pending') {
const aPending = (a.pending_personal || 0) + (a.pending_business || 0);
const bPending = (b.pending_personal || 0) + (b.pending_business || 0);
return bPending - aPending;
}
// Default fallback to ID if created_at is missing
if (userSort === 'newest') return (b.id || 0) - (a.id || 0);
if (userSort === 'oldest') return (a.id || 0) - (b.id || 0);
return 0;
});
return (
<div className="page-main-wide page-enter">
<div className="flex-between align-center" style={{ marginBottom: '24px', flexWrap: 'wrap', gap: '16px' }}>
<h1 style={{ margin: 0, fontSize: '28px', color: 'var(--navy)' }}>
Users <span style={{ color: 'var(--muted)', fontWeight: 400 }}>{tab === 'templates' ? 'Templates' : ''}</span>
</h1>
<div className="">
<h1 style={{
margin: '0 0 32px 0',
fontSize: '42px',
fontFamily: 'var(--font-display)',
fontWeight: '800',
color: 'var(--ink)',
textAlign: 'center',
letterSpacing: '-0.5px'
}}>
Admin Dashboard <span style={{ color: 'var(--brass)', fontWeight: 600, fontSize: '32px' }}>{tab === 'templates' ? '| Templates' : ''}</span>
</h1>
<div style={{ display: 'flex', justifyContent: 'flex-end', marginBottom: '24px', flexWrap: 'wrap', gap: '16px' }}>
{tab === 'users' && (
<div className="search-wrap" style={{ width: '100%', maxWidth: '300px' }}>
<span className="material-symbols-outlined search-icon" style={{position: 'absolute', left: '12px', top: '50%', transform: 'translateY(-50%)', color: 'var(--muted)', fontSize: '20px'}}>search</span>
<input
type="text"
className="search-input"
style={{ width: '100%', padding: '10px 12px 10px 40px', border: '1px solid var(--border)', borderRadius: 'var(--radius-full)', outline: 'none' }}
placeholder="Search by name or email"
value={search}
onChange={(e) => setSearch(e.target.value)}
/>
<div style={{ display: 'flex', gap: '12px', width: '100%', maxWidth: '500px', flexWrap: 'wrap' }}>
<div className="search-wrap" style={{ flex: 1, minWidth: '200px', position: 'relative' }}>
<span className="material-symbols-outlined search-icon" style={{position: 'absolute', left: '12px', top: '50%', transform: 'translateY(-50%)', color: 'var(--muted)', fontSize: '20px'}}>search</span>
<input
type="text"
className="search-input"
style={{ width: '100%', padding: '10px 12px 10px 40px', border: '1px solid var(--border)', borderRadius: 'var(--radius-full)', outline: 'none' }}
placeholder="Search by name or email"
value={search}
onChange={(e) => setSearch(e.target.value)}
/>
</div>
<select
className="select-input"
style={{ width: 'auto', padding: '10px 16px', borderRadius: 'var(--radius-full)', border: '1px solid var(--border)', outline: 'none', background: 'white' }}
value={userSort}
onChange={(e) => setUserSort(e.target.value)}
>
<option value="newest">Newest First</option>
<option value="oldest">Oldest First</option>
<option value="highest_pending">Highest Pending</option>
<option value="asc">Name (A-Z)</option>
<option value="desc">Name (Z-A)</option>
</select>
<select
className="select-input"
style={{ width: 'auto', padding: '10px 16px', borderRadius: 'var(--radius-full)', border: '1px solid var(--border)', outline: 'none', background: 'white' }}
value={filterYear}
onChange={(e) => setFilterYear(e.target.value)}
>
<option value={currentYear - 1}>TY {currentYear - 1}</option>
<option value={currentYear}>TY {currentYear}</option>
<option value={currentYear + 1}>TY {currentYear + 1}</option>
</select>
</div>
)}
</div>
@@ -187,13 +239,13 @@ export default function AdminDashboard() {
</div>
{digestHtml && (
<div style={{ marginTop: '12px', paddingTop: '12px', borderTop: '1px solid rgba(31,93,70,0.2)', fontSize: '13px', color: 'var(--navy)', lineHeight: '1.7' }}
dangerouslySetInnerHTML={{ __html: digestHtml }} />
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(digestHtml) }} />
)}
</div>
{/* Stats Bar */}
<div className="admin-stats">
<div className="stat-card accent-blue">
<div className={`stat-card accent-blue ${userFilter === 'all' ? 'active-filter' : ''}`} onClick={() => setUserFilter('all')} style={{ cursor: 'pointer', border: userFilter === 'all' ? '2px solid var(--blue)' : 'none' }}>
<div className="stat-icon"><span className="material-symbols-outlined">group</span></div>
<div className="stat-value">{stats.total_users}</div>
<div className="stat-label">Total Users</div>
@@ -203,12 +255,12 @@ export default function AdminDashboard() {
<div className="stat-value">{stats.admins}</div>
<div className="stat-label">Admin Accounts</div>
</div>
<div className="stat-card accent-orange">
<div className={`stat-card accent-orange ${userFilter === 'pending_personal' ? 'active-filter' : ''}`} onClick={() => setUserFilter('pending_personal')} style={{ cursor: 'pointer', border: userFilter === 'pending_personal' ? '2px solid var(--orange)' : 'none' }}>
<div className="stat-icon"><span className="material-symbols-outlined">description</span></div>
<div className="stat-value">{stats.pending_personal}</div>
<div className="stat-label">Pending Personal</div>
</div>
<div className="stat-card accent-orange">
<div className={`stat-card accent-orange ${userFilter === 'pending_business' ? 'active-filter' : ''}`} onClick={() => setUserFilter('pending_business')} style={{ cursor: 'pointer', border: userFilter === 'pending_business' ? '2px solid var(--orange)' : 'none' }}>
<div className="stat-icon"><span className="material-symbols-outlined">business</span></div>
<div className="stat-value">{stats.pending_business}</div>
<div className="stat-label">Pending Business</div>
+192 -12
View File
@@ -14,6 +14,7 @@ export default function AdminUserDetail() {
const [userDetail, setUserDetail] = useState(null);
const [documents, setDocuments] = useState([]);
const [showAiSummary, setShowAiSummary] = useState({});
const [activeTab, setActiveTab] = useState('personal');
const [taxYear, setTaxYear] = useState("");
const [loading, setLoading] = useState(true);
@@ -23,6 +24,9 @@ export default function AdminUserDetail() {
const [personalTimeline, setPersonalTimeline] = useState(0);
const [businessTimeline, setBusinessTimeline] = useState(0);
// Reject comment panel: { docId, type, note }
const [rejectPanel, setRejectPanel] = useState(null);
// Export Excel Function
const exportToExcel = async () => {
try {
@@ -33,7 +37,7 @@ export default function AdminUserDetail() {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `user_${userId}_documents.xlsx`;
a.download = `user_${userId}_excel_summaries.zip`;
document.body.appendChild(a);
a.click();
a.remove();
@@ -165,26 +169,31 @@ export default function AdminUserDetail() {
}
};
const handleDocApprove = async (docId, type, isApproved) => {
const handleDocApprove = async (docId, type, isApproved, note = '') => {
try {
const status = isApproved ? 'approved' : 'rejected';
const ep = type === "personal" ? `/api/upload/personal-documents/${docId}/review-status` : `/api/upload/business-documents/${docId}/review-status`;
const res = await authFetch(ep, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ status, note: "" })
body: JSON.stringify({ status, note })
});
if (res.ok) {
setRejectPanel(null);
fetchUserDetails(); // reload docs
} else {
showToast("Failed to save review status", "error");
}
} catch (err) { console.error(err);
console.error("Approval error", err);
showToast("Approval error", "error");
}
};
const openRejectPanel = (docId, type) => {
setRejectPanel({ docId, type, note: '' });
};
const deleteAdminDoc = async (docId) => {
if (!window.confirm("Delete this admin document?")) return;
try {
@@ -309,13 +318,38 @@ export default function AdminUserDetail() {
};
if (loading && !userDetail) {
return <div className="page-main-wide page-enter"><div className="empty-state"><div className="empty-title">Loading user details...</div></div></div>;
return <div className=""><div className="empty-state"><div className="empty-title">Loading user details...</div></div></div>;
}
if (!userDetail) {
return <div className="page-main-wide page-enter"><div className="empty-state"><div className="empty-title">User not found</div></div></div>;
return <div className=""><div className="empty-state"><div className="empty-title">User not found</div></div></div>;
}
const exportAllToZip = async () => {
try {
showToast("Preparing ZIP export... This may take a moment.", "info");
const url = taxYear ? `/api/upload/admin/users/${userId}/export-zip?tax_year=${taxYear}` : `/api/upload/admin/users/${userId}/export-zip`;
const res = await authFetch(url);
if (res.ok) {
const blob = await res.blob();
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
a.download = `user_${userId}_documents.zip`;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(downloadUrl);
showToast("ZIP export ready!", "success");
} else {
showToast("Failed to export ZIP file", "error");
}
} catch (err) {
console.error(err);
showToast("Error exporting ZIP file", "error");
}
};
const currentYear = new Date().getFullYear();
const yearOptions = [currentYear - 1, currentYear, currentYear + 1];
@@ -324,7 +358,12 @@ export default function AdminUserDetail() {
const returnDocs = documents.filter(d => d.type === "admin");
return (
<div className="page-main-wide page-enter">
<div className="">
<button className="btn btn-secondary btn-sm" style={{ marginBottom: '16px', display: 'inline-flex', alignItems: 'center', gap: '4px', borderRadius: 'var(--radius-sm)' }} onClick={() => navigate('/admin-dashboard')}>
<span className="material-symbols-outlined" style={{ fontSize: '18px' }}>arrow_back</span>
Back to Dashboard
</button>
{/* User Info Bar */}
<div className="card aud-user-bar" style={{marginBottom: '20px'}}>
<div className="aud-bar-inner">
@@ -389,6 +428,7 @@ export default function AdminUserDetail() {
{yearOptions.map(y => <option key={y} value={y}>{y}</option>)}
</select>
</div>
<button className="btn btn-secondary btn-sm" onClick={exportAllToZip} style={{borderRadius:'var(--radius-sm)'}} title="Download All Docs (ZIP)"><span className="material-symbols-outlined" style={{fontSize: '18px'}}>archive</span></button>
<button className="btn btn-danger btn-sm" onClick={deleteUser} style={{borderRadius:'var(--radius-sm)'}}>Delete User</button>
</div>
</div>
@@ -424,19 +464,87 @@ export default function AdminUserDetail() {
</div>
{doc.notes && <div style={{ fontSize:'12px', color:'var(--warn)', marginTop:'3px', fontWeight:500 }}>⚠ {doc.notes}</div>}
{doc.review_status && (
<div style={{ marginTop:'5px' }}>
<div style={{ marginTop:'5px', display:'flex', alignItems:'center', gap:'8px', flexWrap:'wrap' }}>
<span className={`badge ${doc.review_status === 'approved' ? 'badge-green' : doc.review_status === 'rejected' ? 'badge-red' : 'badge-yellow'}`} style={{fontWeight:700}}>
{doc.review_status.toUpperCase()}
</span>
{doc.review_status === 'rejected' && doc.review_note && (
<span style={{fontSize:'12px', color:'#c0392b', fontStyle:'italic'}}>"{doc.review_note}"</span>
)}
</div>
)}
</div>
<div className="doc-review-actions">
<button onClick={() => viewDoc(doc.storage_key)} className="btn btn-secondary btn-sm" style={{borderRadius:'var(--radius-sm)'}}>View</button>
<button className="btn btn-secondary btn-sm" style={{borderRadius:'var(--radius-sm)'}} onClick={() => handleDocApprove(doc.id, doc.type, true)}>Approve</button>
<button className="btn btn-danger btn-sm" style={{borderRadius:'var(--radius-sm)'}} onClick={() => handleDocApprove(doc.id, doc.type, false)}>Reject</button>
<button className="btn btn-danger btn-sm" style={{borderRadius:'var(--radius-sm)'}} onClick={() => openRejectPanel(doc.id, doc.type)}>Reject</button>
<button
className="btn btn-secondary btn-sm"
style={{borderRadius:'var(--radius-sm)'}}
onClick={() => setShowAiSummary(prev => ({ ...prev, [doc.id]: !prev[doc.id] }))}
>
<span className="material-symbols-outlined" style={{fontSize: '16px', marginRight: '4px', verticalAlign: 'middle'}}>
{showAiSummary[doc.id] ? 'visibility_off' : 'auto_awesome'}
</span>
{showAiSummary[doc.id] ? 'Hide AI Summary' : 'View AI Summary'}
</button>
</div>
</div>
{/* Inline Reject Comment Panel */}
{rejectPanel?.docId === doc.id && rejectPanel?.type === doc.type && (
<div style={{
marginTop: '12px',
padding: '14px 16px',
background: 'rgba(220,53,69,0.05)',
border: '1px solid rgba(220,53,69,0.25)',
borderRadius: 'var(--radius-sm)',
display: 'flex',
flexDirection: 'column',
gap: '10px'
}}>
<div style={{fontWeight:600, fontSize:'13px', color:'#c0392b', display:'flex', alignItems:'center', gap:'6px'}}>
<span className="material-symbols-outlined" style={{fontSize:'16px'}}>feedback</span>
Reason for Rejection (optional)
</div>
<textarea
rows={3}
placeholder="Explain why this document is being rejected..."
value={rejectPanel.note}
onChange={e => setRejectPanel(prev => ({...prev, note: e.target.value}))}
style={{
width: '100%',
padding: '10px 12px',
border: '1px solid rgba(220,53,69,0.35)',
borderRadius: 'var(--radius-sm)',
fontSize: '13px',
resize: 'vertical',
outline: 'none',
fontFamily: 'inherit',
background: 'white',
boxSizing: 'border-box'
}}
/>
<div style={{display:'flex', gap:'8px', justifyContent:'flex-end'}}>
<button
className="btn btn-secondary btn-sm"
style={{borderRadius:'var(--radius-sm)'}}
onClick={() => setRejectPanel(null)}
>Cancel</button>
<button
className="btn btn-danger btn-sm"
style={{borderRadius:'var(--radius-sm)'}}
onClick={() => handleDocApprove(doc.id, doc.type, false, rejectPanel.note)}
>
<span className="material-symbols-outlined" style={{fontSize:'15px', verticalAlign:'middle', marginRight:'4px'}}>block</span>
Confirm Rejection
</button>
</div>
</div>
)}
{showAiSummary[doc.id] && (
<>
{doc.extracted_data && Object.keys(doc.extracted_data).length > 0 ? (
<div className="ai-summary-block">
<div className="ai-summary-label">
@@ -456,6 +564,8 @@ export default function AdminUserDetail() {
</div>
</div>
) : null}
</>
)}
</div>
))
)}
@@ -521,19 +631,87 @@ export default function AdminUserDetail() {
</div>
{doc.notes && <div style={{ fontSize:'12px', color:'var(--warn)', marginTop:'3px', fontWeight:500 }}>⚠ {doc.notes}</div>}
{doc.review_status && (
<div style={{ marginTop:'5px' }}>
<div style={{ marginTop:'5px', display:'flex', alignItems:'center', gap:'8px', flexWrap:'wrap' }}>
<span className={`badge ${doc.review_status === 'approved' ? 'badge-green' : doc.review_status === 'rejected' ? 'badge-red' : 'badge-yellow'}`} style={{fontWeight:700}}>
{doc.review_status.toUpperCase()}
</span>
{doc.review_status === 'rejected' && doc.review_note && (
<span style={{fontSize:'12px', color:'#c0392b', fontStyle:'italic'}}>"{doc.review_note}"</span>
)}
</div>
)}
</div>
<div className="doc-review-actions">
<button onClick={() => viewDoc(doc.storage_key)} className="btn btn-secondary btn-sm" style={{borderRadius:'var(--radius-sm)'}}>View</button>
<button className="btn btn-secondary btn-sm" style={{borderRadius:'var(--radius-sm)'}} onClick={() => handleDocApprove(doc.id, doc.type, true)}>Approve</button>
<button className="btn btn-danger btn-sm" style={{borderRadius:'var(--radius-sm)'}} onClick={() => handleDocApprove(doc.id, doc.type, false)}>Reject</button>
<button className="btn btn-danger btn-sm" style={{borderRadius:'var(--radius-sm)'}} onClick={() => openRejectPanel(doc.id, doc.type)}>Reject</button>
<button
className="btn btn-secondary btn-sm"
style={{borderRadius:'var(--radius-sm)'}}
onClick={() => setShowAiSummary(prev => ({ ...prev, [doc.id]: !prev[doc.id] }))}
>
<span className="material-symbols-outlined" style={{fontSize: '16px', marginRight: '4px', verticalAlign: 'middle'}}>
{showAiSummary[doc.id] ? 'visibility_off' : 'auto_awesome'}
</span>
{showAiSummary[doc.id] ? 'Hide AI Summary' : 'View AI Summary'}
</button>
</div>
</div>
{/* Inline Reject Comment Panel */}
{rejectPanel?.docId === doc.id && rejectPanel?.type === doc.type && (
<div style={{
marginTop: '12px',
padding: '14px 16px',
background: 'rgba(220,53,69,0.05)',
border: '1px solid rgba(220,53,69,0.25)',
borderRadius: 'var(--radius-sm)',
display: 'flex',
flexDirection: 'column',
gap: '10px'
}}>
<div style={{fontWeight:600, fontSize:'13px', color:'#c0392b', display:'flex', alignItems:'center', gap:'6px'}}>
<span className="material-symbols-outlined" style={{fontSize:'16px'}}>feedback</span>
Reason for Rejection (optional)
</div>
<textarea
rows={3}
placeholder="Explain why this document is being rejected..."
value={rejectPanel.note}
onChange={e => setRejectPanel(prev => ({...prev, note: e.target.value}))}
style={{
width: '100%',
padding: '10px 12px',
border: '1px solid rgba(220,53,69,0.35)',
borderRadius: 'var(--radius-sm)',
fontSize: '13px',
resize: 'vertical',
outline: 'none',
fontFamily: 'inherit',
background: 'white',
boxSizing: 'border-box'
}}
/>
<div style={{display:'flex', gap:'8px', justifyContent:'flex-end'}}>
<button
className="btn btn-secondary btn-sm"
style={{borderRadius:'var(--radius-sm)'}}
onClick={() => setRejectPanel(null)}
>Cancel</button>
<button
className="btn btn-danger btn-sm"
style={{borderRadius:'var(--radius-sm)'}}
onClick={() => handleDocApprove(doc.id, doc.type, false, rejectPanel.note)}
>
<span className="material-symbols-outlined" style={{fontSize:'15px', verticalAlign:'middle', marginRight:'4px'}}>block</span>
Confirm Rejection
</button>
</div>
</div>
)}
{showAiSummary[doc.id] && (
<>
{doc.extracted_data && Object.keys(doc.extracted_data).length > 0 ? (
<div className="ai-summary-block">
<div className="ai-summary-label">
@@ -541,7 +719,7 @@ export default function AdminUserDetail() {
AI Summary
</div>
<ExpandableSummaryBlock
extractedData={doc.extracted_data}
extractedData={doc.extracted_data}
onSave={(newData) => handleUpdateExtractedData(doc.id, doc.type, newData)}
/>
</div>
@@ -553,6 +731,8 @@ export default function AdminUserDetail() {
</div>
</div>
) : null}
</>
)}
</div>
))
)}
+10
View File
@@ -1,8 +1,10 @@
import { useState, useEffect } from 'react';
import { useAuth } from '../context/AuthContext';
import { useNavigate } from 'react-router-dom';
export default function Profile() {
const { user, authFetch } = useAuth();
const navigate = useNavigate();
const [formData, setFormData] = useState({ name: '', phone: '' });
const [pwData, setPwData] = useState({ currentPw: '', newPw: '', confirmPw: '' });
const [showPwSection, setShowPwSection] = useState(false);
@@ -63,6 +65,14 @@ export default function Profile() {
return (
<div style={{ maxWidth: '680px', margin: '0 auto' }}>
<button
className="btn btn-secondary btn-sm"
style={{ marginBottom: '16px', display: 'inline-flex', alignItems: 'center', gap: '4px', borderRadius: 'var(--radius-sm)' }}
onClick={() => navigate((user?.role === 'admin' || user?.role === 'super_admin') ? '/admin-dashboard' : '/dashboard')}
>
<span className="material-symbols-outlined" style={{ fontSize: '18px' }}>arrow_back</span>
Back to Dashboard
</button>
<div className="page-heading">
<div>
<h1>My Profile</h1>
+7 -7
View File
@@ -119,12 +119,12 @@ export default function UploadBusiness() {
body: JSON.stringify({ file_count: docs.length, doc_category: "Business" })
});
if (res.ok) {
showToast("Admin notified successfully", "success");
showToast("Documents sent for approval", "success");
} else {
showToast("Failed to notify admin", "error");
showToast("Failed to send for approval", "error");
}
} catch (err) { console.error(err);
showToast("Error notifying admin", "error");
showToast("Error sending for approval", "error");
}
};
@@ -180,7 +180,7 @@ export default function UploadBusiness() {
<input
type="file"
hidden
accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx,.xls,.xlsx"
accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx,.xls,.xlsx,.zip"
ref={el => fileInputRefs.current[dt.name] = el}
onChange={(e) => {
if (e.target.files[0]) {
@@ -232,7 +232,7 @@ export default function UploadBusiness() {
}}
>
+ Choose Files
<input type="file" multiple hidden accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx,.xls,.xlsx" onChange={handleExtraUpload} />
<input type="file" multiple hidden accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx,.xls,.xlsx,.zip" onChange={handleExtraUpload} />
</label>
</div>
@@ -276,11 +276,11 @@ export default function UploadBusiness() {
<div style={{display:'flex', alignItems:'center', justifyContent:'space-between', flexWrap:'wrap', gap:'16px'}}>
<div>
<h3 style={{marginBottom:'4px'}}>Finished Uploading?</h3>
<p className="text-sm" style={{margin:0}}>Notify your accountant that your business documents are ready for review.</p>
<p className="text-sm" style={{margin:0}}>Send your business documents for review.</p>
</div>
<button className="btn btn-primary" onClick={notifyComplete}>
<span className="material-symbols-outlined">send</span>
Notify Admin: Uploads Complete
Send for Approval
</button>
</div>
</div>
+7 -7
View File
@@ -121,12 +121,12 @@ export default function UploadPersonal() {
body: JSON.stringify({ file_count: docs.length, doc_category: "Personal" })
});
if (res.ok) {
showToast("Admin notified successfully", "success");
showToast("Documents sent for approval", "success");
} else {
showToast("Failed to notify admin", "error");
showToast("Failed to send for approval", "error");
}
} catch (err) { console.error(err);
showToast("Error notifying admin", "error");
showToast("Error sending for approval", "error");
}
};
@@ -182,7 +182,7 @@ export default function UploadPersonal() {
<input
type="file"
hidden
accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx"
accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx,.xls,.xlsx,.zip"
ref={el => fileInputRefs.current[dt.name] = el}
onChange={(e) => {
if (e.target.files[0]) {
@@ -234,7 +234,7 @@ export default function UploadPersonal() {
}}
>
+ Choose Files
<input type="file" multiple hidden accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx" onChange={handleExtraUpload} />
<input type="file" multiple hidden accept=".pdf,.jpg,.jpeg,.png,.webp,.doc,.docx,.xls,.xlsx,.zip" onChange={handleExtraUpload} />
</label>
</div>
@@ -278,11 +278,11 @@ export default function UploadPersonal() {
<div style={{display:'flex', alignItems:'center', justifyContent:'space-between', flexWrap:'wrap', gap:'16px'}}>
<div>
<h3 style={{marginBottom:'4px'}}>Finished Uploading?</h3>
<p className="text-sm" style={{margin:0}}>Notify your accountant that your personal documents are ready for review.</p>
<p className="text-sm" style={{margin:0}}>Send your personal documents for review.</p>
</div>
<button className="btn btn-primary" onClick={notifyComplete}>
<span className="material-symbols-outlined">send</span>
Notify Admin: Uploads Complete
Send for Approval
</button>
</div>
</div>
+110 -117
View File
@@ -12,11 +12,15 @@ export default function UserDashboard() {
const [adminDocs, setAdminDocs] = useState([]);
const [loadingDocs, setLoadingDocs] = useState(false);
const [docLoading, setDocLoading] = useState(false);
const [engagementLink, setEngagementLink] = useState(null);
// 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);
// Reject comment panel for admin docs: { docId, note }
const [rejectPanel, setRejectPanel] = useState(null);
// ── declare callbacks BEFORE the effects that reference them ──
@@ -50,8 +54,22 @@ export default function UserDashboard() {
setEngagementDisabled(true);
}
}
const tplRes = await authFetch("/api/upload/templates?category=engagement&tax_year=2025");
if (tplRes.ok) {
const tpls = await tplRes.json();
if (tpls && tpls.length > 0) {
setEngagementLink(tpls[0].download);
} else {
// Fallback static link if no template is defined
setEngagementLink("/Engagement_Letter_Template.pdf");
}
} else {
setEngagementLink("/Engagement_Letter_Template.pdf");
}
} catch (err) {
console.error(err);
setEngagementLink("/Engagement_Letter_Template.pdf");
}
}, [authFetch]);
@@ -116,13 +134,8 @@ export default function UserDashboard() {
}
};
const respondDoc = async (docId, approved) => {
const respondDoc = async (docId, approved, reason = "") => {
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", {
@@ -131,7 +144,9 @@ export default function UserDashboard() {
body: JSON.stringify({ doc_id: docId, status: approved ? "approved" : "rejected", reason })
});
if (res.ok) {
setRejectPanel(null);
showToast(`Document ${approved ? 'approved' : 'rejected'} successfully`, "success");
loadAdminDocs();
} else {
showToast("Failed to submit response", "error");
}
@@ -142,6 +157,11 @@ export default function UserDashboard() {
}
};
const openUserRejectPanel = (docId) => {
setRejectPanel({ docId, note: '' });
};
const toggleSummary = (docId) => {
setExpandedSummary(prev => ({ ...prev, [docId]: !prev[docId] }));
};
@@ -156,8 +176,25 @@ export default function UserDashboard() {
</div>
<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={{display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', flexWrap: 'wrap', gap: '16px', marginBottom: '16px'}}>
<div>
<h3 style={{margin: 0, marginBottom: '4px'}}>Engagement Letter</h3>
<p className="text-sm">Please review and acknowledge the engagement letter before uploading documents.</p>
</div>
{engagementLink && (
<a
href={engagementLink}
target="_blank"
rel="noopener noreferrer"
className="btn btn-secondary btn-sm"
style={{display: 'flex', alignItems: 'center', gap: '6px', borderRadius: 'var(--radius-pill)'}}
>
<span className="material-symbols-outlined" style={{fontSize: '18px'}}>download</span>
Download PDF
</a>
)}
</div>
<label style={{
display: 'flex', alignItems: 'center', gap: '12px', padding: '16px',
background: 'var(--bg)', borderRadius: 'var(--radius-sm)', border: '1px solid var(--border)',
@@ -224,6 +261,7 @@ export default function UserDashboard() {
<tr>
<th>Document Name</th>
<th>Date Provided</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
@@ -236,126 +274,81 @@ export default function UserDashboard() {
<div className="text-sm text-muted">{doc.filename}</div>
</td>
<td>{new Date(doc.created_at).toLocaleDateString()}</td>
<td>
{doc.review_status ? (
<div>
<span className={`badge ${doc.review_status === 'approved' ? 'badge-green' : doc.review_status === 'rejected' ? 'badge-red' : 'badge-yellow'}`} style={{fontWeight:700}}>
{doc.review_status.toUpperCase()}
</span>
{doc.review_status === 'rejected' && doc.review_note && (
<div style={{fontSize:'12px', color:'#c0392b', fontStyle:'italic', marginTop:'4px'}}>
Reason: "{doc.review_note}"
</div>
)}
</div>
) : (
<span className="badge badge-yellow">PENDING</span>
)}
</td>
<td>
<div style={{display:'flex', gap:'8px', flexWrap:'wrap', alignItems:'center'}}>
<button className="btn btn-secondary btn-sm" onClick={() => viewDoc(doc.storage_key)}>View</button>
<button className="btn btn-primary btn-sm" onClick={() => respondDoc(doc.id, true)} disabled={docLoading}>Approve</button>
<button className="btn btn-danger btn-sm" onClick={() => respondDoc(doc.id, false)} disabled={docLoading}>Reject</button>
{/* AI Summary badge / button */}
{doc.ai_summary === null ? (
<span style={{
display: 'inline-flex', alignItems: 'center', gap: '6px',
fontSize: '11.5px', fontWeight: 500,
color: 'var(--brass-dark)',
padding: '5px 12px', borderRadius: 'var(--radius-pill)',
background: 'var(--brass-light)',
border: '1px solid rgba(176,128,61,0.25)',
letterSpacing: '0.01em',
}}>
<span style={{display:'inline-block', animation:'spin 1.5s linear infinite', fontSize:'13px'}}>✦</span>
Analyzing…
</span>
) : doc.ai_summary ? (
<button
onClick={() => toggleSummary(doc.id)}
style={{
display: 'inline-flex', alignItems: 'center', gap: '6px',
fontSize: '11.5px', fontWeight: 600,
padding: '5px 14px', borderRadius: 'var(--radius-pill)',
border: expandedSummary[doc.id]
? '1px solid var(--accent)'
: '1px solid rgba(44,122,91,0.35)',
cursor: 'pointer',
background: expandedSummary[doc.id]
? 'var(--accent)'
: 'linear-gradient(135deg, rgba(44,122,91,0.10) 0%, rgba(31,93,70,0.06) 100%)',
color: expandedSummary[doc.id] ? '#fff' : 'var(--accent)',
boxShadow: expandedSummary[doc.id] ? 'var(--shadow-sm)' : 'none',
transition: 'all 0.22s ease',
letterSpacing: '0.01em',
}}
>
<span style={{fontSize:'13px'}}>✨</span>
{expandedSummary[doc.id] ? 'Hide Summary' : 'AI Summary'}
</button>
) : null}
<button className="btn btn-danger btn-sm" onClick={() => openUserRejectPanel(doc.id)} disabled={docLoading}>Reject</button>
</div>
</td>
</tr>
{/* Expanded AI Summary panel — spans full row width */}
{expandedSummary[doc.id] && doc.ai_summary && (
<tr key={`${doc.id}-summary`}>
<td colSpan={3} style={{padding: '0 0 14px'}}>
{/* Inline Reject Panel */}
{rejectPanel?.docId === doc.id && (
<tr key={`reject-${doc.id}`}>
<td colSpan={4} style={{padding:'0'}}>
<div style={{
padding: '14px 16px',
background: 'rgba(220,53,69,0.05)',
border: '1px solid rgba(220,53,69,0.25)',
borderTop: 'none',
display: 'flex',
borderRadius: 'var(--radius-md)',
overflow: 'hidden',
border: '1px solid rgba(44,122,91,0.20)',
boxShadow: '0 4px 20px -6px rgba(44,122,91,0.18)',
background: 'linear-gradient(135deg, rgba(44,122,91,0.07) 0%, rgba(31,93,70,0.03) 100%)',
backdropFilter: 'blur(8px)',
animation: 'fadeUp 0.2s ease',
flexDirection: 'column',
gap: '10px'
}}>
{/* Left accent strip */}
<div style={{
width: '4px', flexShrink: 0,
background: 'linear-gradient(180deg, var(--accent) 0%, var(--brass) 100%)',
}} />
<div style={{padding: '16px 20px', flex: 1}}>
{/* Header row */}
<div style={{
display: 'flex', alignItems: 'center', gap: '8px',
marginBottom: '10px'
}}>
<div style={{
width: '28px', height: '28px', borderRadius: 'var(--radius-xs)',
background: 'linear-gradient(135deg, var(--accent) 0%, var(--emerald-dark) 100%)',
display: 'flex', alignItems: 'center', justifyContent: 'center',
fontSize: '14px', flexShrink: 0,
boxShadow: '0 2px 8px rgba(44,122,91,0.30)',
}}>
✨
</div>
<div>
<div style={{
fontSize: '10px', fontWeight: 700,
letterSpacing: '0.08em', textTransform: 'uppercase',
color: 'var(--accent)',
}}>AI Document Summary</div>
<div style={{
fontSize: '11px', color: 'var(--muted)', marginTop: '1px'
}}>Generated by BookKeepPro AI</div>
</div>
</div>
{/* Summary text */}
<p style={{
fontSize: '13.5px', lineHeight: '1.7',
color: 'var(--ink)',
margin: 0,
fontFamily: 'var(--font-body)',
}}>
{doc.ai_summary}
</p>
{/* Footer disclaimer */}
<div style={{
display: 'flex', alignItems: 'center', gap: '6px',
marginTop: '12px',
paddingTop: '10px',
borderTop: '1px solid rgba(44,122,91,0.12)',
}}>
<span style={{fontSize:'11px', color:'var(--muted)'}}>⚠</span>
<span style={{
fontSize: '11px', color: 'var(--muted)',
fontStyle: 'italic',
}}>
AI-generated summary — always review the original document for authoritative information.
</span>
</div>
<div style={{fontWeight:600, fontSize:'13px', color:'#c0392b', display:'flex', alignItems:'center', gap:'6px'}}>
<span className="material-symbols-outlined" style={{fontSize:'16px'}}>feedback</span>
Reason for Rejection (optional)
</div>
<textarea
rows={3}
placeholder="Tell the admin why you are rejecting this document..."
value={rejectPanel.note}
onChange={e => setRejectPanel(prev => ({...prev, note: e.target.value}))}
style={{
width: '100%',
padding: '10px 12px',
border: '1px solid rgba(220,53,69,0.35)',
borderRadius: 'var(--radius-sm)',
fontSize: '13px',
resize: 'vertical',
outline: 'none',
fontFamily: 'inherit',
background: 'white',
boxSizing: 'border-box'
}}
/>
<div style={{display:'flex', gap:'8px', justifyContent:'flex-end'}}>
<button
className="btn btn-secondary btn-sm"
style={{borderRadius:'var(--radius-sm)'}}
onClick={() => setRejectPanel(null)}
>Cancel</button>
<button
className="btn btn-danger btn-sm"
style={{borderRadius:'var(--radius-sm)'}}
disabled={docLoading}
onClick={() => respondDoc(doc.id, false, rejectPanel.note)}
>
<span className="material-symbols-outlined" style={{fontSize:'15px', verticalAlign:'middle', marginRight:'4px'}}>block</span>
Confirm Rejection
</button>
</div>
</div>
</td>