-
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: Add new team editor - button and modal only (#3495)
- Loading branch information
Showing
11 changed files
with
251 additions
and
12 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
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
105 changes: 105 additions & 0 deletions
105
editor.planx.uk/src/pages/FlowEditor/components/Team/components/AddNewEditorModal.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,105 @@ | ||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import Dialog from "@mui/material/Dialog"; | ||
import DialogActions from "@mui/material/DialogActions"; | ||
import DialogContent from "@mui/material/DialogContent"; | ||
import Typography from "@mui/material/Typography"; | ||
import React from "react"; | ||
import InputGroup from "ui/editor/InputGroup"; | ||
import InputLabel from "ui/editor/InputLabel"; | ||
import Input from "ui/shared/Input"; | ||
|
||
import { AddNewEditorModalProps } from "../types"; | ||
|
||
export const AddNewEditorModal = ({ | ||
showModal, | ||
setShowModal, | ||
}: AddNewEditorModalProps) => ( | ||
<Dialog | ||
aria-labelledby="dialog-heading" | ||
PaperProps={{ | ||
sx: (theme) => ({ | ||
width: "100%", | ||
maxWidth: theme.breakpoints.values.md, | ||
borderRadius: 0, | ||
borderTop: `20px solid ${theme.palette.primary.main}`, | ||
background: "#FFF", | ||
margin: theme.spacing(2), | ||
}), | ||
}} | ||
open={showModal} | ||
onClose={() => setShowModal(false)} | ||
> | ||
<form> | ||
<DialogContent> | ||
<Box sx={{ mt: 1, mb: 4 }}> | ||
<Typography variant="h3" component="h2" id="dialog-heading"> | ||
Add a new editor | ||
</Typography> | ||
</Box> | ||
<InputGroup flowSpacing> | ||
<InputLabel label="First name" htmlFor="firstname"> | ||
<Input | ||
name="firstname" | ||
onChange={() => { | ||
console.log("bla"); // TODO in next PR | ||
}} | ||
value={""} | ||
errorMessage={""} | ||
id="firstname" | ||
/> | ||
</InputLabel> | ||
<InputLabel label="Last name" htmlFor="lastname"> | ||
<Input | ||
name="lastname" | ||
onChange={() => { | ||
console.log("bla"); // TODO in next PR | ||
}} | ||
value={""} | ||
errorMessage={""} | ||
id="lastname" | ||
/> | ||
</InputLabel> | ||
<InputLabel label="Email address" htmlFor="email"> | ||
<Input | ||
name="email" | ||
onChange={() => { | ||
console.log("bla"); // TODO in next PR | ||
}} | ||
value={""} | ||
errorMessage={""} | ||
id="email" | ||
/> | ||
</InputLabel> | ||
</InputGroup> | ||
</DialogContent> | ||
<DialogActions | ||
sx={{ | ||
display: "flex", | ||
justifyContent: "flex-start", | ||
padding: 2, | ||
}} | ||
> | ||
<Box> | ||
<Button | ||
variant="contained" | ||
color="prompt" | ||
onClick={() => setShowModal(false)} // nothing yet | ||
data-testid="modal-create-user-button" | ||
> | ||
Create user | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="secondary" | ||
sx={{ ml: 1.5 }} | ||
onClick={() => setShowModal(false)} | ||
data-testid="modal-cancel-button" | ||
> | ||
Cancel | ||
</Button> | ||
</Box> | ||
</DialogActions> | ||
</form> | ||
</Dialog> | ||
); |
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
33 changes: 33 additions & 0 deletions
33
editor.planx.uk/src/pages/FlowEditor/components/Team/tests/TeamMembers.addNewEditor.test.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,33 @@ | ||
/* eslint-disable jest/expect-expect */ | ||
import { screen, within } from "@testing-library/react"; | ||
|
||
import { setupTeamMembersScreen } from "./helpers/setupTeamMembersScreen"; | ||
|
||
jest.mock("lib/featureFlags.ts", () => ({ | ||
hasFeatureFlag: jest.fn().mockReturnValue(true), | ||
})); | ||
|
||
describe("when a user views the Team members screen with the ADD_NEW_EDITOR feature flag enabled", () => { | ||
beforeEach(async () => { | ||
await setupTeamMembersScreen(); | ||
}); | ||
it("shows the 'add new editor' button", async () => { | ||
const teamEditorsTable = screen.getByTestId("team-editors"); | ||
await within(teamEditorsTable).findByText("Add a new editor"); | ||
}); | ||
}); | ||
|
||
describe("when a user with the ADD_NEW_EDITOR feature flag enabled presses 'add a new editor'", () => { | ||
beforeEach(async () => { | ||
const user = await setupTeamMembersScreen(); | ||
const teamEditorsTable = screen.getByTestId("team-editors"); | ||
const addEditorButton = await within(teamEditorsTable).findByText( | ||
"Add a new editor" | ||
); | ||
user.click(addEditorButton); | ||
}); | ||
it("opens the modal and displays the input fields", async () => { | ||
expect(await screen.findByTestId("modal-create-user-button")).toBeVisible(); | ||
expect(await screen.findByLabelText("First name")).toBeVisible(); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
editor.planx.uk/src/pages/FlowEditor/components/Team/tests/exampleTeamMembersData.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,26 @@ | ||
import { Role } from "@opensystemslab/planx-core/types"; | ||
|
||
import { TeamMember } from "../types"; | ||
|
||
export const exampleTeamMembersData: Record<Role, TeamMember[]> = { | ||
platformAdmin: [ | ||
{ | ||
firstName: "Donella", | ||
lastName: "Meadows", | ||
email: "[email protected]", | ||
id: 1, | ||
role: "platformAdmin", | ||
}, | ||
], | ||
teamEditor: [ | ||
{ | ||
firstName: "Bill", | ||
lastName: "Sharpe", | ||
email: "[email protected]", | ||
id: 2, | ||
role: "teamEditor", | ||
}, | ||
], | ||
teamViewer: [], | ||
public: [], | ||
}; |
18 changes: 18 additions & 0 deletions
18
...or.planx.uk/src/pages/FlowEditor/components/Team/tests/helpers/setupTeamMembersScreen.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,18 @@ | ||
import { screen } from "@testing-library/react"; | ||
import React from "react"; | ||
import { DndProvider } from "react-dnd"; | ||
import { HTML5Backend } from "react-dnd-html5-backend"; | ||
|
||
import { setup } from "../../../../../../testUtils"; | ||
import { TeamMembers } from "../../TeamMembers"; | ||
import { exampleTeamMembersData } from "./../exampleTeamMembersData"; | ||
|
||
export async function setupTeamMembersScreen() { | ||
const { user } = setup( | ||
<DndProvider backend={HTML5Backend}> | ||
<TeamMembers teamMembersByRole={exampleTeamMembersData} /> | ||
</DndProvider> | ||
); | ||
await screen.findByText("Team editors"); | ||
return user; | ||
} |
12 changes: 11 additions & 1 deletion
12
editor.planx.uk/src/pages/FlowEditor/components/Team/types.ts
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 |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import { Role, User } from "@opensystemslab/planx-core/types"; | ||
import React, { SetStateAction } from "react"; | ||
|
||
export type TeamMember = Omit<User, "teams" | "isPlatformAdmin"> & { | ||
role: Role; | ||
}; | ||
|
||
export interface Props { | ||
export interface TeamMembersProps { | ||
teamMembersByRole: Record<string, TeamMember[]>; | ||
} | ||
export interface MembersTableProps { | ||
members: TeamMember[]; | ||
showAddMemberButton?: boolean; | ||
setShowModal?: React.Dispatch<SetStateAction<boolean>>; | ||
} | ||
export type AddNewEditorModalProps = { | ||
showModal: boolean; | ||
setShowModal: React.Dispatch<SetStateAction<boolean>>; | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.