| 1 |
import { __ } from '@wordpress/i18n' |
| 2 |
import { Button } from '@wordpress/components' |
| 3 |
import { useState } from '@wordpress/element' |
| 4 |
import { Plugins } from '../../api/Plugins' |
| 5 |
import classNames from 'classnames' |
| 6 |
import { General } from '../../api/General' |
| 7 |
import { useUserStore } from '../../state/User' |
| 8 |
|
| 9 |
export const InstallStandaloneNotice = () => { |
| 10 |
const [text, setText] = useState('') |
| 11 |
const giveFreebieImports = useUserStore((state) => state.giveFreebieImports) |
| 12 |
const installAndActivate = () => { |
| 13 |
setText(__('Installing...', 'extendify')) |
| 14 |
Promise.all([ |
| 15 |
General.ping('stln-footer-install'), |
| 16 |
Plugins.installAndActivate(['extendify']), |
| 17 |
new Promise((resolve) => setTimeout(resolve, 1000)), |
| 18 |
]) |
| 19 |
.then(async () => { |
| 20 |
giveFreebieImports(10) |
| 21 |
setText(__('Success! Reloading...', 'extendify')) |
| 22 |
await General.ping('stln-footer-success') |
| 23 |
window.location.reload() |
| 24 |
}) |
| 25 |
.catch(async (error) => { |
| 26 |
console.error(error) |
| 27 |
setText(__('Error. See console.', 'extendify')) |
| 28 |
await General.ping('stln-footer-fail') |
| 29 |
}) |
| 30 |
} |
| 31 |
|
| 32 |
return ( |
| 33 |
<div> |
| 34 |
<span className="text-black"> |
| 35 |
{__( |
| 36 |
'Install the new Extendify Library plugin to get the latest we have to offer', |
| 37 |
'extendify', |
| 38 |
)} |
| 39 |
</span> |
| 40 |
<span className="px-2 opacity-50" aria-hidden="true"> |
| 41 |
| |
| 42 |
</span> |
| 43 |
<div className="inline-flex space-x-2 items-center relative"> |
| 44 |
<Button |
| 45 |
variant="link" |
| 46 |
className={classNames( |
| 47 |
'text-black underline hover:no-underline p-0 h-auto', |
| 48 |
{ 'opacity-0': text }, |
| 49 |
)} |
| 50 |
onClick={installAndActivate}> |
| 51 |
{__('Install Extendify standalone plugin', 'extendify')} |
| 52 |
</Button> |
| 53 |
{/* Little hacky to keep the text in place. Might need to tweak this */} |
| 54 |
{text ? ( |
| 55 |
<Button |
| 56 |
variant="link" |
| 57 |
disabled={true} |
| 58 |
className="text-black underline hover:no-underline p-0 h-auto absolute left-0 opacity-100" |
| 59 |
onClick={() => {}}> |
| 60 |
{text} |
| 61 |
</Button> |
| 62 |
) : null} |
| 63 |
</div> |
| 64 |
</div> |
| 65 |
) |
| 66 |
} |
| 67 |
|