jiti-meet/react/features/display-name/components/AbstractDisplayNamePrompt.tsx

69 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-01-13 19:33:28 +00:00
import { Component } from 'react';
import { WithTranslation } from 'react-i18next';
2019-03-19 15:42:25 +00:00
import type { Dispatch } from 'redux';
2019-01-13 19:33:28 +00:00
// @ts-ignore
2019-01-13 19:33:28 +00:00
import { updateSettings } from '../../base/settings';
/**
* The type of the React {@code Component} props of
* {@link AbstractDisplayNamePrompt}.
*/
export interface Props extends WithTranslation {
2019-01-13 19:33:28 +00:00
/**
* Invoked to update the local participant's display name.
*/
dispatch: Dispatch<any>;
2019-01-13 19:33:28 +00:00
/**
* Function to be invoked after a successful display name change.
*/
onPostSubmit?: Function;
}
2019-01-13 19:33:28 +00:00
/**
* Implements an abstract class for {@code DisplayNamePrompt}.
*/
export default class AbstractDisplayNamePrompt<S>
2019-01-13 19:33:28 +00:00
extends Component<Props, S> {
/**
* Instantiates a new component.
*
* @inheritdoc
*/
constructor(props: Props) {
super(props);
this._onSetDisplayName = this._onSetDisplayName.bind(this);
}
/**
* Dispatches an action to update the local participant's display name. A
* name must be entered for the action to dispatch.
*
* It returns a boolean to comply the Dialog behaviour:
* {@code true} - the dialog should be closed.
* {@code false} - the dialog should be left open.
*
* @param {string} displayName - The display name to save.
* @returns {boolean}
*/
_onSetDisplayName(displayName: string) {
2019-01-13 19:33:28 +00:00
if (!displayName || !displayName.trim()) {
return false;
}
const { dispatch, onPostSubmit } = this.props;
// Store display name in settings
dispatch(updateSettings({
displayName
}));
onPostSubmit?.();
2019-01-13 19:33:28 +00:00
return true;
}
}