diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 316219fa4c..09edf9aaed 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -137,7 +137,7 @@ jobs: include: - specs: "customizer" envs: "sample-data" - - specs: "tpc" + - specs: "admin" envs: "sample-data" - specs: "visual-regression" envs: "sample-data" diff --git a/assets/apps/dashboard/src/utils/survey.js b/assets/apps/dashboard/src/utils/survey.js index 48f3b6bae6..044f35d6dc 100644 --- a/assets/apps/dashboard/src/utils/survey.js +++ b/assets/apps/dashboard/src/utils/survey.js @@ -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. * @@ -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, + }, + }); }); } diff --git a/e2e-tests/specs/admin/dashboard-survey.spec.ts b/e2e-tests/specs/admin/dashboard-survey.spec.ts new file mode 100644 index 0000000000..e79a20dce8 --- /dev/null +++ b/e2e-tests/specs/admin/dashboard-survey.spec.ts @@ -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); + }); +}); diff --git a/e2e-tests/specs/tpc/tpc-notice-install.spec.ts b/e2e-tests/specs/admin/tpc-notice-install.spec.ts similarity index 100% rename from e2e-tests/specs/tpc/tpc-notice-install.spec.ts rename to e2e-tests/specs/admin/tpc-notice-install.spec.ts diff --git a/inc/admin/dashboard/main.php b/inc/admin/dashboard/main.php index 5a367e5975..ffa8395978 100755 --- a/inc/admin/dashboard/main.php +++ b/inc/admin/dashboard/main.php @@ -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' ); diff --git a/package.json b/package.json index 39149a2ed0..31e13e46c3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 6d59d9f074..337b3b7e7a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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/fs.scandir@2.1.5": version "2.1.5"