bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/waiting-users/component.jsx

335 lines
9.3 KiB
React
Raw Normal View History

import _ from 'lodash';
import React, { useEffect, useState } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
import UserAvatar from '/imports/ui/components/user-avatar/component';
import TextInput from '/imports/ui/components/text-input/component';
2021-10-30 03:53:33 +08:00
import Styled from './styles';
2021-05-18 04:25:07 +08:00
import { PANELS, ACTIONS } from '../layout/enums';
2021-10-30 03:53:33 +08:00
import Settings from '/imports/ui/services/settings';
import browserInfo from '/imports/utils/browserInfo';
const intlMessages = defineMessages({
waitingUsersTitle: {
id: 'app.userList.guest.waitingUsersTitle',
description: 'Title for the notes list',
},
title: {
id: 'app.userList.guest.waitingUsers',
description: 'Label for the waiting users',
},
2019-03-09 10:02:46 +08:00
optionTitle: {
id: 'app.userList.guest.optionTitle',
description: 'Label above the options',
},
allowAllAuthenticated: {
id: 'app.userList.guest.allowAllAuthenticated',
description: 'Title for the waiting users',
},
allowAllGuests: {
id: 'app.userList.guest.allowAllGuests',
description: 'Title for the waiting users',
},
allowEveryone: {
id: 'app.userList.guest.allowEveryone',
description: 'Title for the waiting users',
},
denyEveryone: {
id: 'app.userList.guest.denyEveryone',
description: 'Title for the waiting users',
},
pendingUsers: {
id: 'app.userList.guest.pendingUsers',
description: 'Title for the waiting users',
},
pendingGuestUsers: {
id: 'app.userList.guest.pendingGuestUsers',
description: 'Title for the waiting users',
},
2021-09-04 19:45:52 +08:00
noPendingUsers: {
id: 'app.userList.guest.noPendingUsers',
description: 'Label for no users waiting',
},
rememberChoice: {
id: 'app.userList.guest.rememberChoice',
description: 'Remember label for checkbox',
},
emptyMessage: {
id: 'app.userList.guest.emptyMessage',
description: 'Empty guest lobby message label',
},
inputPlaceholder: {
id: 'app.userList.guest.inputPlaceholder',
description: 'Placeholder to guest lobby message input',
},
2020-01-13 23:45:08 +08:00
accept: {
id: 'app.userList.guest.acceptLabel',
2021-05-18 04:25:07 +08:00
description: 'Accept guest button label',
2020-01-13 23:45:08 +08:00
},
deny: {
id: 'app.userList.guest.denyLabel',
description: 'Deny guest button label',
},
});
const ALLOW_STATUS = 'ALLOW';
const DENY_STATUS = 'DENY';
2021-10-30 03:53:33 +08:00
const { animations } = Settings.application;
2020-01-13 23:45:08 +08:00
const getNameInitials = (name) => {
const nameInitials = name.slice(0, 2);
2021-05-18 04:25:07 +08:00
return nameInitials.replace(/^\w/, (c) => c.toUpperCase());
};
2020-01-13 23:45:08 +08:00
2021-05-18 04:25:07 +08:00
const renderGuestUserItem = (
name, color, handleAccept, handleDeny, role, sequence, userId, avatar, intl,
) => (
2021-10-30 03:53:33 +08:00
<Styled.ListItem key={`userlist-item-${userId}`} animations={animations}>
<Styled.UserContentContainer key={`user-content-container-${userId}`}>
<Styled.UserAvatarContainer key={`user-avatar-container-${userId}`}>
<UserAvatar
2019-03-09 10:02:46 +08:00
key={`user-avatar-${userId}`}
moderator={role === 'MODERATOR'}
avatar={avatar}
color={color}
>
2020-01-13 23:45:08 +08:00
{getNameInitials(name)}
</UserAvatar>
2021-10-30 03:53:33 +08:00
</Styled.UserAvatarContainer>
<Styled.UserName key={`user-name-${userId}`}>
2021-09-02 00:38:24 +08:00
{`[${sequence}] ${name}`}
2021-10-30 03:53:33 +08:00
</Styled.UserName>
</Styled.UserContentContainer>
2021-10-30 03:53:33 +08:00
<Styled.ButtonContainer key={`userlist-btns-${userId}`}>
<Styled.WaitingUsersButton
2019-03-09 10:02:46 +08:00
key={`userbtn-accept-${userId}`}
color="primary"
size="lg"
ghost
2020-01-13 23:45:08 +08:00
label={intl.formatMessage(intlMessages.accept)}
onClick={handleAccept}
/>
|
2021-10-30 03:53:33 +08:00
<Styled.WaitingUsersButton
2019-03-09 10:02:46 +08:00
key={`userbtn-deny-${userId}`}
color="primary"
size="lg"
ghost
2020-01-13 23:45:08 +08:00
label={intl.formatMessage(intlMessages.deny)}
onClick={handleDeny}
/>
2021-10-30 03:53:33 +08:00
</Styled.ButtonContainer>
</Styled.ListItem>
);
2021-09-04 19:45:52 +08:00
const renderNoUserWaitingItem = (message) => (
2021-10-30 03:53:33 +08:00
<Styled.PendingUsers>
<Styled.NoPendingUsers>
2021-09-04 19:45:52 +08:00
{message}
2021-10-30 03:53:33 +08:00
</Styled.NoPendingUsers>
</Styled.PendingUsers>
2021-09-04 19:45:52 +08:00
);
2020-01-13 23:45:08 +08:00
const renderPendingUsers = (message, usersArray, action, intl) => {
if (!usersArray.length) return null;
return (
2021-10-30 03:53:33 +08:00
<Styled.PendingUsers>
<Styled.MainTitle>{message}</Styled.MainTitle>
<Styled.UsersWrapper>
<Styled.Users>
{usersArray.map((user, idx) => renderGuestUserItem(
user.name,
user.color,
() => action([user], ALLOW_STATUS),
() => action([user], DENY_STATUS),
user.role,
idx + 1,
user.intId,
user.avatar,
intl,
))}
2021-10-30 03:53:33 +08:00
</Styled.Users>
</Styled.UsersWrapper>
</Styled.PendingUsers>
);
};
const WaitingUsers = (props) => {
2019-04-04 04:21:48 +08:00
const [rememberChoice, setRememberChoice] = useState(false);
const {
intl,
authenticatedUsers,
guestUsers,
guestUsersCall,
changeGuestPolicy,
isGuestLobbyMessageEnabled,
setGuestLobbyMessage,
guestLobbyMessage,
authenticatedGuest,
2021-08-05 19:03:24 +08:00
layoutContextDispatch,
allowRememberChoice,
} = props;
2021-09-04 19:45:52 +08:00
const existPendingUsers = authenticatedUsers.length > 0 || guestUsers.length > 0;
const closePanel = () => {
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: false,
});
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
value: PANELS.NONE,
});
};
useEffect(() => {
const {
isWaitingRoomEnabled,
} = props;
if (!isWaitingRoomEnabled && !existPendingUsers) {
closePanel();
}
});
const onCheckBoxChange = (e) => {
const { checked } = e.target;
2019-04-04 04:21:48 +08:00
setRememberChoice(checked);
};
const changePolicy = (shouldExecutePolicy, policyRule, cb) => () => {
if (shouldExecutePolicy) {
changeGuestPolicy(policyRule);
}
2021-09-04 19:45:52 +08:00
closePanel();
return cb();
};
const renderButton = (message, { key, policy, action }) => (
2021-10-30 03:53:33 +08:00
<Styled.CustomButton
key={key}
color="primary"
label={message}
size="lg"
2019-04-04 04:21:48 +08:00
onClick={changePolicy(rememberChoice, policy, action)}
/>
);
const authGuestButtonsData = [
{
messageId: intlMessages.allowAllAuthenticated,
action: () => guestUsersCall(authenticatedUsers, ALLOW_STATUS),
2019-03-09 10:02:46 +08:00
key: 'allow-all-auth',
policy: 'ALWAYS_ACCEPT_AUTH',
},
{
messageId: intlMessages.allowAllGuests,
action: () => guestUsersCall(
2019-04-04 04:21:48 +08:00
[...guestUsers].concat(rememberChoice ? authenticatedUsers : []),
ALLOW_STATUS,
),
2019-03-09 10:02:46 +08:00
key: 'allow-all-guest',
policy: 'ALWAYS_ACCEPT',
},
];
const guestButtonsData = [
{
messageId: intlMessages.allowEveryone,
action: () => guestUsersCall([...guestUsers, ...authenticatedUsers], ALLOW_STATUS),
2019-03-09 10:02:46 +08:00
key: 'allow-everyone',
policy: 'ALWAYS_ACCEPT',
},
{
messageId: intlMessages.denyEveryone,
action: () => guestUsersCall([...guestUsers, ...authenticatedUsers], DENY_STATUS),
2019-03-09 10:02:46 +08:00
key: 'deny-everyone',
policy: 'ALWAYS_DENY',
},
];
2021-08-09 22:24:02 +08:00
const buttonsData = authenticatedGuest
? _.concat(authGuestButtonsData, guestButtonsData)
: guestButtonsData;
2021-10-30 03:53:33 +08:00
const { isChrome } = browserInfo;
return (
2021-10-30 03:53:33 +08:00
<Styled.Panel data-test="note" isChrome={isChrome}>
<Styled.Header>
<Styled.Title data-test="noteTitle">
<Styled.HideButton
2021-09-04 19:45:52 +08:00
onClick={() => closePanel()}
label={intl.formatMessage(intlMessages.title)}
icon="left_arrow"
/>
2021-10-30 03:53:33 +08:00
</Styled.Title>
</Styled.Header>
{isGuestLobbyMessageEnabled ? (
2021-10-30 03:53:33 +08:00
<Styled.LobbyMessage>
<TextInput
maxLength={128}
placeholder={intl.formatMessage(intlMessages.inputPlaceholder)}
send={setGuestLobbyMessage}
/>
2021-05-18 04:25:07 +08:00
<p>
<i>
&quot;
{
guestLobbyMessage.length > 0
? guestLobbyMessage
: intl.formatMessage(intlMessages.emptyMessage)
}
&quot;
</i>
</p>
2021-10-30 03:53:33 +08:00
</Styled.LobbyMessage>
) : null}
2021-09-04 19:45:52 +08:00
{existPendingUsers && (
<div>
<div>
2021-10-30 03:53:33 +08:00
<Styled.MainTitle>{intl.formatMessage(intlMessages.optionTitle)}</Styled.MainTitle>
{
2021-05-18 04:25:07 +08:00
buttonsData.map((buttonData) => renderButton(
intl.formatMessage(buttonData.messageId),
buttonData,
))
}
</div>
{allowRememberChoice ? (
2021-10-30 03:53:33 +08:00
<Styled.RememberContainer>
<input id="rememderCheckboxId" type="checkbox" onChange={onCheckBoxChange} />
<label htmlFor="rememderCheckboxId">
{intl.formatMessage(intlMessages.rememberChoice)}
</label>
2021-10-30 03:53:33 +08:00
</Styled.RememberContainer>
) : null}
</div>
2021-09-04 19:45:52 +08:00
)}
{renderPendingUsers(
intl.formatMessage(intlMessages.pendingUsers,
{ 0: authenticatedUsers.length }),
authenticatedUsers,
guestUsersCall,
intl,
)}
{renderPendingUsers(
intl.formatMessage(intlMessages.pendingGuestUsers,
{ 0: guestUsers.length }),
guestUsers,
guestUsersCall,
intl,
)}
2021-09-04 19:45:52 +08:00
{!existPendingUsers && (
renderNoUserWaitingItem(intl.formatMessage(intlMessages.noPendingUsers))
)}
2021-10-30 03:53:33 +08:00
</Styled.Panel>
);
};
export default injectWbResizeEvent(injectIntl(WaitingUsers));