Skip to content
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
12 changes: 11 additions & 1 deletion src/app/admin/components/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ export default function UsersTable({ users }: { users: User[] }) {
const deleteUser = async (id: Schema["User"]["deleteType"]) =>
client.models.User.delete(id);
const updateUser = async (updatedData: Schema["User"]["updateType"]) => {
if (updatedData.role) {
const roleUpdateResult = await client.mutations.AddUserToGroup({
userId: updatedData.id,
groupName: updatedData.role,
});

if (roleUpdateResult.errors) {
throw new Error("Failed to update user role in Cognito");
}
}

return client.models.User.update({
id: updatedData.id,
firstName: updatedData.firstName,
lastName: updatedData.lastName,
role: updatedData.role,
teamId: updatedData.teamId,
});
};
Expand Down
29 changes: 24 additions & 5 deletions src/app/admin/users/UserTablePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,28 @@ const selectionSet = [
export type User = Pick<Schema["User"]["type"], (typeof selectionSet)[number]>;

export default async function UserTablePage() {
const { data: users } = await client.models.User.list({
selectionSet,
});
if (!users || !Array.isArray(users)) return "No participants were found";
return <UsersTable users={users} />;
//paginate incoming data
let allUsers: User[] = [];
let nextToken: string | null | undefined = undefined;

do {
const {
data: users,
nextToken: token,
}: { data?: User[]; nextToken?: string | null } =
await client.models.User.list({
selectionSet,
nextToken,
limit: 1000,
});

if (users && Array.isArray(users)) {
allUsers = [...allUsers, ...users];
}

nextToken = token;
} while (nextToken);

if (!allUsers || allUsers.length === 0) return "No participants were found";
return <UsersTable users={allUsers} />;
}
Loading