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
/
edit_post_time_limit_modal.jsx
187 lines (173 loc) · 7.77 KB
/
edit_post_time_limit_modal.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// 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, FormattedHTMLMessage} from 'react-intl';
import {Modal} from 'react-bootstrap';
import {Constants} from 'utils/constants';
import {localizeMessage} from 'utils/utils.jsx';
import {t} from 'utils/i18n';
const INT32_MAX = 2147483647;
export default class EditPostTimeLimitModal extends React.Component {
static propTypes = {
config: PropTypes.object.isRequired,
show: PropTypes.bool,
onClose: PropTypes.func.isRequired,
actions: PropTypes.shape({
updateConfig: PropTypes.func.isRequired,
getConfig: PropTypes.func.isRequired,
}).isRequired,
};
constructor(props) {
super(props);
this.state = {
postEditTimeLimit: parseInt(props.config.ServiceSettings.PostEditTimeLimit, 10),
saving: false,
errorMessage: '',
};
}
UNSAFE_componentWillMount() { // eslint-disable-line camelcase
this.props.actions.getConfig();
}
save = async () => {
this.setState({saving: true, errorMessage: ''});
const val = parseInt(this.state.postEditTimeLimit, 10);
if (val !== Constants.UNSET_POST_EDIT_TIME_LIMIT) {
if (val.toString() === 'NaN' || val <= 0 || val > INT32_MAX) {
this.setState({errorMessage: localizeMessage('edit_post.time_limit_modal.invalid_time_limit', 'Invalid time limit'), saving: false});
return false;
}
}
const newConfig = JSON.parse(JSON.stringify(this.props.config));
newConfig.ServiceSettings.PostEditTimeLimit = val;
const {error: err} = await this.props.actions.updateConfig(newConfig);
if (err) {
this.setState({errorMessage: err, saving: false});
} else {
this.setState({saving: false});
this.props.onClose();
}
return true;
}
handleOptionChange = (e) => {
const {value} = e.target;
if (value === Constants.ALLOW_EDIT_POST_ALWAYS) {
this.setState({postEditTimeLimit: Constants.UNSET_POST_EDIT_TIME_LIMIT});
} else {
this.setState({postEditTimeLimit: ''});
}
}
handleSecondsChange = (e) => {
const {value} = e.target;
this.setState({postEditTimeLimit: value});
}
render = () => {
return (
<Modal
dialogClassName='admin-modal edit-post-time-limit-modal'
show={this.props.show}
>
<Modal.Header
closeButton={true}
>
<h4 className='modal-title'>
<FormattedMessage
id='edit_post.time_limit_modal.title'
defaultMessage='Configure Global Edit Post Time Limit'
/>
</h4>
</Modal.Header>
<Modal.Body>
<FormattedHTMLMessage
id='edit_post.time_limit_modal.description'
defaultMessage='Setting a time limit <strong>applies to all users</strong> who have the "Edit Post" permissions in any permission scheme.'
/>
<div className='padding-left x2 padding-top padding-bottom'>
<div className='padding-top x2'>
<input
id='anytime'
type='radio'
name='limit'
value={Constants.ALLOW_EDIT_POST_ALWAYS}
checked={this.state.postEditTimeLimit === Constants.UNSET_POST_EDIT_TIME_LIMIT}
onChange={this.handleOptionChange}
/>
<label htmlFor='anytime'>
<FormattedMessage
id='edit_post.time_limit_modal.option_label_anytime'
defaultMessage='Anytime'
/>
</label>
</div>
<div className='padding-top'>
<input
id='timelimit'
type='radio'
name='limit'
value={Constants.ALLOW_EDIT_POST_TIME_LIMIT}
checked={this.state.postEditTimeLimit !== Constants.UNSET_POST_EDIT_TIME_LIMIT}
onChange={this.handleOptionChange}
/>
<label htmlFor='timelimit'>
<FormattedMessage
id='edit_post.time_limit_modal.option_label_time_limit.preinput'
defaultMessage='Can edit for'
/>
</label>
<input
type='number'
className='form-control inline'
min='0'
step='1'
max={INT32_MAX}
id='editPostTimeLimit'
readOnly={this.state.postEditTimeLimit === Constants.UNSET_POST_EDIT_TIME_LIMIT}
onChange={this.handleSecondsChange}
value={this.state.postEditTimeLimit === Constants.UNSET_POST_EDIT_TIME_LIMIT ? '' : this.state.postEditTimeLimit}
/>
<label htmlFor='timelimit'>
<FormattedMessage
id='edit_post.time_limit_modal.option_label_time_limit.postinput'
defaultMessage='seconds after posting'
/>
</label>
</div>
<div className='padding-top x2 light'>
<FormattedMessage
id='edit_post.time_limit_modal.subscript'
defaultMessage='Set the length of time users have to edit their messages after posting.'
/>
</div>
</div>
</Modal.Body>
<Modal.Footer>
<div className='edit-post-time-limit-modal__error'>
{this.state.errorMessage}
</div>
<button
type='button'
className='btn btn-cancel'
onClick={this.props.onClose}
>
<FormattedMessage
id='confirm_modal.cancel'
defaultMessage='Cancel'
/>
</button>
<button
id='linkModalCloseButton'
type='button'
className='btn btn-default'
onClick={this.save}
disabled={this.state.saving}
>
<FormattedMessage
id={this.state.saving ? t('save_button.saving') : t('edit_post.time_limit_modal.save_button')}
defaultMessage='Save Edit Time'
/>
</button>
</Modal.Footer>
</Modal>
);
};
}