Skip to content

Commit

Permalink
fix: php7.4 comma
Browse files Browse the repository at this point in the history
  • Loading branch information
vermorag committed Nov 20, 2024
1 parent 6512ae3 commit ddafbaf
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/CdekApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
117 changes: 63 additions & 54 deletions src/Frontend/AdminSettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div class="city-suggest__404">' +
__('Nothing found', 'cdekdelivery') + '</div>');
return;
}

$('.city-suggest__404').remove();
$('.city-suggest__item').remove();

r.data.forEach(e => {
$('.city-suggest')
.append($('<div class="city-suggest__item"></div>')
.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('<div class="city-suggest__404">' +
__('Nothing found', 'cdekdelivery') + '</div>');
return;
}
__('Temporal error, try again', 'cdekdelivery') + '</div>');
}).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($('<div class="city-suggest__item"></div>')
.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('<div class="city-suggest"></div>')
.after('<span class="city-loader"></span>');

suggest(this.value);
});
}).catch(() => {
$('.city-suggest__404').remove();
$('.city-suggest__item').remove();

$('.city-suggest')
.append('<div class="city-suggest__404">' +
__('Temporal error, try again', 'cdekdelivery') + '</div>');
}).finally(() => $('.city-loader').remove()), 900);

$('input#woocommerce_official_cdek_city').on('input', function() {
$('.city-suggest').remove();
$('.city-loader').remove();

$(this)
.after('<div class="city-suggest"></div>')
.after('<span class="city-loader"></span>');

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(<DeliveryPrice input={deliveryRulesInput} />, div);
} else {
createRoot(div).render(<DeliveryPrice input={deliveryRulesInput} />);

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(<DeliveryPrice input={deliveryRulesInput} />);
} else {
render(<DeliveryPrice input={deliveryRulesInput} />, div);
}
} else {
render(<DeliveryPrice input={deliveryRulesInput} />, div);
}
}
}

(() => {
const banAttachmentCheckbox = $(
'#woocommerce_official_cdek_services_ban_attachment_inspection');
const tryingOnCheckbox = $('#woocommerce_official_cdek_services_trying_on');
Expand Down

0 comments on commit ddafbaf

Please sign in to comment.