-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Setup query and placeholders for TeamMembers
- Loading branch information
1 parent
2f2eb8a
commit 3ea0476
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
editor.planx.uk/src/pages/FlowEditor/components/Team/TeamMembers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Box from "@mui/material/Box"; | ||
import { Role, User } from "@opensystemslab/planx-core/types"; | ||
import React from "react"; | ||
|
||
export type TeamMember = Omit<User, "teams" | "isPlatformAdmin"> & { | ||
role: Role; | ||
}; | ||
|
||
interface Props { | ||
teamMembersByRole: Record<Role, TeamMember[]>; | ||
} | ||
|
||
export const TeamMembers: React.FC<Props> = ({ teamMembersByRole }) => { | ||
return ( | ||
<Box component="pre" sx={{ fontSize: 12 }}> | ||
{JSON.stringify(teamMembersByRole, null, 4)} | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Role, User } from "@opensystemslab/planx-core/types"; | ||
import gql from "graphql-tag"; | ||
import { groupBy } from "lodash"; | ||
import { compose, mount, route, withData } from "navi"; | ||
import { | ||
TeamMember, | ||
TeamMembers, | ||
} from "pages/FlowEditor/components/Team/TeamMembers"; | ||
import { useStore } from "pages/FlowEditor/lib/store"; | ||
import React from "react"; | ||
|
||
import { client } from "../lib/graphql"; | ||
import { makeTitle } from "./utils"; | ||
|
||
interface GetUsersForTeam { | ||
users: User[]; | ||
} | ||
|
||
const teamMembersRoutes = compose( | ||
withData((req) => ({ | ||
mountpath: req.mountpath, | ||
})), | ||
|
||
mount({ | ||
"/": route(async () => { | ||
const teamSlug = useStore.getState().teamSlug; | ||
|
||
const { | ||
data: { users }, | ||
} = await client.query<GetUsersForTeam>({ | ||
query: gql` | ||
query GetUsersForTeam($teamSlug: String!) { | ||
users( | ||
where: { | ||
_or: [ | ||
{ is_platform_admin: { _eq: true } } | ||
{ teams: { team: { slug: { _eq: $teamSlug } } } } | ||
] | ||
} | ||
) { | ||
id | ||
firstName: first_name | ||
lastName: last_name | ||
isPlatformAdmin: is_platform_admin | ||
teams(where: { team: { slug: { _eq: $teamSlug } } }) { | ||
role | ||
} | ||
} | ||
} | ||
`, | ||
variables: { teamSlug }, | ||
}); | ||
|
||
const teamMembers: TeamMember[] = users.map((user) => ({ | ||
firstName: user.firstName, | ||
lastName: user.lastName, | ||
email: user.email, | ||
id: user.id, | ||
role: user.isPlatformAdmin ? "platformAdmin" : user.teams[0].role, | ||
})); | ||
|
||
const teamMembersByRole = groupBy(teamMembers, "role") as Record< | ||
Role, | ||
TeamMember[] | ||
>; | ||
|
||
return { | ||
title: makeTitle("Team Members"), | ||
view: <TeamMembers teamMembersByRole={teamMembersByRole} />, | ||
}; | ||
}), | ||
}), | ||
); | ||
|
||
export default teamMembersRoutes; |