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.

OverflowMenuProfileItem.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Avatar } from '../../../base/avatar';
  4. import { getLocalParticipant } from '../../../base/participants';
  5. import { connect } from '../../../base/redux';
  6. declare var interfaceConfig: Object;
  7. /**
  8. * The type of the React {@code Component} props of
  9. * {@link OverflowMenuProfileItem}.
  10. */
  11. type Props = {
  12. /**
  13. * The redux representation of the local participant.
  14. */
  15. _localParticipant: Object,
  16. /**
  17. * Whether the button support clicking or not.
  18. */
  19. _unclickable: boolean,
  20. /**
  21. * The callback to invoke when {@code OverflowMenuProfileItem} is
  22. * clicked.
  23. */
  24. onClick: Function
  25. };
  26. /**
  27. * A React {@code Component} for displaying a link with a profile avatar as an
  28. * icon.
  29. *
  30. * @extends Component
  31. */
  32. class OverflowMenuProfileItem extends Component<Props> {
  33. /**
  34. * Initializes a new {@code OverflowMenuProfileItem} instance.
  35. *
  36. * @param {Object} props - The read-only properties with which the new
  37. * instance is to be initialized.
  38. */
  39. constructor(props: Props) {
  40. super(props);
  41. // Bind event handler so it is only bound once for every instance.
  42. this._onClick = this._onClick.bind(this);
  43. }
  44. /**
  45. * Implements React's {@link Component#render()}.
  46. *
  47. * @inheritdoc
  48. * @returns {ReactElement}
  49. */
  50. render() {
  51. const { _localParticipant, _unclickable } = this.props;
  52. const classNames = `overflow-menu-item ${
  53. _unclickable ? 'unclickable' : ''}`;
  54. let displayName;
  55. if (_localParticipant && _localParticipant.name) {
  56. displayName = _localParticipant.name;
  57. } else {
  58. displayName = interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME;
  59. }
  60. return (
  61. <li
  62. aria-label = 'Edit your profile'
  63. className = { classNames }
  64. onClick = { this._onClick }>
  65. <span className = 'overflow-menu-item-icon'>
  66. <Avatar
  67. participantId = { _localParticipant.id }
  68. size = { 24 } />
  69. </span>
  70. <span className = 'profile-text'>
  71. { displayName }
  72. </span>
  73. </li>
  74. );
  75. }
  76. _onClick: () => void;
  77. /**
  78. * Invokes an on click callback if clicking is allowed.
  79. *
  80. * @returns {void}
  81. */
  82. _onClick() {
  83. if (!this.props._unclickable) {
  84. this.props.onClick();
  85. }
  86. }
  87. }
  88. /**
  89. * Maps (parts of) the Redux state to the associated
  90. * {@code OverflowMenuProfileItem} component's props.
  91. *
  92. * @param {Object} state - The Redux state.
  93. * @private
  94. * @returns {{
  95. * _localParticipant: Object,
  96. * _unclickable: boolean
  97. * }}
  98. */
  99. function _mapStateToProps(state) {
  100. return {
  101. _localParticipant: getLocalParticipant(state),
  102. _unclickable: !state['features/base/jwt'].isGuest
  103. || !interfaceConfig.SETTINGS_SECTIONS.includes('profile')
  104. };
  105. }
  106. export default connect(_mapStateToProps)(OverflowMenuProfileItem);