Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update NPS Value Survey #9638

Merged
merged 72 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
c5923c3
fix: refactor value component
mutdmour May 23, 2024
931ab36
feat: add nps score to value survey
mutdmour May 23, 2024
6295b8d
feat: add value survey endpoints
mutdmour May 23, 2024
a6fdb1e
Merge branch 'master' of github.com:n8n-io/n8n into ado-768
mutdmour May 24, 2024
213fb7a
fix: add logic to decide to show value survey
mutdmour May 24, 2024
c6e195c
feat: add logic to update survey
mutdmour May 24, 2024
0c4a75e
feat: update logic to show
mutdmour May 24, 2024
1858e28
merge master
mutdmour Jun 3, 2024
08acc4e
reduce changes
mutdmour Jun 3, 2024
e55a241
handle edge case for ignoring users
mutdmour Jun 3, 2024
4a4b9fa
add migration to set for existing users
mutdmour Jun 4, 2024
2a8ce40
prevent if telemetry disabled
mutdmour Jun 4, 2024
b7acea8
Merge branch 'master' of github.com:n8n-io/n8n into ado-768
mutdmour Jun 5, 2024
7c0c2ff
refactor: add clear state to api, add store
mutdmour Jun 5, 2024
33f5c46
refactor to seperate store
mutdmour Jun 5, 2024
9b31e25
clean up
mutdmour Jun 5, 2024
995946e
Merge branch 'master' of github.com:n8n-io/n8n into ado-768
mutdmour Jun 5, 2024
7ef0d9d
add tests
mutdmour Jun 5, 2024
e07e054
refactor, add tests
mutdmour Jun 5, 2024
a560053
add tests for controller
mutdmour Jun 5, 2024
29b19f3
fix up package
mutdmour Jun 5, 2024
cc6b2fc
remove import
mutdmour Jun 5, 2024
007cee7
add initial e2e tests
mutdmour Jun 5, 2024
0436667
Add test for email part
mutdmour Jun 5, 2024
e67caad
lint fix
mutdmour Jun 6, 2024
0aec1b4
rename var
mutdmour Jun 6, 2024
135737e
refactor: rename to nps survey
mutdmour Jun 6, 2024
efc7c74
refactor: rename to nps survey
mutdmour Jun 6, 2024
a48601d
fix: update key name
mutdmour Jun 6, 2024
81a29fc
last bit of rename
mutdmour Jun 6, 2024
3841598
refactor to make more restful
mutdmour Jun 6, 2024
6e90a25
update to add vars on top
mutdmour Jun 7, 2024
9cfef22
refactor to reduce dep cycle
mutdmour Jun 7, 2024
61d2ba0
fix lint issue
mutdmour Jun 7, 2024
c333361
refactor continue
mutdmour Jun 7, 2024
87a14ef
override for postgres
mutdmour Jun 7, 2024
10bdd1c
fix migrations
mutdmour Jun 7, 2024
2d5963e
fix migrations
mutdmour Jun 7, 2024
aaf4aa3
merge master
mutdmour Jun 7, 2024
52b4ad0
add tests
mutdmour Jun 7, 2024
26db1df
add more tests
mutdmour Jun 7, 2024
0854acd
fix tests
mutdmour Jun 7, 2024
fcd5998
fix migrations
mutdmour Jun 8, 2024
1403e5e
update unit tests
mutdmour Jun 8, 2024
aa71cc8
Merge branch 'master' of github.com:n8n-io/n8n into ado-768
mutdmour Jun 8, 2024
cd1224a
fix mysql queries
mutdmour Jun 8, 2024
f846d65
update unit tests
mutdmour Jun 8, 2024
4a5ee8f
clean up
mutdmour Jun 8, 2024
14fa060
fix: bug with e2e
mutdmour Jun 8, 2024
dc7ff61
Merge branch 'master' of github.com:n8n-io/n8n into ado-768
mutdmour Jun 10, 2024
3200e7e
refactor: add comment
mutdmour Jun 10, 2024
7a3a95b
refactor: address feedback
mutdmour Jun 10, 2024
22ba1d1
fix: remove telemetry check
mutdmour Jun 10, 2024
8058b39
fix: add telemetry config
mutdmour Jun 10, 2024
8ab51ca
fix: e2e
mutdmour Jun 10, 2024
ff9218f
fix: remove console log
mutdmour Jun 10, 2024
c50b9ba
Merge branch 'master' of github.com:n8n-io/n8n into ado-768
mutdmour Jun 10, 2024
ebc1e86
fix types
mutdmour Jun 10, 2024
9ec6414
fix last type issues
mutdmour Jun 10, 2024
0be328e
fix: bug with retry logic
mutdmour Jun 10, 2024
b60e4cd
merge in masteR
mutdmour Jun 10, 2024
683848a
update to test domains
mutdmour Jun 10, 2024
962a3e8
clean up unused import
mutdmour Jun 10, 2024
e84151d
make tests less flaky
mutdmour Jun 10, 2024
04db697
remove only
mutdmour Jun 10, 2024
51f58b4
lintfix
netroy Jun 10, 2024
aa72281
Merge branch 'master' of github.com:n8n-io/n8n into ado-768
mutdmour Jun 11, 2024
d4d6829
skip failing test
mutdmour Jun 11, 2024
dd03c94
fix lint
mutdmour Jun 11, 2024
f517535
Update cypress/e2e/42-nps-survey.cy.ts
mutdmour Jun 11, 2024
d8a9b47
address feedback
mutdmour Jun 11, 2024
9fb993d
user assert instead of type check
mutdmour Jun 11, 2024
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
3 changes: 1 addition & 2 deletions cypress/e2e/12-canvas-actions.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WorkflowPage as WorkflowPageClass } from '../pages/workflow';
import { successToast } from '../pages/notifications';
import {
MANUAL_TRIGGER_NODE_NAME,
MANUAL_TRIGGER_NODE_DISPLAY_NAME,
Expand All @@ -8,8 +9,6 @@ import {
IF_NODE_NAME,
HTTP_REQUEST_NODE_NAME,
} from './../constants';
import { WorkflowPage as WorkflowPageClass } from '../pages/workflow';
import { successToast } from '../pages/notifications';

const WorkflowPage = new WorkflowPageClass();
describe('Canvas Actions', () => {
Expand Down
3 changes: 1 addition & 2 deletions cypress/e2e/18-user-management.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { INSTANCE_MEMBERS, INSTANCE_OWNER, INSTANCE_ADMIN } from '../constants';
import { MainSidebar, SettingsSidebar, SettingsUsersPage, WorkflowPage } from '../pages';
import { MainSidebar, SettingsSidebar, SettingsUsersPage } from '../pages';
import { PersonalSettingsPage } from '../pages/settings-personal';
import { getVisibleSelect } from '../utils';
import { errorToast, successToast } from '../pages/notifications';
Expand All @@ -25,7 +25,6 @@ const updatedPersonalData = {
};

const usersSettingsPage = new SettingsUsersPage();
const workflowPage = new WorkflowPage();
const personalSettingsPage = new PersonalSettingsPage();
const settingsSidebar = new SettingsSidebar();
const mainSidebar = new MainSidebar();
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/19-execution.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,6 @@ describe('Execution', () => {
.within(() => cy.get('.fa-check'))
.should('exist');

errorToast().should('contain', `Problem in node ‘Telegram‘`);
errorToast().should('contain', 'Problem in node ‘Telegram‘');
});
});
3 changes: 0 additions & 3 deletions cypress/e2e/33-settings-personal.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { WorkflowPage } from '../pages';
import { errorToast, successToast } from '../pages/notifications';

const workflowPage = new WorkflowPage();

const INVALID_NAMES = [
'https://n8n.io',
'http://n8n.io',
Expand Down
20 changes: 10 additions & 10 deletions cypress/e2e/42-nps-survey.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('NpsSurvey', () => {
res.body.data.telemetry = {
enabled: true,
config: {
key: '1zPn9bgWPzlQc0p8Gj1uiK6DOTn',
url: 'https://telemetry.n8n.io',
key: 'test',
url: 'https://telemetry-test.n8n.io',
},
};
}
Expand Down Expand Up @@ -75,8 +75,8 @@ describe('NpsSurvey', () => {
res.body.data.telemetry = {
enabled: true,
config: {
key: '1zPn9bgWPzlQc0p8Gj1uiK6DOTn',
url: 'https://telemetry.n8n.io',
key: 'test',
url: 'https://telemetry-test.n8n.io',
},
};
}
Expand Down Expand Up @@ -118,25 +118,25 @@ describe('NpsSurvey', () => {
workflowPage.actions.saveWorkflowOnButtonClick();
getNpsSurvey().should('not.be.visible');

// shows up seven days later to ignore again
workflowPage.actions.visit(true, NOW + SEVEN_DAYS * 2 + 10000 * 2);
// shows up after at least sever days later to ignore again
mutdmour marked this conversation as resolved.
Show resolved Hide resolved
workflowPage.actions.visit(true, NOW + (SEVEN_DAYS + 10000) * 2 + ONE_DAY);
workflowPage.actions.saveWorkflowOnButtonClick();
clearNotifications();
getNpsSurvey().should('be.visible');
getNpsSurveyClose().click();
getNpsSurvey().should('not.be.visible');

workflowPage.actions.visit(true, NOW + SEVEN_DAYS * 2 + 10000 * 2);
workflowPage.actions.visit(true, NOW + (SEVEN_DAYS + 10000) * 2 + ONE_DAY * 2);
workflowPage.actions.saveWorkflowOnButtonClick();
getNpsSurvey().should('not.be.visible');

// does not show up again 7 days later
workflowPage.actions.visit(true, NOW + SEVEN_DAYS * 3 + 10000 * 3);
// does not show up again after at least 7 days
workflowPage.actions.visit(true, NOW + (SEVEN_DAYS + 10000) * 3 + ONE_DAY * 3);
workflowPage.actions.saveWorkflowOnButtonClick();
getNpsSurvey().should('not.be.visible');

// shows up 6 months later
workflowPage.actions.visit(true, NOW + SEVEN_DAYS * 3 + 10000 * 3 + ABOUT_SIX_MONTHS);
workflowPage.actions.visit(true, NOW + (SEVEN_DAYS + 10000) * 3 + ABOUT_SIX_MONTHS);
workflowPage.actions.saveWorkflowOnButtonClick();
getNpsSurvey().should('be.visible');
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/7-workflow-actions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Workflow Actions', () => {
WorkflowPage.getters.isWorkflowSaved();
});

it('should not save already saved workflow', () => {
it.skip('should not save already saved workflow', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure that this doesn't get left in the end

cy.intercept('PATCH', '/rest/workflows/*').as('saveWorkflow');
WorkflowPage.actions.saveWorkflowOnButtonClick();
WorkflowPage.actions.addNodeToCanvas(MANUAL_TRIGGER_NODE_NAME);
Expand Down
1 change: 1 addition & 0 deletions cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@ngneat/falso": "^6.4.0",
"@sinonjs/fake-timers": "^11.2.2",
"cross-env": "^7.0.3",
"cypress": "^13.6.2",
"cypress-otp": "^1.0.3",
Expand Down
2 changes: 0 additions & 2 deletions cypress/pages/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { getVisibleSelect } from '../utils';
import { BasePage } from './base';
import { NodeCreator } from './features/node-creator';

type CyGetOptions = Parameters<(typeof cy)['get']>[1];

const nodeCreator = new NodeCreator();
export class WorkflowPage extends BasePage {
url = '/workflow/new';
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'cypress-real-events';
import FakeTimers from '@sinonjs/fake-timers';
import { WorkflowPage } from '../pages';
import {
BACKEND_BASE_URL,
Expand All @@ -7,7 +8,6 @@ import {
INSTANCE_OWNER,
N8N_AUTH_COOKIE,
} from '../constants';
import FakeTimers from '@sinonjs/fake-timers';

Cypress.Commands.add('setAppDate', (targetDate: number | Date) => {
cy.window().then((win) => {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
},
"devDependencies": {
"@n8n_io/eslint-config": "workspace:*",
"@ngneat/falso": "^6.4.0",
"@sinonjs/fake-timers": "^11.2.2",
"@types/jest": "^29.5.3",
"@types/supertest": "^6.0.2",
"@vitest/coverage-v8": "^1.6.0",
Expand Down
42 changes: 5 additions & 37 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,9 @@ export interface IUserListAction {
}

export interface IN8nPrompts {
message: string;
title: string;
showContactPrompt: boolean;
showNpsSurvey: boolean;
message?: string;
title?: string;
showContactPrompt?: boolean;
}

export const enum UserManagementAuthenticationMethod {
Expand Down Expand Up @@ -1206,6 +1205,8 @@ export type Modals = {
[key: string]: ModalState;
};

export type ModalKey = keyof Modals;

export type ModalState = {
open: boolean;
mode?: string | null;
Expand Down Expand Up @@ -1921,39 +1922,6 @@ export type EnterpriseEditionFeatureKey =
| 'WorkerView'
| 'AdvancedPermissions';

export type ModalKey =
| 'about'
| 'chatEmbed'
| 'changePassword'
| 'editCredential'
| 'selectCredential'
| 'deleteUser'
| 'inviteUser'
| 'duplicate'
| 'tagsManager'
| 'versions'
| 'settings'
| 'lmChat'
| 'workflowShare'
| 'personalization'
| 'contactPrompt'
| 'npsSurvey'
| 'activation'
| 'onboardingCallSignup'
| 'communityPackageInstall'
| 'communityPackageManageConfirm'
| 'importCurl'
| 'generateCurl'
| 'settingsLogStream'
| 'sourceControlPush'
| 'sourceControlPull'
| 'debugPaywall'
| 'mfaSetup'
| 'workflowHistoryVersionRestore'
| 'suggestedTemplatePreview'
| 'setupCredentials'
| 'externalSecretsProvider';

export type EnterpriseEditionFeatureValue = keyof Omit<IN8nUISettings['enterprise'], 'projects'>;

export interface IN8nPromptResponse {
Expand Down
6 changes: 0 additions & 6 deletions packages/editor-ui/src/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ export const waitAllPromises = async () => await new Promise((resolve) => setTim
export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = {
initialized: true,
settings: defaultSettings,
promptsData: {
message: '',
title: '',
showContactPrompt: false,
showNpsSurvey: false,
},
userManagement: {
showSetupOnFirstLoad: false,
smtpSetup: false,
Expand Down
11 changes: 6 additions & 5 deletions packages/editor-ui/src/components/ContactPromptModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { createEventBus } from 'n8n-design-system/utils';
import { useToast } from '@/composables/useToast';
import { useNpsSurveyStore } from '@/stores/npsSurvey.store';

export default defineComponent({
name: 'ContactPromptModal',
Expand All @@ -65,17 +66,17 @@ export default defineComponent({
};
},
computed: {
...mapStores(useRootStore, useSettingsStore),
...mapStores(useRootStore, useSettingsStore, useNpsSurveyStore),
title(): string {
if (this.settingsStore.promptsData && this.settingsStore.promptsData.title) {
return this.settingsStore.promptsData.title;
if (this.npsSurveyStore.promptsData?.title) {
return this.npsSurveyStore.promptsData.title;
}

return 'You’re a power user 💪';
},
description(): string {
if (this.settingsStore.promptsData && this.settingsStore.promptsData.message) {
return this.settingsStore.promptsData.message;
if (this.npsSurveyStore.promptsData?.message) {
return this.npsSurveyStore.promptsData.message;
}

return 'Your experience with n8n can help us improve — for you and our entire community.';
Expand Down
63 changes: 31 additions & 32 deletions packages/editor-ui/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {
EnterpriseEditionFeatureKey,
EnterpriseEditionFeatureValue,
ModalKey,
NodeCreatorOpenSource,
} from './Interface';
import { NodeConnectionType } from 'n8n-workflow';
Expand Down Expand Up @@ -36,37 +35,37 @@ export const QUICKSTART_NOTE_NAME = '_QUICKSTART_NOTE_';
export const MAX_TAG_NAME_LENGTH = 24;

// modals
export const ABOUT_MODAL_KEY: ModalKey = 'about';
export const CHAT_EMBED_MODAL_KEY: ModalKey = 'chatEmbed';
export const CHANGE_PASSWORD_MODAL_KEY: ModalKey = 'changePassword';
export const CREDENTIAL_EDIT_MODAL_KEY: ModalKey = 'editCredential';
export const CREDENTIAL_SELECT_MODAL_KEY: ModalKey = 'selectCredential';
export const DELETE_USER_MODAL_KEY: ModalKey = 'deleteUser';
export const INVITE_USER_MODAL_KEY: ModalKey = 'inviteUser';
export const DUPLICATE_MODAL_KEY: ModalKey = 'duplicate';
export const TAGS_MANAGER_MODAL_KEY: ModalKey = 'tagsManager';
export const VERSIONS_MODAL_KEY: ModalKey = 'versions';
export const WORKFLOW_SETTINGS_MODAL_KEY: ModalKey = 'settings';
export const WORKFLOW_LM_CHAT_MODAL_KEY: ModalKey = 'lmChat';
export const WORKFLOW_SHARE_MODAL_KEY: ModalKey = 'workflowShare';
export const PERSONALIZATION_MODAL_KEY: ModalKey = 'personalization';
export const CONTACT_PROMPT_MODAL_KEY: ModalKey = 'contactPrompt';
export const NPS_SURVEY_MODAL_KEY: ModalKey = 'npsSurvey';
export const WORKFLOW_ACTIVE_MODAL_KEY: ModalKey = 'activation';
export const ONBOARDING_CALL_SIGNUP_MODAL_KEY: ModalKey = 'onboardingCallSignup';
export const COMMUNITY_PACKAGE_INSTALL_MODAL_KEY: ModalKey = 'communityPackageInstall';
export const COMMUNITY_PACKAGE_CONFIRM_MODAL_KEY: ModalKey = 'communityPackageManageConfirm';
export const IMPORT_CURL_MODAL_KEY: ModalKey = 'importCurl';
export const GENERATE_CURL_MODAL_KEY: ModalKey = 'generateCurl';
export const LOG_STREAM_MODAL_KEY: ModalKey = 'settingsLogStream';
export const SOURCE_CONTROL_PUSH_MODAL_KEY: ModalKey = 'sourceControlPush';
export const SOURCE_CONTROL_PULL_MODAL_KEY: ModalKey = 'sourceControlPull';
export const DEBUG_PAYWALL_MODAL_KEY: ModalKey = 'debugPaywall';
export const MFA_SETUP_MODAL_KEY: ModalKey = 'mfaSetup';
export const WORKFLOW_HISTORY_VERSION_RESTORE: ModalKey = 'workflowHistoryVersionRestore';
export const SETUP_CREDENTIALS_MODAL_KEY: ModalKey = 'setupCredentials';

export const EXTERNAL_SECRETS_PROVIDER_MODAL_KEY: ModalKey = 'externalSecretsProvider';
export const ABOUT_MODAL_KEY = 'about';
export const CHAT_EMBED_MODAL_KEY = 'chatEmbed';
export const CHANGE_PASSWORD_MODAL_KEY = 'changePassword';
export const CREDENTIAL_EDIT_MODAL_KEY = 'editCredential';
export const CREDENTIAL_SELECT_MODAL_KEY = 'selectCredential';
export const DELETE_USER_MODAL_KEY = 'deleteUser';
export const INVITE_USER_MODAL_KEY = 'inviteUser';
export const DUPLICATE_MODAL_KEY = 'duplicate';
export const TAGS_MANAGER_MODAL_KEY = 'tagsManager';
export const VERSIONS_MODAL_KEY = 'versions';
export const WORKFLOW_SETTINGS_MODAL_KEY = 'settings';
export const WORKFLOW_LM_CHAT_MODAL_KEY = 'lmChat';
export const WORKFLOW_SHARE_MODAL_KEY = 'workflowShare';
export const PERSONALIZATION_MODAL_KEY = 'personalization';
export const CONTACT_PROMPT_MODAL_KEY = 'contactPrompt';
export const NPS_SURVEY_MODAL_KEY = 'npsSurvey';
export const WORKFLOW_ACTIVE_MODAL_KEY = 'activation';
export const ONBOARDING_CALL_SIGNUP_MODAL_KEY = 'onboardingCallSignup';
export const COMMUNITY_PACKAGE_INSTALL_MODAL_KEY = 'communityPackageInstall';
export const COMMUNITY_PACKAGE_CONFIRM_MODAL_KEY = 'communityPackageManageConfirm';
export const IMPORT_CURL_MODAL_KEY = 'importCurl';
export const GENERATE_CURL_MODAL_KEY = 'generateCurl';
export const LOG_STREAM_MODAL_KEY = 'settingsLogStream';
export const SOURCE_CONTROL_PUSH_MODAL_KEY = 'sourceControlPush';
export const SOURCE_CONTROL_PULL_MODAL_KEY = 'sourceControlPull';
export const DEBUG_PAYWALL_MODAL_KEY = 'debugPaywall';
export const MFA_SETUP_MODAL_KEY = 'mfaSetup';
export const WORKFLOW_HISTORY_VERSION_RESTORE = 'workflowHistoryVersionRestore';
export const SETUP_CREDENTIALS_MODAL_KEY = 'setupCredentials';

export const EXTERNAL_SECRETS_PROVIDER_MODAL_KEY = 'externalSecretsProvider';

export const COMMUNITY_PACKAGE_MANAGE_ACTIONS = {
UNINSTALL: 'uninstall',
Expand Down
21 changes: 15 additions & 6 deletions packages/editor-ui/src/stores/npsSurvey.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const useNpsSurveyStore = defineStore('npsSurvey', () => {
const shouldShowNpsSurveyNext = ref<boolean>(false);
const currentSurveyState = ref<NpsSurveyState | undefined>();
const currentUserId = ref<string | undefined>();
const promptsData = ref<IN8nPrompts | undefined>();

function setupNpsSurveyOnLogin(userId: string, settings?: IUserSettings): void {
currentUserId.value = userId;
Expand Down Expand Up @@ -89,7 +90,10 @@ export const useNpsSurveyStore = defineStore('npsSurvey', () => {
const updatedState: NpsSurveyState = {
waitingForResponse: true,
lastShownAt: Date.now(),
ignoredCount: 0,
ignoredCount:
currentSurveyState.value && 'ignoredCount' in currentSurveyState.value
? currentSurveyState.value.ignoredCount
: 0,
};
await updateNpsSurveyState(rootStore.getRestApiContext, updatedState);
currentSurveyState.value = updatedState;
Expand Down Expand Up @@ -135,19 +139,24 @@ export const useNpsSurveyStore = defineStore('npsSurvey', () => {
return;
}

const promptsData: IN8nPrompts = await getPromptsData(
settingsStore.settings.instanceId,
currentUserId.value ?? '',
);
try {
promptsData.value = await getPromptsData(
settingsStore.settings.instanceId,
currentUserId.value ?? '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even want to fetch the prompts data if currentUserId is not set? Why not skip the whole requests then? In what case might this happen? Is there a possible race condition that this is called before currentUserId has value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can add this. Technically no, since specific user actions are needed to trigger this, for example save a workflow.
I think this logic predates user management so maybe that's why. We did not have user id, just instance id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a long time in n8n until v1, setting up an owner user was optional, even after we added user management. so userId could be undefined but a user is logged in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it should always be defined, it would be nicer to have an assert to satisfy TS compiler and to communicate that this should always be defined when this gets called. Otherwise it can cause nasty bugs that are hard to debug (e.g. if there's a bug that this function gets always called before the currentUserId is defined the nps survey will never get initialized properly).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that makes sense. Thanks for the suggestion

);
} catch (e) {
console.error('Failed to fetch prompts data');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing, but maybe the nps survey will show. n8n api might be down, but it should not affect UX and no need to show notification (we make this call too often and user does not know about it).


if (promptsData?.showContactPrompt) {
if (promptsData.value?.showContactPrompt) {
uiStore.openModal(CONTACT_PROMPT_MODAL_KEY);
} else {
await useNpsSurveyStore().showNpsSurveyIfPossible();
}
}

return {
promptsData,
resetNpsSurveyOnLogOut,
showNpsSurveyIfPossible,
ignoreNpsSurvey,
Expand Down
Loading
Loading