Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit df182d4

Browse files
committed
Add block data formatter fn
1 parent 6aa378d commit df182d4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

functions/formatBlockData.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import getFormById from '@/api/wordpress/gravityForms/getFormById'
2+
3+
/**
4+
* Format and retrieve expanded block data.
5+
*
6+
* @param {Array} blocks Basic block data.
7+
* @return {Array} Formatted block data.
8+
*/
9+
export default async function formatBlockData(blocks) {
10+
if (!blocks || !blocks.length) {
11+
return []
12+
}
13+
14+
return await Promise.all(
15+
blocks.map(async (block) => {
16+
const {name, attributes} = block
17+
18+
switch (name) {
19+
case 'gravityforms/form':
20+
// Retrieve form data.
21+
attributes.formData = await getFormById(attributes.formId)
22+
break
23+
}
24+
25+
return {name, attributes}
26+
})
27+
)
28+
}

0 commit comments

Comments
 (0)