2023-09-27 19:48:59 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-07-29 13:30:03 +00:00
|
|
|
import { createRoot } from '@wordpress/element';
|
2024-08-16 01:42:08 +00:00
|
|
|
import { decodeEntities } from '@wordpress/html-entities';
|
2023-09-27 19:48:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { RegionPicker } from './region-picker';
|
2023-10-24 22:51:52 +00:00
|
|
|
import { ShippingCurrencyContext } from './currency-context';
|
2024-08-16 01:42:08 +00:00
|
|
|
import { recursivelyTransformLabels } from './utils';
|
2023-09-27 19:48:59 +00:00
|
|
|
|
|
|
|
const shippingZoneRegionPickerRoot = document.getElementById(
|
|
|
|
'wc-shipping-zone-region-picker-root'
|
|
|
|
);
|
|
|
|
|
2024-08-16 01:42:08 +00:00
|
|
|
const options =
|
|
|
|
recursivelyTransformLabels(
|
|
|
|
window.shippingZoneMethodsLocalizeScript?.region_options,
|
|
|
|
decodeEntities
|
|
|
|
) ?? [];
|
2023-09-27 19:48:59 +00:00
|
|
|
const initialValues = window.shippingZoneMethodsLocalizeScript?.locations ?? [];
|
|
|
|
|
2024-08-16 01:42:08 +00:00
|
|
|
const ShippingApp = () => {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<ShippingCurrencyContext />
|
|
|
|
<RegionPicker options={ options } initialValues={ initialValues } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2023-10-24 22:51:52 +00:00
|
|
|
|
2023-09-27 19:48:59 +00:00
|
|
|
if ( shippingZoneRegionPickerRoot ) {
|
2024-07-29 13:30:03 +00:00
|
|
|
createRoot( shippingZoneRegionPickerRoot ).render( <ShippingApp /> );
|
2023-09-27 19:48:59 +00:00
|
|
|
}
|