Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

People: Normalize invite create validations in the reducer #3293

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion client/lib/invites/reducers/invites-create-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import { fromJS } from 'immutable';
*/
import { action as ActionTypes } from 'lib/invites/constants';

function normalizeSuccessValidations( validations ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could move it to where RECEIVE_CREATE_INVITE_VALIDATION_SUCCESS is dispatched.

if ( Array.isArray( validations ) ) {
return validations;
}

// Since success validations can be returned from the API as an object,
// let's normalize these so that we store an array.
return Object.keys( validations ).map( key => validations[ key ] );
}

const initialState = fromJS( {
success: {},
errors: {}
Expand All @@ -18,7 +28,7 @@ const reducer = ( state = initialState, payload ) => {
switch ( action.type ) {
case ActionTypes.RECEIVE_CREATE_INVITE_VALIDATION_SUCCESS:
return state
.setIn( [ 'success', action.siteId, action.role ], action.data.success )
.setIn( [ 'success', action.siteId, action.role ], normalizeSuccessValidations( action.data.success ) )
.setIn( [ 'errors', action.siteId, action.role ], action.data.errors );
}
return state;
Expand Down
3 changes: 0 additions & 3 deletions client/my-sites/people/invite-people/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ export default React.createClass( {
refreshValidation() {
const errors = InvitesCreateValidationStore.getErrors( this.props.site.ID, this.state.role ) || [];
let success = InvitesCreateValidationStore.getSuccess( this.props.site.ID, this.state.role ) || [];
if ( ! success.indexOf ) {
success = Object.keys( success ).map( key => success[ key ] );
}

this.setState( {
errors,
Expand Down