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.

AbstractDisplayNamePrompt.tsx 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import type { Dispatch } from 'redux';
  4. // @ts-ignore
  5. import { updateSettings } from '../../base/settings';
  6. /**
  7. * The type of the React {@code Component} props of
  8. * {@link AbstractDisplayNamePrompt}.
  9. */
  10. export interface Props extends WithTranslation {
  11. /**
  12. * Invoked to update the local participant's display name.
  13. */
  14. dispatch: Dispatch<any>;
  15. /**
  16. * Function to be invoked after a successful display name change.
  17. */
  18. onPostSubmit?: Function;
  19. }
  20. /**
  21. * Implements an abstract class for {@code DisplayNamePrompt}.
  22. */
  23. export default class AbstractDisplayNamePrompt<S>
  24. extends Component<Props, S> {
  25. /**
  26. * Instantiates a new component.
  27. *
  28. * @inheritdoc
  29. */
  30. constructor(props: Props) {
  31. super(props);
  32. this._onSetDisplayName = this._onSetDisplayName.bind(this);
  33. }
  34. /**
  35. * Dispatches an action to update the local participant's display name. A
  36. * name must be entered for the action to dispatch.
  37. *
  38. * It returns a boolean to comply the Dialog behaviour:
  39. * {@code true} - the dialog should be closed.
  40. * {@code false} - the dialog should be left open.
  41. *
  42. * @param {string} displayName - The display name to save.
  43. * @returns {boolean}
  44. */
  45. _onSetDisplayName(displayName: string) {
  46. if (!displayName || !displayName.trim()) {
  47. return false;
  48. }
  49. const { dispatch, onPostSubmit } = this.props;
  50. // Store display name in settings
  51. dispatch(updateSettings({
  52. displayName
  53. }));
  54. onPostSubmit?.();
  55. return true;
  56. }
  57. }