Cleanup and bugfixes

This commit is contained in:
Atharv1705
2026-10-01 12:58:37 +05:30
parent f199ecdec6
commit 0ca44bc3f4
11 changed files with 529 additions and 212 deletions
+5 -5
View File
@@ -10,14 +10,14 @@ export default function AdminDashboard() {
const [search, setSearch] = useState("");
const [userFilter, setUserFilter] = useState("all");
const [userSort, setUserSort] = useState("newest");
const [filterYear, setFilterYear] = useState(new Date().getFullYear().toString());
const [filterYear, setFilterYear] = useState("2025");
const [tab, setTab] = useState("users");
const [loading, setLoading] = useState(true);
const navigate = useNavigate();
// --- Template Management State ---
const [tplCategory, setTplCategory] = useState("personal");
const [tplYear, setTplYear] = useState(new Date().getFullYear().toString());
const [tplYear, setTplYear] = useState("2025");
const [templates, setTemplates] = useState([]);
const [tplName, setTplName] = useState("");
const [tplFile, setTplFile] = useState(null);
@@ -50,8 +50,8 @@ export default function AdminDashboard() {
// Compute stats locally
const total = usersArray.length;
const pendingP = usersArray.reduce((s, u) => s + (u.pending_personal || 0), 0);
const pendingB = usersArray.reduce((s, u) => s + (u.pending_business || 0), 0);
const pendingP = usersArray.filter(u => u.pending_personal > 0).length;
const pendingB = usersArray.filter(u => u.pending_business > 0).length;
const admins = usersArray.filter(u => u.role === "admin" || u.role === "super_admin").length;
setStats({ total_users: total, pending_personal: pendingP, pending_business: pendingB, admins: admins });
@@ -133,7 +133,7 @@ export default function AdminDashboard() {
}
};
const currentYear = new Date().getFullYear();
const currentYear = 2025;
const yearOptions = [currentYear - 1, currentYear, currentYear + 1];
const filteredUsers = users.filter(u => {
+148 -17
View File
@@ -26,6 +26,10 @@ export default function AdminUserDetail() {
// Reject comment panel: { docId, type, note }
const [rejectPanel, setRejectPanel] = useState(null);
// Send-for-approval panel: { docId, note }
const [sendApprovalPanel, setSendApprovalPanel] = useState(null);
const [sendingApproval, setSendingApproval] = useState(false);
const [markFiledLoading, setMarkFiledLoading] = useState(false);
// Export Excel Function
const exportToExcel = async () => {
@@ -207,6 +211,54 @@ export default function AdminUserDetail() {
}
};
const sendReturnForApproval = async (docId, note = "") => {
setSendingApproval(true);
try {
const res = await authFetch("/api/review/send-return-for-approval", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ doc_id: docId, note })
});
if (res.ok) {
setSendApprovalPanel(null);
showToast("Document sent to client for approval ✔", "success");
fetchUserDetails();
} else {
const data = await res.json().catch(() => ({}));
showToast(data.detail || "Failed to send", "error");
}
} catch (err) { console.error(err);
showToast("Network error", "error");
} finally {
setSendingApproval(false);
}
};
const markFiled = async () => {
const yearForFiling = taxYear || 2025;
if (!window.confirm(`Mark all approved docs for ${yearForFiling} as FILED? This will send a confirmation email to the client.`)) return;
setMarkFiledLoading(true);
try {
const res = await authFetch("/api/review/mark-filed", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ user_id: parseInt(userId), tax_year: parseInt(yearForFiling) })
});
if (res.ok) {
const data = await res.json();
showToast(`Filed: ${data.personal_filed} personal + ${data.business_filed} business docs`, "success");
fetchUserDetails();
} else {
const data = await res.json().catch(() => ({}));
showToast(data.detail || "Mark filed failed", "error");
}
} catch (err) { console.error(err);
showToast("Network error", "error");
} finally {
setMarkFiledLoading(false);
}
};
const uploadAdminDoc = async (file) => {
const fd = new FormData();
fd.append("file", file);
@@ -784,11 +836,20 @@ export default function AdminUserDetail() {
{activeTab === 'returns' && (
<div className="tab-panel active">
<div className="card-flat">
<div style={{display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:'16px'}}>
<h3 style={{margin:0}}>Admin Documents</h3>
<div>
<div style={{display:'flex', justifyContent:'space-between', alignItems:'center', marginBottom:'16px', flexWrap:'wrap', gap:'8px'}}>
<h3 style={{margin:0}}>Admin Returns / Documents</h3>
<div style={{display:'flex', gap:'8px', flexWrap:'wrap'}}>
<input type="file" hidden ref={adminDocInputRef} accept=".pdf,.doc,.docx,.xls,.xlsx" onChange={e => {if(e.target.files[0]) uploadAdminDoc(e.target.files[0])}} />
<button className="btn btn-primary btn-sm" style={{borderRadius:'var(--radius-sm)'}} onClick={() => adminDocInputRef.current?.click()}>+ Upload Document</button>
<button className="btn btn-primary btn-sm" style={{borderRadius:'var(--radius-sm)'}} onClick={() => adminDocInputRef.current?.click()}>+ Upload Return</button>
<button
className="btn btn-secondary btn-sm"
style={{borderRadius:'var(--radius-sm)', background:'#2c7a5b', color:'#fff', borderColor:'#2c7a5b'}}
onClick={markFiled}
disabled={markFiledLoading}
title={`Mark all approved docs for ${taxYear || 'selected year'} as Filed`}
>
{markFiledLoading ? 'Filing...' : '✔ Mark as Filed'}
</button>
</div>
</div>
{returnDocs.length === 0 ? (
@@ -798,25 +859,95 @@ export default function AdminUserDetail() {
<table className="admin-table">
<thead>
<tr>
<th>Filename</th>
<th>Document</th>
<th>Tax Year</th>
<th>Date</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{returnDocs.map(doc => (
<tr key={doc.id}>
<td>
<div style={{fontWeight:500, color:'var(--navy)'}}>{doc.filename}</div>
</td>
<td>{new Date(doc.uploaded_at).toLocaleDateString()}</td>
<td>
<div style={{display:'flex', gap:'8px'}}>
<button className="btn btn-secondary btn-sm" onClick={() => viewDoc(doc.storage_key)}>View</button>
<button className="btn btn-danger btn-sm" onClick={() => deleteAdminDoc(doc.id)}>Delete</button>
</div>
</td>
</tr>
<>
<tr key={doc.id}>
<td>
<div style={{fontWeight:500, color:'var(--navy)'}}>{doc.doc_label || doc.filename}</div>
<div className="text-sm text-muted">{doc.filename}</div>
</td>
<td>{doc.tax_year || <span className="text-muted">N/A</span>}</td>
<td>{new Date(doc.uploaded_at).toLocaleDateString()}</td>
<td>
{(() => {
const s = doc.review_status || 'pending';
const cls = s === 'approved' ? 'badge-green' : s === 'rejected' ? 'badge-red' : s === 'sent_for_approval' ? 'badge-blue' : s === 'filed' ? 'badge-green' : 'badge-yellow';
return (
<div>
<span className={`badge ${cls}`} style={{fontWeight:700}}>{s.replace(/_/g,' ').toUpperCase()}</span>
{doc.review_note && <div className="text-sm text-muted" style={{marginTop:'3px', fontSize:'11px'}}>{doc.review_note}</div>}
</div>
);
})()}
</td>
<td>
<div style={{display:'flex', gap:'6px', flexWrap:'wrap'}}>
<button className="btn btn-secondary btn-sm" onClick={() => viewDoc(doc.storage_key)}>View</button>
{doc.review_status !== 'filed' && doc.review_status !== 'approved' && (
<button
className="btn btn-primary btn-sm"
style={{background:'#2c7a5b', borderColor:'#2c7a5b', fontSize:'12px'}}
onClick={() => setSendApprovalPanel({ docId: doc.id, note: '' })}
disabled={sendingApproval}
>
📤 Send for Approval
</button>
)}
<button className="btn btn-danger btn-sm" onClick={() => deleteAdminDoc(doc.id)}>Delete</button>
</div>
</td>
</tr>
{/* Inline Send-for-Approval Panel */}
{sendApprovalPanel?.docId === doc.id && (
<tr key={`send-${doc.id}`}>
<td colSpan={5} style={{padding:'0'}}>
<div style={{
padding:'14px 16px',
background:'rgba(44,122,91,0.05)',
border:'1px solid rgba(44,122,91,0.25)',
borderTop:'none',
display:'flex', flexDirection:'column', gap:'10px'
}}>
<div style={{fontWeight:600, fontSize:'13px', color:'#2c7a5b'}}>
📤 Send this document to client for review
</div>
<textarea
rows={2}
placeholder="Optional note to client (e.g. 'Please review page 3')..."
value={sendApprovalPanel.note}
onChange={e => setSendApprovalPanel(prev => ({...prev, note: e.target.value}))}
style={{
width:'100%', padding:'8px 12px',
border:'1px solid rgba(44,122,91,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" onClick={() => setSendApprovalPanel(null)}>Cancel</button>
<button
className="btn btn-primary btn-sm"
style={{background:'#2c7a5b', borderColor:'#2c7a5b'}}
disabled={sendingApproval}
onClick={() => sendReturnForApproval(doc.id, sendApprovalPanel.note)}
>
{sendingApproval ? 'Sending...' : 'Confirm & Email Client'}
</button>
</div>
</div>
</td>
</tr>
)}
</>
))}
</tbody>
</table>
+41 -8
View File
@@ -6,7 +6,7 @@ import { useToast } from '../context/ToastContext';
export default function UploadBusiness() {
const { authFetch } = useAuth();
const { showToast } = useToast();
const [taxYear, setTaxYear] = useState(new Date().getFullYear());
const [taxYear, setTaxYear] = useState(2025);
const [docs, setDocs] = useState([]);
const [templates, setTemplates] = useState([]);
const [loading, setLoading] = useState(false);
@@ -162,12 +162,36 @@ export default function UploadBusiness() {
<div className="empty-state">No required documents for this tax year.</div>
) : templates.map((dt, i) => {
const uploaded = docs.filter(d => d.doc_type === dt.name);
const latestDoc = uploaded[0] || null;
const isRejected = latestDoc?.review_status === 'rejected';
const isApproved = latestDoc?.review_status === 'approved';
const isFiled = latestDoc?.review_status === 'filed';
return (
<div className="doc-slot fade-up" key={i} style={{ animationDelay: `${i * 0.04}s` }}>
<div className="doc-slot fade-up" key={i} style={{ animationDelay: `${i * 0.04}s`, borderLeft: isRejected ? '3px solid #dc3545' : isApproved || isFiled ? '3px solid #2c7a5b' : 'none' }}>
<div className="doc-slot-info">
<div className="doc-slot-name">{i+1}. {dt.name}</div>
<div className="doc-slot-status">
{uploaded.length ? (
{isRejected ? (
<div>
<span style={{display:'inline-flex', alignItems:'center', gap:'5px', background:'#fdecea', color:'#c0392b', padding:'3px 10px', borderRadius:'20px', fontSize:'12px', fontWeight:700}}>
<span className="material-symbols-outlined" style={{fontSize:'13px'}}>cancel</span> REJECTED
</span>
{latestDoc.review_note && (
<div style={{fontSize:'12px', color:'#c0392b', marginTop:'5px', fontStyle:'italic', maxWidth:'260px'}}>
⚠️ Reason: "{latestDoc.review_note}"
</div>
)}
<div style={{fontSize:'11px', color:'var(--muted)', marginTop:'3px'}}>Please correct and re-upload below.</div>
</div>
) : isApproved ? (
<span style={{display:'inline-flex', alignItems:'center', gap:'5px', background:'#edf7f2', color:'#2c7a5b', padding:'3px 10px', borderRadius:'20px', fontSize:'12px', fontWeight:700}}>
<span className="material-symbols-outlined" style={{fontSize:'13px'}}>check_circle</span> APPROVED
</span>
) : isFiled ? (
<span style={{display:'inline-flex', alignItems:'center', gap:'5px', background:'#edf7f2', color:'#2c7a5b', padding:'3px 10px', borderRadius:'20px', fontSize:'12px', fontWeight:700}}>
<span className="material-symbols-outlined" style={{fontSize:'13px'}}>inventory_2</span> FILED
</span>
) : uploaded.length ? (
<span className="pill-pending"><span className="material-symbols-outlined">pending</span> Pending Review</span>
) : dt.download ? (
<a href={dt.download} target="_blank" rel="noopener noreferrer" className="btn-link" style={{ fontSize: '14px', color: 'var(--brand)', textDecoration: 'underline' }}>View Template</a>
@@ -189,21 +213,30 @@ export default function UploadBusiness() {
}
}}
/>
<div style={{display: 'flex', gap: '8px', alignItems: 'center'}}>
<div style={{display: 'flex', gap: '8px', alignItems: 'center', flexWrap:'wrap'}}>
{dt.download && (
<a href={dt.download} target="_blank" rel="noreferrer" className="btn btn-secondary btn-sm" style={{borderRadius: 'var(--radius-pill)', padding: '4px 12px', display: 'flex', alignItems: 'center', gap: '4px'}}>
<span className="material-symbols-outlined" style={{fontSize: '16px'}}>download</span> Template
</a>
)}
{!uploaded.length && (
<button className="btn btn-sm btn-upload-pill" onClick={() => fileInputRefs.current[dt.name].click()}>Upload</button>
{/* Show Upload button if no doc OR doc is rejected (re-upload allowed) */}
{(!uploaded.length || isRejected) && (
<button
className={`btn btn-sm ${isRejected ? 'btn-primary' : 'btn-upload-pill'}`}
style={isRejected ? {background:'#2c7a5b', borderColor:'#2c7a5b', color:'#fff', borderRadius:'var(--radius-pill)'} : {}}
onClick={() => fileInputRefs.current[dt.name].click()}
>
{isRejected ? '🔄 Re-upload' : 'Upload'}
</button>
)}
</div>
{uploaded.map(doc => (
<div key={doc.id} style={{display:'flex', flexDirection:'column', gap:'8px', alignItems:'flex-end'}}>
<div key={doc.id} style={{display:'flex', flexDirection:'column', gap:'8px', alignItems:'flex-end', marginTop:'4px'}}>
<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>
{!isApproved && !isFiled && (
<button className="btn btn-danger btn-xs" style={{borderRadius:'var(--radius-sm)'}} onClick={() => deleteDoc(doc.id)}>Delete</button>
)}
</div>
</div>
))}
+41 -8
View File
@@ -6,7 +6,7 @@ import { useToast } from '../context/ToastContext';
export default function UploadPersonal() {
const { authFetch } = useAuth();
const { showToast } = useToast();
const [taxYear, setTaxYear] = useState(new Date().getFullYear());
const [taxYear, setTaxYear] = useState(2025);
const [docs, setDocs] = useState([]);
const [templates, setTemplates] = useState([]);
const [loading, setLoading] = useState(false);
@@ -164,12 +164,36 @@ export default function UploadPersonal() {
<div className="empty-state">No required documents for this tax year.</div>
) : templates.map((dt, i) => {
const uploaded = docs.filter(d => d.doc_type === dt.name);
const latestDoc = uploaded[0] || null;
const isRejected = latestDoc?.review_status === 'rejected';
const isApproved = latestDoc?.review_status === 'approved';
const isFiled = latestDoc?.review_status === 'filed';
return (
<div className="doc-slot fade-up" key={i} style={{ animationDelay: `${i * 0.04}s` }}>
<div className="doc-slot fade-up" key={i} style={{ animationDelay: `${i * 0.04}s`, borderLeft: isRejected ? '3px solid #dc3545' : isApproved || isFiled ? '3px solid #2c7a5b' : 'none' }}>
<div className="doc-slot-info">
<div className="doc-slot-name">{i+1}. {dt.name}</div>
<div className="doc-slot-status">
{uploaded.length ? (
{isRejected ? (
<div>
<span style={{display:'inline-flex', alignItems:'center', gap:'5px', background:'#fdecea', color:'#c0392b', padding:'3px 10px', borderRadius:'20px', fontSize:'12px', fontWeight:700}}>
<span className="material-symbols-outlined" style={{fontSize:'13px'}}>cancel</span> REJECTED
</span>
{latestDoc.review_note && (
<div style={{fontSize:'12px', color:'#c0392b', marginTop:'5px', fontStyle:'italic', maxWidth:'260px'}}>
⚠️ Reason: "{latestDoc.review_note}"
</div>
)}
<div style={{fontSize:'11px', color:'var(--muted)', marginTop:'3px'}}>Please correct and re-upload below.</div>
</div>
) : isApproved ? (
<span style={{display:'inline-flex', alignItems:'center', gap:'5px', background:'#edf7f2', color:'#2c7a5b', padding:'3px 10px', borderRadius:'20px', fontSize:'12px', fontWeight:700}}>
<span className="material-symbols-outlined" style={{fontSize:'13px'}}>check_circle</span> APPROVED
</span>
) : isFiled ? (
<span style={{display:'inline-flex', alignItems:'center', gap:'5px', background:'#edf7f2', color:'#2c7a5b', padding:'3px 10px', borderRadius:'20px', fontSize:'12px', fontWeight:700}}>
<span className="material-symbols-outlined" style={{fontSize:'13px'}}>inventory_2</span> FILED
</span>
) : uploaded.length ? (
<span className="pill-pending"><span className="material-symbols-outlined">pending</span> Pending Review</span>
) : dt.download ? (
<a href={dt.download} target="_blank" rel="noopener noreferrer" className="btn-link" style={{ fontSize: '14px', color: 'var(--brand)', textDecoration: 'underline' }}>View Template</a>
@@ -191,21 +215,30 @@ export default function UploadPersonal() {
}
}}
/>
<div style={{display: 'flex', gap: '8px', alignItems: 'center'}}>
<div style={{display: 'flex', gap: '8px', alignItems: 'center', flexWrap:'wrap'}}>
{dt.download && (
<a href={dt.download} target="_blank" rel="noreferrer" className="btn btn-secondary btn-sm" style={{borderRadius: 'var(--radius-pill)', padding: '4px 12px', display: 'flex', alignItems: 'center', gap: '4px'}}>
<span className="material-symbols-outlined" style={{fontSize: '16px'}}>download</span> Template
</a>
)}
{!uploaded.length && (
<button className="btn btn-sm btn-upload-pill" onClick={() => fileInputRefs.current[dt.name].click()}>Upload</button>
{/* Show Upload button if no doc OR doc is rejected (re-upload allowed) */}
{(!uploaded.length || isRejected) && (
<button
className={`btn btn-sm ${isRejected ? 'btn-primary' : 'btn-upload-pill'}`}
style={isRejected ? {background:'#2c7a5b', borderColor:'#2c7a5b', color:'#fff', borderRadius:'var(--radius-pill)'} : {}}
onClick={() => fileInputRefs.current[dt.name].click()}
>
{isRejected ? '🔄 Re-upload' : 'Upload'}
</button>
)}
</div>
{uploaded.map(doc => (
<div key={doc.id} style={{display:'flex', flexDirection:'column', gap:'8px', alignItems:'flex-end'}}>
<div key={doc.id} style={{display:'flex', flexDirection:'column', gap:'8px', alignItems:'flex-end', marginTop:'4px'}}>
<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>
{!isApproved && !isFiled && (
<button className="btn btn-danger btn-xs" style={{borderRadius:'var(--radius-sm)'}} onClick={() => deleteDoc(doc.id)}>Delete</button>
)}
</div>
</div>
))}