@@ -10,17 +10,23 @@ import { Search } from "lucide-react";
1010
1111const ITEMS_PER_PAGE = 6 ; // 한 번에 보여줄 개수
1212
13+ interface InvitedProps {
14+ searchTitle : string ;
15+ invitationData : Invite [ ] ;
16+ fetchNextPage : ( ) => void ;
17+ hasMore : boolean ;
18+ agreeInvitation ?: ( ) => void ;
19+ onDecision ?: ( inviteId : number ) => void ;
20+ }
21+
1322function InvitedList ( {
1423 searchTitle,
1524 invitationData : invitationData ,
1625 fetchNextPage,
1726 hasMore,
18- } : {
19- searchTitle : string ;
20- invitationData : Invite [ ] ;
21- fetchNextPage : ( ) => void ;
22- hasMore : boolean ;
23- } ) {
27+ agreeInvitation,
28+ onDecision,
29+ } : InvitedProps ) {
2430 const observerRef = useRef < HTMLDivElement | null > ( null ) ;
2531
2632 /* IntersectionObserver 설정 */
@@ -62,10 +68,9 @@ function InvitedList({
6268 } ;
6369 try {
6470 await axiosInstance . put ( apiRoutes . invitationDetail ( inviteId ) , payload ) ;
65- toast . success ( "대시보드 수락 성공" ) ;
66- setTimeout ( ( ) => {
67- window . location . reload ( ) ;
68- } , 1500 ) ;
71+ if ( agreeInvitation ) agreeInvitation ( ) ;
72+ if ( onDecision ) onDecision ( inviteId ) ;
73+ toast . success ( "초대가 수락되었습니다." ) ;
6974 } catch ( error ) {
7075 console . error ( "수락 실패:" , error ) ;
7176 toast . error ( "초대 수락에 실패했습니다" ) ;
@@ -80,10 +85,8 @@ function InvitedList({
8085 } ;
8186 try {
8287 await axiosInstance . put ( apiRoutes . invitationDetail ( inviteId ) , payload ) ;
83- toast . success ( "대시보드 거절 성공" ) ;
84- setTimeout ( ( ) => {
85- window . location . reload ( ) ;
86- } , 1500 ) ;
88+ if ( onDecision ) onDecision ( inviteId ) ;
89+ toast . success ( "초대가 거절되었습니다." ) ;
8790 } catch ( error ) {
8891 console . error ( "거절 실패:" , error ) ;
8992 toast . error ( "초대 거절에 실패했습니다" ) ;
@@ -187,8 +190,13 @@ function InvitedList({
187190}
188191
189192type CursorId = number ;
193+ type InvitedDashBoardProps = {
194+ agreeInvitation ?: ( ) => void ;
195+ } ;
190196
191- export default function InvitedDashBoard ( ) {
197+ export default function InvitedDashBoard ( {
198+ agreeInvitation,
199+ } : InvitedDashBoardProps ) {
192200 const { user } = useUserStore ( ) ;
193201 const [ searchTitle , setSearchTitle ] = useState ( "" ) ;
194202 const [ invitationData , setInvitationData ] = useState < Map < CursorId , Invite [ ] > > (
@@ -270,6 +278,19 @@ export default function InvitedDashBoard() {
270278
271279 const invitationArray = Array . from ( invitationData . values ( ) ) . flat ( ) ;
272280
281+ const removeInvitation = ( inviteId : number ) => {
282+ setInvitationData ( ( prev ) => {
283+ const newMap = new Map ( ) ;
284+ for ( const [ key , list ] of prev ) {
285+ newMap . set (
286+ key ,
287+ list . filter ( ( invite ) => invite . id !== inviteId )
288+ ) ;
289+ }
290+ return newMap ;
291+ } ) ;
292+ } ;
293+
273294 return (
274295 < div >
275296 { invitationArray . length === 0 ? (
@@ -303,6 +324,8 @@ export default function InvitedDashBoard() {
303324 invitationData = { invitationArray }
304325 fetchNextPage = { fetchNextPage }
305326 hasMore = { hasMore }
327+ agreeInvitation = { agreeInvitation }
328+ onDecision = { removeInvitation }
306329 />
307330 </ div >
308331 </ div >
0 commit comments