Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

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

## [8.14.0]

### Updated

- Dependencies to the latest version.

### Changed

- 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.

## [8.13.0]

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

- Initial production release.

[8.14.0]: https://github.com/infinum/eightshift-forms/compare/8.13.0...8.14.0
[8.13.0]: https://github.com/infinum/eightshift-forms/compare/8.12.1...8.13.0
[8.12.1]: https://github.com/infinum/eightshift-forms/compare/8.12.0...8.12.1
[8.12.0]: https://github.com/infinum/eightshift-forms/compare/8.11.0...8.12.0
Expand Down
14 changes: 9 additions & 5 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eightshift-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 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.
* Author: WordPress team @Infinum
* Author URI: https://eightshift.com/
* Version: 8.13.0
* Version: 8.14.0
* Text Domain: eightshift-forms
*
* @package EightshiftForms
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test:e2e:report:pdf": "node tests/e2e/helpers/generate-pdf-report.js"
},
"devDependencies": {
"@playwright/test": "^1.57.0",
"@playwright/test": "^1.58.0",
"husky": "^9.1.7",
"webpack": "^5.104.1",
"webpack-cli": "^6.0.1",
Expand All @@ -43,8 +43,8 @@
"@eightshift/frontend-libs": "^12.1.9",
"@eightshift/ui-components": "^5.6.1",
"autosize": "^6.0.1",
"baseline-browser-mapping": "^2.9.16",
"caniuse-lite": "^1.0.30001765",
"baseline-browser-mapping": "^2.9.18",
"caniuse-lite": "^1.0.30001766",
"choices.js": "^11.1.0",
"dropzone": "^6.0.0-beta.2",
"flatpickr": "^4.6.13",
Expand Down
8 changes: 4 additions & 4 deletions src/Blocks/components/form/assets/geolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export class Geolocation {
*/
onSetSelectField = (event) => {
const { formId } = event.detail;
const countryCookie = cookies?.getCookie('esForms-country')?.toLocaleLowerCase();
const location = this.state.getStateGeolocationLocation()?.toLocaleLowerCase();

if (!countryCookie || countryCookie.length !== 2) {
if (location === '' || location === 'localhost') {
return;
}

Expand All @@ -73,10 +73,10 @@ export class Geolocation {

switch (type) {
case 'country':
this.utils.setManualSelectByAttributeValue(formId, name, [countryCookie], this.state.getStateAttribute('countryCode'));
this.utils.setManualSelectByAttributeValue(formId, name, [location], this.state.getStateAttribute('countryCode'));
break;
case 'phone':
this.utils.setManualPhonePrefixByAttributeValue(formId, name, countryCookie, this.state.getStateAttribute('countryCode'));
this.utils.setManualPhonePrefixByAttributeValue(formId, name, location, this.state.getStateAttribute('countryCode'));
break;
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/Blocks/components/form/assets/state-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const StateEnum = {
ENRICHMENT_ALLOWED_SMART: 'allowedSmart',

GEOLOCATION: 'geolocation',
GEOLOCATION_LOCATION: 'location',

TRACKING: 'tracking',

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

// Enrichment.
const enrichment = esFormsLocalization.enrichment ?? {};
Expand Down
3 changes: 3 additions & 0 deletions src/Blocks/components/form/assets/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ export class State {
getStateGeolocationIsUsed = () => {
return getState([StateEnum.IS_USED], StateEnum.GEOLOCATION) && !getState([StateEnum.IS_ADMIN], StateEnum.CONFIG);
};
getStateGeolocationLocation = () => {
return getState([StateEnum.GEOLOCATION_LOCATION], StateEnum.GEOLOCATION);
};

////////////////////////////////////////////////////////////////
// Enrichment getters.
Expand Down
13 changes: 12 additions & 1 deletion src/Enqueue/Blocks/EnqueueBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use EightshiftForms\CustomPostType\Forms;
use EightshiftForms\Enqueue\SharedEnqueue;
use EightshiftForms\Enqueue\Captcha\EnqueueCaptcha;
use EightshiftForms\Geolocation\GeolocationInterface;
use EightshiftForms\Geolocation\SettingsGeolocation;
use EightshiftForms\Hooks\FiltersOutputMock;
use EightshiftForms\Validation\ValidationPatterns;
Expand Down Expand Up @@ -47,14 +48,23 @@ class EnqueueBlocks extends AbstractEnqueueBlocks
*/
protected EnrichmentInterface $enrichment;

/**
* Instance variable of geolocation data.
*
* @var GeolocationInterface
*/
protected GeolocationInterface $geolocation;

/**
* Create a new admin instance.
*
* @param EnrichmentInterface $enrichment Inject enrichment which holds data about for storing to enrichment.
* @param GeolocationInterface $geolocation Inject geolocation which holds data about for storing to geolocation.
*/
public function __construct(EnrichmentInterface $enrichment)
public function __construct(EnrichmentInterface $enrichment, GeolocationInterface $geolocation)
{
$this->enrichment = $enrichment;
$this->geolocation = $geolocation;
}

/**
Expand Down Expand Up @@ -316,6 +326,7 @@ public function enqueueBlockFrontendScript(): void
// Geolocation config.
$output['geolocation'] = [
'isUsed' => \apply_filters(SettingsGeolocation::FILTER_SETTINGS_GLOBAL_IS_VALID_NAME, false),
'location' => $this->geolocation->getUsersGeolocation(),
];

// Check if Captcha data is set and valid.
Expand Down
9 changes: 0 additions & 9 deletions src/Geolocation/Geolocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,13 @@
*/
class Geolocation extends AbstractGeolocation implements GeolocationInterface
{
/**
* Geolocation check if user is geolocate constant.
*
* @var string
*/
public const GEOLOCATION_IS_USER_LOCATED = 'es_geolocation_is_user_located';

/**
* Register all the hooks
*/
public function register(): void
{
// Use normal geolocation detection from db.
\add_action('init', [$this, 'setNormalLocationCookie']);

\add_filter(self::GEOLOCATION_IS_USER_LOCATED, [$this, 'isUserGeolocated'], 10, 3);
}

/**
Expand Down