@@ -3,19 +3,22 @@ import { AxiosError } from 'axios';
33
44import { deleteRollingPaper , patchRollingPaper } from '@/apis/rolling' ;
55import { DeleteIcon } from '@/assets/icons' ;
6+ import { useState } from 'react' ;
7+ import ConfirmModal from '@/components/ConfirmModal' ;
68
79interface RollingPaperItemProps {
810 information : AdminRollingPaperInformation ;
11+ currentPage : string | number ;
912}
1013
11- export default function RollingPaperItem ( { information } : RollingPaperItemProps ) {
14+ export default function RollingPaperItem ( { information, currentPage } : RollingPaperItemProps ) {
15+ const [ activeDeleteModal , setActiveDeleteModal ] = useState ( false ) ;
1216 const queryClient = useQueryClient ( ) ;
1317
1418 const { mutate : deleteMutate } = useMutation ( {
1519 mutationFn : ( ) => deleteRollingPaper ( information . eventPostId ) ,
1620 onSuccess : ( ) => {
17- // TODO: 페이지네이션 적용 후, 현재 page에 대한 캐싱 날리는 방식으로 변경
18- queryClient . invalidateQueries ( { queryKey : [ 'admin-rolling-paper' ] } ) ;
21+ queryClient . invalidateQueries ( { queryKey : [ 'admin-rolling-paper' , currentPage ] } ) ;
1922 } ,
2023 onError : ( err ) => {
2124 console . error ( err ) ;
@@ -25,9 +28,7 @@ export default function RollingPaperItem({ information }: RollingPaperItemProps)
2528 const { mutate : toggleStatus } = useMutation ( {
2629 mutationFn : ( ) => patchRollingPaper ( information . eventPostId ) ,
2730 onSuccess : ( ) => {
28- // TODO: 기존 데이터 수정하는 방식으로 ㄱㄱㄱㄱㄱㄱㄱ
29- // 일단 임시로 캐싱 날리기
30- queryClient . invalidateQueries ( { queryKey : [ 'admin-rolling-paper' ] } ) ;
31+ queryClient . invalidateQueries ( { queryKey : [ 'admin-rolling-paper' , currentPage ] } ) ;
3132 } ,
3233 onError : ( err : AxiosError < { code : string ; message : string } > ) => {
3334 if ( err . response ?. data . code === 'EVENT-004' ) {
@@ -37,40 +38,53 @@ export default function RollingPaperItem({ information }: RollingPaperItemProps)
3738 } ,
3839 } ) ;
3940
40- // TODO: 진짜 삭제하겠냐고 물어보기
4141 return (
42- < tr className = "border-gray-40 h-14 border-b" >
43- < td className = "w-14 text-center" > { information . eventPostId } </ td >
44- < td className = "text-left" >
45- < div >
46- { information . used && (
47- < span className = "mr-2 rounded-full border border-amber-500 bg-amber-100/70 px-3 py-0.5 whitespace-nowrap text-amber-500" >
48- 진행 중
49- </ span >
50- ) }
51- { information . title }
52- </ div >
53- </ td >
54- < td className = "text-center" >
55- < button
56- type = "button"
57- className = "hover:bg-gray-10 text-gray-60 rounded-md px-3 py-1 hover:text-black"
58- onClick = { ( ) => toggleStatus ( ) }
59- >
60- { information . used ? '중단하기' : '진행하기' }
61- </ button >
62- </ td >
63- < td className = "w-6" >
64- { ! information . used && (
42+ < >
43+ { activeDeleteModal && (
44+ < ConfirmModal
45+ title = "정말 롤링페이퍼를 삭제하시겠어요?"
46+ description = "롤링페이퍼를 삭제하는 경우 복구가 불가능합니다!"
47+ cancelText = "되돌아가기"
48+ confirmText = "삭제하기"
49+ onCancel = { ( ) => {
50+ setActiveDeleteModal ( false ) ;
51+ } }
52+ onConfirm = { deleteMutate }
53+ />
54+ ) }
55+ < tr className = "border-gray-40 h-14 border-b" >
56+ < td className = "w-14 text-center" > { information . eventPostId } </ td >
57+ < td className = "text-left" >
58+ < div >
59+ { information . used && (
60+ < span className = "mr-2 rounded-full border border-amber-500 bg-amber-100/70 px-3 py-0.5 whitespace-nowrap text-amber-500" >
61+ 진행 중
62+ </ span >
63+ ) }
64+ { information . title }
65+ </ div >
66+ </ td >
67+ < td className = "text-center" >
6568 < button
6669 type = "button"
67- className = "text-gray-60 flex items-center justify-center p -1 hover:text-black"
68- onClick = { ( ) => deleteMutate ( ) }
70+ className = "hover:bg-gray-10 text-gray-60 rounded-md px-3 py -1 hover:text-black"
71+ onClick = { ( ) => toggleStatus ( ) }
6972 >
70- < DeleteIcon className = "h-5 w-5" />
73+ { information . used ? '중단하기' : '진행하기' }
7174 </ button >
72- ) }
73- </ td >
74- </ tr >
75+ </ td >
76+ < td className = "w-6" >
77+ { ! information . used && (
78+ < button
79+ type = "button"
80+ className = "text-gray-60 flex items-center justify-center p-1 hover:text-black"
81+ onClick = { ( ) => setActiveDeleteModal ( true ) }
82+ >
83+ < DeleteIcon className = "h-5 w-5" />
84+ </ button >
85+ ) }
86+ </ td >
87+ </ tr >
88+ </ >
7589 ) ;
7690}
0 commit comments