Compare commits
4 Commits
99d60185a9
...
0c14e26937
| Author | SHA1 | Date |
|---|---|---|
|
|
0c14e26937 | |
|
|
221e867a21 | |
|
|
39f415b685 | |
|
|
d4cdc94bbd |
|
|
@ -521,12 +521,12 @@ async function validateStep(step) {
|
|||
}
|
||||
if (!firstName) {
|
||||
isValid = false;
|
||||
showError('First Name is Required', null, step);
|
||||
showError('First Name is Required', 'first-name', step);
|
||||
return isValid;
|
||||
}
|
||||
if (!lastName) {
|
||||
isValid = false;
|
||||
showError('Last Name is Required', null, step);
|
||||
showError('Last Name is Required', 'last-name', step);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
|
@ -545,6 +545,25 @@ async function validateStep(step) {
|
|||
document.getElementById('confirmPassword').classList.remove('field-error');
|
||||
}
|
||||
|
||||
// Validate other required fields
|
||||
const requiredFields = form.querySelectorAll('[required]');
|
||||
requiredFields.forEach(field => {
|
||||
if (field.id !== 'email' && !field.value.trim()) {
|
||||
isValid = false;
|
||||
field.classList.add('field-error');
|
||||
} else if (field.id !== 'email') {
|
||||
field.classList.remove('field-error');
|
||||
}
|
||||
});
|
||||
} else if (step === 2) {
|
||||
const companyName = document.getElementById('company-name').value;
|
||||
|
||||
if (!companyName) {
|
||||
isValid = false;
|
||||
showError('Company Name is Required', 'company-name', step);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
// Validate other required fields
|
||||
const requiredFields = form.querySelectorAll('[required]');
|
||||
requiredFields.forEach(field => {
|
||||
|
|
@ -639,6 +658,7 @@ function saveStepData(step) {
|
|||
formData.userDetails.password = document.getElementById('password').value;
|
||||
break;
|
||||
case 2:
|
||||
formData.userDetails.name = document.getElementById('company-name').value;
|
||||
formData.userDetails.address = document.getElementById('address').value;
|
||||
formData.userDetails.city = document.getElementById('city').value;
|
||||
formData.userDetails.state = document.getElementById('state').value;
|
||||
|
|
@ -882,28 +902,29 @@ async function detectLocation() {
|
|||
await populateStates(countryCode, 'state');
|
||||
await populateStates(countryCode, 'billing-state');
|
||||
|
||||
const stateSelect = document.getElementById('state');
|
||||
const billingStateSelect = document.getElementById('billing-state');
|
||||
// auto populate state if region matches
|
||||
// const stateSelect = document.getElementById('state');
|
||||
// const billingStateSelect = document.getElementById('billing-state');
|
||||
|
||||
if (stateSelect && region) {
|
||||
const matchedState = Array.from(stateSelect.options).find(
|
||||
opt => opt.text.toLowerCase() === region.toLowerCase()
|
||||
);
|
||||
if (matchedState) {
|
||||
stateSelect.value = matchedState.value;
|
||||
stateSelect.dispatchEvent(new Event('change'));
|
||||
}
|
||||
}
|
||||
// if (stateSelect && region) {
|
||||
// const matchedState = Array.from(stateSelect.options).find(
|
||||
// opt => opt.text.toLowerCase() === region.toLowerCase()
|
||||
// );
|
||||
// if (matchedState) {
|
||||
// stateSelect.value = matchedState.value;
|
||||
// stateSelect.dispatchEvent(new Event('change'));
|
||||
// }
|
||||
// }
|
||||
|
||||
if (billingStateSelect && region) {
|
||||
const matchedBillingState = Array.from(billingStateSelect.options).find(
|
||||
opt => opt.text.toLowerCase() === region.toLowerCase()
|
||||
);
|
||||
if (matchedBillingState) {
|
||||
billingStateSelect.value = matchedBillingState.value;
|
||||
billingStateSelect.dispatchEvent(new Event('change'));
|
||||
}
|
||||
}
|
||||
// if (billingStateSelect && region) {
|
||||
// const matchedBillingState = Array.from(billingStateSelect.options).find(
|
||||
// opt => opt.text.toLowerCase() === region.toLowerCase()
|
||||
// );
|
||||
// if (matchedBillingState) {
|
||||
// billingStateSelect.value = matchedBillingState.value;
|
||||
// billingStateSelect.dispatchEvent(new Event('change'));
|
||||
// }
|
||||
// }
|
||||
} catch (error) {
|
||||
console.error('Error detecting location:', error);
|
||||
|
||||
|
|
@ -1092,7 +1113,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
// Handle use business address checkbox
|
||||
document.getElementById('use-business-address').addEventListener('change', function() {
|
||||
if (this.checked) {
|
||||
document.getElementById('billing-name').value = formData.userDetails.firstName || '';
|
||||
document.getElementById('billing-name').value = formData.userDetails.name || '';
|
||||
document.getElementById('billing-address').value = formData.userDetails.address || '';
|
||||
document.getElementById('billing-city').value = formData.userDetails.city || '';
|
||||
document.getElementById('billing-state').value = formData.userDetails.state || '';
|
||||
|
|
@ -1439,6 +1460,93 @@ function preventInvalidLastNameChars(event) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Function to validate company name
|
||||
function validateCompanyName(input) {
|
||||
const errorElement = document.getElementById('company-name-error');
|
||||
const value = input.value;
|
||||
|
||||
// Check various invalid patterns
|
||||
const validationResult = validateCompanyNameContent(value);
|
||||
|
||||
if (!validationResult.isValid && value.trim().length > 0) {
|
||||
errorElement.textContent = validationResult.message;
|
||||
errorElement.style.display = 'block';
|
||||
input.classList.add('field-error');
|
||||
return false;
|
||||
} else {
|
||||
errorElement.style.display = 'none';
|
||||
input.classList.remove('field-error');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function validateCompanyNameContent(companyName) {
|
||||
const trimmed = companyName.trim();
|
||||
|
||||
if (trimmed.length === 0) {
|
||||
return { isValid: false, message: 'Company name is required' };
|
||||
}
|
||||
|
||||
// Check minimum length
|
||||
if (trimmed.length < 2) {
|
||||
return { isValid: false, message: 'Company name must be at least 2 characters' };
|
||||
}
|
||||
|
||||
// Remove whitespace for content analysis
|
||||
const content = trimmed.replace(/\s/g, '');
|
||||
|
||||
// Check if contains only special characters
|
||||
if (/^[^a-zA-Z0-9]+$/.test(content)) {
|
||||
return { isValid: false, message: 'Company name cannot be only special characters' };
|
||||
}
|
||||
|
||||
// Check if contains at least some valid content (letters or numbers)
|
||||
if (!/[a-zA-Z0-9]/.test(content)) {
|
||||
return { isValid: false, message: 'Company name must contain letters or numbers' };
|
||||
}
|
||||
|
||||
// Optional: Check for excessive special characters (more than 50%)
|
||||
const specialCharCount = (content.match(/[^a-zA-Z0-9]/g) || []).length;
|
||||
if (specialCharCount > content.length / 2) {
|
||||
return { isValid: false, message: 'Company name contains too many special characters' };
|
||||
}
|
||||
|
||||
return { isValid: true, message: '' };
|
||||
}
|
||||
|
||||
// Function to prevent invalid character input in real-time
|
||||
function preventInvalidCompanyNameChars(event) {
|
||||
const charCode = event.which ? event.which : event.keyCode;
|
||||
const key = event.key;
|
||||
|
||||
// Allow: letters, numbers, spaces, hyphens, apostrophes, ampersands, periods, commas
|
||||
// Also allow common editing keys
|
||||
if ((charCode >= 65 && charCode <= 90) || // A-Z
|
||||
(charCode >= 97 && charCode <= 122) || // a-z
|
||||
(charCode >= 48 && charCode <= 57) || // 0-9
|
||||
charCode === 32 || // space
|
||||
charCode === 45 || // hyphen
|
||||
charCode === 39 || // apostrophe
|
||||
charCode === 38 || // ampersand (&)
|
||||
charCode === 46 || // period (.)
|
||||
charCode === 44 || // comma (,)
|
||||
charCode === 8 || // backspace
|
||||
charCode === 9 || // tab
|
||||
charCode === 37 || // left arrow
|
||||
charCode === 39 || // right arrow
|
||||
charCode === 16 || // shift
|
||||
charCode === 17 || // ctrl
|
||||
charCode === 18 || // alt
|
||||
charCode === 91 || // cmd (Mac)
|
||||
/^[a-zA-Z0-9\s\-'&.,]$/.test(key)) { // allowed characters
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prevent invalid characters
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Function to validate ZIP code in real-time
|
||||
function validateZipCode(input) {
|
||||
let errorElement;
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ async function va_register_client(req, res) {
|
|||
try {
|
||||
const payload = req.body || {};
|
||||
const { userDetails } = payload;
|
||||
if (!userDetails || !userDetails.email || !userDetails.firstName || !userDetails.lastName || !userDetails.password) {
|
||||
if (!userDetails || !userDetails.email || !userDetails.firstName || !userDetails.lastName || !userDetails.password || !userDetails.name) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "Missing required fields: firstName, lastName, email, and password are required"
|
||||
message: "Missing required fields: firstName, lastName, email, company name and password are required"
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -521,6 +521,24 @@ app.post("/post-test", (req, res) => {
|
|||
return res.status(200).json({ "success": true, "message": "POST request received", "data": req.body })
|
||||
});
|
||||
|
||||
app.get("/tnyk/:sf_token", (req, res) => {
|
||||
const sf_token = req.params.sf_token;
|
||||
console.log("Received token:", sf_token);
|
||||
|
||||
try {
|
||||
const decoded = jwt.verify(sf_token, process.env.JWT_SECRET_SF_TOKEN);
|
||||
if (decoded) {
|
||||
res.render('client/dashboard-dashboard', { sf_token: sf_token });
|
||||
} else {
|
||||
res.render('not_found', { title: "Client" });
|
||||
}
|
||||
} catch (error) {
|
||||
res.render('not_found', { title: "Client" });
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
app.use((req, res) => {
|
||||
res.status(404).render("not_found", {
|
||||
title: "404 - Page Not Found"
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ class SalesforceService {
|
|||
return {
|
||||
userDetails: {
|
||||
_id: _id,
|
||||
name: userDetails.name,
|
||||
firstName: userDetails.firstName,
|
||||
lastName: userDetails.lastName,
|
||||
email: userDetails.email.toLowerCase(),
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class VaClientService {
|
|||
|
||||
// Define allowed fields for update (excluding password)
|
||||
const allowedFields = [
|
||||
"firstName", "lastName", "address", "city", "state", "zip",
|
||||
"name", "firstName", "lastName", "address", "city", "state", "zip",
|
||||
"billingName", "billingEmail", "billingAddress", "billingCity",
|
||||
"billingState", "billingZip", "position", "signatoryName",
|
||||
"signatoryEmail", "paymentMethod", "bankName", "accountNumber",
|
||||
|
|
@ -273,7 +273,7 @@ class VaClientService {
|
|||
userDetails: {
|
||||
firstName: userDetails.firstName,
|
||||
lastName: userDetails.lastName,
|
||||
name: `${userDetails.firstName} ${userDetails.lastName}`,
|
||||
name: userDetails.name,
|
||||
email: userDetails.email.toLowerCase(),
|
||||
password: hashedPassword,
|
||||
address: userDetails.address || null,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="light">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -7,6 +8,7 @@
|
|||
<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>
|
||||
|
||||
<body class="dashboard-body">
|
||||
<div id="root">
|
||||
<nav class="dashboard-header">
|
||||
|
|
@ -122,7 +124,8 @@
|
|||
<!-- Virtual Assistants List -->
|
||||
<div class="content-section">
|
||||
<div class="section-header">
|
||||
<h2 class="section-title">Virtual Assistants <span class="total-count" id="vaListCount">0 VAs</span></h2>
|
||||
<h2 class="section-title">Virtual Assistants <span class="total-count" id="vaListCount">0
|
||||
VAs</span></h2>
|
||||
</div>
|
||||
<div class="table-container">
|
||||
<div class="table-wrapper">
|
||||
|
|
@ -217,7 +220,8 @@
|
|||
<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>
|
||||
<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>
|
||||
|
|
@ -226,137 +230,155 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
// Theme management
|
||||
function setTheme(theme) {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
localStorage.setItem('theme', theme);
|
||||
}
|
||||
<script>
|
||||
window.__SF_TOKEN__ = "<%- typeof sf_token !== 'undefined' ? sf_token : '' %>";
|
||||
|
||||
function getSystemTheme() {
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
}
|
||||
if (window.__SF_TOKEN__ && !localStorage.getItem('knoptpq')) {
|
||||
localStorage.setItem('knoptpq', window.__SF_TOKEN__);
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
|
||||
// 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;
|
||||
// Theme management
|
||||
function setTheme(theme) {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
localStorage.setItem('theme', theme);
|
||||
}
|
||||
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
headers: {
|
||||
'token': `${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
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() {
|
||||
let token = localStorage.getItem('knoptpq');
|
||||
|
||||
if (!token && window.__SF_TOKEN__) {
|
||||
localStorage.setItem('knoptpq', window.__SF_TOKEN__);
|
||||
token = window.__SF_TOKEN__;
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
localStorage.removeItem('knoptpq');
|
||||
localStorage.removeItem('refreshToken');
|
||||
window.location.href = '/';
|
||||
return;
|
||||
return token;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async function handleLogout() {
|
||||
try {
|
||||
// Call logout API
|
||||
await fetchWithAuth(`${API_BASE}/logout`, {
|
||||
method: 'POST'
|
||||
|
||||
|
||||
async function fetchWithAuth(url, options = {}) {
|
||||
const token = getAuthToken();
|
||||
if (!token) {
|
||||
window.location.href = '/';
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
headers: {
|
||||
'token': `${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Logout API error:', error);
|
||||
} finally {
|
||||
// Clear local storage and redirect
|
||||
localStorage.removeItem('knoptpq');
|
||||
localStorage.removeItem('refreshToken');
|
||||
window.location.href = '/';
|
||||
}
|
||||
}
|
||||
|
||||
// Format time function
|
||||
function formatTime(seconds) {
|
||||
if (!seconds) return 'No Record Found';
|
||||
if (response.status === 401) {
|
||||
localStorage.removeItem('knoptpq');
|
||||
localStorage.removeItem('refreshToken');
|
||||
window.location.href = '/';
|
||||
return;
|
||||
}
|
||||
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${minutes}m`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes}m`;
|
||||
} else {
|
||||
return 'Just started';
|
||||
}
|
||||
}
|
||||
|
||||
const vaModal = document.getElementById('vaModal');
|
||||
|
||||
function openVAModal(va) {
|
||||
// Set basic VA info
|
||||
document.getElementById('modalVAName').textContent = va.name;
|
||||
|
||||
// Set projects
|
||||
const projects = va.projects || [];
|
||||
document.getElementById('projectsCountBadge').textContent = projects.length;
|
||||
|
||||
const projectsTableBody = document.getElementById('modalProjectsTableBody');
|
||||
const noProjectsMessage = document.getElementById('modalNoProjects');
|
||||
|
||||
if (projects.length > 0) {
|
||||
projectsTableBody.innerHTML = projects.map(project => createProjectTableRow(project)).join('');
|
||||
projectsTableBody.style.display = '';
|
||||
noProjectsMessage.style.display = 'none';
|
||||
} else {
|
||||
projectsTableBody.innerHTML = '';
|
||||
projectsTableBody.style.display = 'none';
|
||||
noProjectsMessage.style.display = 'block';
|
||||
return response;
|
||||
}
|
||||
|
||||
// Set action button
|
||||
const modalActions = document.getElementById('modalActions');
|
||||
const viewSessionBtn = document.getElementById('viewSessionBtn');
|
||||
|
||||
if (va.isCurrentlyActive && va.lastProjectId) {
|
||||
viewSessionBtn.href = `/live/${va.lastProjectId}/${va.id}`;
|
||||
modalActions.style.display = 'block';
|
||||
} else {
|
||||
modalActions.style.display = 'none';
|
||||
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 = '/';
|
||||
}
|
||||
}
|
||||
|
||||
// Show modal
|
||||
vaModal.style.display = 'flex';
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
// Format time function
|
||||
function formatTime(seconds) {
|
||||
if (!seconds) return 'No Record Found';
|
||||
|
||||
function closeVAModal() {
|
||||
vaModal.style.display = 'none';
|
||||
document.body.style.overflow = 'auto';
|
||||
}
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
|
||||
// Create project table row for modal
|
||||
function createProjectTableRow(project) {
|
||||
const statusClass = project.isCurrentlyWorking ? 'active' : 'inactive';
|
||||
const statusText = project.isCurrentlyWorking ? 'Working' : 'Not Active';
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${minutes}m`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes}m`;
|
||||
} else {
|
||||
return 'Just started';
|
||||
}
|
||||
}
|
||||
|
||||
return `
|
||||
const vaModal = document.getElementById('vaModal');
|
||||
|
||||
function openVAModal(va) {
|
||||
// Set basic VA info
|
||||
document.getElementById('modalVAName').textContent = va.name;
|
||||
|
||||
// Set projects
|
||||
const projects = va.projects || [];
|
||||
document.getElementById('projectsCountBadge').textContent = projects.length;
|
||||
|
||||
const projectsTableBody = document.getElementById('modalProjectsTableBody');
|
||||
const noProjectsMessage = document.getElementById('modalNoProjects');
|
||||
|
||||
if (projects.length > 0) {
|
||||
projectsTableBody.innerHTML = projects.map(project => createProjectTableRow(project)).join('');
|
||||
projectsTableBody.style.display = '';
|
||||
noProjectsMessage.style.display = 'none';
|
||||
} else {
|
||||
projectsTableBody.innerHTML = '';
|
||||
projectsTableBody.style.display = 'none';
|
||||
noProjectsMessage.style.display = 'block';
|
||||
}
|
||||
|
||||
// Set action button
|
||||
const modalActions = document.getElementById('modalActions');
|
||||
const viewSessionBtn = document.getElementById('viewSessionBtn');
|
||||
|
||||
if (va.isCurrentlyActive && va.lastProjectId) {
|
||||
viewSessionBtn.href = `/live/${va.lastProjectId}/${va.id}`;
|
||||
modalActions.style.display = 'block';
|
||||
} else {
|
||||
modalActions.style.display = 'none';
|
||||
}
|
||||
|
||||
// Show modal
|
||||
vaModal.style.display = 'flex';
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
|
||||
function closeVAModal() {
|
||||
vaModal.style.display = 'none';
|
||||
document.body.style.overflow = 'auto';
|
||||
}
|
||||
|
||||
// Create project table row for modal
|
||||
function createProjectTableRow(project) {
|
||||
const statusClass = project.isCurrentlyWorking ? 'active' : 'inactive';
|
||||
const statusText = project.isCurrentlyWorking ? 'Working' : 'Not Active';
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td>
|
||||
<div class="project-info">
|
||||
|
|
@ -376,18 +398,18 @@
|
|||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
// Create VA table row for main table
|
||||
function createVATableRow(va) {
|
||||
const statusClass = va.isCurrentlyActive ? 'active' : 'inactive';
|
||||
const statusText = va.isCurrentlyActive ? 'Active' : 'Inactive';
|
||||
const activeProject = va?.lastProject?.name ? va.lastProject.name : '-';
|
||||
const workedTime = formatTime(va.currentSessionDuration);
|
||||
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>` : '';
|
||||
// Create VA table row for main table
|
||||
function createVATableRow(va) {
|
||||
const statusClass = va.isCurrentlyActive ? 'active' : 'inactive';
|
||||
const statusText = va.isCurrentlyActive ? 'Active' : 'Inactive';
|
||||
const activeProject = va?.lastProject?.name ? va.lastProject.name : '-';
|
||||
const workedTime = formatTime(va.currentSessionDuration);
|
||||
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>` : '';
|
||||
|
||||
return `
|
||||
return `
|
||||
<tr class="va-row" data-va-id="${va.id}">
|
||||
<td>
|
||||
<div class="status-indicator">
|
||||
|
|
@ -414,144 +436,145 @@
|
|||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
// Load dashboard data
|
||||
async function loadDashboardData() {
|
||||
try {
|
||||
const response = await fetchWithAuth(`${API_BASE}/dashboard`);
|
||||
if (!response) return;
|
||||
const result = await response.json();
|
||||
// Load dashboard data
|
||||
async function loadDashboardData() {
|
||||
try {
|
||||
const response = await fetchWithAuth(`${API_BASE}/dashboard`);
|
||||
if (!response) return;
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const data = result.data;
|
||||
const summary = result.summary;
|
||||
if (result.success) {
|
||||
const data = result.data;
|
||||
const summary = result.summary;
|
||||
|
||||
// Update stats cards
|
||||
document.getElementById('activeVaCount').textContent = summary.activeVAs || 0;
|
||||
document.getElementById('totalVaCount').textContent = summary.totalVAs || 0;
|
||||
document.getElementById('totalProjects').textContent = summary.totalProjects || 0;
|
||||
// Update stats cards
|
||||
document.getElementById('activeVaCount').textContent = summary.activeVAs || 0;
|
||||
document.getElementById('totalVaCount').textContent = summary.totalVAs || 0;
|
||||
document.getElementById('totalProjects').textContent = summary.totalProjects || 0;
|
||||
|
||||
// Update VA list count
|
||||
document.getElementById('vaListCount').textContent = `${summary.totalVAs || 0} VAs`;
|
||||
// Update VA list count
|
||||
document.getElementById('vaListCount').textContent = `${summary.totalVAs || 0} VAs`;
|
||||
|
||||
// Update VA table
|
||||
const vaTableBody = document.getElementById('vaTableBody');
|
||||
const vaEmptyState = document.getElementById('vaEmptyState');
|
||||
const allVAs = data.allVAs || [];
|
||||
// Update VA table
|
||||
const vaTableBody = document.getElementById('vaTableBody');
|
||||
const vaEmptyState = document.getElementById('vaEmptyState');
|
||||
const allVAs = data.allVAs || [];
|
||||
|
||||
if (allVAs.length > 0) {
|
||||
vaTableBody.innerHTML = allVAs.map(va => createVATableRow(va)).join('');
|
||||
vaTableBody.style.display = '';
|
||||
vaEmptyState.style.display = 'none';
|
||||
if (allVAs.length > 0) {
|
||||
vaTableBody.innerHTML = allVAs.map(va => createVATableRow(va)).join('');
|
||||
vaTableBody.style.display = '';
|
||||
vaEmptyState.style.display = 'none';
|
||||
|
||||
// Store VA data globally for modal access
|
||||
window.vaData = allVAs;
|
||||
// Store VA data globally for modal access
|
||||
window.vaData = allVAs;
|
||||
|
||||
// Add click event listeners to VA rows
|
||||
document.querySelectorAll('.va-row').forEach((row, index) => {
|
||||
row.addEventListener('click', function(e) {
|
||||
// Don't open modal if clicking on view link
|
||||
if (!e.target.closest('.view-link')) {
|
||||
const va = allVAs[index];
|
||||
openVAModal(va);
|
||||
}
|
||||
// Add click event listeners to VA rows
|
||||
document.querySelectorAll('.va-row').forEach((row, index) => {
|
||||
row.addEventListener('click', function (e) {
|
||||
// Don't open modal if clicking on view link
|
||||
if (!e.target.closest('.view-link')) {
|
||||
const va = allVAs[index];
|
||||
openVAModal(va);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
vaTableBody.innerHTML = '';
|
||||
vaTableBody.style.display = 'none';
|
||||
vaEmptyState.style.display = 'block';
|
||||
}
|
||||
|
||||
} else {
|
||||
vaTableBody.innerHTML = '';
|
||||
vaTableBody.style.display = 'none';
|
||||
vaEmptyState.style.display = 'block';
|
||||
console.error('Failed to load dashboard data:', result.message);
|
||||
showError('Failed to load dashboard data');
|
||||
}
|
||||
|
||||
} else {
|
||||
console.error('Failed to load dashboard data:', result.message);
|
||||
showError('Failed to load dashboard data');
|
||||
} catch (error) {
|
||||
console.error('Error loading dashboard data:', error);
|
||||
showError('Error loading dashboard data');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error loading dashboard data:', error);
|
||||
showError('Error loading dashboard data');
|
||||
}
|
||||
}
|
||||
|
||||
// Show error message
|
||||
function showError(message) {
|
||||
const vaTableBody = document.getElementById('vaTableBody');
|
||||
const vaEmptyState = document.getElementById('vaEmptyState');
|
||||
// Show error message
|
||||
function showError(message) {
|
||||
const vaTableBody = document.getElementById('vaTableBody');
|
||||
const vaEmptyState = document.getElementById('vaEmptyState');
|
||||
|
||||
vaTableBody.style.display = 'none';
|
||||
vaEmptyState.innerHTML = `
|
||||
vaTableBody.style.display = 'none';
|
||||
vaEmptyState.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-exclamation-triangle"></i>
|
||||
<h3>Error</h3>
|
||||
<p>${message}</p>
|
||||
</div>
|
||||
`;
|
||||
vaEmptyState.style.display = 'block';
|
||||
}
|
||||
|
||||
// Close modal when clicking outside
|
||||
vaModal.addEventListener('click', (e) => {
|
||||
if (e.target === vaModal) {
|
||||
closeVAModal();
|
||||
vaEmptyState.style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
// Close modal with escape key
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape' && vaModal.style.display === 'flex') {
|
||||
closeVAModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Optional: Auto-refresh data every 30 seconds
|
||||
setInterval(loadDashboardData, 30000);
|
||||
|
||||
// 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() {
|
||||
// Load dashboard data
|
||||
loadDashboardData();
|
||||
|
||||
// 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 when clicking outside
|
||||
vaModal.addEventListener('click', (e) => {
|
||||
if (e.target === vaModal) {
|
||||
closeVAModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Close modal with escape key
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
closeLogoutModal();
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape' && vaModal.style.display === 'flex') {
|
||||
closeVAModal();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('logoutModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeLogoutModal();
|
||||
}
|
||||
// Optional: Auto-refresh data every 30 seconds
|
||||
setInterval(loadDashboardData, 30000);
|
||||
|
||||
// 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 () {
|
||||
// Load dashboard data
|
||||
loadDashboardData();
|
||||
|
||||
// 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);
|
||||
});
|
||||
|
||||
// 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);
|
||||
});
|
||||
|
||||
</script>
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -171,12 +171,20 @@
|
|||
|
||||
// -------- Download --------
|
||||
downloadBtn.addEventListener("click", () => {
|
||||
const activeBtn = document.querySelector(".os-btn.active")
|
||||
const os = activeBtn.dataset.os;
|
||||
|
||||
const link = document.createElement("a");
|
||||
link.href = `/public/builds/build-1.1.1.1/windows/VA Tracker-Setup-1.1.1.exe`;
|
||||
link.setAttribute("download", "");
|
||||
link.click()
|
||||
|
||||
if(os === "mac") {
|
||||
link.href = `/public/builds/build-1.1.1.1/mac/VA Tracker-1.1.1-universal.dmg`;
|
||||
link.setAttribute("download", "");
|
||||
} else if (os === "windows") {
|
||||
link.href = `/public/builds/build-1.1.1.1/windows/VA Tracker-Setup-1.1.1.exe`;
|
||||
link.setAttribute("download", "");
|
||||
}
|
||||
|
||||
link.click()
|
||||
// window.location.href = ``;
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -152,6 +152,15 @@
|
|||
<div class="error-message" id="step-2-error-message"></div>
|
||||
</div>
|
||||
<form id="business-form">
|
||||
<div class="form-group">
|
||||
<div class="input-container">
|
||||
<input type="text" id="company-name" class="input-field" placeholder=" " oninput="validateCompanyName(this)" required>
|
||||
<label for="company-name" class="input-label">Company Name *</label>
|
||||
</div>
|
||||
<div class="invalid-feedback" id="company-name-error" style="display: none; color: #dc3545; font-size: 12px; margin-top: 5px;">
|
||||
Company name should only contain letters, numbers, spaces, hyphens, apostrophes, ampersands, and periods
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-container">
|
||||
<input type="text" id="address" class="input-field" placeholder=" " required>
|
||||
|
|
|
|||
Loading…
Reference in New Issue