Compare commits
No commits in common. "44132c351e06655313603053b0bdb8111a1fc551" and "a5f8e7bc7f8ef5a9755d7a02a6f202936d802cb6" have entirely different histories.
44132c351e
...
a5f8e7bc7f
|
|
@ -315,7 +315,7 @@ async function client_dashboard(req, res) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const dayNumber = getDayNumber();
|
const dayNumber = getDayNumber(logTime);
|
||||||
|
|
||||||
// Calculate dashboard statistics
|
// Calculate dashboard statistics
|
||||||
const totalHoursLogged = clientProjects.reduce((sum, p) => sum + (p.totalLoggedHours || 0), 0);
|
const totalHoursLogged = clientProjects.reduce((sum, p) => sum + (p.totalLoggedHours || 0), 0);
|
||||||
|
|
|
||||||
|
|
@ -1,193 +0,0 @@
|
||||||
async function clientDashboardGetVaLogsController(req, res) {
|
|
||||||
try {
|
|
||||||
const clientId = req.body.clientId;
|
|
||||||
const clientUser = await ClientModel.findById(clientId);
|
|
||||||
if (!clientUser) {
|
|
||||||
return res.status(404).json({ success: false, message: "Client not found" });
|
|
||||||
}
|
|
||||||
|
|
||||||
const { vaId } = req.params;
|
|
||||||
const vaUser = await VAModel.findById(vaId);
|
|
||||||
if (!vaUser) {
|
|
||||||
return res.status(404).json({ success: false, message: "Virtual Assistant not found" });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the last 15 days
|
|
||||||
const endDate = new Date();
|
|
||||||
endDate.setHours(23, 59, 59, 999); // End of day
|
|
||||||
const startDate = new Date();
|
|
||||||
startDate.setDate(startDate.getDate() - 15);
|
|
||||||
startDate.setHours(0, 0, 0, 0); // Start of day
|
|
||||||
|
|
||||||
// Get shared projects
|
|
||||||
const sharedProjects = await ProjectModel.find({
|
|
||||||
clientId: clientUser._id,
|
|
||||||
'vaAssigned.vaId': vaId,
|
|
||||||
status: "ACTIVE"
|
|
||||||
}).select('name hourlyRate dedicatedHours vaWorkingScheduleStart vaWorkingScheduleEnd isFlexibleAllowed');
|
|
||||||
|
|
||||||
if (!sharedProjects || sharedProjects.length === 0) {
|
|
||||||
return res.status(200).json({
|
|
||||||
success: true,
|
|
||||||
message: "No shared projects found",
|
|
||||||
data: {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const projectLogs = {};
|
|
||||||
const projectIds = sharedProjects.map(p => p._id);
|
|
||||||
|
|
||||||
// Get all work tracks for the last 15 days
|
|
||||||
const workTracks = await WorkTrackModel.find({
|
|
||||||
vaId: vaId,
|
|
||||||
projectId: { $in: projectIds },
|
|
||||||
from: { $gte: startDate },
|
|
||||||
to: { $lte: endDate }
|
|
||||||
})
|
|
||||||
.sort({ from: -1 })
|
|
||||||
.lean();
|
|
||||||
|
|
||||||
// Process each project
|
|
||||||
for (const project of sharedProjects) {
|
|
||||||
const projectIdStr = project._id.toString();
|
|
||||||
|
|
||||||
// Filter tracks for this project
|
|
||||||
const projectTracks = workTracks.filter(track =>
|
|
||||||
track.projectId.toString() === projectIdStr
|
|
||||||
);
|
|
||||||
|
|
||||||
// Group tracks by date
|
|
||||||
const tracksByDate = {};
|
|
||||||
projectTracks.forEach(track => {
|
|
||||||
const dateKey = new Date(track.from).toISOString().split('T')[0];
|
|
||||||
if (!tracksByDate[dateKey]) {
|
|
||||||
tracksByDate[dateKey] = [];
|
|
||||||
}
|
|
||||||
tracksByDate[dateKey].push(track);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create daily logs for the last 15 days
|
|
||||||
const dailyLogs = {};
|
|
||||||
let totalProjectHours = 0;
|
|
||||||
let totalProjectTracks = 0;
|
|
||||||
|
|
||||||
// Generate dates for the last 15 days
|
|
||||||
for (let i = 0; i < 15; i++) {
|
|
||||||
const date = new Date();
|
|
||||||
date.setDate(date.getDate() - i);
|
|
||||||
date.setHours(0, 0, 0, 0);
|
|
||||||
const dateStr = date.toISOString().split('T')[0];
|
|
||||||
|
|
||||||
const dayTracks = tracksByDate[dateStr] || [];
|
|
||||||
const totalTimeDay = dayTracks.reduce((sum, track) => sum + (track.totalTime || 0), 0);
|
|
||||||
|
|
||||||
// Calculate productive time vs idle time if logs are available
|
|
||||||
let productiveTime = 0;
|
|
||||||
let idleTime = 0;
|
|
||||||
|
|
||||||
if (dayTracks.length > 0) {
|
|
||||||
dayTracks.forEach(track => {
|
|
||||||
if (track.logs && Array.isArray(track.logs)) {
|
|
||||||
track.logs.forEach(log => {
|
|
||||||
if (log.status === 'productive' || log.status === 'working') {
|
|
||||||
productiveTime += log.duration || 0;
|
|
||||||
} else if (log.status === 'idle' || log.status === 'away') {
|
|
||||||
idleTime += log.duration || 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
dailyLogs[dateStr] = {
|
|
||||||
logs: dayTracks.map(track => ({
|
|
||||||
id: track._id,
|
|
||||||
from: track.from,
|
|
||||||
to: track.to,
|
|
||||||
totalTime: track.totalTime,
|
|
||||||
logs: track.logs || [],
|
|
||||||
createdAt: track.createdAt,
|
|
||||||
updatedAt: track.updatedAt
|
|
||||||
})),
|
|
||||||
summary: {
|
|
||||||
totalTracks: dayTracks.length,
|
|
||||||
totalTime: totalTimeDay,
|
|
||||||
productiveTime: productiveTime,
|
|
||||||
idleTime: idleTime,
|
|
||||||
efficiency: totalTimeDay > 0 ? (productiveTime / totalTimeDay) * 100 : 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
totalProjectHours += totalTimeDay;
|
|
||||||
totalProjectTracks += dayTracks.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
projectLogs[projectIdStr] = {
|
|
||||||
projectDetails: {
|
|
||||||
id: project._id,
|
|
||||||
name: project.name,
|
|
||||||
hourlyRate: project.hourlyRate,
|
|
||||||
schedule: {
|
|
||||||
start: project.vaWorkingScheduleStart,
|
|
||||||
end: project.vaWorkingScheduleEnd,
|
|
||||||
isFlexibleAllowed: project.isFlexibleAllowed
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dailyLogs: dailyLogs,
|
|
||||||
summary: {
|
|
||||||
totalWorkTracks: totalProjectTracks,
|
|
||||||
totalHours: totalProjectHours,
|
|
||||||
averageDailyHours: totalProjectHours / 15,
|
|
||||||
daysWithActivity: Object.values(dailyLogs).filter(day => day.logs.length > 0).length,
|
|
||||||
lastActivity: projectTracks.length > 0
|
|
||||||
? new Date(projectTracks[0].from)
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate overall statistics
|
|
||||||
const allTracks = workTracks;
|
|
||||||
const totalHoursAllProjects = allTracks.reduce((sum, track) => sum + (track.totalTime || 0), 0);
|
|
||||||
|
|
||||||
return res.status(200).json({
|
|
||||||
success: true,
|
|
||||||
message: "VA logs retrieved successfully",
|
|
||||||
data: {
|
|
||||||
vaDetails: {
|
|
||||||
id: vaUser._id,
|
|
||||||
name: `${vaUser.userDetails?.firstName || ''} ${vaUser.userDetails?.lastName || ''}`.trim(),
|
|
||||||
email: vaUser.userDetails?.email,
|
|
||||||
status: vaUser.status,
|
|
||||||
schedule: vaUser.schedule
|
|
||||||
},
|
|
||||||
dateRange: {
|
|
||||||
startDate: startDate.toISOString().split('T')[0],
|
|
||||||
endDate: endDate.toISOString().split('T')[0],
|
|
||||||
days: 15
|
|
||||||
},
|
|
||||||
projectLogs: projectLogs,
|
|
||||||
summary: {
|
|
||||||
totalProjects: sharedProjects.length,
|
|
||||||
totalWorkTracks: allTracks.length,
|
|
||||||
totalHours: totalHoursAllProjects,
|
|
||||||
averageDailyHours: totalHoursAllProjects / 15,
|
|
||||||
projectsWithActivity: Object.values(projectLogs)
|
|
||||||
.filter(project => project.summary.totalWorkTracks > 0).length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching VA logs:', error);
|
|
||||||
return res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
message: 'Failed to load VA logs',
|
|
||||||
error: process.env.NODE_ENV === 'development' ? error.message : undefined
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
clientDashboardGetVaLogsController
|
|
||||||
};
|
|
||||||
|
|
@ -14,7 +14,6 @@ import { client_verify_email } from "../../controllers/client/vaClientEmailVerif
|
||||||
import { client_dashboard_projects } from "../../controllers/client/dashboard/clientDashboardProjects.controller.js";
|
import { client_dashboard_projects } from "../../controllers/client/dashboard/clientDashboardProjects.controller.js";
|
||||||
import { client_logout_callback } from "../../controllers/client/dashboard/clientLogout.controller.js";
|
import { client_logout_callback } from "../../controllers/client/dashboard/clientLogout.controller.js";
|
||||||
import { va_tips_delete, va_tips_get, va_tips_manage_function, va_tips_update } from "../../controllers/va/vaTips/vaTipsManage.controller.js";
|
import { va_tips_delete, va_tips_get, va_tips_manage_function, va_tips_update } from "../../controllers/va/vaTips/vaTipsManage.controller.js";
|
||||||
import { clientDashboardGetVaLogsController } from "../../controllers/client/dashboard/clientDashboardGetVaLogs.controller.js";
|
|
||||||
|
|
||||||
// clients routes
|
// clients routes
|
||||||
clientRoutes.post("/register", va_register_client); // Register a new VA
|
clientRoutes.post("/register", va_register_client); // Register a new VA
|
||||||
|
|
@ -29,8 +28,6 @@ clientRoutes.get("/tips", clientAuthValidator, va_tips_get);
|
||||||
clientRoutes.patch("/tips/:tipId", clientAuthValidator, va_tips_update);
|
clientRoutes.patch("/tips/:tipId", clientAuthValidator, va_tips_update);
|
||||||
clientRoutes.delete("/tips/:tipId", clientAuthValidator, va_tips_delete);
|
clientRoutes.delete("/tips/:tipId", clientAuthValidator, va_tips_delete);
|
||||||
|
|
||||||
clientRoutes.get("/vaLogsData/:vaId", clientAuthValidator, clientDashboardGetVaLogsController);
|
|
||||||
|
|
||||||
// clientRoutes.get("/:clientID?", va_clients_callback); // VA Clients Callback for getting all VA's or specific client by ID (NC)
|
// clientRoutes.get("/:clientID?", va_clients_callback); // VA Clients Callback for getting all VA's or specific client by ID (NC)
|
||||||
clientRoutes.get("/:clientId/projects/:projectId", va_clients_projects_callback); // VA Clients Projects Callback (NC)
|
clientRoutes.get("/:clientId/projects/:projectId", va_clients_projects_callback); // VA Clients Projects Callback (NC)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -175,15 +175,6 @@ app.get('/client/virtual-assistants/manage-tips', async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/client/virtual-assistants/view-logs', async (req, res) => {
|
|
||||||
try {
|
|
||||||
res.render('client/dashboard-va-logs');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Projects error:', error);
|
|
||||||
res.status(500).render('client/dashboard-va-logs', { error: 'Failed to load profile' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/live/:projectId/:vaId", async (req, res) => {
|
app.get("/live/:projectId/:vaId", async (req, res) => {
|
||||||
const { projectId, vaId } = req.params;
|
const { projectId, vaId } = req.params;
|
||||||
|
|
||||||
|
|
@ -516,11 +507,6 @@ app.get("/health", (req, res) => {
|
||||||
return res.status(200).json({ "success": true, "message": "Server is Healthy" })
|
return res.status(200).json({ "success": true, "message": "Server is Healthy" })
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post("/post-test", (req, res) => {
|
|
||||||
console.log("✅ POST request received at /post-test:", req.body);
|
|
||||||
return res.status(200).json({ "success": true, "message": "POST request received", "data": req.body })
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
res.status(404).render("not_found", {
|
res.status(404).render("not_found", {
|
||||||
title: "404 - Page Not Found"
|
title: "404 - Page Not Found"
|
||||||
|
|
|
||||||
|
|
@ -385,7 +385,7 @@
|
||||||
const activeProject = va?.lastProject?.name ? va.lastProject.name : '-';
|
const activeProject = va?.lastProject?.name ? va.lastProject.name : '-';
|
||||||
const workedTime = formatTime(va.currentSessionDuration);
|
const workedTime = formatTime(va.currentSessionDuration);
|
||||||
const projectsAssigned = va.projectsAssigned || 0;
|
const projectsAssigned = va.projectsAssigned || 0;
|
||||||
const viewLink = va.isCurrentlyActive ? `<a href="/live/${va.lastProjectId}/${va.id}" class="view-link" data-va-id="${va.id}" target="_blank">Live</a>` : '';
|
const viewLink = va.isCurrentlyActive ? `<a href="/live/${va.lastProjectId}/${va.id}" class="view-link" data-va-id="${va.id}" target="_blank">Live Tracking</a>` : '';
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<tr class="va-row" data-va-id="${va.id}">
|
<tr class="va-row" data-va-id="${va.id}">
|
||||||
|
|
|
||||||
|
|
@ -1,334 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en" data-theme="light">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>DocVA Client | Dashboard</title>
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
||||||
<link rel="stylesheet" href="/public/css/dashboard.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.void-btn-a {
|
|
||||||
background: tomato;
|
|
||||||
text-decoration: none;
|
|
||||||
color: #ffffff !important;
|
|
||||||
border: none;
|
|
||||||
padding: 0.5rem 1rem;
|
|
||||||
border-radius: 5px;
|
|
||||||
font-weight: bold;
|
|
||||||
text-decoration: none;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<body class="dashboard-body">
|
|
||||||
<div id="root">
|
|
||||||
<nav class="dashboard-header">
|
|
||||||
<div class="header-content">
|
|
||||||
<div class="header-logo">
|
|
||||||
<div class="logo-container">
|
|
||||||
<h2 class="sidebar-title">DocVA Client Portal</h2>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="header-nav">
|
|
||||||
<ul class="nav-list">
|
|
||||||
<li class="nav-item">
|
|
||||||
<a href="/client/dashboard" class="nav-button">
|
|
||||||
<i class="fas fa-chart-bar"></i>Dashboard
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a href="/client/virtual-assistants" class="nav-button active">
|
|
||||||
<i class="fas fa-users"></i>Virtual Assistants
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a href="/client/projects" class="nav-button">
|
|
||||||
<i class="fas fa-file-invoice"></i>Projects
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<button class="mobile-menu-button">
|
|
||||||
<i class="fas fa-bars"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
<div class="dashboard-container">
|
|
||||||
<aside class="dashboard-sidebar">
|
|
||||||
<nav class="sidebar-nav">
|
|
||||||
<ul class="sidebar-list">
|
|
||||||
<li class="sidebar-item">
|
|
||||||
<a href="/client/profile" class="sidebar-link">
|
|
||||||
<i class="fas fa-user sidebar-icon"></i>
|
|
||||||
<span>Profile</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="sidebar-item">
|
|
||||||
<a href="/client/dashboard" class="sidebar-link">
|
|
||||||
<i class="fas fa-chart-bar sidebar-icon"></i>
|
|
||||||
<span>Dashboard</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="sidebar-item">
|
|
||||||
<a href="/client/virtual-assistants" class="sidebar-link active">
|
|
||||||
<i class="fas fa-users sidebar-icon"></i>
|
|
||||||
<span>Virtual Assistants</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="sidebar-item">
|
|
||||||
<a href="/client/projects" class="sidebar-link">
|
|
||||||
<i class="fas fa-file-invoice sidebar-icon"></i>
|
|
||||||
<span>Projects</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="sidebar-item">
|
|
||||||
<a href="javascript:void(0);" class="sidebar-link" id="logoutButton">
|
|
||||||
<i class="fas fa-sign-out-alt sidebar-icon"></i>
|
|
||||||
<span>Logout</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</aside>
|
|
||||||
<main class="dashboard-main">
|
|
||||||
<div class="dashboard-content">
|
|
||||||
<!-- Virtual Assistants List -->
|
|
||||||
<div class="content-section">
|
|
||||||
<div class="section-header" style="justify-content: space-between;align-items: center;">
|
|
||||||
<a href="/client/virtual-assistants" class="btn btn-secondary">Back</a>
|
|
||||||
</div>
|
|
||||||
<div class="table-container">
|
|
||||||
<div class="table-wrapper">
|
|
||||||
<table class="data-table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Title</th>
|
|
||||||
<th>App Name</th>
|
|
||||||
<th>Link</th>
|
|
||||||
<th>From</th>
|
|
||||||
<th>To</th>
|
|
||||||
<th>Total Time</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="vaLogsTableBody">
|
|
||||||
<!-- Data will be loaded here -->
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<div id="vaEmptyTipState" style="display: none;">
|
|
||||||
<div class="empty-state">
|
|
||||||
<i class="fas fa-users"></i>
|
|
||||||
<h3>No Logs Found</h3>
|
|
||||||
<p>VA haven't logged any time yet.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="logoutModal" class="modal-overlay">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h2 class="modal-title">Confirm Logout</h2>
|
|
||||||
<button class="modal-close" onclick="closeLogoutModal()">
|
|
||||||
<i class="fas fa-times"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="logout-modal-body">
|
|
||||||
<div class="logout-icon">
|
|
||||||
<i class="fas fa-sign-out-alt"></i>
|
|
||||||
</div>
|
|
||||||
<h3 class="logout-title">Are you sure you want to logout?</h3>
|
|
||||||
<p class="logout-message">You will be logged out of your account and redirected to the login page.
|
|
||||||
</p>
|
|
||||||
<div class="logout-actions">
|
|
||||||
<button class="logout-cancel-btn" onclick="closeLogoutModal()">Cancel</button>
|
|
||||||
<button class="logout-confirm-btn" id="confirmLogoutBtn">Yes, Logout</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
// Theme management
|
|
||||||
function setTheme(theme) {
|
|
||||||
document.documentElement.setAttribute('data-theme', theme);
|
|
||||||
localStorage.setItem('theme', theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSystemTheme() {
|
|
||||||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize theme
|
|
||||||
const savedTheme = getSystemTheme();
|
|
||||||
setTheme(savedTheme);
|
|
||||||
|
|
||||||
// API base URL
|
|
||||||
const API_BASE = '/api/v1/client';
|
|
||||||
|
|
||||||
// Auth token management
|
|
||||||
function getAuthToken() {
|
|
||||||
return localStorage.getItem('knoptpq');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchWithAuth(url, options = {}) {
|
|
||||||
const token = getAuthToken();
|
|
||||||
if (!token) {
|
|
||||||
window.location.href = '/';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(url, {
|
|
||||||
...options,
|
|
||||||
headers: {
|
|
||||||
'token': `${token}`,
|
|
||||||
'type': 'client',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'ngrok-skip-browser-warning': 69420,
|
|
||||||
...options.headers,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status === 401) {
|
|
||||||
localStorage.removeItem('knoptpq');
|
|
||||||
localStorage.removeItem('refreshToken');
|
|
||||||
window.location.href = '/';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleLogout() {
|
|
||||||
try {
|
|
||||||
// Call logout API
|
|
||||||
await fetchWithAuth(`${API_BASE}/logout`, {
|
|
||||||
method: 'POST'
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Logout API error:', error);
|
|
||||||
} finally {
|
|
||||||
// Clear local storage and redirect
|
|
||||||
localStorage.removeItem('knoptpq');
|
|
||||||
localStorage.removeItem('refreshToken');
|
|
||||||
window.location.href = '/';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logout Modal Functions
|
|
||||||
function openLogoutModal() {
|
|
||||||
const modal = document.getElementById('logoutModal');
|
|
||||||
modal.style.display = 'flex';
|
|
||||||
document.body.style.overflow = 'hidden';
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeLogoutModal() {
|
|
||||||
const modal = document.getElementById('logoutModal');
|
|
||||||
modal.style.display = 'none';
|
|
||||||
document.body.style.overflow = 'auto';
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
|
||||||
|
|
||||||
// Mobile menu toggle
|
|
||||||
const menuToggle = document.querySelector('.mobile-menu-button');
|
|
||||||
const sidebar = document.querySelector('.dashboard-sidebar');
|
|
||||||
menuToggle.addEventListener('click', () => {
|
|
||||||
sidebar.classList.toggle('active');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Close modal with escape key
|
|
||||||
document.addEventListener('keydown', function (e) {
|
|
||||||
if (e.key === 'Escape') {
|
|
||||||
closeLogoutModal();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('logoutModal').addEventListener('click', function (e) {
|
|
||||||
if (e.target === this) {
|
|
||||||
closeLogoutModal();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Logout button - opens confirmation modal instead of directly logging out
|
|
||||||
document.getElementById('logoutButton').addEventListener('click', openLogoutModal);
|
|
||||||
|
|
||||||
// Confirm logout button
|
|
||||||
document.getElementById('confirmLogoutBtn').addEventListener('click', handleLogout);
|
|
||||||
});
|
|
||||||
|
|
||||||
// ------------------------------
|
|
||||||
// TIP FORM SUBMISSION HANDLER
|
|
||||||
// ------------------------------
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
|
||||||
// Load VAs for tip selection
|
|
||||||
async function loadVAsLogs() {
|
|
||||||
try {
|
|
||||||
let vaId = new URLSearchParams(window.location.search).get('va');
|
|
||||||
const response = await fetchWithAuth(`${API_BASE}/vaLogsData${vaId ? `/${vaId}` : ''}`);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
console.error("Failed to load VAs:", data.message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
console.log("VA Logs Data:", data);
|
|
||||||
|
|
||||||
// const vaSelect = document.getElementById('vaTipTableBody');
|
|
||||||
// data.data.forEach(tip => {
|
|
||||||
// const row = document.createElement('tr');
|
|
||||||
// const cellVoid = document.createElement('td');
|
|
||||||
// const cellStatus = document.createElement('td');
|
|
||||||
// const cellName = document.createElement('td');
|
|
||||||
// const cellDescription = document.createElement('td');
|
|
||||||
// const cellDate = document.createElement('td');
|
|
||||||
// const cellAmount = document.createElement('td');
|
|
||||||
|
|
||||||
// cellVoid.innerHTML = `<button id='voidBtn' class='void-btn-a' data-id='${tip._id}'>Void</button>`;
|
|
||||||
// cellVoid.classList.add('void-btn');
|
|
||||||
|
|
||||||
// cellStatus.textContent = tip.status;
|
|
||||||
// cellName.textContent = tip.vaName;
|
|
||||||
// cellDescription.textContent = tip.description;
|
|
||||||
// cellDate.textContent = tip.createdAt ? new Date(tip.createdAt).toLocaleDateString() : '';
|
|
||||||
// cellAmount.textContent = `$${parseFloat(tip.amount).toFixed(2)}`;
|
|
||||||
|
|
||||||
// row.appendChild(cellVoid);
|
|
||||||
// row.appendChild(cellStatus);
|
|
||||||
// row.appendChild(cellName);
|
|
||||||
// row.appendChild(cellDescription);
|
|
||||||
// row.appendChild(cellDate);
|
|
||||||
// row.appendChild(cellAmount);
|
|
||||||
|
|
||||||
// vaSelect.appendChild(row);
|
|
||||||
// });
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error loading VAs:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadVAsLogs();
|
|
||||||
|
|
||||||
setInterval(loadVAsLogs, 30000);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
|
|
@ -448,7 +448,7 @@
|
||||||
const activeProject = va?.lastProject?.name ? va.lastProject.name : '-';
|
const activeProject = va?.lastProject?.name ? va.lastProject.name : '-';
|
||||||
const workedTime = formatTime(va.currentSessionDuration);
|
const workedTime = formatTime(va.currentSessionDuration);
|
||||||
const projectsAssigned = va.projectsAssigned || 0;
|
const projectsAssigned = va.projectsAssigned || 0;
|
||||||
const viewLink = va.isCurrentlyActive ? `<a href="/live/${va.lastProjectId}/${va.id}" class="view-link va-action" data-va-id="${va.id}" target="_blank">Live</a>` : `<a class="va-logs va-action" data-va-id="${va.id}" target="_blank" href="/client/virtual-assistants/view-logs?va=${va.id}">Logs</a>`;
|
const viewLink = va.isCurrentlyActive ? `<a href="/live/${va.lastProjectId}/${va.id}" class="view-link va-action" data-va-id="${va.id}" target="_blank">Live Tracking</a>` : '<p class="va-logs va-action" data-va-id="${va.id}" target="_blank">Logs</p>';
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<tr class="va-row" data-va-id="${va.id}">
|
<tr class="va-row" data-va-id="${va.id}">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue