| 1 |
import { __ } from '@wordpress/i18n' |
| 2 |
import { Modal, Button } from '@wordpress/components' |
| 3 |
import { useState, render } from '@wordpress/element' |
| 4 |
import { Plugins } from '../../api/Plugins' |
| 5 |
import { useWantedTemplateStore } from '../../state/Importing' |
| 6 |
import ErrorActivating from './ErrorActivating' |
| 7 |
import ReloadRequiredModal from '../ReloadRequiredModal' |
| 8 |
|
| 9 |
export default function ActivatingModal() { |
| 10 |
const [errorMessage, setErrorMessage] = useState('') |
| 11 |
const wantedTemplate = useWantedTemplateStore( |
| 12 |
(store) => store.wantedTemplate, |
| 13 |
) |
| 14 |
|
| 15 |
// Hardcoded temporarily to not force EP install |
| 16 |
// const required = wantedTemplate?.fields?.required_plugins |
| 17 |
const required = wantedTemplate?.fields?.required_plugins.filter( |
| 18 |
(p) => p !== 'editorplus', |
| 19 |
) |
| 20 |
|
| 21 |
Plugins.installAndActivate(required) |
| 22 |
.then(() => { |
| 23 |
useWantedTemplateStore.setState({ |
| 24 |
importOnLoad: true, |
| 25 |
}) |
| 26 |
}) |
| 27 |
.then(async () => { |
| 28 |
await new Promise((resolve) => setTimeout(resolve, 1000)) |
| 29 |
render( |
| 30 |
<ReloadRequiredModal />, |
| 31 |
document.getElementById('extendify-root'), |
| 32 |
) |
| 33 |
}) |
| 34 |
.catch(({ response }) => { |
| 35 |
setErrorMessage(response.data.message) |
| 36 |
}) |
| 37 |
|
| 38 |
if (errorMessage) { |
| 39 |
return <ErrorActivating msg={errorMessage} /> |
| 40 |
} |
| 41 |
|
| 42 |
return ( |
| 43 |
<Modal |
| 44 |
title={__('Activating plugins', 'extendify')} |
| 45 |
isDismissible={false}> |
| 46 |
<Button |
| 47 |
style={{ |
| 48 |
width: '100%', |
| 49 |
}} |
| 50 |
disabled |
| 51 |
isPrimary |
| 52 |
isBusy |
| 53 |
onClick={() => {}}> |
| 54 |
{__('Activating...', 'extendify')} |
| 55 |
</Button> |
| 56 |
</Modal> |
| 57 |
) |
| 58 |
} |
| 59 |
|