Skip to content

Commit

Permalink
Added new segment analytics (mattermost#3511)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLu1997 authored and coreyhulen committed Jul 6, 2016
1 parent 5f93d99 commit 75b2a70
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/user_settings/import_theme_modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ImportThemeModal extends React.Component {
const user = UserStore.getCurrentUser();
user.theme_props = theme;

Client.updateUser(user,
Client.updateUser(user, Constants.UserUpdateEvents.THEME,
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_ME,
Expand Down
3 changes: 2 additions & 1 deletion components/user_settings/manage_languages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import SettingItemMax from '../setting_item_max.jsx';
import Client from 'utils/web_client.jsx';
import * as I18n from 'i18n/i18n.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import Constants from 'utils/constants.jsx';

import {FormattedMessage} from 'react-intl';

Expand Down Expand Up @@ -41,7 +42,7 @@ export default class ManageLanguage extends React.Component {
this.submitUser(user);
}
submitUser(user) {
Client.updateUser(user,
Client.updateUser(user, Constants.UserUpdateEvents.LANGUAGE,
() => {
GlobalActions.newLocalizationSelected(user.locale);
},
Expand Down
29 changes: 23 additions & 6 deletions components/user_settings/user_settings_general.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class UserSettingsGeneralTab extends React.Component {
this.state = this.setupInitialState(props);
this.setState({maxFileSize: global.window.mm_config.MaxFileSize});
}

submitUsername(e) {
e.preventDefault();

Expand All @@ -120,8 +121,9 @@ class UserSettingsGeneralTab extends React.Component {

user.username = username;

this.submitUser(user, false);
this.submitUser(user, Constants.UserUpdateEvents.USERNAME, false);
}

submitNickname(e) {
e.preventDefault();

Expand All @@ -135,8 +137,9 @@ class UserSettingsGeneralTab extends React.Component {

user.nickname = nickname;

this.submitUser(user, false);
this.submitUser(user, Constants.UserUpdateEvents.NICKNAME, false);
}

submitName(e) {
e.preventDefault();

Expand All @@ -152,8 +155,9 @@ class UserSettingsGeneralTab extends React.Component {
user.first_name = firstName;
user.last_name = lastName;

this.submitUser(user, false);
this.submitUser(user, Constants.UserUpdateEvents.FULLNAME, false);
}

submitEmail(e) {
e.preventDefault();

Expand All @@ -179,10 +183,11 @@ class UserSettingsGeneralTab extends React.Component {
}

user.email = email;
this.submitUser(user, true);
this.submitUser(user, Constants.UserUpdateEvents.EMAIL, true);
}
submitUser(user, emailUpdated) {
Client.updateUser(user,

submitUser(user, type, emailUpdated) {
Client.updateUser(user, type,
() => {
this.updateSection('');
AsyncClient.getMe();
Expand All @@ -205,6 +210,7 @@ class UserSettingsGeneralTab extends React.Component {
}
);
}

submitPicture(e) {
e.preventDefault();

Expand Down Expand Up @@ -242,24 +248,31 @@ class UserSettingsGeneralTab extends React.Component {
}
);
}

updateUsername(e) {
this.setState({username: e.target.value});
}

updateFirstName(e) {
this.setState({firstName: e.target.value});
}

updateLastName(e) {
this.setState({lastName: e.target.value});
}

updateNickname(e) {
this.setState({nickname: e.target.value});
}

updateEmail(e) {
this.setState({email: e.target.value});
}

updateConfirmEmail(e) {
this.setState({confirmEmail: e.target.value});
}

updatePicture(e) {
if (e.target.files && e.target.files[0]) {
this.setState({picture: e.target.files[0]});
Expand All @@ -270,19 +283,22 @@ class UserSettingsGeneralTab extends React.Component {
this.setState({picture: null});
}
}

updateSection(section) {
$('.settings-modal .modal-body').scrollTop(0).perfectScrollbar('update');
const emailChangeInProgress = this.state.emailChangeInProgress;
this.setState(Object.assign({}, this.setupInitialState(this.props), {emailChangeInProgress, clientError: '', serverError: '', emailError: ''}));
this.submitActive = false;
this.props.updateSection(section);
}

setupInitialState(props) {
const user = props.user;

return {username: user.username, firstName: user.first_name, lastName: user.last_name, nickname: user.nickname,
email: user.email, confirmEmail: '', picture: null, loadingPicture: false, emailChangeInProgress: false};
}

createEmailSection() {
let emailSection;

Expand Down Expand Up @@ -526,6 +542,7 @@ class UserSettingsGeneralTab extends React.Component {

return emailSection;
}

render() {
const user = this.props.user;
const {formatMessage} = this.props.intl;
Expand Down
2 changes: 1 addition & 1 deletion components/user_settings/user_settings_theme.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class ThemeSetting extends React.Component {
var user = UserStore.getCurrentUser();
user.theme_props = this.state.theme;

Client.updateUser(user,
Client.updateUser(user, Constants.UserUpdateEvents.THEME,
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_ME,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"keymirror": "0.1.1",
"marked": "mattermost/marked#12d2be4cdf54d4ec95fead934e18840b6a2c1a7b",
"match-at": "0.1.0",
"mattermost": "mattermost/mattermost-javascript#798c39c5d302d2d109e768a35575ebdbf2a8ee6a",
"mattermost": "mattermost/mattermost-javascript#18527e6c4a9aea69aa7845a62d9618b357faa4e7",
"object-assign": "4.1.0",
"perfect-scrollbar": "0.6.11",
"react": "15.0.2",
Expand Down
9 changes: 9 additions & 0 deletions utils/constants.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ export default {
EPHEMERAL_MESSAGE: 'ephemeral_message'
},

UserUpdateEvents: {
USERNAME: 'username',
FULLNAME: 'fullname',
NICKNAME: 'nickname',
EMAIL: 'email',
THEME: 'theme',
LANGUAGE: 'language'
},

ScrollTypes: {
FREE: 1,
BOTTOM: 2,
Expand Down

0 comments on commit 75b2a70

Please sign in to comment.