From f9f70e25b50f5805e8fa6484dd10a31f9caf54f3 Mon Sep 17 00:00:00 2001 From: Boegie19 <34578426+Boegie19@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:11:40 +0200 Subject: [PATCH] feat(admin): allows users to disable NPS in strapi config. (#18287) --- examples/getstarted/config/admin.js | 3 +++ examples/kitchensink-ts/config/admin.ts | 3 +++ examples/kitchensink/config/admin.js | 3 +++ packages/admin-test-utils/custom.d.ts | 5 ++++- packages/admin-test-utils/src/environment.ts | 3 +++ .../admin/src/components/NpsSurvey/index.js | 16 +++++++++++----- packages/core/admin/admin/src/index.js | 7 +++++-- packages/core/admin/server/controllers/admin.js | 5 +++-- .../app/src/resources/files/js/config/admin.js | 3 +++ .../app/src/resources/files/ts/config/admin.ts | 3 +++ 10 files changed, 41 insertions(+), 10 deletions(-) diff --git a/examples/getstarted/config/admin.js b/examples/getstarted/config/admin.js index 1b4b970d1f..40e8a1a6a9 100644 --- a/examples/getstarted/config/admin.js +++ b/examples/getstarted/config/admin.js @@ -14,4 +14,7 @@ module.exports = ({ env }) => ({ salt: env('TRANSFER_TOKEN_SALT', 'example-salt'), }, }, + flags: { + nps: env.bool('FLAG_NPS', true), + }, }); diff --git a/examples/kitchensink-ts/config/admin.ts b/examples/kitchensink-ts/config/admin.ts index ff4a13a2fa..b7183c6a5c 100644 --- a/examples/kitchensink-ts/config/admin.ts +++ b/examples/kitchensink-ts/config/admin.ts @@ -10,4 +10,7 @@ export default ({ env }) => ({ salt: env('TRANSFER_TOKEN_SALT', 'example-salt'), }, }, + flags: { + nps: env.bool('FLAG_NPS', true), + }, }); diff --git a/examples/kitchensink/config/admin.js b/examples/kitchensink/config/admin.js index 7d943bf3ab..a52636d73a 100644 --- a/examples/kitchensink/config/admin.js +++ b/examples/kitchensink/config/admin.js @@ -11,4 +11,7 @@ module.exports = ({ env }) => ({ salt: env('TRANSFER_TOKEN_SALT', 'example-salt'), }, }, + flags: { + nps: env.bool('FLAG_NPS', true), + }, }); diff --git a/packages/admin-test-utils/custom.d.ts b/packages/admin-test-utils/custom.d.ts index 19947d3565..950d007c10 100644 --- a/packages/admin-test-utils/custom.d.ts +++ b/packages/admin-test-utils/custom.d.ts @@ -1,4 +1,4 @@ -export {}; +export { }; declare global { interface Window { @@ -11,6 +11,9 @@ declare global { }; projectType: string; telemetryDisabled: boolean; + flags: { + nps: boolean + } }; } } diff --git a/packages/admin-test-utils/src/environment.ts b/packages/admin-test-utils/src/environment.ts index cbf0363b67..05807a73c5 100644 --- a/packages/admin-test-utils/src/environment.ts +++ b/packages/admin-test-utils/src/environment.ts @@ -65,6 +65,9 @@ window.strapi = { }, projectType: 'Community', telemetryDisabled: true, + flags: { + nps: true + } }; /* ------------------------------------------------------------------------------------------------- diff --git a/packages/core/admin/admin/src/components/NpsSurvey/index.js b/packages/core/admin/admin/src/components/NpsSurvey/index.js index c990c99cc1..a1f1446efb 100644 --- a/packages/core/admin/admin/src/components/NpsSurvey/index.js +++ b/packages/core/admin/admin/src/components/NpsSurvey/index.js @@ -71,17 +71,23 @@ const checkIfShouldShowSurvey = (settings) => { const { enabled, lastResponseDate, firstDismissalDate, lastDismissalDate } = settings; // This function goes through all the cases where we'd want to not show the survey: - // 1. If the survey is disabled, abort mission, don't bother checking the other settings. - // 2. If the user has already responded to the survey, check if enough time has passed since the last response. - // 3. If the user has dismissed the survey twice or more before, check if enough time has passed since the last dismissal. - // 4. If the user has only dismissed the survey once before, check if enough time has passed since the first dismissal. + // 1. If the survey is disabled by strapi, abort mission, don't bother checking the other settings. + // 2. If the survey is disabled by user, abort mission, don't bother checking the other settings. + // 3. If the user has already responded to the survey, check if enough time has passed since the last response. + // 4. If the user has dismissed the survey twice or more before, check if enough time has passed since the last dismissal. + // 5. If the user has only dismissed the survey once before, check if enough time has passed since the first dismissal. // If none of these cases check out, then we show the survey. // Note that submitting a response resets the dismissal counts. - // Checks 3 and 4 should not be reversed, since the first dismissal will also exist if the user has dismissed the survey twice or more before. + // Checks 4 and 5 should not be reversed, since the first dismissal will also exist if the user has dismissed the survey twice or more before. // For users who had created an account before the NPS feature was introduced, // we assume that they would have enabled the NPS feature if they had the chance. + // Global strapi disable for NSP. + if (window.strapi.flags.nps === false) { + return false + } + // User chose not to enable the NPS feature when signing up if (enabled === false) { return false; diff --git a/packages/core/admin/admin/src/index.js b/packages/core/admin/admin/src/index.js index 7addf37d9f..e79527ca7f 100644 --- a/packages/core/admin/admin/src/index.js +++ b/packages/core/admin/admin/src/index.js @@ -23,6 +23,9 @@ window.strapi = { REVIEW_WORKFLOWS: 'review-workflows', }, projectType: 'Community', + flags: { + nps: false + }, }; const customConfig = appCustomisations; @@ -41,16 +44,16 @@ const run = async () => { try { const { data: { - data: { isEE, features }, + data: { isEE, features, flags }, }, } = await get('/admin/project-type'); window.strapi.isEE = isEE; + window.strapi.flags = flags; window.strapi.features = { ...window.strapi.features, isEnabled: (featureName) => features.some((feature) => feature.name === featureName), }; - window.strapi.projectType = isEE ? 'Enterprise' : 'Community'; } catch (err) { console.error(err); diff --git a/packages/core/admin/server/controllers/admin.js b/packages/core/admin/server/controllers/admin.js index 88c50cba7b..273612a3ef 100644 --- a/packages/core/admin/server/controllers/admin.js +++ b/packages/core/admin/server/controllers/admin.js @@ -26,11 +26,12 @@ module.exports = { // When removing this we need to update the /admin/src/index.js file // where we set the strapi.window.isEE value async getProjectType() { + const flags = strapi.config.get('admin.flags', {}); // FIXME try { - return { data: { isEE: strapi.EE, features: ee.features.list() } }; + return { data: { isEE: strapi.EE, features: ee.features.list(), flags } }; } catch (err) { - return { data: { isEE: false, features: [] } }; + return { data: { isEE: false, features: [], flags } }; } }, diff --git a/packages/generators/app/src/resources/files/js/config/admin.js b/packages/generators/app/src/resources/files/js/config/admin.js index 92f535b14b..8873071a84 100644 --- a/packages/generators/app/src/resources/files/js/config/admin.js +++ b/packages/generators/app/src/resources/files/js/config/admin.js @@ -10,4 +10,7 @@ module.exports = ({ env }) => ({ salt: env('TRANSFER_TOKEN_SALT'), }, }, + flags: { + nps: env.bool('FLAG_NPS', true), + }, }); diff --git a/packages/generators/app/src/resources/files/ts/config/admin.ts b/packages/generators/app/src/resources/files/ts/config/admin.ts index 0362175d28..c85010edac 100644 --- a/packages/generators/app/src/resources/files/ts/config/admin.ts +++ b/packages/generators/app/src/resources/files/ts/config/admin.ts @@ -10,4 +10,7 @@ export default ({ env }) => ({ salt: env('TRANSFER_TOKEN_SALT'), }, }, + flags: { + nps: env.bool('FLAG_NPS', true), + }, });