Skip to content

Commit

Permalink
feat: add Hyve Promo
Browse files Browse the repository at this point in the history
  • Loading branch information
HardeepAsrani committed Sep 18, 2024
1 parent 8f9eabc commit bcaf401
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 57 deletions.
215 changes: 161 additions & 54 deletions assets/src/Components/ImportModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ImportModal = ( {
widgets: true,
cleanup: false,
performanceAddon: true,
hyveLite: true,
theme_install: themeData !== false,
} );
const site = tiobDash.onboarding.homeUrl || '';
Expand All @@ -61,6 +62,7 @@ const ImportModal = ( {
const [ performanceAddonProgress, setPerformanceAddonProgress ] = useState(
false
);
const [ hyveLiteProgress, setHyveLiteProgress ] = useState( false );
const [ cleanupProgress, setCleanupProgress ] = useState( false );
const [ pluginsProgress, setPluginsProgress ] = useState( false );
const [ contentProgress, setContentProgress ] = useState( false );
Expand All @@ -81,7 +83,9 @@ const ImportModal = ( {
cleanupAllowed
);
const [ email, setEmail ] = useState( tiobDash.emailSubscribe.email || '' );
const [ skipSubscribe, setSkipSubscribe ] = useState( 'yes' === tiobDash?.emailSubscribe?.skipStatus );
const [ skipSubscribe, setSkipSubscribe ] = useState(
'yes' === tiobDash?.emailSubscribe?.skipStatus
);
const [ processingSub, setProcessingSub ] = useState( false );

useEffect( () => {
Expand Down Expand Up @@ -260,6 +264,43 @@ const ImportModal = ( {
}
),
},
hyveLite: {
title: __( 'AI Chatbot', 'templates-patterns-collection' ),
icon: 'admin-comments',
tooltip: createInterpolateElement(
sprintf(
// translators: %s is Hyve plugin name.
__(
'Hyve is an AI-powered chatbot that transforms your WordPress content into engaging conversations. <a><span>%s</span><icon/></a>',
'templates-patterns-collection'
),
'Hyve'
),
{
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
href="https://wordpress.org/plugins/hyve-lite/"
target={ '_blank' }
rel="external noreferrer noopener"
style={ {
textDecoration: 'none',
display: 'inline-flex',
alignItems: 'center',
} }
/>
),
icon: (
<Icon
size={ 10 }
icon="external"
style={ { marginLeft: 0 } }
/>
),
span: <div />,
}
),
},
};

if ( isCleanupAllowed === 'yes' ) {
Expand Down Expand Up @@ -305,7 +346,11 @@ const ImportModal = ( {
<span>{ title }</span>
{ tooltip && (
<CustomTooltip
toLeft={ id === 'performanceAddon' || id === 'cleanup' }
toLeft={ [
'performanceAddon',
'cleanup',
'hyveLite',
].includes( id ) }
rightOffset={ id === 'cleanup' ? -90 : 0 }
>
{ tooltip }
Expand Down Expand Up @@ -343,15 +388,19 @@ const ImportModal = ( {
return null;
}

const [ pluginsOpened, setPluginsOpened ] = useState( Object.keys( allPlugins ).length < 3 );
const [ pluginsOpened, setPluginsOpened ] = useState(
Object.keys( allPlugins ).length < 3
);

const toggleOpen = () => {
setPluginsOpened( ! pluginsOpened );
};

const pluginsList = Object.keys( allPlugins ).map( ( slug, index ) => {
return allPlugins[ slug ];
} ).join( ', ' );
const pluginsList = Object.keys( allPlugins )
.map( ( slug, index ) => {
return allPlugins[ slug ];
} )
.join( ', ' );

return (
<>
Expand Down Expand Up @@ -392,18 +441,21 @@ const ImportModal = ( {
);
} ) }
</PanelBody>
{ ! pluginsOpened && (<i className="plugin-summary">
<CustomTooltip
toLeft={false}
>
<span
dangerouslySetInnerHTML={ {
__html: pluginsList,
} }
/>
</CustomTooltip>
{ __( 'Additional plugins are required for this Starter Site in order to work properly. ', 'templates-patterns-collection' ) }
</i>) }
{ ! pluginsOpened && (
<i className="plugin-summary">
<CustomTooltip toLeft={ false }>
<span
dangerouslySetInnerHTML={ {
__html: pluginsList,
} }
/>
</CustomTooltip>
{ __(
'Additional plugins are required for this Starter Site in order to work properly. ',
'templates-patterns-collection'
) }
</i>
) }
</>
);
};
Expand Down Expand Up @@ -495,7 +547,11 @@ const ImportModal = ( {

function runImportPlugins() {
// console.clear();
if ( ! pluginOptions && ! general.performanceAddon ) {
if (
! pluginOptions &&
! general.performanceAddon &&
! general.hyveLite
) {
console.log( '[S] Plugins.' );
runImportContent();
return false;
Expand Down Expand Up @@ -602,7 +658,7 @@ const ImportModal = ( {
function runPerformanceAddonInstall() {
if ( ! general.performanceAddon ) {
console.log( '[S] Performance Addon.' );
importDone();
runHyveLiteInstall();
return false;
}
setCurrentStep( 'performanceAddon' );
Expand All @@ -616,13 +672,37 @@ const ImportModal = ( {
}
console.log( '[D] Performance Addon.' );
setPerformanceAddonProgress( 'done' );
importDone();
runHyveLiteInstall();
} )
.catch( ( incomingError ) =>
handleError( incomingError, 'performanceAddon' )
);
}

function runHyveLiteInstall() {
if ( ! general.hyveLite ) {
console.log( '[S] Hyve Lite.' );
importDone();
return false;
}
setCurrentStep( 'hyveLite' );
console.log( '[P] Hyve Lite.' );

installPlugins( { 'hyve-lite': true } )
.then( ( response ) => {
if ( ! response.success ) {
handleError( response, 'hyveLite' );
return false;
}
console.log( '[D] Hyve Lite.' );
setHyveLiteProgress( 'done' );
importDone();
} )
.catch( ( incomingError ) =>
handleError( incomingError, 'hyveLite' )
);
}

function importDone() {
setCurrentStep( 'done' );
setIsCleanupAllowed( 'yes' );
Expand Down Expand Up @@ -671,6 +751,10 @@ const ImportModal = ( {
'Something went wrong while installing the performance addon.',
'templates-patterns-collection'
),
hyveLite: __(
'Something went wrong while installing the Hyve Lite plugin.',
'templates-patterns-collection'
),
};

switch ( step ) {
Expand All @@ -692,6 +776,9 @@ const ImportModal = ( {
case 'performanceAddon':
setPerformanceAddonProgress( 'error' );
break;
case 'hyveLite':
setHyveLiteProgress( 'error' );
break;
}
setError(
incomingError.data
Expand Down Expand Up @@ -735,24 +822,25 @@ const ImportModal = ( {
'templates-patterns-collection'
);
if ( skipSubscribe ) {
viewWebsiteText = __(
'View Website',
'templates-patterns-collection'
);
viewWebsiteText = __( 'View Website', 'templates-patterns-collection' );
skipText = __(
'Add your own content',
'templates-patterns-collection'
);
}

const markSubscribeSkip = ( redirect, data = {} ) => {
ajaxAction( tiobDash.emailSubscribe.ajaxURL, 'skip_subscribe', tiobDash.emailSubscribe.nonce, data )
.then(() => {
setSkipSubscribe(true);
setProcessingSub( false );
window.location.href = redirect;
});
}
ajaxAction(
tiobDash.emailSubscribe.ajaxURL,
'skip_subscribe',
tiobDash.emailSubscribe.nonce,
data
).then( () => {
setSkipSubscribe( true );
setProcessingSub( false );
window.location.href = redirect;
} );
};

const goToEditContent = () => {
if ( skipSubscribe ) {
Expand All @@ -779,34 +867,36 @@ const ImportModal = ( {
fetch( 'https://api.themeisle.com/tracking/subscribe', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
},
body: JSON.stringify({
body: JSON.stringify( {
slug: 'templates-patterns-collection',
site,
email
})
})
.then( r => r.json() )
email,
} ),
} )
.then( ( r ) => r.json() )
.then( ( response ) => {
if ( 'success' === response.code ) {
markSubscribeSkip( site )
markSubscribeSkip( site );
}
})?.catch( ( error ) => {
} )
?.catch( ( error ) => {
console.error( error );
markSubscribeSkip( site, { isTempSkip: true } )
});
}
markSubscribeSkip( site, { isTempSkip: true } );
} );
};

let modalTitle = importData ?
sprintf(
let modalTitle = importData
? sprintf(
/* translators: name of starter site */
__(
'Import %s as a complete site',
'templates-patterns-collection'
),
importData.title
) : '';
)
: '';
if ( 'done' === currentStep && ! error ) {
modalTitle = __(
'Content was successfully imported',
Expand All @@ -832,12 +922,14 @@ const ImportModal = ( {
siteData.doc_url && (
<DocNotice
data={ {
text: __( 'Learn more about this starter site', 'templates-patterns-collection' ),
text: __(
'Learn more about this starter site',
'templates-patterns-collection'
),
url: siteData.doc_url,
} }
/>
)
}
) }
{ ! importing && 'done' !== currentStep && ! error ? (
<>
<ModalHead />
Expand Down Expand Up @@ -869,18 +961,26 @@ const ImportModal = ( {
customizer: customizerProgress,
widgets: widgetsProgress,
performanceAddon: performanceAddonProgress,
hyveLite: hyveLiteProgress,
} }
currentStep={ currentStep }
willDo={ general }
/>
) }
{ 'done' === currentStep && ! skipSubscribe && (
<>
<p className="tpc-subscribe-email-text">{ __( 'Stay up-to-date on news, tips and product updates', 'templates-patterns-collection' ) }</p>
<p className="tpc-subscribe-email-text">
{ __(
'Stay up-to-date on news, tips and product updates',
'templates-patterns-collection'
) }
</p>

<TextControl
aria-label={ __( 'Enter your email', 'templates-patterns-collection' ) }

aria-label={ __(
'Enter your email',
'templates-patterns-collection'
) }
type="email"
value={ email }
onChange={ setEmail }
Expand All @@ -889,7 +989,12 @@ const ImportModal = ( {
</>
) }
{ 'done' === currentStep && skipSubscribe && (
<span style={{display: 'block', marginBottom: '60px'}}/>
<span
style={ {
display: 'block',
marginBottom: '60px',
} }
/>
) }
</>
) }
Expand Down Expand Up @@ -932,7 +1037,9 @@ const ImportModal = ( {
<div className="import-done-actions">
<Button
isLink
className={ classnames( 'close', { 'is-grayed': ! skipSubscribe } ) }
className={ classnames( 'close', {
'is-grayed': ! skipSubscribe,
} ) }
disabled={ processingSub }
onClick={ goToEditContent }
>
Expand Down
8 changes: 8 additions & 0 deletions assets/src/Components/ImportStepper.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ const ImportStepper = ( { currentStep, progress, willDo } ) => {
status: progress.performanceAddon,
willDo: willDo.performanceAddon,
},
hyveLite: {
label: __(
'Installing Hyve Lite Plugin',
'templates-patterns-collection'
),
status: progress.hyveLite,
willDo: willDo.hyveLite,
},
};

return (
Expand Down
Loading

0 comments on commit bcaf401

Please sign in to comment.