RequiredPluginsModal.js (2404B)
1 import { __, sprintf } from '@wordpress/i18n' 2 import ExtendifyLibrary from '../../ExtendifyLibrary' 3 import { 4 Modal, Button, ButtonGroup, 5 } from '@wordpress/components' 6 import { render } from '@wordpress/element' 7 import InstallingModal from './InstallingModal' 8 import { useWantedTemplateStore } from '../../state/Importing' 9 import { getPluginDescription } from '../../util/general' 10 import { useUserStore } from '../../state/User' 11 import NeedsPermissionModal from '../NeedsPermissionModal' 12 13 export default function RequiredPluginsModal(props) { 14 const wantedTemplate = useWantedTemplateStore(store => store.wantedTemplate) 15 const closeModal = () => { 16 if (props.forceOpen) { 17 return 18 } 19 render(<ExtendifyLibrary show={true} />, document.getElementById('extendify-root')) 20 } 21 const installPlugins = () => render(<InstallingModal />, document.getElementById('extendify-root')) 22 const requiredPlugins = wantedTemplate?.fields?.required_plugins || [] 23 24 if (!useUserStore.getState()?.canInstallPlugins) { 25 return <NeedsPermissionModal/> 26 } 27 28 return <Modal 29 title={props.title ?? __('Install required plugins', 'extendify-sdk')} 30 isDismissible={false} 31 > 32 <p style={{ 33 maxWidth: '400px', 34 }}> 35 {props.message ?? __(sprintf('There is just one more step. This %s requires the following to be automatically installed and activated:', 36 wantedTemplate?.fields?.type ?? 'template'), 37 'extendify-sdk')} 38 </p> 39 {props.message?.length > 0 || <ul> 40 { 41 // Hardcoded temporarily to not force EP install 42 // requiredPlugins.map((plugin) => 43 requiredPlugins.filter((p) => p !== 'editorplus').map((plugin) => 44 <li key={plugin}> 45 {getPluginDescription(plugin)} 46 </li>) 47 } 48 </ul>} 49 <ButtonGroup> 50 <Button isPrimary onClick={installPlugins}> 51 {props.buttonLabel ?? __('Install Plugins', 'extendify-sdk')} 52 </Button> 53 {props.forceOpen || <Button isTertiary onClick={closeModal} style={{ 54 boxShadow: 'none', margin: '0 4px', 55 }}> 56 {__('No thanks, take me back', 'extendify-sdk')} 57 </Button>} 58 </ButtonGroup> 59 </Modal> 60 }