Skip to content

Commit 092955a

Browse files
committed
fix: Go back in survey dialog
1 parent ea068f3 commit 092955a

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/providers/SurveyProvider/SurveyDialog/SurveyDialog.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ export const SurveyDialog: FC = () => {
1414
const {
1515
activeSurvey,
1616
activeQuestionIndex,
17+
setActiveQuestionIndex,
1718
cancelSurvey,
1819
hideSurvey,
1920
answerQuestion,
2021
currentAnswer,
22+
setCurrentAnswer,
2123
isCancelled,
2224
} = useSurvey();
2325
const [isAnswering, setIsAnswering] = useState(false);
@@ -60,11 +62,27 @@ export const SurveyDialog: FC = () => {
6062
}
6163
};
6264

65+
const handleOnBack = () => {
66+
if (activeQuestionIndex === 0) {
67+
cancelSurvey();
68+
} else if (activeQuestionIndex) {
69+
const previousAnswer =
70+
activeSurvey.questions[activeQuestionIndex - 1].answer;
71+
if (previousAnswer) {
72+
setActiveQuestionIndex((prev) => (prev ?? 1) - 1);
73+
setCurrentAnswer({
74+
id: activeSurvey.questions[activeQuestionIndex - 1].questionId,
75+
...previousAnswer,
76+
});
77+
}
78+
}
79+
};
80+
6381
const defaultActions: DialogProps['actions'] = [
6482
{
65-
text: activeQuestionIndex === 0 ? 'Maybe later' : 'Cancel',
83+
text: activeQuestionIndex === 0 ? 'Maybe later' : 'Back',
6684
variant: 'ghost',
67-
onClick: cancelSurvey,
85+
onClick: handleOnBack,
6886
},
6987
{
7088
text:

0 commit comments

Comments
 (0)