From 90bb012ab82cbf3ee95df6f58f4c561f3b61d0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Tue, 13 Nov 2018 16:30:43 -0500 Subject: [PATCH] Move EditUserModal fields into an ItemList to make more extendable (#1593) --- .../js/src/forum/components/EditUserModal.js | 150 ++++++++++-------- 1 file changed, 81 insertions(+), 69 deletions(-) diff --git a/framework/core/js/src/forum/components/EditUserModal.js b/framework/core/js/src/forum/components/EditUserModal.js index 81b61dcc1..99f43a517 100644 --- a/framework/core/js/src/forum/components/EditUserModal.js +++ b/framework/core/js/src/forum/components/EditUserModal.js @@ -3,6 +3,7 @@ import Button from '../../common/components/Button'; import GroupBadge from '../../common/components/GroupBadge'; import Group from '../../common/models/Group'; import extractText from '../../common/utils/extractText'; +import ItemList from '../../common/utils/ItemList'; /** * The `EditUserModal` component displays a modal dialog with a login form. @@ -37,80 +38,91 @@ export default class EditUserModal extends Modal { return (
-
- - -
- - {app.session.user !== this.props.user ? [ -
- -
- -
- {!this.isEmailConfirmed() ? ( -
- {Button.component({ - className: 'Button Button--block', - children: app.translator.trans('core.forum.edit_user.activate_button'), - loading: this.loading, - onclick: this.activate.bind(this) - })} -
- ) : ''} -
, - -
- -
- - {this.setPassword() ? ( - - ) : ''} -
-
- ] : ''} - -
- -
- {Object.keys(this.groups) - .map(id => app.store.getById('groups', id)) - .map(group => ( - - ))} -
-
- -
- {Button.component({ - className: 'Button Button--primary', - type: 'submit', - loading: this.loading, - children: app.translator.trans('core.forum.edit_user.submit_button') - })} -
+ {this.fields().toArray()}
); } + fields() { + const items = new ItemList(); + + items.add('username',
+ + +
, 40); + + if (app.session.user !== this.props.user) { + items.add('email',
+ +
+ +
+ {!this.isEmailConfirmed() ? ( +
+ {Button.component({ + className: 'Button Button--block', + children: app.translator.trans('core.forum.edit_user.activate_button'), + loading: this.loading, + onclick: this.activate.bind(this) + })} +
+ ) : ''} +
, 30); + + items.add('password',
+ +
+ + {this.setPassword() ? ( + + ) : ''} +
+
, 20); + + } + + items.add('groups',
+ +
+ {Object.keys(this.groups) + .map(id => app.store.getById('groups', id)) + .map(group => ( + + ))} +
+
, 10); + + items.add('submit',
+ {Button.component({ + className: 'Button Button--primary', + type: 'submit', + loading: this.loading, + children: app.translator.trans('core.forum.edit_user.submit_button') + })} +
, -10); + + return items; + } + activate() { this.loading = true; const data = {