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:
parent
df2b35a4e4
commit
9eeb14ffcd
|
|
@ -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 {
|
||||
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);
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ contextBridge.exposeInMainWorld('electron', {
|
|||
|
||||
getPayslips: (vaId: string) => ipcRenderer.invoke("get-payslips", vaId),
|
||||
getLeaveList: () => ipcRenderer.invoke("get-leave-list"),
|
||||
getAdjustmentsList:() => ipcRenderer.invoke("get-adjustments-list"),
|
||||
getAdjustmentsList:(vaId: string) => ipcRenderer.invoke("get-adjustments-list",vaId),
|
||||
|
||||
} satisfies Window['electron']);
|
||||
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ const DashboardLayout = () => {
|
|||
|
||||
// Create a ref to store the stop function so it can be called from the hook
|
||||
const stopTrackingRef = useRef<(() => Promise<void>) | null>(null);
|
||||
const limitAlertShownRef = useRef(false);
|
||||
|
||||
// Define handleStopTracking FIRST
|
||||
const handleStopTracking = useCallback(async () => {
|
||||
|
|
@ -148,6 +149,9 @@ const DashboardLayout = () => {
|
|||
return;
|
||||
}
|
||||
|
||||
// Reset alert flag when stopping
|
||||
limitAlertShownRef.current = false;
|
||||
|
||||
let currentStopTime = new Date().toISOString();
|
||||
const projectId = selectedProject.projectId;
|
||||
|
||||
|
|
@ -282,25 +286,34 @@ const DashboardLayout = () => {
|
|||
|
||||
// NOW define handleLimitExceeded using the defined handleStopTracking
|
||||
const handleLimitExceeded = useCallback(async () => {
|
||||
console.log("🚨 LIMIT EXCEEDED - Auto-stopping tracking");
|
||||
console.log("🚨 LIMIT EXCEEDED - Showing alert (not stopping)");
|
||||
|
||||
if (!selectedProject) {
|
||||
console.error(" No selected project for limit exceeded");
|
||||
console.error("❌ No selected project for limit exceeded");
|
||||
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
|
||||
alert(
|
||||
`⏰ Daily Limit Reached!\n\n` +
|
||||
`Project: ${selectedProject.projectName}\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
|
||||
// await handleStopTracking();
|
||||
}, [selectedProject, handleStopTracking]);
|
||||
|
||||
console.log("✅ Alert shown, timer continues running");
|
||||
}, [selectedProject]);
|
||||
|
||||
// Initialize useActiveAppTracker and store finalizeTracking in ref
|
||||
const { finalizeTracking } = useActiveAppTracker(
|
||||
|
|
@ -384,6 +397,8 @@ const DashboardLayout = () => {
|
|||
|
||||
console.log(`⏰ Starting tracking. Remaining time: ${limitCheck.remaining}`);
|
||||
|
||||
limitAlertShownRef.current = false;
|
||||
|
||||
setLoadingStart(true);
|
||||
|
||||
const now = Date.now();
|
||||
|
|
@ -468,15 +483,15 @@ const DashboardLayout = () => {
|
|||
// Check if time limit reached
|
||||
const totalTimeWorked = alreadyWorkedSeconds + timeSinceStart;
|
||||
|
||||
if (totalTimeWorked >= dedicatedSeconds) {
|
||||
if (totalTimeWorked >= dedicatedSeconds && !limitAlertShownRef.current) {
|
||||
console.warn("🚨 CLIENT-SIDE: Time limit reached!");
|
||||
console.log(`Total worked: ${Math.floor(totalTimeWorked / 60)}m vs Limit: ${Math.floor(dedicatedSeconds / 60)}m`);
|
||||
|
||||
// Clear timer first to prevent multiple triggers
|
||||
if (timerRef.current) {
|
||||
clearInterval(timerRef.current);
|
||||
timerRef.current = null;
|
||||
}
|
||||
// if (timerRef.current) {
|
||||
// clearInterval(timerRef.current);
|
||||
// timerRef.current = null;
|
||||
// }
|
||||
|
||||
// Trigger auto-stop
|
||||
handleLimitExceeded();
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ console.log("projectSummary46" , projectSummary)
|
|||
const fetchAdjustments = async () => {
|
||||
setLoadingAdjustments(true);
|
||||
try {
|
||||
const res: ApiResponse<AdjustmentItem[]> = await window.electron.getAdjustmentsList();
|
||||
const res: ApiResponse<AdjustmentItem[]> = await window.electron.getAdjustmentsList(projectSummary?.vaId);
|
||||
if (res.success) {
|
||||
setAdjustments(res.data || []);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ const Timesheets: React.FC = () => {
|
|||
|
||||
|
||||
const fetchProjects = async () => {
|
||||
setInitialLoading(true);
|
||||
try {
|
||||
console.log("📡 Fetching projects...");
|
||||
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
|
||||
<tr>
|
||||
<td colSpan={4} className="bg-base-200/50">
|
||||
|
|
@ -251,7 +252,7 @@ const Timesheets: React.FC = () => {
|
|||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
)} */}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ interface Window {
|
|||
data?: any;
|
||||
}>;
|
||||
|
||||
getAdjustmentsList: () => Promise<{
|
||||
getAdjustmentsList: (vaId: string) => Promise<{
|
||||
success: boolean;
|
||||
data?: any;
|
||||
}>;
|
||||
|
|
|
|||
Loading…
Reference in New Issue