Skip to content

Commit

Permalink
feat: Setup query and placeholder components for "Team members" page (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored May 3, 2024
1 parent f4df65a commit f047472
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
14 changes: 11 additions & 3 deletions editor.planx.uk/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,17 @@ const EditorToolbar: React.FC<{

{/* Only show team settings link if inside a team route */}
{isTeamSettingsVisible && (
<MenuItem onClick={() => navigate(`${rootTeamPath()}/settings`)}>
Team Settings
</MenuItem>
<>
<MenuItem
onClick={() => navigate(`${rootTeamPath()}/settings`)}
>
Team Settings
</MenuItem>
{/* Hidden until feature complete */}
{/* <MenuItem onClick={() => navigate(`${rootTeamPath()}/members`)}>
Team Members
</MenuItem> */}
</>
)}

{/* Only show flow settings link if inside a flow route */}
Expand Down
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>
);
};
2 changes: 2 additions & 0 deletions editor.planx.uk/src/routes/team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const routes = compose(

return import("./flow");
}),

"/members": lazy(() => import("./teamMembers")),
}),
);

Expand Down
77 changes: 77 additions & 0 deletions editor.planx.uk/src/routes/teamMembers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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 } } } }
]
}
order_by: { first_name: asc }
) {
id
firstName: first_name
lastName: last_name
isPlatformAdmin: is_platform_admin
email
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;

0 comments on commit f047472

Please sign in to comment.