import React, { useState, useCallback } from "react"; import { useFetcher } from "@remix-run/react"; import { Button } from "~/components/ui/button"; import { Input } from "~/components/ui/input"; interface ApiKeyAuthSectionProps { integration: { id: string; name: string; }; specData: any; activeAccount: any; } export function ApiKeyAuthSection({ integration, specData, activeAccount, }: ApiKeyAuthSectionProps) { const [apiKey, setApiKey] = useState(""); const [isLoading, setIsLoading] = useState(false); const [showApiKeyForm, setShowApiKeyForm] = useState(false); const apiKeyFetcher = useFetcher(); const handleApiKeyConnect = useCallback(() => { if (!apiKey.trim()) return; setIsLoading(true); apiKeyFetcher.submit( { integrationDefinitionId: integration.id, apiKey, }, { method: "post", action: "/api/v1/integration_account", encType: "application/json", }, ); }, [integration.id, apiKey, apiKeyFetcher]); React.useEffect(() => { if (apiKeyFetcher.state === "idle" && isLoading) { if (apiKeyFetcher.data !== undefined) { window.location.reload(); } } }, [apiKeyFetcher.state, apiKeyFetcher.data, isLoading]); if (activeAccount || !specData?.auth?.api_key) { return null; } return (

API Key Authentication

{!showApiKeyForm ? ( ) : (
setApiKey(e.target.value)} /> {specData?.auth?.api_key?.description && (

{specData.auth.api_key.description}

)}
)}
); }