2019-04-04 04:11:47 +08:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2019-02-27 01:08:15 +08:00
|
|
|
import { Session } from 'meteor/session';
|
|
|
|
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 Button from '/imports/ui/components/button/component';
|
|
|
|
import { styles } from './styles';
|
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
2019-02-27 01:08:15 +08:00
|
|
|
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',
|
|
|
|
},
|
2019-04-04 04:11:47 +08:00
|
|
|
rememberChoice: {
|
|
|
|
id: 'app.userList.guest.rememberChoice',
|
|
|
|
description: 'Remember label for checkbox',
|
|
|
|
},
|
2020-01-13 23:45:08 +08:00
|
|
|
accept: {
|
|
|
|
id: 'app.userList.guest.acceptLabel',
|
|
|
|
description: 'Accept guest button label'
|
|
|
|
},
|
|
|
|
deny: {
|
|
|
|
id: 'app.userList.guest.denyLabel',
|
|
|
|
description: 'Deny guest button label',
|
|
|
|
},
|
2019-02-27 01:08:15 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const ALLOW_STATUS = 'ALLOW';
|
|
|
|
const DENY_STATUS = 'DENY';
|
|
|
|
|
2020-01-13 23:45:08 +08:00
|
|
|
const getNameInitials = (name) => {
|
|
|
|
const nameInitials = name.slice(0, 2);
|
|
|
|
|
|
|
|
return nameInitials.replace(/^\w/, c => c.toUpperCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
const renderGuestUserItem = (name, color, handleAccept, handleDeny, role, sequence, userId, intl) => (
|
2019-03-09 10:02:46 +08:00
|
|
|
<div key={`userlist-item-${userId}`} className={styles.listItem}>
|
|
|
|
<div key={`user-content-container-${userId}`} className={styles.userContentContainer}>
|
|
|
|
<div key={`user-avatar-container-${userId}`} className={styles.userAvatar}>
|
2019-02-27 01:08:15 +08:00
|
|
|
<UserAvatar
|
2019-03-09 10:02:46 +08:00
|
|
|
key={`user-avatar-${userId}`}
|
2019-02-27 01:08:15 +08:00
|
|
|
moderator={role === 'MODERATOR'}
|
|
|
|
color={color}
|
|
|
|
>
|
2020-01-13 23:45:08 +08:00
|
|
|
{getNameInitials(name)}
|
2019-02-27 01:08:15 +08:00
|
|
|
</UserAvatar>
|
|
|
|
</div>
|
2019-03-09 10:02:46 +08:00
|
|
|
<p key={`user-name-${userId}`} className={styles.userName}>
|
|
|
|
[
|
|
|
|
{sequence}
|
|
|
|
]
|
|
|
|
{name}
|
|
|
|
</p>
|
2019-02-27 01:08:15 +08:00
|
|
|
</div>
|
|
|
|
|
2019-03-09 10:02:46 +08:00
|
|
|
<div key={`userlist-btns-${userId}`} className={styles.buttonContainer}>
|
2019-02-27 01:08:15 +08:00
|
|
|
<Button
|
2019-03-09 10:02:46 +08:00
|
|
|
key={`userbtn-accept-${userId}`}
|
2019-02-27 01:08:15 +08:00
|
|
|
className={styles.button}
|
|
|
|
color="primary"
|
|
|
|
size="lg"
|
|
|
|
ghost
|
2020-01-13 23:45:08 +08:00
|
|
|
label={intl.formatMessage(intlMessages.accept)}
|
2019-02-27 01:08:15 +08:00
|
|
|
onClick={handleAccept}
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
<Button
|
2019-03-09 10:02:46 +08:00
|
|
|
key={`userbtn-deny-${userId}`}
|
2019-02-27 01:08:15 +08:00
|
|
|
className={styles.button}
|
|
|
|
color="primary"
|
|
|
|
size="lg"
|
|
|
|
ghost
|
2020-01-13 23:45:08 +08:00
|
|
|
label={intl.formatMessage(intlMessages.deny)}
|
2019-02-27 01:08:15 +08:00
|
|
|
onClick={handleDeny}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2020-01-13 23:45:08 +08:00
|
|
|
const renderPendingUsers = (message, usersArray, action, intl) => {
|
2019-02-27 01:08:15 +08:00
|
|
|
if (!usersArray.length) return null;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<p className={styles.mainTitle}>{message}</p>
|
|
|
|
{usersArray.map((user, idx) => renderGuestUserItem(
|
|
|
|
user.name,
|
|
|
|
user.color,
|
|
|
|
() => action([user], ALLOW_STATUS),
|
|
|
|
() => action([user], DENY_STATUS),
|
|
|
|
user.role,
|
|
|
|
idx + 1,
|
2019-03-09 10:02:46 +08:00
|
|
|
user.intId,
|
2020-01-13 23:45:08 +08:00
|
|
|
intl,
|
2019-02-27 01:08:15 +08:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const WaitingUsers = (props) => {
|
2019-04-04 04:21:48 +08:00
|
|
|
const [rememberChoice, setRememberChoice] = useState(false);
|
2019-04-04 04:11:47 +08:00
|
|
|
|
2019-02-27 01:08:15 +08:00
|
|
|
useEffect(() => {
|
|
|
|
const {
|
|
|
|
authenticatedUsers,
|
|
|
|
guestUsers,
|
|
|
|
} = props;
|
|
|
|
if (!authenticatedUsers.length && !guestUsers.length) Session.set('openPanel', 'userlist');
|
|
|
|
});
|
|
|
|
|
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
authenticatedUsers,
|
|
|
|
guestUsers,
|
|
|
|
guestUsersCall,
|
2019-04-04 04:11:47 +08:00
|
|
|
changeGuestPolicy,
|
2019-02-27 01:08:15 +08:00
|
|
|
} = props;
|
|
|
|
|
2019-04-04 04:11:47 +08:00
|
|
|
const onCheckBoxChange = (e) => {
|
|
|
|
const { checked } = e.target;
|
2019-04-04 04:21:48 +08:00
|
|
|
setRememberChoice(checked);
|
2019-04-04 04:11:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const changePolicy = (shouldExecutePolicy, policyRule, cb) => () => {
|
|
|
|
if (shouldExecutePolicy) {
|
|
|
|
changeGuestPolicy(policyRule);
|
|
|
|
}
|
|
|
|
return cb();
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderButton = (message, { key, policy, action }) => (
|
|
|
|
<Button
|
|
|
|
key={key}
|
|
|
|
color="primary"
|
|
|
|
label={message}
|
|
|
|
size="lg"
|
2019-04-04 04:21:48 +08:00
|
|
|
onClick={changePolicy(rememberChoice, policy, action)}
|
2019-04-04 04:11:47 +08:00
|
|
|
className={styles.customBtn}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2019-02-27 01:08:15 +08:00
|
|
|
const buttonsData = [
|
|
|
|
{
|
|
|
|
messageId: intlMessages.allowAllAuthenticated,
|
|
|
|
action: () => guestUsersCall(authenticatedUsers, ALLOW_STATUS),
|
2019-03-09 10:02:46 +08:00
|
|
|
key: 'allow-all-auth',
|
2019-04-04 04:11:47 +08:00
|
|
|
policy: 'ALWAYS_ACCEPT_AUTH',
|
2019-02-27 01:08:15 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
messageId: intlMessages.allowAllGuests,
|
2019-04-04 04:11:47 +08:00
|
|
|
action: () => guestUsersCall(
|
2019-04-04 04:21:48 +08:00
|
|
|
[...guestUsers].concat(rememberChoice ? authenticatedUsers : []),
|
2019-04-04 04:11:47 +08:00
|
|
|
ALLOW_STATUS,
|
|
|
|
),
|
2019-03-09 10:02:46 +08:00
|
|
|
key: 'allow-all-guest',
|
2019-04-04 04:11:47 +08:00
|
|
|
policy: 'ALWAYS_ACCEPT',
|
2019-02-27 01:08:15 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
messageId: intlMessages.allowEveryone,
|
|
|
|
action: () => guestUsersCall([...guestUsers, ...authenticatedUsers], ALLOW_STATUS),
|
2019-03-09 10:02:46 +08:00
|
|
|
key: 'allow-everyone',
|
2019-04-04 04:11:47 +08:00
|
|
|
policy: 'ALWAYS_ACCEPT',
|
2019-02-27 01:08:15 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
messageId: intlMessages.denyEveryone,
|
|
|
|
action: () => guestUsersCall([...guestUsers, ...authenticatedUsers], DENY_STATUS),
|
2019-03-09 10:02:46 +08:00
|
|
|
key: 'deny-everyone',
|
2019-04-04 04:11:47 +08:00
|
|
|
policy: 'ALWAYS_DENY',
|
2019-02-27 01:08:15 +08:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
data-test="note"
|
|
|
|
className={styles.panel}
|
|
|
|
>
|
|
|
|
<header className={styles.header}>
|
|
|
|
<div
|
|
|
|
data-test="noteTitle"
|
|
|
|
className={styles.title}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
Session.set('openPanel', 'userlist');
|
|
|
|
}}
|
|
|
|
label={intl.formatMessage(intlMessages.title)}
|
|
|
|
icon="left_arrow"
|
|
|
|
className={styles.hideBtn}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<main>
|
|
|
|
<div>
|
2019-03-09 10:02:46 +08:00
|
|
|
<p className={styles.mainTitle}>{intl.formatMessage(intlMessages.optionTitle)}</p>
|
2019-02-27 01:08:15 +08:00
|
|
|
{
|
2019-03-09 10:02:46 +08:00
|
|
|
buttonsData.map(buttonData => renderButton(
|
2019-02-27 01:08:15 +08:00
|
|
|
intl.formatMessage(buttonData.messageId),
|
2019-04-04 04:11:47 +08:00
|
|
|
buttonData,
|
2019-02-27 01:08:15 +08:00
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
2019-06-05 23:30:10 +08:00
|
|
|
<div className={styles.rememberContainer}>
|
|
|
|
<input id="rememderCheckboxId" type="checkbox" onChange={onCheckBoxChange} />
|
|
|
|
<label htmlFor="rememderCheckboxId">
|
|
|
|
{intl.formatMessage(intlMessages.rememberChoice)}
|
2019-04-04 04:11:47 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
2019-02-27 01:08:15 +08:00
|
|
|
{renderPendingUsers(
|
|
|
|
intl.formatMessage(intlMessages.pendingUsers,
|
|
|
|
{ 0: authenticatedUsers.length }),
|
|
|
|
authenticatedUsers,
|
|
|
|
guestUsersCall,
|
2020-01-13 23:45:08 +08:00
|
|
|
intl,
|
2019-02-27 01:08:15 +08:00
|
|
|
)}
|
|
|
|
{renderPendingUsers(
|
|
|
|
intl.formatMessage(intlMessages.pendingGuestUsers,
|
|
|
|
{ 0: guestUsers.length }),
|
|
|
|
guestUsers,
|
|
|
|
guestUsersCall,
|
2020-01-13 23:45:08 +08:00
|
|
|
intl,
|
2019-02-27 01:08:15 +08:00
|
|
|
)}
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default injectWbResizeEvent(injectIntl(WaitingUsers));
|