Skip to content

Commit

Permalink
Add ManagedGroups section to user page
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogasp committed Nov 22, 2024
1 parent 5db1ca0 commit 598e1ed
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/app/(pages)/users/[user]/components/ManagedGroups/Table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Link from "@/components/Link";
import { ManagedGroup } from "@/models/groups";

type ManagedGroupsTableProps = {
managedGroups: ManagedGroup[];
};

export default function ManagedGroupsTable(
props: Readonly<ManagedGroupsTableProps>
) {
const { managedGroups } = props;
return (
<table className="w-full table-auto rounded-lg">
<tbody>
{managedGroups.map(group => (
<tr key={group.id} className="tbl-tr">
<td className="tbl-td">
<Link href={`/groups/${group.id}`}>{group.name}</Link>
</td>
</tr>
))}
</tbody>
</table>
);
}
23 changes: 23 additions & 0 deletions src/app/(pages)/users/[user]/components/ManagedGroups/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { User } from "@/models/scim";
import { fetchManagedGroups } from "@/services/groups";
import ManagedGroupsTable from "./Table";
import { Section } from "@/components/Layout";

type ManagedGroupsProps = {
user: User;
};

export default async function ManagedGroups(
props: Readonly<ManagedGroupsProps>
) {
const { user } = props;
const { managedGroups } = await fetchManagedGroups(user.id);
if (managedGroups.length === 0) {
return null;
}
return (
<Section title="Managed Groups">
<ManagedGroupsTable managedGroups={managedGroups} />
</Section>
);
}
2 changes: 2 additions & 0 deletions src/app/(pages)/users/[user]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Groups } from "./components/Groups";
import { LinkedAccounts } from "./components/LinkedAccounts";
import SSHKeys from "./components/SSHKeys";
import Attributes from "./components/Attributes";
import ManagedGroups from "./components/ManagedGroups";

type UserPageProps = {
params: { user: string };
Expand All @@ -32,6 +33,7 @@ export default async function UserPage(props: Readonly<UserPageProps>) {
<UserInfo user={user} isMe={isMe} />
<Groups user={user} isAdmin={isAdmin} />
<GroupRequests user={user} isMe={isMe} />
<ManagedGroups user={user} />
<LinkedAccounts user={user} />
<Certificates user={user} />
<SSHKeys user={user} />
Expand Down
16 changes: 16 additions & 0 deletions src/models/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ export interface GroupsSearchResponse {
startIndex: number;
Resources: Group[];
}

export interface ManagedGroup {
id: string;
name: string;
description?: string;
parent?: string;
}

export type UnmanagedGroup = ManagedGroup;

export type ManagedGroupResponse = {
id: string;
username: string;
managedGroups: ManagedGroup[];
unmanagedGroups: ManagedGroup[];
};
11 changes: 10 additions & 1 deletion src/services/groups/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"use server";
import { Group, GroupsSearchResponse } from "@/models/groups";
import {
Group,
GroupsSearchResponse,
ManagedGroupResponse,
} from "@/models/groups";
import { authFetch, getItem } from "@/utils/fetch";
import getConfig from "@/utils/config";
import { Paginated } from "@/models/pagination";
Expand Down Expand Up @@ -249,3 +253,8 @@ export const revokeGroupManager = async (groupId: string, userId: string) => {
});
}
};

export async function fetchManagedGroups(userId: string) {
const url = `${BASE_URL}/iam/account/${userId}/managed-groups`;
return getItem<ManagedGroupResponse>(url);
}

0 comments on commit 598e1ed

Please sign in to comment.