@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 76 lines 2.73 KB
Raw
1 import type { EnvironmentId } from "@t3tools/contracts";
2 import {
3 readHostCredentialSettings,
4 sourceControlClients,
5 } from "@t3tools/client-runtime/source-control-clients";
6 import { ExternalLinkIcon } from "lucide-react";
7 import { T, Var } from "gt-react";
8
9 import { useEnvironmentSettings } from "../hooks/useSettings";
10 import { cn } from "../lib/utils";
11 import { useEnvironmentQuery } from "../state/query";
12 import { sourceControlEnvironment } from "../state/sourceControl";
13 import { T3AppIcon } from "./T3AppIcon";
14 import { InlineButton } from "./ui/button";
15
16 /**
17 * Says when the server's forge app sign-in cannot reach `repository`, so requests there fall back
18 * to the user's own login. Renders nothing for servers that do not use the app.
19 */
20 export function SourceControlAppAccessNotice(props: {
21 readonly environmentId: EnvironmentId;
22 readonly provider: string | undefined;
23 readonly host: string | undefined;
24 /** `owner/name`. */
25 readonly repository: string;
26 readonly className?: string;
27 }) {
28 const definition = props.provider ? sourceControlClients.find(props.provider) : undefined;
29 const appSignIn = definition?.credentials?.appSignIn;
30 const host = (props.host ?? definition?.publicHost ?? "").toLowerCase();
31 const signedIn = useEnvironmentSettings(props.environmentId, (settings) =>
32 definition === undefined
33 ? false
34 : (readHostCredentialSettings(settings, definition.kind).signIns[host] ?? "").length > 0,
35 );
36 const access = useEnvironmentQuery(
37 definition !== undefined && appSignIn?.hosts.includes(host) && signedIn
38 ? sourceControlEnvironment.appAccess({
39 environmentId: props.environmentId,
40 input: { provider: definition.kind, host, repository: props.repository },
41 })
42 : null,
43 );
44 if (appSignIn === undefined || access.data?.status !== "not-covered") return null;
45 const owner = props.repository.split("/")[0] ?? props.repository;
46
47 return (
48 <div
49 role="note"
50 className={cn(
51 "flex items-center gap-2.5 bg-muted/40 px-4 py-2 text-xs text-muted-foreground",
52 props.className,
53 )}
54 >
55 <T3AppIcon className="size-4 shrink-0" />
56 <p className="min-w-0 flex-1">
57 <T>
58 <Var>{appSignIn.appName}</Var> isn't installed on{" "}
59 <span className="text-foreground">
60 <Var>{owner}</Var>
61 </span>
62 , so requests here use your own GitHub login and its lower rate limit.
63 </T>
64 </p>
65 <InlineButton
66 className="shrink-0"
67 render={<a href={appSignIn.installUrl} target="_blank" rel="noreferrer noopener" />}
68 >
69 <T>
70 Install on <Var>{owner}</Var>
71 </T>
72 <ExternalLinkIcon aria-hidden className="size-3" />
73 </InlineButton>
74 </div>
75 );
76 }