import { useState } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { Key, RotateCw, Loader2, AlertCircle, CheckCircle, Eye, EyeOff } from 'lucide-react'; import { Card } from './ui/card'; import { Button } from './ui/button'; import { Badge } from './ui/badge'; import { Alert, AlertDescription } from './ui/alert'; import { CopyButton } from './CopyButton'; import { integrationsApi } from '../services/api/integrations'; export function IntegrationsComponent() { const queryClient = useQueryClient(); const [showToken, setShowToken] = useState(false); const [successMessage, setSuccessMessage] = useState(null); const { data, isLoading, error } = useQuery({ queryKey: ['integrations'], queryFn: () => integrationsApi.get(), }); const rotateMutation = useMutation({ mutationFn: () => integrationsApi.rotateApiToken(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['integrations'] }); setSuccessMessage('API token rotated. Update the token in any connected services.'); setTimeout(() => setSuccessMessage(null), 8000); }, }); if (isLoading) { return (
); } if (error) { return (

Error Loading Integrations

{(error as Error)?.message || 'An error occurred'}

); } const token = data?.apiToken?.token || ''; const maskedToken = token ? `${token.slice(0, 6)}${'*'.repeat(Math.max(0, token.length - 6))}` : ''; return (

Integrations

Manage API tokens and service connections

{successMessage && ( {successMessage} )} {rotateMutation.error && ( {(rotateMutation.error as Error)?.message || 'Failed to rotate token'} )}

API Token

Bearer token for authenticating with the Wild Central API

{token ? ( <> Configured ) : ( <> Not Set )}
{token && ( <>
{showToken ? token : maskedToken}

Usage

Services like Wild Cloud use this token to authenticate with Wild Central's API. Set it as the WILD_CENTRAL_TOKEN environment variable.

WILD_CENTRAL_TOKEN={showToken ? token : maskedToken}
)}
{token && (

Rotating the token will invalidate the current one. Connected services will need to be updated.

)}
); }