@@ -11,7 +11,7 @@ import Button from '../button'
1111 * External dependencies
1212 */
1313import classnames from 'classnames'
14- import { i18n } from 'stackable'
14+ import { i18n , cimo } from 'stackable'
1515import {
1616 useAttributeName , useBlockAttributesContext , useBlockSetAttributesContext ,
1717} from '~stackable/hooks'
@@ -20,8 +20,11 @@ import {
2020 * WordPress dependencies
2121 */
2222import { __ } from '@wordpress/i18n'
23- import { Fragment , memo } from '@wordpress/element'
23+ import {
24+ Fragment , memo , useEffect , useState ,
25+ } from '@wordpress/element'
2426import { MediaUpload } from '@wordpress/block-editor'
27+ import { currentUserHasCapability } from '~stackable/util'
2528
2629const ImageControl = memo ( props => {
2730 const attrNameId = useAttributeName ( `${ props . attribute } Id` , props . responsive , props . hover )
@@ -81,7 +84,37 @@ const ImageControl = memo( props => {
8184 } )
8285 }
8386
84- return (
87+ const [ CimoDownloadNotice , setCimoDownloadNotice ] = useState ( null )
88+
89+ useEffect ( ( ) => {
90+ // Skip displaying the Cimo notice if the plugin is already activated or the user has chosen to hide the notice
91+ if ( ! cimo || cimo . hideNotice || cimo . status === 'activated' ) {
92+ return
93+ }
94+
95+ const userCanInstall = currentUserHasCapability ( 'install_plugins' )
96+ const userCanActivate = currentUserHasCapability ( 'activate_plugins' )
97+ // Show the Cimo notice only if the user has permissions to install or activate plugins
98+ if ( ( cimo . status === 'not_installed' && userCanInstall ) || ( cimo . status === 'installed' && userCanActivate ) ) {
99+ const loadNotice = async ( ) => {
100+ try {
101+ // Import the Cimo notice component with explicit chunk naming
102+ const { default : CimoNoticeComponent } = await import (
103+ /* webpackChunkName: "cimo-download-notice" */
104+ /* webpackMode: "lazy" */
105+ '../../lazy-components/cimo'
106+ )
107+ setCimoDownloadNotice ( ( ) => CimoNoticeComponent )
108+ } catch ( err ) {
109+ // eslint-disable-next-line no-console
110+ console . error ( 'Failed to load Cimo download notice component:' , err )
111+ }
112+ }
113+ loadNotice ( )
114+ }
115+ } , [ ] )
116+
117+ return ( < >
85118 < AdvancedControl
86119 { ...controlProps }
87120 valueCheckAttribute = { props . attribute + 'Url' }
@@ -112,7 +145,7 @@ const ImageControl = memo( props => {
112145 />
113146 ) }
114147 { type === 'image' && (
115- // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
148+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
116149 < img
117150 className = "ugb-image-preview"
118151 draggable = "false"
@@ -172,6 +205,8 @@ const ImageControl = memo( props => {
172205 hasPanelModifiedIndicator = { props . hasPanelModifiedIndicator }
173206 />
174207 </ AdvancedControl >
208+ { CimoDownloadNotice && < CimoDownloadNotice onDismiss = { ( ) => setCimoDownloadNotice ( null ) } /> }
209+ </ >
175210 )
176211} )
177212
0 commit comments