Skip to content

Commit

Permalink
Merge 59bbd18 into 53b34ea
Browse files Browse the repository at this point in the history
  • Loading branch information
InsidersByte committed Apr 4, 2017
2 parents 53b34ea + 59bbd18 commit c1f67a2
Show file tree
Hide file tree
Showing 9 changed files with 408 additions and 137 deletions.
65 changes: 0 additions & 65 deletions public/actions/users.js

This file was deleted.

19 changes: 0 additions & 19 deletions public/constants/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,6 @@ export const PASSWORD_RESET_REQUEST = 'PASSWORD_RESET_REQUEST';
export const PASSWORD_RESET_SUCCESS = 'PASSWORD_RESET_SUCCESS';
export const PASSWORD_RESET_ERROR = 'PASSWORD_RESET_ERROR';

export const OPEN_USER_MODAL = 'OPEN_USER_MODAL';
export const CLOSE_USER_MODAL = 'CLOSE_USER_MODAL';

export const LOAD_USERS_REQUEST = 'LOAD_USERS_REQUEST';
export const LOAD_USERS_SUCCESS = 'LOAD_USERS_SUCCESS';
export const LOAD_USERS_ERROR = 'LOAD_USERS_ERROR';

export const CREATE_USER_REQUEST = 'CREATE_USER_REQUEST';
export const CREATE_USER_SUCCESS = 'CREATE_USER_SUCCESS';
export const CREATE_USER_ERROR = 'CREATE_USER_ERROR';

export const DELETE_USER_REQUEST = 'DELETE_USER_REQUEST';
export const DELETE_USER_SUCCESS = 'DELETE_USER_SUCCESS';
export const DELETE_USER_ERROR = 'DELETE_USER_ERROR';

export const CHANGE_PASSWORD_REQUEST = 'CHANGE_PASSWORD_REQUEST';
export const CHANGE_PASSWORD_SUCCESS = 'CHANGE_PASSWORD_SUCCESS';
export const CHANGE_PASSWORD_ERROR = 'CHANGE_PASSWORD_ERROR';

export const LOAD_WEDDING_PROFILE_REQUEST = 'LOAD_WEDDING_PROFILE_REQUEST';
export const LOAD_WEDDING_PROFILE_SUCCESS = 'LOAD_WEDDING_PROFILE_SUCCESS';
export const LOAD_WEDDING_PROFILE_ERROR = 'LOAD_WEDDING_PROFILE_ERROR';
Expand Down
2 changes: 1 addition & 1 deletion public/containers/ProfilePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as userActions from '../actions/users';
import * as userActions from '../redux/users';
import * as notificationActions from '../redux/notifications';
import ProfileForm from '../components/ProfileForm';
import { MINIMUM_PASSWORD_LENGTH, MINIMUM_PASSWORD_MESSAGE, MATCHING_PASSWORD_MESSAGE } from '../constants';
Expand Down
2 changes: 1 addition & 1 deletion public/containers/UsersPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as actions from '../actions/users';
import * as actions from '../redux/users';
import UserList from '../components/UserList';
import User from '../components/UserDialog';

Expand Down
49 changes: 0 additions & 49 deletions public/reducers/users.js

This file was deleted.

2 changes: 1 addition & 1 deletion public/redux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { combineReducers } from 'redux';
import auth from '../reducers/auth';
import users from '../reducers/users';
import users from './users';
import notifications from './notifications';
import weddingProfile from '../reducers/weddingProfile';
import signUp from '../reducers/signUp';
Expand Down
133 changes: 133 additions & 0 deletions public/redux/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// @flow

import { combineReducers } from 'redux';
import { success } from './notifications';
import { CALL_API } from '../middleware/api';
import { HTTP_METHODS } from '../constants/api';
import type { ActionType, UsersType, UserType } from '../types';

