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

feat: Remove a User #3706

merged 34 commits into from
Oct 2, 2024

Conversation

RODO94
Copy link
Contributor

@RODO94 RODO94 commented Sep 18, 2024

What does this PR do?

This PR tackles the Trello Ticket: https://trello.com/c/0jbcXque/3012-remove-user-in-editor?filter=member:rorydoak2

It includes a range of refactors which build on the Add User and Edit User work. We are using a Styled Component called SettingsDialog to ensure consistent styling across different modal uses. This should be extended to a style override in the theme.ts file governing the whole editor. This has been outlined as a future refactoring PR.

Unit tests have been written to ensure removing a user follows a predictable path with correct messaging while being available at the right permission level.

I had to make an adjustment to the deleteUser mutation in planx-core. It wasn't breaking but was throwing an error due to a typo in return bool.

theopensystemslab/planx-core#516

@RODO94
Copy link
Contributor Author

RODO94 commented Sep 20, 2024

The lock files have a huge amount of changes where ' become " - is there a way I can stop this?

Copy link

github-actions bot commented Sep 20, 2024

Removed vultr server and associated DNS entries

@RODO94
Copy link
Contributor Author

RODO94 commented Sep 20, 2024

Remove user in Editor

@RODO94 RODO94 marked this pull request as ready for review September 20, 2024 15:31
Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

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

A few small nits and comments on PR, please see below. I think the main areas to focus on is how the refactor of the SettingsModal is handled, and how shared types should work.

Pizza working as expected, but I hit a bug related to the cache of existing users persisting - I think we encountered and resolved something similar before?

Screen.Recording.2024-09-23.at.07.39.53.mov

The lock files have a huge amount of changes where ' become " - is there a way I can stop this?

There's some linting inconsistencies across our devices - clearly husky or prettier is not configured correctly. Let's try and solve this IRL this week 👍

@RODO94
Copy link
Contributor Author

RODO94 commented Sep 30, 2024

@DafyddLlyr for the bug, to solve the caching issue, would I need to trigger a re-rendering of the component? Would there be a reason this doesn't happen when I set state in the global store here:

export const optimisticallyUpdateExistingMember = async (
  values: UpdateEditorFormValues,
  userId: number
) => {
  const existingMembers = useStore.getState().teamMembers;
  const updatedMembers: TeamMember[] = existingMembers.map((member) => {
    if (member.id === userId) {
      return { ...values, id: userId, role: member.role };
    }
    return member;
  });
  await useStore.getState().setTeamMembers(updatedMembers);
};

See the bug is present when editing a users details as well, but not when adding, so I wonder why this is performing differently. Does Zustand not see a difference between the old array of TeamMembers and the new?

@@ -56,6 +56,7 @@ const teamMembersRoutes = compose(
} = await client.query<GetUsersForTeam>({
query: GET_USERS_FOR_TEAM_QUERY,
variables: { teamSlug },
fetchPolicy: "no-cache",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DafyddLlyr added this to resolve the caching bug when removing a user

@@ -157,4 +158,13 @@ export const teamStore: StateCreator<
setTeamMembers: async (teamMembers: TeamMember[]) => {
set(() => ({ teamMembers }));
},
deleteUser: async (userId: number) => {
try {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

trycatch() block added to throw useful error on mutation failure.

@@ -16,3 +17,14 @@ export const StyledTableRow = styled(TableRow)(({ theme }) => ({
background: theme.palette.background.paper,
},
}));

export const SettingsDialog = styled(Dialog)(({ theme }) => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This works for now, but a future PR should refactor this into a global Editor style override in the theme.ts file

</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

@RODO94 RODO94 requested a review from DafyddLlyr October 1, 2024 13:42
const Root = styled(Box, {
shouldForwardProp: (prop) => prop !== "background",
})<RootProps>(({ background, theme }) => ({
})<BoxProps & { background?: boolean }>(({ background, theme }) => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to revert bgcolor since background was a boolean to conditionally style the ServiceSettings component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found this when running tests and seeing the other places this component was used

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

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

Looking good - thanks for those changes 👍

@RODO94 RODO94 merged commit 12f22c3 into main Oct 2, 2024
12 checks passed
@RODO94 RODO94 deleted the rory/remove-user branch October 2, 2024 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants