Skip to content
102 linesCodeBlameRaw
1/**
2 * Integrations in the Marketplace: every connector a workspace can connect
3 * today, connected ones first, then the ones the catalog lists as coming.
4 * Each is set up on its own page under Workspace → Integrations; owners
5 * connect, anyone else asks.
6 */
7import { Search } from "lucide-react";
8import { useState } from "react";
9import { Link } from "react-router";
10
11import { connectorView, connectorsFor, CONNECTORS } from "@g1t/contracts/connectors";
12
13import type { Route } from "./+types/integrations";
14import { ConnectorMark } from "../../../components/connectors";
15import { ComingBadge, IntegrationCard, SectionHead } from "../../../components/marketplace";
16import { comingIntegrations, integrationListings, integrationMatches } from "../../../lib/marketplace";
17import { loadConnected } from "../../../lib/marketplace.server";
18import { requireUser, roleIn } from "../../../lib/session.server";
19import { useMarketplace } from "./layout";
20
21export async function loader({ params, context, request }: Route.LoaderArgs) {
22 const viewer = requireUser(context, request);
23 const slug = params.owner.toLowerCase();
24 if (!roleIn(viewer, slug)) throw new Response(null, { status: 404 });
25 return { connected: await loadConnected(slug, viewer) };
26}
27
28export default function MarketplaceIntegrations({ loaderData }: Route.ComponentProps) {
29 const { slug, owner, username, requests } = useMarketplace();
30 const [query, setQuery] = useState("");
31 const views = connectorsFor("workspace");
32 const all = integrationListings(views, loaderData.connected, requests?.requests ?? [], username, slug);
33 const shown = all.filter((listing) => integrationMatches(listing, query));
34 const connected = shown.filter((listing) => listing.connected);
35 const available = shown.filter((listing) => !listing.connected);
36 const wanted = query.trim().toLowerCase();
37 const personal = CONNECTORS.filter((c) => !c.scopes.includes("workspace")).map((c) => connectorView(c, "personal")).filter((view) => view != null);
38 const coming = comingIntegrations(views, personal).filter((view) => !wanted || [view.name, view.description, ...view.keywords].some((w) => w.toLowerCase().includes(wanted)));
39 return (
40 <div className="space-y-10">
41 <div className="flex flex-wrap items-center justify-between gap-3">
42 <label className="flex h-9 w-full max-w-sm items-center gap-2 rounded-lg border border-line bg-surface px-2.5 text-sm focus-within:border-line-strong">
43 <Search size={15} className="shrink-0 text-faint" />
44 <input
45 value={query}
46 onChange={(event) => setQuery(event.target.value)}
47 placeholder="Find an integration"
48 aria-label="Find an integration"
49 autoComplete="off"
50 className="min-w-0 grow bg-transparent outline-none placeholder:text-faint"
51 />
52 </label>
53 <Link to={`/${slug}/-/integrations`} className="text-[0.8125rem] text-muted hover:text-fg">
54 Workspace integrations settings
55 </Link>
56 </div>
57
58 {connected.length > 0 && (
59 <section aria-labelledby="connected">
60 <SectionHead id="connected" title="Connected" aside={`${connected.length}`} />
61 <div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
62 {connected.map((listing) => (
63 <IntegrationCard key={listing.ref} listing={listing} slug={slug} owner={owner} />
64 ))}
65 </div>
66 </section>
67 )}
68
69 <section aria-labelledby="available">
70 <SectionHead id="available" title={connected.length > 0 ? "Available" : "Available to connect"} aside={`${available.length}`} />
71 {available.length === 0 ? (
72 <p className="rounded-xl border border-dashed border-line px-4 py-6 text-center text-sm text-muted">{wanted ? "No integration you can connect matches." : "Everything available is connected."}</p>
73 ) : (
74 <div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
75 {available.map((listing) => (
76 <IntegrationCard key={listing.ref} listing={listing} slug={slug} owner={owner} />
77 ))}
78 </div>
79 )}
80 </section>
81
82 {coming.length > 0 && (
83 <section aria-labelledby="coming">
84 <SectionHead id="coming" title="Coming" aside={<ComingBadge />}>
85 Planned, not built. Nobody can connect these yet.
86 </SectionHead>
87 <ul className="grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
88 {coming.map((view) => (
89 <li key={view.id} className="flex items-center gap-3 rounded-lg border border-dashed border-line px-3 py-2.5">
90 <ConnectorMark view={view} size={28} />
91 <span className="min-w-0">
92 <span className="block truncate text-sm">{view.name}</span>
93 <span className="block truncate text-xs text-faint">{view.description}</span>
94 </span>
95 </li>
96 ))}
97 </ul>
98 </section>
99 )}
100 </div>
101 );
102}