ldc-ovoteam/resources/ts/back/Components/InputError.tsx

40 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2026-03-30 14:17:31 +02:00
import { usePage } from "@inertiajs/react";
2026-07-09 12:10:37 +02:00
import { AlertCircleIcon } from "lucide-react";
2026-03-30 14:17:31 +02:00
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import trans from "@/hooks/use-translations";
2026-03-30 14:17:31 +02:00
import { cn } from "@/lib/utils";
export default function InputError({
all,
message,
}: Readonly<{
2026-03-30 14:17:31 +02:00
all?: boolean;
message?: string;
}>) {
2026-03-30 14:17:31 +02:00
const { errors } = usePage().props;
const errorsTrans = trans("uwil-backend::back.errors");
let messages = {} as string[];
2026-03-30 14:17:31 +02:00
if (message) {
messages = Object.values([message]);
} else if (Object.values(errors).length && all) {
messages = Object.values(errors);
}
if (messages.length) {
return (
<Alert
variant="destructive"
className={cn("text-left col-span-2", { "mb-4": all })}
2026-03-30 14:17:31 +02:00
>
<AlertCircleIcon className="h-4 w-4" />
{all && <AlertTitle>{errorsTrans}</AlertTitle>}
<AlertDescription>
{messages.map((errorMessage) => {
return <p key={errorMessage}>{errorMessage}</p>;
})}
</AlertDescription>
</Alert>
);
}
}