2017-11-07 14:32:31 +01:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* EditPage actions
|
|
|
|
|
*
|
|
|
|
|
*/
|
2017-11-15 15:11:10 +01:00
|
|
|
import { fromJS, List, Map } from 'immutable';
|
2017-11-20 14:21:08 +01:00
|
|
|
import { get } from 'lodash';
|
2017-11-07 14:32:31 +01:00
|
|
|
import {
|
2017-11-07 18:16:42 +01:00
|
|
|
ADD_USER,
|
2017-11-15 15:11:10 +01:00
|
|
|
GET_PERMISSIONS,
|
|
|
|
|
GET_PERMISSIONS_SUCCEEDED,
|
2017-11-15 14:00:51 +01:00
|
|
|
GET_ROLE,
|
|
|
|
|
GET_ROLE_SUCCEEDED,
|
2017-11-23 12:43:40 +01:00
|
|
|
GET_USER,
|
|
|
|
|
GET_USER_SUCCEEDED,
|
2017-11-07 16:33:15 +01:00
|
|
|
ON_CANCEL,
|
|
|
|
|
ON_CHANGE_INPUT,
|
2017-11-23 13:09:05 +01:00
|
|
|
ON_CLICK_ADD,
|
2017-11-07 18:16:42 +01:00
|
|
|
ON_CLICK_DELETE,
|
2017-11-23 12:15:06 +01:00
|
|
|
SET_ACTION_TYPE,
|
|
|
|
|
SET_ERRORS,
|
2017-11-15 14:00:51 +01:00
|
|
|
SET_FORM,
|
2017-11-23 12:15:06 +01:00
|
|
|
SUBMIT,
|
|
|
|
|
SUBMIT_ERROR,
|
|
|
|
|
SUBMIT_SUCCEEDED,
|
2017-11-07 14:32:31 +01:00
|
|
|
} from './constants';
|
|
|
|
|
|
2017-11-07 18:16:42 +01:00
|
|
|
export function addUser(newUser) {
|
|
|
|
|
return {
|
|
|
|
|
type: ADD_USER,
|
|
|
|
|
newUser,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 15:11:10 +01:00
|
|
|
export function getPermissions() {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_PERMISSIONS,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getPermissionsSucceeded(data) {
|
|
|
|
|
const permissions = Map(fromJS(data.permissions));
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: GET_PERMISSIONS_SUCCEEDED,
|
|
|
|
|
permissions,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getRole(id) {
|
2017-11-15 14:00:51 +01:00
|
|
|
return {
|
|
|
|
|
type: GET_ROLE,
|
2017-11-15 15:11:10 +01:00
|
|
|
id,
|
2017-11-15 14:00:51 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getRoleSucceeded(data) {
|
2017-11-15 15:11:10 +01:00
|
|
|
const form = Map({
|
|
|
|
|
name: get(data, ['role', 'name']),
|
|
|
|
|
description: get(data, ['role', 'description']),
|
|
|
|
|
users: List(get(data, ['role', 'users'])),
|
|
|
|
|
permissions: Map(fromJS(get(data, ['role', 'permissions']))),
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-15 14:00:51 +01:00
|
|
|
return {
|
|
|
|
|
type: GET_ROLE_SUCCEEDED,
|
2017-11-15 15:11:10 +01:00
|
|
|
form,
|
2017-11-15 14:00:51 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 12:43:40 +01:00
|
|
|
export function getUser(user) {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_USER,
|
|
|
|
|
user,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getUserSucceeded(users) {
|
|
|
|
|
return {
|
|
|
|
|
type: GET_USER_SUCCEEDED,
|
|
|
|
|
users,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
export function onCancel() {
|
2017-11-07 14:32:31 +01:00
|
|
|
return {
|
2017-11-07 16:33:15 +01:00
|
|
|
type: ON_CANCEL,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function onChangeInput({ target }) {
|
2017-11-20 14:21:08 +01:00
|
|
|
const keys = ['modifiedData'].concat(target.name.split('.'));
|
|
|
|
|
|
2017-11-07 16:33:15 +01:00
|
|
|
return {
|
|
|
|
|
type: ON_CHANGE_INPUT,
|
2017-11-16 13:43:55 +01:00
|
|
|
keys,
|
2017-11-07 16:33:15 +01:00
|
|
|
value: target.value,
|
2017-11-07 14:32:31 +01:00
|
|
|
};
|
|
|
|
|
}
|
2017-11-07 18:16:42 +01:00
|
|
|
|
2017-11-23 13:09:05 +01:00
|
|
|
export function onClickAdd(itemToAdd) {
|
|
|
|
|
return {
|
|
|
|
|
type: ON_CLICK_ADD,
|
|
|
|
|
itemToAdd,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 18:16:42 +01:00
|
|
|
export function onClickDelete(itemToDelete) {
|
|
|
|
|
return {
|
|
|
|
|
type: ON_CLICK_DELETE,
|
|
|
|
|
itemToDelete,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-11-23 12:15:06 +01:00
|
|
|
export function setActionType(action) {
|
|
|
|
|
const actionType = action === 'create' ? 'POST' : 'PUT';
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: SET_ACTION_TYPE,
|
|
|
|
|
actionType,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setErrors(formErrors) {
|
|
|
|
|
return {
|
|
|
|
|
type: SET_ERRORS,
|
|
|
|
|
formErrors,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-11-15 14:00:51 +01:00
|
|
|
|
|
|
|
|
export function setForm() {
|
|
|
|
|
const form = Map({
|
|
|
|
|
name: '',
|
|
|
|
|
description: '',
|
2017-11-23 12:15:06 +01:00
|
|
|
users: List([]),
|
2017-11-15 15:11:10 +01:00
|
|
|
permissions: Map({}),
|
2017-11-15 14:00:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: SET_FORM,
|
|
|
|
|
form,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-11-23 12:15:06 +01:00
|
|
|
|
|
|
|
|
export function submit() {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function submitError(errors) {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT_ERROR,
|
|
|
|
|
errors,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function submitSucceeded() {
|
|
|
|
|
return {
|
|
|
|
|
type: SUBMIT_SUCCEEDED,
|
|
|
|
|
};
|
|
|
|
|
}
|