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: Setup query and placeholder components for "Team members" page #3109

Merged
merged 2 commits into from
May 3, 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
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;
Loading