Skip to content

Commit

Permalink
Merge pull request #4217 from Codeinwp/fix/formbricks-loading
Browse files Browse the repository at this point in the history
Use Formbricks survey from SDK
  • Loading branch information
preda-bogdan authored Mar 28, 2024
2 parents 5d0f063 + 82c4f6a commit 6fa26d4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
include:
- specs: "customizer"
envs: "sample-data"
- specs: "tpc"
- specs: "admin"
envs: "sample-data"
- specs: "visual-regression"
envs: "sample-data"
Expand Down
39 changes: 18 additions & 21 deletions assets/apps/dashboard/src/utils/survey.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* This file is used to initialize the FormBricks survey.
*/
import formbricks from '@formbricks/js';

/**
* Take the number of days since install and convert it to a category for NPS user profile.
*
Expand All @@ -26,21 +21,23 @@ const convertToCategory = (number, scale = 1) => {
};

if ('undefined' !== typeof window && 'undefined' !== typeof window.neveDash) {
formbricks.init({
environmentId: 'clr0ply35522h8up0bay2de4y',
apiHost: 'https://app.formbricks.com',
userId:
'neve_' +
(window.neveDash?.license?.key ??
window.neveDash?.rootUrl?.replace(/[^\w\d]*/g, '')),
attributes: {
plan: window.neveDash?.pro ? window.neveDash?.license?.tier : 0,
days_since_install: convertToCategory(
window.neveDash.daysSinceInstall
),
license_status: window.neveDash?.license?.valid ?? 'invalid',
free_version: window.neveDash?.version,
pro_version: window.neveDash?.proPluginVersion,
},
window.addEventListener('themeisle:survey:loaded', function () {
window?.tsdk_formbricks?.init?.({
environmentId: 'clr0ply35522h8up0bay2de4y',
apiHost: 'https://app.formbricks.com',
userId:
'neve_' +
(window.neveDash?.license?.key ??
window.neveDash?.rootUrl?.replace(/[^\w\d]*/g, '')),
attributes: {
plan: window.neveDash?.pro ? window.neveDash?.license?.tier : 0,
days_since_install: convertToCategory(
window.neveDash.daysSinceInstall
),
license_status: window.neveDash?.license?.valid ?? 'invalid',
free_version: window.neveDash?.version,
pro_version: window.neveDash?.proPluginVersion,
},
});
});
}
12 changes: 12 additions & 0 deletions e2e-tests/specs/admin/dashboard-survey.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from '@playwright/test';

test.describe('Survey', () => {
test('NPS survey loading in dashboard', async ({ page }) => {
const requestPromise = page.waitForRequest(/survey_deps/);
await page.goto('wp-admin/admin.php?page=neve-welcome');

const request = await requestPromise;
expect(request).not.toBeNull();
expect((await request.response())?.status()).toBe(200);
});
});
5 changes: 4 additions & 1 deletion inc/admin/dashboard/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,13 @@ public function enqueue() {
$build_path = get_template_directory_uri() . '/assets/apps/dashboard/build/';
$dependencies = ( include get_template_directory() . '/assets/apps/dashboard/build/dashboard.asset.php' );

$survey_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'survey' );
do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' );

wp_register_style( 'neve-dash-style', $build_path . 'style-dashboard.css', [ 'wp-components', 'neve-components' ], $dependencies['version'] );
wp_style_add_data( 'neve-dash-style', 'rtl', 'replace' );
wp_enqueue_style( 'neve-dash-style' );
wp_register_script( 'neve-dash-script', $build_path . 'dashboard.js', array_merge( $dependencies['dependencies'], [ 'updates' ] ), $dependencies['version'], true );
wp_register_script( 'neve-dash-script', $build_path . 'dashboard.js', array_merge( $dependencies['dependencies'], [ 'updates', $survey_handler ] ), $dependencies['version'], true );
wp_localize_script( 'neve-dash-script', 'neveDash', apply_filters( 'neve_dashboard_page_data', $this->get_localization() ) );
wp_enqueue_script( 'neve-dash-script' );

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"pre-commit": "npx lint-staged"
},
"dependencies": {
"@formbricks/js": "^1.4.1",
"@neve-wp/components": "file:./assets/apps/components",
"array-move": "^3.0.1",
"classnames": "^2.2.6",
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2174,11 +2174,6 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"

"@formbricks/js@^1.4.1":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@formbricks/js/-/js-1.4.1.tgz#2dbba3463a0942a01e271a49021c1d90556a391b"
integrity sha512-lL+DsPAIdoiOPPQ4OX7bXOjvygGbD+hqU2nfurctz+iq/zZ2y/boQ3BpvqGxmqnsKLjY4scV31lPJi9kAnT7mw==

"@gar/promisify@^1.0.1", "@gar/promisify@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6"
Expand Down Expand Up @@ -2469,7 +2464,7 @@
glob-to-regexp "^0.3.0"

"@neve-wp/components@file:./assets/apps/components":
version "0.0.51"
version "0.0.54"

"@nodelib/[email protected]":
version "2.1.5"
Expand Down

0 comments on commit 6fa26d4

Please sign in to comment.