2020-04-01 07:47:51 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2020-04-01 07:47:51 +00:00
|
|
|
|
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import { Icon, IconInviteMore } from '../../../base/icons';
|
|
|
|
import { getParticipantCount } from '../../../base/participants';
|
|
|
|
import { connect } from '../../../base/redux';
|
|
|
|
import { beginAddPeople } from '../../../invite';
|
2020-07-24 12:14:33 +00:00
|
|
|
import { isButtonEnabled, isToolboxVisible } from '../../../toolbox/functions.web';
|
2020-04-01 07:47:51 +00:00
|
|
|
|
2020-06-16 11:07:37 +00:00
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
2020-04-01 07:47:51 +00:00
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
2021-03-18 12:09:22 +00:00
|
|
|
* Whether to show the option to invite more people.
|
2020-04-01 07:47:51 +00:00
|
|
|
*/
|
2021-03-18 12:09:22 +00:00
|
|
|
_shouldShow: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the toolbox is visible.
|
|
|
|
*/
|
|
|
|
_toolboxVisible: boolean,
|
2020-04-01 07:47:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler to open the invite dialog.
|
|
|
|
*/
|
|
|
|
onClick: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a replacement for the subject, prompting the
|
|
|
|
* sole participant to invite more participants.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The props of the component.
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
|
|
|
function InviteMore({
|
2021-03-18 12:09:22 +00:00
|
|
|
_shouldShow,
|
|
|
|
_toolboxVisible,
|
2020-04-01 07:47:51 +00:00
|
|
|
onClick,
|
|
|
|
t
|
|
|
|
}: Props) {
|
2021-06-10 12:48:44 +00:00
|
|
|
const onKeyPressHandler = useCallback(e => {
|
|
|
|
if (onClick && (e.key === ' ' || e.key === 'Enter')) {
|
|
|
|
e.preventDefault();
|
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
}, [ onClick ]);
|
|
|
|
|
2020-04-01 07:47:51 +00:00
|
|
|
return (
|
2021-03-18 12:09:22 +00:00
|
|
|
_shouldShow
|
|
|
|
? <div className = { `invite-more-container${_toolboxVisible ? '' : ' elevated'}` }>
|
|
|
|
<div className = 'invite-more-content'>
|
2021-06-10 12:48:44 +00:00
|
|
|
<div
|
|
|
|
className = 'invite-more-header'
|
|
|
|
role = 'heading'>
|
2021-03-18 12:09:22 +00:00
|
|
|
{t('addPeople.inviteMoreHeader')}
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className = 'invite-more-button'
|
2021-06-10 12:48:44 +00:00
|
|
|
onClick = { onClick }
|
|
|
|
onKeyPress = { onKeyPressHandler }
|
|
|
|
role = 'button'
|
|
|
|
tabIndex = { 0 }>
|
2021-03-18 12:09:22 +00:00
|
|
|
<Icon src = { IconInviteMore } />
|
|
|
|
<div className = 'invite-more-button-text'>
|
|
|
|
{t('addPeople.inviteMorePrompt')}
|
|
|
|
</div>
|
2020-04-01 07:47:51 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div> : null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated
|
|
|
|
* {@code Subject}'s props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
const participantCount = getParticipantCount(state);
|
2020-06-16 11:07:37 +00:00
|
|
|
const isAlone = participantCount === 1;
|
|
|
|
const hide = interfaceConfig.HIDE_INVITE_MORE_HEADER;
|
2020-04-01 07:47:51 +00:00
|
|
|
|
|
|
|
return {
|
2021-03-18 12:09:22 +00:00
|
|
|
_shouldShow: isButtonEnabled('invite', state) && isAlone && !hide,
|
|
|
|
_toolboxVisible: isToolboxVisible(state)
|
2020-04-01 07:47:51 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps dispatching of some action to React component props.
|
|
|
|
*
|
|
|
|
* @param {Function} dispatch - Redux action dispatcher.
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
onClick: () => beginAddPeople()
|
|
|
|
};
|
|
|
|
|
|
|
|
export default translate(connect(mapStateToProps, mapDispatchToProps)(InviteMore));
|