forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

record-not-found.tsx35 lines, 1.5 KiBHistoryRawDownload
1import { Link, useLocation, useRouter } from "@tanstack/solid-router";
2import { buttonVariants } from "@/components/ui/button";
3import { EmptyState } from "@/components/ui/empty-state";
4import { PAGE_STATE_CARD, PageCenter, pageStateText as tt } from "@/components/layout/page-center";
5import { cn } from "@/lib/cn";
6import { listPathFor } from "@/lib/record-list-path";
7
8/**
9 * What a detail page shows when its record does not exist (a 404 — deleted,
10 * or a bad link): there is nothing to retry, so it offers the way back to the
11 * list instead. Centered in the content column like the route error view.
12 * Also rendered by the router's error fallback, which can sit above the i18n
13 * provider, hence `pageStateText` instead of `useT()`.
14 */
15export function RecordNotFound(props: { backTo?: string }) {
16 const router = useRouter();
17 const location = useLocation();
18 const backTo = () =>
19 props.backTo ?? listPathFor(location().pathname, (path) => path in router.routesByPath);
20 return (
21 <PageCenter>
22 <EmptyState
23 kind="search"
24 class={PAGE_STATE_CARD}
25 title={tt("errors.recordNotFound.title")}
26 description={tt("errors.recordNotFound.description")}
27 action={
28 <Link to={backTo()} class={cn(buttonVariants({ variant: "outline", size: "sm" }), "h-9 rounded-lg px-4 text-sm")}>
29 {backTo() === "/" ? tt("errors.recordNotFound.backHome") : tt("errors.recordNotFound.backToList")}
30 </Link>
31 }
32 />
33 </PageCenter>
34 );
35}