diff --git a/web/roles/role-actions-menu.react.js b/web/roles/role-actions-menu.react.js
index ddca38da9..28960cc7e 100644
--- a/web/roles/role-actions-menu.react.js
+++ b/web/roles/role-actions-menu.react.js
@@ -1,120 +1,124 @@
// @flow
import invariant from 'invariant';
import * as React from 'react';
import { useModalContext } from 'lib/components/modal-provider.react.js';
import SWMansionIcon from 'lib/components/swmansion-icon.react.js';
import {
roleIsDefaultRole,
useRoleUserSurfacedPermissions,
} from 'lib/shared/thread-utils.js';
-import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
+import type {
+ RoleInfo,
+ ThreadInfo,
+} from 'lib/types/minimally-encoded-thread-permissions-types.js';
+import { values } from 'lib/utils/objects.js';
import { useRoleDeletableAndEditableStatus } from 'lib/utils/role-utils.js';
import CreateRolesModal from './create-roles-modal.react.js';
import DeleteRoleModal from './delete-role-modal.react.js';
import css from './role-actions-menu.css';
import MenuItem from '../components/menu-item.react.js';
import Menu from '../components/menu.react.js';
const menuIcon = ;
type RoleActionsMenuProps = {
+threadInfo: ThreadInfo,
+roleName: string,
};
function RoleActionsMenu(props: RoleActionsMenuProps): React.Node {
const { threadInfo, roleName } = props;
const { pushModal } = useModalContext();
const defaultRoleID = Object.keys(threadInfo.roles).find(roleID =>
roleIsDefaultRole(threadInfo.roles[roleID]),
);
invariant(defaultRoleID, 'default role should exist');
- const existingRoleID = Object.keys(threadInfo.roles).find(
- roleID => threadInfo.roles[roleID].name === roleName,
+ const existingRole = values(threadInfo.roles).find(
+ (role: RoleInfo) => role.name === roleName,
);
- invariant(existingRoleID, 'existing role should exist');
+ invariant(existingRole, 'existing role should exist');
const roleOptions = useRoleDeletableAndEditableStatus(
roleName,
defaultRoleID,
- existingRoleID,
+ existingRole.id,
);
const roleNamesToUserSurfacedPermissions =
useRoleUserSurfacedPermissions(threadInfo);
const openEditRoleModal = React.useCallback(
() =>
pushModal(
,
),
[
- existingRoleID,
+ existingRole.id,
pushModal,
roleName,
roleNamesToUserSurfacedPermissions,
threadInfo,
],
);
const openDeleteRoleModal = React.useCallback(() => {
pushModal(
,
);
- }, [existingRoleID, pushModal, threadInfo, defaultRoleID]);
+ }, [pushModal, threadInfo, defaultRoleID, existingRole.id]);
const menuItems = React.useMemo(() => {
const availableOptions = [];
const { isDeletable, isEditable } = roleOptions;
if (isEditable) {
availableOptions.push(
,
);
}
if (isDeletable) {
availableOptions.push(
,
);
}
return availableOptions;
}, [roleOptions, openDeleteRoleModal, openEditRoleModal]);
return (
);
}
export default RoleActionsMenu;