/** * External Dependencies */ import jQuery from 'jquery'; /** * WordPress Dependencies */ import { useContext } from '@wordpress/element'; /** * Internal Dependencies */ import { OneClickContext } from './store/context'; import { noticeSuccess, noticeError } from './Notices'; function updateSetting( module, status ) { return jQuery.ajax( { url: ajaxurl, method: 'POST', data: { action: 'advads_pubguru_module_change', security: advancedAds.oneclick.security, module, status, }, } ); } function backupAdsTxt() { return jQuery.ajax( { url: ajaxurl, method: 'POST', data: { action: 'advads_pubguru_backup_ads_txt', security: advancedAds.oneclick.security, }, } ); } function Setting( { id, label, className, option, disabled = false, children, } ) { const { settings, updateSettings } = useContext( OneClickContext ); const checked = settings[ option ] ?? false; const name = id.replace( /-/g, '_' ).replace( 'pubguru_', '' ); const onChange = ( event ) => { const status = event.target.checked; updateSetting( name, status ).done( ( response ) => { if ( response.data.notice && '' !== response.data.notice ) { noticeError( response.data.notice, response.data.action ? { actions: [ { label: response.data.action, onClick: ( clickEvent, remove ) => { clickEvent.target.disabled = true; backupAdsTxt() .done( ( backupResponse ) => { remove(); clickEvent.target.disabled = false; if ( backupResponse.success ) { noticeSuccess( backupResponse.data ); } else { noticeError( backupResponse.data ); } } ) .error( ( backupResponse ) => { clickEvent.target.disabled = false; noticeError( 'Error: ' + backupResponse.statusText ); } ); }, }, ], } : null ); } updateSettings( option, status ); } ); }; return (
); } export default function Settings() { const { settings } = advancedAds.oneclick; const { settings: options, selectedMethod } = useContext( OneClickContext ); const disabled = 'page' === selectedMethod; let headerBiddingLabel = settings.headerBidding; if ( disabled ) { headerBiddingLabel += '  ' + settings.onlyPreview + ''; } return (
{ settings.title }
{ options.headerBidding && ( ) } { settings.hasTrafficCop && ( { settings.trafficCopTrial } ) }

); }