Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Changes for exposing OOO feature in status dropdown #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions components/admin_console/admin_definition.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,26 @@ const AdminDefinition = {
],
},
},
out_of_office: {
url: 'out_of_office',
title: t('admin.sidebar.outOfOffice'),
title_default: 'Out Of Office',
schema: {
id: 'OutOfOfficeSettings',
name: t('admin.customization.outOfOffice'),
name_default: 'Out Of Office',
settings: [
{
type: Constants.SettingsTypes.TYPE_BOOL,
key: 'ServiceSettings.ShowOutOfOfficeInStatusDropdown',
label: t('admin.customization.showOutOfOfficeInStatusDropdown'),
label_default: 'Show Out Of Office In Status Dropdown:',
help_text: t('admin.customization.showOutOfOfficeInStatusDropdownDesc'),
help_text_default: 'Allows user to change status to Out Of Office either from status dropdown or from notification tab in settings sidebar.',
},
],
},
},
posts: {
url: 'site_config/posts',
title: t('admin.sidebar.posts'),
Expand Down
6 changes: 6 additions & 0 deletions components/status_dropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {setStatus} from 'mattermost-redux/actions/users';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {Client4} from 'mattermost-redux/client';
import {getCurrentUser, getStatusForUserId} from 'mattermost-redux/selectors/entities/users';
import {Preferences} from 'mattermost-redux/constants';
Expand All @@ -15,17 +16,22 @@ import StatusDropdown from 'components/status_dropdown/status_dropdown.jsx';

function mapStateToProps(state) {
const currentUser = getCurrentUser(state);
const config = getConfig(state);

if (!currentUser) {
return {};
}

const showOutOfOfficeInStatusDropdown = config.ShowOutOfOfficeInStatusDropdown === 'true';
const enableAutoResponder = config.ExperimentalEnableAutomaticReplies === 'true';
const userId = currentUser.id;
return {
userId,
profilePicture: Client4.getProfilePictureUrl(userId, currentUser.last_picture_update),
autoResetPref: get(state, Preferences.CATEGORY_AUTO_RESET_MANUAL_STATUS, userId, ''),
status: getStatusForUserId(state, userId),
showOutOfOfficeInStatusDropdown,
enableAutoResponder,
};
}

Expand Down
15 changes: 15 additions & 0 deletions components/status_dropdown/ooo_settings/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {connect} from 'react-redux';
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';

import OooSettings from './ooo_settings.jsx';

function mapStateToProps(state) {
return {
user: getCurrentUser(state),
};
}

export default connect(mapStateToProps)(OooSettings);
15 changes: 15 additions & 0 deletions components/status_dropdown/ooo_settings/modal/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {connect} from 'react-redux';
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';

import OooSettingsModal from './ooo_settings_modal.jsx';

function mapStateToProps(state) {
return {
currentUser: getCurrentUser(state),
};
}

export default connect(mapStateToProps)(OooSettingsModal);
107 changes: 107 additions & 0 deletions components/status_dropdown/ooo_settings/modal/ooo_settings_modal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {Modal} from 'react-bootstrap';

import {FormattedMessage, injectIntl} from 'react-intl';
import PropTypes from 'prop-types';

import Constants from 'utils/constants.jsx';
import * as Utils from 'utils/utils.jsx';
import {AsyncComponent} from 'components/async_load';

import OooSetting from 'bundle-loader?lazy!components/status_dropdown/ooo_settings';

class AutoResponderModal extends React.Component {
static propTypes = {
currentUser: PropTypes.object,
onHide: PropTypes.func.isRequired,
};

constructor(props) {
super(props);

this.state = {
active_section: '',
prev_active_section: 'dummySectionName', // dummy value that should never match any section name
show: true,
};
}
componentDidMount() {
document.addEventListener('keydown', this.handleKeyDown);
}

componentWillUnmount() {
document.removeEventListener('keydown', this.handleKeyDown);
}

handleKeyDown = (e) => {
if (Utils.cmdOrCtrlPressed(e) && e.shiftKey && Utils.isKeyPressed(e, Constants.KeyCodes.A)) {
this.handleHide();
}
};

// Called when the close button is pressed on the main modal
handleHide = () => {
this.setState({
show: false,
});
};

// called after the dialog is fully hidden and faded out
handleHidden = () => {
this.setState({
active_section: '',
prev_active_section: 'dummySectionName',
});
this.props.onHide();
};

updateSection = (section) => {
this.setState({
prev_active_section: section ? '' : this.state.active_section,
active_section: section,
show: !this.state.show,
});
};

render() {
if (this.props.currentUser == null) {
return (<div/>);
}

return (
<Modal
id='oooAutoResponderModal'
dialogClassName='auto-responder-modal'
show={this.state.show}
onHide={this.handleHide}
onExited={this.handleHidden}
enforceFocus={this.state.enforceFocus}
>
<Modal.Header
id='oooAutoResponderHeader'
closeButton={true}
>
<Modal.Title id='oooAutoResponderTitle'>
<FormattedMessage
id='status.dropdown.modal.title'
defaultMessage='Automatic Replies(Out of Office)'
/>
</Modal.Title>
</Modal.Header>
<Modal.Body ref='modalBody'>

<div>
<AsyncComponent
doLoad={OooSetting}
updateSection={this.updateSection}
/>
</div>
</Modal.Body>
</Modal>
);
}
}

export default injectIntl(AutoResponderModal);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {updateMe} from 'mattermost-redux/actions/users';
import {getConfig} from 'mattermost-redux/selectors/entities/general';

import OooAutoResponder from './ooo_auto_reponder.jsx';

function mapStateToProps(state) {
const config = getConfig(state);

const enableAutoResponder = config.ExperimentalEnableAutomaticReplies === 'true';

return {
enableAutoResponder,
};
}

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({updateMe}, dispatch),
};
}

export default connect(mapStateToProps, mapDispatchToProps)(OooAutoResponder);
Loading