fix(TestsPage): move lastActivityDate outside component to fix TDZ error
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
useMemo executes its factory immediately on first render. lastActivityDate was defined with const after the useMemo call inside the component, causing a temporal dead zone: 'Cannot access v before initialization'. Fix: move the function to module scope (before the component), where it is fully initialized before any hook runs.
This commit is contained in:
@@ -72,6 +72,23 @@ function currentTeamForState(state: TestState): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Helper: most recent activity timestamp on a test ──────────────── */
|
||||||
|
// updated_at column does not exist in the DB — derive from available fields
|
||||||
|
function lastActivityDate(t: Test): string | null {
|
||||||
|
const candidates = [
|
||||||
|
t.blue_validated_at,
|
||||||
|
t.red_validated_at,
|
||||||
|
(t as any).blue_work_started_at,
|
||||||
|
(t as any).blue_started_at,
|
||||||
|
(t as any).red_started_at,
|
||||||
|
t.created_at,
|
||||||
|
].filter(Boolean) as string[];
|
||||||
|
if (!candidates.length) return null;
|
||||||
|
return candidates.reduce((latest, d) =>
|
||||||
|
new Date(d) > new Date(latest) ? d : latest
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/* ── Helper: elapsed time since a date ─────────────────────────────── */
|
/* ── Helper: elapsed time since a date ─────────────────────────────── */
|
||||||
|
|
||||||
function formatElapsed(dateStr: string | null | undefined): string {
|
function formatElapsed(dateStr: string | null | undefined): string {
|
||||||
@@ -281,23 +298,6 @@ export default function TestsPage() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// updated_at doesn't exist in DB — derive "last activity" from the most
|
|
||||||
// recent non-null timestamp available on the test record
|
|
||||||
const lastActivityDate = (t: import("../types/models").Test): string | null => {
|
|
||||||
const candidates = [
|
|
||||||
t.blue_validated_at,
|
|
||||||
t.red_validated_at,
|
|
||||||
(t as any).blue_work_started_at,
|
|
||||||
(t as any).blue_started_at,
|
|
||||||
(t as any).red_started_at,
|
|
||||||
t.created_at,
|
|
||||||
].filter(Boolean) as string[];
|
|
||||||
if (!candidates.length) return null;
|
|
||||||
return candidates.reduce((latest, d) =>
|
|
||||||
new Date(d) > new Date(latest) ? d : latest
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
// ── My tasks label ────────────────────────────────────────────────
|
// ── My tasks label ────────────────────────────────────────────────
|
||||||
const myTasksLabel = useMemo(() => {
|
const myTasksLabel = useMemo(() => {
|
||||||
if (!user) return "My Tasks";
|
if (!user) return "My Tasks";
|
||||||
|
|||||||
Reference in New Issue
Block a user