feat: review style of error and refacto
This commit is contained in:
@@ -4,6 +4,7 @@ import { PreferencesService } from "@/lib/services/preferences.service";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { RefreshButton } from "@/components/library/RefreshButton";
|
||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||
|
||||
interface PageProps {
|
||||
params: { libraryId: string };
|
||||
@@ -97,11 +98,11 @@ async function LibraryPage({ params, searchParams }: PageProps) {
|
||||
<h1 className="text-3xl font-bold">Séries</h1>
|
||||
<RefreshButton libraryId={params.libraryId} refreshLibrary={refreshLibrary} />
|
||||
</div>
|
||||
<div className="rounded-md bg-destructive/15 p-4">
|
||||
<p className="text-sm text-destructive">
|
||||
{error instanceof Error ? error.message : "Erreur lors de la récupération des séries"}
|
||||
</p>
|
||||
</div>
|
||||
<ErrorMessage
|
||||
message={
|
||||
error instanceof Error ? error.message : "Erreur lors de la récupération des séries"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { HomeService } from "@/lib/services/home.service";
|
||||
import { redirect } from "next/navigation";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||
|
||||
async function refreshHome() {
|
||||
"use server";
|
||||
@@ -30,11 +31,9 @@ async function HomePage() {
|
||||
|
||||
return (
|
||||
<main className="container mx-auto px-4 py-8">
|
||||
<div className="rounded-md bg-destructive/15 p-4">
|
||||
<p className="text-sm text-destructive">
|
||||
{error instanceof Error ? error.message : "Une erreur est survenue"}
|
||||
</p>
|
||||
</div>
|
||||
<ErrorMessage
|
||||
message={error instanceof Error ? error.message : "Une erreur est survenue"}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { SeriesService } from "@/lib/services/series.service";
|
||||
import { PreferencesService } from "@/lib/services/preferences.service";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||
|
||||
interface PageProps {
|
||||
params: { seriesId: string };
|
||||
@@ -68,11 +69,11 @@ async function SeriesPage({ params, searchParams }: PageProps) {
|
||||
return (
|
||||
<div className="container py-8 space-y-8">
|
||||
<h1 className="text-3xl font-bold">Série</h1>
|
||||
<div className="rounded-md bg-destructive/15 p-4">
|
||||
<p className="text-sm text-destructive">
|
||||
{error instanceof Error ? error.message : "Erreur lors de la récupération de la série"}
|
||||
</p>
|
||||
</div>
|
||||
<ErrorMessage
|
||||
message={
|
||||
error instanceof Error ? error.message : "Erreur lors de la récupération de la série"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
30
src/components/ui/ErrorMessage.tsx
Normal file
30
src/components/ui/ErrorMessage.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user