From b41b5d62243dbd5106de65fce90aa57a71669e65 Mon Sep 17 00:00:00 2001 From: family36 Date: Mon, 16 Sep 2024 20:39:38 +0900 Subject: [PATCH] feat: list all the credential groups --- apps/dashboard/src/api/bandadaAPI.ts | 8 +++- apps/dashboard/src/pages/groups.tsx | 56 ++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/src/api/bandadaAPI.ts b/apps/dashboard/src/api/bandadaAPI.ts index d9f533a9..8d477445 100644 --- a/apps/dashboard/src/api/bandadaAPI.ts +++ b/apps/dashboard/src/api/bandadaAPI.ts @@ -40,9 +40,13 @@ export async function generateMagicLink( * @param adminId The admin id. * @returns The list of groups or null. */ -export async function getGroups(adminId: string): Promise { +export async function getGroups(adminId?: string): Promise { try { - const groups = await request(`${API_URL}/groups/?adminId=${adminId}`) + const url = adminId + ? `${API_URL}/groups/?adminId=${adminId}` + : `${API_URL}/groups/` + + const groups = await request(url) return groups.map((group: Group) => ({ ...group, diff --git a/apps/dashboard/src/pages/groups.tsx b/apps/dashboard/src/pages/groups.tsx index b1ae40b8..c8dc645f 100644 --- a/apps/dashboard/src/pages/groups.tsx +++ b/apps/dashboard/src/pages/groups.tsx @@ -27,6 +27,7 @@ export default function GroupsPage(): JSX.Element { const { admin } = useContext(AuthContext) const [_isLoading, setIsLoading] = useState(false) const [_groups, setGroups] = useState([]) + const [_allCredentialGroups, setAllCredentialGroups] = useState([]) const [_searchField, setSearchField] = useState("") const navigate = useNavigate() @@ -35,6 +36,7 @@ export default function GroupsPage(): JSX.Element { if (admin) { setIsLoading(true) setGroups([]) + setAllCredentialGroups([]) await Promise.all([ getOnchainGroups(admin.address).then((onchainGroups) => { @@ -49,6 +51,14 @@ export default function GroupsPage(): JSX.Element { ...offchainGroups ]) } + }), + getOffchainGroups().then((allOffchainGroups) => { + if (allOffchainGroups) { + const credentialGroups = allOffchainGroups.filter( + (group) => group.credentials !== null + ) + setAllCredentialGroups(credentialGroups) + } }) ]) @@ -153,6 +163,52 @@ export default function GroupsPage(): JSX.Element { ))} )} + + + + + + All credential groups + + + + {_isLoading && ( + + + + )} + + {!_isLoading && _allCredentialGroups.length === 0 && ( + + No credential groups found + + )} + + {!_isLoading && _allCredentialGroups.length > 0 && ( + + {_allCredentialGroups + .sort( + (a, b) => + new Date(b.createdAt || "").getTime() - + new Date(a.createdAt || "").getTime() + ) + .map((group) => ( + + + + + + ))} + + )} )