Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: list all the credential groups #552

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading