import {
createElement,
Component,
createRef,
useState,
useEffect,
useRef,
} from '@wordpress/element'
import { __, sprintf } from 'ct-i18n'
import $ from 'jquery'
const NotificationBlocksDrop = ({
initialStatus,
url,
pluginUrl,
pluginLink,
}) => {
const [pluginStatus, setPluginStatus] = useState('installed')
const [isLoading, setIsLoading] = useState(false)
const containerEl = useRef(null)
useEffect(() => {
setPluginStatus(initialStatus)
}, [])
const dismiss = () => {
containerEl.current.closest('.notice').remove()
$.ajax(ajaxurl, {
type: 'POST',
data: {
action: 'blocksy_dismissed_blocks_move_notice_handler',
},
})
}
return (
{
dismiss()
}}
type="button"
className="notice-dismiss">
{__('Dismiss this notice.', 'blocksy')}
{__(
'Heads up - soon theme blocks are going to be moved to the Blocksy Companion plugin',
'blocksy'
)}
' +
__(
'If you where using the theme blocks before, there is no need to worry, just activate the Blocksy Companion plugin and you will have access to those blocks as before.',
'blocksy'
),
}}
/>
{
setIsLoading(true)
setTimeout(() => {})
$.ajax(ajaxurl, {
type: 'POST',
data: {
action: 'blocksy_notice_button_click',
nonce: ct_localizations.nonce,
},
}).then(({ success, data }) => {
if (success) {
setPluginStatus(data.status)
if (data.status === 'active') {
location.assign(pluginUrl)
}
}
setIsLoading(false)
})
}}>
{isLoading
? __('Installing & activating...', 'blocksy')
: pluginStatus === 'uninstalled'
? __('Install Blocksy Companion', 'blocksy')
: pluginStatus === 'installed'
? __('Activate Blocksy Companion', 'blocksy')
: __('Blocksy Companion active!', 'blocksy')}
{isLoading && (
)}
{__('Why you need Blocksy Companion?', 'blocksy')}
)
}
export default NotificationBlocksDrop