-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathErrorDisplay.tsx
More file actions
97 lines (90 loc) · 2.94 KB
/
ErrorDisplay.tsx
File metadata and controls
97 lines (90 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { HomeIcon } from "@heroicons/react/20/solid";
import { isRouteErrorResponse, useRouteError } from "@remix-run/react";
import { motion } from "framer-motion";
import { friendlyErrorDisplay } from "~/utils/httpErrors";
import { LinkButton } from "./primitives/Buttons";
import { Header1 } from "./primitives/Headers";
import { Paragraph } from "./primitives/Paragraph";
import { type ReactNode, useEffect } from "react";
declare global {
namespace JSX {
interface IntrinsicElements {
"spline-viewer": React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & {
url?: string;
"loading-anim-type"?: string;
},
HTMLElement
>;
}
}
}
type ErrorDisplayOptions = {
button?: {
title: string;
to: string;
};
};
export function RouteErrorDisplay(options?: ErrorDisplayOptions) {
const error = useRouteError();
return (
<>
{isRouteErrorResponse(error) ? (
<ErrorDisplay
title={friendlyErrorDisplay(error.status, error.statusText).title}
message={
error.data.message ?? friendlyErrorDisplay(error.status, error.statusText).message
}
{...options}
/>
) : error instanceof Error ? (
<ErrorDisplay title={error.name} message={error.message} {...options} />
) : (
<ErrorDisplay title="Oops" message={JSON.stringify(error)} {...options} />
)}
</>
);
}
type DisplayOptionsProps = {
title: string;
message?: ReactNode;
} & ErrorDisplayOptions;
export function ErrorDisplay({ title, message, button }: DisplayOptionsProps) {
useEffect(() => {
// Dynamically load the Spline viewer script
if (!customElements.get("spline-viewer")) {
const script = document.createElement("script");
script.type = "module";
script.src = "https://unpkg.com/@splinetool/viewer@1.12.29/build/spline-viewer.js";
document.head.appendChild(script);
}
}, []);
return (
<div className="relative flex min-h-screen flex-col items-center justify-center bg-[#16181C]">
<div className="z-10 mt-[30vh] flex flex-col items-center gap-8">
<Header1>{title}</Header1>
{message && <Paragraph>{message}</Paragraph>}
<LinkButton
to={button ? button.to : "/"}
shortcut={{ modifiers: ["mod"], key: "g" }}
variant="primary/medium"
LeadingIcon={HomeIcon}
>
{button ? button.title : "Go to homepage"}
</LinkButton>
</div>
<motion.div
className="pointer-events-none absolute inset-0 overflow-hidden"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: 0.5, duration: 2, ease: "easeOut" }}
>
<spline-viewer
loading-anim-type="spinner-small-light"
url="https://prod.spline.design/wRly8TZN-e0Twb8W/scene.splinecode"
style={{ width: "100%", height: "100%" }}
/>
</motion.div>
</div>
);
}