Page MenuHomePhabricator

D3382.id10204.diff
No OneTemporary

D3382.id10204.diff

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}
/>
) : (
- <MenuItem key="make_admin" text="Make admin" icon={faPlusCircle} />
+ <MenuItem
+ key="make_admin"
+ text="Make admin"
+ icon={faPlusCircle}
+ 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(
() => <SWMansionIcon icon="edit" size={17} />,

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 17, 8:55 PM (20 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2531797
Default Alt Text
D3382.id10204.diff (2 KB)

Event Timeline