| 1 |
/** |
| 2 |
* WordPress dependencies |
| 3 |
*/ |
| 4 |
import {__} from '@wordpress/i18n'; |
| 5 |
|
| 6 |
const {InnerBlocks} = wp.blockEditor; |
| 7 |
const {useEffect} = wp.element; |
| 8 |
const {select, dispatch} = wp.data; |
| 9 |
|
| 10 |
const edit = ({isSelected, clientId}) => { |
| 11 |
// When adding a new Multi-Form Goal block, select the inner Progress Bar block by default |
| 12 |
useEffect(() => { |
| 13 |
if (isSelected) { |
| 14 |
selectProgressBar(); |
| 15 |
} |
| 16 |
}, []); |
| 17 |
|
| 18 |
const selectProgressBar = () => { |
| 19 |
const parentBlock = select('core/editor').getBlocksByClientId(clientId)[0]; |
| 20 |
const progressBarBlock = parentBlock.innerBlocks[parentBlock.innerBlocks.length - 1]; |
| 21 |
// prevent error if progressBarBlock is slow to load |
| 22 |
if (progressBarBlock) { |
| 23 |
dispatch('core/block-editor').selectBlock(progressBarBlock.clientId); |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
const blockTemplate = [ |
| 28 |
[ |
| 29 |
'core/media-text', |
| 30 |
{ |
| 31 |
imageFill: true, |
| 32 |
}, |
| 33 |
[ |
| 34 |
[ |
| 35 |
'core/heading', |
| 36 |
{ |
| 37 |
placeholder: __('Heading', 'give'), |
| 38 |
}, |
| 39 |
], |
| 40 |
[ |
| 41 |
'core/paragraph', |
| 42 |
{ |
| 43 |
placeholder: __('Summary', 'give'), |
| 44 |
}, |
| 45 |
], |
| 46 |
], |
| 47 |
], |
| 48 |
['give/progress-bar', {}], |
| 49 |
]; |
| 50 |
|
| 51 |
return ( |
| 52 |
<div className="give-multi-form-goal-block"> |
| 53 |
<InnerBlocks template={blockTemplate} templateLock="all" /> |
| 54 |
</div> |
| 55 |
); |
| 56 |
}; |
| 57 |
export default edit; |
| 58 |
|