2023-12-14 10:37:29 +00:00
|
|
|
import { BsX } from "react-icons/bs";
|
2023-12-07 22:42:19 +00:00
|
|
|
import { ErrorWithLabel } from "../rqbit-web";
|
2023-12-07 16:33:37 +00:00
|
|
|
|
2023-12-14 10:37:29 +00:00
|
|
|
const AlertDanger: React.FC<{
|
|
|
|
|
title: string;
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
onClose?: () => void;
|
|
|
|
|
}> = ({ title, children, onClose }) => {
|
|
|
|
|
return (
|
2023-12-15 14:38:14 +00:00
|
|
|
<div className="bg-red-200 p-3 rounded-md mb-3 dark:bg-red-800/60">
|
2023-12-14 10:37:29 +00:00
|
|
|
<div className="flex justify-between mb-2">
|
|
|
|
|
<h2 className="text-lg font-semibold">{title}</h2>
|
|
|
|
|
{onClose && (
|
|
|
|
|
<button onClick={onClose}>
|
|
|
|
|
<BsX />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-07 16:33:37 +00:00
|
|
|
export const ErrorComponent = (props: {
|
2023-12-07 22:42:19 +00:00
|
|
|
error: ErrorWithLabel | null;
|
2023-12-07 16:33:37 +00:00
|
|
|
remove?: () => void;
|
|
|
|
|
}) => {
|
|
|
|
|
let { error, remove } = props;
|
|
|
|
|
|
|
|
|
|
if (error == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2023-12-14 10:37:29 +00:00
|
|
|
<AlertDanger onClose={remove} title={error.text}>
|
2023-12-07 16:33:37 +00:00
|
|
|
{error.details?.statusText && (
|
2023-12-14 10:37:29 +00:00
|
|
|
<div className="pb-2 text-md">{error.details?.statusText}</div>
|
2023-12-07 16:33:37 +00:00
|
|
|
)}
|
2023-12-16 18:43:41 +00:00
|
|
|
<div className="whitespace-pre-wrap text-sm">{error.details?.text}</div>
|
2023-12-14 10:37:29 +00:00
|
|
|
</AlertDanger>
|
2023-12-07 16:33:37 +00:00
|
|
|
);
|
|
|
|
|
};
|