Skip to content

Commit 184061e

Browse files
authored
fix: 템플릿 질문 리스트 질문 추가 과정에서 나오는 "질문 수정을 취소하시겠어요" 모달을 이전 화면 과정에서 이탈시 나오게 제공 (#798)
* fix: #795 질문 수정 취소 플로우 변경 * fix: #795 코드리뷰 피드백 반영
1 parent b855e81 commit 184061e

File tree

2 files changed

+41
-48
lines changed

2 files changed

+41
-48
lines changed

apps/web/src/app/desktop/component/retrospectCreate/QuestionEditSection/AddQuestionView.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ export default function AddQuestionView({ onAddQuestions, maxCount }: AddQuestio
145145
padding: 0;
146146
`}
147147
>
148-
<ButtonProvider.Primary
149-
onClick={handleAddQuestion}
150-
disabled={customQuestion.trim().length === 0 && selectedValues.length === 0}
151-
>
148+
<ButtonProvider.Primary onClick={handleAddQuestion} disabled={customQuestion.trim().length === 0 && selectedValues.length === 0}>
152149
{selectedValues.length > 0 ? (
153150
<span>
154151
추가하기

apps/web/src/app/desktop/component/retrospectCreate/QuestionEditSection/index.tsx

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from "react";
1+
import { useState, useEffect, useCallback } from "react";
22
import { Button, ButtonProvider } from "@/component/common/button";
33
import { Icon } from "@/component/common/Icon";
44
import { Spacing } from "@/component/common/Spacing";
@@ -19,6 +19,8 @@ import AddQuestionView from "./AddQuestionView";
1919
import { useModal } from "@/hooks/useModal";
2020
import { isEqual } from "lodash-es";
2121

22+
const MAX_QUESTION_COUNT = 10;
23+
2224
type QuestionEditSectionProps = {
2325
onClose: () => void;
2426
};
@@ -102,20 +104,37 @@ export default function QuestionEditSection({ onClose }: QuestionEditSectionProp
102104
* 새 질문 추가 핸들러
103105
*/
104106
const handleAddQuestion = () => {
105-
if (questions.length >= 10) return;
107+
if (questions.length >= MAX_QUESTION_COUNT) return;
106108

107109
// 현재 질문들을 백업하고 질문 추가 모드로 전환
108-
setBackupQuestions([...questions]);
110+
const questionsToBackup = [...questions];
111+
setBackupQuestions(questionsToBackup);
109112
setIsAddMode(true);
113+
114+
const cancelCallback = () => {
115+
setEditingQuestions(questionsToBackup);
116+
setIsAddMode(false);
117+
setBackupQuestions([]);
118+
setModalDataState((prev) => ({
119+
...prev,
120+
title: "질문 리스트",
121+
options: {
122+
enableFooter: false,
123+
needsBackButton: true,
124+
backButtonCallback: handleCancel,
125+
},
126+
}));
127+
};
128+
110129
setModalDataState((prev) => ({
111130
...prev,
112131
title: "질문 추가",
113-
onClose: handleAddQuestionCancel,
132+
onClose: cancelCallback,
114133
options: {
115134
enableFooter: false,
116135
needsBackButton: true,
117136
disabledClose: true,
118-
backButtonCallback: handleAddQuestionCancel,
137+
backButtonCallback: cancelCallback,
119138
},
120139
}));
121140
};
@@ -149,7 +168,7 @@ export default function QuestionEditSection({ onClose }: QuestionEditSectionProp
149168
/**
150169
* 질문 수정 취소 핸들러 (뒤로가기 버튼)
151170
*/
152-
const handleCancel = () => {
171+
const handleCancel = useCallback(() => {
153172
const hasChanged = !isEqual(originalQuestions, editingQuestions);
154173

155174
if (hasChanged) {
@@ -168,35 +187,7 @@ export default function QuestionEditSection({ onClose }: QuestionEditSectionProp
168187
} else {
169188
onClose();
170189
}
171-
};
172-
173-
/**
174-
* 질문 추가 취소 핸들러
175-
*/
176-
const handleAddQuestionCancel = () => {
177-
openExitWarningModal({
178-
title: "질문 추가를 취소하시겠어요?",
179-
contents: "추가중인 내용은 모두 사라져요",
180-
onConfirm: () => {
181-
// 백업된 질문들로 복원
182-
setEditingQuestions(backupQuestions);
183-
setIsAddMode(false);
184-
setBackupQuestions([]);
185-
setModalDataState((prev) => ({
186-
...prev,
187-
title: "질문 리스트",
188-
options: {
189-
enableFooter: false,
190-
needsBackButton: true,
191-
backButtonCallback: handleCancel,
192-
},
193-
}));
194-
},
195-
options: {
196-
buttonText: ["취소", "나가기"],
197-
},
198-
});
199-
};
190+
}, [originalQuestions, editingQuestions, onClose, openExitWarningModal]);
200191

201192
/**
202193
* 삭제 모드 진입 핸들러
@@ -245,23 +236,25 @@ export default function QuestionEditSection({ onClose }: QuestionEditSectionProp
245236
onClose();
246237
};
247238

248-
// 모달의 뒤로가기 버튼 콜백을 handleCancel로 설정
239+
// 모달의 뒤로가기 버튼과 닫기 버튼 콜백을 handleCancel로 설정
249240
useEffect(() => {
250241
if (!isAddMode) {
251242
setModalDataState((prev) => ({
252243
...prev,
244+
onClose: handleCancel,
253245
options: {
254246
...prev.options,
247+
disabledClose: true,
255248
backButtonCallback: handleCancel,
256249
},
257250
}));
258251
}
259-
}, [editingQuestions, isAddMode]);
252+
}, [isAddMode, handleCancel]);
260253

261254
return (
262255
<>
263256
{isAddMode ? (
264-
<AddQuestionView onAddQuestions={handleAddQuestions} maxCount={10 - questions.length} />
257+
<AddQuestionView onAddQuestions={handleAddQuestions} maxCount={MAX_QUESTION_COUNT - questions.length} />
265258
) : (
266259
<>
267260
<section
@@ -295,9 +288,9 @@ export default function QuestionEditSection({ onClose }: QuestionEditSectionProp
295288
{/* ---------- 추가 버튼 ---------- */}
296289
<button
297290
onClick={handleAddQuestion}
298-
disabled={questions.length >= 10}
291+
disabled={questions.length >= MAX_QUESTION_COUNT}
299292
css={css`
300-
background-color: ${questions.length >= 10 ? DESIGN_TOKEN_COLOR.gray200 : DESIGN_TOKEN_COLOR.blue100};
293+
background-color: ${questions.length >= MAX_QUESTION_COUNT ? DESIGN_TOKEN_COLOR.gray200 : DESIGN_TOKEN_COLOR.blue100};
301294
border-radius: 1.2rem;
302295
border: none;
303296
display: flex;
@@ -306,14 +299,17 @@ export default function QuestionEditSection({ onClose }: QuestionEditSectionProp
306299
height: 4.8rem;
307300
width: 100%;
308301
transition: background-color 0.2s ease;
309-
cursor: ${questions.length >= 10 ? "not-allowed" : "pointer"};
310-
302+
cursor: ${questions.length >= MAX_QUESTION_COUNT ? "not-allowed" : "pointer"};
311303
&:hover {
312-
background-color: ${questions.length >= 10 ? DESIGN_TOKEN_COLOR.gray200 : DESIGN_TOKEN_COLOR.blue200};
304+
background-color: ${questions.length >= MAX_QUESTION_COUNT ? DESIGN_TOKEN_COLOR.gray200 : DESIGN_TOKEN_COLOR.blue200};
313305
}
314306
`}
315307
>
316-
<Icon icon="ic_plus_thin" size={1.8} color={questions.length >= 10 ? DESIGN_TOKEN_COLOR.gray400 : DESIGN_TOKEN_COLOR.blue600} />
308+
<Icon
309+
icon="ic_plus_thin"
310+
size={1.8}
311+
color={questions.length >= MAX_QUESTION_COUNT ? DESIGN_TOKEN_COLOR.gray400 : DESIGN_TOKEN_COLOR.blue600}
312+
/>
317313
</button>
318314
</section>
319315
</section>

0 commit comments

Comments
 (0)