diff --git a/web/modals/threads/members/member.react.js b/web/modals/threads/members/member.react.js --- a/web/modals/threads/members/member.react.js +++ b/web/modals/threads/members/member.react.js @@ -9,10 +9,16 @@ import * as React from 'react'; import { useState } from 'react'; +import { + removeUsersFromThread, + changeThreadMemberRoles, +} from 'lib/actions/thread-actions'; import { memberIsAdmin, memberHasAdminPowers, threadHasPermission, + removeMemberFromThread, + switchMemberAdminRoleInThread, } from 'lib/shared/thread-utils'; import { stringForUser } from 'lib/shared/user-utils'; import { @@ -20,6 +26,10 @@ type ThreadInfo, threadPermissions, } from 'lib/types/thread-types'; +import { + useDispatchActionPromise, + useServerCall, +} from 'lib/utils/action-utils'; import Label from '../../../components/label.react'; import MenuItem from '../../../components/menu-item.react'; @@ -41,6 +51,41 @@ onMenuChange(isMenuOpen); }, [isMenuOpen, onMenuChange]); + const dispatchActionPromise = useDispatchActionPromise(); + const boundRemoveUsersFromThread = useServerCall(removeUsersFromThread); + + const onRemoveUser = React.useCallback( + () => + removeMemberFromThread( + threadInfo, + memberInfo, + dispatchActionPromise, + boundRemoveUsersFromThread, + ), + [boundRemoveUsersFromThread, dispatchActionPromise, memberInfo, threadInfo], + ); + + const isCurrentlyAdmin = memberIsAdmin(memberInfo, threadInfo); + const boundChangeThreadMemberRoles = useServerCall(changeThreadMemberRoles); + + const onSwitchAdmin = React.useCallback( + () => + switchMemberAdminRoleInThread( + threadInfo, + memberInfo, + isCurrentlyAdmin, + dispatchActionPromise, + boundChangeThreadMemberRoles, + ), + [ + boundChangeThreadMemberRoles, + dispatchActionPromise, + isCurrentlyAdmin, + memberInfo, + threadInfo, + ], + ); + const menuItems = React.useMemo(() => { const { role } = memberInfo; if (!role) { @@ -65,9 +110,15 @@ key="remove_admin" text="Remove admin" icon={faMinusCircle} + onClick={onSwitchAdmin} /> ) : ( - + ), ); } @@ -82,13 +133,14 @@ key="remove_user" text="Remove user" icon={faSignOutAlt} + onClick={onRemoveUser} dangerous />, ); } return actions; - }, [memberInfo, threadInfo]); + }, [memberInfo, onRemoveUser, onSwitchAdmin, threadInfo]); const userSettingsIcon = React.useMemo( () => ,