You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InviteMore.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // @flow
  2. import React, { useCallback } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { Icon, IconInviteMore } from '../../../base/icons';
  5. import { getParticipantCount } from '../../../base/participants';
  6. import { connect } from '../../../base/redux';
  7. import { beginAddPeople } from '../../../invite';
  8. import { isButtonEnabled, isToolboxVisible } from '../../../toolbox/functions.web';
  9. declare var interfaceConfig: Object;
  10. type Props = {
  11. /**
  12. * Whether to show the option to invite more people.
  13. */
  14. _shouldShow: boolean,
  15. /**
  16. * Whether the toolbox is visible.
  17. */
  18. _toolboxVisible: boolean,
  19. /**
  20. * Handler to open the invite dialog.
  21. */
  22. onClick: Function,
  23. /**
  24. * Invoked to obtain translated strings.
  25. */
  26. t: Function
  27. }
  28. /**
  29. * Represents a replacement for the subject, prompting the
  30. * sole participant to invite more participants.
  31. *
  32. * @param {Object} props - The props of the component.
  33. * @returns {React$Element<any>}
  34. */
  35. function InviteMore({
  36. _shouldShow,
  37. _toolboxVisible,
  38. onClick,
  39. t
  40. }: Props) {
  41. const onKeyPressHandler = useCallback(e => {
  42. if (onClick && (e.key === ' ' || e.key === 'Enter')) {
  43. e.preventDefault();
  44. onClick();
  45. }
  46. }, [ onClick ]);
  47. return (
  48. _shouldShow
  49. ? <div className = { `invite-more-container${_toolboxVisible ? '' : ' elevated'}` }>
  50. <div className = 'invite-more-content'>
  51. <div
  52. className = 'invite-more-header'
  53. role = 'heading'>
  54. {t('addPeople.inviteMoreHeader')}
  55. </div>
  56. <div
  57. className = 'invite-more-button'
  58. onClick = { onClick }
  59. onKeyPress = { onKeyPressHandler }
  60. role = 'button'
  61. tabIndex = { 0 }>
  62. <Icon src = { IconInviteMore } />
  63. <div className = 'invite-more-button-text'>
  64. {t('addPeople.inviteMorePrompt')}
  65. </div>
  66. </div>
  67. </div>
  68. </div> : null
  69. );
  70. }
  71. /**
  72. * Maps (parts of) the Redux state to the associated
  73. * {@code Subject}'s props.
  74. *
  75. * @param {Object} state - The Redux state.
  76. * @private
  77. * @returns {Props}
  78. */
  79. function mapStateToProps(state) {
  80. const participantCount = getParticipantCount(state);
  81. const isAlone = participantCount === 1;
  82. const hide = interfaceConfig.HIDE_INVITE_MORE_HEADER;
  83. return {
  84. _shouldShow: isButtonEnabled('invite', state) && isAlone && !hide,
  85. _toolboxVisible: isToolboxVisible(state)
  86. };
  87. }
  88. /**
  89. * Maps dispatching of some action to React component props.
  90. *
  91. * @param {Function} dispatch - Redux action dispatcher.
  92. * @returns {Props}
  93. */
  94. const mapDispatchToProps = {
  95. onClick: () => beginAddPeople()
  96. };
  97. export default translate(connect(mapStateToProps, mapDispatchToProps)(InviteMore));