import React from "react"; import { CheckCircle, AlertCircle } from "lucide-react"; import { Badge } from "@/src/components/ui/badge"; import { Button } from "@/src/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/src/components/ui/card"; import { Alert, AlertDescription } from "@/src/components/ui/alert"; import { api } from "@/src/utils/api"; import { SlackConnectButton } from "@/src/features/slack/components/SlackConnectButton"; import { SlackDisconnectButton } from "@/src/features/slack/components/SlackDisconnectButton"; /** * Props for the SlackConnectionCard component */ interface SlackConnectionCardProps { /** Project ID for the Slack integration */ projectId: string; /** Whether the component is disabled */ disabled?: boolean; /** Optional callback when connection status changes */ onConnectionChange?: (connected: boolean) => void; /** Whether to show the connect button in the card */ showConnectButton?: boolean; } /** * A reusable card component that displays Slack connection status and management controls. * * This component handles: * - Displaying current connection status * - Showing team information when connected * - Providing connection and disconnection actions * - Handling error states with appropriate messaging * * The component automatically fetches the integration status and updates when the connection changes. * * @param projectId - The project ID for the Slack integration * @param disabled - Whether the component should be disabled * @param onConnectionChange - Optional callback when connection status changes * @param showConnectButton - Whether to show the connect button in the card (default: true) */ export const SlackConnectionCard: React.FC = ({ projectId, disabled = false, onConnectionChange, showConnectButton = true, }) => { // Get Slack integration status const { data: integrationStatus, isLoading, refetch: refetchStatus, error: statusError, } = api.slack.getIntegrationStatus.useQuery( { projectId }, { enabled: !!projectId, // Refetch every 30 seconds to keep status up to date refetchInterval: 30000, }, ); // Handle connection status change const handleConnectionChange = (connected: boolean) => { refetchStatus(); onConnectionChange?.(connected); }; // Handle loading state if (isLoading) { return ( Slack Connection Checking connection status...
Loading...
); } // Handle error state if (statusError) { return ( Slack Connection Error loading connection status Failed to load Slack integration status. Please try again. ); } // Handle not connected state if (!integrationStatus?.isConnected) { return ( Slack Connection Connect your Slack workspace to send notifications {integrationStatus?.error && ( {integrationStatus.error} )}

Connect your Slack workspace to enable real-time notifications for your automations.

{showConnectButton && ( handleConnectionChange(true)} onError={(error: Error) => { console.error("Slack connection error:", error); }} /> )}
); } // Handle connected state return ( Slack Connection Connected to your Slack workspace {/* Connection Status */}
Connected
{/* Team Information */}
Workspace: {integrationStatus.teamName}
Team ID: {integrationStatus.teamId}
{integrationStatus.botUserId && (
Bot User: {integrationStatus.botUserId}
)}
{/* Management Actions */}
handleConnectionChange(false)} onError={(error: Error) => { console.error("Slack disconnection error:", error); }} />
); };