Add mapper for mapping form body to blocks

[MAILPOET-2451]
This commit is contained in:
Rostislav Wolny
2019-12-02 17:14:35 +01:00
committed by Jack Kitterhing
parent 293956bbec
commit 4e71908332
2 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
export default (data) => (
data.map((item) => {
const mapped = {
clientId: item.id,
isValid: true,
innerBlocks: [],
};
switch (item.id) {
case 'email':
mapped.name = 'mailpoet-form/email-input';
mapped.attributes = {
label: item.params.label,
labelWithinInput: !!item.params.label_within,
};
return mapped;
case 'submit':
mapped.name = 'mailpoet-form/submit-button';
mapped.attributes = {
label: item.params.label,
};
return mapped;
default:
return null;
}
}).filter(Boolean)
);