From da20453e9063c31e0c29d201c73b65ba1790e045 Mon Sep 17 00:00:00 2001 From: SylvainP1 <5533467-SylvainP1@users.noreply.replit.com> Date: Tue, 14 Apr 2026 08:29:04 +0000 Subject: [PATCH] Automatically show the current month's timesheet when viewing the timesheets page Redirect to the current month's timesheet detail page if it exists, otherwise show the list of timesheets. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 55837015-10e9-4be9-b857-7f5e6be73772 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: ca4f6ae2-ceaf-44e2-aa91-4c2204934186 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1cc377db-7ea0-49f2-97ce-c3e87e0228cc/55837015-10e9-4be9-b857-7f5e6be73772/3QF56xd Replit-Helium-Checkpoint-Created: true --- artifacts/cra-app/src/pages/timesheets.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/artifacts/cra-app/src/pages/timesheets.tsx b/artifacts/cra-app/src/pages/timesheets.tsx index aae4e76..375436f 100644 --- a/artifacts/cra-app/src/pages/timesheets.tsx +++ b/artifacts/cra-app/src/pages/timesheets.tsx @@ -1,5 +1,5 @@ -import { useState } from "react"; -import { Link } from "wouter"; +import { useState, useEffect } from "react"; +import { Link, useLocation } from "wouter"; import { useListTimesheets, getListTimesheetsQueryKey, @@ -19,14 +19,27 @@ import { MONTHS, formatMonthYear, STATUS_LABELS, STATUS_COLORS, cn } from "@/lib export default function TimesheetsPage() { const currentYear = new Date().getFullYear(); + const currentMonth = new Date().getMonth() + 1; const [yearFilter, setYearFilter] = useState(currentYear.toString()); const [isCreateOpen, setIsCreateOpen] = useState(false); + const [, navigate] = useLocation(); + const [redirectChecked, setRedirectChecked] = useState(false); const { data: timesheets, isLoading } = useListTimesheets( { year: parseInt(yearFilter) }, { query: { queryKey: getListTimesheetsQueryKey({ year: parseInt(yearFilter) }) } } ); + useEffect(() => { + if (!isLoading && timesheets && !redirectChecked && parseInt(yearFilter) === currentYear) { + setRedirectChecked(true); + const currentMonthTs = timesheets.find(ts => ts.month === currentMonth && ts.year === currentYear); + if (currentMonthTs) { + navigate(`/timesheets/${currentMonthTs.id}`); + } + } + }, [isLoading, timesheets, redirectChecked, yearFilter, currentYear, currentMonth, navigate]); + return (