"use client"; /** * Federation Settings Page * Configure local instance federation settings (spoke configuration) * Admin-only page */ import { useState, useEffect } from "react"; import { SpokeConfigurationForm } from "@/components/federation/SpokeConfigurationForm"; import { fetchInstanceIdentity, updateInstanceConfiguration, regenerateInstanceKeys, type PublicInstanceIdentity, type UpdateInstanceRequest, } from "@/lib/api/federation"; export default function FederationSettingsPage(): React.JSX.Element { const [instance, setInstance] = useState(null); const [isLoading, setIsLoading] = useState(false); const [isSaving, setIsSaving] = useState(false); const [isRegenerating, setIsRegenerating] = useState(false); const [error, setError] = useState(null); const [saveError, setSaveError] = useState(null); const [successMessage, setSuccessMessage] = useState(null); const [showRegenerateConfirm, setShowRegenerateConfirm] = useState(false); // Load instance identity on mount useEffect(() => { void loadInstance(); }, []); const loadInstance = async (): Promise => { setIsLoading(true); setError(null); try { const data = await fetchInstanceIdentity(); setInstance(data); } catch (err) { setError( err instanceof Error ? err.message : "Unable to load instance configuration. Please try again." ); } finally { setIsLoading(false); } }; const handleSave = async (updates: UpdateInstanceRequest): Promise => { setIsSaving(true); setSaveError(null); setSuccessMessage(null); try { const updatedInstance = await updateInstanceConfiguration(updates); setInstance(updatedInstance); setSuccessMessage("Configuration saved successfully"); // Clear success message after 3 seconds setTimeout(() => { setSuccessMessage(null); }, 3000); } catch (err) { setSaveError( err instanceof Error ? err.message : "Unable to save configuration. Please try again." ); } finally { setIsSaving(false); } }; const handleRegenerateKeys = async (): Promise => { setIsRegenerating(true); setSaveError(null); setSuccessMessage(null); try { const updatedInstance = await regenerateInstanceKeys(); setInstance(updatedInstance); setSuccessMessage("Instance keypair regenerated successfully"); setShowRegenerateConfirm(false); // Clear success message after 3 seconds setTimeout(() => { setSuccessMessage(null); }, 3000); } catch (err) { setSaveError( err instanceof Error ? err.message : "Unable to regenerate keys. Please try again." ); } finally { setIsRegenerating(false); } }; // Loading state if (isLoading) { return (

Federation Settings

Loading configuration...
); } // Error state if (error) { return (

Federation Settings

Unable to Load Configuration

{error}

); } // No instance (shouldn't happen, but handle gracefully) if (!instance) { return (

Federation Settings

No instance configuration found
); } return (
{/* Page Header */}

Federation Settings

Configure your instance's federation capabilities and identity. These settings determine how your instance interacts with other Mosaic Stack instances.

{/* Success Message */} {successMessage && (
{successMessage}
)} {/* Main Configuration Form */}
{/* Advanced Section: Regenerate Keys */}

Advanced

Regenerating your instance's keypair will invalidate all existing federation connections. Connected instances will need to re-establish connections with your new public key.

{showRegenerateConfirm ? (

Confirm Keypair Regeneration

This action will disconnect all federated instances. They will need to reconnect using your new public key. This action cannot be undone.

) : ( )}
); }