Skip to content

Commit

Permalink
chore: fix QA issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cristian-ungureanu committed Sep 7, 2023
1 parent 9e056dd commit d9e4b99
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 90 deletions.
2 changes: 1 addition & 1 deletion includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function init() {
add_action( 'admin_menu', array( $this, 'register' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
add_filter( 'ti_tpc_editor_data', array( $this, 'add_tpc_editor_data' ), 20 );
add_action( 'admin_footer_text', array( $this, 'activation_redirect' ) );
add_action( 'admin_init', array( $this, 'activation_redirect' ) );

$this->setup_white_label();

Expand Down
85 changes: 48 additions & 37 deletions onboarding/src/Components/CustomizeControls/LogoControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const LogoControl = ( { userCustomSettings, handleLogoChange } ) => {
isTertiary
onClick={ () => {
setLogo( '' );
handleLogoChange( {} );
handleLogoChange( null );
} }
>
<Icon icon="no" />
Expand All @@ -92,49 +92,60 @@ const LogoControl = ( { userCustomSettings, handleLogoChange } ) => {

export default compose(
withSelect( ( select ) => {
const { getUserCustomSettings, getImportData } = select( 'ti-onboarding' );
const { getUserCustomSettings, getImportData } = select(
'ti-onboarding'
);
return {
userCustomSettings: getUserCustomSettings(),
importData: getImportData(),
};
} ),
withDispatch( ( dispatch, { importData, userCustomSettings } ) => {
const { setUserCustomSettings, setImportData } = dispatch(
'ti-onboarding'
);
withDispatch(
( dispatch, { importData, userCustomSettings, importDataDefault } ) => {
const { setUserCustomSettings, setImportData } = dispatch(
'ti-onboarding'
);

return {
handleLogoChange: ( newLogo ) => {
const updatedSettings = {
...userCustomSettings,
siteLogo: newLogo,
};
setUserCustomSettings( updatedSettings );
return {
handleLogoChange: ( newLogo ) => {
const updatedSettings = {
...userCustomSettings,
siteLogo: newLogo,
};
setUserCustomSettings( updatedSettings );

const newImportData = {
...importData,
theme_mods: {
...importData.theme_mods,
custom_logo: newLogo.id,
logo_logo: JSON.stringify( {
dark: newLogo.id,
light: newLogo.id,
same: true,
} ),
},
};
setImportData( newImportData );
const newImportData = {
...importData,
theme_mods: {
...importData.theme_mods,
custom_logo: newLogo
? newLogo.id
: importDataDefault.theme_mods.custom_logo,
logo_logo: newLogo
? JSON.stringify( {
dark: newLogo.id,
light: newLogo.id,
same: true,
} )
: JSON.stringify( {
...importDataDefault.theme_mods
.logo_logo,
} ),
},
};
setImportData( newImportData );

const logoDisplay = newImportData?.theme_mods?.logo_display;
const logoDisplay = newImportData?.theme_mods?.logo_display;

sendPostMessage( {
type: 'updateSiteInfo',
data: {
...updatedSettings,
logoDisplay,
},
} );
},
};
} )
sendPostMessage( {
type: 'updateSiteInfo',
data: {
...updatedSettings,
logoDisplay,
},
} );
},
};
}
)
)( LogoControl );
64 changes: 34 additions & 30 deletions onboarding/src/Components/CustomizeControls/SiteNameControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,41 @@ export default compose(
importData: getImportData(),
};
} ),
withDispatch( ( dispatch, { importData, userCustomSettings } ) => {
const { setUserCustomSettings, setImportData } = dispatch(
'ti-onboarding'
);
withDispatch(
( dispatch, { importData, userCustomSettings, importDataDefault } ) => {
const { setUserCustomSettings, setImportData } = dispatch(
'ti-onboarding'
);

return {
handleSiteNameChange: ( newSiteName ) => {
const updatedSettings = {
...userCustomSettings,
siteName: newSiteName,
};
setUserCustomSettings( updatedSettings );
return {
handleSiteNameChange: ( newSiteName ) => {
const updatedSettings = {
...userCustomSettings,
siteName: newSiteName,
};
setUserCustomSettings( updatedSettings );

const newImportData = {
...importData,
wp_options: {
...importData.wp_options,
blogname: newSiteName,
},
};
setImportData( newImportData );
const newImportData = {
...importData,
wp_options: {
...importData.wp_options,
blogname:
newSiteName ||
importDataDefault.wp_options.blogname,
},
};
setImportData( newImportData );

const logoDisplay = newImportData?.theme_mods?.logo_display;
sendPostMessage( {
type: 'updateSiteInfo',
data: {
...updatedSettings,
logoDisplay,
},
} );
},
};
} )
const logoDisplay = newImportData?.theme_mods?.logo_display;
sendPostMessage( {
type: 'updateSiteInfo',
data: {
...updatedSettings,
logoDisplay,
},
} );
},
};
}
)
)( SiteNameControl );
35 changes: 23 additions & 12 deletions onboarding/src/Components/SitePreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { useEffect, useState } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
import { sendPostMessage } from '../utils/common';

const SitePreview = ( { userCustomSettings, siteData, importData } ) => {
const SitePreview = ( {
userCustomSettings,
siteData,
importData,
siteStyle,
} ) => {
const [ loading, setLoading ] = useState( true );

const loadDefaultFonts = ( message ) => {
Expand All @@ -20,6 +25,21 @@ const SitePreview = ( { userCustomSettings, siteData, importData } ) => {
return;
}

const logoDisplay = importData?.theme_mods?.logo_display;

sendPostMessage( {
type: 'updateSiteInfo',
data: {
...userCustomSettings,
logoDisplay,
},
} );

sendPostMessage( {
type: 'styleChange',
data: siteStyle,
} );

const scriptsToLoad = JSON.parse( value );
scriptsToLoad.forEach( ( element ) => {
const { id, href } = element;
Expand All @@ -34,16 +54,6 @@ const SitePreview = ( { userCustomSettings, siteData, importData } ) => {
useEffect( () => {
window.addEventListener( 'message', loadDefaultFonts );

const logoDisplay = importData?.theme_mods?.logo_display;

sendPostMessage( {
type: 'updateSiteInfo',
data: {
...userCustomSettings,
logoDisplay,
},
} );

if ( loading !== false ) {
return;
}
Expand All @@ -65,7 +75,8 @@ const SitePreview = ( { userCustomSettings, siteData, importData } ) => {
id="ti-ss-preview"
className="iframe"
title="Your Iframe"
src={ siteUrl }
// src={ siteUrl }
src="https://neve.test"
onLoad={ handleIframeLoading }
></iframe>
);
Expand Down
21 changes: 14 additions & 7 deletions onboarding/src/Components/SiteSettings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { Button } from '@wordpress/components';
Expand All @@ -18,12 +18,11 @@ export const SiteSettings = ( {
setGeneral,
fetching,
siteData,
siteStyle,
setSiteStyle,
importDataDefault,
} ) => {
const [ settingsPage, setSettingsPage ] = useState( 1 );
const [ siteStyle, setSiteStyle ] = useState( {
palette: 'base',
font: 'default',
} );
const canImport = ! siteData.upsell;

let heading =
Expand Down Expand Up @@ -120,8 +119,16 @@ export const SiteSettings = ( {
{ settingsPage === 2 &&
( canImport ? (
<>
<SiteNameControl />
<LogoControl />
<SiteNameControl
importDataDefault={
importDataDefault
}
/>
<LogoControl
importDataDefault={
importDataDefault
}
/>
</>
) : (
<Button
Expand Down
19 changes: 16 additions & 3 deletions onboarding/src/Components/Steps/CustomizeSite.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global tiobDash */
import SiteSettings from '../SiteSettings';
import { __ } from '@wordpress/i18n';
import { useEffect } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { trailingSlashIt } from '../../utils/common';
Expand All @@ -17,6 +17,12 @@ const CustomizeSite = ( {
general,
setGeneral,
} ) => {
const [ siteStyle, setSiteStyle ] = useState( {
palette: 'base',
font: 'default',
} );
const [ importDataDefault, setImportDataDefault ] = useState( null );

const { license } = tiobDash;

useEffect( () => {
Expand Down Expand Up @@ -44,6 +50,7 @@ const CustomizeSite = ( {
}
response.json().then( ( result ) => {
setImportData( { ...result, ...siteData } );
setImportDataDefault( { ...result, ...siteData } );
const mandatory = {
...( result.mandatory_plugins || {} ),
};
Expand Down Expand Up @@ -87,8 +94,14 @@ const CustomizeSite = ( {

return (
<div className="ob-container row ovf-initial">
<SiteSettings general={ general } setGeneral={ setGeneral } />
<SitePreview />
<SiteSettings
importDataDefault={ importDataDefault }
siteStyle={ siteStyle }
setSiteStyle={ setSiteStyle }
general={ general }
setGeneral={ setGeneral }
/>
<SitePreview siteStyle={ siteStyle } />
</div>
);
};
Expand Down

0 comments on commit d9e4b99

Please sign in to comment.