store
1 year ago
AddonRow.jsx
1 year ago
App.jsx
1 year ago
Metabox.jsx
1 year ago
Modal.jsx
1 year ago
Notices.jsx
1 year ago
Select2.jsx
1 year ago
Settings.jsx
1 year ago
Step1.jsx
1 year ago
Step2.jsx
1 year ago
Step3.jsx
1 year ago
StepWrapper.jsx
1 year ago
main.js
1 year ago
Settings.jsx
161 lines
| 1 | /** |
| 2 | * External Dependencies |
| 3 | */ |
| 4 | import jQuery from 'jquery'; |
| 5 | |
| 6 | /** |
| 7 | * WordPress Dependencies |
| 8 | */ |
| 9 | import { useContext } from '@wordpress/element'; |
| 10 | |
| 11 | /** |
| 12 | * Internal Dependencies |
| 13 | */ |
| 14 | import { OneClickContext } from './store/context'; |
| 15 | import { noticeSuccess, noticeError } from './Notices'; |
| 16 | import actions from './store/actions'; |
| 17 | |
| 18 | function updateSetting(module, status) { |
| 19 | return jQuery.ajax({ |
| 20 | url: ajaxurl, |
| 21 | method: 'POST', |
| 22 | data: { |
| 23 | action: 'pubguru_module_change', |
| 24 | security: advancedAds.oneclick.security, |
| 25 | module, |
| 26 | status, |
| 27 | }, |
| 28 | }); |
| 29 | } |
| 30 | |
| 31 | function backupAdsTxt() { |
| 32 | return jQuery.ajax({ |
| 33 | url: ajaxurl, |
| 34 | method: 'POST', |
| 35 | data: { |
| 36 | action: 'pubguru_backup_ads_txt', |
| 37 | security: advancedAds.oneclick.security, |
| 38 | }, |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | function Setting({ id, label, className, option, disabled = false, children }) { |
| 43 | const { settings, updateSettings } = useContext(OneClickContext); |
| 44 | const checked = settings[option] ?? false; |
| 45 | const name = id.replace(/-/g, '_').replace('pubguru_', ''); |
| 46 | |
| 47 | const onChange = (event) => { |
| 48 | const status = event.target.checked |
| 49 | updateSetting(name, status) |
| 50 | .done((response) => { |
| 51 | if ( response.data.notice && '' !== response.data.notice ) { |
| 52 | noticeError( |
| 53 | response.data.notice, |
| 54 | response.data.action ? { |
| 55 | actions: [ |
| 56 | { |
| 57 | label: response.data.action, |
| 58 | onClick: (event, remove) => { |
| 59 | event.target.disabled = true; |
| 60 | backupAdsTxt() |
| 61 | .done((response) => { |
| 62 | remove(); |
| 63 | event.target.disabled = false; |
| 64 | if ( response.success ) { |
| 65 | noticeSuccess(response.data); |
| 66 | } else { |
| 67 | noticeError(response.data); |
| 68 | } |
| 69 | }) |
| 70 | .error((response) => { |
| 71 | event.target.disabled = false; |
| 72 | noticeError('Error: ' + response.statusText); |
| 73 | }); |
| 74 | }, |
| 75 | }, |
| 76 | ] |
| 77 | } : null |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | updateSettings(option, status); |
| 82 | }); |
| 83 | }; |
| 84 | |
| 85 | return ( |
| 86 | <div className={className}> |
| 87 | <label htmlFor={id} className="advads-ui-switch"> |
| 88 | <input |
| 89 | type="checkbox" |
| 90 | id={id} |
| 91 | checked={checked} |
| 92 | onChange={onChange} |
| 93 | disabled={disabled} |
| 94 | /> |
| 95 | <div></div> |
| 96 | <span dangerouslySetInnerHTML={{ __html: label }} /> |
| 97 | {children} |
| 98 | </label> |
| 99 | </div> |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | export default function Settings() { |
| 104 | const { settings } = advancedAds.oneclick; |
| 105 | const { settings: options, selectedMethod } = useContext(OneClickContext); |
| 106 | const disabled = 'page' === selectedMethod; |
| 107 | let headerBiddingLabel = settings.headerBidding; |
| 108 | if (disabled) { |
| 109 | headerBiddingLabel += ' <em class="muted">' + settings.onlyPreview + '</em>' |
| 110 | } |
| 111 | |
| 112 | return ( |
| 113 | <div className="mb-8"> |
| 114 | <div className="subheader inline">{settings.title}</div> |
| 115 | |
| 116 | <div className="advads-ui-switch-list mt-6"> |
| 117 | <Setting |
| 118 | id="pubguru-header-bidding" |
| 119 | label={headerBiddingLabel} |
| 120 | option="headerBidding" |
| 121 | disabled={disabled} |
| 122 | /> |
| 123 | |
| 124 | {options.headerBidding && ( |
| 125 | <Setting |
| 126 | id="pubguru-header-bidding-at-body" |
| 127 | label={settings.scriptLocation} |
| 128 | className="ml-4" |
| 129 | option="headerBiddingAtBody" |
| 130 | /> |
| 131 | )} |
| 132 | |
| 133 | <Setting |
| 134 | id="pubguru-ads-txt" |
| 135 | label={settings.adsTxt} |
| 136 | option="adsTxt" |
| 137 | /> |
| 138 | |
| 139 | <Setting |
| 140 | id="pubguru-traffic-cop" |
| 141 | label={settings.trafficCop} |
| 142 | option="trafficCop" |
| 143 | > |
| 144 | {settings.hasTrafficCop && (<span className="pg-tc-trail"> |
| 145 | {settings.trafficCopTrial} |
| 146 | </span>)} |
| 147 | </Setting> |
| 148 | |
| 149 | <Setting |
| 150 | id="pubguru-tag-conversion" |
| 151 | className="hidden" |
| 152 | label={settings.activateTags} |
| 153 | option="tagConversion" |
| 154 | /> |
| 155 | </div> |
| 156 | |
| 157 | <p dangerouslySetInnerHTML={{ __html: settings.help }}></p> |
| 158 | </div> |
| 159 | ); |
| 160 | } |
| 161 |