diff --git a/assets/src/dashboard/parts/connected/CSAT.js b/assets/src/dashboard/parts/connected/CSAT.js deleted file mode 100644 index 0b49257fd..000000000 --- a/assets/src/dashboard/parts/connected/CSAT.js +++ /dev/null @@ -1,134 +0,0 @@ -/** - * External dependencies. - */ -import { info } from '@wordpress/icons'; - -/** - * WordPress dependencies. - */ -import { - Button, - Icon, - TextareaControl, - Tooltip -} from '@wordpress/components'; - -import { useSelect } from '@wordpress/data'; - -import { - useEffect, - useState -} from '@wordpress/element'; - -/** - * Internal dependencies. - */ -import CSAT from './csat/index'; -import useSettings from '../../utils/use-settings'; - -const CSATList = () => { - const [ isVisible, setIsVisible ] = useState( false ); - const [ getOption, updateOption, status ] = useSettings(); - - const settings = ( 'loaded' === status && undefined !== getOption( 'optml_csat' ) ) && JSON.parse( getOption( 'optml_csat' ) ); - - const { - hasImages, - isFirstSite - } = useSelect( select => { - const { getUserData } = select( 'optimole' ); - - return { - hasImages: 0 < getUserData()?.images_number, - isFirstSite: 1 === getUserData()?.whitelist?.length - }; - }); - - const visits = localStorage.getItem( 'optimole_settings_visits' ); - - useEffect( () => { - setIsVisible( hasImages && isFirstSite && 3 <= parseInt( visits ) && false !== settings && true !== settings?.firstImpressions ); - }, [ visits, settings ]); - - return ( - <> - updateOption( 'optml_csat', JSON.stringify({ ...settings, firstImpressions: true }) ) } - strings={ { - title: optimoleDashboardApp.strings.csat.title, - close: optimoleDashboardApp.strings.csat.close - } } - pages={ [ - { - showHeader: true, - content: ( props ) => ( -
-
- { optimoleDashboardApp.strings.csat.heading_one } -
- -
- { [ 1, 2, 3, 4, 5 ].map( value => ( - - ) ) } -
- -
- { optimoleDashboardApp.strings.csat.low } - { optimoleDashboardApp.strings.csat.high } -
-
- ) - }, - { - showHeader: true, - content: ( props ) => ( -
-
- { optimoleDashboardApp.strings.csat.heading_two } -
- - props.changeData({ feedback }) } - /> - -
-
- - - -
-
-
- ) - } - ] } - /> - - ); -}; - -export default CSATList; diff --git a/assets/src/dashboard/parts/connected/csat/index.js b/assets/src/dashboard/parts/connected/csat/index.js deleted file mode 100644 index c2b744681..000000000 --- a/assets/src/dashboard/parts/connected/csat/index.js +++ /dev/null @@ -1,214 +0,0 @@ -/** - * External dependencies. - */ -import { - check, - closeSmall -} from '@wordpress/icons'; - -/** - * WordPress dependencies. - */ -import { - Button, - Icon -} from '@wordpress/components'; - -import { - useEffect, - useState -} from '@wordpress/element'; - -const Header = ({ - strings, - onClose -}) => { - return ( -
-

- { strings.title } -

- -
- ); -}; - -window.optimoleCSAT = { - hasSubmitted: false, - data: {} -}; - -const CSAT = ({ - id, - show = false, - strings = {}, - pages = [], - onDismiss = () => {} -}) => { - const [ isVisibile, setIsVisible ] = useState( false ); - const [ currentPage, setCurrentPage ] = useState( 0 ); - const [ hasDismissed, setHasDismissed ] = useState( false ); - const [ hasSubmitted, setHasSubmitted ] = useState( false ); - const [ data, setData ] = useState({}); - - useEffect( () => { - const beforeUnload = () => { - if ( ! window.optimoleCSAT.hasSubmitted && window.optimoleCSAT.data?.score ) { - localStorage.setItem( `optimole_csat_data_${ id }`, JSON.stringify( window.optimoleCSAT.data ) ); - } - }; - - window.addEventListener( 'beforeunload', beforeUnload ); - - return () => { - window.removeEventListener( 'beforeunload', beforeUnload ); - }; - }, []); - - useEffect( () => { - if ( show && ! hasDismissed ) { - setIsVisible( show ); - } - }, [ show ]); - - useEffect( () => { - window.optimoleCSAT = { - hasSubmitted, - data - }; - }, [ hasSubmitted, data ]); - - const onSubmit = ( dismiss = false, params = data ) => { - onDismiss(); - - if ( hasSubmitted || ! params?.score ) { - setHasDismissed( true ); - return null; - } - - const body = { - email: optimoleDashboardApp.user_data.user_email, - product: 'Optimole', - site: optimoleDashboardApp.home_url, - ...params - }; - - try { - fetch( `https://api.themeisle.com/tracking/csat/${ params?.score }`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json, */*;q=0.1', - 'Cache-Control': 'no-cache' - }, - body: JSON.stringify( body ) - }); - } catch ( e ) { - console.warn( e ); - } - - setHasSubmitted( true ); - setCurrentPage( pages.length ); - - if ( dismiss ) { - setIsVisible( false ); - setHasDismissed( true ); - } - }; - - const changeData = ( obj, skip = false ) => { - setData({ - ...data, - ...obj - }); - - if ( skip ) { - setCurrentPage( currentPage + 1 ); - } - }; - - // If localStorage has data, use it to send the request. - useEffect( () => { - const localState = localStorage.getItem( `optimole_csat_data_${ id }` ); - - if ( localState ) { - onSubmit( true, JSON.parse( localState ) ); - - localStorage.removeItem( `optimole_csat_data_${ id }` ); - } - }, []); - - const onClose = () => { - setIsVisible( false ); - setHasDismissed( true ); - onSubmit(); - }; - - if ( ! isVisibile ) { - return null; - } - - if ( 0 === pages.length ) { - return null; - } - - const canGoForward = currentPage < pages.length; - - const Content = pages[ currentPage ]?.content; - - return ( -
- - { pages[ currentPage ] && ( - <> - { pages[ currentPage ]?.showHeader && ( -
- ) } - - - - ) } - - { ! canGoForward && ( -
- - -
- { optimoleDashboardApp.strings.csat.heading_three } -
- -
- { optimoleDashboardApp.strings.csat.thank_you } -
- - -
- ) } -
- ); -}; - -export default CSAT; diff --git a/assets/src/dashboard/parts/connected/index.js b/assets/src/dashboard/parts/connected/index.js index 230a56b41..0ea56cdaa 100644 --- a/assets/src/dashboard/parts/connected/index.js +++ b/assets/src/dashboard/parts/connected/index.js @@ -19,7 +19,6 @@ import Conflicts from './conflicts'; import Settings from './settings'; import Help from './help'; import Sidebar from './Sidebar'; -import CSAT from './CSAT'; import { retrieveConflicts } from '../../utils/api'; import BlackFridayBanner from '../components/BlackFridayBanner'; @@ -124,8 +123,6 @@ const ConnectedLayout = ({ - - ); }; diff --git a/assets/src/dashboard/parts/connected/settings/index.js b/assets/src/dashboard/parts/connected/settings/index.js index 269595a3d..4bda66ecb 100644 --- a/assets/src/dashboard/parts/connected/settings/index.js +++ b/assets/src/dashboard/parts/connected/settings/index.js @@ -49,16 +49,6 @@ const Settings = ({ toggleDamSidebarLink( 'enabled' === damEnabled ); }, [ damEnabled ]); - useEffect( () => { - const visits = localStorage.getItem( 'optimole_settings_visits' ); - - if ( 3 < visits ) { - return; - } - - localStorage.setItem( 'optimole_settings_visits', visits ? parseInt( visits ) + 1 : 1 ); - }, [ tab ]); - const toggleShowSample = () => { setShowSample( ! showSample ); }; diff --git a/assets/src/dashboard/utils/use-settings.js b/assets/src/dashboard/utils/use-settings.js deleted file mode 100644 index 602adffa9..000000000 --- a/assets/src/dashboard/utils/use-settings.js +++ /dev/null @@ -1,75 +0,0 @@ -/** - * WordPress dependencies. - */ -import api from '@wordpress/api'; - -import { __ } from '@wordpress/i18n'; - -import { - useEffect, - useState -} from '@wordpress/element'; - -/** - * useSettings Hook. - * - * useSettings hook to get/update WordPress' settings database. - * - * Setting field needs to be registered to REST for this function to work. - * - * @author Hardeep Asrani - * @version 1.0 - * - */ -const useSettings = () => { - const [ settings, setSettings ] = useState({}); - const [ status, setStatus ] = useState( 'loading' ); - - const getSettings = () => { - api.loadPromise.then( async() => { - try { - const settings = new api.models.Settings(); - const response = await settings.fetch(); - setSettings( response ); - } catch ( error ) { - setStatus( 'error' ); - } finally { - setStatus( 'loaded' ); - } - }); - }; - - useEffect( () => { - getSettings(); - }, []); - - const getOption = option => { - return settings?.[option]; - }; - - const updateOption = ( option, value, success = __( 'Settings saved.', 'textdomain' ) ) => { - setStatus( 'saving' ); - - const save = new api.models.Settings({ [option]: value }).save(); - - save.success( ( response, status ) => { - if ( 'success' === status ) { - setStatus( 'loaded' ); - } - - if ( 'error' === status ) { - setStatus( 'error' ); - } - - getSettings(); - }); - - save.error( ( response ) => { - setStatus( 'error' ); - }); - }; - - return [ getOption, updateOption, status ]; -}; - -export default useSettings; diff --git a/inc/admin.php b/inc/admin.php index 609422983..69da4d742 100755 --- a/inc/admin.php +++ b/inc/admin.php @@ -2114,17 +2114,7 @@ private function get_dashboard_strings() { 'big_optimization' => __( '❤️❤️❤️ Our moles just nailed it, this one is {ratio} smaller.', 'optimole-wp' ), ], 'csat' => [ - 'title' => __( 'Your opinion matters', 'optimole-wp' ), 'close' => __( 'Close', 'optimole-wp' ), - 'heading_one' => __( 'How easy did you find to get started using Optimole, on a scale of 1 to 5?', 'optimole-wp' ), - 'heading_two' => __( 'Any specific feedback you would like to add?', 'optimole-wp' ), - 'heading_three' => __( 'Thank you!', 'optimole-wp' ), - 'low' => __( 'Very Poor', 'optimole-wp' ), - 'high' => __( 'Excellent', 'optimole-wp' ), - 'feedback_placeholder' => __( 'Add your feedback here (optional)', 'optimole-wp' ), - 'skip' => __( 'Skip', 'optimole-wp' ), - 'submit' => __( 'Submit', 'optimole-wp' ), - 'thank_you' => __( 'Your input is highly appreciated and helps us shape a better experience in Optimole.', 'optimole-wp' ), ], 'cron_error' => sprintf( /* translators: 1 is code to disable cron, 2 value of the constant */ __( 'It seems that you have the %1$s constant defined as %2$s. The offloading process uses cron events to offload the images in the background. Please remove the constant from your wp-config.php file in order for the offloading process to work.', 'optimole-wp' ), 'DISABLE_WP_CRON', 'true' ), 'cancel' => __( 'Cancel', 'optimole-wp' ), diff --git a/inc/settings.php b/inc/settings.php index de6ab74ea..b4050c92e 100644 --- a/inc/settings.php +++ b/inc/settings.php @@ -172,8 +172,6 @@ public function __construct() { } } } - - add_action( 'init', [ $this, 'register_settings' ] ); } /** @@ -734,24 +732,6 @@ public function get_raw_settings() { return get_option( $this->namespace, false ); } - /** - * Get settings for CSAT. - * - * @return void - */ - public function register_settings() { - register_setting( - 'optml_settings', - 'optml_csat', - [ - 'type' => 'string', - 'sanitize_callback' => 'sanitize_text_field', - 'show_in_rest' => true, - 'default' => '{}', - ] - ); - } - /** * Clear cache.