Skip to content

Commit 3e4ceaa

Browse files
authored
Add back user feedback survey behaviour (codesandbox#2980)
* Add back user feedback survey behaviour * Change call to notification
1 parent 91267cf commit 3e4ceaa

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

packages/app/src/app/overmind/actions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ type ModalName =
7676
| 'preferences'
7777
| 'share'
7878
| 'searchDependencies'
79-
| 'signInForTemplates';
79+
| 'signInForTemplates'
80+
| 'userSurvey';
8081
export const modalOpened: Action<{ modal: ModalName; message?: string }> = (
8182
{ state, effects },
8283
{ modal, message }

packages/app/src/app/overmind/effects/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export default {
6868
getCurrentUser(): Promise<CurrentUser> {
6969
return api.get('/users/current');
7070
},
71+
markSurveySeen(): Promise<void> {
72+
return api.post('/users/survey-seen', {});
73+
},
7174
getDependency(name: string): Promise<Dependency> {
7275
return api.get(`/dependencies/${name}@latest`);
7376
},

packages/app/src/app/overmind/factories.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const withLoadApp = <T>(
3030
state.user = await effects.api.getCurrentUser();
3131
actions.internal.setPatronPrice();
3232
actions.internal.setSignedInCookie();
33+
actions.internal.showUserSurveyIfNeeded();
3334
effects.live.connect();
3435
actions.userNotifications.internal.initialize();
3536
effects.api.preloadTemplates();
@@ -112,7 +113,7 @@ export const createModals = <
112113
state?: {
113114
current: keyof T;
114115
} & {
115-
[K in keyof T]: T[K]['state'] & { isCurrent: IDerive<any, any, boolean> }
116+
[K in keyof T]: T[K]['state'] & { isCurrent: IDerive<any, any, boolean> };
116117
};
117118
actions?: {
118119
[K in keyof T]: {
@@ -121,7 +122,7 @@ export const createModals = <
121122
T[K]['result']
122123
>;
123124
close: AsyncAction<T[K]['result']>;
124-
}
125+
};
125126
};
126127
} => {
127128
function createModal(name, modal) {

packages/app/src/app/overmind/internalActions.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@codesandbox/common/lib/types';
1010
import { identify, setUserId } from '@codesandbox/common/lib/utils/analytics';
1111

12+
import { NotificationStatus } from '@codesandbox/notifications';
1213
import { createOptimisticModule } from './utils/common';
1314
import getItems from './utils/items';
1415
import { defaultOpenedModule, mainModule } from './utils/main-module';
@@ -68,6 +69,33 @@ export const setSignedInCookie: Action = ({ state }) => {
6869
setUserId(state.user.id);
6970
};
7071

72+
export const showUserSurveyIfNeeded: Action = ({ state, effects, actions }) => {
73+
if (state.user.sendSurvey) {
74+
// Let the server know that we've seen the survey
75+
effects.api.markSurveySeen();
76+
77+
effects.notificationToast.add({
78+
title: 'Help improve CodeSandbox',
79+
message:
80+
"We'd love to hear your thoughts, it's 7 questions and will only take 2 minutes.",
81+
status: NotificationStatus.NOTICE,
82+
sticky: true,
83+
actions: {
84+
primary: [
85+
{
86+
label: 'Open Survey',
87+
run: () => {
88+
actions.modalOpened({
89+
modal: 'userSurvey',
90+
});
91+
},
92+
},
93+
],
94+
},
95+
});
96+
}
97+
};
98+
7199
export const addNotification: Action<{
72100
title: string;
73101
type: 'notice' | 'success' | 'warning' | 'error';

packages/common/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export type CurrentUser = {
125125
email: string;
126126
};
127127
};
128+
sendSurvey: boolean;
128129
};
129130

130131
export type CustomTemplate = {

0 commit comments

Comments
 (0)