-
Notifications
You must be signed in to change notification settings - Fork 929
feat: add warning dialog when removing member from organization #14695
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { | ||
groupsByUserId, | ||
groupsByUserIdInOrganization, | ||
} from "api/queries/groups"; | ||
import type { Interpolation, Theme } from "@emotion/react"; | ||
import { getErrorMessage } from "api/errors"; | ||
import { groupsByUserIdInOrganization } from "api/queries/groups"; | ||
import { | ||
addOrganizationMember, | ||
organizationMembers, | ||
|
@@ -11,9 +10,12 @@ import { | |
} from "api/queries/organizations"; | ||
import { organizationRoles } from "api/queries/roles"; | ||
import type { OrganizationMemberWithUserData, User } from "api/typesGenerated"; | ||
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"; | ||
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils"; | ||
import { Loader } from "components/Loader/Loader"; | ||
import { Stack } from "components/Stack/Stack"; | ||
import { useAuthenticated } from "contexts/auth/RequireAuth"; | ||
import type { FC } from "react"; | ||
import { type FC, useState } from "react"; | ||
import { useMutation, useQuery, useQueryClient } from "react-query"; | ||
import { useParams } from "react-router-dom"; | ||
import { useOrganizationSettings } from "./ManagementSettingsLayout"; | ||
|
@@ -52,45 +54,96 @@ const OrganizationMembersPage: FC = () => { | |
const organization = organizations?.find((o) => o.name === organizationName); | ||
const permissionsQuery = useQuery(organizationPermissions(organization?.id)); | ||
|
||
const [memberToDelete, setMemberToDelete] = | ||
useState<OrganizationMemberWithUserData>(); | ||
|
||
const permissions = permissionsQuery.data; | ||
if (!permissions) { | ||
return <Loader />; | ||
} | ||
|
||
return ( | ||
<OrganizationMembersPageView | ||
allAvailableRoles={organizationRolesQuery.data} | ||
canEditMembers={permissions.editMembers} | ||
error={ | ||
membersQuery.error ?? | ||
addMemberMutation.error ?? | ||
removeMemberMutation.error ?? | ||
updateMemberRolesMutation.error | ||
} | ||
isAddingMember={addMemberMutation.isLoading} | ||
isUpdatingMemberRoles={updateMemberRolesMutation.isLoading} | ||
me={me} | ||
members={members} | ||
groupsByUserId={groupsByUserIdQuery.data} | ||
addMember={async (user: User) => { | ||
await addMemberMutation.mutateAsync(user.id); | ||
void membersQuery.refetch(); | ||
}} | ||
removeMember={async (member: OrganizationMemberWithUserData) => { | ||
await removeMemberMutation.mutateAsync(member.user_id); | ||
void membersQuery.refetch(); | ||
}} | ||
updateMemberRoles={async ( | ||
member: OrganizationMemberWithUserData, | ||
newRoles: string[], | ||
) => { | ||
await updateMemberRolesMutation.mutateAsync({ | ||
userId: member.user_id, | ||
roles: newRoles, | ||
}); | ||
}} | ||
/> | ||
<> | ||
<OrganizationMembersPageView | ||
allAvailableRoles={organizationRolesQuery.data} | ||
canEditMembers={permissions.editMembers} | ||
error={ | ||
membersQuery.error ?? | ||
addMemberMutation.error ?? | ||
removeMemberMutation.error ?? | ||
updateMemberRolesMutation.error | ||
} | ||
isAddingMember={addMemberMutation.isLoading} | ||
isUpdatingMemberRoles={updateMemberRolesMutation.isLoading} | ||
me={me} | ||
members={members} | ||
groupsByUserId={groupsByUserIdQuery.data} | ||
addMember={async (user: User) => { | ||
await addMemberMutation.mutateAsync(user.id); | ||
void membersQuery.refetch(); | ||
}} | ||
removeMember={setMemberToDelete} | ||
updateMemberRoles={async ( | ||
member: OrganizationMemberWithUserData, | ||
newRoles: string[], | ||
) => { | ||
await updateMemberRolesMutation.mutateAsync({ | ||
userId: member.user_id, | ||
roles: newRoles, | ||
}); | ||
}} | ||
/> | ||
|
||
<ConfirmDialog | ||
type="delete" | ||
open={memberToDelete !== undefined} | ||
onClose={() => setMemberToDelete(undefined)} | ||
title="Remove member" | ||
confirmText="Remove" | ||
onConfirm={async () => { | ||
try { | ||
if (memberToDelete) { | ||
await removeMemberMutation.mutateAsync(memberToDelete?.user_id); | ||
} | ||
setMemberToDelete(undefined); | ||
await membersQuery.refetch(); | ||
displaySuccess("User removed from organization successfully!"); | ||
} catch (error) { | ||
setMemberToDelete(undefined); | ||
displayError( | ||
getErrorMessage(error, "Failed to remove user from organization"), | ||
); | ||
} | ||
}} | ||
description={ | ||
<Stack> | ||
<p> | ||
Removing this member will: | ||
<ul> | ||
<li>Remove the member from all groups in this organization</li> | ||
<li>Remove all user role assignments</li> | ||
<li> | ||
Orphan all the member's workspaces associated with this | ||
organization | ||
</li> | ||
</ul> | ||
</p> | ||
|
||
<p css={styles.test}> | ||
Are you sure you want to remove{" "} | ||
<strong>{memberToDelete?.username}</strong>? | ||
</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any way we could fiddle the types so that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feels difficult to remove the undefined from memberToDelete without restructuring the pattern that ConfirmDialog uses. For now, maybe its safer to just not display the username here. |
||
</Stack> | ||
} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
const styles = { | ||
test: { | ||
paddingBottom: 20, | ||
}, | ||
} satisfies Record<string, Interpolation<Theme>>; | ||
|
||
export default OrganizationMembersPage; |
Uh oh!
There was an error while loading. Please reload this page.