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.js 1.7KB

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