Skip to content

Commit

Permalink
Merge pull request #552 from family36/feature/issue-323
Browse files Browse the repository at this point in the history
feat: list all the credential groups
  • Loading branch information
vplasencia authored Sep 17, 2024
2 parents 11a0a56 + b41b5d6 commit 36f937a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
8 changes: 6 additions & 2 deletions apps/dashboard/src/api/bandadaAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Group[] | null> {
export async function getGroups(adminId?: string): Promise<Group[] | null> {
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,
Expand Down
56 changes: 56 additions & 0 deletions apps/dashboard/src/pages/groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function GroupsPage(): JSX.Element {
const { admin } = useContext(AuthContext)
const [_isLoading, setIsLoading] = useState(false)
const [_groups, setGroups] = useState<Group[]>([])
const [_allCredentialGroups, setAllCredentialGroups] = useState<Group[]>([])
const [_searchField, setSearchField] = useState<string>("")
const navigate = useNavigate()

Expand All @@ -35,6 +36,7 @@ export default function GroupsPage(): JSX.Element {
if (admin) {
setIsLoading(true)
setGroups([])
setAllCredentialGroups([])

await Promise.all([
getOnchainGroups(admin.address).then((onchainGroups) => {
Expand All @@ -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)
}
})
])

Expand Down Expand Up @@ -153,6 +163,52 @@ export default function GroupsPage(): JSX.Element {
))}
</Grid>
)}

<Box h="100px" />

<HStack justifyContent="space-between" width="100%">
<Heading fontSize="40px" as="h1">
All credential groups
</Heading>
</HStack>

{_isLoading && (
<Box pt="100px">
<Spinner />
</Box>
)}

{!_isLoading && _allCredentialGroups.length === 0 && (
<Text fontSize="2xl" fontWeight="bold" pt="100px">
No credential groups found
</Text>
)}

{!_isLoading && _allCredentialGroups.length > 0 && (
<Grid
templateColumns="repeat(3, 1fr)"
gap={10}
w="100%"
mt="60px"
>
{_allCredentialGroups
.sort(
(a, b) =>
new Date(b.createdAt || "").getTime() -
new Date(a.createdAt || "").getTime()
)
.map((group) => (
<Link
key={group.id + group.name}
to={`/groups/${group.type}/${group.id}`}
>
<GridItem>
<GroupCard {...group} />
</GridItem>
</Link>
))}
</Grid>
)}
</VStack>
</Container>
)
Expand Down

0 comments on commit 36f937a

Please sign in to comment.