156 lines · 6.0 KB
import { useState } from "react";
import { createIntegration } from "~/fns/integrations";
import type { listIntegrations } from "~/fns/integrations";
import { useAction } from "~/hooks/use-action";
import { Button, buttonClass } from "~/ui/Button";
import { SelectField, TextField } from "~/ui/Field";
import { ErrorBanner } from "~/ui/Callout";
import { EmptyState } from "~/ui/EmptyState";
import { Panel } from "~/ui/Panel";
import { DEFAULT_INTEGRATION_EVENTS, INTEGRATION_EVENT_LABELS, INTEGRATION_EVENTS } from "~/lib/integrations";
import { IntegrationCard } from "./IntegrationCard";
import { Callout } from "~/ui/Callout";

export type IntegrationsData = Awaited<ReturnType<typeof listIntegrations>>;
export type ScopeParams = { owner: string; repo: string | null };

const WEBHOOK_KINDS = [
  { value: "slack", label: "Slack (incoming webhook)", placeholder: "https://hooks.slack.com/services/…" },
  {
    value: "google_chat",
    label: "Google Chat (space webhook)",
    placeholder: "https://chat.googleapis.com/v1/spaces/…",
  },
  { value: "webhook", label: "Generic webhook (signed JSON)", placeholder: "https://example.com/hooks/gitfor" },
] as const;

type WebhookKind = (typeof WEBHOOK_KINDS)[number]["value"];

function installHref(provider: string, scope: ScopeParams): string {
  const query = new URLSearchParams({ owner: scope.owner });
  if (scope.repo) query.set("repo", scope.repo);
  return `/integrations/${provider}/install?${query.toString()}`;
}

function ConnectApps({ data, scope }: { data: IntegrationsData; scope: ScopeParams }) {
  const apps = [
    { provider: "slack", label: "Add to Slack", enabled: data.providers.slackOAuth },
    { provider: "linear", label: "Connect Linear", enabled: data.providers.linear },
    { provider: "github", label: "Install GitHub App", enabled: data.providers.githubApp },
  ];