diff --git a/frontend/src/components/AdminLayout/index.tsx b/frontend/src/components/AdminLayout/index.tsx index a413caa..80e6f89 100644 --- a/frontend/src/components/AdminLayout/index.tsx +++ b/frontend/src/components/AdminLayout/index.tsx @@ -13,7 +13,7 @@ export default function AdminLayout() { - + diff --git a/frontend/src/components/Header/UserProfileForm.tsx b/frontend/src/components/Header/UserProfileForm.tsx new file mode 100644 index 0000000..584290b --- /dev/null +++ b/frontend/src/components/Header/UserProfileForm.tsx @@ -0,0 +1,46 @@ +import { useState } from 'react'; +import { Button } from '../ui/button'; +import useAuthStore from '@/stores/useAuthStore'; +import useLogoutQuery from '@/queries/auth/useLogoutQuery'; +export default function UserProfileForm({ onClose }: { onClose: () => void }) { + const profile = useAuthStore((state) => state.profile); + const { nickname, profileImage } = profile || { nickname: '', profileImage: '' }; + + const logoutMutation = useLogoutQuery(); + const [isLoggingOut, setIsLoggingOut] = useState(false); + + const handleLogout = async () => { + setIsLoggingOut(true); + logoutMutation.mutate(undefined, { + onSuccess: () => { + onClose(); + }, + }); + }; + return ( + + + {profileImage ? ( + + ) : ( + + )} + + {nickname || 'Guest'} + + + + {isLoggingOut ? '로그아웃 중...' : '로그아웃'} + + + ); +} diff --git a/frontend/src/components/Header/UserProfileModal.tsx b/frontend/src/components/Header/UserProfileModal.tsx new file mode 100644 index 0000000..9e92679 --- /dev/null +++ b/frontend/src/components/Header/UserProfileModal.tsx @@ -0,0 +1,31 @@ +import React from 'react'; +import { Dialog, DialogContent, DialogHeader, DialogTrigger } from '../ui/dialogCustom'; +import { User } from 'lucide-react'; +import UserProfileForm from './UserProfileForm'; + +export default function UserProfileModal() { + const [isOpen, setIsOpen] = React.useState(false); + + const handleOpen = () => setIsOpen(true); + const handleClose = () => setIsOpen(false); + + return ( + + + + + + + + + + + + ); +} diff --git a/frontend/src/components/Header/index.tsx b/frontend/src/components/Header/index.tsx index 0375839..d1a2fab 100644 --- a/frontend/src/components/Header/index.tsx +++ b/frontend/src/components/Header/index.tsx @@ -1,7 +1,8 @@ import * as React from 'react'; import { cn } from '@/lib/utils'; -import { Bell, User } from 'lucide-react'; +import { Bell } from 'lucide-react'; import { useLocation, Link, useParams } from 'react-router-dom'; +import UserProfileModal from './UserProfileModal'; export interface HeaderProps extends React.HTMLAttributes {} @@ -60,7 +61,7 @@ export default function Header({ className, ...props }: HeaderProps) { {!isHomePage && ( - + )} diff --git a/frontend/src/mocks/reviewHandlers.ts b/frontend/src/mocks/reviewHandlers.ts index 1c65479..3e5e222 100644 --- a/frontend/src/mocks/reviewHandlers.ts +++ b/frontend/src/mocks/reviewHandlers.ts @@ -125,19 +125,22 @@ export const reviewHandlers = [ const projectId = Array.isArray(params.projectId) ? parseInt(params.projectId[0], 10) : parseInt(params.projectId as string, 10); - console.log(projectId); const reviewStatus = Array.isArray(params.reviewStatus) ? params.reviewStatus[0] : params.reviewStatus; - const lastReviewId = Array.isArray(params.lastReviewId) ? params.lastReviewId[0] : params.lastReviewId; + const lastReviewId = Array.isArray(params.lastReviewId) + ? parseInt(params.lastReviewId[0], 10) + : parseInt(params.lastReviewId as string, 10) || 0; const limitPage = Array.isArray(params.limitPage) ? parseInt(params.limitPage[0], 10) : parseInt(params.limitPage as string, 10) || 10; - const reviews: ReviewResponse[] = Array.from({ length: limitPage }, (_, index) => ({ + // 총 100개의 리뷰를 생성 + const totalReviews = 100; + const reviews: ReviewResponse[] = Array.from({ length: totalReviews }, (_, index) => ({ projectId, - reviewId: lastReviewId ? parseInt(lastReviewId, 10) + index : index + 1, + reviewId: index + 1, title: `Review ${index + 1}`, content: `Review content ${index + 1}`, status: (reviewStatus || 'REQUESTED') as 'REQUESTED' | 'APPROVED' | 'REJECTED', @@ -146,6 +149,10 @@ export const reviewHandlers = [ author: { id: 1, nickname: 'Author', profileImage: '', email: 'author@example.com' }, })); - return HttpResponse.json(reviews); + // 마지막 리뷰 ID 기준으로 데이터를 잘라서 반환 + const startIndex = lastReviewId > 0 ? lastReviewId : 0; + const slicedReviews = reviews.slice(startIndex, startIndex + limitPage); + + return HttpResponse.json(slicedReviews); }), ]; diff --git a/frontend/src/pages/ProjectReviewList.tsx b/frontend/src/pages/ProjectReviewList.tsx index 405743d..4fa219c 100644 --- a/frontend/src/pages/ProjectReviewList.tsx +++ b/frontend/src/pages/ProjectReviewList.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { Suspense, useState, useEffect, useRef } from 'react'; import { useParams, Link } from 'react-router-dom'; import useReviewByStatusQuery from '@/queries/reviews/useReviewByStatusQuery'; import useAuthStore from '@/stores/useAuthStore'; @@ -14,33 +14,70 @@ export default function ProjectReviewList() { const [, setSearchQuery] = useState(''); const [sortValue, setSortValue] = useState('latest'); - const { data: projectReviews = [] } = useReviewByStatusQuery( + const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = useReviewByStatusQuery( Number(projectId), memberId, activeTab !== 'all' ? activeTab : undefined ); - return ( - - - 프로젝트 리뷰 - - 리뷰 요청 - - + const projectReviews = data?.pages.flat() || []; - - + const loadMoreRef = useRef(null); + + useEffect(() => { + if (!hasNextPage || isFetchingNextPage) return; + + const observer = new IntersectionObserver( + (entries) => { + if (entries[0].isIntersecting) { + fetchNextPage(); + } + }, + { threshold: 1.0 } + ); + + const currentLoadMoreRef = loadMoreRef.current; + if (currentLoadMoreRef) { + observer.observe(currentLoadMoreRef); + } + + return () => { + if (currentLoadMoreRef) { + observer.unobserve(currentLoadMoreRef); + } + }; + }, [hasNextPage, isFetchingNextPage, fetchNextPage]); + + return ( + }> + + + 프로젝트 리뷰 + + 리뷰 요청 + + + + + + {isFetchingNextPage} + + + + ); } diff --git a/frontend/src/pages/WorkspaceReviewList.tsx b/frontend/src/pages/WorkspaceReviewList.tsx index 92f0a7c..9c01c1c 100644 --- a/frontend/src/pages/WorkspaceReviewList.tsx +++ b/frontend/src/pages/WorkspaceReviewList.tsx @@ -1,10 +1,10 @@ -import { useState } from 'react'; +import { useState, useEffect, useRef } from 'react'; import { useParams, Link } from 'react-router-dom'; import useWorkspaceReviewsQuery from '@/queries/workspaces/useWorkspaceReviewsQuery'; import useAuthStore from '@/stores/useAuthStore'; import ReviewList from '@/components/ReviewList'; import { Button } from '@/components/ui/button'; - +import { Suspense } from 'react'; export default function WorkspaceReviewList() { const { workspaceId } = useParams<{ workspaceId: string }>(); const profile = useAuthStore((state) => state.profile); @@ -14,32 +14,70 @@ export default function WorkspaceReviewList() { const [, setSearchQuery] = useState(''); const [sortValue, setSortValue] = useState('latest'); - const { data: workspaceReviews = [] } = useWorkspaceReviewsQuery( + const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = useWorkspaceReviewsQuery( Number(workspaceId), memberId, activeTab !== 'all' ? activeTab : undefined ); + const workspaceReviews = data?.pages.flat() || []; + + const loadMoreRef = useRef(null); + + useEffect(() => { + if (!hasNextPage || isFetchingNextPage) return; + + const observer = new IntersectionObserver( + (entries) => { + if (entries[0].isIntersecting) { + fetchNextPage(); + } + }, + { threshold: 1.0 } + ); + + const currentLoadMoreRef = loadMoreRef.current; + if (currentLoadMoreRef) { + observer.observe(currentLoadMoreRef); + } + + return () => { + if (currentLoadMoreRef) { + observer.unobserve(currentLoadMoreRef); + } + }; + }, [hasNextPage, isFetchingNextPage, fetchNextPage]); + return ( - - - 워크스페이스 리뷰 - - 리뷰 요청 - - - - + }> + + + 워크스페이스 리뷰 + + 리뷰 요청 + + + + + + {isFetchingNextPage} + + + + ); } diff --git a/frontend/src/queries/auth/useLogoutQuery.ts b/frontend/src/queries/auth/useLogoutQuery.ts new file mode 100644 index 0000000..2379128 --- /dev/null +++ b/frontend/src/queries/auth/useLogoutQuery.ts @@ -0,0 +1,16 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import useAuthStore from '@/stores/useAuthStore'; +import { logout } from '@/api/authApi'; + +export default function useLogoutQuery() { + const queryClient = useQueryClient(); + const { clearAuth } = useAuthStore(); + + return useMutation({ + mutationFn: logout, + onSuccess: () => { + clearAuth(); + queryClient.invalidateQueries({ queryKey: ['profile'] }); + }, + }); +} diff --git a/frontend/src/queries/reviews/useReviewByStatusQuery.ts b/frontend/src/queries/reviews/useReviewByStatusQuery.ts index d677d8e..97793d7 100644 --- a/frontend/src/queries/reviews/useReviewByStatusQuery.ts +++ b/frontend/src/queries/reviews/useReviewByStatusQuery.ts @@ -1,13 +1,22 @@ +import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; import { getReviewByStatus } from '@/api/reviewApi'; -import { useSuspenseQuery } from '@tanstack/react-query'; +import { ReviewResponse } from '@/types'; export default function useReviewByStatusQuery( projectId: number, memberId: number, reviewStatus: 'REQUESTED' | 'APPROVED' | 'REJECTED' | undefined ) { - return useSuspenseQuery({ + return useSuspenseInfiniteQuery({ queryKey: ['reviewByStatus', projectId, reviewStatus], - queryFn: () => getReviewByStatus(projectId, memberId, reviewStatus), + queryFn: ({ pageParam = undefined }) => { + return getReviewByStatus(projectId, memberId, reviewStatus, pageParam as number | undefined); + }, + getNextPageParam: (lastPage) => { + if (lastPage.length === 0) return undefined; + const lastReview = lastPage[lastPage.length - 1]; + return lastReview.reviewId; + }, + initialPageParam: undefined, }); } diff --git a/frontend/src/queries/workspaces/useWorkspaceReviewsQuery.tsx b/frontend/src/queries/workspaces/useWorkspaceReviewsQuery.tsx index 2e03385..7832914 100644 --- a/frontend/src/queries/workspaces/useWorkspaceReviewsQuery.tsx +++ b/frontend/src/queries/workspaces/useWorkspaceReviewsQuery.tsx @@ -1,15 +1,24 @@ +import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; import { getWorkspaceReviews } from '@/api/workspaceApi'; -import { useSuspenseQuery } from '@tanstack/react-query'; +import { ReviewResponse } from '@/types'; export default function useWorkspaceReviewsQuery( workspaceId: number, memberId: number, reviewStatus?: 'REQUESTED' | 'APPROVED' | 'REJECTED', - lastReviewId?: number, - limitPage?: number + limitPage: number = 10 ) { - return useSuspenseQuery({ - queryKey: ['workspaceReviews', workspaceId, reviewStatus, lastReviewId], - queryFn: () => getWorkspaceReviews(workspaceId, memberId, reviewStatus, lastReviewId, limitPage), + return useSuspenseInfiniteQuery({ + queryKey: ['workspaceReviews', workspaceId, reviewStatus], + queryFn: ({ pageParam = undefined }) => + getWorkspaceReviews(workspaceId, memberId, reviewStatus, pageParam as number | undefined, limitPage), + + getNextPageParam: (lastPage) => { + if (lastPage.length === 0) return undefined; + const lastReview = lastPage[lastPage.length - 1]; + return lastReview.reviewId; + }, + + initialPageParam: undefined, }); }