Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AbstractDisplayNamePrompt.tsx 1.7KB

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