(fix) ParamsYearInvalidMessage moved to client-side component so that it can use useEffect

This commit is contained in:
2026-01-05 16:03:38 +01:00
parent 1076797c89
commit 488c771a09
2 changed files with 23 additions and 20 deletions

View File

@@ -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(
<main className="flex min-h-screen flex-col p-6 bg-base-300">
<p className="text-center text-2xl text-red-500">The year specified in the URL is invalid ... redirecting</p>
</main>
);
};
export const HomePage:FC<HomePageProps> = async ({ searchParams }) => {
/** years found in the DB sorted descending */

View File

@@ -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(
<main className="flex min-h-screen flex-col p-6 bg-base-300">
<p className="text-center text-2xl text-red-500">The year specified in the URL is invalid ... redirecting</p>
</main>
);
};