diff --git a/adminfront/src/features/tenants/routes/TenantListPage.tsx b/adminfront/src/features/tenants/routes/TenantListPage.tsx index 43cec0d5..9cdbe340 100644 --- a/adminfront/src/features/tenants/routes/TenantListPage.tsx +++ b/adminfront/src/features/tenants/routes/TenantListPage.tsx @@ -61,6 +61,7 @@ import { serializeTenantImportCSV, } from "../utils/tenantCsvImport"; import { isSeedTenant } from "../utils/protectedTenants"; +import { buildTenantFullTree, type TenantNode } from "../../../lib/tenantTree"; const tenantCSVTemplate = "name,type,parent_tenant_slug,slug,memo,email_domain\n"; @@ -211,8 +212,25 @@ function TenantListPage() { : null; const allTenants = query.data?.items ?? []; + const tenantsWithRecursiveCount = React.useMemo(() => { + // Build tree to calculate recursiveMemberCount, but we map it back to a flat array for the table + const { subTree } = buildTenantFullTree(allTenants); + + const flatMap = new Map(); + const flatten = (nodes: TenantNode[]) => { + for (const node of nodes) { + flatMap.set(node.id, node); + flatten(node.children); + } + }; + flatten(subTree); + + // Map back to allTenants ensuring recursiveMemberCount is present + return allTenants.map((t) => flatMap.get(t.id) ?? { ...t, children: [], recursiveMemberCount: t.memberCount || 0 }); + }, [allTenants]); + const tenants = React.useMemo(() => { - let filtered = allTenants; + let filtered = tenantsWithRecursiveCount; if (search.trim()) { const term = search.toLowerCase(); filtered = filtered.filter( @@ -232,7 +250,7 @@ function TenantListPage() { if (valA > valB) return sortOrder === "asc" ? 1 : -1; return 0; }); - }, [allTenants, search, sortKey, sortOrder]); + }, [tenantsWithRecursiveCount, search, sortKey, sortOrder]); const deletableTenants = React.useMemo( () => tenants.filter((tenant) => !isSeedTenant(tenant)), @@ -701,9 +719,8 @@ function TenantListPage() { - {tenant.memberCount} - - + {(tenant as unknown as TenantNode).recursiveMemberCount ?? tenant.memberCount} + {tenant.updatedAt ? new Date(tenant.updatedAt).toLocaleString("ko-KR") : "-"}