From da41adeacf8d1df66a607a4f4c1263405a541432 Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Tue, 6 Feb 2018 17:32:15 +0100 Subject: [PATCH 1/7] Use new input lib in AuthPage container --- .../lib/src/components/InputsIndex/index.js | 3 +- .../admin/src/containers/AuthPage/form.json | 44 ++++++++++++++----- .../admin/src/containers/AuthPage/index.js | 4 +- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js b/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js index 3a7d75defc..44b6c60816 100644 --- a/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js @@ -32,8 +32,9 @@ const inputs = { function InputsIndex(props) { const Input = inputs[props.type] ? inputs[props.type] : DefaultInputError; + const inputValue = props.value || ''; - return ; + return ; } InputsIndex.propTypes = { diff --git a/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/form.json b/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/form.json index a286de0f76..433c9dd564 100644 --- a/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/form.json +++ b/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/form.json @@ -3,7 +3,9 @@ "forgot-password": [ { "customBootstrapClass": "col-md-12", - "label": "users-permissions.Auth.form.forgot-password.email.label", + "label": { + "id": "users-permissions.Auth.form.forgot-password.email.label" + }, "name": "email", "type": "email", "placeholder": "users-permissions.Auth.form.forgot-password.email.placeholder" @@ -12,20 +14,26 @@ "login": [ { "customBootstrapClass": "col-md-12", - "label": "users-permissions.Auth.form.login.username.label", + "label": { + "id": "users-permissions.Auth.form.login.username.label" + }, "name": "identifier", "type": "text", "placeholder": "users-permissions.Auth.form.login.username.placeholder" }, { "customBootstrapClass": "col-md-12", - "label": "users-permissions.Auth.form.login.password.label", + "label": { + "id": "users-permissions.Auth.form.login.password.label" + }, "name": "password", "type": "password" }, { "customBootstrapClass": "col-md-6", - "label": "users-permissions.Auth.form.login.rememberMe.label", + "label": { + "id": "users-permissions.Auth.form.login.rememberMe.label" + }, "name": "rememberMe", "type": "checkbox" } @@ -33,26 +41,34 @@ "register": [ { "customBootstrapClass": "col-md-12", - "label": "users-permissions.Auth.form.register.username.label", + "label": { + "id": "users-permissions.Auth.form.register.username.label" + }, "name": "username", "type": "text", "placeholder": "users-permissions.Auth.form.register.username.placeholder" }, { "customBootstrapClass": "col-md-12", - "label": "users-permissions.Auth.form.register.password.label", + "label": { + "id": "users-permissions.Auth.form.register.password.label" + }, "name": "password", "type": "password" }, { "customBootstrapClass": "col-md-12", - "label": "users-permissions.Auth.form.register.confirmPassword.label", + "label": { + "id": "users-permissions.Auth.form.register.confirmPassword.label" + }, "name": "confirmPassword", "type": "password" }, { "customBootstrapClass": "col-md-12", - "label": "users-permissions.Auth.form.register.email.label", + "label": { + "id": "users-permissions.Auth.form.register.email.label" + }, "name": "email", "placeholder": "users-permissions.Auth.form.register.email.placeholder", "type": "email" @@ -63,7 +79,9 @@ "customBootstrapClass": "col-md-12", "name": "email", "type": "email", - "label": "users-permissions.Auth.form.register-success.email.label", + "label": { + "id": "users-permissions.Auth.form.register-success.email.label" + }, "placeholder": "users-permissions.Auth.form.register-success.email.placeholder" } ], @@ -72,13 +90,17 @@ "customBootstrapClass": "col-md-12", "name": "password", "type": "password", - "label": "users-permissions.Auth.form.register.password.label" + "label": { + "id": "users-permissions.Auth.form.register.password.label" + } }, { "customBootstrapClass": "col-md-12", "name": "passwordConfirmation", "type": "password", - "label": "users-permissions.Auth.form.register.confirmPassword.label" + "label": { + "id": "users-permissions.Auth.form.register.confirmPassword.label" + } } ] } diff --git a/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/index.js b/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/index.js index b8baa3e3ba..a315953588 100644 --- a/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/index.js +++ b/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/index.js @@ -18,7 +18,7 @@ import LogoStrapi from 'assets/images/logo_strapi.png'; // Design import Button from 'components/Button'; -import Input from 'components/Input'; +import Input from 'components/InputsIndex'; // Utils import injectSaga from 'utils/injectSaga'; @@ -142,7 +142,7 @@ export class AuthPage extends React.Component { // eslint-disable-line react/pre const headerDescription = this.props.match.params.authType === 'register' ? : ; - + return (
From 8a2d5cf8e6500aeb98ca4423b377fbee34edf19b Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Tue, 6 Feb 2018 17:47:50 +0100 Subject: [PATCH 2/7] Fix label succes email sent --- .../admin/src/containers/AuthPage/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/index.js b/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/index.js index a315953588..819589cf2b 100644 --- a/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/index.js +++ b/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/index.js @@ -173,7 +173,7 @@ export class AuthPage extends React.Component { // eslint-disable-line react/pre didCheckErrors={this.props.didCheckErrors} errors={get(this.props.formErrors, [findIndex(this.props.formErrors, ['name', input.name]), 'errors'])} key={get(input, 'name')} - label={this.props.match.params.authType === 'forgot-password' && this.props.submitSuccess? 'users-permissions.Auth.form.forgot-password.email.label.success' : get(input, 'label')} + label={this.props.match.params.authType === 'forgot-password' && this.props.submitSuccess? { id: 'users-permissions.Auth.form.forgot-password.email.label.success' } : get(input, 'label')} name={get(input, 'name')} onChange={this.props.onChangeInput} placeholder={get(input, 'placeholder')} From 5002dd43ab0c462cbe40db03cb5575daaa7c5aeb Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Tue, 6 Feb 2018 17:59:06 +0100 Subject: [PATCH 3/7] Rename custome InputCheckbox I ran into an issue with webpack which chould get the appropriate file beacsue of conflicting between components from the strapi-helper-plugin and components from the plugin itself. Had to rename this file in order to solve the bug --- .../lib/src/components/InputsIndex/index.js | 2 +- .../admin/src/components/Controller/index.js | 2 +- .../src/components/InputCheckbox/index.js | 115 ------------------ .../src/components/InputCheckbox/styles.scss | 58 --------- 4 files changed, 2 insertions(+), 175 deletions(-) delete mode 100644 packages/strapi-plugin-users-permissions/admin/src/components/InputCheckbox/index.js delete mode 100644 packages/strapi-plugin-users-permissions/admin/src/components/InputCheckbox/styles.scss diff --git a/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js b/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js index 47503c68eb..4fbbf753e4 100644 --- a/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js @@ -34,7 +34,7 @@ const inputs = { function InputsIndex(props) { const Input = inputs[props.type] ? inputs[props.type] : DefaultInputError; - const inputValue = props.value || ''; + const inputValue = props.type === 'checkbox' ? props.value || false : props.value || ''; return ; } diff --git a/packages/strapi-plugin-users-permissions/admin/src/components/Controller/index.js b/packages/strapi-plugin-users-permissions/admin/src/components/Controller/index.js index a25fb1af57..8d8dc7cb64 100644 --- a/packages/strapi-plugin-users-permissions/admin/src/components/Controller/index.js +++ b/packages/strapi-plugin-users-permissions/admin/src/components/Controller/index.js @@ -10,7 +10,7 @@ import { get, map, some } from 'lodash'; import cn from 'classnames'; import { FormattedMessage } from 'react-intl'; -import InputCheckbox from 'components/InputCheckbox'; +import InputCheckbox from 'components/InputCheckboxPlugin'; import styles from './styles.scss'; class Controller extends React.Component { diff --git a/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckbox/index.js b/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckbox/index.js deleted file mode 100644 index 0c68f53240..0000000000 --- a/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckbox/index.js +++ /dev/null @@ -1,115 +0,0 @@ -/** -* -* InputCheckbox -* -*/ - -import React from 'react'; -import PropTypes from 'prop-types'; -import cn from 'classnames'; - -import styles from './styles.scss'; - -class InputCheckbox extends React.Component { // eslint-disable-line react/prefer-stateless-function - state = { showBackground: false, showCog: false }; - - componentWillReceiveProps(nextProps) { - // Remove background if another input is selected - if (nextProps.inputSelected !== this.props.inputSelected && nextProps.inputSelected !== this.props.name) { - this.setState({ showBackground: false }); - } - - if (!nextProps.isOpen) { - this.setState({ showBackground: false, showCog: false }); - } - } - - handleChange = () => { - const target = { - type: 'checkbox', - name: this.props.name, - value: !this.props.value, - }; - - // Don't show the label background if the user unselects the input - if (!this.props.value) { - this.setState({ showBackground: true }); - // Tell the Parent component that another input has been selected - this.props.setNewInputSelected(this.props.name); - // Tell the policies component to show the associated routes - this.context.setShouldDisplayPolicieshint(); - this.context.setInputPoliciesPath(this.props.name); - } else { - this.setState({ showBackground: false, showCog: false }); - this.props.setNewInputSelected(''); - } - - this.context.onChange({ target }); - } - - handleClick = () => { - this.setState({ showBackground: !this.state.showBackground }); - this.props.setNewInputSelected(this.props.name); - this.context.setInputPoliciesPath(this.props.name); - - if (this.state.showBackground) { - this.context.resetShouldDisplayPoliciesHint(); - } else { - this.context.setShouldDisplayPolicieshint(); - } - } - - render() { - return ( -
{ - if (this.props.value) { - this.setState({ showCog: true }); - } - }} - onMouseLeave={() => this.setState({ showCog: false })} - > -
- - {this.state.showCog || this.state.showBackground ? ( - - ) : ''} -
-
- ); - } -} - -InputCheckbox.contextTypes = { - onChange: PropTypes.func.isRequired, - resetShouldDisplayPoliciesHint: PropTypes.func.isRequired, - setInputPoliciesPath: PropTypes.func.isRequired, - setShouldDisplayPolicieshint: PropTypes.func.isRequired, -}; - -InputCheckbox.defaultProps = { - label: '', - value: false, -}; - -InputCheckbox.propTypes = { - inputSelected: PropTypes.string.isRequired, - isOpen: PropTypes.bool.isRequired, - label: PropTypes.string, - name: PropTypes.string.isRequired, - setNewInputSelected: PropTypes.func.isRequired, - value: PropTypes.bool, -}; - -export default InputCheckbox; diff --git a/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckbox/styles.scss b/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckbox/styles.scss deleted file mode 100644 index 040dd8f601..0000000000 --- a/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckbox/styles.scss +++ /dev/null @@ -1,58 +0,0 @@ -.inputCheckbox { - margin-bottom: .5rem; - padding-left: 0; - font-size: 13px; - - > div { - height: 26px; - padding-left: 15px; - line-height: 26px; - - > i { - position: absolute; - top: 8px; - right: 10px; - color: #787E8F; - cursor: pointer; - } - } -} - -.label { - margin-left: 9px; - cursor: pointer; - > input { - display: none; - margin-right: 9px; - } - - &:before { - content: ''; - position: absolute; - left:15px; top: 6px; - width: 14px; height: 14px; - border: 1px solid rgba(16,22,34,0.15); - background-color: #FDFDFD; - border-radius: 3px; - } -} - -.checked { - &:after { - content: '\f00c'; - position: absolute; - top: 0; left: 17px; - font-size: 10px; - font-family: 'FontAwesome'; - font-weight: 100; - color: #1C5DE7; - transition: all .2s; - - } -} - -.highlighted { - border-radius: 3px; - background-color: #E9EAEB; - font-weight: 600; -} From 9740ab3869b333b90959b1538db49edd22a23133 Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Tue, 6 Feb 2018 18:01:44 +0100 Subject: [PATCH 4/7] Rename custome InputCheckbox I ran into an issue with webpack which chould get the appropriate file beacsue of conflicting between components from the strapi-helper-plugin and components from the plugin itself. Had to rename this file in order to solve the bug --- .../components/InputCheckboxPlugin/index.js | 115 ++++++++++++++++++ .../InputCheckboxPlugin/styles.scss | 58 +++++++++ 2 files changed, 173 insertions(+) create mode 100644 packages/strapi-plugin-users-permissions/admin/src/components/InputCheckboxPlugin/index.js create mode 100644 packages/strapi-plugin-users-permissions/admin/src/components/InputCheckboxPlugin/styles.scss diff --git a/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckboxPlugin/index.js b/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckboxPlugin/index.js new file mode 100644 index 0000000000..7962b3babf --- /dev/null +++ b/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckboxPlugin/index.js @@ -0,0 +1,115 @@ +/** +* +* InputCheckboxPlugin +* +*/ + +import React from 'react'; +import PropTypes from 'prop-types'; +import cn from 'classnames'; + +import styles from './styles.scss'; + +class InputCheckboxPlugin extends React.Component { // eslint-disable-line react/prefer-stateless-function + state = { showBackground: false, showCog: false }; + + componentWillReceiveProps(nextProps) { + // Remove background if another input is selected + if (nextProps.inputSelected !== this.props.inputSelected && nextProps.inputSelected !== this.props.name) { + this.setState({ showBackground: false }); + } + + if (!nextProps.isOpen) { + this.setState({ showBackground: false, showCog: false }); + } + } + + handleChange = () => { + const target = { + type: 'checkbox', + name: this.props.name, + value: !this.props.value, + }; + + // Don't show the label background if the user unselects the input + if (!this.props.value) { + this.setState({ showBackground: true }); + // Tell the Parent component that another input has been selected + this.props.setNewInputSelected(this.props.name); + // Tell the policies component to show the associated routes + this.context.setShouldDisplayPolicieshint(); + this.context.setInputPoliciesPath(this.props.name); + } else { + this.setState({ showBackground: false, showCog: false }); + this.props.setNewInputSelected(''); + } + + this.context.onChange({ target }); + } + + handleClick = () => { + this.setState({ showBackground: !this.state.showBackground }); + this.props.setNewInputSelected(this.props.name); + this.context.setInputPoliciesPath(this.props.name); + + if (this.state.showBackground) { + this.context.resetShouldDisplayPoliciesHint(); + } else { + this.context.setShouldDisplayPolicieshint(); + } + } + + render() { + return ( +
{ + if (this.props.value) { + this.setState({ showCog: true }); + } + }} + onMouseLeave={() => this.setState({ showCog: false })} + > +
+ + {this.state.showCog || this.state.showBackground ? ( + + ) : ''} +
+
+ ); + } +} + +InputCheckboxPlugin.contextTypes = { + onChange: PropTypes.func.isRequired, + resetShouldDisplayPoliciesHint: PropTypes.func.isRequired, + setInputPoliciesPath: PropTypes.func.isRequired, + setShouldDisplayPolicieshint: PropTypes.func.isRequired, +}; + +InputCheckboxPlugin.defaultProps = { + label: '', + value: false, +}; + +InputCheckboxPlugin.propTypes = { + inputSelected: PropTypes.string.isRequired, + isOpen: PropTypes.bool.isRequired, + label: PropTypes.string, + name: PropTypes.string.isRequired, + setNewInputSelected: PropTypes.func.isRequired, + value: PropTypes.bool, +}; + +export default InputCheckboxPlugin; diff --git a/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckboxPlugin/styles.scss b/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckboxPlugin/styles.scss new file mode 100644 index 0000000000..040dd8f601 --- /dev/null +++ b/packages/strapi-plugin-users-permissions/admin/src/components/InputCheckboxPlugin/styles.scss @@ -0,0 +1,58 @@ +.inputCheckbox { + margin-bottom: .5rem; + padding-left: 0; + font-size: 13px; + + > div { + height: 26px; + padding-left: 15px; + line-height: 26px; + + > i { + position: absolute; + top: 8px; + right: 10px; + color: #787E8F; + cursor: pointer; + } + } +} + +.label { + margin-left: 9px; + cursor: pointer; + > input { + display: none; + margin-right: 9px; + } + + &:before { + content: ''; + position: absolute; + left:15px; top: 6px; + width: 14px; height: 14px; + border: 1px solid rgba(16,22,34,0.15); + background-color: #FDFDFD; + border-radius: 3px; + } +} + +.checked { + &:after { + content: '\f00c'; + position: absolute; + top: 0; left: 17px; + font-size: 10px; + font-family: 'FontAwesome'; + font-weight: 100; + color: #1C5DE7; + transition: all .2s; + + } +} + +.highlighted { + border-radius: 3px; + background-color: #E9EAEB; + font-weight: 600; +} From 5b27933d66a5218169fd389f68ea41f8c89ce25c Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Tue, 6 Feb 2018 18:14:30 +0100 Subject: [PATCH 5/7] Add new input lib to EditPage container --- .../lib/src/components/InputsIndex/index.js | 2 +- .../admin/src/containers/EditPage/index.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js b/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js index 4fbbf753e4..b929abd9d2 100644 --- a/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/InputsIndex/index.js @@ -34,7 +34,7 @@ const inputs = { function InputsIndex(props) { const Input = inputs[props.type] ? inputs[props.type] : DefaultInputError; - const inputValue = props.type === 'checkbox' ? props.value || false : props.value || ''; + const inputValue = props.type === 'checkbox' || props.type === 'toggle' ? props.value || false : props.value || ''; return ; } diff --git a/packages/strapi-plugin-users-permissions/admin/src/containers/EditPage/index.js b/packages/strapi-plugin-users-permissions/admin/src/containers/EditPage/index.js index 621594bc30..fa4e06ff01 100644 --- a/packages/strapi-plugin-users-permissions/admin/src/containers/EditPage/index.js +++ b/packages/strapi-plugin-users-permissions/admin/src/containers/EditPage/index.js @@ -15,7 +15,7 @@ import cn from 'classnames'; // Design import BackHeader from 'components/BackHeader'; -import Input from 'components/Input'; +import Input from 'components/InputsIndex'; import InputSearch from 'components/InputSearch'; import PluginHeader from 'components/PluginHeader'; import Plugins from 'components/Plugins'; @@ -159,7 +159,7 @@ export class EditPage extends React.Component { // eslint-disable-line react/pre customBootstrapClass="col-md-12" errors={get(this.props.editPage, ['formErrors', findIndex(this.props.editPage.formErrors, ['name', 'name']), 'errors'])} didCheckErrors={this.props.editPage.didCheckErrors} - label="users-permissions.EditPage.form.roles.label.name" + label={{ id: 'users-permissions.EditPage.form.roles.label.name' }} name="name" onChange={this.props.onChangeInput} type="text" @@ -170,7 +170,7 @@ export class EditPage extends React.Component { // eslint-disable-line react/pre
Date: Tue, 6 Feb 2018 18:42:42 +0100 Subject: [PATCH 6/7] Implement new lib input in EditPage container Use Label component in InputSearchContainer. Add new Inputselect in Policies component --- .../index.js | 32 ++++++++++++------- .../styles.scss | 11 +++++++ .../admin/src/components/Policies/index.js | 4 +-- .../admin/src/containers/EditPage/index.js | 10 ++++-- 4 files changed, 40 insertions(+), 17 deletions(-) rename packages/strapi-plugin-users-permissions/admin/src/components/{InputSearch => InputSearchContainer}/index.js (79%) rename packages/strapi-plugin-users-permissions/admin/src/components/{InputSearch => InputSearchContainer}/styles.scss (91%) diff --git a/packages/strapi-plugin-users-permissions/admin/src/components/InputSearch/index.js b/packages/strapi-plugin-users-permissions/admin/src/components/InputSearchContainer/index.js similarity index 79% rename from packages/strapi-plugin-users-permissions/admin/src/components/InputSearch/index.js rename to packages/strapi-plugin-users-permissions/admin/src/components/InputSearchContainer/index.js index 76cd8e19da..e663988892 100644 --- a/packages/strapi-plugin-users-permissions/admin/src/components/InputSearch/index.js +++ b/packages/strapi-plugin-users-permissions/admin/src/components/InputSearchContainer/index.js @@ -1,6 +1,6 @@ /** * -* InputSearch +* InputSearchContainer * */ @@ -10,15 +10,17 @@ import { findIndex, has, includes, isEmpty, map, toLower } from 'lodash'; import cn from 'classnames'; import PropTypes from 'prop-types'; +import Label from 'components/Label'; import InputSearchLi from 'components/InputSearchLi'; import styles from './styles.scss'; -class InputSearch extends React.Component { // eslint-disable-line react/prefer-stateless-function +class InputSearchContainer extends React.Component { // eslint-disable-line react/prefer-stateless-function state = { errors: [], filteredUsers: this.props.values, isAdding: false, + isFocused: false, users: this.props.values, value: '', autoFocus: false, @@ -38,6 +40,8 @@ class InputSearch extends React.Component { // eslint-disable-line react/prefer- } } + handleBlur = () => this.setState({ isFocused: !this.state.isFocused }); + handleChange = ({ target }) => { const filteredUsers = isEmpty(target.value) ? this.state.users @@ -54,6 +58,8 @@ class InputSearch extends React.Component { // eslint-disable-line react/prefer- this.setState({ value: target.value, filteredUsers }); } + handleFocus = () => this.setState({ isFocused: !this.state.isFocused }); + handleClick = (item) => { if (this.state.isAdding) { const id = has(item, '_id') ? '_id' : 'id'; @@ -76,18 +82,18 @@ class InputSearch extends React.Component { // eslint-disable-line react/prefer- render() { return (
- +