Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

78 linesCodeBlameRaw
1import { Form, Link, useLocation, useRouteLoaderData } from "react-router";
2
3import type { Membership, User } from "@g1t/contracts";
4
5import { withNext } from "../lib/next";
6import { useSignUpCopy } from "../lib/registration";
7import { missingKind, notFoundCopy } from "../lib/not-found";
8import { PageMain } from "./landmark";
9import { Pixel404 } from "./logo";
10import { ButtonLink, SubmitButton } from "./ui";
11
12/**
13 * The page for anything someone cannot see. It reads only the kind of thing
14 * the address names and who is signed in, so a private project and a
15 * missing one give the same page, word for word, and the same 404.
16 */
17export function NotFound({ data }: { data?: unknown }) {
18 const { pathname, search } = useLocation();
19 const root = useRouteLoaderData("root") as
20 | { user?: User | null; shell?: { workspace?: Membership | null; repo?: { namespace: string; name: string } | null } }
21 | undefined;
22 const user = root?.user ?? null;
23 const workspace = user ? (root?.shell?.workspace ?? null) : null;
24 // Something missing inside a project the viewer can see: back to it.
25 const project = root?.shell?.repo ?? null;
26 const inProject = project != null && pathname.toLowerCase().startsWith(`/${project.namespace}/${project.name}/`.toLowerCase());
27 const kind = missingKind(data, pathname);
28 const copy = notFoundCopy(kind, user?.username);
29 const here = pathname + search;
30 const signUp = useSignUpCopy();
31 return (
32 <PageMain className="mx-auto flex max-w-lg flex-col items-center px-4 py-20 text-center sm:py-28">
33 <Pixel404 className="text-[3.5rem] sm:text-[4.5rem]" />
34 <h1 className="mt-10 text-balance text-2xl font-semibold tracking-tight">{copy.title}</h1>
35 <p className="mt-2 text-balance text-muted">{copy.body}</p>
36
37 <div className="mt-8 flex flex-wrap justify-center gap-2">
38 {copy.signIn ? (
39 <ButtonLink to={withNext("/login", here)}>Sign in</ButtonLink>
40 ) : kind === "person" ? (
41 <ButtonLink to="/search?type=people">Search people</ButtonLink>
42 ) : inProject ? (
43 <ButtonLink to={`/${project.namespace}/${project.name}`}>Go to {project.name}</ButtonLink>
44 ) : workspace ? (
45 <ButtonLink to={`/${workspace.slug}`}>Go to {workspace.name?.trim() || workspace.slug}</ButtonLink>
46 ) : user ? (
47 <ButtonLink to="/">Go home</ButtonLink>
48 ) : null}
49 <ButtonLink to="/explore" variant="outline">
50 {user ? "Explore" : "Explore public projects"}
51 </ButtonLink>
52 </div>
53
54 <p className="mt-6 hidden text-sm text-faint sm:block">
55 Looking for something? Press <kbd className="rounded bg-raised px-1.5 py-0.5 font-mono text-[0.6875rem] text-muted ring-1 ring-line">⌘K</kbd> to search.
56 </p>
57
58 {copy.signIn && (
59 <p className="mt-3 text-xs text-faint">
60 New to g1t?{" "}
61 <Link to={withNext("/register", here)} className="text-muted underline-offset-4 hover:text-fg hover:underline">
62 {signUp.primary}
63 </Link>
64 </p>
65 )}
66
67 {copy.signedInAs && (
68 // Signing out, then in again, comes back here.
69 <Form method="post" action={`/logout?next=${encodeURIComponent(withNext("/login", here))}`} className="mt-3 text-xs text-faint">
70 Signed in as <span className="font-mono text-muted">@{copy.signedInAs}</span> ·{" "}
71 <SubmitButton pending="Signing out…" variant="link" size="inline" className="gap-1 text-muted hover:text-fg">
72 Switch account
73 </SubmitButton>
74 </Form>
75 )}
76 </PageMain>
77 );
78}