Skip to content

Commit 2e76bc9

Browse files
committed
Fix/User feedback as default survey
1 parent 63cd8d0 commit 2e76bc9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { PropsWithChildren } from 'react';
88
jest.mock('next/router', () => require('next-router-mock'));
99

1010
const NEW_QUESTION_TITLE = 'new question';
11-
1211
const NEW_SURVEY_TITLE = 'new survey title';
1312

1413
const setUp = () => {
@@ -27,6 +26,7 @@ const setUp = () => {
2726
});
2827

2928
act(() => {
29+
result.current.removeAllQuestions();
3030
result.current.addQuestion({
3131
draftId: v4(),
3232
type: 'INPUT',

src/features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { CreateEditSurveyPayload } from 'pages/api/survey';
1414
import { QuestionWithLogicPath } from 'types/QuestionWithLogicPath';
1515
import { useApplicationContext } from 'features/application/context';
1616
import { Page } from 'features/application/types/Page';
17+
import { USER_FEEDBACK_TEMPLATE } from 'features/surveys/features/SurveyCreator/constants/templatesData/UserFeedbackTemplate';
1718

1819
export interface DraftQuestion {
1920
draftId: string;
@@ -100,6 +101,9 @@ export const useCreateSurveyManager = (initialData?: SurveyWithQuestions) => {
100101
if (title !== undefined) setTitle(title);
101102
if (questions !== undefined) setQuestions(questions);
102103
if (surveyOptions !== undefined) setSurveyOptions(surveyOptions);
104+
} else {
105+
setTitle(USER_FEEDBACK_TEMPLATE.title);
106+
setQuestions(USER_FEEDBACK_TEMPLATE.questions);
103107
}
104108
setIsLoaded(true);
105109
} else if (isEditMode) {
@@ -124,6 +128,10 @@ export const useCreateSurveyManager = (initialData?: SurveyWithQuestions) => {
124128
setError('');
125129
};
126130

131+
const removeAllQuestions = () => {
132+
setQuestions([]);
133+
};
134+
127135
const removeQuestion = (index: number) => {
128136
setQuestions((oldQuestions) => {
129137
oldQuestions.forEach((question) => {
@@ -524,6 +532,7 @@ export const useCreateSurveyManager = (initialData?: SurveyWithQuestions) => {
524532
updateLogicPath,
525533
expandAdvancedSettings,
526534
selectTemplate,
535+
removeAllQuestions,
527536
};
528537
};
529538

0 commit comments

Comments
 (0)