Skip to content

Commit 516f5ac

Browse files
authored
8.14.0 (#584)
* update geo logic
1 parent 963859f commit 516f5ac

File tree

10 files changed

+57
-35
lines changed

10 files changed

+57
-35
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44

55
This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).
66

7+
## [8.14.0]
8+
9+
### Updated
10+
11+
- Dependencies to the latest version.
12+
13+
### Changed
14+
15+
- Geolocation is now using new way of detecting user's geolocation by providing data to the JS state via PHP code. Cookie will be set but manually changing the value on the frontend will not work anymore.
16+
717
## [8.13.0]
818

919
### Added
@@ -1661,6 +1671,7 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a
16611671

16621672
- Initial production release.
16631673

1674+
[8.14.0]: https://github.com/infinum/eightshift-forms/compare/8.13.0...8.14.0
16641675
[8.13.0]: https://github.com/infinum/eightshift-forms/compare/8.12.1...8.13.0
16651676
[8.12.1]: https://github.com/infinum/eightshift-forms/compare/8.12.0...8.12.1
16661677
[8.12.0]: https://github.com/infinum/eightshift-forms/compare/8.11.0...8.12.0

bun.lock

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eightshift-forms.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Description: Eightshift Forms is a complete form builder plugin that utilizes modern Block editor features with multiple third-party integrations, bringing your project to a new level.
77
* Author: WordPress team @Infinum
88
* Author URI: https://eightshift.com/
9-
* Version: 8.13.0
9+
* Version: 8.14.0
1010
* Text Domain: eightshift-forms
1111
*
1212
* @package EightshiftForms

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"test:e2e:report:pdf": "node tests/e2e/helpers/generate-pdf-report.js"
3434
},
3535
"devDependencies": {
36-
"@playwright/test": "^1.57.0",
36+
"@playwright/test": "^1.58.0",
3737
"husky": "^9.1.7",
3838
"webpack": "^5.104.1",
3939
"webpack-cli": "^6.0.1",
@@ -43,8 +43,8 @@
4343
"@eightshift/frontend-libs": "^12.1.9",
4444
"@eightshift/ui-components": "^5.6.1",
4545
"autosize": "^6.0.1",
46-
"baseline-browser-mapping": "^2.9.16",
47-
"caniuse-lite": "^1.0.30001765",
46+
"baseline-browser-mapping": "^2.9.18",
47+
"caniuse-lite": "^1.0.30001766",
4848
"choices.js": "^11.1.0",
4949
"dropzone": "^6.0.0-beta.2",
5050
"flatpickr": "^4.6.13",

src/Blocks/components/form/assets/geolocation.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ export class Geolocation {
6060
*/
6161
onSetSelectField = (event) => {
6262
const { formId } = event.detail;
63-
const countryCookie = cookies?.getCookie('esForms-country')?.toLocaleLowerCase();
63+
const location = this.state.getStateGeolocationLocation()?.toLocaleLowerCase();
6464

65-
if (!countryCookie || countryCookie.length !== 2) {
65+
if (location === '' || location === 'localhost') {
6666
return;
6767
}
6868

@@ -73,10 +73,10 @@ export class Geolocation {
7373

7474
switch (type) {
7575
case 'country':
76-
this.utils.setManualSelectByAttributeValue(formId, name, [countryCookie], this.state.getStateAttribute('countryCode'));
76+
this.utils.setManualSelectByAttributeValue(formId, name, [location], this.state.getStateAttribute('countryCode'));
7777
break;
7878
case 'phone':
79-
this.utils.setManualPhonePrefixByAttributeValue(formId, name, countryCookie, this.state.getStateAttribute('countryCode'));
79+
this.utils.setManualPhonePrefixByAttributeValue(formId, name, location, this.state.getStateAttribute('countryCode'));
8080
break;
8181
}
8282
});

src/Blocks/components/form/assets/state-init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export const StateEnum = {
111111
ENRICHMENT_ALLOWED_SMART: 'allowedSmart',
112112

113113
GEOLOCATION: 'geolocation',
114+
GEOLOCATION_LOCATION: 'location',
114115

115116
TRACKING: 'tracking',
116117

@@ -268,6 +269,7 @@ export function setStateInitial() {
268269
// Geolocation.
269270
const geolocation = esFormsLocalization.geolocation ?? {};
270271
setState([StateEnum.IS_USED], Boolean(geolocation.isUsed), StateEnum.GEOLOCATION);
272+
setState([StateEnum.GEOLOCATION_LOCATION], geolocation.location, StateEnum.GEOLOCATION);
271273

272274
// Enrichment.
273275
const enrichment = esFormsLocalization.enrichment ?? {};

src/Blocks/components/form/assets/state.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ export class State {
438438
getStateGeolocationIsUsed = () => {
439439
return getState([StateEnum.IS_USED], StateEnum.GEOLOCATION) && !getState([StateEnum.IS_ADMIN], StateEnum.CONFIG);
440440
};
441+
getStateGeolocationLocation = () => {
442+
return getState([StateEnum.GEOLOCATION_LOCATION], StateEnum.GEOLOCATION);
443+
};
441444

442445
////////////////////////////////////////////////////////////////
443446
// Enrichment getters.

src/Enqueue/Blocks/EnqueueBlocks.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use EightshiftForms\CustomPostType\Forms;
2121
use EightshiftForms\Enqueue\SharedEnqueue;
2222
use EightshiftForms\Enqueue\Captcha\EnqueueCaptcha;
23+
use EightshiftForms\Geolocation\GeolocationInterface;
2324
use EightshiftForms\Geolocation\SettingsGeolocation;
2425
use EightshiftForms\Hooks\FiltersOutputMock;
2526
use EightshiftForms\Validation\ValidationPatterns;
@@ -47,14 +48,23 @@ class EnqueueBlocks extends AbstractEnqueueBlocks
4748
*/
4849
protected EnrichmentInterface $enrichment;
4950

51+
/**
52+
* Instance variable of geolocation data.
53+
*
54+
* @var GeolocationInterface
55+
*/
56+
protected GeolocationInterface $geolocation;
57+
5058
/**
5159
* Create a new admin instance.
5260
*
5361
* @param EnrichmentInterface $enrichment Inject enrichment which holds data about for storing to enrichment.
62+
* @param GeolocationInterface $geolocation Inject geolocation which holds data about for storing to geolocation.
5463
*/
55-
public function __construct(EnrichmentInterface $enrichment)
64+
public function __construct(EnrichmentInterface $enrichment, GeolocationInterface $geolocation)
5665
{
5766
$this->enrichment = $enrichment;
67+
$this->geolocation = $geolocation;
5868
}
5969

6070
/**
@@ -316,6 +326,7 @@ public function enqueueBlockFrontendScript(): void
316326
// Geolocation config.
317327
$output['geolocation'] = [
318328
'isUsed' => \apply_filters(SettingsGeolocation::FILTER_SETTINGS_GLOBAL_IS_VALID_NAME, false),
329+
'location' => $this->geolocation->getUsersGeolocation(),
319330
];
320331

321332
// Check if Captcha data is set and valid.

src/Geolocation/Geolocation.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,13 @@
2424
*/
2525
class Geolocation extends AbstractGeolocation implements GeolocationInterface
2626
{
27-
/**
28-
* Geolocation check if user is geolocate constant.
29-
*
30-
* @var string
31-
*/
32-
public const GEOLOCATION_IS_USER_LOCATED = 'es_geolocation_is_user_located';
33-
3427
/**
3528
* Register all the hooks
3629
*/
3730
public function register(): void
3831
{
3932
// Use normal geolocation detection from db.
4033
\add_action('init', [$this, 'setNormalLocationCookie']);
41-
42-
\add_filter(self::GEOLOCATION_IS_USER_LOCATED, [$this, 'isUserGeolocated'], 10, 3);
4334
}
4435

4536
/**

0 commit comments

Comments
 (0)