From ddafbafabc4e971b6c1eb38538213c4df43f7ee4 Mon Sep 17 00:00:00 2001 From: AlexV Date: Wed, 20 Nov 2024 14:53:00 +0700 Subject: [PATCH] fix: php7.4 comma --- src/CdekApi.php | 2 +- src/Frontend/AdminSettings/index.js | 117 +++++++++++++++------------- 2 files changed, 64 insertions(+), 55 deletions(-) diff --git a/src/CdekApi.php b/src/CdekApi.php index 4ee9d1d..a25412d 100644 --- a/src/CdekApi.php +++ b/src/CdekApi.php @@ -152,7 +152,7 @@ public function cityCodeGet(string $city, string $postcode): ?string */ private function cityCodeGetWithFallback( string $city, - ?string $postcode = null, + ?string $postcode = null ): ?string { try { $result = HttpClient::sendJsonRequest( diff --git a/src/Frontend/AdminSettings/index.js b/src/Frontend/AdminSettings/index.js index 3791836..8544353 100644 --- a/src/Frontend/AdminSettings/index.js +++ b/src/Frontend/AdminSettings/index.js @@ -7,67 +7,76 @@ import { DeliveryPrice } from './components/DeliveryPrice'; import apiFetch from '@wordpress/api-fetch'; import { addQueryArgs } from '@wordpress/url'; -const suggest = debounce((q) => apiFetch({ - url: addQueryArgs(ajaxurl, { - action: `${window.cdek.prefix}-cities`, _wpnonce: window.cdek.nonce, q, - }), -}).then(r => { - if (r.data.length === 0) { +(() => { + const suggest = debounce((q) => apiFetch({ + url: addQueryArgs(ajaxurl, { + action: `${window.cdek.prefix}-cities`, + _wpnonce: window.cdek.nonce, + q, + }), + }).then(r => { + if (r.data.length === 0) { + $('.city-suggest') + .append('
' + + __('Nothing found', 'cdekdelivery') + '
'); + return; + } + + $('.city-suggest__404').remove(); + $('.city-suggest__item').remove(); + + r.data.forEach(e => { + $('.city-suggest') + .append($('
') + .html(e.full_name) + .on('click', () => { + $('input#woocommerce_official_cdek_city') + .val(e.full_name.split(',', 2)[0]); + $('input#woocommerce_official_cdek_city_code') + .val(e.code); + $('.city-suggest').remove(); + })); + }); + }).catch(() => { + $('.city-suggest__404').remove(); + $('.city-suggest__item').remove(); + $('.city-suggest') .append('
' + - __('Nothing found', 'cdekdelivery') + '
'); - return; - } + __('Temporal error, try again', 'cdekdelivery') + ''); + }).finally(() => $('.city-loader').remove()), 900); - $('.city-suggest__404').remove(); - $('.city-suggest__item').remove(); + $('input#woocommerce_official_cdek_city').on('input', function() { + $('.city-suggest').remove(); + $('.city-loader').remove(); - r.data.forEach(e => { - $('.city-suggest') - .append($('
') - .html(e.full_name) - .on('click', () => { - $('input#woocommerce_official_cdek_city') - .val(e.full_name.split(',', 2)[0]); - $('input#woocommerce_official_cdek_city_code') - .val(e.code); - $('.city-suggest').remove(); - })); + $(this) + .after('
') + .after(''); + + suggest(this.value); }); -}).catch(() => { - $('.city-suggest__404').remove(); - $('.city-suggest__item').remove(); - - $('.city-suggest') - .append('
' + - __('Temporal error, try again', 'cdekdelivery') + '
'); -}).finally(() => $('.city-loader').remove()), 900); - -$('input#woocommerce_official_cdek_city').on('input', function() { - $('.city-suggest').remove(); - $('.city-loader').remove(); - - $(this) - .after('
') - .after(''); - - suggest(this.value); -}); - -const deliveryRulesInput = $( - 'input#woocommerce_official_cdek_delivery_price_rules'); - -if (deliveryRulesInput.length) { - const div = window.document.createElement('div'); - deliveryRulesInput.after(div); - if (typeof render === 'function') { - render(, div); - } else { - createRoot(div).render(); + + const deliveryRulesInput = $( + 'input#woocommerce_official_cdek_delivery_price_rules'); + + if (deliveryRulesInput.length) { + const div = window.document.createElement('div'); + deliveryRulesInput.after(div); + + if (createRoot !== undefined) { + const root = createRoot(div); + + if (root !== undefined && typeof root.render === 'function') { + root.render(); + } else { + render(, div); + } + } else { + render(, div); + } } -} -(() => { const banAttachmentCheckbox = $( '#woocommerce_official_cdek_services_ban_attachment_inspection'); const tryingOnCheckbox = $('#woocommerce_official_cdek_services_trying_on');