2022-08-01 07:04:36 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2018-06-20 20:19:53 +00:00
|
|
|
import React from 'react';
|
2022-08-08 09:36:06 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2018-06-20 20:19:53 +00:00
|
|
|
|
2022-10-19 08:42:54 +00:00
|
|
|
// @ts-expect-error
|
2018-06-20 20:19:53 +00:00
|
|
|
import UIEvents from '../../../../../service/UI/UIEvents';
|
2022-09-07 08:20:05 +00:00
|
|
|
import { createProfilePanelButtonEvent } from '../../../analytics/AnalyticsEvents';
|
|
|
|
import { sendAnalytics } from '../../../analytics/functions';
|
2022-08-01 07:04:36 +00:00
|
|
|
// @ts-ignore
|
2020-05-20 10:57:03 +00:00
|
|
|
import { AbstractDialogTab } from '../../../base/dialog';
|
2022-08-01 07:04:36 +00:00
|
|
|
// @ts-ignore
|
2020-05-20 10:57:03 +00:00
|
|
|
import type { Props as AbstractDialogTabProps } from '../../../base/dialog';
|
2022-08-08 09:36:06 +00:00
|
|
|
import { translate } from '../../../base/i18n/functions';
|
2022-08-04 10:39:22 +00:00
|
|
|
import { Button } from '../../../base/ui/components/web';
|
2022-08-01 07:04:36 +00:00
|
|
|
import Input from '../../../base/ui/components/web/Input';
|
|
|
|
// @ts-ignore
|
2021-04-23 15:00:51 +00:00
|
|
|
import { openLogoutDialog } from '../../actions';
|
2018-06-20 20:19:53 +00:00
|
|
|
|
2022-09-06 17:32:20 +00:00
|
|
|
declare let APP: any;
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link ProfileTab}.
|
|
|
|
*/
|
2022-08-08 09:36:06 +00:00
|
|
|
export type Props = AbstractDialogTabProps & WithTranslation & {
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not server-side authentication is available.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
authEnabled: boolean;
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the currently (server-side) authenticated user.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
authLogin: string;
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The display name to display for the local participant.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
displayName: string;
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The email to display for the local participant.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
email: string;
|
2018-06-20 20:19:53 +00:00
|
|
|
|
2021-09-06 10:01:13 +00:00
|
|
|
/**
|
2022-08-01 07:04:36 +00:00
|
|
|
* Whether to hide the email input in the profile settings.
|
2021-09-06 10:01:13 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
hideEmailInSettings?: boolean;
|
2021-09-06 10:01:13 +00:00
|
|
|
|
2021-12-13 15:17:38 +00:00
|
|
|
/**
|
2022-08-01 07:04:36 +00:00
|
|
|
* If the display name is read only.
|
2021-12-13 15:17:38 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
readOnlyName: boolean;
|
2021-12-13 15:17:38 +00:00
|
|
|
|
2018-06-20 20:19:53 +00:00
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
t: Function;
|
|
|
|
};
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* React {@code Component} for modifying the local user's profile.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-06-20 20:19:53 +00:00
|
|
|
*/
|
|
|
|
class ProfileTab extends AbstractDialogTab<Props> {
|
2019-06-26 14:08:23 +00:00
|
|
|
static defaultProps = {
|
|
|
|
displayName: '',
|
|
|
|
email: ''
|
|
|
|
};
|
|
|
|
|
2018-06-20 20:19:53 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code ConnectedSettingsDialog} instance.
|
|
|
|
*
|
|
|
|
* @param {Props} props - The React {@code Component} props to initialize
|
|
|
|
* the new {@code ConnectedSettingsDialog} instance with.
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
|
|
|
this._onAuthToggle = this._onAuthToggle.bind(this);
|
2021-06-10 12:48:44 +00:00
|
|
|
this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
|
|
|
|
this._onEmailChange = this._onEmailChange.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes display name of the user.
|
|
|
|
*
|
2022-08-01 07:04:36 +00:00
|
|
|
* @param {string} value - The key event to handle.
|
2021-06-10 12:48:44 +00:00
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-01 07:04:36 +00:00
|
|
|
_onDisplayNameChange(value: string) {
|
2021-06-10 12:48:44 +00:00
|
|
|
super._onChange({ displayName: value });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes email of the user.
|
|
|
|
*
|
2022-08-01 07:04:36 +00:00
|
|
|
* @param {string} value - The key event to handle.
|
2021-06-10 12:48:44 +00:00
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-01 07:04:36 +00:00
|
|
|
_onEmailChange(value: string) {
|
2021-06-10 12:48:44 +00:00
|
|
|
super._onChange({ email: value });
|
2018-06-20 20:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
authEnabled,
|
|
|
|
displayName,
|
|
|
|
email,
|
2021-12-13 15:17:38 +00:00
|
|
|
hideEmailInSettings,
|
2021-09-06 10:01:13 +00:00
|
|
|
readOnlyName,
|
2022-08-01 07:04:36 +00:00
|
|
|
t // @ts-ignore
|
2018-06-20 20:19:53 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className = 'profile-edit'>
|
|
|
|
<div className = 'profile-edit-field'>
|
2022-08-01 07:04:36 +00:00
|
|
|
<Input
|
|
|
|
disabled = { readOnlyName }
|
2018-06-20 20:19:53 +00:00
|
|
|
id = 'setDisplayName'
|
|
|
|
label = { t('profile.setDisplayNameLabel') }
|
2022-08-01 07:04:36 +00:00
|
|
|
name = 'name'
|
2021-06-10 12:48:44 +00:00
|
|
|
onChange = { this._onDisplayNameChange }
|
2018-06-20 20:19:53 +00:00
|
|
|
placeholder = { t('settings.name') }
|
|
|
|
type = 'text'
|
|
|
|
value = { displayName } />
|
|
|
|
</div>
|
2021-12-13 15:17:38 +00:00
|
|
|
{!hideEmailInSettings && <div className = 'profile-edit-field'>
|
2022-08-01 07:04:36 +00:00
|
|
|
<Input
|
2018-06-20 20:19:53 +00:00
|
|
|
id = 'setEmail'
|
|
|
|
label = { t('profile.setEmailLabel') }
|
2022-08-01 07:04:36 +00:00
|
|
|
name = 'email'
|
2021-06-10 12:48:44 +00:00
|
|
|
onChange = { this._onEmailChange }
|
2018-06-20 20:19:53 +00:00
|
|
|
placeholder = { t('profile.setEmailInput') }
|
|
|
|
type = 'text'
|
|
|
|
value = { email } />
|
2021-12-13 15:17:38 +00:00
|
|
|
</div>}
|
2018-06-20 20:19:53 +00:00
|
|
|
</div>
|
|
|
|
{ authEnabled && this._renderAuth() }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the dialog for logging in or out of a server and closes this
|
|
|
|
* dialog.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onAuthToggle() {
|
2022-08-01 07:04:36 +00:00
|
|
|
// @ts-ignore
|
2018-06-20 20:19:53 +00:00
|
|
|
if (this.props.authLogin) {
|
|
|
|
sendAnalytics(createProfilePanelButtonEvent('logout.button'));
|
|
|
|
|
2021-04-23 15:00:51 +00:00
|
|
|
APP.store.dispatch(openLogoutDialog(
|
|
|
|
() => APP.UI.emitEvent(UIEvents.LOGOUT)
|
|
|
|
));
|
2018-06-20 20:19:53 +00:00
|
|
|
} else {
|
|
|
|
sendAnalytics(createProfilePanelButtonEvent('login.button'));
|
|
|
|
|
|
|
|
APP.UI.emitEvent(UIEvents.AUTH_CLICKED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a React Element for interacting with server-side authentication.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderAuth() {
|
|
|
|
const {
|
|
|
|
authLogin,
|
|
|
|
t
|
2022-08-01 07:04:36 +00:00
|
|
|
// @ts-ignore
|
2018-06-20 20:19:53 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2021-06-10 12:48:44 +00:00
|
|
|
<h2 className = 'mock-atlaskit-label'>
|
2018-06-20 20:19:53 +00:00
|
|
|
{ t('toolbar.authenticate') }
|
2021-06-10 12:48:44 +00:00
|
|
|
</h2>
|
2018-06-20 20:19:53 +00:00
|
|
|
{ authLogin
|
|
|
|
&& <div className = 'auth-name'>
|
|
|
|
{ t('settings.loggedIn', { name: authLogin }) }
|
|
|
|
</div> }
|
|
|
|
<Button
|
2022-08-04 10:39:22 +00:00
|
|
|
accessibilityLabel = { authLogin ? t('toolbar.logout') : t('toolbar.login') }
|
2018-06-20 20:19:53 +00:00
|
|
|
id = 'login_button'
|
2022-08-04 10:39:22 +00:00
|
|
|
label = { authLogin ? t('toolbar.logout') : t('toolbar.login') }
|
|
|
|
onClick = { this._onAuthToggle } />
|
2018-06-20 20:19:53 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-08 09:36:06 +00:00
|
|
|
// @ts-ignore
|
2018-06-20 20:19:53 +00:00
|
|
|
export default translate(ProfileTab);
|