Updated client dashboard
This commit is contained in:
parent
16a62670e7
commit
4d757daf97
|
|
@ -826,6 +826,7 @@ tr[data-vaid]:hover {
|
|||
cursor: pointer;
|
||||
z-index: 10;
|
||||
position: relative;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Project Details Styles in Popup */
|
||||
|
|
@ -1300,3 +1301,12 @@ tr[data-vaid]:hover {
|
|||
background: #4b5563;
|
||||
color: #d1d5db;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
text-align: center;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.modal-actions a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
|
@ -691,10 +691,11 @@
|
|||
formData.userDetails.city = document.getElementById('city').value;
|
||||
formData.userDetails.state = document.getElementById('state').value;
|
||||
formData.userDetails.country = document.getElementById('country').value;
|
||||
formData.status = document.getElementById('status').value;
|
||||
break;
|
||||
case 3:
|
||||
formData.userDetails.phone = document.getElementById('phone').value;
|
||||
formData.userDetails.skype = document.getElementById('skype').value;
|
||||
// formData.userDetails.skype = document.getElementById('skype').value;
|
||||
break;
|
||||
case 4:
|
||||
const selectedPayment = document.querySelector('.payment-option.selected');
|
||||
|
|
@ -1150,7 +1151,7 @@ function validateSkypeId(input) {
|
|||
|
||||
if (value && !/^[a-zA-Z][a-zA-Z0-9\.,\-_]+$/.test(value)) {
|
||||
input.style.border = '1px solid #ef4444';
|
||||
showError('Skype ID must start with a letter and can only contain letters, numbers, dots, hyphens, and underscores', 'skype', 3);
|
||||
showError('Invalid Skype ID', 'skype', 3);
|
||||
return false;
|
||||
} else {
|
||||
input.style.border = '';
|
||||
|
|
|
|||
|
|
@ -68,12 +68,7 @@ async function client_dashboard(req, res) {
|
|||
$cond: [{ $eq: ["$loggedType", "LOGIN"] }, 1, 0]
|
||||
}
|
||||
},
|
||||
lastActivity: { $first: "$time" },
|
||||
projectsWorked: {
|
||||
$addToSet: "$projectId"
|
||||
},
|
||||
// Get all login logs for this VA
|
||||
allLogs: { $push: "$$ROOT" }
|
||||
lastActivity: { $first: "$time" }
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -85,22 +80,12 @@ async function client_dashboard(req, res) {
|
|||
|
||||
const activeVaIds = agg.map((a) => a._id).filter(Boolean);
|
||||
|
||||
// Get active VA details
|
||||
const activeVAs = await VAModel.find({
|
||||
_id: { $in: activeVaIds },
|
||||
clientIds: clientID
|
||||
})
|
||||
.select('userDetails.firstName userDetails.lastName userDetails.email userDetails.phone status createdAt projectIds')
|
||||
.lean()
|
||||
.exec();
|
||||
|
||||
// Create mapping for last log and activity data
|
||||
const activityByVa = agg.reduce((acc, a) => {
|
||||
acc[String(a._id)] = {
|
||||
lastLog: a.lastLog,
|
||||
totalLogins: a.totalLogins,
|
||||
lastActivity: a.lastActivity,
|
||||
projectsWorked: a.projectsWorked || []
|
||||
lastActivity: a.lastActivity
|
||||
};
|
||||
return acc;
|
||||
}, {});
|
||||
|
|
@ -126,14 +111,14 @@ async function client_dashboard(req, res) {
|
|||
logsByVa[vaId].push(log);
|
||||
});
|
||||
|
||||
// Calculate total worked time for each VA using the same logic as va_log_work_report_callback
|
||||
// Calculate total worked time for each VA
|
||||
for (const [vaId, logs] of Object.entries(logsByVa)) {
|
||||
let totalWorkSeconds = 0;
|
||||
|
||||
// Group logs by date (YYYY-MM-DD format)
|
||||
const logsByDate = {};
|
||||
logs.forEach(log => {
|
||||
const date = new Date(log.time).toISOString().split('T')[0]; // YYYY-MM-DD
|
||||
const date = new Date(log.time).toISOString().split('T')[0];
|
||||
if (!logsByDate[date]) {
|
||||
logsByDate[date] = [];
|
||||
}
|
||||
|
|
@ -147,7 +132,6 @@ async function client_dashboard(req, res) {
|
|||
|
||||
let dayWorkSeconds = 0;
|
||||
let lastLogin = null;
|
||||
let lastProjectId = null;
|
||||
|
||||
// If day has adjustment logs, only process adjustment logs
|
||||
// If no adjustment logs, process all logs for that day
|
||||
|
|
@ -164,14 +148,10 @@ async function client_dashboard(req, res) {
|
|||
|
||||
if (log.loggedType === "LOGIN") {
|
||||
lastLogin = time;
|
||||
lastProjectId = log.projectId?.toString() || null;
|
||||
} else if (log.loggedType === "LOGOUT" && lastLogin) {
|
||||
const diffSec = (time - lastLogin) / 1000;
|
||||
dayWorkSeconds += diffSec;
|
||||
|
||||
// reset after each pair
|
||||
lastLogin = null;
|
||||
lastProjectId = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,25 +164,93 @@ async function client_dashboard(req, res) {
|
|||
};
|
||||
}
|
||||
|
||||
// NEW: Calculate project-wise work time for each VA
|
||||
const projectWorkTimeByVa = {};
|
||||
|
||||
for (const [vaId, logs] of Object.entries(logsByVa)) {
|
||||
const projectWorkTime = {};
|
||||
|
||||
// Group logs by project
|
||||
const logsByProject = {};
|
||||
logs.forEach(log => {
|
||||
const projectId = log.projectId?.toString();
|
||||
if (projectId) {
|
||||
if (!logsByProject[projectId]) {
|
||||
logsByProject[projectId] = [];
|
||||
}
|
||||
logsByProject[projectId].push(log);
|
||||
}
|
||||
});
|
||||
|
||||
// Calculate work time per project
|
||||
for (const [projectId, projectLogs] of Object.entries(logsByProject)) {
|
||||
let projectWorkSeconds = 0;
|
||||
|
||||
// Group logs by date
|
||||
const logsByDate = {};
|
||||
projectLogs.forEach(log => {
|
||||
const date = new Date(log.time).toISOString().split('T')[0];
|
||||
if (!logsByDate[date]) {
|
||||
logsByDate[date] = [];
|
||||
}
|
||||
logsByDate[date].push(log);
|
||||
});
|
||||
|
||||
// Process each day separately
|
||||
for (const [date, dayLogs] of Object.entries(logsByDate)) {
|
||||
const hasAdjustmentLogs = dayLogs.some(log => log.isAdjustment === true);
|
||||
let dayWorkSeconds = 0;
|
||||
let lastLogin = null;
|
||||
|
||||
const logsToProcess = hasAdjustmentLogs
|
||||
? dayLogs.filter(log => log.isAdjustment === true)
|
||||
: dayLogs;
|
||||
|
||||
logsToProcess.sort((a, b) => new Date(a.time) - new Date(b.time));
|
||||
|
||||
for (const log of logsToProcess) {
|
||||
const time = new Date(log.time);
|
||||
|
||||
if (log.loggedType === "LOGIN") {
|
||||
lastLogin = time;
|
||||
} else if (log.loggedType === "LOGOUT" && lastLogin) {
|
||||
const diffSec = (time - lastLogin) / 1000;
|
||||
dayWorkSeconds += diffSec;
|
||||
lastLogin = null;
|
||||
}
|
||||
}
|
||||
|
||||
projectWorkSeconds += dayWorkSeconds;
|
||||
}
|
||||
|
||||
projectWorkTime[projectId] = {
|
||||
totalSeconds: projectWorkSeconds,
|
||||
formatted: formatTime(projectWorkSeconds),
|
||||
projectName: projectMap[projectId]?.name || 'Unknown Project'
|
||||
};
|
||||
}
|
||||
|
||||
projectWorkTimeByVa[vaId] = projectWorkTime;
|
||||
}
|
||||
|
||||
// Calculate session duration for currently active VAs
|
||||
const currentTime = new Date();
|
||||
|
||||
// Format all assigned VAs
|
||||
// Format all assigned VAs - Only include data needed for frontend
|
||||
const allVAsFormatted = allAssignedVAs.map((v) => {
|
||||
const activity = activityByVa[String(v._id)] || {};
|
||||
const workedTime = totalWorkedTimeByVa[String(v._id)] || { totalSeconds: 0, formatted: '00:00:00' };
|
||||
const lastLog = activity.lastLog;
|
||||
const projectWorkTime = projectWorkTimeByVa[String(v._id)] || {};
|
||||
|
||||
// Calculate current session duration if still logged in
|
||||
let currentSessionDuration = null;
|
||||
let isCurrentlyActive = false;
|
||||
let currentSessionFormatted = null;
|
||||
let currentProjectDetails = null;
|
||||
|
||||
if (lastLog && lastLog.loggedType === "LOGIN") {
|
||||
const loginTime = new Date(lastLog.time);
|
||||
currentSessionDuration = Math.floor((currentTime - loginTime) / 1000);
|
||||
currentSessionFormatted = formatTime(currentSessionDuration);
|
||||
isCurrentlyActive = true;
|
||||
|
||||
// Consider VA inactive if last login was more than 24 hours ago
|
||||
|
|
@ -223,6 +271,29 @@ async function client_dashboard(req, res) {
|
|||
// Combine first and last name
|
||||
const fullName = `${v.userDetails?.firstName || ''} ${v.userDetails?.lastName || ''}`.trim() || 'Unknown';
|
||||
|
||||
// Filter: Only include projects that belong to this client
|
||||
const clientProjectsAssigned = (v.projectIds || []).filter(projectId =>
|
||||
clientProjectIds.some(clientProjectId =>
|
||||
clientProjectId.toString() === projectId.toString()
|
||||
)
|
||||
);
|
||||
|
||||
// Format project work time for popup
|
||||
const projectsWithWorkTime = clientProjectsAssigned.map(projectId => {
|
||||
const projectIdStr = projectId.toString();
|
||||
const workData = projectWorkTime[projectIdStr] || { totalSeconds: 0, formatted: '00:00:00' };
|
||||
const project = projectMap[projectIdStr];
|
||||
|
||||
return {
|
||||
id: projectId,
|
||||
name: project?.name || 'Unknown Project',
|
||||
totalWorkedTime: workData.formatted,
|
||||
totalWorkedSeconds: workData.totalSeconds,
|
||||
isCurrentlyWorking: currentProjectDetails?.id?.toString() === projectIdStr,
|
||||
hourlyRate: project?.hourlyRate || 0
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
id: v._id,
|
||||
name: fullName,
|
||||
|
|
@ -231,99 +302,18 @@ async function client_dashboard(req, res) {
|
|||
status: v.status || 'active',
|
||||
isCurrentlyActive: isCurrentlyActive,
|
||||
lastLoginTime: lastLog?.time || null,
|
||||
lastActivity: activity.lastActivity,
|
||||
currentSessionDuration: currentSessionDuration,
|
||||
currentSessionFormatted: currentSessionFormatted,
|
||||
totalWorkedTime: workedTime.formatted,
|
||||
totalWorkedSeconds: workedTime.totalSeconds,
|
||||
totalLogins: activity.totalLogins || 0,
|
||||
lastProject: currentProjectDetails,
|
||||
lastProjectId: lastLog?.projectId || null,
|
||||
projectsWorked: activity.projectsWorked || [],
|
||||
projectsAssigned: v.projectIds?.length || 0,
|
||||
projectsAssigned: clientProjectsAssigned.length,
|
||||
// Detailed project information for popup
|
||||
projects: projectsWithWorkTime,
|
||||
vaSince: v.createdAt
|
||||
};
|
||||
});
|
||||
|
||||
// Format active VAs (currently working)
|
||||
const activeVAsFormatted = activeVAs.map((v) => {
|
||||
const activity = activityByVa[String(v._id)] || {};
|
||||
const workedTime = totalWorkedTimeByVa[String(v._id)] || { totalSeconds: 0, formatted: '00:00:00' };
|
||||
const lastLog = activity.lastLog;
|
||||
|
||||
let currentSessionDuration = null;
|
||||
let currentSessionFormatted = null;
|
||||
let currentProjectDetails = null;
|
||||
|
||||
if (lastLog && lastLog.loggedType === "LOGIN") {
|
||||
const loginTime = new Date(lastLog.time);
|
||||
currentSessionDuration = Math.floor((currentTime - loginTime) / 1000);
|
||||
currentSessionFormatted = formatTime(currentSessionDuration);
|
||||
|
||||
// Get current project details
|
||||
if (lastLog.projectId && projectMap[lastLog.projectId.toString()]) {
|
||||
currentProjectDetails = {
|
||||
id: lastLog.projectId,
|
||||
name: projectMap[lastLog.projectId.toString()].name
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Combine first and last name
|
||||
const fullName = `${v.userDetails?.firstName || ''} ${v.userDetails?.lastName || ''}`.trim() || 'Unknown';
|
||||
|
||||
return {
|
||||
id: v._id,
|
||||
name: fullName,
|
||||
email: v.userDetails?.email,
|
||||
phone: v.userDetails?.phone,
|
||||
status: v.status || 'active',
|
||||
lastLoginTime: lastLog?.time || null,
|
||||
currentSessionDuration: currentSessionDuration,
|
||||
currentSessionFormatted: currentSessionFormatted,
|
||||
totalWorkedTime: workedTime.formatted,
|
||||
totalWorkedSeconds: workedTime.totalSeconds,
|
||||
totalLogins: activity.totalLogins || 0,
|
||||
currentProject: currentProjectDetails,
|
||||
currentProjectId: lastLog?.projectId || null,
|
||||
projectsAssigned: v.projectIds?.length || 0,
|
||||
vaSince: v.createdAt
|
||||
};
|
||||
});
|
||||
|
||||
// Format projects with additional data
|
||||
const projectsFormatted = clientProjects.map((p) => {
|
||||
// Find VAs currently working on this project
|
||||
const activeVAsOnProject = allVAsFormatted.filter(va =>
|
||||
va.isCurrentlyActive && va.lastProjectId &&
|
||||
va.lastProjectId.toString() === p._id.toString()
|
||||
);
|
||||
|
||||
// Find all VAs assigned to this project
|
||||
const assignedVAs = allAssignedVAs.filter(va =>
|
||||
va.projectIds && va.projectIds.some(projectId =>
|
||||
projectId.toString() === p._id.toString()
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
id: p._id,
|
||||
name: p.name,
|
||||
hourlyRate: p.hourlyRate,
|
||||
totalLoggedHours: p.totalLoggedHours || 0,
|
||||
dedicatedHours: p.dedicatedHours || 0,
|
||||
vaAssigned: assignedVAs.length,
|
||||
vaCurrentlyWorking: activeVAsOnProject.length,
|
||||
activeVAs: activeVAsOnProject.map(va => ({
|
||||
id: va.id,
|
||||
name: va.name,
|
||||
currentSession: va.currentSessionFormatted,
|
||||
lastLoginTime: va.lastLoginTime
|
||||
})),
|
||||
createdAt: p.createdAt
|
||||
};
|
||||
});
|
||||
|
||||
// Calculate dashboard statistics
|
||||
const totalHoursLogged = clientProjects.reduce((sum, p) => sum + (p.totalLoggedHours || 0), 0);
|
||||
const totalDedicatedHours = clientProjects.reduce((sum, p) => sum + (p.dedicatedHours || 0), 0);
|
||||
|
|
@ -334,45 +324,22 @@ async function client_dashboard(req, res) {
|
|||
// Calculate total worked time across all VAs
|
||||
const totalWorkedTimeAllVAs = allVAsFormatted.reduce((total, va) => total + (va.totalWorkedSeconds || 0), 0);
|
||||
|
||||
// Calculate projects with active workers
|
||||
const projectsWithActiveWorkers = projectsFormatted.filter(p => p.vaCurrentlyWorking > 0).length;
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
data: {
|
||||
// All assigned VAs with their status
|
||||
allVAs: {
|
||||
active: currentlyActiveVAs,
|
||||
inactive: inactiveVAs,
|
||||
total: allVAsFormatted
|
||||
},
|
||||
// Currently working VAs (active session)
|
||||
activeVAs: activeVAsFormatted,
|
||||
// All client projects
|
||||
projects: projectsFormatted
|
||||
// Only send data that frontend actually uses
|
||||
allVAs: allVAsFormatted
|
||||
},
|
||||
summary: {
|
||||
totalVAs: allAssignedVAs.length,
|
||||
activeVAs: currentlyActiveVAs.length,
|
||||
inactiveVAs: inactiveVAs.length,
|
||||
totalProjects: clientProjects.length,
|
||||
projectsWithActiveWorkers: projectsWithActiveWorkers,
|
||||
totalHoursLogged: totalHoursLogged,
|
||||
totalDedicatedHours: totalDedicatedHours,
|
||||
totalWorkedTime: formatTime(totalWorkedTimeAllVAs),
|
||||
utilizationRate: totalDedicatedHours > 0 ?
|
||||
((totalHoursLogged / totalDedicatedHours) * 100).toFixed(2) + '%' : '0%',
|
||||
lastUpdated: currentTime.toISOString()
|
||||
},
|
||||
counts: {
|
||||
vas: {
|
||||
total: allAssignedVAs.length,
|
||||
active: currentlyActiveVAs.length,
|
||||
inactive: inactiveVAs.length
|
||||
},
|
||||
projects: clientProjects.length,
|
||||
activeSessions: activeVAsFormatted.length,
|
||||
projectsWithActivity: projectsWithActiveWorkers
|
||||
((totalHoursLogged / totalDedicatedHours) * 100).toFixed(2) + '%' : '0%'
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -386,7 +353,7 @@ async function client_dashboard(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
// Helper function to format time (same as in va_log_work_report_callback)
|
||||
// Helper function to format time
|
||||
function formatTime(seconds) {
|
||||
const h = Math.floor(seconds / 3600);
|
||||
const m = Math.floor((seconds % 3600) / 60);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import VaClientRepository from "../../repository/vaClient.repository.js";
|
||||
import VaClientService from "../../services/vaClient.service.js";
|
||||
import logger from "../../config/logger.js";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
const vaClientService = new VaClientService(new VaClientRepository());
|
||||
|
||||
|
|
@ -51,9 +52,9 @@ async function va_register_client(req, res) {
|
|||
}
|
||||
|
||||
// Additional controller methods can be added here
|
||||
async function get_client_by_email(req, res) {
|
||||
async function get_client_profile(req, res) {
|
||||
try {
|
||||
const { email } = req.params;
|
||||
const email = req.body.clientEmail;
|
||||
const client = await vaClientService.getClientByEmail(email);
|
||||
|
||||
if (!client) {
|
||||
|
|
@ -179,9 +180,130 @@ async function update_client(req, res) {
|
|||
}
|
||||
}
|
||||
|
||||
async function get_client_dashboard_profile(req, res) {
|
||||
try {
|
||||
const accessToken = req.headers.token;
|
||||
|
||||
if (!accessToken) {
|
||||
return res.status(401).json({ success: false, message: "Missing token" });
|
||||
}
|
||||
|
||||
const decoded = jwt.verify(accessToken, process.env.JWT_SECRET_ACCESS_TOKEN);
|
||||
|
||||
if (!decoded || !decoded.email) {
|
||||
return res.status(401).json({ success: false, message: "Invalid token" });
|
||||
}
|
||||
|
||||
const clientEmail = decoded.email;
|
||||
|
||||
// Use the new method that returns only necessary fields
|
||||
const client = await vaClientService.getClientProfileByEmail(clientEmail);
|
||||
|
||||
if (!client) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Client not found"
|
||||
});
|
||||
}
|
||||
|
||||
// Format the response to only include userDetails
|
||||
const profileData = {
|
||||
name: client.userDetails?.name || '',
|
||||
email: client.userDetails?.email || '',
|
||||
address: client.userDetails?.address || '',
|
||||
city: client.userDetails?.city || '',
|
||||
state: client.userDetails?.state || '',
|
||||
zip: client.userDetails?.zip || '',
|
||||
position: client.userDetails?.position || ''
|
||||
};
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
data: profileData
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(`ClientController - Get dashboard profile error: ${error.message}`);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Internal Server Error"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function update_client_password(req, res) {
|
||||
logger.info("ClientController - Update Client Password Hit ...");
|
||||
console.log("Update Client Password - Request Body:", req.body);
|
||||
try {
|
||||
const accessToken = req.headers.token;
|
||||
|
||||
if (!accessToken) {
|
||||
return res.status(401).json({ success: false, message: "Missing token" });
|
||||
}
|
||||
|
||||
const decoded = jwt.verify(accessToken, process.env.JWT_SECRET_ACCESS_TOKEN);
|
||||
|
||||
if (!decoded || !decoded.email) {
|
||||
return res.status(401).json({ success: false, message: "Invalid token" });
|
||||
}
|
||||
|
||||
const clientEmail = decoded.email;
|
||||
const payload = req.body || {};
|
||||
const { userDetails } = payload;
|
||||
|
||||
// Get client by email to get the ID
|
||||
const client = await vaClientService.getClientByEmail(clientEmail);
|
||||
|
||||
if (!client) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Client not found"
|
||||
});
|
||||
}
|
||||
|
||||
const clientId = client._id;
|
||||
|
||||
// Call service to update password
|
||||
const result = await vaClientService.updateClientPassword(clientId, userDetails);
|
||||
|
||||
logger.info(`ClientController - Client password updated successfully: ${clientEmail}`);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: "Password updated successfully",
|
||||
data: result
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
logger.error(`ClientController - Update password error: ${error.message}`);
|
||||
|
||||
if (error.message === "Client not found") {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
|
||||
if (error.message.includes("Current password is incorrect") ||
|
||||
error.message.includes("New passwords do not match") ||
|
||||
error.message.includes("All password fields are required")) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "Internal Server Error"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
va_register_client,
|
||||
get_client_by_email,
|
||||
get_client_profile,
|
||||
delete_client,
|
||||
update_client
|
||||
update_client,
|
||||
get_client_dashboard_profile,
|
||||
update_client_password
|
||||
};
|
||||
|
|
@ -5,7 +5,7 @@ import { updateEntityRelationships } from "../../helper/updateEntityRelationship
|
|||
async function project_add_sf(req, res) {
|
||||
try {
|
||||
const payload = req.body|| {};
|
||||
const { name, hourlyRate, clientId, vaAssigned, dedicatedHours } = payload;
|
||||
const { name, hourlyRate, clientId, vaAssigned, dedicatedHours, vaWorkingScheduleStart, vaWorkingScheduleEnd, isFlexibleAllowedPt, vaWorkingDelayAllowedStart, vaWorkingDelayAllowedEnd } = payload;
|
||||
|
||||
// Validate required fields
|
||||
if (!name) {
|
||||
|
|
@ -65,6 +65,11 @@ async function project_add_sf(req, res) {
|
|||
clientId: clientObjectId,
|
||||
vaAssigned: vaAssignedArray,
|
||||
dedicatedHours: dedicatedHours ? parseFloat(dedicatedHours) : 0,
|
||||
vaWorkingScheduleStart: vaWorkingScheduleStart || null,
|
||||
vaWorkingScheduleEnd: vaWorkingScheduleEnd || null,
|
||||
isFlexibleAllowedPt: isFlexibleAllowedPt || true,
|
||||
vaWorkingDelayAllowedStart: vaWorkingDelayAllowedStart || null,
|
||||
vaWorkingDelayAllowedEnd: vaWorkingDelayAllowedEnd || null
|
||||
};
|
||||
|
||||
const created = await ProjectModel.create(toCreate);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,12 @@ async function update_project_sf(req, res) {
|
|||
vaAssigned,
|
||||
dedicatedHours,
|
||||
status,
|
||||
totalLoggedHours
|
||||
totalLoggedHours ,
|
||||
vaWorkingScheduleStart,
|
||||
vaWorkingScheduleEnd,
|
||||
isFlexibleAllowedPt,
|
||||
vaWorkingDelayAllowedStart,
|
||||
vaWorkingDelayAllowedEnd
|
||||
} = payload;
|
||||
|
||||
// Validate projectId
|
||||
|
|
@ -88,6 +93,27 @@ async function update_project_sf(req, res) {
|
|||
updateData.status = status;
|
||||
}
|
||||
|
||||
// Update VA working schedule if provided
|
||||
if (vaWorkingScheduleStart !== undefined) {
|
||||
updateData.vaWorkingScheduleStart = vaWorkingScheduleStart || null;
|
||||
}
|
||||
|
||||
if (vaWorkingScheduleEnd !== undefined) {
|
||||
updateData.vaWorkingScheduleEnd = vaWorkingScheduleEnd || null;
|
||||
}
|
||||
|
||||
if (isFlexibleAllowedPt !== undefined) {
|
||||
updateData.isFlexibleAllowedPt = isFlexibleAllowedPt;
|
||||
}
|
||||
|
||||
if (vaWorkingDelayAllowedStart !== undefined) {
|
||||
updateData.vaWorkingDelayAllowedStart = vaWorkingDelayAllowedStart || null;
|
||||
}
|
||||
|
||||
if (vaWorkingDelayAllowedEnd !== undefined) {
|
||||
updateData.vaWorkingDelayAllowedEnd = vaWorkingDelayAllowedEnd || null;
|
||||
}
|
||||
|
||||
// Handle VA assignments - this requires relationship updates
|
||||
if (vaAssigned !== undefined) {
|
||||
let newVaAssignedArray = [];
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ async function va_leave_apply_function(req, res) {
|
|||
totalDays: totalDays,
|
||||
leaveType,
|
||||
comment: processedComment.processedHTML,
|
||||
attachments: processedComment.extractedImages,
|
||||
// attachments: processedComment.extractedImages,
|
||||
status: "PENDING"
|
||||
},
|
||||
// SyncSalesforce: result
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ async function va_profile_update_callback(req, res) {
|
|||
|
||||
|
||||
const payload = req.body || {};
|
||||
const { userDetails } = payload;
|
||||
const { userDetails, status } = payload;
|
||||
|
||||
if (!userDetails) {
|
||||
return res.status(400).json({ success: false, message: "Missing userDetails" });
|
||||
|
|
@ -136,6 +136,11 @@ async function va_profile_update_callback(req, res) {
|
|||
});
|
||||
}
|
||||
|
||||
if (status) {
|
||||
vaUser.status = status;
|
||||
updatedFields.push('status');
|
||||
}
|
||||
|
||||
await vaUser.save();
|
||||
|
||||
const updatedUser = await VAModel.findById(vaUser._id)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { LoggedModel, WorkTrackModel, ProjectModel } from "../../../models/vaModel.js";
|
||||
import { LoggedModel, WorkTrackModel, ProjectModel, VAModel } from "../../../models/vaModel.js";
|
||||
|
||||
// Helper function to get start and end of day in UTC
|
||||
function getDayRange(date = new Date()) {
|
||||
|
|
@ -47,12 +47,6 @@ function parseISOTimeString(timeString) {
|
|||
}
|
||||
}
|
||||
|
||||
function setMillisecondsToZero(date) {
|
||||
const newDate = new Date(date);
|
||||
newDate.setMilliseconds(0);
|
||||
return newDate;
|
||||
}
|
||||
|
||||
// Helper function to check if time difference is less than threshold
|
||||
function isTimeWithinThreshold(receivedTime, currentTime, thresholdSeconds = 10) {
|
||||
const diffMs = Math.abs(currentTime - receivedTime);
|
||||
|
|
@ -68,6 +62,89 @@ function getCurrentUTCTime() {
|
|||
return now;
|
||||
}
|
||||
|
||||
// function parseTimeToMinutes(timeString) {
|
||||
// if (!timeString) return null;
|
||||
|
||||
// const [hours, minutes] = timeString.split(':').map(Number);
|
||||
// return hours * 60 + (minutes || 0);
|
||||
// }
|
||||
|
||||
// function parseDelayToMinutes(delayString) {
|
||||
// if (!delayString) return 0;
|
||||
|
||||
// if (delayString.includes('h')) {
|
||||
// const hours = parseInt(delayString.replace('h', '').trim());
|
||||
// return hours * 60;
|
||||
// } else if (delayString.includes('m')) {
|
||||
// return parseInt(delayString.replace('m', '').trim());
|
||||
// }
|
||||
|
||||
// return parseInt(delayString) || 0; // Default to minutes if no unit specified
|
||||
// }
|
||||
|
||||
// function checkScheduleCompliance(currentTime, project, vaStatus, type) {
|
||||
// const warnings = [];
|
||||
|
||||
// // If project doesn't have schedule or VA is PARTTIME with flexible allowed, no schedule restrictions
|
||||
// if (!project.vaWorkingScheduleStart || !project.vaWorkingScheduleEnd) {
|
||||
// return { isCompliant: true, warnings };
|
||||
// }
|
||||
|
||||
// const currentDate = new Date(currentTime);
|
||||
// const currentMinutes = currentDate.getUTCHours() * 60 + currentDate.getUTCMinutes();
|
||||
|
||||
// const scheduleStartMinutes = parseTimeToMinutes(project.vaWorkingScheduleStart);
|
||||
// const scheduleEndMinutes = parseTimeToMinutes(project.vaWorkingScheduleEnd);
|
||||
// const allowedStartDelay = parseDelayToMinutes(project.vaWorkingDelayAllowedStart);
|
||||
// const allowedEndDelay = parseDelayToMinutes(project.vaWorkingDelayAllowedEnd);
|
||||
|
||||
// // Calculate allowed time ranges
|
||||
// const allowedStartMinutes = scheduleStartMinutes - allowedStartDelay;
|
||||
// const allowedEndMinutes = scheduleEndMinutes + allowedEndDelay;
|
||||
|
||||
// console.log(`Schedule Check - Current: ${currentMinutes}, Start: ${scheduleStartMinutes}, End: ${scheduleEndMinutes}, Allowed Start: ${allowedStartMinutes}, Allowed End: ${allowedEndMinutes}`);
|
||||
|
||||
// // Check for PARTTIME with flexible schedule
|
||||
// if (vaStatus === "PARTTIME" && project.isFlexibleAllowedPt) {
|
||||
// return { isCompliant: true, warnings };
|
||||
// }
|
||||
|
||||
// // For all other cases, check schedule compliance
|
||||
// if (type === "LOGIN") {
|
||||
// // Check if login is too early
|
||||
// if (currentMinutes < allowedStartMinutes) {
|
||||
// warnings.push("early_login");
|
||||
// }
|
||||
|
||||
// // Check if login is after shift end
|
||||
// if (currentMinutes > scheduleEndMinutes) {
|
||||
// warnings.push("working_after_shift_end");
|
||||
// }
|
||||
|
||||
// // Check if login is within allowed range
|
||||
// // const isWithinAllowedRange = currentMinutes >= allowedStartMinutes && currentMinutes <= allowedEndMinutes;
|
||||
|
||||
// return {
|
||||
// isCompliant: true, // Allow login regardless of time
|
||||
// warnings
|
||||
// };
|
||||
|
||||
// } else if (type === "LOGOUT") {
|
||||
// // Check if logout is too late
|
||||
// if (currentMinutes > allowedEndMinutes) {
|
||||
// warnings.push("late_logout");
|
||||
// }
|
||||
|
||||
// // For logout, we're generally more permissive - allow logout even if late
|
||||
// return {
|
||||
// isCompliant: true, // Allow logout regardless of time
|
||||
// warnings
|
||||
// };
|
||||
// }
|
||||
|
||||
// return { isCompliant: true, warnings };
|
||||
// }
|
||||
|
||||
// function to close open work tracks and create logout
|
||||
async function closePreviousSession(vaId, lastLog, logTime = new Date()) {
|
||||
try {
|
||||
|
|
@ -164,7 +241,7 @@ async function va_project_log_callback(req, res) {
|
|||
try {
|
||||
const payload = req.body || {};
|
||||
const { vaId, vaEmail, projectId, type, time: receivedTimeString } = payload;
|
||||
console.log("Received payload:", payload);
|
||||
// console.log("Received payload:", payload);
|
||||
|
||||
if (!vaId || !vaEmail || !projectId || !type) {
|
||||
return res.status(400).send("Missing required properties");
|
||||
|
|
@ -189,8 +266,6 @@ async function va_project_log_callback(req, res) {
|
|||
console.log(`Received: ${receivedTimeString} (parsed: ${receivedTime.toISOString()})`);
|
||||
console.log(`Current: ${currentTime.toISOString()}`);
|
||||
}
|
||||
} else {
|
||||
console.log(`ℹ️ No time received, using current UTC time: ${currentTime.toISOString()}`);
|
||||
}
|
||||
|
||||
const project = await ProjectModel.findById(projectId);
|
||||
|
|
@ -198,6 +273,22 @@ async function va_project_log_callback(req, res) {
|
|||
return res.status(400).json({ success: false, message: "Project not found" });
|
||||
}
|
||||
|
||||
const vaUser = await VAModel.findById(vaId);
|
||||
if (!vaUser) {
|
||||
return res.status(400).json({ success: false, message: "VA not found" });
|
||||
}
|
||||
|
||||
// Check schedule compliance
|
||||
// const scheduleCheck = checkScheduleCompliance(logTime, project, vaUser.status, type);
|
||||
// console.log(`Schedule compliance check:`, scheduleCheck);
|
||||
// if (!scheduleCheck.isCompliant) {
|
||||
// return res.status(400).json({
|
||||
// success: false,
|
||||
// message: `Cannot ${type.toLowerCase()} - outside of allowed schedule time`,
|
||||
// warnings: scheduleCheck.warnings
|
||||
// });
|
||||
// }
|
||||
|
||||
// For LOGIN requests, check daily hours (using UTC day range)
|
||||
if (type === "LOGIN") {
|
||||
const { start, end } = getDayRange(); // UTC day range
|
||||
|
|
@ -218,7 +309,8 @@ async function va_project_log_callback(req, res) {
|
|||
if (project.dedicatedHours > 0 && totalTodayHours >= project.dedicatedHours) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: `Cannot login - daily hours already completed (${formatHoursToReadable(totalTodayHours)} / ${formatHoursToReadable(project.dedicatedHours)})`
|
||||
message: `Cannot login - daily hours already completed (${formatHoursToReadable(totalTodayHours)} / ${formatHoursToReadable(project.dedicatedHours)})`,
|
||||
// warnings: scheduleCheck.warnings
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -245,17 +337,57 @@ async function va_project_log_callback(req, res) {
|
|||
time: logTime
|
||||
});
|
||||
|
||||
return res.status(201).send({
|
||||
try {
|
||||
const salesforceUrl = `${process.env.SF_DOCTRACKER_API_URL}services/apexrest/docva/api/va-project-log`;
|
||||
const sfData = {
|
||||
"_id": createdLog._id,
|
||||
"loggedType": "LOGIN",
|
||||
"vaId": vaId,
|
||||
"vaEmail": vaEmail,
|
||||
"projectId": projectId,
|
||||
"time": createdLog.time,
|
||||
}
|
||||
|
||||
const response = await fetch(salesforceUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
// Add any required headers for Salesforce authentication
|
||||
// 'Authorization': 'Bearer ' + process.env.SF_ACCESS_TOKEN
|
||||
},
|
||||
body: JSON.stringify(sfData)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
throw new Error(`Salesforce API responded with status ${response.status}: ${errorText}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
// console.log("✅ Successfully synced VA data to Salesforce:", result);
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
message: `Login Successful (previous session closed)`,
|
||||
message: `${type} Successfully`,
|
||||
logId: createdLog._id,
|
||||
SyncSalesforce: result,
|
||||
previousSession: {
|
||||
closedWorkTracks: closeResult.closedWorkTracks,
|
||||
logoutLogId: closeResult.logoutLogId
|
||||
},
|
||||
timeUsed: receivedTimeString ? 'received' : 'current',
|
||||
actualTime: createdLog.time
|
||||
actualTime: createdLog.time,
|
||||
// warnings: scheduleCheck.warnings
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to sync with Salesforce:", error.message);
|
||||
console.log(error)
|
||||
|
||||
// Create a custom error to distinguish Salesforce errors
|
||||
const salesforceError = new Error(`Salesforce sync failed: ${error.message}`);
|
||||
salesforceError.isSalesforceError = true;
|
||||
throw salesforceError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -302,7 +434,8 @@ async function va_project_log_callback(req, res) {
|
|||
logId: createdLog._id,
|
||||
SyncSalesforce: result,
|
||||
timeUsed: receivedTimeString ? 'received' : 'current',
|
||||
actualTime: createdLog.time
|
||||
actualTime: createdLog.time,
|
||||
// warnings: scheduleCheck.warnings
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to sync with Salesforce:", error.message);
|
||||
|
|
|
|||
|
|
@ -101,7 +101,27 @@ const projectSchema = new Schema({
|
|||
type: String,
|
||||
enum: ["ACTIVE", "INACTIVE"],
|
||||
default: "ACTIVE"
|
||||
}
|
||||
},
|
||||
vaWorkingScheduleStart: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
vaWorkingScheduleEnd: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
isFlexibleAllowedPt: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
vaWorkingDelayAllowedStart: {
|
||||
type: String,
|
||||
default: '5m'
|
||||
},
|
||||
vaWorkingDelayAllowedEnd: {
|
||||
type: String,
|
||||
default: '5m'
|
||||
},
|
||||
});
|
||||
|
||||
/* ---------------------- Client Details Schema ---------------------- */
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class VaClientRepository {
|
|||
|
||||
async findByEmail(email) {
|
||||
try {
|
||||
const response = await ClientModel.findOne({ "userDetails.email": email.toLowerCase() });
|
||||
const response = await ClientModel.findOne({ "userDetails.email": email });
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
|
|
@ -59,6 +59,50 @@ class VaClientRepository {
|
|||
}
|
||||
}
|
||||
|
||||
async findProfileByEmail(email) {
|
||||
try {
|
||||
const response = await ClientModel.findOne(
|
||||
{ "userDetails.email": email },
|
||||
{
|
||||
// Only specify the fields you want to include
|
||||
"userDetails.name": 1,
|
||||
"userDetails.email": 1,
|
||||
"userDetails.address": 1,
|
||||
"userDetails.city": 1,
|
||||
"userDetails.state": 1,
|
||||
"userDetails.zip": 1,
|
||||
"userDetails.position": 1
|
||||
// Don't include any exclusion fields (0) when using inclusion (1)
|
||||
}
|
||||
).lean(); // Use lean() for better performance since we don't need mongoose document
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Alternative: If you need to be more explicit about excluding sensitive fields
|
||||
async findProfileByEmailExplicit(email) {
|
||||
try {
|
||||
const response = await ClientModel.findOne(
|
||||
{ "userDetails.email": email }
|
||||
).select({
|
||||
'userDetails.name': 1,
|
||||
'userDetails.email': 1,
|
||||
'userDetails.address': 1,
|
||||
'userDetails.city': 1,
|
||||
'userDetails.state': 1,
|
||||
'userDetails.zip': 1,
|
||||
'userDetails.position': 1
|
||||
}).lean();
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async delete(id, options = {}) {
|
||||
try {
|
||||
const response = await ClientModel.findByIdAndDelete(id, options);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import express from "express";
|
||||
const clientRoutes = express.Router();
|
||||
|
||||
import { va_register_client, delete_client, update_client } from "../../controllers/client/vaClient.controller.js";
|
||||
import { va_register_client, delete_client, update_client, get_client_dashboard_profile, update_client_password } from "../../controllers/client/vaClient.controller.js";
|
||||
// import { va_clients_callback } from "../../controllers/va/vaClients/vaClients.controller.js";
|
||||
import { va_clients_projects_callback } from "../../controllers/va/vaClients/vaClientProject.controller.js";
|
||||
import { va_login_client } from "../../controllers/client/vaClientLogin.controller.js";
|
||||
|
|
@ -21,8 +21,6 @@ clientRoutes.get("/refreshToken", client_refresh_token_callback); // Client Refr
|
|||
clientRoutes.post("/forgot-password", client_request_password_reset);
|
||||
clientRoutes.post("/verify-client-email", client_verify_email);
|
||||
clientRoutes.post("/logout", clientAuthValidator, client_logout_callback);
|
||||
clientRoutes.patch("/:clientId", update_client);
|
||||
clientRoutes.delete("/:clientId", delete_client);
|
||||
|
||||
// clientRoutes.get("/:clientID?", va_clients_callback); // VA Clients Callback for getting all VA's or specific client by ID (NC)
|
||||
clientRoutes.get("/:clientId/projects/:projectId", va_clients_projects_callback); // VA Clients Projects Callback (NC)
|
||||
|
|
@ -33,6 +31,10 @@ clientRoutes.get("/:clientId/projects/:projectId", va_clients_projects_callback)
|
|||
clientRoutes.get("/dashboard", clientAuthValidator, client_dashboard); // VA Clients Projects Callback
|
||||
clientRoutes.post("/dashboard/va-report", clientAuthValidator, client_dashboard_va_log); // VA details
|
||||
clientRoutes.get("/dashboard-projects", clientAuthValidator, client_dashboard_projects); // VA Clients Projects Callback
|
||||
clientRoutes.get("/profile", clientAuthValidator, get_client_dashboard_profile);
|
||||
clientRoutes.patch("/profile", clientAuthValidator, update_client_password);
|
||||
clientRoutes.patch("/:clientId", update_client);
|
||||
clientRoutes.delete("/:clientId", delete_client);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ vaRoutes.get("/leaves/all", authValidator, va_leave_list_function); // Get all l
|
|||
vaRoutes.get("/leaves/status/:status", authValidator, va_leave_list_function); // Leaves Filter by status
|
||||
vaRoutes.get("/leaves/type/:leaveType", authValidator, va_leave_list_function); // Filter by leave type
|
||||
vaRoutes.get("/leaves/status/:status/type/:leaveType", authValidator, va_leave_list_function); // leaves Filter
|
||||
vaRoutes.post("/leave/request", authValidator, va_leave_apply_function); // Timesheet Adjustment for VA
|
||||
vaRoutes.post("/leave/request", authValidator, va_leave_apply_function); // Leave for VA
|
||||
vaRoutes.patch("/leave/:leaveId", va_leave_manage_function);
|
||||
|
||||
// timesheet adjustment routes
|
||||
|
|
|
|||
|
|
@ -154,7 +154,17 @@ app.get('/client/projects', async (req, res) => {
|
|||
res.render('client/dashboard-projects');
|
||||
} catch (error) {
|
||||
console.error('Projects error:', error);
|
||||
res.status(500).render('client/dashboard-projects', { error: 'Failed to load virtual assistants' });
|
||||
res.status(500).render('client/dashboard-projects', { error: 'Failed to load projects' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/client/profile', async (req, res) => {
|
||||
try {
|
||||
// const vaData = await virtualAssistantService.getClientVAs(req.user.id);
|
||||
res.render('client/dashboard-profile');
|
||||
} catch (error) {
|
||||
console.error('Projects error:', error);
|
||||
res.status(500).render('client/dashboard-profile', { error: 'Failed to load profile' });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import logger from "../config/logger.js";
|
||||
import SalesforceService from "./salesforce.service.js";
|
||||
import { VAModel, ProjectModel, LoggedModel, WorkTrackModel } from "../models/vaModel.js";
|
||||
import bcrypt from "bcrypt";
|
||||
|
||||
class VaClientService {
|
||||
constructor(vaClientRepository) {
|
||||
|
|
@ -197,6 +198,70 @@ class VaClientService {
|
|||
}
|
||||
}
|
||||
|
||||
async getClientProfileByEmail(email) {
|
||||
try {
|
||||
const response = await this.clientRepository.findProfileByEmail(email);
|
||||
return response;
|
||||
} catch (error) {
|
||||
logger.error("Client Service - getClientProfileByEmail error: " + error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async updateClientPassword(id, passwordData) {
|
||||
try {
|
||||
// Check if client exists
|
||||
const existingClient = await this.clientRepository.findById(id);
|
||||
if (!existingClient) {
|
||||
throw new Error("Client not found");
|
||||
}
|
||||
|
||||
const { currentPassword, newPassword, confirmPassword } = passwordData;
|
||||
|
||||
// Validate required fields
|
||||
if (!currentPassword || !newPassword || !confirmPassword) {
|
||||
throw new Error("All password fields are required");
|
||||
}
|
||||
|
||||
// Validate password match
|
||||
if (newPassword !== confirmPassword) {
|
||||
throw new Error("New passwords do not match");
|
||||
}
|
||||
|
||||
// Verify current password
|
||||
const isMatch = await bcrypt.compare(currentPassword, existingClient.userDetails.password);
|
||||
if (!isMatch) {
|
||||
throw new Error("Current password is incorrect");
|
||||
}
|
||||
|
||||
// Hash new password
|
||||
const saltRounds = 10;
|
||||
const hashedPassword = await bcrypt.hash(newPassword, saltRounds);
|
||||
|
||||
// Prepare update data
|
||||
const updateData = {
|
||||
userDetails: {
|
||||
password: hashedPassword
|
||||
}
|
||||
};
|
||||
|
||||
// Update the client password
|
||||
const updatedClient = await this.clientRepository.update(id, updateData);
|
||||
|
||||
logger.info(`Client password updated successfully: ${id}`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Password updated successfully",
|
||||
clientId: id
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
logger.error("Client Service - updateClientPassword error: " + error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to sanitize data
|
||||
sanitizeClientData(payload) {
|
||||
const { userDetails } = payload;
|
||||
|
|
|
|||
|
|
@ -34,16 +34,6 @@
|
|||
<i class="fas fa-file-invoice"></i>Projects
|
||||
</a>
|
||||
</li>
|
||||
<!-- <li class="nav-item">
|
||||
<a href="/client/timesheets" class="nav-button">
|
||||
<i class="fas fa-clock"></i>Timesheets
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="/client/referrals" class="nav-button">
|
||||
<i class="fas fa-share-alt"></i>Referrals
|
||||
</a>
|
||||
</li> -->
|
||||
</ul>
|
||||
|
||||
<button class="mobile-menu-button">
|
||||
|
|
@ -54,9 +44,6 @@
|
|||
</nav>
|
||||
<div class="dashboard-container">
|
||||
<aside class="dashboard-sidebar">
|
||||
<!-- <div class="sidebar-header">
|
||||
<h2 class="sidebar-title">DocVA Client Portal</h2>
|
||||
</div> -->
|
||||
<nav class="sidebar-nav">
|
||||
<ul class="sidebar-list">
|
||||
<li class="sidebar-item">
|
||||
|
|
@ -77,18 +64,12 @@
|
|||
<span>Projects</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- <li class="sidebar-item">
|
||||
<a href="/client/invoices" class="sidebar-link">
|
||||
<i class="fas fa-file-invoice sidebar-icon"></i>
|
||||
<span>Invoices</span>
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/profile" class="sidebar-link">
|
||||
<i class="fas fa-user sidebar-icon"></i>
|
||||
<span>Profile</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/referrals" class="sidebar-link">
|
||||
<i class="fas fa-share-alt sidebar-icon"></i>
|
||||
<span>Referrals</span>
|
||||
</a>
|
||||
</li> -->
|
||||
<li class="sidebar-item">
|
||||
<a href="javascript:void(0);" class="sidebar-link" id="logoutButton">
|
||||
<i class="fas fa-sign-out-alt sidebar-icon"></i>
|
||||
|
|
@ -142,7 +123,6 @@
|
|||
<div class="content-section">
|
||||
<div class="section-header">
|
||||
<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">
|
||||
|
|
@ -151,9 +131,9 @@
|
|||
<tr>
|
||||
<th>Status</th>
|
||||
<th>Virtual Assistant</th>
|
||||
<th>Projects Assigned</th>
|
||||
<th>Active Projects</th>
|
||||
<th>Worked Time</th>
|
||||
<th>Active Project</th>
|
||||
<th>Total Projects</th>
|
||||
<th>Today Logged Hours</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -174,6 +154,55 @@
|
|||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<div id="vaModal" class="modal-overlay">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="display: flex;align-items: center;justify-content: space-between;">
|
||||
<h2 class="modal-title" id="modalVAName">VA Details</h2>
|
||||
<button class="modal-close" onclick="closeVAModal()">
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<!-- Projects Section -->
|
||||
<div class="va-details-section">
|
||||
<h3 class="va-section-title">
|
||||
<i class="fas fa-briefcase"></i>
|
||||
Projects
|
||||
<span class="va-count-badge" id="projectsCountBadge">0</span>
|
||||
</h3>
|
||||
|
||||
<div class="va-table-container">
|
||||
<table class="va-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Project Name</th>
|
||||
<th>Hourly Rate</th>
|
||||
<th>Worked Time</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="modalProjectsTableBody">
|
||||
<!-- Project details will be loaded here -->
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="modalNoProjects" class="no-vas-message" style="display: none;">
|
||||
<i class="fas fa-briefcase"></i>
|
||||
<h4>No Projects</h4>
|
||||
<p>This VA is not assigned to any projects.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Button -->
|
||||
<div class="modal-actions" id="modalActions" style="display: none;">
|
||||
<a href="#" class="view-session-btn" id="viewSessionBtn" target="_blank">
|
||||
<i class="fas fa-eye"></i>
|
||||
View Live Session
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
// Theme management
|
||||
|
|
@ -256,20 +285,88 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Create VA card HTML
|
||||
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">
|
||||
<div class="project-name">${project.name}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span class="hourly-rate">$${project.hourlyRate}/hr</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="worked-time">${project.totalWorkedTime}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="status-badge ${statusClass}">
|
||||
<span class="status-text">${statusText}</span>
|
||||
</div>
|
||||
</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">
|
||||
<i class="fas fa-eye"></i>
|
||||
View
|
||||
</a>` : '';
|
||||
const viewLink = va.isCurrentlyActive ? `<a href="/live/${va.lastProjectId}/${va.id}" class="view-link" data-va-id="${va.id}" target="_blank">Live Tracking</a>` : '';
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<tr class="va-row" data-va-id="${va.id}">
|
||||
<td>
|
||||
<div class="status-indicator">
|
||||
<span class="status-text ${statusClass}">${statusText}</span>
|
||||
|
|
@ -303,7 +400,6 @@
|
|||
const response = await fetchWithAuth(`${API_BASE}/dashboard`);
|
||||
if (!response) return;
|
||||
const result = await response.json();
|
||||
// console.log(data)
|
||||
|
||||
if (result.success) {
|
||||
const data = result.data;
|
||||
|
|
@ -320,22 +416,26 @@
|
|||
// Update VA table
|
||||
const vaTableBody = document.getElementById('vaTableBody');
|
||||
const vaEmptyState = document.getElementById('vaEmptyState');
|
||||
const allVAs = data.allVAs?.total || [];
|
||||
const allVAs = data.allVAs || [];
|
||||
|
||||
if (allVAs.length > 0) {
|
||||
vaTableBody.innerHTML = allVAs.map(va => createVATableRow(va)).join('');
|
||||
vaTableBody.style.display = '';
|
||||
vaEmptyState.style.display = 'none';
|
||||
|
||||
// Add event listeners to view links
|
||||
// document.querySelectorAll('.view-link').forEach(link => {
|
||||
// link.addEventListener('click', function(e) {
|
||||
// e.preventDefault();
|
||||
// const vaId = this.getAttribute('data-va-id');
|
||||
// // You can update this link as needed
|
||||
// window.location.href = `/client/virtual-assistants/${vaId}`;
|
||||
// });
|
||||
// });
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
vaTableBody.innerHTML = '';
|
||||
vaTableBody.style.display = 'none';
|
||||
|
|
@ -369,10 +469,23 @@
|
|||
vaEmptyState.style.display = 'block';
|
||||
}
|
||||
|
||||
// Close modal when clicking outside
|
||||
vaModal.addEventListener('click', (e) => {
|
||||
if (e.target === vaModal) {
|
||||
closeVAModal();
|
||||
}
|
||||
});
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Load dashboard data
|
||||
loadDashboardData();
|
||||
|
|
@ -386,9 +499,12 @@
|
|||
|
||||
// Logout button
|
||||
const logoutButton = document.getElementById('logoutButton');
|
||||
logoutButton.addEventListener('click', handleLogout);
|
||||
logoutButton.addEventListener('click', () => {
|
||||
if (confirm('Are you sure you want to logout?')) {
|
||||
handleLogout();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,685 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="light">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DocVA Client | Profile</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="/public/css/dashboard.css">
|
||||
<style>
|
||||
.profile-container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.profile-header {
|
||||
margin-bottom: 30px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid #e1e5e9;
|
||||
}
|
||||
|
||||
.profile-title {
|
||||
font-size: 2rem;
|
||||
font-weight: 600;
|
||||
color: #2d3748;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.profile-sections {
|
||||
display: grid;
|
||||
gap: 30px;
|
||||
}
|
||||
|
||||
.profile-section {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
border: 1px solid #e1e5e9;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 25px;
|
||||
padding-bottom: 15px;
|
||||
border-bottom: 1px solid #e1e5e9;
|
||||
}
|
||||
|
||||
.section-icon {
|
||||
font-size: 1.5rem;
|
||||
color: #4299e1;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
color: #2d3748;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 500;
|
||||
color: #4a5568;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.form-input {
|
||||
padding: 12px;
|
||||
border: 1px solid #e1e5e9;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
background: #f7fafc;
|
||||
color: #4a5568;
|
||||
}
|
||||
|
||||
.empty-field {
|
||||
color: #a0aec0;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.password-section {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
.change-password-btn {
|
||||
background: #4299e1;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
font-size: 1rem;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.change-password-btn:hover {
|
||||
background: #3182ce;
|
||||
}
|
||||
|
||||
/* Modal Styles */
|
||||
.modal-overlay {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 1000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 24px;
|
||||
border-bottom: 1px solid #e1e5e9;
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
color: #2d3748;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.25rem;
|
||||
cursor: pointer;
|
||||
color: #718096;
|
||||
padding: 5px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.modal-close:hover {
|
||||
background: #f7fafc;
|
||||
color: #2d3748;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.modal-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.modal-form .form-group {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.modal-form .form-label {
|
||||
font-weight: 500;
|
||||
color: #4a5568;
|
||||
}
|
||||
|
||||
.modal-form .form-input {
|
||||
padding: 12px;
|
||||
border: 1px solid #cbd5e0;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
background: white;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.modal-form .form-input:focus {
|
||||
outline: none;
|
||||
border-color: #4299e1;
|
||||
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
|
||||
}
|
||||
|
||||
.modal-form .form-input.error {
|
||||
border-color: #e53e3e;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #e53e3e;
|
||||
font-size: 0.875rem;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.success-message {
|
||||
color: #38a169;
|
||||
font-size: 0.875rem;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
justify-content: flex-end;
|
||||
margin-top: 30px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #e1e5e9;
|
||||
}
|
||||
|
||||
.save-btn {
|
||||
background: #48bb78;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.save-btn:hover {
|
||||
background: #38a169;
|
||||
}
|
||||
|
||||
.save-btn:disabled {
|
||||
background: #a0aec0;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
background: #e53e3e;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 24px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.cancel-btn:hover {
|
||||
background: #c53030;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="dashboard-body">
|
||||
<div id="root">
|
||||
<nav class="dashboard-header">
|
||||
<div class="header-content">
|
||||
<div class="header-logo">
|
||||
<div class="logo-container">
|
||||
<h2 class="sidebar-title">DocVA Client Portal</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="header-nav">
|
||||
<ul class="nav-list">
|
||||
<li class="nav-item">
|
||||
<a href="/client/dashboard" class="nav-button">
|
||||
<i class="fas fa-chart-bar"></i>Dashboard
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="/client/virtual-assistants" class="nav-button">
|
||||
<i class="fas fa-users"></i>Virtual Assistants
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="/client/projects" class="nav-button">
|
||||
<i class="fas fa-file-invoice"></i>Projects
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<button class="mobile-menu-button">
|
||||
<i class="fas fa-bars"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="dashboard-container">
|
||||
<aside class="dashboard-sidebar">
|
||||
<nav class="sidebar-nav">
|
||||
<ul class="sidebar-list">
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/dashboard" class="sidebar-link">
|
||||
<i class="fas fa-chart-bar sidebar-icon"></i>
|
||||
<span>Dashboard</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/virtual-assistants" class="sidebar-link">
|
||||
<i class="fas fa-users sidebar-icon"></i>
|
||||
<span>Virtual Assistants</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/projects" class="sidebar-link">
|
||||
<i class="fas fa-file-invoice sidebar-icon"></i>
|
||||
<span>Projects</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/profile" class="sidebar-link active">
|
||||
<i class="fas fa-user sidebar-icon"></i>
|
||||
<span>Profile</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<a href="javascript:void(0);" class="sidebar-link" id="logoutButton">
|
||||
<i class="fas fa-sign-out-alt sidebar-icon"></i>
|
||||
<span>Logout</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</aside>
|
||||
<main class="dashboard-main">
|
||||
<div class="dashboard-content">
|
||||
<div class="profile-container">
|
||||
<div class="profile-header">
|
||||
<h1 class="profile-title">Client Profile</h1>
|
||||
</div>
|
||||
|
||||
<div class="profile-sections">
|
||||
<!-- Personal Information -->
|
||||
<div class="profile-section">
|
||||
<div class="section-header">
|
||||
<i class="fas fa-user section-icon"></i>
|
||||
<h2 class="section-title">Personal Information</h2>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Full Name</label>
|
||||
<input type="text" class="form-input" id="name" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Email</label>
|
||||
<input type="email" class="form-input" id="email" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Position</label>
|
||||
<input type="text" class="form-input" id="position" readonly>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Address Information -->
|
||||
<div class="profile-section">
|
||||
<div class="section-header">
|
||||
<i class="fas fa-home section-icon"></i>
|
||||
<h2 class="section-title">Address Information</h2>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Address</label>
|
||||
<input type="text" class="form-input" id="address" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">City</label>
|
||||
<input type="text" class="form-input" id="city" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">State</label>
|
||||
<input type="text" class="form-input" id="state" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">ZIP Code</label>
|
||||
<input type="text" class="form-input" id="zip" readonly>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Password Change Section -->
|
||||
<div class="profile-section">
|
||||
<div class="password-section">
|
||||
<button class="change-password-btn" id="changePasswordBtn">
|
||||
<i class="fas fa-lock"></i>
|
||||
Change Password
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- Change Password Modal -->
|
||||
<div id="passwordModal" class="modal-overlay">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-title">Change Password</h2>
|
||||
<button class="modal-close" onclick="closePasswordModal()">
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="modal-form" id="passwordForm">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Current Password</label>
|
||||
<input type="password" class="form-input" id="currentPassword" required>
|
||||
<div class="error-message" id="currentPasswordError"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">New Password</label>
|
||||
<input type="password" class="form-input" id="newPassword" required>
|
||||
<div class="error-message" id="newPasswordError"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Confirm New Password</label>
|
||||
<input type="password" class="form-input" id="confirmPassword" required>
|
||||
<div class="error-message" id="confirmPasswordError"></div>
|
||||
</div>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="cancel-btn" onclick="closePasswordModal()">Cancel</button>
|
||||
<button type="submit" class="save-btn" id="savePasswordBtn">Change Password</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 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 = '/client/login';
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch(url, {
|
||||
...options,
|
||||
headers: {
|
||||
'token': `${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
localStorage.removeItem('knoptpq');
|
||||
localStorage.removeItem('refreshToken');
|
||||
window.location.href = '/client/login';
|
||||
return;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async function handleLogout() {
|
||||
try {
|
||||
await fetchWithAuth(`${API_BASE}/logout`, { method: 'POST' });
|
||||
} catch (error) {
|
||||
console.error('Logout API error:', error);
|
||||
} finally {
|
||||
localStorage.removeItem('knoptpq');
|
||||
localStorage.removeItem('refreshToken');
|
||||
window.location.href = '/client/login';
|
||||
}
|
||||
}
|
||||
|
||||
// Format empty fields
|
||||
function formatEmptyFields() {
|
||||
const inputs = document.querySelectorAll('.form-input');
|
||||
inputs.forEach(input => {
|
||||
if (!input.value.trim()) {
|
||||
input.value = 'Not provided';
|
||||
input.classList.add('empty-field');
|
||||
} else {
|
||||
input.classList.remove('empty-field');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Load profile data
|
||||
async function loadProfileData() {
|
||||
try {
|
||||
const response = await fetchWithAuth(`${API_BASE}/profile`);
|
||||
if (!response) return;
|
||||
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
const data = result.data;
|
||||
|
||||
// Populate only personal and address information
|
||||
const fieldsToShow = ['name', 'email', 'position', 'address', 'city', 'state', 'zip'];
|
||||
|
||||
fieldsToShow.forEach(key => {
|
||||
const element = document.getElementById(key);
|
||||
if (element && data[key]) {
|
||||
element.value = data[key];
|
||||
}
|
||||
});
|
||||
|
||||
formatEmptyFields();
|
||||
|
||||
} else {
|
||||
console.error('Failed to load profile data:', result.message);
|
||||
alert('Failed to load profile data');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading profile data:', error);
|
||||
alert('Error loading profile data');
|
||||
}
|
||||
}
|
||||
|
||||
// Password Modal Functions
|
||||
function openPasswordModal() {
|
||||
const modal = document.getElementById('passwordModal');
|
||||
modal.style.display = 'flex';
|
||||
document.body.style.overflow = 'hidden';
|
||||
|
||||
// Clear form
|
||||
document.getElementById('passwordForm').reset();
|
||||
clearErrorMessages();
|
||||
}
|
||||
|
||||
function closePasswordModal() {
|
||||
const modal = document.getElementById('passwordModal');
|
||||
modal.style.display = 'none';
|
||||
document.body.style.overflow = 'auto';
|
||||
|
||||
// Clear form and errors
|
||||
document.getElementById('passwordForm').reset();
|
||||
clearErrorMessages();
|
||||
}
|
||||
|
||||
function clearErrorMessages() {
|
||||
document.getElementById('currentPasswordError').textContent = '';
|
||||
document.getElementById('newPasswordError').textContent = '';
|
||||
document.getElementById('confirmPasswordError').textContent = '';
|
||||
}
|
||||
|
||||
// Change password
|
||||
async function changePassword(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const currentPassword = document.getElementById('currentPassword').value;
|
||||
const newPassword = document.getElementById('newPassword').value;
|
||||
const confirmPassword = document.getElementById('confirmPassword').value;
|
||||
|
||||
// Reset errors
|
||||
clearErrorMessages();
|
||||
|
||||
let hasError = false;
|
||||
|
||||
if (!currentPassword) {
|
||||
document.getElementById('currentPasswordError').textContent = 'Current password is required';
|
||||
hasError = true;
|
||||
}
|
||||
|
||||
if (!newPassword) {
|
||||
document.getElementById('newPasswordError').textContent = 'New password is required';
|
||||
hasError = true;
|
||||
} else if (newPassword.length < 6) {
|
||||
document.getElementById('newPasswordError').textContent = 'Password must be at least 6 characters';
|
||||
hasError = true;
|
||||
}
|
||||
|
||||
if (!confirmPassword) {
|
||||
document.getElementById('confirmPasswordError').textContent = 'Please confirm your password';
|
||||
hasError = true;
|
||||
} else if (newPassword !== confirmPassword) {
|
||||
document.getElementById('confirmPasswordError').textContent = 'Passwords do not match';
|
||||
hasError = true;
|
||||
}
|
||||
|
||||
if (hasError) return;
|
||||
|
||||
try {
|
||||
const saveBtn = document.getElementById('savePasswordBtn');
|
||||
saveBtn.disabled = true;
|
||||
saveBtn.textContent = 'Changing Password...';
|
||||
|
||||
const response = await fetchWithAuth(`${API_BASE}/profile`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({
|
||||
userDetails: {
|
||||
currentPassword,
|
||||
newPassword,
|
||||
confirmPassword
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
if (!response) {
|
||||
saveBtn.disabled = false;
|
||||
saveBtn.textContent = 'Change Password';
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
alert('Password changed successfully!');
|
||||
closePasswordModal();
|
||||
} else {
|
||||
alert(result.message || 'Failed to change password');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error changing password:', error);
|
||||
alert('Error changing password');
|
||||
} finally {
|
||||
const saveBtn = document.getElementById('savePasswordBtn');
|
||||
saveBtn.disabled = false;
|
||||
saveBtn.textContent = 'Change Password';
|
||||
}
|
||||
}
|
||||
|
||||
// Event listeners
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadProfileData();
|
||||
|
||||
// Change password button
|
||||
document.getElementById('changePasswordBtn').addEventListener('click', openPasswordModal);
|
||||
|
||||
// Password form submission
|
||||
document.getElementById('passwordForm').addEventListener('submit', changePassword);
|
||||
|
||||
// Close modal when clicking outside
|
||||
document.getElementById('passwordModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closePasswordModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Close modal with escape key
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
closePasswordModal();
|
||||
}
|
||||
});
|
||||
|
||||
// Mobile menu toggle
|
||||
const menuToggle = document.querySelector('.mobile-menu-button');
|
||||
const sidebar = document.querySelector('.dashboard-sidebar');
|
||||
menuToggle.addEventListener('click', () => {
|
||||
sidebar.classList.toggle('active');
|
||||
});
|
||||
|
||||
// Logout button
|
||||
document.getElementById('logoutButton').addEventListener('click', handleLogout);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -78,18 +78,12 @@
|
|||
<span>Projects</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- <li class="sidebar-item">
|
||||
<a href="/client/invoices" class="sidebar-link">
|
||||
<i class="fas fa-file-invoice sidebar-icon"></i>
|
||||
<span>Invoices</span>
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/profile" class="sidebar-link">
|
||||
<i class="fas fa-user sidebar-icon"></i>
|
||||
<span>Profile</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/referrals" class="sidebar-link">
|
||||
<i class="fas fa-share-alt sidebar-icon"></i>
|
||||
<span>Referrals</span>
|
||||
</a>
|
||||
</li> -->
|
||||
<li class="sidebar-item">
|
||||
<a href="javascript:void(0);" class="sidebar-link" id="logoutButton">
|
||||
<i class="fas fa-sign-out-alt sidebar-icon"></i>
|
||||
|
|
@ -115,7 +109,6 @@
|
|||
<th>Hourly Rate</th>
|
||||
<th>Total VA Assigned</th>
|
||||
<th>Dedicated Hours</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="projectsTableBody">
|
||||
|
|
@ -137,8 +130,11 @@
|
|||
</div>
|
||||
<div id="projectModal" class="modal-overlay">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<div class="modal-header" style="display: flex;align-items: center;justify-content: space-between;">
|
||||
<h2 class="modal-title" id="modalProjectName">Project Details</h2>
|
||||
<button class="modal-close" id="modalClose">
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="va-details-section">
|
||||
|
|
@ -352,12 +348,6 @@
|
|||
<td>
|
||||
<span class="dedicated-hours">${dedicatedHours}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="status-badge ${statusClass}">
|
||||
<div class="status-dot ${statusClass}"></div>
|
||||
<span class="status-text">${statusText}</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}
|
||||
|
|
@ -459,8 +449,14 @@
|
|||
|
||||
// Logout button
|
||||
const logoutButton = document.getElementById('logoutButton');
|
||||
logoutButton.addEventListener('click', handleLogout);
|
||||
logoutButton.addEventListener('click', () => {
|
||||
if (confirm('Are you sure you want to logout?')) {
|
||||
handleLogout();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
modalClose.addEventListener('click', closeProjectModal);
|
||||
|
||||
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -34,16 +34,6 @@
|
|||
<i class="fas fa-file-invoice"></i>Projects
|
||||
</a>
|
||||
</li>
|
||||
<!-- <li class="nav-item">
|
||||
<a href="/client/timesheets" class="nav-button">
|
||||
<i class="fas fa-clock"></i>Timesheets
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="/client/referrals" class="nav-button">
|
||||
<i class="fas fa-share-alt"></i>Referrals
|
||||
</a>
|
||||
</li> -->
|
||||
</ul>
|
||||
|
||||
<button class="mobile-menu-button">
|
||||
|
|
@ -54,9 +44,6 @@
|
|||
</nav>
|
||||
<div class="dashboard-container">
|
||||
<aside class="dashboard-sidebar">
|
||||
<!-- <div class="sidebar-header">
|
||||
<h2 class="sidebar-title">DocVA Client Portal</h2>
|
||||
</div> -->
|
||||
<nav class="sidebar-nav">
|
||||
<ul class="sidebar-list">
|
||||
<li class="sidebar-item">
|
||||
|
|
@ -77,18 +64,12 @@
|
|||
<span>Projects</span>
|
||||
</a>
|
||||
</li>
|
||||
<!-- <li class="sidebar-item">
|
||||
<a href="/client/invoices" class="sidebar-link">
|
||||
<i class="fas fa-file-invoice sidebar-icon"></i>
|
||||
<span>Invoices</span>
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/profile" class="sidebar-link">
|
||||
<i class="fas fa-user sidebar-icon"></i>
|
||||
<span>Profile</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="sidebar-item">
|
||||
<a href="/client/referrals" class="sidebar-link">
|
||||
<i class="fas fa-share-alt sidebar-icon"></i>
|
||||
<span>Referrals</span>
|
||||
</a>
|
||||
</li> -->
|
||||
<li class="sidebar-item">
|
||||
<a href="javascript:void(0);" class="sidebar-link" id="logoutButton">
|
||||
<i class="fas fa-sign-out-alt sidebar-icon"></i>
|
||||
|
|
@ -142,7 +123,6 @@
|
|||
<div class="content-section">
|
||||
<div class="section-header">
|
||||
<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">
|
||||
|
|
@ -151,9 +131,9 @@
|
|||
<tr>
|
||||
<th>Status</th>
|
||||
<th>Virtual Assistant</th>
|
||||
<th>Projects Assigned</th>
|
||||
<th>Active Projects</th>
|
||||
<th>Worked Time</th>
|
||||
<th>Active Project</th>
|
||||
<th>Total Projects</th>
|
||||
<th>Today Logged Hours</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -174,6 +154,55 @@
|
|||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<div id="vaModal" class="modal-overlay">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header" style="display: flex;align-items: center;justify-content: space-between;">
|
||||
<h2 class="modal-title" id="modalVAName">VA Details</h2>
|
||||
<button class="modal-close" onclick="closeVAModal()">
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<!-- Projects Section -->
|
||||
<div class="va-details-section">
|
||||
<h3 class="va-section-title">
|
||||
<i class="fas fa-briefcase"></i>
|
||||
Projects
|
||||
<span class="va-count-badge" id="projectsCountBadge">0</span>
|
||||
</h3>
|
||||
|
||||
<div class="va-table-container">
|
||||
<table class="va-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Project Name</th>
|
||||
<th>Hourly Rate</th>
|
||||
<th>Worked Time</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="modalProjectsTableBody">
|
||||
<!-- Project details will be loaded here -->
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="modalNoProjects" class="no-vas-message" style="display: none;">
|
||||
<i class="fas fa-briefcase"></i>
|
||||
<h4>No Projects</h4>
|
||||
<p>This VA is not assigned to any projects.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Button -->
|
||||
<div class="modal-actions" id="modalActions" style="display: none;">
|
||||
<a href="#" class="view-session-btn" id="viewSessionBtn" target="_blank">
|
||||
<i class="fas fa-eye"></i>
|
||||
View Live Session
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
// Theme management
|
||||
|
|
@ -256,20 +285,88 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Create VA card HTML
|
||||
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">
|
||||
<div class="project-name">${project.name}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span class="hourly-rate">$${project.hourlyRate}/hr</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="worked-time">${project.totalWorkedTime}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="status-badge ${statusClass}">
|
||||
<span class="status-text">${statusText}</span>
|
||||
</div>
|
||||
</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">
|
||||
<i class="fas fa-eye"></i>
|
||||
View
|
||||
</a>` : '';
|
||||
const viewLink = va.isCurrentlyActive ? `<a href="/live/${va.lastProjectId}/${va.id}" class="view-link" data-va-id="${va.id}" target="_blank">Live Tracking</a>` : '';
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<tr class="va-row" data-va-id="${va.id}">
|
||||
<td>
|
||||
<div class="status-indicator">
|
||||
<span class="status-text ${statusClass}">${statusText}</span>
|
||||
|
|
@ -303,7 +400,6 @@
|
|||
const response = await fetchWithAuth(`${API_BASE}/dashboard`);
|
||||
if (!response) return;
|
||||
const result = await response.json();
|
||||
// console.log(data)
|
||||
|
||||
if (result.success) {
|
||||
const data = result.data;
|
||||
|
|
@ -320,12 +416,26 @@
|
|||
// Update VA table
|
||||
const vaTableBody = document.getElementById('vaTableBody');
|
||||
const vaEmptyState = document.getElementById('vaEmptyState');
|
||||
const allVAs = data.allVAs?.total || [];
|
||||
const allVAs = data.allVAs || [];
|
||||
|
||||
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;
|
||||
|
||||
// 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';
|
||||
|
|
@ -359,6 +469,20 @@
|
|||
vaEmptyState.style.display = 'block';
|
||||
}
|
||||
|
||||
// Close modal when clicking outside
|
||||
vaModal.addEventListener('click', (e) => {
|
||||
if (e.target === vaModal) {
|
||||
closeVAModal();
|
||||
}
|
||||
});
|
||||
|
||||
// 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);
|
||||
|
||||
|
|
@ -375,9 +499,12 @@
|
|||
|
||||
// Logout button
|
||||
const logoutButton = document.getElementById('logoutButton');
|
||||
logoutButton.addEventListener('click', handleLogout);
|
||||
logoutButton.addEventListener('click', () => {
|
||||
if (confirm('Are you sure you want to logout?')) {
|
||||
handleLogout();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@
|
|||
<div class="input-container">
|
||||
<!-- <input type="text" id="state" class="input-field" placeholder=" " required> -->
|
||||
<select id="state" class="select-field" required>
|
||||
<option value=""></option>
|
||||
<option value="" disable selected style="display: none"></option>
|
||||
<!-- States will be populated by JavaScript -->
|
||||
</select>
|
||||
<label for="state" class="input-label">State *</label>
|
||||
|
|
@ -157,7 +157,7 @@
|
|||
<label for="zip" class="input-label">ZIP *</label>
|
||||
</div>
|
||||
<div class="invalid-feedback" id="zip-error" style="display: none; color: #dc3545; font-size: 12px; margin-top: 5px;">
|
||||
ZIP code should contain only numbers
|
||||
Invalid Zip code
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
|
|
@ -203,7 +203,7 @@
|
|||
<div class="input-container">
|
||||
<!-- <input type="text" id="billing-state" class="input-field" placeholder=" " required> -->
|
||||
<select id="billing-state" class="select-field" required>
|
||||
<option value=""></option>
|
||||
<option value="" disable selected style="display: none"></option>
|
||||
<!-- States will be populated by JavaScript -->
|
||||
</select>
|
||||
<label for="billing-state" class="input-label">State *</label>
|
||||
|
|
@ -353,7 +353,7 @@
|
|||
<div class="form-group">
|
||||
<div class="input-container">
|
||||
<select id="account-type" class="select-field" required>
|
||||
<option value=""></option>
|
||||
<option value="" disable selected style="display: none"></option>
|
||||
<option value="checking">Checking</option>
|
||||
<option value="savings">Savings</option>
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -281,6 +281,15 @@
|
|||
<!-- <div class="location-loading" id="state-loading">Loading states...</div> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-container">
|
||||
<select id="status" class="select-field" required>
|
||||
<option value="FULLTIME" selected>Full Time</option>
|
||||
<option value="PARTTIME">Part Time</option>
|
||||
</select>
|
||||
<label for="status" class="input-label">Status *</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="button" class="btn btn-secondary" onclick="prevStep(1)">Back</button>
|
||||
|
|
@ -300,19 +309,19 @@
|
|||
<label for="phone" class="input-label">Phone Number *</label>
|
||||
<div class="input-container">
|
||||
<input type="tel" id="phone" class="input-field" placeholder=" " pattern="[0-9]*" minlength="10" maxlength="15" oninput="validatePhoneNumber(this)" required>
|
||||
<label for="phone" class="input-label">+ Phone Number</label>
|
||||
<label for="phone" class="input-label">Phone Number</label>
|
||||
</div>
|
||||
<div class="invalid-feedback" id="phone-error" style="display: none; color: #dc3545; font-size: 12px; margin-top: 5px;">
|
||||
Please enter a valid phone number (10-15 digits)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<!-- <div class="form-group">
|
||||
<div class="input-container">
|
||||
<input type="text" id="skype" class="input-field" placeholder=" " oninput="validateSkypeId(this)">
|
||||
<label for="skype" class="input-label">Skype ID</label>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="button" class="btn btn-secondary" onclick="prevStep(2)">Back</button>
|
||||
|
|
|
|||
Loading…
Reference in New Issue