import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { Edit, Globe, Plus, Save, Trash2 } from "lucide-react"; import { useState } from "react"; import { useParams } from "react-router-dom"; import { Button } from "../../../components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "../../../components/ui/card"; import { Input } from "../../../components/ui/input"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../../../components/ui/table"; import { createIdpConfigForClient, listIdpConfigsForClient, } from "../../../lib/devApi"; import type { IdpConfig, IdpConfigCreateRequest } from "../../../lib/devApi"; import { t } from "../../../lib/i18n"; // Proper Modal Component with Form const CreateIdpModal = ({ isOpen, onClose, clientId, }: { isOpen: boolean; onClose: () => void; clientId: string; }) => { const queryClient = useQueryClient(); const [formData, setFormData] = useState({ client_id: clientId, provider_type: "oidc", display_name: "", status: "active", issuer_url: "", oidc_client_id: "", oidc_client_secret: "", scopes: "openid email profile", }); const mutation = useMutation({ mutationFn: (newData: IdpConfigCreateRequest) => createIdpConfigForClient(newData), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["idpConfigs", clientId] }); onClose(); }, onError: (error) => { alert(`Failed to create configuration: ${error.message}`); }, }); const handleChange = ( e: React.ChangeEvent, ) => { const { name, value } = e.target; setFormData((prev) => ({ ...prev, [name]: value, })); }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); mutation.mutate(formData); }; if (!isOpen) return null; return (
{t("ui.dev.clients.federation.add_title", "Add Identity Provider")} {t( "msg.dev.clients.federation.add_subtitle", "Connect an external OIDC provider.", )}
); }; export function ClientFederationPage() { const { id: clientId } = useParams<{ id: string }>(); const [isCreateModalOpen, setCreateModalOpen] = useState(false); if (!clientId) { return (
Client ID is missing
); } const { data, isLoading, error } = useQuery({ queryKey: ["idpConfigs", clientId], queryFn: () => listIdpConfigsForClient(clientId), }); return (

{t("ui.dev.clients.federation.title", "Identity Federation")}

{t( "msg.dev.clients.federation.subtitle", "Manage external identity providers for this application.", )}

Display Name Provider Type Status Actions {isLoading ? ( {t("msg.common.loading", "Loading...")} ) : error ? ( {(error as Error).message} ) : data?.length === 0 ? ( {t( "msg.dev.clients.federation.empty", "No IdP configurations found.", )} ) : ( data?.map((config: IdpConfig) => ( {config.display_name} {config.provider_type.toUpperCase()} {config.status}
)) )}
setCreateModalOpen(false)} clientId={clientId} />
); }