Skip to content

Commit

Permalink
linagora#1960 Add guests in user list state
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane VIEIRA committed Mar 11, 2022
1 parent c03fb81 commit e9966be
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ChannelGuestsState } from 'app/features/channel-members/state/channel-g
import { useGlobalEffect } from 'app/features/global/hooks/use-global-effect';
import { LoadingState } from 'app/features/global/state/atoms/Loading';
import ChannelMembersAPIClient from '../api/channel-members-api-client';
import UserAPIClient from 'app/features/users/api/user-api-client';
import { useSetUserList } from 'app/features/users/hooks/use-user-list';

export const useChannelGuests = (
key: AtomChannelMembersKey,
Expand All @@ -18,6 +20,7 @@ export const useChannelGuests = (
} => {
const [channelGuests, _setChannelGuests] = useRecoilState(ChannelGuestsState(key));
const [loading, setLoading] = useRecoilState(LoadingState(`channel-guests-${key.channelId}`));
const { set: setUserList } = useSetUserList('useChannelGuests');

const refresh = async () => {
const { companyId, workspaceId, channelId } = key;
Expand All @@ -31,6 +34,11 @@ export const useChannelGuests = (
);

if (channelGuestsUpdated) _setChannelGuests(channelGuestsUpdated);

const usersIdx = channelGuestsUpdated.map(guest => guest.user_id || '');
const users = await UserAPIClient.list(usersIdx, [companyId]);

if (users.length) setUserList(users);
};

useGlobalEffect(
Expand Down

0 comments on commit e9966be

Please sign in to comment.