Feat: 로그아웃 쿼리 추가

This commit is contained in:
정현조 2024-09-26 03:41:17 +09:00
parent 8009108119
commit cf97dc4d20
3 changed files with 43 additions and 9 deletions

View File

@ -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'] });
},
});
}

View File

@ -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<ReviewResponse[]>({
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,
});
}

View File

@ -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<ReviewResponse[]>({
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,
});
}