This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
join_leave_section.jsx
135 lines (120 loc) · 5.42 KB
/
join_leave_section.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';
import {Preferences} from 'mattermost-redux/constants';
import SettingItemMax from 'components/setting_item_max.jsx';
import SettingItemMin from 'components/setting_item_min';
import {AdvancedSections} from 'utils/constants.jsx';
export default class JoinLeaveSection extends React.PureComponent {
static propTypes = {
activeSection: PropTypes.string,
currentUserId: PropTypes.string.isRequired,
joinLeave: PropTypes.string,
onUpdateSection: PropTypes.func.isRequired,
renderOnOffLabel: PropTypes.func.isRequired,
actions: PropTypes.shape({
savePreferences: PropTypes.func.isRequired,
}).isRequired,
}
constructor(props) {
super(props);
this.state = {
joinLeaveState: props.joinLeave,
};
}
handleOnChange = (e) => {
const value = e.currentTarget.value;
this.setState({joinLeaveState: value});
}
handleUpdateSection = (section) => {
if (!section) {
this.setState({joinLeaveState: this.props.joinLeave});
}
this.props.onUpdateSection(section);
}
handleSubmit = () => {
const {actions, currentUserId, onUpdateSection} = this.props;
const joinLeavePreference = {category: Preferences.CATEGORY_ADVANCED_SETTINGS, user_id: currentUserId, name: Preferences.ADVANCED_FILTER_JOIN_LEAVE, value: this.state.joinLeaveState};
actions.savePreferences(currentUserId, [joinLeavePreference]);
onUpdateSection();
}
render() {
const {joinLeaveState} = this.state;
if (this.props.activeSection === AdvancedSections.JOIN_LEAVE) {
return (
<SettingItemMax
title={
<FormattedMessage
id='user.settings.advance.joinLeaveTitle'
defaultMessage='Enable Join/Leave Messages'
/>
}
inputs={[
<fieldset key='joinLeaveSetting'>
<div className='radio'>
<label>
<input
id='joinLeaveOn'
type='radio'
value={'true'}
name={AdvancedSections.JOIN_LEAVE}
checked={joinLeaveState === 'true'}
onChange={this.handleOnChange}
/>
<FormattedMessage
id='user.settings.advance.on'
defaultMessage='On'
/>
</label>
<br/>
</div>
<div className='radio'>
<label>
<input
id='joinLeaveOff'
type='radio'
value={'false'}
name={AdvancedSections.JOIN_LEAVE}
checked={joinLeaveState === 'false'}
onChange={this.handleOnChange}
/>
<FormattedMessage
id='user.settings.advance.off'
defaultMessage='Off'
/>
</label>
<br/>
</div>
<div className='margin-top x3'>
<FormattedMessage
id='user.settings.advance.joinLeaveDesc'
defaultMessage='When "On", System Messages saying a user has joined or left a channel will be visible. When "Off", the System Messages about joining or leaving a channel will be hidden. A message will still show up when you are added to a channel, so you can receive a notification.'
/>
</div>
</fieldset>,
]}
setting={AdvancedSections.JOIN_LEAVE}
submit={this.handleSubmit}
saving={this.state.isSaving}
server_error={this.state.serverError}
updateSection={this.handleUpdateSection}
/>
);
}
return (
<SettingItemMin
title={
<FormattedMessage
id='user.settings.advance.joinLeaveTitle'
defaultMessage='Enable Join/Leave Messages'
/>
}
describe={this.props.renderOnOffLabel(joinLeaveState)}
section={AdvancedSections.JOIN_LEAVE}
updateSection={this.handleUpdateSection}
/>
);
}
}