Compare commits

...

1 Commits

Author SHA1 Message Date
a.bouhuolia
5f0700b5e5 fix: hotbug account dialog edit payload transformation. 2021-11-20 18:52:45 +02:00

View File

@@ -1,5 +1,6 @@
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
import * as R from 'ramda'; import * as R from 'ramda';
import { isEmpty } from 'lodash';
export const transformApiErrors = (errors) => { export const transformApiErrors = (errors) => {
const fields = {}; const fields = {};
@@ -42,12 +43,18 @@ const mergeWithAccount = R.curry((transformed, account) => {
}; };
}); });
/**
* Default account payload transformer.
*/
const defaultPayloadTransform = () => ({});
/** /**
* Defined payload transformers. * Defined payload transformers.
*/ */
function getConditions() { function getConditions() {
return [ return [
['edit', transformEditMode], ['edit'],
['new_child', transformEditMode],
['NEW_ACCOUNT_DEFINED_TYPE', transformNewAccountDefinedType], ['NEW_ACCOUNT_DEFINED_TYPE', transformNewAccountDefinedType],
]; ];
} }
@@ -59,9 +66,13 @@ export const transformAccountToForm = (account, payload) => {
const conditions = getConditions(); const conditions = getConditions();
const results = conditions.map((condition) => { const results = conditions.map((condition) => {
const transformer = !isEmpty(condition[1])
? condition[1]
: defaultPayloadTransform;
return [ return [
condition[0] === payload.action ? R.T : R.F, condition[0] === payload.action ? R.T : R.F,
mergeWithAccount(condition[1](payload)), mergeWithAccount(transformer(payload)),
]; ];
}); });
return R.cond(results)(account); return R.cond(results)(account);