Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import { Theme } from '@mui/material';
  2. import React from 'react';
  3. import { WithTranslation } from 'react-i18next';
  4. import { connect } from 'react-redux';
  5. import { withStyles } from 'tss-react/mui';
  6. import { createProfilePanelButtonEvent } from '../../../analytics/AnalyticsEvents';
  7. import { sendAnalytics } from '../../../analytics/functions';
  8. import { IStore } from '../../../app/types';
  9. import { login, logout } from '../../../authentication/actions.web';
  10. import Avatar from '../../../base/avatar/components/Avatar';
  11. import AbstractDialogTab, {
  12. IProps as AbstractDialogTabProps } from '../../../base/dialog/components/web/AbstractDialogTab';
  13. import { translate } from '../../../base/i18n/functions';
  14. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  15. import Button from '../../../base/ui/components/web/Button';
  16. import Input from '../../../base/ui/components/web/Input';
  17. /**
  18. * The type of the React {@code Component} props of {@link ProfileTab}.
  19. */
  20. export interface IProps extends AbstractDialogTabProps, WithTranslation {
  21. /**
  22. * Whether server-side authentication is available.
  23. */
  24. authEnabled: boolean;
  25. /**
  26. * The name of the currently (server-side) authenticated user.
  27. */
  28. authLogin: string;
  29. /**
  30. * CSS classes object.
  31. */
  32. classes?: Partial<Record<keyof ReturnType<typeof styles>, string>>;
  33. /**
  34. * Invoked to change the configured calendar integration.
  35. */
  36. dispatch: IStore['dispatch'];
  37. /**
  38. * The display name to display for the local participant.
  39. */
  40. displayName: string;
  41. /**
  42. * The email to display for the local participant.
  43. */
  44. email: string;
  45. /**
  46. * Whether to hide the email input in the profile settings.
  47. */
  48. hideEmailInSettings?: boolean;
  49. /**
  50. * The id of the local participant.
  51. */
  52. id: string;
  53. /**
  54. * If the display name is read only.
  55. */
  56. readOnlyName: boolean;
  57. }
  58. const styles = (theme: Theme) => {
  59. return {
  60. container: {
  61. display: 'flex',
  62. flexDirection: 'column' as const,
  63. width: '100%',
  64. padding: '0 2px'
  65. },
  66. avatarContainer: {
  67. display: 'flex',
  68. width: '100%',
  69. justifyContent: 'center',
  70. marginBottom: theme.spacing(4)
  71. },
  72. bottomMargin: {
  73. marginBottom: theme.spacing(4)
  74. },
  75. label: {
  76. color: `${theme.palette.text01} !important`,
  77. ...withPixelLineHeight(theme.typography.bodyShortRegular),
  78. marginBottom: theme.spacing(2)
  79. },
  80. name: {
  81. marginBottom: theme.spacing(1)
  82. }
  83. };
  84. };
  85. /**
  86. * React {@code Component} for modifying the local user's profile.
  87. *
  88. * @augments Component
  89. */
  90. class ProfileTab extends AbstractDialogTab<IProps, any> {
  91. static defaultProps = {
  92. displayName: '',
  93. email: ''
  94. };
  95. /**
  96. * Initializes a new {@code ConnectedSettingsDialog} instance.
  97. *
  98. * @param {IProps} props - The React {@code Component} props to initialize
  99. * the new {@code ConnectedSettingsDialog} instance with.
  100. */
  101. constructor(props: IProps) {
  102. super(props);
  103. // Bind event handlers so they are only bound once for every instance.
  104. this._onAuthToggle = this._onAuthToggle.bind(this);
  105. this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
  106. this._onEmailChange = this._onEmailChange.bind(this);
  107. }
  108. /**
  109. * Changes display name of the user.
  110. *
  111. * @param {string} value - The key event to handle.
  112. *
  113. * @returns {void}
  114. */
  115. _onDisplayNameChange(value: string) {
  116. super._onChange({ displayName: value });
  117. }
  118. /**
  119. * Changes email of the user.
  120. *
  121. * @param {string} value - The key event to handle.
  122. *
  123. * @returns {void}
  124. */
  125. _onEmailChange(value: string) {
  126. super._onChange({ email: value });
  127. }
  128. /**
  129. * Implements React's {@link Component#render()}.
  130. *
  131. * @inheritdoc
  132. * @returns {ReactElement}
  133. */
  134. render() {
  135. const {
  136. authEnabled,
  137. displayName,
  138. email,
  139. hideEmailInSettings,
  140. id,
  141. readOnlyName,
  142. t
  143. } = this.props;
  144. const classes = withStyles.getClasses(this.props);
  145. return (
  146. <div className = { classes.container } >
  147. <div className = { classes.avatarContainer }>
  148. <Avatar
  149. participantId = { id }
  150. size = { 60 } />
  151. </div>
  152. <Input
  153. className = { classes.bottomMargin }
  154. disabled = { readOnlyName }
  155. id = 'setDisplayName'
  156. label = { t('profile.setDisplayNameLabel') }
  157. name = 'name'
  158. onChange = { this._onDisplayNameChange }
  159. placeholder = { t('settings.name') }
  160. type = 'text'
  161. value = { displayName } />
  162. {!hideEmailInSettings && <div className = 'profile-edit-field'>
  163. <Input
  164. className = { classes.bottomMargin }
  165. id = 'setEmail'
  166. label = { t('profile.setEmailLabel') }
  167. name = 'email'
  168. onChange = { this._onEmailChange }
  169. placeholder = { t('profile.setEmailInput') }
  170. type = 'text'
  171. value = { email } />
  172. </div>}
  173. { authEnabled && this._renderAuth() }
  174. </div>
  175. );
  176. }
  177. /**
  178. * Shows the dialog for logging in or out of a server and closes this
  179. * dialog.
  180. *
  181. * @private
  182. * @returns {void}
  183. */
  184. _onAuthToggle() {
  185. if (this.props.authLogin) {
  186. sendAnalytics(createProfilePanelButtonEvent('logout.button'));
  187. this.props.dispatch(logout());
  188. } else {
  189. sendAnalytics(createProfilePanelButtonEvent('login.button'));
  190. this.props.dispatch(login());
  191. }
  192. }
  193. /**
  194. * Returns a React Element for interacting with server-side authentication.
  195. *
  196. * @private
  197. * @returns {ReactElement}
  198. */
  199. _renderAuth() {
  200. const {
  201. authLogin,
  202. t
  203. } = this.props;
  204. const classes = withStyles.getClasses(this.props);
  205. return (
  206. <div>
  207. <h2 className = { classes.label }>
  208. { t('toolbar.authenticate') }
  209. </h2>
  210. { authLogin
  211. && <div className = { classes.name }>
  212. { t('settings.loggedIn', { name: authLogin }) }
  213. </div> }
  214. <Button
  215. accessibilityLabel = { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  216. id = 'login_button'
  217. label = { authLogin ? t('toolbar.logout') : t('toolbar.login') }
  218. onClick = { this._onAuthToggle } />
  219. </div>
  220. );
  221. }
  222. }
  223. export default withStyles(translate(connect()(ProfileTab)), styles);