Change the Dashboard Layout when times is up show the alert window but time still run when user handleStop then only stop

This commit is contained in:
JaiPandey425 2025-12-04 11:43:00 +05:30
parent df2b35a4e4
commit 9eeb14ffcd
6 changed files with 36 additions and 20 deletions

View File

@ -462,10 +462,10 @@ ipcMain.handle("get-leave-list", async () => {
} }
}); });
ipcMain.handle("get-adjustments-list", async () => { ipcMain.handle("get-adjustments-list", async (event, vaId: string) => {
try { try {
const res = await api.get("/timesheet/adjustments/list"); const res = await api.get(`/timesheet/adjustments/list?vaId=${vaId}`);
console.log("/timesheet/adjustments/list", res.data); console.log("/timesheet/adjustments/list", res.data);
return { return {

View File

@ -57,7 +57,7 @@ contextBridge.exposeInMainWorld('electron', {
getPayslips: (vaId: string) => ipcRenderer.invoke("get-payslips", vaId), getPayslips: (vaId: string) => ipcRenderer.invoke("get-payslips", vaId),
getLeaveList: () => ipcRenderer.invoke("get-leave-list"), getLeaveList: () => ipcRenderer.invoke("get-leave-list"),
getAdjustmentsList:() => ipcRenderer.invoke("get-adjustments-list"), getAdjustmentsList:(vaId: string) => ipcRenderer.invoke("get-adjustments-list",vaId),
} satisfies Window['electron']); } satisfies Window['electron']);

View File

@ -138,6 +138,7 @@ const DashboardLayout = () => {
// Create a ref to store the stop function so it can be called from the hook // Create a ref to store the stop function so it can be called from the hook
const stopTrackingRef = useRef<(() => Promise<void>) | null>(null); const stopTrackingRef = useRef<(() => Promise<void>) | null>(null);
const limitAlertShownRef = useRef(false);
// Define handleStopTracking FIRST // Define handleStopTracking FIRST
const handleStopTracking = useCallback(async () => { const handleStopTracking = useCallback(async () => {
@ -148,6 +149,9 @@ const DashboardLayout = () => {
return; return;
} }
// Reset alert flag when stopping
limitAlertShownRef.current = false;
let currentStopTime = new Date().toISOString(); let currentStopTime = new Date().toISOString();
const projectId = selectedProject.projectId; const projectId = selectedProject.projectId;
@ -282,25 +286,34 @@ const DashboardLayout = () => {
// NOW define handleLimitExceeded using the defined handleStopTracking // NOW define handleLimitExceeded using the defined handleStopTracking
const handleLimitExceeded = useCallback(async () => { const handleLimitExceeded = useCallback(async () => {
console.log("🚨 LIMIT EXCEEDED - Auto-stopping tracking"); console.log("🚨 LIMIT EXCEEDED - Showing alert (not stopping)");
if (!selectedProject) { if (!selectedProject) {
console.error(" No selected project for limit exceeded"); console.error("❌ No selected project for limit exceeded");
return; return;
} }
console.log("Alert Message 1") // Only show alert once per tracking session
if (limitAlertShownRef.current) {
console.log("⚠️ Alert already shown, skipping");
return;
}
limitAlertShownRef.current = true;
console.log("⏰ Showing limit exceeded alert");
// Show alert to user // Show alert to user
alert( alert(
`⏰ Daily Limit Reached!\n\n` + `⏰ Daily Limit Reached!\n\n` +
`Project: ${selectedProject.projectName}\n` + `Project: ${selectedProject.projectName}\n` +
`Dedicated Hours: ${selectedProject.dedicatedHours}\n\n` + `Dedicated Hours: ${selectedProject.dedicatedHours}\n\n` +
`Your tracking has been stopped automatically because you've reached the daily time limit for this project.` `You've reached the daily time limit for this project.\n` +
`Timer will continue running. Please stop manually when ready.`
); );
console.log("Alert Message 2")
// Stop tracking console.log("✅ Alert shown, timer continues running");
// await handleStopTracking(); }, [selectedProject]);
}, [selectedProject, handleStopTracking]);
// Initialize useActiveAppTracker and store finalizeTracking in ref // Initialize useActiveAppTracker and store finalizeTracking in ref
const { finalizeTracking } = useActiveAppTracker( const { finalizeTracking } = useActiveAppTracker(
@ -384,6 +397,8 @@ const DashboardLayout = () => {
console.log(`⏰ Starting tracking. Remaining time: ${limitCheck.remaining}`); console.log(`⏰ Starting tracking. Remaining time: ${limitCheck.remaining}`);
limitAlertShownRef.current = false;
setLoadingStart(true); setLoadingStart(true);
const now = Date.now(); const now = Date.now();
@ -468,15 +483,15 @@ const DashboardLayout = () => {
// Check if time limit reached // Check if time limit reached
const totalTimeWorked = alreadyWorkedSeconds + timeSinceStart; const totalTimeWorked = alreadyWorkedSeconds + timeSinceStart;
if (totalTimeWorked >= dedicatedSeconds) { if (totalTimeWorked >= dedicatedSeconds && !limitAlertShownRef.current) {
console.warn("🚨 CLIENT-SIDE: Time limit reached!"); console.warn("🚨 CLIENT-SIDE: Time limit reached!");
console.log(`Total worked: ${Math.floor(totalTimeWorked / 60)}m vs Limit: ${Math.floor(dedicatedSeconds / 60)}m`); console.log(`Total worked: ${Math.floor(totalTimeWorked / 60)}m vs Limit: ${Math.floor(dedicatedSeconds / 60)}m`);
// Clear timer first to prevent multiple triggers // Clear timer first to prevent multiple triggers
if (timerRef.current) { // if (timerRef.current) {
clearInterval(timerRef.current); // clearInterval(timerRef.current);
timerRef.current = null; // timerRef.current = null;
} // }
// Trigger auto-stop // Trigger auto-stop
handleLimitExceeded(); handleLimitExceeded();

View File

@ -82,7 +82,7 @@ console.log("projectSummary46" , projectSummary)
const fetchAdjustments = async () => { const fetchAdjustments = async () => {
setLoadingAdjustments(true); setLoadingAdjustments(true);
try { try {
const res: ApiResponse<AdjustmentItem[]> = await window.electron.getAdjustmentsList(); const res: ApiResponse<AdjustmentItem[]> = await window.electron.getAdjustmentsList(projectSummary?.vaId);
if (res.success) { if (res.success) {
setAdjustments(res.data || []); setAdjustments(res.data || []);
} }

View File

@ -86,6 +86,7 @@ const Timesheets: React.FC = () => {
const fetchProjects = async () => { const fetchProjects = async () => {
setInitialLoading(true);
try { try {
console.log("📡 Fetching projects..."); console.log("📡 Fetching projects...");
const res = await window.electron.getProjectList(); const res = await window.electron.getProjectList();
@ -241,7 +242,7 @@ const Timesheets: React.FC = () => {
)) ))
)} )}
{refreshing && projectsData.length > 0 && ( {/* {refreshing && projectsData.length > 0 && (
// Show a single skeleton row at the top while refreshing with existing data // Show a single skeleton row at the top while refreshing with existing data
<tr> <tr>
<td colSpan={4} className="bg-base-200/50"> <td colSpan={4} className="bg-base-200/50">
@ -251,7 +252,7 @@ const Timesheets: React.FC = () => {
</div> </div>
</td> </td>
</tr> </tr>
)} )} */}
</tbody> </tbody>
</table> </table>
</div> </div>

2
types.d.ts vendored
View File

@ -218,7 +218,7 @@ interface Window {
data?: any; data?: any;
}>; }>;
getAdjustmentsList: () => Promise<{ getAdjustmentsList: (vaId: string) => Promise<{
success: boolean; success: boolean;
data?: any; data?: any;
}>; }>;