|
@@ -0,0 +1,150 @@
|
|
1
|
+import AKFieldText from '@atlaskit/field-text';
|
|
2
|
+import React, { Component } from 'react';
|
|
3
|
+import { connect } from 'react-redux';
|
|
4
|
+
|
|
5
|
+import { Dialog } from '../../base/dialog';
|
|
6
|
+import { translate } from '../../base/i18n';
|
|
7
|
+import {
|
|
8
|
+ getLocalParticipant,
|
|
9
|
+ participantDisplayNameChanged
|
|
10
|
+} from '../../base/participants';
|
|
11
|
+
|
|
12
|
+/**
|
|
13
|
+ * Implements a React {@code Component} for displaying a dialog with an field
|
|
14
|
+ * for setting the local participant's display name.
|
|
15
|
+ *
|
|
16
|
+ * @extends Component
|
|
17
|
+ */
|
|
18
|
+class DisplayNamePrompt extends Component {
|
|
19
|
+ /**
|
|
20
|
+ * {@code DisplayNamePrompt} component's property types.
|
|
21
|
+ *
|
|
22
|
+ * @static
|
|
23
|
+ */
|
|
24
|
+ static propTypes = {
|
|
25
|
+ /**
|
|
26
|
+ * The current ID for the local participant. Used for setting the
|
|
27
|
+ * display name on the associated participant.
|
|
28
|
+ */
|
|
29
|
+ _localParticipantID: React.PropTypes.string,
|
|
30
|
+
|
|
31
|
+ /**
|
|
32
|
+ * Invoked to update the local participant's display name.
|
|
33
|
+ */
|
|
34
|
+ dispatch: React.PropTypes.func,
|
|
35
|
+
|
|
36
|
+ /**
|
|
37
|
+ * Invoked to obtain translated strings.
|
|
38
|
+ */
|
|
39
|
+ t: React.PropTypes.func
|
|
40
|
+ };
|
|
41
|
+
|
|
42
|
+ /**
|
|
43
|
+ * Initializes a new {@code DisplayNamePrompt} instance.
|
|
44
|
+ *
|
|
45
|
+ * @param {Object} props - The read-only properties with which the new
|
|
46
|
+ * instance is to be initialized.
|
|
47
|
+ */
|
|
48
|
+ constructor(props) {
|
|
49
|
+ super(props);
|
|
50
|
+
|
|
51
|
+ this.state = {
|
|
52
|
+ /**
|
|
53
|
+ * The name to show in the display name text field.
|
|
54
|
+ *
|
|
55
|
+ * @type {string}
|
|
56
|
+ */
|
|
57
|
+ displayName: ''
|
|
58
|
+ };
|
|
59
|
+
|
|
60
|
+ // Bind event handlers so they are only bound once for every instance.
|
|
61
|
+ this._onDisplayNameChange = this._onDisplayNameChange.bind(this);
|
|
62
|
+ this._onSubmit = this._onSubmit.bind(this);
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ /**
|
|
66
|
+ * Implements React's {@link Component#render()}.
|
|
67
|
+ *
|
|
68
|
+ * @inheritdoc
|
|
69
|
+ * @returns {ReactElement}
|
|
70
|
+ */
|
|
71
|
+ render() {
|
|
72
|
+ return (
|
|
73
|
+ <Dialog
|
|
74
|
+ isModal = { true }
|
|
75
|
+ onSubmit = { this._onSubmit }
|
|
76
|
+ titleKey = 'dialog.displayNameRequired'
|
|
77
|
+ width = 'small'>
|
|
78
|
+ <AKFieldText
|
|
79
|
+ autoFocus = { true }
|
|
80
|
+ compact = { true }
|
|
81
|
+ label = { this.props.t('dialog.enterDisplayName') }
|
|
82
|
+ name = 'displayName'
|
|
83
|
+ onChange = { this._onDisplayNameChange }
|
|
84
|
+ shouldFitContainer = { true }
|
|
85
|
+ type = 'text'
|
|
86
|
+ value = { this.state.displayName } />
|
|
87
|
+ </Dialog>);
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ /**
|
|
91
|
+ * Updates the entered display name.
|
|
92
|
+ *
|
|
93
|
+ * @param {Object} event - The DOM event triggered from the entered display
|
|
94
|
+ * name value having changed.
|
|
95
|
+ * @private
|
|
96
|
+ * @returns {void}
|
|
97
|
+ */
|
|
98
|
+ _onDisplayNameChange(event) {
|
|
99
|
+ this.setState({
|
|
100
|
+ displayName: event.target.value
|
|
101
|
+ });
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ /**
|
|
105
|
+ * Dispatches an action to update the local participant's display name. A
|
|
106
|
+ * name must be entered for the action to dispatch.
|
|
107
|
+ *
|
|
108
|
+ * @private
|
|
109
|
+ * @returns {void}
|
|
110
|
+ */
|
|
111
|
+ _onSubmit() {
|
|
112
|
+ const { displayName } = this.state;
|
|
113
|
+
|
|
114
|
+ if (!displayName.trim()) {
|
|
115
|
+ return false;
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ const { dispatch, _localParticipantID } = this.props;
|
|
119
|
+
|
|
120
|
+ dispatch(
|
|
121
|
+ participantDisplayNameChanged(_localParticipantID, displayName));
|
|
122
|
+
|
|
123
|
+ return true;
|
|
124
|
+ }
|
|
125
|
+}
|
|
126
|
+
|
|
127
|
+/**
|
|
128
|
+ * Maps (parts of) the Redux state to the associated {@code DisplayNamePrompt}'s
|
|
129
|
+ * props.
|
|
130
|
+ *
|
|
131
|
+ * @param {Object} state - The Redux state.
|
|
132
|
+ * @private
|
|
133
|
+ * @returns {{
|
|
134
|
+ * _localParticipantID: string
|
|
135
|
+ * }}
|
|
136
|
+ */
|
|
137
|
+function _mapStateToProps(state) {
|
|
138
|
+ const { id } = getLocalParticipant(state);
|
|
139
|
+
|
|
140
|
+ return {
|
|
141
|
+ /**
|
|
142
|
+ * The current ID for the local participant.
|
|
143
|
+ *
|
|
144
|
+ * @type {string}
|
|
145
|
+ */
|
|
146
|
+ _localParticipantID: id
|
|
147
|
+ };
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+export default translate(connect(_mapStateToProps)(DisplayNamePrompt));
|