fix: error on hydration and ErrorMessage

This commit is contained in:
Julien Froidefond
2025-02-28 07:38:48 +01:00
parent 4994cbd2e9
commit 5893f1a15f
6 changed files with 10 additions and 8 deletions

View File

@@ -6,6 +6,7 @@ import { notFound } from "next/navigation";
import { withPageTiming } from "@/lib/hoc/withPageTiming"; import { withPageTiming } from "@/lib/hoc/withPageTiming";
import { KomgaBookWithPages } from "@/types/komga"; import { KomgaBookWithPages } from "@/types/komga";
import { ErrorMessage } from "@/components/ui/ErrorMessage"; import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { ERROR_CODES } from "@/constants/errorCodes";
async function BookPage({ params }: { params: { bookId: string } }) { async function BookPage({ params }: { params: { bookId: string } }) {
try { try {
@@ -20,7 +21,7 @@ async function BookPage({ params }: { params: { bookId: string } }) {
console.error("Erreur:", error); console.error("Erreur:", error);
return ( return (
<div className="container py-8 space-y-8"> <div className="container py-8 space-y-8">
<ErrorMessage error={error as Error} errorCode="BOOK_FETCH_ERROR" /> <ErrorMessage errorCode={ERROR_CODES.SERIES.FETCH_ERROR} />
</div> </div>
); );
} }

View File

@@ -8,6 +8,7 @@ import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { LibraryResponse } from "@/types/library"; import { LibraryResponse } from "@/types/library";
import { KomgaSeries, KomgaLibrary } from "@/types/komga"; import { KomgaSeries, KomgaLibrary } from "@/types/komga";
import { UserPreferences } from "@/types/preferences"; import { UserPreferences } from "@/types/preferences";
import { ERROR_CODES } from "@/constants/errorCodes";
interface PageProps { interface PageProps {
params: { libraryId: string }; params: { libraryId: string };
@@ -98,13 +99,13 @@ async function LibraryPage({ params, searchParams }: PageProps) {
<h1 className="text-3xl font-bold">Séries</h1> <h1 className="text-3xl font-bold">Séries</h1>
<RefreshButton libraryId={params.libraryId} refreshLibrary={refreshLibrary} /> <RefreshButton libraryId={params.libraryId} refreshLibrary={refreshLibrary} />
</div> </div>
<ErrorMessage error={error as Error} errorCode="SERIES_FETCH_ERROR" /> <ErrorMessage errorCode={ERROR_CODES.SERIES.FETCH_ERROR} />
</div> </div>
); );
} }
return ( return (
<div className="container py-8 space-y-8"> <div className="container py-8 space-y-8">
<ErrorMessage error={error as Error} errorCode="SERIES_FETCH_ERROR" /> <ErrorMessage errorCode={ERROR_CODES.SERIES.FETCH_ERROR} />
</div> </div>
); );
} }

View File

@@ -24,7 +24,6 @@ async function refreshHome() {
async function HomePage() { async function HomePage() {
try { try {
const data: HomeData = await HomeService.getHomeData(); const data: HomeData = await HomeService.getHomeData();
return <HomeContent data={data} refreshHome={refreshHome} />; return <HomeContent data={data} refreshHome={refreshHome} />;
} catch (error) { } catch (error) {
// Si l'erreur indique une configuration manquante, rediriger vers les préférences // Si l'erreur indique une configuration manquante, rediriger vers les préférences
@@ -34,7 +33,7 @@ async function HomePage() {
return ( return (
<main className="container mx-auto px-4 py-8"> <main className="container mx-auto px-4 py-8">
<ErrorMessage error={error as Error} errorCode="HOME_FETCH_ERROR" /> <ErrorMessage errorCode={ERROR_CODES.KOMGA.SERVER_UNREACHABLE} />
</main> </main>
); );
} }

View File

@@ -8,6 +8,7 @@ import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { LibraryResponse } from "@/types/library"; import { LibraryResponse } from "@/types/library";
import { KomgaBook, KomgaSeries } from "@/types/komga"; import { KomgaBook, KomgaSeries } from "@/types/komga";
import { UserPreferences } from "@/types/preferences"; import { UserPreferences } from "@/types/preferences";
import { ERROR_CODES } from "@/constants/errorCodes";
interface PageProps { interface PageProps {
params: { seriesId: string }; params: { seriesId: string };
@@ -78,7 +79,7 @@ async function SeriesPage({ params, searchParams }: PageProps) {
return ( return (
<div className="container py-8 space-y-8"> <div className="container py-8 space-y-8">
<h1 className="text-3xl font-bold">Série</h1> <h1 className="text-3xl font-bold">Série</h1>
<ErrorMessage error={error as Error} errorCode="SERIES_FETCH_ERROR" /> <ErrorMessage errorCode={ERROR_CODES.SERIES.FETCH_ERROR} />
</div> </div>
); );
} }

View File

@@ -89,7 +89,7 @@ export function LoginForm({ from }: LoginFormProps) {
{t("login.form.remember")} {t("login.form.remember")}
</label> </label>
</div> </div>
{error && <ErrorMessage error={error as Error} errorCode={error.code} variant="form" />} {error && <ErrorMessage errorCode={error.code} variant="form" />}
<button <button
type="submit" type="submit"
disabled={isLoading} disabled={isLoading}

View File

@@ -100,7 +100,7 @@ export function RegisterForm({ from }: RegisterFormProps) {
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50" className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
/> />
</div> </div>
{error && <ErrorMessage error={error as Error} errorCode={error.code} variant="form" />} {error && <ErrorMessage errorCode={error.code} variant="form" />}
<button <button
type="submit" type="submit"
disabled={isLoading} disabled={isLoading}