diff --git a/app/components/user_list/index.tsx b/app/components/user_list/index.tsx index 0706df928..9383e1cda 100644 --- a/app/components/user_list/index.tsx +++ b/app/components/user_list/index.tsx @@ -61,30 +61,30 @@ const sectionRoleKeyExtractor = (cAdmin: boolean) => { return cAdmin ? messages.admins : messages.members; }; -export function createProfilesSections(intl: IntlShape, profiles: UserProfile[], members?: ChannelMember[]) { +export function createProfilesSections(intl: IntlShape, profiles: UserProfile[], members?: ChannelMembership[]) { if (!profiles.length) { return []; } - const sections = new Map(); + const sections = new Map(); if (members?.length) { // when channel members are provided, build the sections by admins and members - const membersDictionary = new Map(); - const membersSections = new Map(); + const membersDictionary = new Map(); + const membersSections = new Map(); const {formatMessage} = intl; members.forEach((m) => membersDictionary.set(m.user_id, m)); profiles.forEach((p) => { const member = membersDictionary.get(p.id); - const sectionKey = sectionRoleKeyExtractor(member.scheme_admin!); - const sectionValue = membersSections.get(sectionKey) || []; - - // combine UserProfile and ChannelMember objects so can get channel member scheme_admin permission - const section = [...sectionValue, {...p, ...member}]; - membersSections.set(sectionKey, section); + if (member) { + const sectionKey = sectionRoleKeyExtractor(member.scheme_admin!).id; + const section = membersSections.get(sectionKey) || []; + section.push(p); + membersSections.set(sectionKey, section); + } }); - sections.set(formatMessage(messages.admins), membersSections.get(messages.admins)); - sections.set(formatMessage(messages.members), membersSections.get(messages.members)); + sections.set(formatMessage(messages.admins), membersSections.get(messages.admins.id) || []); + sections.set(formatMessage(messages.members), membersSections.get(messages.members.id) || []); } else { // when channel members are not provided, build the sections alphabetically profiles.forEach((p) => { @@ -98,13 +98,11 @@ export function createProfilesSections(intl: IntlShape, profiles: UserProfile[], const results = []; let index = 0; for (const [k, v] of sections) { - if (v) { - results.push({ - first: index === 0, - id: k, - data: v, - }); - } + results.push({ + first: index === 0, + id: k, + data: v, + }); index++; } return results; @@ -147,11 +145,11 @@ const getStyleFromTheme = makeStyleSheetFromTheme((theme) => { type Props = { profiles: UserProfile[]; - channelMembers?: ChannelMember[]; + channelMembers?: ChannelMembership[]; currentUserId: string; teammateNameDisplay: string; handleSelectProfile: (user: UserProfile) => void; - fetchMore: () => void; + fetchMore?: () => void; loading: boolean; manageMode?: boolean; showManageMode?: boolean; @@ -332,4 +330,3 @@ export default function UserList({ } return renderSectionList(data as Array>); } - diff --git a/app/screens/manage_channel_members/manage_channel_members.tsx b/app/screens/manage_channel_members/manage_channel_members.tsx index 81e1199e2..920bbf53f 100644 --- a/app/screens/manage_channel_members/manage_channel_members.tsx +++ b/app/screens/manage_channel_members/manage_channel_members.tsx @@ -218,6 +218,7 @@ export default function ManageChannelMembers({ useEffect(() => { mounted.current = true; + getProfiles(); return () => { mounted.current = false; }; @@ -262,7 +263,6 @@ export default function ManageChannelMembers({ {/* fix flashing No Results page when results are present */}