@@ -5,6 +5,7 @@ import EmptyInvitations from "./EmptyInvitations";
55import { apiRoutes } from "@/api/apiRoutes" ;
66import axiosInstance from "@/api/axiosInstance" ;
77import { Invite } from "@/types/invite" ;
8+ import useUserStore from "@/store/useUserStore" ;
89
910const ITEMS_PER_PAGE = 6 ; // 한 번에 보여줄 개수
1011
@@ -179,6 +180,7 @@ function InvitedList({
179180type CursorId = number ;
180181
181182export default function InvitedDashBoard ( ) {
183+ const { user } = useUserStore ( ) ;
182184 const [ searchTitle , setSearchTitle ] = useState ( "" ) ;
183185 const [ invitationData , setInvitationData ] = useState < Map < CursorId , Invite [ ] > > (
184186 new Map ( )
@@ -193,63 +195,67 @@ export default function InvitedDashBoard() {
193195 } ;
194196
195197 useEffect ( ( ) => {
196- fetchNextPage ( ) ; // 초기 데이터 6개 불러오기
197- } , [ ] ) ;
198+ if ( user ) {
199+ fetchNextPage ( ) ;
200+ } // 초기 데이터 6개 불러오기
201+ } , [ user ] ) ;
198202
199203 /* 초대 목록 데이터 불러오기 */
200204 const fetchNextPage = async ( ) => {
201- try {
202- const existingCursorId =
203- cursorId !== null && cursorId !== undefined
204- ? invitationData . get ( cursorId )
205- : undefined ;
205+ if ( user ) {
206+ try {
207+ const existingCursorId =
208+ cursorId !== null && cursorId !== undefined
209+ ? invitationData . get ( cursorId )
210+ : undefined ;
206211
207- if ( existingCursorId && existingCursorId . length > 0 ) {
208- // 이미 데이터가 존재하면 더 이상 요청하지 않음
209- return ;
210- }
212+ if ( existingCursorId && existingCursorId . length > 0 ) {
213+ // 이미 데이터가 존재하면 더 이상 요청하지 않음
214+ return ;
215+ }
211216
212- if ( isFetchingRef . current ) return ; // 이미 데이터가 불러와졌다면 중복 요청 방지
213- isFetchingRef . current = true ; // 데이터 요청 시작
217+ if ( isFetchingRef . current ) return ; // 이미 데이터가 불러와졌다면 중복 요청 방지
218+ isFetchingRef . current = true ; // 데이터 요청 시작
214219
215- const res = await axiosInstance . get ( apiRoutes . Invitations ( ) , {
216- params : {
217- size : ITEMS_PER_PAGE ,
218- cursorId : cursorId || null ,
219- } ,
220- } ) ;
220+ const res = await axiosInstance . get ( apiRoutes . Invitations ( ) , {
221+ params : {
222+ size : ITEMS_PER_PAGE ,
223+ cursorId : cursorId || null ,
224+ } ,
225+ } ) ;
221226
222- if ( res . data && Array . isArray ( res . data . invitations ) ) {
223- const newInvitations = res . data . invitations . map (
224- ( item : {
225- id : number ;
226- dashboard : { title : string } ;
227- inviter : { nickname : string } ;
228- } ) => ( {
229- id : item . id ,
230- title : item . dashboard . title ,
231- nickname : item . inviter . nickname ,
232- } )
233- ) as Invite [ ] ;
227+ if ( res . data && Array . isArray ( res . data . invitations ) ) {
228+ const newInvitations = res . data . invitations . map (
229+ ( item : {
230+ id : number ;
231+ dashboard : { title : string } ;
232+ inviter : { nickname : string } ;
233+ } ) => ( {
234+ id : item . id ,
235+ title : item . dashboard . title ,
236+ nickname : item . inviter . nickname ,
237+ } )
238+ ) as Invite [ ] ;
234239
235- if ( newInvitations . length > 0 ) {
236- setCursorId ( res . data . cursorId ) ;
237- }
240+ if ( newInvitations . length > 0 ) {
241+ setCursorId ( res . data . cursorId ) ;
242+ }
238243
239- setInvitationData ( ( prev ) => {
240- const newMap = new Map ( prev ) ;
241- newMap . set ( cursorId as CursorId , newInvitations ) ;
242- return newMap ;
243- } ) ;
244+ setInvitationData ( ( prev ) => {
245+ const newMap = new Map ( prev ) ;
246+ newMap . set ( cursorId as CursorId , newInvitations ) ;
247+ return newMap ;
248+ } ) ;
244249
245- if ( newInvitations . length < ITEMS_PER_PAGE ) {
246- setHasMore ( false ) ;
250+ if ( newInvitations . length < ITEMS_PER_PAGE ) {
251+ setHasMore ( false ) ;
252+ }
247253 }
254+ } catch ( error ) {
255+ console . error ( "초대내역 불러오는데 오류 발생:" , error ) ;
256+ } finally {
257+ isFetchingRef . current = false ; // 데이터 요청 완료
248258 }
249- } catch ( error ) {
250- console . error ( "초대내역 불러오는데 오류 발생:" , error ) ;
251- } finally {
252- isFetchingRef . current = false ; // 데이터 요청 완료
253259 }
254260 } ;
255261
0 commit comments