g1t/apps/web/app/components/not-found.tsx

88 lines3,694 bytesCodeBlame
1import { EyeOff, KeyRound, UserX } from "lucide-react";
2import { Form, Link, useLocation, useRouteLoaderData } from "react-router";
3
4import type { User } from "@g1t/contracts";
5
6import { withNext } from "../lib/next";
7import { useSignUpCopy } from "../lib/registration";
8import { missingKind, notFoundCopy } from "../lib/not-found";
9import { Avatar, ButtonLink } from "./ui";
10
11/**
12 * The page for anything someone cannot see. It reads only the kind of thing
13 * the address names and who is signed in, so a private project and a
14 * missing one give the same page, word for word.
15 */
16export function NotFound({ data }: { data?: unknown }) {
17 const { pathname, search } = useLocation();
18 const user = (useRouteLoaderData("root") as { user?: User | null } | undefined)?.user ?? null;
19 const kind = missingKind(data, pathname);
20 const copy = notFoundCopy(kind, user?.username);
21 const here = pathname + search;
22 const signUp = useSignUpCopy();
23 const Icon = kind === "person" ? UserX : copy.signIn ? KeyRound : EyeOff;
24 return (
25 <main className="mx-auto flex max-w-lg flex-col items-center px-4 py-24 text-center sm:py-32">
26 <span className="flex size-11 items-center justify-center rounded-xl bg-surface text-muted ring-1 ring-line">
27 <Icon size={20} />
28 </span>
29 <h1 className="mt-6 text-balance text-2xl font-semibold tracking-tight">{copy.title}</h1>
30 {copy.body && <p className="mt-3 text-muted">{copy.body}</p>}
31
32 {copy.signIn && (
33 <>
34 <div className="mt-8 flex flex-wrap justify-center gap-2">
35 <ButtonLink to={withNext("/login", here)}>Sign in</ButtonLink>
36 <ButtonLink to="/explore" variant="quiet">
37 Explore public projects
38 </ButtonLink>
39 </div>
40 <p className="mt-5 text-sm text-muted">
41 New to g1t?{" "}
42 <Link to={withNext("/register", here)} className="font-medium text-fg underline-offset-4 hover:underline">
43 {signUp.primary}
44 </Link>
45 </p>
46 </>
47 )}
48
49 {copy.signedInAs && (
50 <>
51 <div className="mt-6 flex w-full flex-col items-center gap-3 rounded-lg bg-surface px-4 py-4 text-sm ring-1 ring-line">
52 <p className="flex items-center gap-2 text-muted">
53 <Avatar name={copy.signedInAs} image={user?.avatar} size={20} />
54 Signed in as <span className="font-mono font-medium text-fg">@{copy.signedInAs}</span>
55 </p>
56 {/* Signing out, then in again, comes back here. */}
57 <Form method="post" action={`/logout?next=${encodeURIComponent(withNext("/login", here))}`}>
58 <span className="text-faint">Not you? </span>
59 <button type="submit" className="font-medium text-fg underline-offset-4 hover:underline">
60 Switch account
61 </button>
62 </Form>
63 </div>
64 {copy.askOwner && (
65 <p className="mt-4 text-sm text-muted">
66 If you should have access, ask an owner of the workspace to add you.
67 </p>
68 )}
69 <div className="mt-8 flex flex-wrap justify-center gap-2">
70 <ButtonLink to="/">Back to Mission control</ButtonLink>
71 <ButtonLink to="/explore" variant="quiet">
72 Explore
73 </ButtonLink>
74 </div>
75 </>
76 )}
77
78 {kind === "person" && (
79 <div className="mt-8 flex flex-wrap justify-center gap-2">
80 <ButtonLink to="/search?type=people">Search people</ButtonLink>
81 <ButtonLink to="/explore" variant="quiet">
82 Explore
83 </ButtonLink>
84 </div>
85 )}
86 </main>
87 );
88}