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: Remove a User #3706

Merged
merged 34 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5961d8e
init remove button work
RODO94 Sep 17, 2024
470f3ea
init wiring up
RODO94 Sep 18, 2024
5850037
refactor: merge modal design into one dialog comp
RODO94 Sep 19, 2024
489e74a
add showEditButton bool to remove button and fix styling
RODO94 Sep 19, 2024
63b362c
fix: unused variables
RODO94 Sep 19, 2024
dd0f118
feat: optimistic update and type change for email:null
RODO94 Sep 19, 2024
c17aa24
init test work
RODO94 Sep 19, 2024
8e6235d
refactor: move from 'remove' / 'delete' to 'archive'
RODO94 Sep 19, 2024
13937e8
testing work for basic modal function working
RODO94 Sep 19, 2024
40f0fda
move to remove naming and run success testing
RODO94 Sep 19, 2024
e927c9e
finish success and axe testing
RODO94 Sep 20, 2024
5f111fa
update planx-core refs
RODO94 Sep 20, 2024
9e35fc4
fix: alter TeamMembers tests for new mock member
RODO94 Sep 20, 2024
242acd8
fix: alter TeamMembers tests for new mock member
RODO94 Sep 20, 2024
3c412f8
ui-fix: change colSpan to 5
RODO94 Sep 20, 2024
e483c88
feat: refine naming of variables
RODO94 Sep 20, 2024
7675e91
feat: add logic to only show remove on team editor table
RODO94 Sep 20, 2024
3a3653e
remove console log
RODO94 Sep 20, 2024
fe83df1
refactor: content refinement
RODO94 Sep 20, 2024
30214e2
fix: unusued vars and testid changes:
RODO94 Sep 20, 2024
2d3ab7a
alter permission conditions to focus on content
RODO94 Sep 30, 2024
92b0118
introduce showRemoveButton bool
RODO94 Sep 30, 2024
a5bc1d6
refactor: move onClick to fns define for each action
RODO94 Sep 30, 2024
6cc2beb
refactor: switch test-id using index to member.id
RODO94 Sep 30, 2024
3347877
change settingsModal into styled comp
RODO94 Sep 30, 2024
0843ae0
remove settingsModal
RODO94 Sep 30, 2024
df879ef
refactor: move styled dialog to styles file
RODO94 Sep 30, 2024
df8dc58
refactor: update types to keep type safety in adding members
RODO94 Sep 30, 2024
8e270d5
refactor: updateEditor test refactor for new testid
RODO94 Sep 30, 2024
2809806
refactor: trycatch in store and new lock file
RODO94 Oct 1, 2024
5f5f4bb
add fetchPolicy to get users for team query
RODO94 Oct 1, 2024
5883395
refactor: yaml file resetting
RODO94 Oct 1, 2024
92950bc
refactor: use BoxProps in SettingsSection comp
RODO94 Oct 1, 2024
1f0744b
alter ServiceSection to include background boolean
RODO94 Oct 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const TeamMembers = () => {

return (
<Container maxWidth="contentWrap">
<SettingsSection testId="team-editors">
<SettingsSection data-testid="team-editors">
<Typography variant="h2" component="h3" gutterBottom>
Team editors
</Typography>
Expand All @@ -52,6 +52,7 @@ export const TeamMembers = () => {
members={activeMembers}
showAddMemberButton={isNotTemplatesTeam}
showEditMemberButton={isNotTemplatesTeam}
showRemoveMemberButton={isNotTemplatesTeam}
/>
</SettingsSection>
<SettingsSection>
Expand All @@ -67,7 +68,7 @@ export const TeamMembers = () => {
/>
</SettingsSection>
{archivedMembers.length > 0 && (
<SettingsSection>
<SettingsSection data-testid="archived-members">
<Typography variant="h2" component="h3" gutterBottom>
Archived team editors
</Typography>
Expand Down
RODO94 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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";
Expand All @@ -19,16 +18,17 @@ import {
} from "../errors/addNewEditorErrors";
import { upsertEditorSchema } from "../formSchema";
import { createAndAddUserToTeam } from "../queries/createAndAddUserToTeam";
import { updateTeamMember } from "../queries/updateUser";
import { SettingsDialog } from "../styles";
import { AddNewEditorFormValues, EditorModalProps } from "../types";
import {
optimisticallyAddNewMember,
optimisticallyUpdateExistingMember,
} from "./lib/optimisticallyUpdateMembersTable";
import { updateTeamMember } from "../queries/updateUser";

export const EditorUpsertModal = ({
showModal,
setShowModal,
showModal,
initialValues,
actionType,
}: EditorModalProps) => {
Expand All @@ -43,7 +43,7 @@ export const EditorUpsertModal = ({

const handleSubmit = async (
values: AddNewEditorFormValues,
{ resetForm }: FormikHelpers<AddNewEditorFormValues>
{ resetForm }: FormikHelpers<AddNewEditorFormValues>,
) => {
switch (actionType) {
case "add":
Expand All @@ -63,7 +63,7 @@ export const EditorUpsertModal = ({
formik.values.firstName,
formik.values.lastName,
teamId,
teamSlug
teamSlug,
).catch((err) => {
if (isUserAlreadyExistsError(err.message)) {
setShowUserAlreadyExistsError(true);
Expand All @@ -88,7 +88,7 @@ export const EditorUpsertModal = ({
}
const response = await updateTeamMember(
initialValues.id,
formik.values
formik.values,
).catch((err) => {
if (isUserAlreadyExistsError(err.message)) {
setShowUserAlreadyExistsError(true);
Expand Down Expand Up @@ -120,22 +120,10 @@ export const EditorUpsertModal = ({
});

return (
<Dialog
<SettingsDialog
aria-labelledby="dialog-heading"
data-testid={
actionType === "add" ? "dialog-create-user" : "dialog-edit-user"
}
PaperProps={{
sx: (theme) => ({
width: "100%",
maxWidth: theme.breakpoints.values.md,
borderRadius: 0,
borderTop: `20px solid ${theme.palette.primary.main}`,
background: theme.palette.background.paper,
margin: theme.spacing(2),
}),
}}
open={showModal}
data-testid={`dialog-${actionType}-user`}
open={showModal || false}
onClose={() => setShowModal(false)}
>
<form onSubmit={formik.handleSubmit}>
Expand Down Expand Up @@ -235,6 +223,6 @@ export const EditorUpsertModal = ({
</ErrorWrapper>
</DialogActions>
</form>
</Dialog>
</SettingsDialog>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Chip from "@mui/material/Chip";
import Dialog from "@mui/material/Dialog";
import { styled } from "@mui/material/styles";
import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
Expand All @@ -13,27 +14,40 @@ import React, { useState } from "react";
import Permission from "ui/editor/Permission";

import { StyledAvatar, StyledTableRow } from "./../styles";
import { MembersTableProps, TeamMember } from "./../types";
import { ActionType, MembersTableProps, TeamMember } from "./../types";
import { EditorUpsertModal } from "./EditorUpsertModal";
import { RemoveUserModal } from "./RemoveUserModal";

const EditUserButton = styled(Button)(({ theme }) => ({
color: theme.palette.primary.main,
const TableRowButton = styled(Button)(({ theme }) => ({
textDecoration: "underline",
boxShadow: "none",
"&:hover": {
boxShadow: "none",
color: theme.palette.primary.main,
textDecoration: "underline",
backgroundColor: theme.palette.action.hover,
},
}));
const EditUserButton = styled(TableRowButton)(({ theme }) => ({
RODO94 marked this conversation as resolved.
Show resolved Hide resolved
color: theme.palette.primary.light,
"&:hover": {
color: theme.palette.primary.dark,
},
}));
const RemoveUserButton = styled(TableRowButton)(({ theme }) => ({
color: theme.palette.text.secondary,
"&:hover": {
color: theme.palette.secondary.contrastText,
},
}));
RODO94 marked this conversation as resolved.
Show resolved Hide resolved

export const MembersTable = ({
members,
showAddMemberButton,
showEditMemberButton,
showRemoveMemberButton,
}: MembersTableProps) => {
const [showAddModal, setShowAddModal] = useState<boolean>(false);
const [showUpdateModal, setShowUpdateModal] = useState<boolean>(false);
const [showModal, setShowModal] = useState<boolean>(false);
const [actionType, setActionType] = useState<ActionType>("add");
const [initialValues, setInitialValues] = useState<TeamMember | undefined>();

const roleLabels: Record<string, string> = {
Expand All @@ -42,6 +56,22 @@ export const MembersTable = ({
teamViewer: "Viewer",
};

const editUser = (member: TeamMember) => {
setActionType("edit");
setShowModal(true);
setInitialValues(member);
};
const removeUser = (member: TeamMember) => {
setActionType("remove");
setShowModal(true);
setInitialValues(member);
};
const addUser = () => {
setActionType("add");
setShowModal(true);
setInitialValues(undefined);
};

const getRoleLabel = (role: string) => {
return roleLabels[role] || role;
};
Expand All @@ -62,8 +92,7 @@ export const MembersTable = ({
<TableCell colSpan={3}>
<AddButton
onClick={() => {
setInitialValues(undefined);
setShowAddModal(true);
addUser();
}}
>
Add a new editor
Expand All @@ -72,12 +101,12 @@ export const MembersTable = ({
</TableRow>
)}
</Table>
{showAddModal && (
{showModal && (
<EditorUpsertModal
showModal={showAddModal}
setShowModal={setShowAddModal}
showModal={showModal}
setShowModal={setShowModal}
initialValues={initialValues}
actionType={"add"}
actionType={actionType}
/>
)}
</>
Expand All @@ -99,6 +128,10 @@ export const MembersTable = ({
<TableCell>
<strong>Email</strong>
</TableCell>{" "}
{
// empty table cells for styling across buttons
}
<TableCell></TableCell>
<TableCell></TableCell>
</StyledTableRow>
</TableHead>
Expand Down Expand Up @@ -130,59 +163,68 @@ export const MembersTable = ({
/>
</TableCell>
<TableCell>{member.email}</TableCell>
{showEditMemberButton && (
<TableCell>
<Permission.IsPlatformAdmin>
<TableCell>
{showEditMemberButton && (
<EditUserButton
onClick={() => {
setShowUpdateModal(true);
setInitialValues(member);
editUser(member);
}}
data-testId={`edit-button-${i}`}
data-testid={`edit-button-${member.id}`}
>
Edit
</EditUserButton>
</TableCell>
)}
</Permission.IsPlatformAdmin>
</TableCell>
<TableCell>
<Permission.IsPlatformAdmin>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permission level moved inside <TableCell> to ensure consistent UI across different permission levels

{showRemoveMemberButton && (
<RemoveUserButton
onClick={() => {
removeUser(member);
}}
data-testid={`remove-button-${member.id}`}
>
Remove
</RemoveUserButton>
)}
</Permission.IsPlatformAdmin>
)}
</TableCell>
</StyledTableRow>
))}
{showAddMemberButton && (
<Permission.IsPlatformAdmin>
<TableRow>
<TableCell colSpan={3}>
<AddButton
onClick={() => {
setInitialValues(undefined);
setShowAddModal(true);
}}
>
Add a new editor
</AddButton>
</TableCell>
</TableRow>
</Permission.IsPlatformAdmin>
<TableRow>
<TableCell colSpan={5}>
<AddButton
onClick={() => {
addUser();
}}
>
Add a new editor
</AddButton>
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</TableContainer>
{showAddModal && (
<EditorUpsertModal
showModal={showAddModal}
setShowModal={setShowAddModal}
initialValues={initialValues}
actionType={"add"}
/>
)}
{showUpdateModal && (
<EditorUpsertModal
showModal={showUpdateModal}
setShowModal={setShowUpdateModal}
initialValues={initialValues}
userId={initialValues?.id || 1}
actionType={"edit"}
/>
)}
{showModal &&
(actionType === "remove" ? (
<RemoveUserModal
setShowModal={setShowModal}
showModal={showModal}
initialValues={initialValues}
actionType={actionType}
/>
) : (
<EditorUpsertModal
setShowModal={setShowModal}
showModal={showModal}
initialValues={initialValues}
actionType={actionType}
/>
))}
</>
);
};
Loading
Loading