Compare commits
17 Commits
9429caacd6
...
db51e213f1
| Author | SHA1 | Date |
|---|---|---|
|
|
db51e213f1 | |
|
|
d49ba5a8b1 | |
|
|
e1fc8d9d13 | |
|
|
e9a2ace3db | |
|
|
36bdc24b54 | |
|
|
acb1061de5 | |
|
|
e9ff5ec612 | |
|
|
8254fab09a | |
|
|
b2fee65156 | |
|
|
7e7a6423b1 | |
|
|
682393a82c | |
|
|
7fe3836f73 | |
|
|
ea574004ce | |
|
|
79eff1a6e3 | |
|
|
6358564131 | |
|
|
47f8d96a02 | |
|
|
5bfc6b8bd5 |
Binary file not shown.
|
After Width: | Height: | Size: 504 B |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 27 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 782 B |
Binary file not shown.
|
After Width: | Height: | Size: 255 B |
|
|
@ -50,7 +50,8 @@ async function va_register(req, res) {
|
||||||
// Send data to Salesforce API after successful registration
|
// Send data to Salesforce API after successful registration
|
||||||
try {
|
try {
|
||||||
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/virtualassistant`;
|
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/virtualassistant`;
|
||||||
|
delete created.userDetails._id;
|
||||||
|
created.userDetails._id = created._id; // Include VA's MongoDB ID
|
||||||
const response = await fetch(salesforceUrl, {
|
const response = await fetch(salesforceUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ const projectSchema = new Schema({
|
||||||
],
|
],
|
||||||
dedicatedHours: {
|
dedicatedHours: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 0
|
default: "0"
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|
@ -166,6 +166,7 @@ const clientDetailsSchema = new Schema({
|
||||||
enum: ["CHECKING", "SAVINGS"],
|
enum: ["CHECKING", "SAVINGS"],
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
accountHolderName: {
|
accountHolderName: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
|
@ -332,7 +333,7 @@ const vaWorkTrackSchema = new Schema({
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
const passwordResetSchema = new mongoose.Schema({
|
const passwordResetSchema = new mongoose.Schema({
|
||||||
|
|
|
||||||
169
src/server.js
169
src/server.js
|
|
@ -13,16 +13,32 @@ import cors from 'cors';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
|
||||||
import apiRoutes from './routes/index.js'
|
import apiRoutes from './routes/index.js'
|
||||||
|
|
||||||
|
|
||||||
import { render_reset_form } from "./controllers/passwordReset.controllers.js";
|
import { render_reset_form } from "./controllers/passwordReset.controllers.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
|
||||||
const server = new createServer(app);
|
const server = new createServer(app);
|
||||||
const io = new Server(server);
|
const io = new Server(server);
|
||||||
|
|
||||||
|
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
|
||||||
|
console.log("⚠️ Certificate error:", url);
|
||||||
|
|
||||||
|
// Allow for ngrok only
|
||||||
|
if (url.includes("ngrok")) {
|
||||||
|
event.preventDefault();
|
||||||
|
callback(true); // approve the certificate
|
||||||
|
} else {
|
||||||
|
callback(false); // reject others
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
|
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
|
||||||
console.log("⚠️ Certificate error:", url);
|
console.log("⚠️ Certificate error:", url);
|
||||||
|
|
||||||
|
|
@ -93,13 +109,18 @@ app.get('/varegister/:sf_token?', (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/clientregister/:sf_token?', (req, res) => {
|
app.get('/clientregister/:sf_token?', (req, res) => {
|
||||||
|
const { sf_token } = req.params;
|
||||||
|
try {
|
||||||
|
const decoded = jwt.verify(sf_token, process.env.JWT_SECRET_SF_TOKEN);
|
||||||
|
|
||||||
// portalId: RECORDid => 8990928342309
|
if (decoded) {
|
||||||
// email
|
res.render('va_client_register', { title: "Client Registration" });
|
||||||
|
} else {
|
||||||
// const { sf_token } = useParams();
|
res.render('not_found', { title: "Client Registration" });
|
||||||
|
}
|
||||||
res.render('va_client_register', { title: "Client Registration" });
|
} catch (error) {
|
||||||
|
res.render('not_found', { title: "Client Registration" });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/auth/password/reset-form', render_reset_form);
|
app.get('/auth/password/reset-form', render_reset_form);
|
||||||
|
|
@ -138,35 +159,28 @@ app.get('/client/virtual-assistants', async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// app.get('/client/timesheets', async (req, res) => {
|
app.get("/live/:projectId/:vaId", async (req, res) => {
|
||||||
// try {
|
const { projectId, vaId } = req.params;
|
||||||
// const timesheetData = await timesheetService.getClientTimesheets(req.user.id);
|
|
||||||
// res.render('client/dashboard-timesheets', timesheetData);
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error('Timesheets error:', error);
|
|
||||||
// res.status(500).render('client/dashboard-timesheets', { error: 'Failed to load timesheets' });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// app.get('/client/invoices', async (req, res) => {
|
if (!projectId || !vaId) {
|
||||||
// try {
|
return res.status(400).send({ "message": "Page not found" });
|
||||||
// const invoiceData = await invoiceService.getClientInvoices(req.user.id);
|
}
|
||||||
// res.render('client/dashboard-invoices', invoiceData);
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error('Invoices error:', error);
|
|
||||||
// res.status(500).render('client/dashboard-invoices', { error: 'Failed to load invoices' });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// app.get('/client/referrals', async (req, res) => {
|
let clientId = null;
|
||||||
// try {
|
try {
|
||||||
// const referralData = await referralService.getClientReferrals(req.user.id);
|
const clientRes = await ProjectModel.findById(projectId);
|
||||||
// res.render('client/dashboard-referrals', referralData);
|
if (clientRes) {
|
||||||
// } catch (error) {
|
clientId = clientRes.clientId.toString();
|
||||||
// console.error('Referrals error:', error);
|
}
|
||||||
// res.status(500).render('client/dashboard-referrals', { error: 'Failed to load referrals' });
|
} catch (err) {
|
||||||
// }
|
console.error("Error fetching client for project:", err.message);
|
||||||
// });
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!clientId) return res.status(400).send({ "message": "Page not found" });
|
||||||
|
|
||||||
|
res.render("va_live_tracker", { title: "VA Live Tracker", projectId, vaId, clientId })
|
||||||
|
})
|
||||||
|
|
||||||
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;
|
||||||
|
|
@ -193,16 +207,17 @@ app.get("/live/:projectId/:vaId", async (req, res) => {
|
||||||
|
|
||||||
// Handling Socket
|
// Handling Socket
|
||||||
import { VAModel, ProjectModel, ClientModel } from './models/vaModel.js';
|
import { VAModel, ProjectModel, ClientModel } from './models/vaModel.js';
|
||||||
import { ObjectId } from 'mongodb/lib/bson.js';
|
|
||||||
|
|
||||||
|
|
||||||
const vaSocketRespectToClient = new Map();
|
const vaSocketRespectToClient = new Map();
|
||||||
|
|
||||||
|
// Handling Socket
|
||||||
io.use(async (socket, next) => {
|
io.use(async (socket, next) => {
|
||||||
try {
|
try {
|
||||||
const token = socket.handshake.auth?.token;
|
const token = socket.handshake.auth?.token;
|
||||||
const projectId = socket.handshake.auth?.projectId;
|
const projectId = socket.handshake.auth?.projectId;
|
||||||
const userType = socket.handshake.auth?.userType;
|
const userType = socket.handshake.auth?.userType;
|
||||||
|
const vaId = socket.handshake.auth?.vaId;
|
||||||
|
|
||||||
|
|
||||||
console.log("🔐 Received token:", token);
|
console.log("🔐 Received token:", token);
|
||||||
|
|
||||||
|
|
@ -216,7 +231,7 @@ io.use(async (socket, next) => {
|
||||||
return next(new Error("Invalid token payload"));
|
return next(new Error("Invalid token payload"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------- 1️⃣ Check if VA ---------------------- */
|
/* ---------------------- 1️⃣ Check if VA ---------------------- */
|
||||||
let vaUser = null;
|
let vaUser = null;
|
||||||
let clientData = null;
|
let clientData = null;
|
||||||
|
|
||||||
|
|
@ -241,13 +256,13 @@ io.use(async (socket, next) => {
|
||||||
|
|
||||||
console.log(a, b, c, "vaProjClientId vs clientData.clientId");
|
console.log(a, b, c, "vaProjClientId vs clientData.clientId");
|
||||||
|
|
||||||
vaSocketRespectToClient.set(`${vaProjClientId.toString()}-${vaUser._id.toString()}`, socket.id)
|
vaSocketRespectToClient.set(`${vaProjClientId.toString()}-${vaUser._id.toString()}-${projectId.toString()}-va`, socket.id)
|
||||||
|
|
||||||
console.log("✅ Authenticated VA:", vaUser.userDetails.email);
|
console.log("✅ Authenticated VA:", vaUser.userDetails.email);
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------- 2️⃣ Check if Client ---------------------- */
|
/* ---------------------- 2️⃣ Check if Client ---------------------- */
|
||||||
// const clientUser = await ClientModel.findOne({ "userDetails.email": decoded.email });
|
// const clientUser = await ClientModel.findOne({ "userDetails.email": decoded.email });
|
||||||
|
|
||||||
// if (clientUser) {
|
// if (clientUser) {
|
||||||
|
|
@ -268,6 +283,7 @@ io.use(async (socket, next) => {
|
||||||
|
|
||||||
// Get all VA IDs assigned to this client
|
// Get all VA IDs assigned to this client
|
||||||
socket.data.allowedVAs = clientData.vaAssigned.map((va) => va.toString());
|
socket.data.allowedVAs = clientData.vaAssigned.map((va) => va.toString());
|
||||||
|
vaSocketRespectToClient.set(`${vaProjClientId.toString()}-${vaId.toString()}-${projectId.toString()}-client`, socket.id)
|
||||||
|
|
||||||
// console.log("✅ Authenticated Client:", clientUser.userDetails.email);
|
// console.log("✅ Authenticated Client:", clientUser.userDetails.email);
|
||||||
return next();
|
return next();
|
||||||
|
|
@ -280,8 +296,6 @@ io.use(async (socket, next) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
io.on("connection", (socket) => {
|
io.on("connection", (socket) => {
|
||||||
console.log("User connected:", socket.id);
|
console.log("User connected:", socket.id);
|
||||||
|
|
||||||
|
|
@ -316,7 +330,7 @@ io.on("connection", (socket) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// When VA sends live image
|
// When VA sends live image
|
||||||
socket.on("sendImage", async ({ token, image, title }) => {
|
socket.on("sendImage", async ({ token, image, title, projectId }) => {
|
||||||
try {
|
try {
|
||||||
// Verify token
|
// Verify token
|
||||||
const decoded = jwt.verify(token, process.env.JWT_SECRET_ACCESS_TOKEN);
|
const decoded = jwt.verify(token, process.env.JWT_SECRET_ACCESS_TOKEN);
|
||||||
|
|
@ -329,30 +343,42 @@ io.on("connection", (socket) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const project = await ProjectModel.findById(projectId);
|
||||||
|
if (!project) {
|
||||||
|
console.log("❌ Invalid Project ID");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientId = project.clientId.toString();
|
||||||
const vaId = vaUser._id.toString();
|
const vaId = vaUser._id.toString();
|
||||||
|
const clientVaUniqueId = `${clientId}-${vaId}-${projectId}-client`;
|
||||||
|
const socketId = vaSocketRespectToClient.get(clientVaUniqueId);
|
||||||
|
|
||||||
console.log("🟢 Received image from VA:", vaId);
|
console.log("🟢 Received image from VA:", vaId);
|
||||||
|
|
||||||
// Broadcast image only to allowed clients
|
// Broadcast image only to allowed clients
|
||||||
for (let [_, clientSocket] of io.sockets.sockets) {
|
// for (let [_, clientSocket] of io.sockets.sockets) {
|
||||||
if (
|
// if (
|
||||||
clientSocket.data.role === "client" &&
|
// clientSocket.data.role === "client" &&
|
||||||
clientSocket.data.allowedVAs?.includes(vaId)
|
// clientSocket.data.allowedVAs?.includes(vaId)
|
||||||
) {
|
// ) {
|
||||||
clientSocket.emit("receiveImage", image, title);
|
// clientSocket.emit("receiveImage", image, title);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// Can be like clientId-projectId-vaId to uniquely identify
|
||||||
|
socket.to(socketId).emit("receiveImage", image, title);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("❌ Token verification failed:", err.message);
|
console.error("❌ Token verification failed:", err.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("selectApp", ({ appTitle, clientId }) => {
|
socket.on("selectApp", ({ appTitle, clientId, vaId, projectId }) => {
|
||||||
console.log(`VA selected app: ${appTitle}`);
|
console.log(`VA selected app: ${appTitle}`);
|
||||||
|
|
||||||
const sssrrrr = vaSocketRespectToClient.get(`${clientId}-${socket.data.vaId}`);
|
console.log(vaSocketRespectToClient.get(`${clientId}-${vaId}-${projectId}-va`), "vaSocketRespectToClient[clientId]")
|
||||||
console.log(vaSocketRespectToClient.get(`${clientId}-${socket.data.vaId}`), sssrrrr, "vaSocketRespectToClient[clientId]")
|
|
||||||
// You can forward this info to the respective Electron client
|
// You can forward this info to the respective Electron client
|
||||||
socket.to(vaSocketRespectToClient.get(`${clientId}-${socket.data.vaId}`)).emit("appToCapture", { appTitle });
|
socket.to(vaSocketRespectToClient.get(`${clientId}-${vaId}-${projectId}-va`)).emit("appToCapture", { appTitle });
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("getVisibleApps", async ({ token, apps }) => {
|
socket.on("getVisibleApps", async ({ token, apps }) => {
|
||||||
|
|
@ -377,7 +403,7 @@ io.on("connection", (socket) => {
|
||||||
clientSocket.data.role === "client" &&
|
clientSocket.data.role === "client" &&
|
||||||
clientSocket.data.allowedVAs?.includes(vaId)
|
clientSocket.data.allowedVAs?.includes(vaId)
|
||||||
) {
|
) {
|
||||||
clientSocket.emit("receiveVisibleApps", apps);
|
clientSocket.emit("receiveVisibleApps", { apps, vaId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -391,39 +417,10 @@ io.on("connection", (socket) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// io.on('connection', (socket) => {
|
|
||||||
|
|
||||||
// socket.on("sendImage", (base64String) => {
|
|
||||||
// io.emit("receiveImage", base64String);
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
// socket.on('disconnect', () => {
|
|
||||||
// console.log('a user Disconnected');
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
// Express App Listening
|
|
||||||
// app.listen(PORT, () => {
|
|
||||||
// mongoose
|
|
||||||
// .connect(
|
|
||||||
// process.env.MONGO_URI,
|
|
||||||
// )
|
|
||||||
// .then(() => console.log("mongodb connected"))
|
|
||||||
// .catch((err) => {
|
|
||||||
// console.log(err.message);
|
|
||||||
// process.exit(1);
|
|
||||||
// });
|
|
||||||
// console.log(`Express started on http://localhost:${PORT}`);
|
|
||||||
// });
|
|
||||||
|
|
||||||
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"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,35 @@ async function testPaths() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testPaths();
|
testPaths();// testVpnApi.js
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
const apiUrl = "http://165.140.240.203:3000/api";
|
||||||
|
const apiKey = "hellovpn123";
|
||||||
|
|
||||||
|
const possiblePaths = [
|
||||||
|
"/", "/v1", "/servers", "/status", "/vpn", "/health", "/ping",
|
||||||
|
"/nodes", "/list", "/connect", "/config", "/create", "/createConfig",
|
||||||
|
"/check", "/organizations", "/users"
|
||||||
|
];
|
||||||
|
|
||||||
|
async function testPaths() {
|
||||||
|
for (const path of possiblePaths) {
|
||||||
|
try {
|
||||||
|
const res = await axios.get(`${apiUrl}${path}`, {
|
||||||
|
headers: { "x-api-key": apiKey },
|
||||||
|
timeout: 3000
|
||||||
|
});
|
||||||
|
console.log(`✅ ${path} → ${res.status} ${res.statusText}`);
|
||||||
|
console.log("Response:", res.data);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.response) {
|
||||||
|
console.log(`❌ ${path} → ${err.response.status}`);
|
||||||
|
} else {
|
||||||
|
console.log(`⚠️ ${path} → No response`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testPaths();
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -148,8 +148,7 @@
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th>Virtual Assistant</th>
|
<th>Virtual Assistant</th>
|
||||||
<th>Projects Assigned</th>
|
<th>Projects Assigned</th>
|
||||||
<th>Working from</th>
|
<th>Worked Time</th>
|
||||||
<th>Total Worked</th>
|
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
@ -222,7 +221,7 @@
|
||||||
|
|
||||||
// Format time function
|
// Format time function
|
||||||
function formatTime(seconds) {
|
function formatTime(seconds) {
|
||||||
if (!seconds) return '';
|
if (!seconds) return 'Not working';
|
||||||
|
|
||||||
const hours = Math.floor(seconds / 3600);
|
const hours = Math.floor(seconds / 3600);
|
||||||
const minutes = Math.floor((seconds % 3600) / 60);
|
const minutes = Math.floor((seconds % 3600) / 60);
|
||||||
|
|
@ -231,8 +230,6 @@
|
||||||
return `${hours}h ${minutes}m`;
|
return `${hours}h ${minutes}m`;
|
||||||
} else if (minutes > 0) {
|
} else if (minutes > 0) {
|
||||||
return `${minutes}m`;
|
return `${minutes}m`;
|
||||||
} else if (seconds > 0) {
|
|
||||||
return `${seconds}s`;
|
|
||||||
} else {
|
} else {
|
||||||
return 'Just started';
|
return 'Just started';
|
||||||
}
|
}
|
||||||
|
|
@ -243,7 +240,6 @@
|
||||||
const statusClass = va.isCurrentlyActive ? 'active' : 'inactive';
|
const statusClass = va.isCurrentlyActive ? 'active' : 'inactive';
|
||||||
const statusText = va.isCurrentlyActive ? 'Active' : 'Inactive';
|
const statusText = va.isCurrentlyActive ? 'Active' : 'Inactive';
|
||||||
const workedTime = formatTime(va.currentSessionDuration);
|
const workedTime = formatTime(va.currentSessionDuration);
|
||||||
const totalWorkedTime = formatTime(va.totalWorkedSeconds);
|
|
||||||
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">
|
const viewLink = va.isCurrentlyActive ? `<a href="/live/${va.lastProjectId}/${va.id}" class="view-link" data-va-id="${va.id}" target="_blank">
|
||||||
<i class="fas fa-eye"></i>
|
<i class="fas fa-eye"></i>
|
||||||
|
|
@ -251,7 +247,7 @@
|
||||||
</a>` : '';
|
</a>` : '';
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<tr data-vaid="${va.id}">
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div class="status-indicator">
|
<div class="status-indicator">
|
||||||
<div class="status-dot ${statusClass}"></div>
|
<div class="status-dot ${statusClass}"></div>
|
||||||
|
|
@ -260,7 +256,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="va-info">
|
<div class="va-info">
|
||||||
<div class="va-name">${va.name}</div>
|
<div class="va-name">${va.firstName} ${va.lastName}</div>
|
||||||
<div class="va-email">${va.email || 'N/A'}</div>
|
<div class="va-email">${va.email || 'N/A'}</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
@ -270,9 +266,6 @@
|
||||||
<td>
|
<td>
|
||||||
<span class="worked-time">${workedTime}</span>
|
<span class="worked-time">${workedTime}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
<span class="worked-time">${totalWorkedTime}</span>
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
${viewLink}
|
${viewLink}
|
||||||
</td>
|
</td>
|
||||||
|
|
@ -309,35 +302,16 @@
|
||||||
vaTableBody.innerHTML = allVAs.map(va => createVATableRow(va)).join('');
|
vaTableBody.innerHTML = allVAs.map(va => createVATableRow(va)).join('');
|
||||||
vaTableBody.style.display = '';
|
vaTableBody.style.display = '';
|
||||||
vaEmptyState.style.display = 'none';
|
vaEmptyState.style.display = 'none';
|
||||||
|
|
||||||
// Add event listeners to table rows
|
// Add event listeners to view links
|
||||||
document.querySelectorAll('tr[data-vaid]').forEach(row => {
|
document.querySelectorAll('.view-link').forEach(link => {
|
||||||
row.addEventListener('click', async function(e) {
|
link.addEventListener('click', function(e) {
|
||||||
// Don't trigger if click is on view link
|
e.preventDefault();
|
||||||
if (e.target.closest('.view-link')) {
|
const vaId = this.getAttribute('data-va-id');
|
||||||
return;
|
// You can update this link as needed
|
||||||
}
|
window.location.href = `/client/virtual-assistants/${vaId}`;
|
||||||
|
|
||||||
const vaId = this.getAttribute('data-vaid');
|
|
||||||
const vaData = allVAs.find(va => va.id === vaId);
|
|
||||||
|
|
||||||
if (vaData) {
|
|
||||||
// Show loading state
|
|
||||||
const originalContent = this.innerHTML;
|
|
||||||
this.innerHTML = '<td colspan="6" style="text-align: center;"><i class="fas fa-spinner fa-spin"></i> Loading...</td>';
|
|
||||||
|
|
||||||
// Fetch additional VA details from /test API
|
|
||||||
const projectData = await fetchVADetails(vaId);
|
|
||||||
|
|
||||||
// Restore original content
|
|
||||||
this.innerHTML = originalContent;
|
|
||||||
|
|
||||||
// Show popup with VA details
|
|
||||||
showVAPopup(projectData);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
vaTableBody.innerHTML = '';
|
vaTableBody.innerHTML = '';
|
||||||
vaTableBody.style.display = 'none';
|
vaTableBody.style.display = 'none';
|
||||||
|
|
@ -376,128 +350,7 @@
|
||||||
|
|
||||||
// Optional: Auto-refresh data every 30 seconds
|
// Optional: Auto-refresh data every 30 seconds
|
||||||
setInterval(loadDashboardData, 30000);
|
setInterval(loadDashboardData, 30000);
|
||||||
|
|
||||||
function createPopup(vaData) {
|
|
||||||
// Extract project details from the API response
|
|
||||||
// The API response is the project array, so use it directly
|
|
||||||
const projectDetails = Array.isArray(vaData) ? vaData : (vaData.projects || []);
|
|
||||||
|
|
||||||
// Create project details HTML
|
|
||||||
const projectsHTML = projectDetails.length > 0
|
|
||||||
? projectDetails.map(project => `
|
|
||||||
<div class="project-item">
|
|
||||||
<div class="project-header">
|
|
||||||
<span class="project-name">${project.projectName || 'Unknown Project'}</span>
|
|
||||||
<span class="project-time">${project.totalTime || '00:00:00'}</span>
|
|
||||||
</div>
|
|
||||||
<div class="project-id">ID: ${project.projectId || 'N/A'}</div>
|
|
||||||
</div>
|
|
||||||
`).join('')
|
|
||||||
: '<div class="no-projects">No project data available</div>';
|
|
||||||
|
|
||||||
return `
|
|
||||||
<div class="popup-overlay" id="vaPopup">
|
|
||||||
<div class="popup-content">
|
|
||||||
<div class="popup-header">
|
|
||||||
<h3>Project Work Details</h3>
|
|
||||||
<button class="popup-close" id="closePopup">
|
|
||||||
<i class="fas fa-times"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="popup-body">
|
|
||||||
<!-- Project Count -->
|
|
||||||
<div class="project-summary">
|
|
||||||
<div class="total-projects">
|
|
||||||
<i class="fas fa-folder-open"></i>
|
|
||||||
<span>Total Projects: ${projectDetails.length}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Project Details List -->
|
|
||||||
<div class="projects-list">
|
|
||||||
${projectsHTML}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="popup-footer">
|
|
||||||
<button class="btn btn-secondary" id="closePopupBtn">
|
|
||||||
<i class="fas fa-times"></i> Close
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show popup with VA details
|
|
||||||
function showVAPopup(projectData) {
|
|
||||||
console.log('Project Data:', projectData);
|
|
||||||
|
|
||||||
// Remove existing popup if any
|
|
||||||
const existingPopup = document.getElementById('vaPopup');
|
|
||||||
if (existingPopup) {
|
|
||||||
existingPopup.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and show new popup with only project data
|
|
||||||
const popupHTML = createPopup(projectData);
|
|
||||||
document.body.insertAdjacentHTML('beforeend', popupHTML);
|
|
||||||
|
|
||||||
// Add event listeners for closing popup
|
|
||||||
document.getElementById('closePopup').addEventListener('click', closePopup);
|
|
||||||
document.getElementById('closePopupBtn').addEventListener('click', closePopup);
|
|
||||||
|
|
||||||
// Close popup when clicking outside
|
|
||||||
document.getElementById('vaPopup').addEventListener('click', function(e) {
|
|
||||||
if (e.target === this) {
|
|
||||||
closePopup();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Close popup with Escape key
|
|
||||||
document.addEventListener('keydown', function(e) {
|
|
||||||
if (e.key === 'Escape') {
|
|
||||||
closePopup();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch VA details for popup - now returns only project data
|
|
||||||
async function fetchVADetails(vaId) {
|
|
||||||
try {
|
|
||||||
const response = await fetchWithAuth(`${API_BASE}/dashboard/va-report`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify({ vaId: vaId }),
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response) return;
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
console.log('API Response:', result);
|
|
||||||
|
|
||||||
if (result.success) {
|
|
||||||
// Return the projects array directly
|
|
||||||
return result.projects || [];
|
|
||||||
} else {
|
|
||||||
console.error('Failed to fetch project details:', result.message);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching project details:', error);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close popup function
|
|
||||||
function closePopup() {
|
|
||||||
const popup = document.getElementById('vaPopup');
|
|
||||||
if (popup) {
|
|
||||||
popup.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,7 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<img src="/public/images/logo-white-vertical.svg" alt="DocVA Logo" />
|
<img src="/public/images/logo-white-vertical.svg" alt="DocVA Logo" />
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -246,7 +247,7 @@
|
||||||
|
|
||||||
setTheme(getSystemTheme());
|
setTheme(getSystemTheme());
|
||||||
checkAuthentication();
|
checkAuthentication();
|
||||||
|
|
||||||
document.querySelector("form").addEventListener("submit", async (e) => {
|
document.querySelector("form").addEventListener("submit", async (e) => {
|
||||||
e.preventDefault(); // prevent page reload
|
e.preventDefault(); // prevent page reload
|
||||||
|
|
||||||
|
|
@ -291,11 +292,11 @@
|
||||||
alert(err.message || "Something went wrong while logging in");
|
alert(err.message || "Something went wrong while logging in");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if user is already authenticated and redirect to dashboard
|
// Check if user is already authenticated and redirect to dashboard
|
||||||
async function checkAuthentication() {
|
async function checkAuthentication() {
|
||||||
const authToken = localStorage.getItem("knoptpq");
|
const authToken = localStorage.getItem("knoptpq");
|
||||||
|
|
||||||
if (!authToken) {
|
if (!authToken) {
|
||||||
return false; // No token found
|
return false; // No token found
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -332,6 +333,4 @@
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
|
||||||
|
|
@ -192,4 +192,4 @@
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* SIDEBAR */
|
||||||
.sidebar {
|
.sidebar {
|
||||||
width: 280px;
|
width: 280px;
|
||||||
background: #181818;
|
background: #181818;
|
||||||
|
|
@ -81,7 +82,6 @@
|
||||||
#liveImage {
|
#liveImage {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
max-width: 900px;
|
max-width: 900px;
|
||||||
border: 2px solid #555;
|
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
border: 2px solid #444;
|
border: 2px solid #444;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
|
|
@ -185,49 +185,54 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/socket.io/socket.io.js"></script>
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const vaId = "<%= vaId %>";
|
const vaId = "<%= vaId %>";
|
||||||
const clientId = "<%= clientId %>";
|
const clientId = "<%= clientId %>";
|
||||||
const token = localStorage.getItem("knoptpq");
|
const projectId = "<%= projectId %>";
|
||||||
const socket = io({
|
const token = localStorage.getItem("knoptpq");
|
||||||
auth: {
|
|
||||||
token: token,
|
|
||||||
userType: "client",
|
|
||||||
projectId: "<%= projectId %>"
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.emit("register", {
|
const socket = io({
|
||||||
role: "client",
|
auth: {
|
||||||
id: vaId,
|
token: token,
|
||||||
projectId: "<%= projectId %>",
|
userType: "client",
|
||||||
clientId: clientId
|
projectId: projectId,
|
||||||
});
|
vaId: vaId
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const sidebar = document.getElementById("sidebar");
|
socket.emit("register", {
|
||||||
const toggleBtn = document.getElementById("toggleBtn");
|
role: "client",
|
||||||
const overlay = document.getElementById("overlay");
|
id: vaId,
|
||||||
|
projectId: "<%= projectId %>",
|
||||||
|
clientId: clientId
|
||||||
|
});
|
||||||
|
|
||||||
const appsList = document.getElementById("appsList");
|
const sidebar = document.getElementById("sidebar");
|
||||||
const liveImage = document.getElementById("liveImage");
|
const toggleBtn = document.getElementById("toggleBtn");
|
||||||
const selectedAppTitle = document.getElementById("selectedAppTitle");
|
const overlay = document.getElementById("overlay");
|
||||||
const placeholder = document.getElementById("placeholder");
|
|
||||||
|
|
||||||
let currentApp = null;
|
const appsList = document.getElementById("appsList");
|
||||||
|
const liveImage = document.getElementById("liveImage");
|
||||||
|
const selectedAppTitle = document.getElementById("selectedAppTitle");
|
||||||
|
const placeholder = document.getElementById("placeholder");
|
||||||
|
|
||||||
/* MOBILE SIDEBAR TOGGLE */
|
let currentApp = null;
|
||||||
toggleBtn.onclick = () => {
|
|
||||||
sidebar.classList.add("open");
|
|
||||||
overlay.classList.add("show");
|
|
||||||
};
|
|
||||||
|
|
||||||
overlay.onclick = () => {
|
/* MOBILE SIDEBAR TOGGLE */
|
||||||
|
toggleBtn.onclick = () => {
|
||||||
|
sidebar.classList.add("open");
|
||||||
|
overlay.classList.add("show");
|
||||||
|
};
|
||||||
|
|
||||||
|
overlay.onclick = () => {
|
||||||
sidebar.classList.remove("open");
|
sidebar.classList.remove("open");
|
||||||
overlay.classList.remove("show");
|
overlay.classList.remove("show");
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Receive visible apps */
|
/* Receive visible apps */
|
||||||
socket.on("receiveVisibleApps", (apps) => {
|
socket.on("receiveVisibleApps", ({apps, vaId: senderVaId}) => {
|
||||||
|
if (vaId !== senderVaId) return;
|
||||||
|
|
||||||
appsList.innerHTML = "";
|
appsList.innerHTML = "";
|
||||||
|
|
||||||
if (!apps?.length) {
|
if (!apps?.length) {
|
||||||
|
|
@ -250,7 +255,7 @@
|
||||||
placeholder.style.display = "none";
|
placeholder.style.display = "none";
|
||||||
liveImage.style.display = "none";
|
liveImage.style.display = "none";
|
||||||
|
|
||||||
socket.emit("selectApp", { appTitle: app.name, clientId, vaId });
|
socket.emit("selectApp", { appTitle: app.name, clientId, vaId, projectId });
|
||||||
|
|
||||||
// Close sidebar on mobile
|
// Close sidebar on mobile
|
||||||
sidebar.classList.remove("open");
|
sidebar.classList.remove("open");
|
||||||
|
|
@ -276,7 +281,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue