@@ -4,6 +4,8 @@ import { usePatchConfirmPick } from '@/features/pick/apis/usePatchConfirmPick';
44import type { PickStatus } from '@/libs/types/pick' ;
55import { useNavigate } from 'react-router' ;
66import { useToast } from '@/common/hooks/useToast' ;
7+ import { useState } from 'react' ;
8+ import CustomAlert from '@/common/components/CustomAlert' ;
79
810const PICK_EXPIRED_MESSAGE : Record < Exclude < PickStatus , 'PENDING' | 'CONFIRMED' > , string > = {
911 CANCELLED : '취소된 PICK이에요' ,
@@ -24,11 +26,23 @@ const DetailBottom = ({ id, itemId, isCreator, pickState, chatRoomId }: Props) =
2426 const { mutate : cancel } = usePatchCancelPick ( ) ;
2527 const { mutate : confirm } = usePatchConfirmPick ( ) ;
2628 const { openToast } = useToast ( ) ;
29+ const [ showAlert , setShowAlert ] = useState ( false ) ;
30+
31+ const cancelType = pickState === 'PENDING' ? '거절' : '취소' ;
32+
33+ const onNo = ( ) => {
34+ setShowAlert ( false ) ;
35+ } ;
36+
37+ const handleAlert = ( ) => {
38+ setShowAlert ( true ) ;
39+ } ;
2740
2841 const cancelPick = ( ) => {
2942 cancel ( id , {
3043 onSuccess : ( ) => {
3144 navigate ( `/detail/${ itemId } ` , { replace : true } ) ;
45+ setShowAlert ( false ) ;
3246 openToast ( { message : 'PICK이 취소되었어요' } ) ;
3347 } ,
3448 } ) ;
@@ -50,12 +64,12 @@ const DetailBottom = ({ id, itemId, isCreator, pickState, chatRoomId }: Props) =
5064 < div className = { s . Container } >
5165 { canChangeState ? (
5266 isCreator ? (
53- < button className = { s . Button ( { color : 'main ' } ) } onClick = { cancelPick } >
67+ < button className = { s . Button ( { color : 'gray ' } ) } onClick = { handleAlert } >
5468 PICK 취소하기
5569 </ button >
5670 ) : (
5771 < >
58- < button className = { s . Button ( { color : 'gray' } ) } onClick = { cancelPick } >
72+ < button className = { s . Button ( { color : 'gray' } ) } onClick = { handleAlert } >
5973 { pickState === 'PENDING' ? '거절하기' : 'PICK 취소하기' }
6074 </ button >
6175 { pickState === 'PENDING' && (
@@ -68,6 +82,15 @@ const DetailBottom = ({ id, itemId, isCreator, pickState, chatRoomId }: Props) =
6882 ) : (
6983 < div className = { s . Button ( { color : 'gray' } ) } > { PICK_EXPIRED_MESSAGE [ pickState ] } </ div >
7084 ) }
85+ { showAlert && (
86+ < CustomAlert
87+ onYes = { cancelPick }
88+ subTitle = "정말 취소하실 건가요?"
89+ title = { `PICK을 ${ cancelType } 하면\n더 이상 거래를 할 수 없어요.` }
90+ yesBtn = "네, 취소할래요"
91+ onNo = { onNo }
92+ />
93+ ) }
7194 </ div >
7295 ) ;
7396} ;
0 commit comments