115 lines
1.7 KiB
JavaScript
Raw Normal View History

/**
*
* EditPage actions
*
*/
import { get } from 'lodash';
import { getValidationsFromForm } from 'utils/formValidations';
import {
2018-02-21 15:09:33 +01:00
CHANGE_DATA,
GET_DATA,
GET_DATA_SUCCEEDED,
INIT_MODEL_PROPS,
ON_CANCEL,
RESET_PROPS,
SET_FILE_RELATIONS,
SET_LOADER,
SET_FORM_ERRORS,
2018-02-22 11:33:01 +01:00
SUBMIT,
SUBMIT_SUCCESS,
UNSET_LOADER,
} from './constants';
2018-02-21 15:09:33 +01:00
export function changeData({ target }) {
return {
type: CHANGE_DATA,
keys: target.name.split('.'),
value: target.value,
};
}
export function getData(id, source, mainField) {
return {
type: GET_DATA,
id,
source,
mainField,
};
}
export function getDataSucceeded(id, data, pluginHeaderTitle) {
return {
type: GET_DATA_SUCCEEDED,
id,
data,
pluginHeaderTitle,
};
}
export function initModelProps(modelName, isCreating, source, attributes) {
const formValidations = getValidationsFromForm(
Object.keys(attributes).map(attr => ({ name: attr, validations: get(attributes, attr, {}) })),
[],
);
return {
type: INIT_MODEL_PROPS,
formValidations,
isCreating,
modelName,
2018-02-21 15:09:33 +01:00
source,
};
}
export function onCancel() {
return {
type: ON_CANCEL,
};
}
export function resetProps() {
return {
type: RESET_PROPS,
};
}
export function setFileRelations(fileRelations) {
return {
type: SET_FILE_RELATIONS,
fileRelations,
};
}
export function setFormErrors(formErrors) {
return {
type: SET_FORM_ERRORS,
formErrors,
};
}
2018-02-22 11:33:01 +01:00
export function setLoader() {
return {
type: SET_LOADER,
};
}
2018-02-22 11:33:01 +01:00
export function submit() {
return {
type: SUBMIT,
};
}
export function submitSuccess() {
return {
type: SUBMIT_SUCCESS,
};
}
export function unsetLoader() {
return {
type: UNSET_LOADER,
};
}