Skip to content

Commit e620801

Browse files
Merge pull request #13127 from mezonai/bug26b/webdesktop/Not-list-updated-when-removing-user/role-from-private-channel
260520 - WEB/DESKTOP - Not list updated when removing user/role from private channel
2 parents ce85568 + 8d2de4e commit e620801

3 files changed

Lines changed: 23 additions & 19 deletions

File tree

libs/components/src/lib/components/ChannelSetting/Component/Modal/addMemRoleModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const AddMemRole: React.FC<AddMemRoleProps> = ({
7070
);
7171

7272
const usersClan = useSelector(selectAllUserClans);
73-
const userChannelIds = getUserChannelIdsFromStore(channel.channel_id);
73+
const userChannelIds = getUserChannelIdsFromStore(channel.id);
7474

7575
const listUserInvite = useMemo(() => {
7676
if (channel.channel_private !== 1) {

libs/components/src/lib/components/ChannelSetting/Component/PermissionsChannel/listMemberPermission.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { channelUsersActions, selectCurrentClanId, selectMemberClanByUserId, sel
44
import { Icons } from '@mezon/ui';
55
import type { IChannel } from '@mezon/utils';
66
import { createImgproxyUrl, generateE2eId, getAvatarForPrioritize, getNameForPrioritize } from '@mezon/utils';
7+
import { useMemo } from 'react';
78
import { useTranslation } from 'react-i18next';
89
import { useSelector } from 'react-redux';
910
import { AvatarImage } from '../../../AvatarImage/AvatarImage';
@@ -19,11 +20,24 @@ const ListMemberPermission = (props: ListMemberPermissionProps) => {
1920

2021
const dispatch = useAppDispatch();
2122
const idUsers = useSelector((state) => selectUserChannelIds(state, channel.id));
23+
const displayUserIds = useMemo(() => {
24+
const sourceIds = channel.channel_private === 1 ? idUsers : props.selectedUserIds;
25+
return Array.from(new Set(sourceIds.filter(Boolean)));
26+
}, [channel.channel_private, idUsers, props.selectedUserIds]);
2227
const currentClanId = useSelector(selectCurrentClanId);
2328
const navigate = useCustomNavigate();
2429
const userProfile = useAuth();
2530
const { toMembersPage } = useAppNavigation();
31+
2632
const deleteMember = async (userId: string) => {
33+
if (channel.channel_private !== 1) {
34+
props.setSelectedUserIds?.(props.selectedUserIds.filter((selectedId) => selectedId !== userId));
35+
return;
36+
}
37+
38+
if (!idUsers.includes(userId)) {
39+
return;
40+
}
2741
const body: removeChannelUsersPayload = {
2842
channelId: channel.id,
2943
userId,
@@ -36,15 +50,8 @@ const ListMemberPermission = (props: ListMemberPermissionProps) => {
3650
}
3751
};
3852

39-
return idUsers.map((id) => (
40-
<ItemMemberPermission
41-
key={id}
42-
id={id}
43-
onDelete={() => deleteMember(id as string)}
44-
channelOwner={channel.creator_id === id}
45-
selectedUserIds={props.selectedUserIds}
46-
setSelectedUserIds={props.setSelectedUserIds}
47-
/>
53+
return displayUserIds.map((id) => (
54+
<ItemMemberPermission key={id} id={id} onDelete={() => deleteMember(id as string)} channelOwner={channel.creator_id === id} />
4855
));
4956
};
5057

@@ -59,21 +66,15 @@ type ItemMemberPermissionProps = {
5966
clanAvatar?: string;
6067
onDelete: () => void;
6168
channelOwner?: boolean;
62-
selectedUserIds?: string[];
63-
setSelectedUserIds?: (userIds: string[]) => void;
6469
};
6570

6671
const ItemMemberPermission = (props: ItemMemberPermissionProps) => {
67-
const { id = '', onDelete, channelOwner, selectedUserIds = [], setSelectedUserIds } = props;
72+
const { id = '', onDelete, channelOwner } = props;
6873
const user = useSelector((state) => selectMemberClanByUserId(state, id));
6974
const namePrioritize = getNameForPrioritize(user?.clan_nick, user?.user?.display_name, user?.user?.username);
7075
const avatarPrioritize = getAvatarForPrioritize(user?.clan_avatar, user?.user?.avatar_url);
7176

7277
const handleDelete = () => {
73-
if (setSelectedUserIds && selectedUserIds) {
74-
const newSelectedUserIds = selectedUserIds.filter((userId) => userId !== id);
75-
setSelectedUserIds(newSelectedUserIds);
76-
}
7778
if (!channelOwner) {
7879
onDelete();
7980
}

libs/store/src/lib/permissionChannel/permissionChannel.slice.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type addChannelUsersPayload = {
1616
};
1717
export const addChannelUsers = createAsyncThunk(
1818
'channelUsers/addChannelUsers',
19-
async ({ channelId, channelType, userIds, clanId }: addChannelUsersPayload, thunkAPI) => {
19+
async ({ channelId, channelType, userIds, clanId: _clanId }: addChannelUsersPayload, thunkAPI) => {
2020
try {
2121
const mezon = await ensureSession(getMezonCtx(thunkAPI));
2222
const response = await mezon.client.addChannelUsers(mezon.session, channelId, userIds);
@@ -59,14 +59,17 @@ export type banChannelUsersPayload = {
5959

6060
export const removeChannelUsers = createAsyncThunk(
6161
'channelUsers/removeChannelUsers',
62-
async ({ channelId, userId }: removeChannelUsersPayload, thunkAPI) => {
62+
async ({ channelId, userId, channelType: _channelType }: removeChannelUsersPayload, thunkAPI) => {
6363
try {
6464
const mezon = await ensureSession(getMezonCtx(thunkAPI));
6565
const userIds = [userId];
6666
const response = await mezon.client.removeChannelUsers(mezon.session, channelId, userIds);
6767
if (!response) {
6868
return thunkAPI.rejectWithValue([]);
6969
}
70+
if (channelId) {
71+
thunkAPI.dispatch(userChannelsActions.removeUserChannel({ channelId, userRemoves: userIds }));
72+
}
7073

7174
return response;
7275
} catch (error) {

0 commit comments

Comments
 (0)