"use client"; import { ColumnDef } from "@tanstack/react-table"; import { IdpDataTable } from "./AdminIdpDataTable"; import { Button } from "@app/components/ui/button"; import { ArrowRight, ArrowUpDown, MoreHorizontal } from "lucide-react"; import { useState } from "react"; import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog"; import { toast } from "@app/hooks/useToast"; import { formatAxiosError } from "@app/lib/api"; import { createApiClient } from "@app/lib/api"; import { useEnvContext } from "@app/hooks/useEnvContext"; import { Badge } from "@app/components/ui/badge"; import { useRouter } from "next/navigation"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@app/components/ui/dropdown-menu"; import Link from "next/link"; export type IdpRow = { idpId: number; name: string; type: string; orgCount: number; }; type Props = { idps: IdpRow[]; }; export default function IdpTable({ idps }: Props) { const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [selectedIdp, setSelectedIdp] = useState(null); const api = createApiClient(useEnvContext()); const router = useRouter(); const deleteIdp = async (idpId: number) => { try { await api.delete(`/idp/${idpId}`); toast({ title: "Success", description: "Identity provider deleted successfully" }); router.refresh(); } catch (e) { toast({ title: "Error", description: formatAxiosError(e), variant: "destructive" }); } }; const getTypeDisplay = (type: string) => { switch (type) { case "oidc": return "OAuth2/OIDC"; default: return type; } }; const columns: ColumnDef[] = [ { id: "dots", cell: ({ row }) => { const r = row.original; return ( View settings { setSelectedIdp(r); setIsDeleteModalOpen(true); }} > Delete ); } }, { accessorKey: "idpId", header: ({ column }) => { return ( ); } }, { accessorKey: "name", header: ({ column }) => { return ( ); } }, { accessorKey: "type", header: ({ column }) => { return ( ); }, cell: ({ row }) => { const type = row.original.type; return ( {getTypeDisplay(type)} ); } }, { accessorKey: "orgCount", header: ({ column }) => { return ( ); } }, { id: "actions", cell: ({ row }) => { const siteRow = row.original; return (
); } } ]; return ( <> {selectedIdp && ( { setIsDeleteModalOpen(val); setSelectedIdp(null); }} dialog={

Are you sure you want to permanently delete the identity provider {selectedIdp.name}?

This will remove the identity provider and all associated configurations. Users who authenticate through this provider will no longer be able to log in.

To confirm, please type the name of the identity provider below.

} buttonText="Confirm Delete Identity Provider" onConfirm={async () => deleteIdp(selectedIdp.idpId)} string={selectedIdp.name} title="Delete Identity Provider" /> )} ); }