Add Super Admin Chatbot widget with system overview and FAQs
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
<link rel="stylesheet" href="/css/base.css" />
|
||||
<link rel="stylesheet" href="/css/components.css" />
|
||||
<link rel="stylesheet" href="/css/animations.css" />
|
||||
<link rel="stylesheet" href="/css/chatbot.css" />
|
||||
<style>
|
||||
.users-grid {
|
||||
display: grid;
|
||||
@@ -343,6 +344,7 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script src="/js/admin-chatbot.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<link rel="stylesheet" href="/css/base.css"/>
|
||||
<link rel="stylesheet" href="/css/components.css"/>
|
||||
<link rel="stylesheet" href="/css/animations.css"/>
|
||||
<link rel="stylesheet" href="/css/chatbot.css"/>
|
||||
<style>
|
||||
.approval-row {
|
||||
display:flex; align-items:flex-start; gap:16px;
|
||||
@@ -450,5 +451,6 @@ document.addEventListener("DOMContentLoaded",()=>{
|
||||
if(label) label.addEventListener("keydown",e=>{if(e.key==="Enter"||e.key===" "){e.preventDefault();label.click();}});
|
||||
});
|
||||
</script>
|
||||
<script src="/js/admin-chatbot.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,406 @@
|
||||
/* ============================================================
|
||||
chatbot.css — BookKeepPro Chatbot Widget
|
||||
Floating chat bubble + chat window
|
||||
============================================================ */
|
||||
|
||||
/* ── Chat Bubble (FAB) ──────────────────────────────────── */
|
||||
.chatbot-fab {
|
||||
position: fixed;
|
||||
bottom: 24px;
|
||||
right: 24px;
|
||||
width: 58px;
|
||||
height: 58px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, var(--blue) 0%, var(--accent) 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 4px 20px rgba(0, 119, 200, 0.35);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 28px;
|
||||
z-index: 9998;
|
||||
transition: transform 0.25s ease, box-shadow 0.25s ease;
|
||||
}
|
||||
.chatbot-fab:hover {
|
||||
transform: scale(1.08);
|
||||
box-shadow: 0 6px 28px rgba(0, 119, 200, 0.45);
|
||||
}
|
||||
.chatbot-fab:active {
|
||||
transform: scale(0.96);
|
||||
}
|
||||
.chatbot-fab .fab-icon { transition: transform 0.3s ease; }
|
||||
.chatbot-fab.open .fab-icon { transform: rotate(90deg); }
|
||||
|
||||
/* Pulse ring animation */
|
||||
.chatbot-fab::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: -4px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid var(--blue);
|
||||
opacity: 0;
|
||||
animation: chatPulse 2.5s ease-out infinite;
|
||||
}
|
||||
.chatbot-fab.open::before { animation: none; opacity: 0; }
|
||||
|
||||
@keyframes chatPulse {
|
||||
0% { transform: scale(1); opacity: 0.5; }
|
||||
100% { transform: scale(1.4); opacity: 0; }
|
||||
}
|
||||
|
||||
/* Notification dot */
|
||||
.chatbot-fab .notif-dot {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
right: 2px;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
background: var(--orange);
|
||||
border: 2px solid #fff;
|
||||
animation: dotBounce 1.5s ease infinite;
|
||||
}
|
||||
.chatbot-fab.open .notif-dot { display: none; }
|
||||
|
||||
@keyframes dotBounce {
|
||||
0%, 100% { transform: scale(1); }
|
||||
50% { transform: scale(1.2); }
|
||||
}
|
||||
|
||||
/* ── Chat Window ────────────────────────────────────────── */
|
||||
.chatbot-window {
|
||||
position: fixed;
|
||||
bottom: 96px;
|
||||
right: 24px;
|
||||
width: 380px;
|
||||
max-height: 520px;
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--card);
|
||||
box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
z-index: 9999;
|
||||
overflow: hidden;
|
||||
opacity: 0;
|
||||
transform: translateY(20px) scale(0.95);
|
||||
pointer-events: none;
|
||||
transition: opacity 0.3s ease, transform 0.3s ease;
|
||||
}
|
||||
.chatbot-window.visible {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
/* ── Header ─────────────────────────────────────────────── */
|
||||
.chatbot-header {
|
||||
background: linear-gradient(135deg, var(--blue) 0%, #005fa3 100%);
|
||||
color: #fff;
|
||||
padding: 16px 18px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.chatbot-header .bot-avatar {
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.chatbot-header .bot-info h4 {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
color: #fff;
|
||||
}
|
||||
.chatbot-header .bot-info span {
|
||||
font-size: 11px;
|
||||
opacity: 0.8;
|
||||
}
|
||||
.chatbot-header .close-chat {
|
||||
margin-left: auto;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
border: none;
|
||||
color: #fff;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
.chatbot-header .close-chat:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
/* ── Messages Area ──────────────────────────────────────── */
|
||||
.chatbot-messages {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
background: #f8fbfe;
|
||||
min-height: 200px;
|
||||
max-height: 340px;
|
||||
}
|
||||
.chatbot-messages::-webkit-scrollbar { width: 5px; }
|
||||
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
|
||||
.chatbot-messages::-webkit-scrollbar-thumb { background: #c5d9ee; border-radius: 10px; }
|
||||
|
||||
/* ── Message Bubbles ────────────────────────────────────── */
|
||||
.chat-msg {
|
||||
max-width: 85%;
|
||||
padding: 10px 14px;
|
||||
border-radius: 14px;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
animation: msgSlideIn 0.3s ease;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
@keyframes msgSlideIn {
|
||||
from { opacity: 0; transform: translateY(8px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
.chat-msg.bot {
|
||||
background: #fff;
|
||||
color: #222;
|
||||
border: 1px solid var(--border);
|
||||
border-bottom-left-radius: 4px;
|
||||
align-self: flex-start;
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,0.04);
|
||||
}
|
||||
.chat-msg.user {
|
||||
background: linear-gradient(135deg, var(--blue), var(--accent));
|
||||
color: #fff;
|
||||
border-bottom-right-radius: 4px;
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
/* ── Typing Indicator ───────────────────────────────────── */
|
||||
.typing-indicator {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding: 12px 16px;
|
||||
align-self: flex-start;
|
||||
}
|
||||
.typing-indicator span {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--blue);
|
||||
opacity: 0.4;
|
||||
animation: typingDot 1.2s ease-in-out infinite;
|
||||
}
|
||||
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
|
||||
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
|
||||
|
||||
@keyframes typingDot {
|
||||
0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
|
||||
30% { transform: translateY(-6px); opacity: 1; }
|
||||
}
|
||||
|
||||
/* ── Quick Reply Buttons ────────────────────────────────── */
|
||||
.quick-replies {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
.quick-reply-btn {
|
||||
background: #fff;
|
||||
border: 1.5px solid var(--blue);
|
||||
color: var(--blue);
|
||||
padding: 9px 14px;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
transition: all 0.2s ease;
|
||||
font-family: inherit;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.quick-reply-btn:hover {
|
||||
background: var(--blue);
|
||||
color: #fff;
|
||||
transform: translateX(4px);
|
||||
box-shadow: 0 2px 8px rgba(0, 119, 200, 0.2);
|
||||
}
|
||||
.quick-reply-btn .qr-icon {
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ── Doc Status Cards ───────────────────────────────────── */
|
||||
.doc-status-card {
|
||||
background: #fff;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-xs);
|
||||
padding: 10px 12px;
|
||||
margin-top: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.doc-status-card .doc-name {
|
||||
font-weight: 600;
|
||||
color: var(--navy);
|
||||
margin-bottom: 4px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.doc-status-card .doc-year {
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
.doc-status-card .doc-badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: var(--radius-pill);
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.3px;
|
||||
}
|
||||
.doc-badge.pending { background: var(--warn-bg); color: var(--warn); }
|
||||
.doc-badge.approved { background: var(--success-bg); color: var(--success); }
|
||||
.doc-badge.rejected { background: var(--error-bg); color: var(--error); }
|
||||
|
||||
.doc-status-card .doc-note {
|
||||
margin-top: 4px;
|
||||
color: var(--muted);
|
||||
font-style: italic;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
/* ── Summary Banner ─────────────────────────────────────── */
|
||||
.status-summary {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.summary-item {
|
||||
text-align: center;
|
||||
padding: 8px 4px;
|
||||
border-radius: var(--radius-xs);
|
||||
background: #f1f7fb;
|
||||
}
|
||||
.summary-item .count {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
display: block;
|
||||
}
|
||||
.summary-item .label {
|
||||
font-size: 10px;
|
||||
text-transform: uppercase;
|
||||
color: var(--muted);
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
.summary-item.pending .count { color: var(--warn); }
|
||||
.summary-item.approved .count { color: var(--success); }
|
||||
.summary-item.rejected .count { color: var(--error); }
|
||||
|
||||
/* ── FAQ List ───────────────────────────────────────────── */
|
||||
.faq-question {
|
||||
background: #fff;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-xs);
|
||||
padding: 9px 12px;
|
||||
font-size: 12.5px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
text-align: left;
|
||||
color: var(--navy);
|
||||
width: 100%;
|
||||
font-family: inherit;
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
}
|
||||
.faq-question:hover {
|
||||
border-color: var(--blue);
|
||||
color: var(--blue);
|
||||
background: var(--blue-light);
|
||||
}
|
||||
|
||||
/* ── Back Button ────────────────────────────────────────── */
|
||||
.back-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--blue);
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
padding: 4px 0;
|
||||
font-family: inherit;
|
||||
font-weight: 500;
|
||||
margin-top: 6px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.back-btn:hover { text-decoration: underline; }
|
||||
|
||||
/* ── Mobile Responsive ──────────────────────────────────── */
|
||||
@media (max-width: 480px) {
|
||||
.chatbot-window {
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
max-height: 75vh;
|
||||
border-radius: var(--radius-md) var(--radius-md) 0 0;
|
||||
}
|
||||
.chatbot-fab {
|
||||
bottom: 16px;
|
||||
right: 16px;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Dark Mode Support ──────────────────────────────────── */
|
||||
[data-theme="dark"] .chatbot-window { background: #1a2332; }
|
||||
[data-theme="dark"] .chatbot-messages { background: #0f1923; }
|
||||
[data-theme="dark"] .chat-msg.bot {
|
||||
background: #1e2d3d;
|
||||
border-color: #2a3f54;
|
||||
color: #d4dde6;
|
||||
}
|
||||
[data-theme="dark"] .quick-reply-btn {
|
||||
background: #1e2d3d;
|
||||
border-color: var(--blue);
|
||||
color: var(--accent);
|
||||
}
|
||||
[data-theme="dark"] .quick-reply-btn:hover {
|
||||
background: var(--blue);
|
||||
color: #fff;
|
||||
}
|
||||
[data-theme="dark"] .doc-status-card {
|
||||
background: #1e2d3d;
|
||||
border-color: #2a3f54;
|
||||
}
|
||||
[data-theme="dark"] .doc-status-card .doc-name { color: #d4dde6; }
|
||||
[data-theme="dark"] .faq-question {
|
||||
background: #1e2d3d;
|
||||
border-color: #2a3f54;
|
||||
color: #d4dde6;
|
||||
}
|
||||
[data-theme="dark"] .faq-question:hover {
|
||||
background: #253648;
|
||||
border-color: var(--blue);
|
||||
}
|
||||
[data-theme="dark"] .summary-item { background: #1e2d3d; }
|
||||
@@ -10,6 +10,7 @@
|
||||
<link rel="stylesheet" href="/css/base.css" />
|
||||
<link rel="stylesheet" href="/css/components.css" />
|
||||
<link rel="stylesheet" href="/css/animations.css" />
|
||||
<link rel="stylesheet" href="/css/chatbot.css" />
|
||||
<style>
|
||||
.action-grid {
|
||||
display: grid;
|
||||
@@ -322,6 +323,8 @@
|
||||
loadAdminUploadedDocs();
|
||||
});
|
||||
</script>
|
||||
<script src="/js/auth.js"></script>
|
||||
<script src="/js/chatbot.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
/**
|
||||
* admin-chatbot.js — BookKeepPro Admin Chatbot Widget
|
||||
*
|
||||
* Provides:
|
||||
* - Admin status overview (fetches from /api/chatbot/admin-status)
|
||||
* - Admin FAQs
|
||||
*
|
||||
* Requires: auth.js (for authFetch)
|
||||
*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Admin FAQ Knowledge Base
|
||||
───────────────────────────────────────────── */
|
||||
const FAQ_DATA = {
|
||||
"Document Review": [
|
||||
{
|
||||
q: "How do I review a document?",
|
||||
a: "From the <a href='/admin-dashboard'>Admin Dashboard</a>, click on any user. You'll see their uploaded documents. Click <b>Approve</b> or <b>Reject</b> and leave a note if needed."
|
||||
},
|
||||
{
|
||||
q: "What happens when I reject a document?",
|
||||
a: "The document's status changes to <b>Rejected</b> and the user is notified. They will see your review note and can upload a corrected version to replace it."
|
||||
},
|
||||
{
|
||||
q: "How do I upload admin documents for a user?",
|
||||
a: "Go to the user's detail page and scroll down to <b>Admin Documents</b>. You can upload tax returns, reports, and other finalized forms there. These will be visible to the user."
|
||||
}
|
||||
],
|
||||
"User Management": [
|
||||
{
|
||||
q: "How do I see user details?",
|
||||
a: "Simply click on any user in the <b>Admin Dashboard</b> table. This will take you to their detailed view where you can see their info and all their documents."
|
||||
},
|
||||
{
|
||||
q: "Can I add another admin?",
|
||||
a: "Currently, Super Admins can only be created via the backend script `create_super_admin.py` for security reasons."
|
||||
}
|
||||
],
|
||||
"Notifications": [
|
||||
{
|
||||
q: "How are users notified?",
|
||||
a: "Users receive automated emails when they sign up, when their documents are ready for review, and when you approve or reject their documents."
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const CATEGORY_ICONS = {
|
||||
"Document Review": "📑",
|
||||
"User Management": "👥",
|
||||
"Notifications": "🔔"
|
||||
};
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Inject HTML
|
||||
───────────────────────────────────────────── */
|
||||
function injectWidget() {
|
||||
const widget = document.createElement("div");
|
||||
widget.id = "chatbot-widget";
|
||||
widget.innerHTML = `
|
||||
<button class="chatbot-fab" id="chatFab" aria-label="Open admin assistant" style="background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 100%);">
|
||||
<span class="fab-icon">🤖</span>
|
||||
<span class="notif-dot"></span>
|
||||
</button>
|
||||
<div class="chatbot-window" id="chatWindow">
|
||||
<div class="chatbot-header" style="background: linear-gradient(135deg, var(--navy) 0%, #005fa3 100%);">
|
||||
<div class="bot-avatar">🤖</div>
|
||||
<div class="bot-info">
|
||||
<h4>Admin Assistant</h4>
|
||||
<span>System Insights & Help</span>
|
||||
</div>
|
||||
<button class="close-chat" id="chatClose" aria-label="Close chat">✕</button>
|
||||
</div>
|
||||
<div class="chatbot-messages" id="chatMessages"></div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(widget);
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Core Chat Logic
|
||||
───────────────────────────────────────────── */
|
||||
let messagesEl;
|
||||
|
||||
function addBotMessage(html) {
|
||||
const div = document.createElement("div");
|
||||
div.className = "chat-msg bot";
|
||||
div.innerHTML = html;
|
||||
messagesEl.appendChild(div);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
function addUserMessage(text) {
|
||||
const div = document.createElement("div");
|
||||
div.className = "chat-msg user";
|
||||
div.style.background = "linear-gradient(135deg, var(--navy), var(--blue))";
|
||||
div.textContent = text;
|
||||
messagesEl.appendChild(div);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
function showTyping() {
|
||||
const div = document.createElement("div");
|
||||
div.className = "typing-indicator";
|
||||
div.id = "typingIndicator";
|
||||
div.innerHTML = "<span></span><span></span><span></span>";
|
||||
messagesEl.appendChild(div);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
function hideTyping() {
|
||||
const el = document.getElementById("typingIndicator");
|
||||
if (el) el.remove();
|
||||
}
|
||||
|
||||
function scrollToBottom() {
|
||||
requestAnimationFrame(() => {
|
||||
messagesEl.scrollTop = messagesEl.scrollHeight;
|
||||
});
|
||||
}
|
||||
|
||||
function botReply(html, delay) {
|
||||
delay = delay || 600;
|
||||
showTyping();
|
||||
setTimeout(() => {
|
||||
hideTyping();
|
||||
addBotMessage(html);
|
||||
}, delay);
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Quick Replies (Menu Buttons)
|
||||
───────────────────────────────────────────── */
|
||||
function addQuickReplies(options) {
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.className = "quick-replies";
|
||||
options.forEach(opt => {
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "quick-reply-btn";
|
||||
btn.innerHTML = `<span class="qr-icon">${opt.icon}</span> ${opt.label}`;
|
||||
btn.onclick = () => {
|
||||
addUserMessage(opt.label);
|
||||
opt.action();
|
||||
};
|
||||
wrapper.appendChild(btn);
|
||||
});
|
||||
messagesEl.appendChild(wrapper);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Main Menu
|
||||
───────────────────────────────────────────── */
|
||||
function showMainMenu() {
|
||||
botReply("Hello Admin! 🛠️ How can I assist you today?", 400);
|
||||
setTimeout(() => {
|
||||
addQuickReplies([
|
||||
{ icon: "📊", label: "System Overview", action: handleSystemOverview },
|
||||
{ icon: "❓", label: "Admin FAQs", action: handleFAQCategories }
|
||||
]);
|
||||
}, 1050);
|
||||
}
|
||||
|
||||
function addBackButton() {
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "back-btn";
|
||||
btn.innerHTML = "← Back to main menu";
|
||||
btn.onclick = () => {
|
||||
addUserMessage("Back to main menu");
|
||||
showMainMenu();
|
||||
};
|
||||
messagesEl.appendChild(btn);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
System Overview Flow
|
||||
───────────────────────────────────────────── */
|
||||
async function handleSystemOverview() {
|
||||
const token = localStorage.getItem("token");
|
||||
if (!token) {
|
||||
botReply('You need to be logged in to view stats.', 500);
|
||||
setTimeout(addBackButton, 1200);
|
||||
return;
|
||||
}
|
||||
|
||||
showTyping();
|
||||
|
||||
try {
|
||||
const res = await window.authFetch("/api/chatbot/admin-status");
|
||||
if (!res || !res.ok) {
|
||||
hideTyping();
|
||||
addBotMessage("Sorry, I couldn't fetch the system status right now.");
|
||||
addBackButton();
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
hideTyping();
|
||||
|
||||
addBotMessage(`Here is the current system overview:`);
|
||||
|
||||
const summaryHtml = `
|
||||
<div class="status-summary" style="grid-template-columns: repeat(2, 1fr);">
|
||||
<div class="summary-item" style="grid-column: span 2;">
|
||||
<span class="count">${data.total_users}</span>
|
||||
<span class="label">Total Users</span>
|
||||
</div>
|
||||
<div class="summary-item pending">
|
||||
<span class="count">${data.pending_personal}</span>
|
||||
<span class="label">Pending Personal</span>
|
||||
</div>
|
||||
<div class="summary-item pending">
|
||||
<span class="count">${data.pending_business}</span>
|
||||
<span class="label">Pending Business</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
addBotMessage(summaryHtml);
|
||||
|
||||
if (data.total_pending > 0) {
|
||||
setTimeout(() => {
|
||||
addBotMessage(`You have a total of <b>${data.total_pending} documents</b> waiting for review!`);
|
||||
}, 400);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
addBotMessage("All caught up! 🎉 There are no pending documents to review right now.");
|
||||
}, 400);
|
||||
}
|
||||
|
||||
setTimeout(addBackButton, 800);
|
||||
|
||||
} catch (err) {
|
||||
hideTyping();
|
||||
addBotMessage("Oops! Something went wrong while fetching stats.");
|
||||
addBackButton();
|
||||
}
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
FAQ Flow
|
||||
───────────────────────────────────────────── */
|
||||
function handleFAQCategories() {
|
||||
botReply("Choose a category to view admin guides:", 400);
|
||||
setTimeout(() => {
|
||||
const options = Object.keys(FAQ_DATA).map(cat => ({
|
||||
icon: CATEGORY_ICONS[cat] || "📌",
|
||||
label: cat,
|
||||
action: () => showFAQList(cat)
|
||||
}));
|
||||
options.push({ icon: "←", label: "Back to main menu", action: showMainMenu });
|
||||
addQuickReplies(options);
|
||||
}, 1050);
|
||||
}
|
||||
|
||||
function showFAQList(category) {
|
||||
addBotMessage(`<b>${CATEGORY_ICONS[category] || ""} ${category}</b> — Select a guide:`);
|
||||
|
||||
const wrapper = document.createElement("div");
|
||||
FAQ_DATA[category].forEach(item => {
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "faq-question";
|
||||
btn.textContent = item.q;
|
||||
btn.onclick = () => {
|
||||
addUserMessage(item.q);
|
||||
botReply(item.a, 500);
|
||||
setTimeout(() => {
|
||||
addQuickReplies([
|
||||
{ icon: "📌", label: "More " + category + " questions", action: () => showFAQList(category) },
|
||||
{ icon: "🏠", label: "Back to main menu", action: showMainMenu }
|
||||
]);
|
||||
}, 1200);
|
||||
};
|
||||
wrapper.appendChild(btn);
|
||||
});
|
||||
messagesEl.appendChild(wrapper);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Initialize Widget
|
||||
───────────────────────────────────────────── */
|
||||
function init() {
|
||||
injectWidget();
|
||||
|
||||
const fab = document.getElementById("chatFab");
|
||||
const window_ = document.getElementById("chatWindow");
|
||||
const close_ = document.getElementById("chatClose");
|
||||
messagesEl = document.getElementById("chatMessages");
|
||||
|
||||
let isOpen = false;
|
||||
let hasOpened = false;
|
||||
|
||||
function toggle() {
|
||||
isOpen = !isOpen;
|
||||
fab.classList.toggle("open", isOpen);
|
||||
window_.classList.toggle("visible", isOpen);
|
||||
sessionStorage.setItem("admin_chatbot_open", isOpen ? "1" : "0");
|
||||
|
||||
if (isOpen && !hasOpened) {
|
||||
hasOpened = true;
|
||||
showMainMenu();
|
||||
}
|
||||
}
|
||||
|
||||
fab.addEventListener("click", toggle);
|
||||
close_.addEventListener("click", toggle);
|
||||
|
||||
// Restore state from session
|
||||
if (sessionStorage.getItem("admin_chatbot_open") === "1") {
|
||||
toggle();
|
||||
}
|
||||
}
|
||||
|
||||
/* Start when DOM is ready */
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,416 @@
|
||||
/**
|
||||
* chatbot.js — BookKeepPro Chatbot Widget
|
||||
*
|
||||
* Provides:
|
||||
* - Document status checking (fetches from /api/chatbot/doc-status)
|
||||
* - FAQ answers (hardcoded knowledge base)
|
||||
* - Contact support shortcut
|
||||
*
|
||||
* Requires: auth.js (for authFetch)
|
||||
*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
FAQ Knowledge Base
|
||||
───────────────────────────────────────────── */
|
||||
const FAQ_DATA = {
|
||||
"Account": [
|
||||
{
|
||||
q: "How do I reset my password?",
|
||||
a: 'Go to the <a href="/login">login page</a> and click <b>"Forgot Password"</b>. Enter your email and we\'ll send a reset link to your inbox.'
|
||||
},
|
||||
{
|
||||
q: "How do I verify my email?",
|
||||
a: 'Check your inbox for a verification email from BookKeepPro. Click the link inside to verify. If you didn\'t receive it, visit the <a href="/resend-verification">Resend Verification</a> page.'
|
||||
},
|
||||
{
|
||||
q: "How do I update my profile?",
|
||||
a: 'Go to your <a href="/profile">Profile page</a> to update your name, phone number, or change your password.'
|
||||
},
|
||||
{
|
||||
q: "Can I change my email address?",
|
||||
a: "Currently, email addresses cannot be changed once registered. Please contact support if you need assistance."
|
||||
}
|
||||
],
|
||||
"Documents": [
|
||||
{
|
||||
q: "What file types are accepted?",
|
||||
a: "We accept <b>PDF, JPG, PNG, WEBP, DOC, and DOCX</b> files. The maximum file size is <b>10 MB</b>."
|
||||
},
|
||||
{
|
||||
q: 'What does "Pending" status mean?',
|
||||
a: 'Your document has been <b>uploaded successfully</b> and is waiting for an admin to review it. You\'ll be notified once it\'s reviewed.'
|
||||
},
|
||||
{
|
||||
q: 'What does "Rejected" mean?',
|
||||
a: "The admin found an issue with your document. Check the <b>review note</b> for details about what needs to be fixed, then re-upload a corrected version."
|
||||
},
|
||||
{
|
||||
q: "How long does review take?",
|
||||
a: "Typically <b>1–3 business days</b>. You'll receive an email notification when your documents are reviewed."
|
||||
},
|
||||
{
|
||||
q: "Can I replace an uploaded document?",
|
||||
a: "Yes! Simply go to the upload page for that document type and upload a new file. It will replace the previous one."
|
||||
}
|
||||
],
|
||||
"Tax Filing": [
|
||||
{
|
||||
q: "What tax years are supported?",
|
||||
a: "We currently support tax years <b>2023, 2024, 2025, and 2026</b>."
|
||||
},
|
||||
{
|
||||
q: "What personal documents do I need?",
|
||||
a: 'An <b>Individual Taxpayer Organizer</b> for your tax year. Visit the <a href="/upload-personal">Personal Documents</a> page for the full checklist.'
|
||||
},
|
||||
{
|
||||
q: "What business documents do I need?",
|
||||
a: '<b>S-Corp, LLC, or Partnership Organizer</b> plus Certificate of Formation, EIN, and Annual Financial Statements. Visit the <a href="/upload-business">Business Documents</a> page.'
|
||||
}
|
||||
],
|
||||
"Security": [
|
||||
{
|
||||
q: "Is my data secure?",
|
||||
a: "Absolutely. All files are stored securely on our servers with <b>encrypted access tokens</b>. Only you and authorized admins can view your documents."
|
||||
},
|
||||
{
|
||||
q: "Who can see my documents?",
|
||||
a: "Only <b>you</b> and <b>authorized BookKeepPro administrators</b>. Your documents are never shared with third parties."
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const CATEGORY_ICONS = {
|
||||
"Account": "👤",
|
||||
"Documents": "📄",
|
||||
"Tax Filing": "📋",
|
||||
"Security": "🔒"
|
||||
};
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Inject HTML
|
||||
───────────────────────────────────────────── */
|
||||
function injectWidget() {
|
||||
const widget = document.createElement("div");
|
||||
widget.id = "chatbot-widget";
|
||||
widget.innerHTML = `
|
||||
<button class="chatbot-fab" id="chatFab" aria-label="Open chat assistant">
|
||||
<span class="fab-icon">💬</span>
|
||||
<span class="notif-dot"></span>
|
||||
</button>
|
||||
<div class="chatbot-window" id="chatWindow">
|
||||
<div class="chatbot-header">
|
||||
<div class="bot-avatar">🤖</div>
|
||||
<div class="bot-info">
|
||||
<h4>BookKeep Assistant</h4>
|
||||
<span>Always here to help</span>
|
||||
</div>
|
||||
<button class="close-chat" id="chatClose" aria-label="Close chat">✕</button>
|
||||
</div>
|
||||
<div class="chatbot-messages" id="chatMessages"></div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(widget);
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Core Chat Logic
|
||||
───────────────────────────────────────────── */
|
||||
let messagesEl;
|
||||
|
||||
function addBotMessage(html) {
|
||||
const div = document.createElement("div");
|
||||
div.className = "chat-msg bot";
|
||||
div.innerHTML = html;
|
||||
messagesEl.appendChild(div);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
function addUserMessage(text) {
|
||||
const div = document.createElement("div");
|
||||
div.className = "chat-msg user";
|
||||
div.textContent = text;
|
||||
messagesEl.appendChild(div);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
function showTyping() {
|
||||
const div = document.createElement("div");
|
||||
div.className = "typing-indicator";
|
||||
div.id = "typingIndicator";
|
||||
div.innerHTML = "<span></span><span></span><span></span>";
|
||||
messagesEl.appendChild(div);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
function hideTyping() {
|
||||
const el = document.getElementById("typingIndicator");
|
||||
if (el) el.remove();
|
||||
}
|
||||
|
||||
function scrollToBottom() {
|
||||
requestAnimationFrame(() => {
|
||||
messagesEl.scrollTop = messagesEl.scrollHeight;
|
||||
});
|
||||
}
|
||||
|
||||
function botReply(html, delay) {
|
||||
delay = delay || 600;
|
||||
showTyping();
|
||||
setTimeout(() => {
|
||||
hideTyping();
|
||||
addBotMessage(html);
|
||||
}, delay);
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Quick Replies (Menu Buttons)
|
||||
───────────────────────────────────────────── */
|
||||
function addQuickReplies(options) {
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.className = "quick-replies";
|
||||
options.forEach(opt => {
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "quick-reply-btn";
|
||||
btn.innerHTML = `<span class="qr-icon">${opt.icon}</span> ${opt.label}`;
|
||||
btn.onclick = () => {
|
||||
addUserMessage(opt.label);
|
||||
opt.action();
|
||||
};
|
||||
wrapper.appendChild(btn);
|
||||
});
|
||||
messagesEl.appendChild(wrapper);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Main Menu
|
||||
───────────────────────────────────────────── */
|
||||
function showMainMenu() {
|
||||
botReply("Hi there! 👋 I'm your BookKeep Assistant. How can I help you today?", 400);
|
||||
setTimeout(() => {
|
||||
addQuickReplies([
|
||||
{ icon: "📄", label: "Check Document Status", action: handleDocStatus },
|
||||
{ icon: "❓", label: "FAQs", action: handleFAQCategories },
|
||||
{ icon: "📞", label: "Contact Support", action: handleContact }
|
||||
]);
|
||||
}, 1050);
|
||||
}
|
||||
|
||||
function addBackButton() {
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "back-btn";
|
||||
btn.innerHTML = "← Back to main menu";
|
||||
btn.onclick = () => {
|
||||
addUserMessage("Back to main menu");
|
||||
showMainMenu();
|
||||
};
|
||||
messagesEl.appendChild(btn);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Document Status Flow
|
||||
───────────────────────────────────────────── */
|
||||
async function handleDocStatus() {
|
||||
const token = localStorage.getItem("token");
|
||||
if (!token) {
|
||||
botReply('You need to <a href="/login">log in</a> first to check your document status.', 500);
|
||||
setTimeout(addBackButton, 1200);
|
||||
return;
|
||||
}
|
||||
|
||||
showTyping();
|
||||
|
||||
try {
|
||||
const res = await window.authFetch("/api/chatbot/doc-status");
|
||||
if (!res || !res.ok) {
|
||||
hideTyping();
|
||||
addBotMessage("Sorry, I couldn't fetch your document status right now. Please try again later.");
|
||||
addBackButton();
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
hideTyping();
|
||||
|
||||
if (data.summary.total === 0) {
|
||||
addBotMessage("You haven't uploaded any documents yet! 📭");
|
||||
addBotMessage('Head over to <a href="/upload-personal">Personal Documents</a> or <a href="/upload-business">Business Documents</a> to get started.');
|
||||
addBackButton();
|
||||
return;
|
||||
}
|
||||
|
||||
// Summary banner
|
||||
addBotMessage(`Here's your document overview — <b>${data.summary.total} documents</b> total:`);
|
||||
|
||||
const summaryHtml = `
|
||||
<div class="status-summary">
|
||||
<div class="summary-item pending">
|
||||
<span class="count">${data.summary.pending}</span>
|
||||
<span class="label">Pending</span>
|
||||
</div>
|
||||
<div class="summary-item approved">
|
||||
<span class="count">${data.summary.approved}</span>
|
||||
<span class="label">Approved</span>
|
||||
</div>
|
||||
<div class="summary-item rejected">
|
||||
<span class="count">${data.summary.rejected}</span>
|
||||
<span class="label">Rejected</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
addBotMessage(summaryHtml);
|
||||
|
||||
// Personal docs
|
||||
if (data.personal.length > 0) {
|
||||
let personalHtml = "<b>📂 Personal Documents:</b>";
|
||||
data.personal.forEach(doc => {
|
||||
personalHtml += buildDocCard(doc.doc_type, doc.status, doc.note, doc.tax_year);
|
||||
});
|
||||
addBotMessage(personalHtml);
|
||||
}
|
||||
|
||||
// Business docs
|
||||
if (data.business.length > 0) {
|
||||
let businessHtml = "<b>💼 Business Documents:</b>";
|
||||
data.business.forEach(doc => {
|
||||
businessHtml += buildDocCard(doc.business_type, doc.status, doc.note, doc.tax_year);
|
||||
});
|
||||
addBotMessage(businessHtml);
|
||||
}
|
||||
|
||||
// Alert on rejected
|
||||
if (data.summary.rejected > 0) {
|
||||
setTimeout(() => {
|
||||
addBotMessage('⚠️ You have <b>' + data.summary.rejected + ' rejected</b> document(s). Please check the review notes and re-upload corrected versions.');
|
||||
}, 300);
|
||||
}
|
||||
|
||||
setTimeout(addBackButton, 500);
|
||||
|
||||
} catch (err) {
|
||||
hideTyping();
|
||||
addBotMessage("Oops! Something went wrong while fetching your status. Please try again.");
|
||||
addBackButton();
|
||||
}
|
||||
}
|
||||
|
||||
function buildDocCard(name, status, note, year) {
|
||||
const statusIcon = status === "approved" ? "🟢" : status === "rejected" ? "🔴" : "🟡";
|
||||
const noteHtml = note ? `<div class="doc-note">📝 ${escapeText(note)}</div>` : "";
|
||||
return `
|
||||
<div class="doc-status-card">
|
||||
<div class="doc-name">${escapeText(name)}</div>
|
||||
<div class="doc-year">Tax Year: ${year}</div>
|
||||
<span class="doc-badge ${status}">${statusIcon} ${status}</span>
|
||||
${noteHtml}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function escapeText(str) {
|
||||
if (typeof window.escapeHtml === "function") return window.escapeHtml(str);
|
||||
const div = document.createElement("div");
|
||||
div.textContent = str || "";
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
FAQ Flow
|
||||
───────────────────────────────────────────── */
|
||||
function handleFAQCategories() {
|
||||
botReply("Choose a category to browse common questions:", 400);
|
||||
setTimeout(() => {
|
||||
const options = Object.keys(FAQ_DATA).map(cat => ({
|
||||
icon: CATEGORY_ICONS[cat] || "📌",
|
||||
label: cat,
|
||||
action: () => showFAQList(cat)
|
||||
}));
|
||||
options.push({ icon: "←", label: "Back to main menu", action: showMainMenu });
|
||||
addQuickReplies(options);
|
||||
}, 1050);
|
||||
}
|
||||
|
||||
function showFAQList(category) {
|
||||
addBotMessage(`<b>${CATEGORY_ICONS[category] || ""} ${category}</b> — Pick a question:`);
|
||||
|
||||
const wrapper = document.createElement("div");
|
||||
FAQ_DATA[category].forEach(item => {
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "faq-question";
|
||||
btn.textContent = item.q;
|
||||
btn.onclick = () => {
|
||||
addUserMessage(item.q);
|
||||
botReply(item.a, 500);
|
||||
setTimeout(() => {
|
||||
addQuickReplies([
|
||||
{ icon: "📌", label: "More " + category + " questions", action: () => showFAQList(category) },
|
||||
{ icon: "🏠", label: "Back to main menu", action: showMainMenu }
|
||||
]);
|
||||
}, 1200);
|
||||
};
|
||||
wrapper.appendChild(btn);
|
||||
});
|
||||
messagesEl.appendChild(wrapper);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Contact Support Flow
|
||||
───────────────────────────────────────────── */
|
||||
function handleContact() {
|
||||
botReply(
|
||||
'You can reach our team anytime! 📧<br><br>' +
|
||||
'<b>Email:</b> <a href="mailto:atharvg.aiindia@gmail.com">atharvg.aiindia@gmail.com</a><br><br>' +
|
||||
'Or use our <a href="/contact">Contact Form</a> and we\'ll get back to you within 24 hours.',
|
||||
500
|
||||
);
|
||||
setTimeout(addBackButton, 1200);
|
||||
}
|
||||
|
||||
/* ─────────────────────────────────────────────
|
||||
Initialize Widget
|
||||
───────────────────────────────────────────── */
|
||||
function init() {
|
||||
injectWidget();
|
||||
|
||||
const fab = document.getElementById("chatFab");
|
||||
const window_ = document.getElementById("chatWindow");
|
||||
const close_ = document.getElementById("chatClose");
|
||||
messagesEl = document.getElementById("chatMessages");
|
||||
|
||||
let isOpen = false;
|
||||
let hasOpened = false;
|
||||
|
||||
function toggle() {
|
||||
isOpen = !isOpen;
|
||||
fab.classList.toggle("open", isOpen);
|
||||
window_.classList.toggle("visible", isOpen);
|
||||
sessionStorage.setItem("chatbot_open", isOpen ? "1" : "0");
|
||||
|
||||
if (isOpen && !hasOpened) {
|
||||
hasOpened = true;
|
||||
showMainMenu();
|
||||
}
|
||||
}
|
||||
|
||||
fab.addEventListener("click", toggle);
|
||||
close_.addEventListener("click", toggle);
|
||||
|
||||
// Restore state from session
|
||||
if (sessionStorage.getItem("chatbot_open") === "1") {
|
||||
toggle();
|
||||
}
|
||||
}
|
||||
|
||||
/* Start when DOM is ready */
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -8,6 +8,7 @@
|
||||
<link rel="stylesheet" href="/css/base.css"/>
|
||||
<link rel="stylesheet" href="/css/components.css"/>
|
||||
<link rel="stylesheet" href="/css/animations.css"/>
|
||||
<link rel="stylesheet" href="/css/chatbot.css"/>
|
||||
|
||||
<style>html{height:100%;}</style> <script src="/js/theme.js?v=2"></script>
|
||||
</head>
|
||||
@@ -159,5 +160,6 @@ async function saveProfile() {
|
||||
|
||||
loadProfile();
|
||||
</script>
|
||||
<script src="/js/chatbot.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<link rel="stylesheet" href="/css/base.css"/>
|
||||
<link rel="stylesheet" href="/css/components.css"/>
|
||||
<link rel="stylesheet" href="/css/animations.css"/>
|
||||
<link rel="stylesheet" href="/css/chatbot.css"/>
|
||||
<style>
|
||||
.doc-slot { display:flex;align-items:center;gap:14px;padding:14px 18px;border:1.5px solid var(--border);border-radius:var(--radius-md);background:var(--card);margin-bottom:10px;transition:border-color var(--transition),background var(--transition); }
|
||||
.doc-slot:hover { border-color:#c5d9ee;background:#fafcff; }
|
||||
@@ -264,5 +265,6 @@ async function loadSavedBusinessDocuments(){
|
||||
onYearChange();
|
||||
})();
|
||||
</script>
|
||||
<script src="/js/chatbot.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<link rel="stylesheet" href="/css/base.css"/>
|
||||
<link rel="stylesheet" href="/css/components.css"/>
|
||||
<link rel="stylesheet" href="/css/animations.css"/>
|
||||
<link rel="stylesheet" href="/css/chatbot.css"/>
|
||||
<style>
|
||||
.doc-slot {
|
||||
display:flex; align-items:center; gap:14px; padding:14px 18px;
|
||||
@@ -325,5 +326,6 @@ async function loadSavedDocuments() {
|
||||
onYearChange();
|
||||
})();
|
||||
</script>
|
||||
<script src="/js/chatbot.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -49,6 +49,12 @@ try:
|
||||
except Exception as exc:
|
||||
log.exception("Failed to load review router: %s", exc)
|
||||
|
||||
try:
|
||||
from app.routers import chatbot # type: ignore
|
||||
app.include_router(chatbot.router)
|
||||
except Exception as exc:
|
||||
log.exception("Failed to load chatbot router: %s", exc)
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# CORS
|
||||
# ─────────────────────────────────────────────
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import logging
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models import PersonalDocument, BusinessDocument, User
|
||||
from app.db import get_db
|
||||
from app.auth.security import get_current_user, require_admin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/api/chatbot", tags=["chatbot"])
|
||||
|
||||
|
||||
@router.get("/doc-status")
|
||||
def get_doc_status(
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
"""Return a consolidated summary of the user's document statuses."""
|
||||
|
||||
personal = (
|
||||
db.query(PersonalDocument)
|
||||
.filter(
|
||||
PersonalDocument.user_id == current_user.id,
|
||||
PersonalDocument.deleted_at == None,
|
||||
)
|
||||
.order_by(PersonalDocument.tax_year.desc(), PersonalDocument.uploaded_at.desc())
|
||||
.all()
|
||||
)
|
||||
|
||||
business = (
|
||||
db.query(BusinessDocument)
|
||||
.filter(
|
||||
BusinessDocument.user_id == current_user.id,
|
||||
BusinessDocument.deleted_at == None,
|
||||
)
|
||||
.order_by(BusinessDocument.tax_year.desc(), BusinessDocument.uploaded_at.desc())
|
||||
.all()
|
||||
)
|
||||
|
||||
personal_list = [
|
||||
{
|
||||
"doc_type": d.doc_type,
|
||||
"status": d.review_status,
|
||||
"note": d.review_note,
|
||||
"tax_year": d.tax_year,
|
||||
"filename": d.filename,
|
||||
}
|
||||
for d in personal
|
||||
]
|
||||
|
||||
business_list = [
|
||||
{
|
||||
"business_type": d.business_type,
|
||||
"status": d.review_status,
|
||||
"note": d.review_note,
|
||||
"tax_year": d.tax_year,
|
||||
"filename": d.filename,
|
||||
}
|
||||
for d in business
|
||||
]
|
||||
|
||||
all_docs = personal_list + business_list
|
||||
summary = {
|
||||
"total": len(all_docs),
|
||||
"pending": sum(1 for d in all_docs if d["status"] == "pending"),
|
||||
"approved": sum(1 for d in all_docs if d["status"] == "approved"),
|
||||
"rejected": sum(1 for d in all_docs if d["status"] == "rejected"),
|
||||
}
|
||||
|
||||
return {
|
||||
"personal": personal_list,
|
||||
"business": business_list,
|
||||
"summary": summary,
|
||||
}
|
||||
|
||||
@router.get("/admin-status")
|
||||
def get_admin_status(
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user),
|
||||
_=Depends(require_admin),
|
||||
):
|
||||
"""Return system-wide stats for the super admin chatbot."""
|
||||
total_users = db.query(User).count()
|
||||
|
||||
pending_personal = (
|
||||
db.query(PersonalDocument)
|
||||
.filter(
|
||||
PersonalDocument.review_status == "pending",
|
||||
PersonalDocument.deleted_at == None,
|
||||
)
|
||||
.count()
|
||||
)
|
||||
|
||||
pending_business = (
|
||||
db.query(BusinessDocument)
|
||||
.filter(
|
||||
BusinessDocument.review_status == "pending",
|
||||
BusinessDocument.deleted_at == None,
|
||||
)
|
||||
.count()
|
||||
)
|
||||
|
||||
return {
|
||||
"total_users": total_users,
|
||||
"pending_personal": pending_personal,
|
||||
"pending_business": pending_business,
|
||||
"total_pending": pending_personal + pending_business,
|
||||
}
|
||||
Reference in New Issue
Block a user