const OPEN_USER_MODAL = 'our-wedding-heroes/users/OPEN_USER_MODAL';
const CLOSE_USER_MODAL = 'our-wedding-heroes/users/CLOSE_USER_MODAL';
const LOAD_USERS_REQUEST = 'our-wedding-heroes/users/LOAD_USERS_REQUEST';
const LOAD_USERS_SUCCESS = 'our-wedding-heroes/users/LOAD_USERS_SUCCESS';
const LOAD_USERS_ERROR = 'our-wedding-heroes/users/LOAD_USERS_ERROR';
const CREATE_USER_REQUEST = 'our-wedding-heroes/users/CREATE_USER_REQUEST';
const CREATE_USER_SUCCESS = 'our-wedding-heroes/users/CREATE_USER_SUCCESS';
const CREATE_USER_ERROR = 'our-wedding-heroes/users/CREATE_USER_ERROR';
const DELETE_USER_REQUEST = 'our-wedding-heroes/users/DELETE_USER_REQUEST';
const DELETE_USER_SUCCESS = 'our-wedding-heroes/users/DELETE_USER_SUCCESS';
const DELETE_USER_ERROR = 'our-wedding-heroes/users/DELETE_USER_ERROR';
const CHANGE_PASSWORD_REQUEST = 'our-wedding-heroes/users/CHANGE_PASSWORD_REQUEST';
const CHANGE_PASSWORD_SUCCESS = 'our-wedding-heroes/users/CHANGE_PASSWORD_SUCCESS';
const CHANGE_PASSWORD_ERROR = 'our-wedding-heroes/users/CHANGE_PASSWORD_ERROR';

const userModalOpen = (state: boolean = false, action: ActionType) => {
switch (action.type) {
case OPEN_USER_MODAL:
return true;
case CLOSE_USER_MODAL:
return false;
default:
return state;
}
};

const loading = (state: boolean = false, action: ActionType) => {
switch (action.type) {
case LOAD_USERS_REQUEST:
return true;
case LOAD_USERS_SUCCESS:
case LOAD_USERS_ERROR:
return false;
default:
return state;
}
};

const saving = (state: boolean = false, action: ActionType) => {
switch (action.type) {
case CREATE_USER_REQUEST:
return true;
case CREATE_USER_SUCCESS:
case CREATE_USER_ERROR:
return false;
default:
return state;
}
};

const deleting = (state: boolean = false, action: ActionType) => {
switch (action.type) {
case DELETE_USER_REQUEST:
return true;
case DELETE_USER_SUCCESS:
case DELETE_USER_ERROR:
return false;
default:
return state;
}
};

const users = (state: UsersType = [], action: ActionType) => {
switch (action.type) {
case LOAD_USERS_SUCCESS:
return action.payload;
default:
return state;
}
};

export default combineReducers({ userModalOpen, loading, saving, deleting, users });

export const openUserModal = (): ActionType => ({ type: OPEN_USER_MODAL });
export const closeUserModal = (): ActionType => ({ type: CLOSE_USER_MODAL });

export const loadUsers = () => ({
[CALL_API]: {
endpoint: 'user',
method: HTTP_METHODS.GET,
authenticated: true,
types: [LOAD_USERS_REQUEST, LOAD_USERS_SUCCESS, LOAD_USERS_ERROR],
},
});

export const createUser = (user: UserType) => ({
[CALL_API]: {
data: user,
endpoint: 'user',
method: HTTP_METHODS.POST,
authenticated: true,
onSuccess: dispatch => {
dispatch(success({ message: 'User created successfully' }));
dispatch(closeUserModal());
},
types: [CREATE_USER_REQUEST, CREATE_USER_SUCCESS, CREATE_USER_ERROR],
},
});

export const deleteUser = (user: UserType) => ({
[CALL_API]: {
data: user,
endpoint: `user/${user.id}`,
method: HTTP_METHODS.DELETE,
authenticated: true,
onSuccess: dispatch => {
dispatch(success({ message: 'User deleted successfully' }));
},
types: [DELETE_USER_REQUEST, DELETE_USER_SUCCESS, DELETE_USER_ERROR],
},
});

// TODO: extract to profile
export const changePassword = (user: UserType) => ({
[CALL_API]: {
data: user,
endpoint: 'user/password',
method: HTTP_METHODS.PUT,
authenticated: true,
onSuccess: dispatch => {
dispatch(success({ message: 'Password Changed' }));
},
types: [CHANGE_PASSWORD_REQUEST, CHANGE_PASSWORD_SUCCESS, CHANGE_PASSWORD_ERROR],
},
});
Loading

0 comments on commit c1f67a2

Please sign in to comment.