bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/actions-bar/create-breakout-room/component.jsx

635 lines
18 KiB
React
Raw Normal View History

2018-09-28 22:42:07 +08:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl, intlShape } from 'react-intl';
2018-09-29 02:09:15 +08:00
import _ from 'lodash';
import cx from 'classnames';
import browser from 'browser-detect';
import Button from '/imports/ui/components/button/component';
import { Session } from 'meteor/session';
import Modal from '/imports/ui/components/modal/fullscreen/component';
import { withModalMounter } from '/imports/ui/components/modal/service';
2018-09-29 02:09:15 +08:00
import HoldButton from '/imports/ui/components/presentation/presentation-toolbar/zoom-tool/holdButton/component';
import SortList from './sort-user-list/component';
import styles from './styles';
2018-09-28 22:42:07 +08:00
const intlMessages = defineMessages({
2018-10-24 01:18:09 +08:00
breakoutRoomTitle: {
2018-09-28 22:42:07 +08:00
id: 'app.createBreakoutRoom.title',
description: 'modal title',
},
2018-10-24 01:18:09 +08:00
breakoutRoomDesc: {
2018-09-28 22:42:07 +08:00
id: 'app.createBreakoutRoom.modalDesc',
2018-10-30 03:29:45 +08:00
description: 'modal description',
2018-09-28 22:42:07 +08:00
},
2018-10-24 01:18:09 +08:00
confirmButton: {
id: 'app.createBreakoutRoom.confirm',
2018-10-30 03:29:45 +08:00
description: 'confirm button label',
2018-10-24 01:18:09 +08:00
},
dismissLabel: {
id: 'app.presentationUploder.dismissLabel',
description: 'used in the button that close modal',
},
2018-10-24 01:18:09 +08:00
numberOfRooms: {
id: 'app.createBreakoutRoom.numberOfRooms',
2018-10-30 03:29:45 +08:00
description: 'number of rooms label',
2018-10-24 01:18:09 +08:00
},
duration: {
id: 'app.createBreakoutRoom.durationInMinutes',
2018-10-30 03:29:45 +08:00
description: 'duration time label',
2018-10-24 01:18:09 +08:00
},
randomlyAssign: {
id: 'app.createBreakoutRoom.randomlyAssign',
2018-10-30 03:29:45 +08:00
description: 'randomly assign label',
},
roomName: {
id: 'app.createBreakoutRoom.roomName',
description: 'room intl to name the breakout meetings',
2018-10-24 01:18:09 +08:00
},
freeJoinLabel: {
id: 'app.createBreakoutRoom.freeJoin',
description: 'free join label',
},
roomLabel: {
id: 'app.createBreakoutRoom.room',
description: 'Room label',
},
leastOneWarnBreakout: {
id: 'app.createBreakoutRoom.leastOneWarnBreakout',
description: 'warn message label',
},
notAssigned: {
id: 'app.createBreakoutRoom.notAssigned',
description: 'Not assigned label',
},
breakoutRoomLabel: {
id: 'app.createBreakoutRoom.breakoutRoomLabel',
description: 'breakout room label',
},
addParticipantLabel: {
id: 'app.createBreakoutRoom.addParticipantLabel',
description: 'add Participant label',
},
nextLabel: {
id: 'app.createBreakoutRoom.nextLabel',
description: 'Next label',
},
backLabel: {
id: 'app.audio.backLabel',
description: 'Back label',
},
2018-12-28 00:20:03 +08:00
invitationTitle: {
id: 'app.invitation.title',
2018-12-28 19:51:41 +08:00
description: 'isInvitationto breakout title',
2018-12-28 00:20:03 +08:00
},
invitationConfirm: {
id: 'app.invitation.confirm',
2019-01-17 01:41:21 +08:00
description: 'Invitation to breakout confirm button label',
2018-12-28 00:20:03 +08:00
},
minusRoomTime: {
id: 'app.createBreakoutRoom.minusRoomTime',
description: 'aria label for btn to decrease room time',
},
addRoomTime: {
id: 'app.createBreakoutRoom.addRoomTime',
description: 'aria label for btn to increase room time',
},
2018-09-28 22:42:07 +08:00
});
const MIN_BREAKOUT_ROOMS = 2;
const MAX_BREAKOUT_ROOMS = 8;
2018-09-28 22:42:07 +08:00
const propTypes = {
intl: intlShape.isRequired,
isInvitation: PropTypes.bool.isRequired,
meetingName: PropTypes.string.isRequired,
users: PropTypes.arrayOf(PropTypes.object).isRequired,
createBreakoutRoom: PropTypes.func.isRequired,
getUsersNotAssigned: PropTypes.func.isRequired,
getBreakouts: PropTypes.func.isRequired,
sendInvitation: PropTypes.func.isRequired,
mountModal: PropTypes.func.isRequired,
};
2018-09-28 22:42:07 +08:00
class BreakoutRoom extends Component {
constructor(props) {
super(props);
2018-10-24 01:18:09 +08:00
this.changeNumberOfRooms = this.changeNumberOfRooms.bind(this);
2018-09-28 22:42:07 +08:00
this.changeDurationTime = this.changeDurationTime.bind(this);
this.changeUserRoom = this.changeUserRoom.bind(this);
2018-09-28 22:42:07 +08:00
this.increaseDurationTime = this.increaseDurationTime.bind(this);
this.decreaseDurationTime = this.decreaseDurationTime.bind(this);
2018-10-24 01:18:09 +08:00
this.onCreateBreakouts = this.onCreateBreakouts.bind(this);
this.setRoomUsers = this.setRoomUsers.bind(this);
this.setFreeJoin = this.setFreeJoin.bind(this);
this.getUserByRoom = this.getUserByRoom.bind(this);
2018-12-17 21:48:42 +08:00
this.onAssignRandomly = this.onAssignRandomly.bind(this);
2018-12-28 00:20:03 +08:00
this.onInviteBreakout = this.onInviteBreakout.bind(this);
this.renderUserItemByRoom = this.renderUserItemByRoom.bind(this);
this.renderRoomsGrid = this.renderRoomsGrid.bind(this);
this.renderBreakoutForm = this.renderBreakoutForm.bind(this);
this.renderFreeJoinCheck = this.renderFreeJoinCheck.bind(this);
this.renderRoomSortList = this.renderRoomSortList.bind(this);
this.renderDesktop = this.renderDesktop.bind(this);
this.renderMobile = this.renderMobile.bind(this);
this.renderButtonSetLevel = this.renderButtonSetLevel.bind(this);
this.renderSelectUserScreen = this.renderSelectUserScreen.bind(this);
2018-12-28 00:20:03 +08:00
this.renderTitle = this.renderTitle.bind(this);
this.handleDismiss = this.handleDismiss.bind(this);
2018-12-28 00:20:03 +08:00
this.setInvitationConfig = this.setInvitationConfig.bind(this);
this.blurDurationTime = this.blurDurationTime.bind(this);
2018-11-28 02:00:15 +08:00
2018-09-28 22:42:07 +08:00
this.state = {
numberOfRooms: MIN_BREAKOUT_ROOMS,
2018-11-28 02:00:15 +08:00
seletedId: '',
users: [],
durationTime: 15,
freeJoin: false,
formFillLevel: 1,
roomSelected: 0,
preventClosing: true,
valid: true,
2018-09-28 22:42:07 +08:00
};
this.breakoutFormId = _.uniqueId('breakout-form-');
this.freeJoinId = _.uniqueId('free-join-check-');
this.btnLevelId = _.uniqueId('btn-set-level-');
2018-09-28 22:42:07 +08:00
}
componentDidMount() {
2018-12-28 19:51:41 +08:00
const { isInvitation } = this.props;
this.setRoomUsers();
2018-12-28 19:51:41 +08:00
if (isInvitation) {
2018-12-28 00:20:03 +08:00
this.setInvitationConfig();
}
}
componentDidUpdate(prevProps, prevstate) {
const { numberOfRooms } = this.state;
if (numberOfRooms < prevstate.numberOfRooms) {
this.resetUserWhenRoomsChange(numberOfRooms);
}
}
2018-10-24 01:18:09 +08:00
onCreateBreakouts() {
const {
createBreakoutRoom,
2018-10-30 03:29:45 +08:00
meetingName,
intl,
2018-10-24 01:18:09 +08:00
} = this.props;
2018-12-20 01:08:01 +08:00
const {
users,
freeJoin,
} = this.state;
2018-10-24 01:18:09 +08:00
if (users.length === this.getUserByRoom(0).length && !freeJoin) {
this.setState({ valid: false });
return;
}
this.setState({ preventClosing: false });
2018-10-24 01:18:09 +08:00
const { numberOfRooms, durationTime } = this.state;
2018-10-30 03:29:45 +08:00
const rooms = _.range(1, numberOfRooms + 1).map(value => ({
users: this.getUserByRoom(value).map(u => u.userId),
2018-10-30 03:29:45 +08:00
name: intl.formatMessage(intlMessages.roomName, {
0: meetingName,
1: value,
}),
2018-12-20 01:08:01 +08:00
freeJoin,
2018-10-30 03:29:45 +08:00
sequence: value,
}));
2018-10-24 01:18:09 +08:00
2018-12-20 01:08:01 +08:00
createBreakoutRoom(rooms, durationTime, freeJoin);
Session.set('isUserListOpen', true);
2018-10-24 01:18:09 +08:00
}
2018-12-28 00:20:03 +08:00
onInviteBreakout() {
2018-12-28 19:51:41 +08:00
const { getBreakouts, sendInvitation } = this.props;
2018-12-28 00:20:03 +08:00
const { users } = this.state;
const breakouts = getBreakouts();
if (users.length === this.getUserByRoom(0).length) {
this.setState({ valid: false });
return;
}
2019-01-17 01:41:21 +08:00
breakouts.forEach((breakout) => {
const { breakoutId } = breakout;
const breakoutUsers = this.getUserByRoom(breakout.sequence);
breakoutUsers.forEach(user => sendInvitation(breakoutId, user.userId));
});
2018-12-28 00:20:03 +08:00
this.setState({ preventClosing: false });
}
2018-12-17 21:48:42 +08:00
onAssignRandomly() {
const { numberOfRooms } = this.state;
return this.getUserByRoom(0)
.filter(user => !user.isModerator)
.forEach(user => this.changeUserRoom(
user.userId,
Math.floor(Math.random() * (numberOfRooms) + 1),
));
2018-12-17 21:48:42 +08:00
}
2018-12-28 00:20:03 +08:00
setInvitationConfig() {
const { getBreakouts } = this.props;
this.setState({
numberOfRooms: getBreakouts().length,
formFillLevel: 2,
});
}
setRoomUsers() {
2018-12-28 00:20:03 +08:00
const { users, getUsersNotAssigned } = this.props;
2018-12-28 00:20:03 +08:00
const roomUsers = getUsersNotAssigned(users).map(user => ({
userId: user.userId,
userName: user.name,
isModerator: user.moderator,
room: 0,
}));
this.setState({
users: roomUsers,
});
}
2018-11-22 00:29:20 +08:00
setFreeJoin(e) {
this.setState({ freeJoin: e.target.checked });
2018-09-28 22:42:07 +08:00
}
getUserByRoom(room) {
2018-12-20 01:08:01 +08:00
const { users } = this.state;
return users.filter(user => user.room === room);
}
handleDismiss() {
const { mountModal } = this.props;
return new Promise((resolve) => {
mountModal(null);
this.setState({
preventClosing: false,
}, resolve);
});
}
resetUserWhenRoomsChange(rooms) {
const { users } = this.state;
const filtredUsers = users.filter(u => u.room > rooms);
filtredUsers.forEach(u => this.changeUserRoom(u.userId, 0));
}
changeUserRoom(userId, room) {
const { users } = this.state;
2018-12-28 00:20:03 +08:00
const idxUser = users.findIndex(user => user.userId === userId);
users[idxUser].room = room;
this.setState({ users });
}
2018-09-28 22:42:07 +08:00
increaseDurationTime() {
2018-12-20 01:08:01 +08:00
const { durationTime } = this.state;
this.setState({ durationTime: (1 * durationTime) + 1 });
2018-09-28 22:42:07 +08:00
}
decreaseDurationTime() {
2018-12-20 01:08:01 +08:00
const { durationTime } = this.state;
const number = ((1 * durationTime) - 1);
2018-10-02 21:48:12 +08:00
this.setState({ durationTime: number < 1 ? 1 : number });
2018-09-28 22:42:07 +08:00
}
2018-11-22 00:29:20 +08:00
changeDurationTime(event) {
this.setState({ durationTime: Number.parseInt(event.target.value, 10) || '' });
}
blurDurationTime(event) {
const value = Number.parseInt(event.target.value, 10);
this.setState({ durationTime: !(value <= 0) ? value : 1 });
}
2018-11-22 00:29:20 +08:00
changeNumberOfRooms(event) {
this.setState({ numberOfRooms: Number.parseInt(event.target.value, 10) });
}
renderRoomsGrid() {
const { intl } = this.props;
2018-12-20 01:08:01 +08:00
const {
valid,
numberOfRooms,
} = this.state;
const allowDrop = (ev) => {
ev.preventDefault();
};
const drop = room => (ev) => {
ev.preventDefault();
const data = ev.dataTransfer.getData('text');
this.changeUserRoom(data, room);
2018-11-28 02:00:15 +08:00
this.setState({ seletedId: '' });
};
return (
<div className={styles.boxContainer} key="rooms-grid-">
<div className={!valid ? styles.changeToWarn : null}>
<p className={styles.freeJoinLabel}>
2018-11-28 02:00:15 +08:00
{intl.formatMessage(intlMessages.notAssigned, { 0: this.getUserByRoom(0).length })}
</p>
2018-12-20 01:08:01 +08:00
<div className={styles.breakoutBox} onDrop={drop(0)} onDragOver={allowDrop}>
{this.renderUserItemByRoom(0)}
</div>
2018-12-20 01:08:01 +08:00
<span className={valid ? styles.dontShow : styles.leastOneWarn}>
{intl.formatMessage(intlMessages.leastOneWarnBreakout)}
</span>
</div>
{
2018-12-20 01:08:01 +08:00
_.range(1, numberOfRooms + 1).map(value => (
<div key={`room-${value}`}>
<p className={styles.freeJoinLabel}>
2018-12-20 01:08:01 +08:00
{intl.formatMessage(intlMessages.roomLabel, { 0: (value) })}
</p>
<div className={styles.breakoutBox} onDrop={drop(value)} onDragOver={allowDrop}>
{this.renderUserItemByRoom(value)}
</div>
</div>
2018-12-20 01:08:01 +08:00
))
}
</div>
);
}
renderBreakoutForm() {
2018-12-28 00:20:03 +08:00
const {
intl,
2018-12-28 19:51:41 +08:00
isInvitation,
2018-12-28 00:20:03 +08:00
} = this.props;
2018-12-20 01:08:01 +08:00
const {
numberOfRooms,
durationTime,
} = this.state;
2018-12-28 19:51:41 +08:00
if (isInvitation) return null;
2018-12-28 00:20:03 +08:00
return (
<div className={styles.breakoutSettings} key={this.breakoutFormId}>
<div>
<p className={styles.labelText} aria-hidden>
{intl.formatMessage(intlMessages.numberOfRooms)}
</p>
<select
2018-12-20 01:08:01 +08:00
id="numberOfRooms"
name="numberOfRooms"
className={styles.inputRooms}
2018-12-20 01:08:01 +08:00
value={numberOfRooms}
onChange={this.changeNumberOfRooms}
aria-label={intl.formatMessage(intlMessages.numberOfRooms)}
>
{
_.range(MIN_BREAKOUT_ROOMS, MAX_BREAKOUT_ROOMS + 1).map(item => (<option key={_.uniqueId('value-')}>{item}</option>))
}
</select>
</div>
2018-12-20 01:08:01 +08:00
<label htmlFor="breakoutRoomTime">
<p className={styles.labelText} aria-hidden>
{intl.formatMessage(intlMessages.duration)}
</p>
<div className={styles.durationArea}>
<input
type="number"
className={styles.duration}
min="1"
2018-12-20 01:08:01 +08:00
value={durationTime}
onChange={this.changeDurationTime}
onBlur={this.blurDurationTime}
aria-label={intl.formatMessage(intlMessages.duration)}
/>
<HoldButton
key="decrease-breakout-time"
exec={this.decreaseDurationTime}
minBound={MIN_BREAKOUT_ROOMS}
value={durationTime}
className={styles.btnStyle}
>
<Button
label={intl.formatMessage(intlMessages.minusRoomTime)}
icon="substract"
onClick={() => {}}
hideLabel
circle
size="sm"
/>
</HoldButton>
<HoldButton
key="increase-breakout-time"
exec={this.increaseDurationTime}
className={styles.btnStyle}
>
<Button
label={intl.formatMessage(intlMessages.addRoomTime)}
icon="add"
onClick={() => {}}
hideLabel
circle
size="sm"
/>
</HoldButton>
</div>
</label>
<Button
label={intl.formatMessage(intlMessages.randomlyAssign)}
className={styles.randomlyAssignBtn}
2018-12-28 00:20:03 +08:00
onClick={this.onAssignRandomly}
size="sm"
color="default"
/>
</div>
);
}
renderSelectUserScreen() {
2018-12-20 01:08:01 +08:00
const {
users,
roomSelected,
} = this.state;
return (
<SortList
confirm={() => this.setState({ formFillLevel: 2 })}
2018-12-20 01:08:01 +08:00
users={users}
room={roomSelected}
onCheck={this.changeUserRoom}
onUncheck={userId => this.changeUserRoom(userId, 0)}
/>
);
}
renderFreeJoinCheck() {
2018-12-28 19:51:41 +08:00
const { intl, isInvitation } = this.props;
if (isInvitation) return null;
2018-12-20 01:08:01 +08:00
const { freeJoin } = this.state;
return (
<label htmlFor="freeJoinCheckbox" className={styles.freeJoinLabel} key={this.freeJoinId}>
<input
type="checkbox"
className={styles.freeJoinCheckbox}
onChange={this.setFreeJoin}
2018-12-20 01:08:01 +08:00
checked={freeJoin}
aria-label={intl.formatMessage(intlMessages.freeJoinLabel)}
/>
<span aria-hidden>{intl.formatMessage(intlMessages.freeJoinLabel)}</span>
</label>
);
}
renderUserItemByRoom(room) {
2018-12-20 01:08:01 +08:00
const {
valid,
seletedId,
} = this.state;
2018-11-28 02:00:15 +08:00
const dragStart = (ev) => {
ev.dataTransfer.setData('text', ev.target.id);
2018-11-28 02:00:15 +08:00
this.setState({ seletedId: ev.target.id });
2018-12-20 01:08:01 +08:00
if (!valid) {
this.setState({ valid: true });
}
2018-11-28 02:00:15 +08:00
};
const dragEnd = () => {
2018-11-28 02:00:15 +08:00
this.setState({ seletedId: '' });
};
return this.getUserByRoom(room)
.map(user => (
<p
id={user.userId}
key={user.userId}
2018-11-28 02:00:15 +08:00
className={cx(
styles.roomUserItem,
2018-12-20 01:08:01 +08:00
seletedId === user.userId ? styles.selectedItem : null,
)
2018-11-28 02:00:15 +08:00
}
draggable
2018-11-28 02:00:15 +08:00
onDragStart={dragStart}
onDragEnd={dragEnd}
>
{user.userName}
</p>));
}
renderRoomSortList() {
2018-12-28 19:51:41 +08:00
const { intl, isInvitation } = this.props;
const { numberOfRooms } = this.state;
const onClick = roomNumber => this.setState({ formFillLevel: 3, roomSelected: roomNumber });
return (
<div className={styles.listContainer}>
<span>
{
new Array(numberOfRooms).fill(1).map((room, idx) => (
<div className={styles.roomItem}>
<h2 className={styles.itemTitle}>
{intl.formatMessage(intlMessages.breakoutRoomLabel, { 0: idx + 1 })}
</h2>
<Button
className={styles.itemButton}
label={intl.formatMessage(intlMessages.addParticipantLabel)}
size="lg"
ghost
color="primary"
onClick={() => onClick(idx + 1)}
/>
</div>
))
}
</span>
2018-12-28 19:51:41 +08:00
{ isInvitation || this.renderButtonSetLevel(1, intl.formatMessage(intlMessages.backLabel))}
</div>
);
}
renderDesktop() {
return [
this.renderBreakoutForm(),
2018-12-17 21:48:42 +08:00
this.renderFreeJoinCheck(),
this.renderRoomsGrid(),
];
}
renderMobile() {
const { intl } = this.props;
const { formFillLevel } = this.state;
if (formFillLevel === 2) {
return this.renderRoomSortList();
}
if (formFillLevel === 3) {
return this.renderSelectUserScreen();
}
return [
this.renderBreakoutForm(),
2018-12-17 21:48:42 +08:00
this.renderFreeJoinCheck(),
this.renderButtonSetLevel(2, intl.formatMessage(intlMessages.nextLabel)),
];
}
renderButtonSetLevel(level, label) {
return (
<Button
color="primary"
size="lg"
label={label}
onClick={() => this.setState({ formFillLevel: level })}
key={this.btnLevelId}
/>
);
}
2018-12-28 00:20:03 +08:00
renderTitle() {
2018-09-28 22:42:07 +08:00
const { intl } = this.props;
2018-12-28 00:20:03 +08:00
return (
<p className={styles.subTitle}>
{intl.formatMessage(intlMessages.breakoutRoomDesc)}
</p>
);
}
render() {
2018-12-28 19:51:41 +08:00
const { intl, isInvitation } = this.props;
2018-12-20 01:08:01 +08:00
const { preventClosing } = this.state;
const BROWSER_RESULTS = browser();
2018-12-20 01:08:01 +08:00
const isMobileBrowser = BROWSER_RESULTS.mobile || BROWSER_RESULTS.os.includes('Android');
2018-09-28 22:42:07 +08:00
return (
<Modal
2018-12-28 00:20:03 +08:00
title={
2018-12-28 19:51:41 +08:00
isInvitation
2018-12-28 00:20:03 +08:00
? intl.formatMessage(intlMessages.invitationTitle)
: intl.formatMessage(intlMessages.breakoutRoomTitle)
}
2018-10-24 01:18:09 +08:00
confirm={
{
2018-12-28 19:51:41 +08:00
label: isInvitation
2018-12-28 00:20:03 +08:00
? intl.formatMessage(intlMessages.invitationConfirm)
: intl.formatMessage(intlMessages.confirmButton),
2018-12-28 19:51:41 +08:00
callback: isInvitation ? this.onInviteBreakout : this.onCreateBreakouts,
2018-10-24 01:18:09 +08:00
}
}
dismiss={{
callback: this.handleDismiss,
label: intl.formatMessage(intlMessages.dismissLabel),
}}
2018-12-20 01:08:01 +08:00
preventClosing={preventClosing}
2018-09-28 22:42:07 +08:00
>
<div className={styles.content}>
2018-12-28 19:51:41 +08:00
{isInvitation || this.renderTitle()}
2018-12-20 01:08:01 +08:00
{isMobileBrowser ? this.renderMobile() : this.renderDesktop()}
2018-09-28 22:42:07 +08:00
</div>
2018-12-17 21:48:42 +08:00
</Modal>
2018-09-28 22:42:07 +08:00
);
}
}
BreakoutRoom.propTypes = propTypes;
export default withModalMounter(injectIntl(BreakoutRoom));