feat: review style of error and refacto

This commit is contained in:
Julien Froidefond
2025-02-25 05:44:53 +01:00
parent 7c6eb6ab58
commit d4871d1afb
4 changed files with 46 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ import { PreferencesService } from "@/lib/services/preferences.service";
import { revalidatePath } from "next/cache"; import { revalidatePath } from "next/cache";
import { RefreshButton } from "@/components/library/RefreshButton"; import { RefreshButton } from "@/components/library/RefreshButton";
import { withPageTiming } from "@/lib/hoc/withPageTiming"; import { withPageTiming } from "@/lib/hoc/withPageTiming";
import { ErrorMessage } from "@/components/ui/ErrorMessage";
interface PageProps { interface PageProps {
params: { libraryId: string }; params: { libraryId: string };
@@ -97,11 +98,11 @@ 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>
<div className="rounded-md bg-destructive/15 p-4"> <ErrorMessage
<p className="text-sm text-destructive"> message={
{error instanceof Error ? error.message : "Erreur lors de la récupération des séries"} error instanceof Error ? error.message : "Erreur lors de la récupération des séries"
</p> }
</div> />
</div> </div>
); );
} }

View File

@@ -3,6 +3,7 @@ import { HomeService } from "@/lib/services/home.service";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { revalidatePath } from "next/cache"; import { revalidatePath } from "next/cache";
import { withPageTiming } from "@/lib/hoc/withPageTiming"; import { withPageTiming } from "@/lib/hoc/withPageTiming";
import { ErrorMessage } from "@/components/ui/ErrorMessage";
async function refreshHome() { async function refreshHome() {
"use server"; "use server";
@@ -30,11 +31,9 @@ async function HomePage() {
return ( return (
<main className="container mx-auto px-4 py-8"> <main className="container mx-auto px-4 py-8">
<div className="rounded-md bg-destructive/15 p-4"> <ErrorMessage
<p className="text-sm text-destructive"> message={error instanceof Error ? error.message : "Une erreur est survenue"}
{error instanceof Error ? error.message : "Une erreur est survenue"} />
</p>
</div>
</main> </main>
); );
} }

View File

@@ -4,6 +4,7 @@ import { SeriesService } from "@/lib/services/series.service";
import { PreferencesService } from "@/lib/services/preferences.service"; import { PreferencesService } from "@/lib/services/preferences.service";
import { revalidatePath } from "next/cache"; import { revalidatePath } from "next/cache";
import { withPageTiming } from "@/lib/hoc/withPageTiming"; import { withPageTiming } from "@/lib/hoc/withPageTiming";
import { ErrorMessage } from "@/components/ui/ErrorMessage";
interface PageProps { interface PageProps {
params: { seriesId: string }; params: { seriesId: string };
@@ -68,11 +69,11 @@ 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>
<div className="rounded-md bg-destructive/15 p-4"> <ErrorMessage
<p className="text-sm text-destructive"> message={
{error instanceof Error ? error.message : "Erreur lors de la récupération de la série"} error instanceof Error ? error.message : "Erreur lors de la récupération de la série"
</p> }
</div> />
</div> </div>
); );
} }

View File

@@ -0,0 +1,30 @@
import { AlertCircle } from "lucide-react";
interface ErrorMessageProps {
message: string;
}
export const ErrorMessage = ({ message }: ErrorMessageProps) => {
return (
<div
role="alert"
aria-live="assertive"
className="relative overflow-hidden rounded-lg border border-destructive/50 bg-background p-6 shadow-lg dark:border-destructive/30 dark:bg-destructive/5"
>
<div className="absolute inset-0 bg-destructive/5 dark:bg-gradient-to-b dark:from-destructive/10 dark:to-destructive/5" />
<div className="relative flex items-start gap-4">
<div className="rounded-full bg-destructive/10 p-2 dark:bg-destructive/30">
<AlertCircle className="h-5 w-5 text-destructive dark:text-red-400" />
</div>
<div className="flex-1">
<h3 className="mb-1 font-medium text-destructive dark:text-red-400">
Une erreur est survenue
</h3>
<p className="text-sm text-destructive/90 dark:text-red-300/90">{message}</p>
</div>
</div>
</div>
);
};