Compare commits
4 Commits
99d60185a9
...
0c14e26937
| Author | SHA1 | Date |
|---|---|---|
|
|
0c14e26937 | |
|
|
221e867a21 | |
|
|
39f415b685 | |
|
|
d4cdc94bbd |
|
|
@ -521,12 +521,12 @@ async function validateStep(step) {
|
||||||
}
|
}
|
||||||
if (!firstName) {
|
if (!firstName) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
showError('First Name is Required', null, step);
|
showError('First Name is Required', 'first-name', step);
|
||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
if (!lastName) {
|
if (!lastName) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
showError('Last Name is Required', null, step);
|
showError('Last Name is Required', 'last-name', step);
|
||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -545,6 +545,25 @@ async function validateStep(step) {
|
||||||
document.getElementById('confirmPassword').classList.remove('field-error');
|
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
|
// Validate other required fields
|
||||||
const requiredFields = form.querySelectorAll('[required]');
|
const requiredFields = form.querySelectorAll('[required]');
|
||||||
requiredFields.forEach(field => {
|
requiredFields.forEach(field => {
|
||||||
|
|
@ -639,6 +658,7 @@ function saveStepData(step) {
|
||||||
formData.userDetails.password = document.getElementById('password').value;
|
formData.userDetails.password = document.getElementById('password').value;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
formData.userDetails.name = document.getElementById('company-name').value;
|
||||||
formData.userDetails.address = document.getElementById('address').value;
|
formData.userDetails.address = document.getElementById('address').value;
|
||||||
formData.userDetails.city = document.getElementById('city').value;
|
formData.userDetails.city = document.getElementById('city').value;
|
||||||
formData.userDetails.state = document.getElementById('state').value;
|
formData.userDetails.state = document.getElementById('state').value;
|
||||||
|
|
@ -882,28 +902,29 @@ async function detectLocation() {
|
||||||
await populateStates(countryCode, 'state');
|
await populateStates(countryCode, 'state');
|
||||||
await populateStates(countryCode, 'billing-state');
|
await populateStates(countryCode, 'billing-state');
|
||||||
|
|
||||||
const stateSelect = document.getElementById('state');
|
// auto populate state if region matches
|
||||||
const billingStateSelect = document.getElementById('billing-state');
|
// const stateSelect = document.getElementById('state');
|
||||||
|
// const billingStateSelect = document.getElementById('billing-state');
|
||||||
|
|
||||||
if (stateSelect && region) {
|
// if (stateSelect && region) {
|
||||||
const matchedState = Array.from(stateSelect.options).find(
|
// const matchedState = Array.from(stateSelect.options).find(
|
||||||
opt => opt.text.toLowerCase() === region.toLowerCase()
|
// opt => opt.text.toLowerCase() === region.toLowerCase()
|
||||||
);
|
// );
|
||||||
if (matchedState) {
|
// if (matchedState) {
|
||||||
stateSelect.value = matchedState.value;
|
// stateSelect.value = matchedState.value;
|
||||||
stateSelect.dispatchEvent(new Event('change'));
|
// stateSelect.dispatchEvent(new Event('change'));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (billingStateSelect && region) {
|
// if (billingStateSelect && region) {
|
||||||
const matchedBillingState = Array.from(billingStateSelect.options).find(
|
// const matchedBillingState = Array.from(billingStateSelect.options).find(
|
||||||
opt => opt.text.toLowerCase() === region.toLowerCase()
|
// opt => opt.text.toLowerCase() === region.toLowerCase()
|
||||||
);
|
// );
|
||||||
if (matchedBillingState) {
|
// if (matchedBillingState) {
|
||||||
billingStateSelect.value = matchedBillingState.value;
|
// billingStateSelect.value = matchedBillingState.value;
|
||||||
billingStateSelect.dispatchEvent(new Event('change'));
|
// billingStateSelect.dispatchEvent(new Event('change'));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error detecting location:', error);
|
console.error('Error detecting location:', error);
|
||||||
|
|
||||||
|
|
@ -1092,7 +1113,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
// Handle use business address checkbox
|
// Handle use business address checkbox
|
||||||
document.getElementById('use-business-address').addEventListener('change', function() {
|
document.getElementById('use-business-address').addEventListener('change', function() {
|
||||||
if (this.checked) {
|
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-address').value = formData.userDetails.address || '';
|
||||||
document.getElementById('billing-city').value = formData.userDetails.city || '';
|
document.getElementById('billing-city').value = formData.userDetails.city || '';
|
||||||
document.getElementById('billing-state').value = formData.userDetails.state || '';
|
document.getElementById('billing-state').value = formData.userDetails.state || '';
|
||||||
|
|
@ -1439,6 +1460,93 @@ function preventInvalidLastNameChars(event) {
|
||||||
return false;
|
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 to validate ZIP code in real-time
|
||||||
function validateZipCode(input) {
|
function validateZipCode(input) {
|
||||||
let errorElement;
|
let errorElement;
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,10 @@ async function va_register_client(req, res) {
|
||||||
try {
|
try {
|
||||||
const payload = req.body || {};
|
const payload = req.body || {};
|
||||||
const { userDetails } = payload;
|
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({
|
return res.status(400).json({
|
||||||
success: false,
|
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 })
|
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) => {
|
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"
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ class SalesforceService {
|
||||||
return {
|
return {
|
||||||
userDetails: {
|
userDetails: {
|
||||||
_id: _id,
|
_id: _id,
|
||||||
|
name: userDetails.name,
|
||||||
firstName: userDetails.firstName,
|
firstName: userDetails.firstName,
|
||||||
lastName: userDetails.lastName,
|
lastName: userDetails.lastName,
|
||||||
email: userDetails.email.toLowerCase(),
|
email: userDetails.email.toLowerCase(),
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class VaClientService {
|
||||||
|
|
||||||
// Define allowed fields for update (excluding password)
|
// Define allowed fields for update (excluding password)
|
||||||
const allowedFields = [
|
const allowedFields = [
|
||||||
"firstName", "lastName", "address", "city", "state", "zip",
|
"name", "firstName", "lastName", "address", "city", "state", "zip",
|
||||||
"billingName", "billingEmail", "billingAddress", "billingCity",
|
"billingName", "billingEmail", "billingAddress", "billingCity",
|
||||||
"billingState", "billingZip", "position", "signatoryName",
|
"billingState", "billingZip", "position", "signatoryName",
|
||||||
"signatoryEmail", "paymentMethod", "bankName", "accountNumber",
|
"signatoryEmail", "paymentMethod", "bankName", "accountNumber",
|
||||||
|
|
@ -273,7 +273,7 @@ class VaClientService {
|
||||||
userDetails: {
|
userDetails: {
|
||||||
firstName: userDetails.firstName,
|
firstName: userDetails.firstName,
|
||||||
lastName: userDetails.lastName,
|
lastName: userDetails.lastName,
|
||||||
name: `${userDetails.firstName} ${userDetails.lastName}`,
|
name: userDetails.name,
|
||||||
email: userDetails.email.toLowerCase(),
|
email: userDetails.email.toLowerCase(),
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
address: userDetails.address || null,
|
address: userDetails.address || null,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" data-theme="light">
|
<html lang="en" data-theme="light">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
||||||
<link rel="stylesheet" href="/public/css/dashboard.css">
|
<link rel="stylesheet" href="/public/css/dashboard.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="dashboard-body">
|
<body class="dashboard-body">
|
||||||
<div id="root">
|
<div id="root">
|
||||||
<nav class="dashboard-header">
|
<nav class="dashboard-header">
|
||||||
|
|
@ -122,7 +124,8 @@
|
||||||
<!-- Virtual Assistants List -->
|
<!-- Virtual Assistants List -->
|
||||||
<div class="content-section">
|
<div class="content-section">
|
||||||
<div class="section-header">
|
<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>
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
<div class="table-wrapper">
|
<div class="table-wrapper">
|
||||||
|
|
@ -217,7 +220,8 @@
|
||||||
<i class="fas fa-sign-out-alt"></i>
|
<i class="fas fa-sign-out-alt"></i>
|
||||||
</div>
|
</div>
|
||||||
<h3 class="logout-title">Are you sure you want to logout?</h3>
|
<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">
|
<div class="logout-actions">
|
||||||
<button class="logout-cancel-btn" onclick="closeLogoutModal()">Cancel</button>
|
<button class="logout-cancel-btn" onclick="closeLogoutModal()">Cancel</button>
|
||||||
<button class="logout-confirm-btn" id="confirmLogoutBtn">Yes, Logout</button>
|
<button class="logout-confirm-btn" id="confirmLogoutBtn">Yes, Logout</button>
|
||||||
|
|
@ -226,137 +230,155 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
// Theme management
|
window.__SF_TOKEN__ = "<%- typeof sf_token !== 'undefined' ? sf_token : '' %>";
|
||||||
function setTheme(theme) {
|
|
||||||
document.documentElement.setAttribute('data-theme', theme);
|
|
||||||
localStorage.setItem('theme', theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSystemTheme() {
|
if (window.__SF_TOKEN__ && !localStorage.getItem('knoptpq')) {
|
||||||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
localStorage.setItem('knoptpq', window.__SF_TOKEN__);
|
||||||
}
|
}
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
|
||||||
// Initialize theme
|
// Theme management
|
||||||
const savedTheme = getSystemTheme();
|
function setTheme(theme) {
|
||||||
setTheme(savedTheme);
|
document.documentElement.setAttribute('data-theme', theme);
|
||||||
|
localStorage.setItem('theme', theme);
|
||||||
// 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, {
|
function getSystemTheme() {
|
||||||
...options,
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||||
headers: {
|
}
|
||||||
'token': `${token}`,
|
|
||||||
'Content-Type': 'application/json',
|
// Initialize theme
|
||||||
...options.headers,
|
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) {
|
return token;
|
||||||
localStorage.removeItem('knoptpq');
|
|
||||||
localStorage.removeItem('refreshToken');
|
|
||||||
window.location.href = '/';
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleLogout() {
|
|
||||||
try {
|
|
||||||
// Call logout API
|
async function fetchWithAuth(url, options = {}) {
|
||||||
await fetchWithAuth(`${API_BASE}/logout`, {
|
const token = getAuthToken();
|
||||||
method: 'POST'
|
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
|
if (response.status === 401) {
|
||||||
function formatTime(seconds) {
|
localStorage.removeItem('knoptpq');
|
||||||
if (!seconds) return 'No Record Found';
|
localStorage.removeItem('refreshToken');
|
||||||
|
window.location.href = '/';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const hours = Math.floor(seconds / 3600);
|
return response;
|
||||||
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';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set action button
|
async function handleLogout() {
|
||||||
const modalActions = document.getElementById('modalActions');
|
try {
|
||||||
const viewSessionBtn = document.getElementById('viewSessionBtn');
|
// Call logout API
|
||||||
|
await fetchWithAuth(`${API_BASE}/logout`, {
|
||||||
if (va.isCurrentlyActive && va.lastProjectId) {
|
method: 'POST'
|
||||||
viewSessionBtn.href = `/live/${va.lastProjectId}/${va.id}`;
|
});
|
||||||
modalActions.style.display = 'block';
|
} catch (error) {
|
||||||
} else {
|
console.error('Logout API error:', error);
|
||||||
modalActions.style.display = 'none';
|
} finally {
|
||||||
|
// Clear local storage and redirect
|
||||||
|
localStorage.removeItem('knoptpq');
|
||||||
|
localStorage.removeItem('refreshToken');
|
||||||
|
window.location.href = '/';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show modal
|
// Format time function
|
||||||
vaModal.style.display = 'flex';
|
function formatTime(seconds) {
|
||||||
document.body.style.overflow = 'hidden';
|
if (!seconds) return 'No Record Found';
|
||||||
}
|
|
||||||
|
|
||||||
function closeVAModal() {
|
const hours = Math.floor(seconds / 3600);
|
||||||
vaModal.style.display = 'none';
|
const minutes = Math.floor((seconds % 3600) / 60);
|
||||||
document.body.style.overflow = 'auto';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create project table row for modal
|
if (hours > 0) {
|
||||||
function createProjectTableRow(project) {
|
return `${hours}h ${minutes}m`;
|
||||||
const statusClass = project.isCurrentlyWorking ? 'active' : 'inactive';
|
} else if (minutes > 0) {
|
||||||
const statusText = project.isCurrentlyWorking ? 'Working' : 'Not Active';
|
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>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div class="project-info">
|
<div class="project-info">
|
||||||
|
|
@ -376,18 +398,18 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create VA table row for main table
|
// Create VA table row for main table
|
||||||
function createVATableRow(va) {
|
function createVATableRow(va) {
|
||||||
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 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</a>` : '';
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<tr class="va-row" data-va-id="${va.id}">
|
<tr class="va-row" data-va-id="${va.id}">
|
||||||
<td>
|
<td>
|
||||||
<div class="status-indicator">
|
<div class="status-indicator">
|
||||||
|
|
@ -414,144 +436,145 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load dashboard data
|
// Load dashboard data
|
||||||
async function loadDashboardData() {
|
async function loadDashboardData() {
|
||||||
try {
|
try {
|
||||||
const response = await fetchWithAuth(`${API_BASE}/dashboard`);
|
const response = await fetchWithAuth(`${API_BASE}/dashboard`);
|
||||||
if (!response) return;
|
if (!response) return;
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const data = result.data;
|
const data = result.data;
|
||||||
const summary = result.summary;
|
const summary = result.summary;
|
||||||
|
|
||||||
// Update stats cards
|
// Update stats cards
|
||||||
document.getElementById('activeVaCount').textContent = summary.activeVAs || 0;
|
document.getElementById('activeVaCount').textContent = summary.activeVAs || 0;
|
||||||
document.getElementById('totalVaCount').textContent = summary.totalVAs || 0;
|
document.getElementById('totalVaCount').textContent = summary.totalVAs || 0;
|
||||||
document.getElementById('totalProjects').textContent = summary.totalProjects || 0;
|
document.getElementById('totalProjects').textContent = summary.totalProjects || 0;
|
||||||
|
|
||||||
// Update VA list count
|
// Update VA list count
|
||||||
document.getElementById('vaListCount').textContent = `${summary.totalVAs || 0} VAs`;
|
document.getElementById('vaListCount').textContent = `${summary.totalVAs || 0} VAs`;
|
||||||
|
|
||||||
// Update VA table
|
// Update VA table
|
||||||
const vaTableBody = document.getElementById('vaTableBody');
|
const vaTableBody = document.getElementById('vaTableBody');
|
||||||
const vaEmptyState = document.getElementById('vaEmptyState');
|
const vaEmptyState = document.getElementById('vaEmptyState');
|
||||||
const allVAs = data.allVAs || [];
|
const allVAs = data.allVAs || [];
|
||||||
|
|
||||||
if (allVAs.length > 0) {
|
if (allVAs.length > 0) {
|
||||||
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';
|
||||||
|
|
||||||
// Store VA data globally for modal access
|
// Store VA data globally for modal access
|
||||||
window.vaData = allVAs;
|
window.vaData = allVAs;
|
||||||
|
|
||||||
// Add click event listeners to VA rows
|
// Add click event listeners to VA rows
|
||||||
document.querySelectorAll('.va-row').forEach((row, index) => {
|
document.querySelectorAll('.va-row').forEach((row, index) => {
|
||||||
row.addEventListener('click', function(e) {
|
row.addEventListener('click', function (e) {
|
||||||
// Don't open modal if clicking on view link
|
// Don't open modal if clicking on view link
|
||||||
if (!e.target.closest('.view-link')) {
|
if (!e.target.closest('.view-link')) {
|
||||||
const va = allVAs[index];
|
const va = allVAs[index];
|
||||||
openVAModal(va);
|
openVAModal(va);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
vaTableBody.innerHTML = '';
|
||||||
|
vaTableBody.style.display = 'none';
|
||||||
|
vaEmptyState.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
vaTableBody.innerHTML = '';
|
console.error('Failed to load dashboard data:', result.message);
|
||||||
vaTableBody.style.display = 'none';
|
showError('Failed to load dashboard data');
|
||||||
vaEmptyState.style.display = 'block';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} catch (error) {
|
||||||
console.error('Failed to load dashboard data:', result.message);
|
console.error('Error loading dashboard data:', error);
|
||||||
showError('Failed to load dashboard data');
|
showError('Error loading dashboard data');
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading dashboard data:', error);
|
|
||||||
showError('Error loading dashboard data');
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Show error message
|
// Show error message
|
||||||
function showError(message) {
|
function showError(message) {
|
||||||
const vaTableBody = document.getElementById('vaTableBody');
|
const vaTableBody = document.getElementById('vaTableBody');
|
||||||
const vaEmptyState = document.getElementById('vaEmptyState');
|
const vaEmptyState = document.getElementById('vaEmptyState');
|
||||||
|
|
||||||
vaTableBody.style.display = 'none';
|
vaTableBody.style.display = 'none';
|
||||||
vaEmptyState.innerHTML = `
|
vaEmptyState.innerHTML = `
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<i class="fas fa-exclamation-triangle"></i>
|
<i class="fas fa-exclamation-triangle"></i>
|
||||||
<h3>Error</h3>
|
<h3>Error</h3>
|
||||||
<p>${message}</p>
|
<p>${message}</p>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
vaEmptyState.style.display = 'block';
|
vaEmptyState.style.display = 'block';
|
||||||
}
|
|
||||||
|
|
||||||
// Close modal when clicking outside
|
|
||||||
vaModal.addEventListener('click', (e) => {
|
|
||||||
if (e.target === vaModal) {
|
|
||||||
closeVAModal();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// Close modal with escape key
|
// Close modal when clicking outside
|
||||||
document.addEventListener('keydown', (e) => {
|
vaModal.addEventListener('click', (e) => {
|
||||||
if (e.key === 'Escape' && vaModal.style.display === 'flex') {
|
if (e.target === vaModal) {
|
||||||
closeVAModal();
|
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 with escape key
|
// Close modal with escape key
|
||||||
document.addEventListener('keydown', function(e) {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape' && vaModal.style.display === 'flex') {
|
||||||
closeLogoutModal();
|
closeVAModal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('logoutModal').addEventListener('click', function(e) {
|
// Optional: Auto-refresh data every 30 seconds
|
||||||
if (e.target === this) {
|
setInterval(loadDashboardData, 30000);
|
||||||
closeLogoutModal();
|
|
||||||
}
|
// 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
|
</script>
|
||||||
document.getElementById('logoutButton').addEventListener('click', openLogoutModal);
|
|
||||||
|
|
||||||
// Confirm logout button
|
|
||||||
document.getElementById('confirmLogoutBtn').addEventListener('click', handleLogout);
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -171,12 +171,20 @@
|
||||||
|
|
||||||
// -------- Download --------
|
// -------- Download --------
|
||||||
downloadBtn.addEventListener("click", () => {
|
downloadBtn.addEventListener("click", () => {
|
||||||
|
const activeBtn = document.querySelector(".os-btn.active")
|
||||||
|
const os = activeBtn.dataset.os;
|
||||||
|
|
||||||
const link = document.createElement("a");
|
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 = ``;
|
// window.location.href = ``;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,15 @@
|
||||||
<div class="error-message" id="step-2-error-message"></div>
|
<div class="error-message" id="step-2-error-message"></div>
|
||||||
</div>
|
</div>
|
||||||
<form id="business-form">
|
<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="form-group">
|
||||||
<div class="input-container">
|
<div class="input-container">
|
||||||
<input type="text" id="address" class="input-field" placeholder=" " required>
|
<input type="text" id="address" class="input-field" placeholder=" " required>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue