Skip to content

Commit d865730

Browse files
authored
feat: add not_found route (#194)
* feat: add not_found route * leftover
1 parent 648a674 commit d865730

File tree

7 files changed

+71
-21
lines changed

7 files changed

+71
-21
lines changed

icons/FlipBackward.svg

-3
This file was deleted.

src/Page.test.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { render } from "./lib/test-utils";
2+
import Page from "./Page";
3+
4+
test("render NotFound route", () => {
5+
const { getByText, getByRole } = render(<Page />, {
6+
routeConfig: {
7+
initialEntries: ["/fake-route"],
8+
},
9+
});
10+
11+
expect(getByText(/Oops! There's nothing here/i)).toBeVisible();
12+
expect(getByRole("button", { name: "Home" })).toBeVisible();
13+
});

src/Page.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { RouteChat } from "./routes/route-chat";
88
import { RouteDashboard } from "./routes/route-dashboard";
99
import { RouteCertificateSecurity } from "./routes/route-certificate-security";
1010
import { RouteWorkspaceCreation } from "./routes/route-workspace-creation";
11+
import { RouteNotFound } from "./routes/route-not-found";
1112

1213
export default function Page() {
1314
return (
@@ -23,6 +24,7 @@ export default function Page() {
2324
path="/certificates/security"
2425
element={<RouteCertificateSecurity />}
2526
/>
27+
<Route path="*" element={<RouteNotFound />} />
2628
</Routes>
2729
);
2830
}

src/components/EmptyState.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
interface EmptyStateProps {
2+
children?: React.ReactNode;
3+
title?: string | React.ReactNode;
4+
description?: string | React.ReactNode;
5+
illustration?: React.ReactNode;
6+
}
7+
8+
export function EmptyState({
9+
illustration,
10+
title,
11+
children,
12+
description,
13+
}: EmptyStateProps) {
14+
return (
15+
<>
16+
<div className="my-4">
17+
{illustration != null && (
18+
<div className="m-auto flex w-full justify-center pb-2">
19+
{illustration}
20+
</div>
21+
)}
22+
<div className="mb-1 text-center text-xl font-medium text-gray-900">
23+
{title}
24+
</div>
25+
<div className="m-auto mb-6 text-center font-normal text-secondary">
26+
{description}
27+
</div>
28+
{children != null && (
29+
<div className="flex justify-center">{children}</div>
30+
)}
31+
</div>
32+
</>
33+
);
34+
}

src/components/icons/FlipBackward.tsx

-17
This file was deleted.

src/components/icons/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export { default as Continue } from "./Continue";
22
export { default as Copilot } from "./Copilot";
33
export { default as Discord } from "./Discord";
4-
export { default as FlipBackward } from "./FlipBackward";
54
export { default as Github } from "./Github";
65
export { default as Youtube } from "./Youtube";

src/routes/route-not-found.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { EmptyState } from "@/components/EmptyState";
2+
import { IllustrationError, Button } from "@stacklok/ui-kit";
3+
import { useNavigate } from "react-router-dom";
4+
import { FlipBackward } from "@untitled-ui/icons-react";
5+
6+
export function RouteNotFound() {
7+
const navigate = useNavigate();
8+
9+
return (
10+
<div className="flex items-center justify-center h-full">
11+
<EmptyState
12+
title="Oops! There's nothing here"
13+
description="Either the page you were looking for doesn’t exist or the link may be broken."
14+
illustration={<IllustrationError className="w-1/2" />}
15+
>
16+
<Button variant="primary" onPress={() => navigate("/")}>
17+
<FlipBackward /> Home
18+
</Button>
19+
</EmptyState>
20+
</div>
21+
);
22+
}

0 commit comments

Comments
 (0)