From 488c771a0945066bddc66ee560ef51d3124e625b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Mon, 5 Jan 2026 16:03:38 +0100 Subject: [PATCH] (fix) ParamsYearInvalidMessage moved to client-side component so that it can use `useEffect` --- app/ui/HomePage.tsx | 22 ++-------------------- app/ui/ParamsYearInvalidMessage.tsx | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 app/ui/ParamsYearInvalidMessage.tsx diff --git a/app/ui/HomePage.tsx b/app/ui/HomePage.tsx index fd7d4aa..2e46fcb 100644 --- a/app/ui/HomePage.tsx +++ b/app/ui/HomePage.tsx @@ -2,9 +2,9 @@ import { fetchAllLocations } from '@/app/lib/actions/locationActions'; import { fetchAvailableYears } from '@/app/lib/actions/monthActions'; import { getUserSettings } from '@/app/lib/actions/userSettingsActions'; import { BillingLocation, YearMonth } from '@/app/lib/db-types'; -import { FC, useEffect } from 'react'; +import { FC } from 'react'; import { MonthLocationList } from '@/app/ui/MonthLocationList'; -import { redirect } from 'next/navigation'; +import { ParamsYearInvalidMessage } from './ParamsYearInvalidMessage'; export interface HomePageProps { searchParams?: { @@ -13,24 +13,6 @@ export interface HomePageProps { }; } -const ParamsYearInvalidMessage:FC<{ firstAvailableYear?: number }> = ({ firstAvailableYear }) => { - - // Redirect to the first available year after showing the message - useEffect(() => { - if(firstAvailableYear) { - redirect(`/?year=${firstAvailableYear}`); - } else { - redirect(`/`); - } - }); - - return( -
-

The year specified in the URL is invalid ... redirecting

-
- ); -}; - export const HomePage:FC = async ({ searchParams }) => { /** years found in the DB sorted descending */ diff --git a/app/ui/ParamsYearInvalidMessage.tsx b/app/ui/ParamsYearInvalidMessage.tsx new file mode 100644 index 0000000..ea20a1c --- /dev/null +++ b/app/ui/ParamsYearInvalidMessage.tsx @@ -0,0 +1,21 @@ +"use client"; +import { FC, useEffect } from 'react'; +import { redirect } from 'next/navigation'; + +export const ParamsYearInvalidMessage:FC<{ firstAvailableYear?: number }> = ({ firstAvailableYear }) => { + + // Redirect to the first available year after showing the message + useEffect(() => { + if(firstAvailableYear) { + redirect(`/?year=${firstAvailableYear}`); + } else { + redirect(`/`); + } + }); + + return( +
+

The year specified in the URL is invalid ... redirecting

+
+ ); +}; \ No newline at end of file