@@ -12,7 +12,6 @@ import { useQueryClient } from "@tanstack/react-query";
1212import { ExtendedActionItemType } from "@/types/actionItem" ;
1313import { useModal } from "@/hooks/useModal" ;
1414import { useDeleteActionItemList } from "@/hooks/api/actionItem/useDeleteActionItemList" ;
15- import { useApiPostActionItem } from "@/hooks/api/actionItem/useApiPostActionItem" ;
1615import { useToast } from "@/hooks/useToast" ;
1716
1817type ActionItem = {
@@ -39,13 +38,11 @@ export default function ActionItemsEditSection({ spaceId, retrospectId, todoList
3938 const [ actionItems , setActionItems ] = useState < ActionItem [ ] > ( todoList ) ;
4039 const [ nextTempId , setNextTempId ] = useState ( INIT_TEMP_ID ) ;
4140
42- const { mutate : createActionItem , isPending : isPendingCreateActionItem } = useApiPostActionItem ( ) ;
4341 const { mutate : patchActionItem , isPending : isPendingPatchActionItem } = usePatchActionItemList ( ) ;
4442 const { mutate : deleteActionItem } = useDeleteActionItemList ( ) ;
4543
4644 /**
4745 * 리스트의 아이템 순서 변경
48- *
4946 * @param list
5047 * @param startIndex
5148 * @param endIndex
@@ -61,7 +58,6 @@ export default function ActionItemsEditSection({ spaceId, retrospectId, todoList
6158
6259 /**
6360 * 드래그 앤 드롭이 끝났을 때 호출
64- *
6561 * @param result
6662 * @returns
6763 */
@@ -76,7 +72,6 @@ export default function ActionItemsEditSection({ spaceId, retrospectId, todoList
7672
7773 /**
7874 * 아이템 삭제 핸들러
79- *
8075 * @param id
8176 */
8277 const handleDelete = ( id : string ) => {
@@ -115,8 +110,7 @@ export default function ActionItemsEditSection({ spaceId, retrospectId, todoList
115110
116111 closeModal ( ) ;
117112 } ,
118- onError : ( error ) => {
119- console . error ( "삭제 실패:" , error ) ;
113+ onError : ( ) => {
120114 closeModal ( ) ;
121115 } ,
122116 } ,
@@ -130,7 +124,6 @@ export default function ActionItemsEditSection({ spaceId, retrospectId, todoList
130124
131125 /**
132126 * 아이템 내용 변경 핸들러
133- *
134127 * @param id
135128 * @param newContent
136129 */
@@ -147,70 +140,43 @@ export default function ActionItemsEditSection({ spaceId, retrospectId, todoList
147140 setActionItems ( [ ...actionItems , { actionItemId : newId , content : "" , isNew : true } ] ) ;
148141 } ;
149142
143+ /**
144+ * 완료 버튼 클릭 시, 실행목표 수정 API 호출
145+ * * 요청에 보낼 아이템 리스트 생성
146+ * * 내용이 비어있는 아이템은 제외
147+ * * isNew 플래그에 따라 id 포함 여부 결정
148+ */
150149 const handleComplete = async ( ) => {
151- // * 기존 아이템과 새로운 아이템 분리
152- const existingItems = actionItems . filter ( ( item ) => ! item . isNew ) ;
153- const newItems = actionItems . filter ( ( item ) => item . isNew && item . content . trim ( ) !== "" ) ;
154-
155150 try {
156- // 1. 새로운 아이템 생성 (순차 처리) 후 생성된 아이템 정보 수집
157- const createdItems : { id : number ; content : string } [ ] = [ ] ;
158-
159- if ( newItems . length > 0 ) {
160- for ( const item of newItems ) {
161- const createdId = await new Promise < number > ( ( resolve , reject ) => {
162- createActionItem (
163- {
164- retrospectId,
165- content : item . content ,
166- } ,
167- {
168- onSuccess : ( data ) => {
169- resolve ( data . data . actionItemId ) ;
170- } ,
171- onError : reject ,
172- } ,
173- ) ;
174- } ) ;
175-
176- // 생성된 아이템을 배열에 추가
177- createdItems . push ( {
178- id : createdId ,
151+ const requestItems = actionItems
152+ . filter ( ( item ) => item . content . trim ( ) !== "" )
153+ . map ( ( item ) => {
154+ if ( item . isNew ) {
155+ return { content : item . content } ;
156+ }
157+ return {
158+ id : parseInt ( item . actionItemId ) ,
179159 content : item . content ,
180- } ) ;
181- }
182- }
183-
184- // 2. 기존 아이템 + 방금 생성된 아이템 합쳐서 업데이트
185- const allItemsToUpdate = [
186- ...existingItems . map ( ( item ) => ( {
187- id : parseInt ( item . actionItemId ) ,
188- content : item . content ,
189- } ) ) ,
190- ...createdItems ,
191- ] ;
192-
193- if ( allItemsToUpdate . length > 0 ) {
194- await new Promise ( ( resolve , reject ) => {
195- patchActionItem (
196- {
197- retrospectId,
198- actionItems : allItemsToUpdate ,
199- } ,
200- {
201- onSuccess : resolve ,
202- onError : reject ,
203- } ,
204- ) ;
160+ } ;
205161 } ) ;
206- }
207162
208- // 3. 모든 작업 완료 후 캐시 무효화 및 완료 처리
163+ await new Promise ( ( resolve , reject ) => {
164+ patchActionItem (
165+ {
166+ retrospectId,
167+ actionItems : requestItems ,
168+ } ,
169+ {
170+ onSuccess : resolve ,
171+ onError : reject ,
172+ } ,
173+ ) ;
174+ } ) ;
175+
209176 await queryClient . invalidateQueries ( { queryKey : [ "getTeamActionItemList" , spaceId ] } ) ;
210177 toast . success ( "실행목표 편집이 완료되었어요!" ) ;
211178 onClose ( ) ;
212179 } catch ( error ) {
213- console . error ( "아이템 저장 실패:" , error ) ;
214180 toast . error ( "실행목표 편집에 실패했어요." ) ;
215181 }
216182 } ;
@@ -383,7 +349,7 @@ export default function ActionItemsEditSection({ spaceId, retrospectId, todoList
383349 padding : 0 ;
384350 ` }
385351 >
386- < Button colorSchema = { "primary" } onClick = { handleComplete } isProgress = { isPendingCreateActionItem || isPendingPatchActionItem } >
352+ < Button colorSchema = { "primary" } onClick = { handleComplete } isProgress = { isPendingPatchActionItem } >
387353 완료
388354 </ Button >
389355 </ ButtonProvider >
0 commit comments