Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Integrations are a directory of connectors, for a workspace and for each person | 1 | import { Link } from "react-router"; |
| 2 | ||
| 3 | import { connectorsFor } from "@g1t/contracts/connectors"; | |
| 4 | ||
| 5 | import type { Route } from "./+types/integrations"; | |
| 6 | import { ConnectorDirectory } from "../../components/connectors"; | |
| 7 | import type { ConnectedState } from "../../lib/connectors"; | |
| 8 | import { githubSignIn } from "../../lib/github.server"; | |
| 9 | import { page } from "../../lib/meta"; | |
| 10 | import { identity } from "../../lib/services.server"; | |
| 11 | import { requireUser } from "../../lib/session.server"; | |
| 12 | ||
| 13 | export function meta(args: Route.MetaArgs) { | |
| 14 | return page(args, { title: "Integrations · Settings · g1t" }); | |
| 15 | } | |
| 16 | ||
| 17 | /** | |
| 18 | * Your own integrations: the connector directory's personal side, with | |
| 19 | * what you have connected (GitHub sign-in, applications on the MCP server). | |
| 20 | * Each is still set up on its own settings page. | |
| 21 | */ | |
| 22 | export async function loader({ request, context }: Route.LoaderArgs) { | |
| 23 | const user = requireUser(context, request); | |
| 24 | const [github, grants] = await Promise.all([ | |
| 25 | githubSignIn.account(user).catch(() => null), | |
| 26 | identity.listOAuthGrants(user).catch(() => []), | |
| 27 | ]); | |
| 28 | const connected: Record<string, ConnectedState> = {}; | |
| 29 | if (github?.account) { | |
| 30 | connected.github = { | |
| 31 | detail: `Linked to @${github.account.login}`, | |
| 32 | problem: github.account.authorized ? null : "Access ended: link it again to import repositories.", | |
| 33 | manage: null, | |
| 34 | }; | |
| 35 | } | |
| 36 | if (grants.length > 0) { | |
| 37 | connected.mcp = { | |
| 38 | detail: grants.length === 1 ? grants[0]!.clientName : `${grants.length} applications`, | |
| 39 | problem: null, | |
| 40 | manage: null, | |
| 41 | }; | |
| 42 | } | |
| 43 | const workspaces = (user.workspaces ?? []).map((membership) => ({ slug: membership.slug, name: membership.name ?? membership.slug })); | |
| 44 | return { connected, workspaces }; | |
| 45 | } | |
| 46 | ||
| 47 | export default function PersonalIntegrations({ loaderData }: Route.ComponentProps) { | |
| 48 | const { connected, workspaces } = loaderData; | |
| 49 | return ( | |
| 50 | <div> | |
| 51 | <ConnectorDirectory | |
| 52 | scope="personal" | |
| 53 | views={connectorsFor("personal")} | |
| 54 | connected={connected} | |
| 55 | workspace={null} | |
| 56 | canManage | |
| 57 | nav="chips" | |
| 58 | /> | |
| 59 | {workspaces.length > 0 && ( | |
| 60 | <p className="mt-10 border-t border-line pt-5 text-sm text-muted"> | |
| 61 | Tools the whole team shares are connected for each workspace:{" "} | |
| 62 | {workspaces.map((workspace, index) => ( | |
| 63 | <span key={workspace.slug}> | |
| 64 | {index > 0 && ", "} | |
| 65 | <Link to={`/${workspace.slug}/-/integrations`} className="text-accent hover:underline"> | |
| 66 | {workspace.name} | |
| 67 | </Link> | |
| 68 | </span> | |
| 69 | ))} | |
| 70 | . | |
| 71 | </p> | |
| 72 | )} | |
| 73 | </div> | |
| 74 | ); | |
| 75 | } |