inputs
1 year ago
wizard
1 year ago
Divider.jsx
1 year ago
ErrorMessage.jsx
1 year ago
Preloader.jsx
1 year ago
SelectAccount.jsx
1 year ago
SelectAccount.jsx
57 lines
| 1 | import { wizard } from '@advancedAds/i18n'; |
| 2 | |
| 3 | export default function SelectAccount({ accounts, tokenData, done, fail }) { |
| 4 | const params = new URLSearchParams(document.location.search); |
| 5 | const options = [ |
| 6 | <option value="" key="select-account"> |
| 7 | {wizard.selectAccount.optionZero} |
| 8 | </option>, |
| 9 | ]; |
| 10 | |
| 11 | for (const id in accounts) { |
| 12 | options.push( |
| 13 | <option value={JSON.stringify(accounts[id])} key={id}> |
| 14 | {accounts[id].name} ({id}) |
| 15 | </option> |
| 16 | ); |
| 17 | } |
| 18 | |
| 19 | const saveSelection = function (event) { |
| 20 | if (!event.target.value) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | event.target.disabled = true; |
| 25 | const account = JSON.parse(event.target.value); |
| 26 | |
| 27 | wp.ajax |
| 28 | .post('advads_gadsense_mapi_select_account', { |
| 29 | nonce: params.get('nonce'), |
| 30 | account, |
| 31 | token_data: tokenData, |
| 32 | }) |
| 33 | .done(function (response) { |
| 34 | if ('function' === typeof done) { |
| 35 | done.call(null, response); |
| 36 | } |
| 37 | }) |
| 38 | .fail(function (response) { |
| 39 | if ('function' === typeof fail) { |
| 40 | fail.call(null, response); |
| 41 | } |
| 42 | event.target.disabled = false; |
| 43 | }); |
| 44 | }; |
| 45 | |
| 46 | return ( |
| 47 | <> |
| 48 | <h2>{wizard.selectAccount.title}</h2> |
| 49 | <label htmlFor="g-account"> |
| 50 | <select id="g-account" onChange={(ev) => saveSelection(ev)}> |
| 51 | {options} |
| 52 | </select> |
| 53 | </label> |
| 54 | </> |
| 55 | ); |
| 56 | } |
| 57 |