| 1 |
import { Modal, Button, ButtonGroup } from '@wordpress/components' |
| 2 |
import { render } from '@wordpress/element' |
| 3 |
import { __, sprintf } from '@wordpress/i18n' |
| 4 |
import ExtendifyLibrary from '@library/ExtendifyLibrary' |
| 5 |
import { useWantedTemplateStore } from '@library/state/Importing' |
| 6 |
import { useUserStore } from '@library/state/User' |
| 7 |
import { getPluginDescription } from '@library/util/general' |
| 8 |
import NeedsPermissionModal from '../NeedsPermissionModal' |
| 9 |
import InstallingModal from './InstallingModal' |
| 10 |
|
| 11 |
export default function RequiredPluginsModal({ |
| 12 |
forceOpen, |
| 13 |
buttonLabel, |
| 14 |
title, |
| 15 |
message, |
| 16 |
requiredPlugins, |
| 17 |
}) { |
| 18 |
// If there's a template in cache ready to be installed. |
| 19 |
// TODO: this could probably be refactored out when overhauling required plugins |
| 20 |
const wantedTemplate = useWantedTemplateStore( |
| 21 |
(store) => store.wantedTemplate, |
| 22 |
) |
| 23 |
requiredPlugins = |
| 24 |
requiredPlugins ?? wantedTemplate?.fields?.required_plugins |
| 25 |
|
| 26 |
const closeModal = () => { |
| 27 |
if (forceOpen) { |
| 28 |
return |
| 29 |
} |
| 30 |
render( |
| 31 |
<ExtendifyLibrary show={true} />, |
| 32 |
document.getElementById('extendify-root'), |
| 33 |
) |
| 34 |
} |
| 35 |
const installPlugins = () => |
| 36 |
render( |
| 37 |
<InstallingModal requiredPlugins={requiredPlugins} />, |
| 38 |
document.getElementById('extendify-root'), |
| 39 |
) |
| 40 |
|
| 41 |
if (!useUserStore.getState()?.canInstallPlugins) { |
| 42 |
return <NeedsPermissionModal /> |
| 43 |
} |
| 44 |
|
| 45 |
return ( |
| 46 |
<Modal |
| 47 |
title={title ?? __('Install required plugins', 'extendify')} |
| 48 |
isDismissible={false}> |
| 49 |
<p |
| 50 |
style={{ |
| 51 |
maxWidth: '400px', |
| 52 |
}}> |
| 53 |
{message ?? |
| 54 |
__( |
| 55 |
sprintf( |
| 56 |
'There is just one more step. This %s requires the following to be automatically installed and activated:', |
| 57 |
wantedTemplate?.fields?.type ?? 'template', |
| 58 |
), |
| 59 |
'extendify', |
| 60 |
)} |
| 61 |
</p> |
| 62 |
{message?.length > 0 || ( |
| 63 |
<ul> |
| 64 |
{ |
| 65 |
// Hardcoded temporarily to not force EP install |
| 66 |
// requiredPlugins.map((plugin) => |
| 67 |
requiredPlugins |
| 68 |
.filter((p) => p !== 'editorplus') |
| 69 |
.map((plugin) => ( |
| 70 |
<li key={plugin}> |
| 71 |
{getPluginDescription(plugin)} |
| 72 |
</li> |
| 73 |
)) |
| 74 |
} |
| 75 |
</ul> |
| 76 |
)} |
| 77 |
<ButtonGroup> |
| 78 |
<Button isPrimary onClick={installPlugins}> |
| 79 |
{buttonLabel ?? __('Install Plugins', 'extendify')} |
| 80 |
</Button> |
| 81 |
{forceOpen || ( |
| 82 |
<Button |
| 83 |
isTertiary |
| 84 |
onClick={closeModal} |
| 85 |
style={{ |
| 86 |
boxShadow: 'none', |
| 87 |
margin: '0 4px', |
| 88 |
}}> |
| 89 |
{__('No thanks, take me back', 'extendify')} |
| 90 |
</Button> |
| 91 |
)} |
| 92 |
</ButtonGroup> |
| 93 |
</Modal> |
| 94 |
) |
| 95 |
} |
| 96 |
|