From d7eb9f702f29a9c2d54bafa03a99e3ff54307ea6 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 29 Nov 2016 19:47:29 -0300 Subject: [PATCH 1/2] Ivan - frontend Add ban users [skip ci] --- .../panel/users/admin-panel-ban-users.js | 117 +++++++++++++++++- .../panel/users/admin-panel-ban-users.scss | 36 ++++++ client/src/core-components/search-box.js | 47 ++++++- client/src/data/fixtures/user-fixtures.js | 81 ++++++++++++ client/src/data/languages/en.js | 5 + 5 files changed, 280 insertions(+), 6 deletions(-) create mode 100644 client/src/app/admin/panel/users/admin-panel-ban-users.scss diff --git a/client/src/app/admin/panel/users/admin-panel-ban-users.js b/client/src/app/admin/panel/users/admin-panel-ban-users.js index acb259e4..328fcec2 100644 --- a/client/src/app/admin/panel/users/admin-panel-ban-users.js +++ b/client/src/app/admin/panel/users/admin-panel-ban-users.js @@ -1,14 +1,127 @@ import React from 'react'; +import i18n from 'lib-app/i18n'; +import API from 'lib-app/api-call'; + +import Header from 'core-components/header'; +import Table from 'core-components/table'; +import SearchBox from 'core-components/search-box'; +import Button from 'core-components/button'; +import SubmitButton from 'core-components/submit-button'; +import Form from 'core-components/form'; +import FormField from 'core-components/form-field'; + class AdminPanelBanUsers extends React.Component { + state = { + loadingList: true, + loadingForm: false, + emails: [], + filteredEmails: [] + }; + + componentDidMount() { + this.retrieveEmails() + } + render() { return ( -
- /admin/panel/users/ban-users +
+
+
+ + + +
+ + {i18n('BAN_NEW_EMAIL')} + +
+ + {i18n('BAN_EMAIL')} + +
); } + + getTableProps() { + return { + loading: this.state.loadingList, + headers: [{ + key: 'email', + value: i18n('EMAIL_BANNED') + }], + pageSize: 10, + rows: this.state.filteredEmails.map(this.getEmailRow.bind(this)) + }; + } + + getFormProps() { + return { + loading: this.state.loadingForm, + onSubmit: this.onBanMailFormSubmit.bind(this) + }; + } + + getEmailRow(email) { + return { + email: ( +
+ {email} + +
+ ) + }; + } + + onSearch(query) { + this.setState({ + filteredEmails: SearchBox.searchQueryInList(this.state.emails, query) + }); + } + + onBanMailFormSubmit(form) { + this.setState({ + loadingForm: true + }); + + API.call({ + path: '/user/ban', + data: { + email: form.email + } + }).then(this.retrieveEmails.bind(this)); + } + + onUnBanClick(email) { + API.call({ + path: '/user/un-ban', + data: { + email: email + } + }).then(this.retrieveEmails.bind(this)); + } + + retrieveEmails() { + this.setState({ + loadingList: true + }); + + API.call({ + path: '/user/list-ban', + data: {} + }).then((result) => { + this.setState({ + loadingList: false, + loadingForm: false, + emails: result.data, + filteredEmails: result.data + }); + }); + } } export default AdminPanelBanUsers; \ No newline at end of file diff --git a/client/src/app/admin/panel/users/admin-panel-ban-users.scss b/client/src/app/admin/panel/users/admin-panel-ban-users.scss new file mode 100644 index 00000000..799e21fe --- /dev/null +++ b/client/src/app/admin/panel/users/admin-panel-ban-users.scss @@ -0,0 +1,36 @@ +@import '../../../../scss/vars'; + +.admin-panel-ban-users { + padding: 0 20px; + + &__email-list { + + } + + &__search { + margin-bottom: 20px; + } + + &__email-row { + text-align: left; + padding: 5px 10px; + } + + &__un-ban-button { + float: right; + margin-top: -5px; + } + + &__ban-email { + text-align: center; + + &-title { + color: $primary-black; + font-size: $font-size--md; + } + } + + &__input { + display: inline-block; + } +} \ No newline at end of file diff --git a/client/src/core-components/search-box.js b/client/src/core-components/search-box.js index 13489a75..90477e9d 100644 --- a/client/src/core-components/search-box.js +++ b/client/src/core-components/search-box.js @@ -1,4 +1,6 @@ import React from 'react'; +import classNames from 'classnames'; +import _ from 'lodash'; import Input from 'core-components/input'; import Icon from 'core-components/icon'; @@ -6,17 +8,40 @@ import keyCode from 'keycode'; class SearchBox extends React.Component { + static searchQueryInList(list, query) { + let match = []; + let rest = []; + + list.forEach(function (item) { + if(_.startsWith(item, query)) { + match.push(item); + } else { + rest.push(item); + } + }); + + rest.forEach(function (item) { + if(_.includes(item, query)) { + match.push(item); + } + }); + + return match; + } + static propTypes = { - onSearch: React.PropTypes.func + onSearch: React.PropTypes.func, + searchOnType: React.PropTypes.bool }; state = { - value: '' + value: '', + searchOnType: false }; render() { return ( -
+
@@ -25,14 +50,28 @@ class SearchBox extends React.Component { ); } + getClass() { + let classes = { + 'search-box': true + }; + + classes[this.props.className] = (this.props.className); + + return classNames(classes); + } + onChange(event) { this.setState({ value: event.target.value }); + + if (this.props.searchOnType && this.props.onSearch) { + this.props.onSearch(event.target.value); + } } onKeyDown(event) { - if(keyCode(event) === 'enter' && this.props.onSearch) { + if(keyCode(event) === 'enter' && this.props.onSearch && !this.props.searchOnType) { this.props.onSearch(this.state.value); } } diff --git a/client/src/data/fixtures/user-fixtures.js b/client/src/data/fixtures/user-fixtures.js index 1177e941..a97cb5b4 100644 --- a/client/src/data/fixtures/user-fixtures.js +++ b/client/src/data/fixtures/user-fixtures.js @@ -489,5 +489,86 @@ module.exports = [ } }; } + }, + { + path: '/user/un-ban', + time: 100, + response: function () { + return { + status: 'success', + data: {} + }; + } + }, + { + path: '/user/ban', + time: 100, + response: function () { + return { + status: 'success', + data: {} + }; + } + }, + { + path: '/user/list-ban', + time: 100, + response: function () { + return { + status: 'success', + data: [ + 'unairable@randomword.com', + 'hotchpot@randomword.com', + 'elucidator@randomword.com', + 'sug@randomword.com', + 'nonculpability@randomword.com', + 'steeplechaser@randomword.com', + 'undefinite@randomword.com', + 'anthobian@randomword.com', + 'nontourist@randomword.com', + 'berberis@randomword.com', + 'sextus@randomword.com', + 'empiristic@randomword.com', + 'epistolized@randomword.com', + 'duntroon@randomword.com', + 'unpalled@randomword.com', + 'baddish@randomword.com', + 'subcritical@randomword.com', + 'bolger@randomword.com', + 'deactivate@randomword.com', + 'visually@randomword.com', + 'cameral@randomword.com', + 'unpieced@randomword.com', + 'gaging@randomword.com', + 'advancement@randomword.com', + 'plenteous@randomword.com', + 'thallious@randomword.com', + 'vernalizing@randomword.com', + 'nekhbetv@randomword.com', + 'unsmocke@randomword.com', + 'nonprojective@randomword.com', + 'nonconductible@randomword.com', + 'gladsomeness@randomword.com', + 'nongravitation@randomword.com', + 'restatement@randomword.com', + 'pokeys@randomword.com', + 'epis@randomword.com', + 'successor@randomword.com', + 'jurisprudentially@randomword.com', + 'medullization@randomword.com', + 'evan@randomword.com', + 'outliver@randomword.com', + 'antipode@randomword.com', + 'sunshiny@randomword.com', + 'microscopopy@randomword.com', + 'enatic@randomword.com', + 'smittle@randomword.com', + 'musk@randomword.com', + 'litui@randomword.com', + 'aquarellist@randomword.com', + 'chirac@randomword.com' + ] + }; + } } ]; \ No newline at end of file diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index e964ceec..dd25e42f 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -75,6 +75,10 @@ export default { 'WARNING': 'Warning', 'INFO': 'Information', 'ALL_DEPARTMENTS': 'All Departments', + 'EMAIL_BANNED': 'Email banned', + 'UN_BAN': 'Disable ban', + 'BAN_NEW_EMAIL': 'Ban new email', + 'BAN_EMAIL': 'Ban email', //VIEW DESCRIPTIONS 'CREATE_TICKET_DESCRIPTION': 'This is a form for creating tickets. Fill the form and send us your issues/doubts/suggestions. Our support system will answer it as soon as possible.', @@ -88,6 +92,7 @@ export default { 'NEW_TICKETS_DESCRIPTION': 'Here you can view all the new tickets that are not assigned by anyone.', 'ALL_TICKETS_DESCRIPTION': 'Here you can view the tickets of the departments you are assigned.', 'TICKET_VIEW_DESCRIPTION': 'This ticket has been sent by a customer. Here you can respond or assign the ticket', + 'BAN_USERS_DESCRIPTION': 'Here you can see a list of banned emails, you can un-ban them or add more emails to the list.', //ERRORS 'EMAIL_OR_PASSWORD': 'Email or password invalid', From 7f94773abbeb2edf28395d9d971d0be03f70f884 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 29 Nov 2016 19:51:37 -0300 Subject: [PATCH 2/2] Ivan - Fix conflicts [skip ci] --- client/src/app/admin/panel/users/admin-panel-ban-users.js | 2 +- client/src/data/languages/en.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/app/admin/panel/users/admin-panel-ban-users.js b/client/src/app/admin/panel/users/admin-panel-ban-users.js index 328fcec2..a368eeaf 100644 --- a/client/src/app/admin/panel/users/admin-panel-ban-users.js +++ b/client/src/app/admin/panel/users/admin-panel-ban-users.js @@ -29,7 +29,7 @@ class AdminPanelBanUsers extends React.Component {
- +
diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index 58fe1a1f..da5706d9 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -82,8 +82,9 @@ export default { 'NAME': 'Name', 'SIGNUP_DATE': 'Sign up date', 'SEARCH_USERS': 'Search users...', + 'SEARCH_EMAIL': 'Search email...', 'USER_VIEW_TITLE': 'User #{userId}', - + //VIEW DESCRIPTIONS 'CREATE_TICKET_DESCRIPTION': 'This is a form for creating tickets. Fill the form and send us your issues/doubts/suggestions. Our support system will answer it as soon as possible.', 'TICKET_LIST_DESCRIPTION': 'Here you can find a list of all tickets you have sent to our support team.',