Refactor: 쿼리 리팩토링
This commit is contained in:
parent
5d50a1a943
commit
3e6b8e9df6
@ -1,39 +1,39 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import useAuthStore from '@/stores/useAuthStore';
|
||||
import { reissueToken } from '@/api/authApi';
|
||||
import { useEffect } from 'react';
|
||||
// import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
// import useAuthStore from '@/stores/useAuthStore';
|
||||
// import { reissueToken } from '@/api/authApi';
|
||||
// import { useEffect } from 'react';
|
||||
|
||||
import useProfileQuery from '@/queries/useProfileQuery';
|
||||
// import useProfileQuery from '@/queries/auth/useProfileQuery';
|
||||
|
||||
export const useReissueToken = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { setLoggedIn } = useAuthStore();
|
||||
// export const useReissueToken = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
// const { setLoggedIn } = useAuthStore();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: reissueToken,
|
||||
onSuccess: (data) => {
|
||||
setLoggedIn(true, data.accessToken);
|
||||
queryClient.invalidateQueries({ queryKey: ['profile'] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// return useMutation({
|
||||
// mutationFn: reissueToken,
|
||||
// onSuccess: (data) => {
|
||||
// setLoggedIn(true, data.accessToken);
|
||||
// queryClient.invalidateQueries({ queryKey: ['profile'] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
export const useProfile = () => {
|
||||
const { setProfile } = useAuthStore();
|
||||
const query = useProfileQuery();
|
||||
// export const useProfile = () => {
|
||||
// const { setProfile } = useAuthStore();
|
||||
// const query = useProfileQuery();
|
||||
|
||||
// TODO: query.data가 변경될 때마다 setProfile을 호출하여 profile 업데이트, useEffect 제거
|
||||
useEffect(() => {
|
||||
setProfile(query.data);
|
||||
}, [query.data, setProfile]);
|
||||
// // TODO: query.data가 변경될 때마다 setProfile을 호출하여 profile 업데이트, useEffect 제거
|
||||
// useEffect(() => {
|
||||
// setProfile(query.data);
|
||||
// }, [query.data, setProfile]);
|
||||
|
||||
return query;
|
||||
};
|
||||
// return query;
|
||||
// };
|
||||
|
||||
export const useFetchProfile = () => {
|
||||
const { setProfile } = useAuthStore();
|
||||
const query = useProfileQuery();
|
||||
if (query.data) {
|
||||
setProfile(query.data);
|
||||
}
|
||||
};
|
||||
// export const useFetchProfile = () => {
|
||||
// const { setProfile } = useAuthStore();
|
||||
// const query = useProfileQuery();
|
||||
// if (query.data) {
|
||||
// setProfile(query.data);
|
||||
// }
|
||||
// };
|
||||
|
@ -1,7 +1,7 @@
|
||||
import useAuthStore from '@/stores/useAuthStore';
|
||||
import useProfileQuery from '@/queries/useProfileQuery';
|
||||
import useProfileQuery from '@/queries/auth/useProfileQuery';
|
||||
|
||||
export function useHandleOAuthCallback() {
|
||||
export default function useHandleOAuthCallback() {
|
||||
const queryParams = new URLSearchParams(window.location.search);
|
||||
const accessToken = queryParams.get('accessToken');
|
||||
const setLoggedIn = useAuthStore((state) => state.setLoggedIn);
|
||||
|
@ -112,87 +112,87 @@
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import {
|
||||
createProject,
|
||||
updateProject,
|
||||
deleteProject,
|
||||
addProjectMember,
|
||||
updateProjectMemberPrivilege,
|
||||
removeProjectMember,
|
||||
} from '@/api/projectApi';
|
||||
import { ProjectResponse, ProjectRequest, ProjectMemberRequest, ProjectMemberResponse } from '@/types';
|
||||
// import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
// import {
|
||||
// createProject,
|
||||
// updateProject,
|
||||
// deleteProject,
|
||||
// addProjectMember,
|
||||
// updateProjectMemberPrivilege,
|
||||
// removeProjectMember,
|
||||
// } from '@/api/projectApi';
|
||||
// import { ProjectResponse, ProjectRequest, ProjectMemberRequest, ProjectMemberResponse } from '@/types';
|
||||
|
||||
export const useCreateProject = () => {
|
||||
const queryClient = useQueryClient();
|
||||
// export const useCreateProject = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<ProjectResponse, Error, { workspaceId: number; memberId: number; data: ProjectRequest }>({
|
||||
mutationFn: ({ workspaceId, memberId, data }) => createProject(workspaceId, memberId, data),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projects', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// return useMutation<ProjectResponse, Error, { workspaceId: number; memberId: number; data: ProjectRequest }>({
|
||||
// mutationFn: ({ workspaceId, memberId, data }) => createProject(workspaceId, memberId, data),
|
||||
// onSuccess: (_, variables) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['projects', variables.workspaceId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
export const useUpdateProject = () => {
|
||||
const queryClient = useQueryClient();
|
||||
// export const useUpdateProject = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<ProjectResponse, Error, { projectId: number; memberId: number; data: ProjectRequest }>({
|
||||
mutationFn: ({ projectId, memberId, data }) => updateProject(projectId, memberId, data),
|
||||
onSuccess: (data) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['project', data.id] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// return useMutation<ProjectResponse, Error, { projectId: number; memberId: number; data: ProjectRequest }>({
|
||||
// mutationFn: ({ projectId, memberId, data }) => updateProject(projectId, memberId, data),
|
||||
// onSuccess: (data) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['project', data.id] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
export const useDeleteProject = () => {
|
||||
const queryClient = useQueryClient();
|
||||
// export const useDeleteProject = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<void, Error, { projectId: number; memberId: number }>({
|
||||
mutationFn: ({ projectId, memberId }) => deleteProject(projectId, memberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projects', variables.projectId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// return useMutation<void, Error, { projectId: number; memberId: number }>({
|
||||
// mutationFn: ({ projectId, memberId }) => deleteProject(projectId, memberId),
|
||||
// onSuccess: (_, variables) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['projects', variables.projectId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
export const useAddProjectMember = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<
|
||||
ProjectMemberResponse,
|
||||
Error,
|
||||
{ projectId: number; memberId: number; newMember: ProjectMemberRequest }
|
||||
>({
|
||||
mutationFn: ({ projectId, memberId, newMember }) => addProjectMember(projectId, memberId, newMember),
|
||||
onSuccess: (_, { projectId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projectMembers', projectId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// export const useAddProjectMember = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
// return useMutation<
|
||||
// ProjectMemberResponse,
|
||||
// Error,
|
||||
// { projectId: number; memberId: number; newMember: ProjectMemberRequest }
|
||||
// >({
|
||||
// mutationFn: ({ projectId, memberId, newMember }) => addProjectMember(projectId, memberId, newMember),
|
||||
// onSuccess: (_, { projectId }) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['projectMembers', projectId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
// 프로젝트 멤버 권한 수정 훅
|
||||
export const useUpdateProjectMemberPrivilege = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<
|
||||
ProjectMemberResponse,
|
||||
Error,
|
||||
{ projectId: number; memberId: number; privilegeData: ProjectMemberRequest }
|
||||
>({
|
||||
mutationFn: ({ projectId, memberId, privilegeData }) =>
|
||||
updateProjectMemberPrivilege(projectId, memberId, privilegeData),
|
||||
onSuccess: (_, { projectId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projectMembers', projectId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// // 프로젝트 멤버 권한 수정 훅
|
||||
// export const useUpdateProjectMemberPrivilege = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
// return useMutation<
|
||||
// ProjectMemberResponse,
|
||||
// Error,
|
||||
// { projectId: number; memberId: number; privilegeData: ProjectMemberRequest }
|
||||
// >({
|
||||
// mutationFn: ({ projectId, memberId, privilegeData }) =>
|
||||
// updateProjectMemberPrivilege(projectId, memberId, privilegeData),
|
||||
// onSuccess: (_, { projectId }) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['projectMembers', projectId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
// 프로젝트 멤버 삭제 훅
|
||||
export const useRemoveProjectMember = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<void, Error, { projectId: number; memberId: number; targetMemberId: number }>({
|
||||
mutationFn: ({ projectId, memberId, targetMemberId }) => removeProjectMember(projectId, memberId, targetMemberId),
|
||||
onSuccess: (_, { projectId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projectMembers', projectId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// // 프로젝트 멤버 삭제 훅
|
||||
// export const useRemoveProjectMember = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
// return useMutation<void, Error, { projectId: number; memberId: number; targetMemberId: number }>({
|
||||
// mutationFn: ({ projectId, memberId, targetMemberId }) => removeProjectMember(projectId, memberId, targetMemberId),
|
||||
// onSuccess: (_, { projectId }) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['projectMembers', projectId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
@ -1,57 +1,57 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { createReview, updateReview, deleteReview, updateReviewStatus } from '@/api/reviewApi';
|
||||
import { ReviewRequest, ReviewResponse } from '@/types';
|
||||
// import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
// import { createReview, updateReview, deleteReview, updateReviewStatus } from '@/api/reviewApi';
|
||||
// import { ReviewRequest, ReviewResponse } from '@/types';
|
||||
|
||||
// 리뷰 생성 훅
|
||||
export const useCreateReview = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<ReviewResponse, Error, { projectId: number; memberId: number; reviewData: ReviewRequest }>({
|
||||
mutationFn: ({ projectId, memberId, reviewData }) => createReview(projectId, memberId, reviewData),
|
||||
onSuccess: (_, { projectId, memberId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['reviewList', projectId, memberId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// // 리뷰 생성 훅
|
||||
// export const useCreateReview = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
// return useMutation<ReviewResponse, Error, { projectId: number; memberId: number; reviewData: ReviewRequest }>({
|
||||
// mutationFn: ({ projectId, memberId, reviewData }) => createReview(projectId, memberId, reviewData),
|
||||
// onSuccess: (_, { projectId, memberId }) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['reviewList', projectId, memberId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
// 리뷰 수정 훅
|
||||
export const useUpdateReview = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<
|
||||
ReviewResponse,
|
||||
Error,
|
||||
{ projectId: number; reviewId: number; memberId: number; reviewData: ReviewRequest }
|
||||
>({
|
||||
mutationFn: ({ projectId, reviewId, memberId, reviewData }) =>
|
||||
updateReview(projectId, reviewId, memberId, reviewData),
|
||||
onSuccess: (_, { projectId, reviewId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['reviewDetail', projectId, reviewId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// // 리뷰 수정 훅
|
||||
// export const useUpdateReview = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
// return useMutation<
|
||||
// ReviewResponse,
|
||||
// Error,
|
||||
// { projectId: number; reviewId: number; memberId: number; reviewData: ReviewRequest }
|
||||
// >({
|
||||
// mutationFn: ({ projectId, reviewId, memberId, reviewData }) =>
|
||||
// updateReview(projectId, reviewId, memberId, reviewData),
|
||||
// onSuccess: (_, { projectId, reviewId }) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['reviewDetail', projectId, reviewId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
// 리뷰 삭제 훅
|
||||
export const useDeleteReview = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<void, Error, { projectId: number; reviewId: number; memberId: number }>({
|
||||
mutationFn: ({ projectId, reviewId, memberId }) => deleteReview(projectId, reviewId, memberId),
|
||||
onSuccess: (_, { projectId, reviewId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['reviewDetail', projectId, reviewId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// // 리뷰 삭제 훅
|
||||
// export const useDeleteReview = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
// return useMutation<void, Error, { projectId: number; reviewId: number; memberId: number }>({
|
||||
// mutationFn: ({ projectId, reviewId, memberId }) => deleteReview(projectId, reviewId, memberId),
|
||||
// onSuccess: (_, { projectId, reviewId }) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['reviewDetail', projectId, reviewId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
// 리뷰 상태 변경 훅
|
||||
export const useUpdateReviewStatus = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<
|
||||
ReviewResponse,
|
||||
Error,
|
||||
{ projectId: number; reviewId: number; memberId: number; reviewStatus: string }
|
||||
>({
|
||||
mutationFn: ({ projectId, reviewId, memberId, reviewStatus }) =>
|
||||
updateReviewStatus(projectId, reviewId, memberId, reviewStatus),
|
||||
onSuccess: (_, { projectId, reviewId }) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['reviewDetail', projectId, reviewId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// // 리뷰 상태 변경 훅
|
||||
// export const useUpdateReviewStatus = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
// return useMutation<
|
||||
// ReviewResponse,
|
||||
// Error,
|
||||
// { projectId: number; reviewId: number; memberId: number; reviewStatus: string }
|
||||
// >({
|
||||
// mutationFn: ({ projectId, reviewId, memberId, reviewStatus }) =>
|
||||
// updateReviewStatus(projectId, reviewId, memberId, reviewStatus),
|
||||
// onSuccess: (_, { projectId, reviewId }) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['reviewDetail', projectId, reviewId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
@ -88,68 +88,68 @@
|
||||
// });
|
||||
// };
|
||||
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import {
|
||||
createWorkspace,
|
||||
updateWorkspace,
|
||||
deleteWorkspace,
|
||||
addWorkspaceMember,
|
||||
removeWorkspaceMember,
|
||||
} from '@/api/workspaceApi';
|
||||
import { WorkspaceResponse, WorkspaceRequest } from '@/types';
|
||||
// import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
// import {
|
||||
// createWorkspace,
|
||||
// updateWorkspace,
|
||||
// deleteWorkspace,
|
||||
// addWorkspaceMember,
|
||||
// removeWorkspaceMember,
|
||||
// } from '@/api/workspaceApi';
|
||||
// import { WorkspaceResponse, WorkspaceRequest } from '@/types';
|
||||
|
||||
export const useCreateWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
// export const useCreateWorkspace = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<WorkspaceResponse, Error, { memberId: number; data: WorkspaceRequest }>({
|
||||
mutationFn: ({ memberId, data }) => createWorkspace(memberId, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspaceList'] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// return useMutation<WorkspaceResponse, Error, { memberId: number; data: WorkspaceRequest }>({
|
||||
// mutationFn: ({ memberId, data }) => createWorkspace(memberId, data),
|
||||
// onSuccess: () => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['workspaceList'] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
export const useUpdateWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
// export const useUpdateWorkspace = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<WorkspaceResponse, Error, { workspaceId: number; memberId: number; data: WorkspaceRequest }>({
|
||||
mutationFn: ({ workspaceId, memberId, data }) => updateWorkspace(workspaceId, memberId, data),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// return useMutation<WorkspaceResponse, Error, { workspaceId: number; memberId: number; data: WorkspaceRequest }>({
|
||||
// mutationFn: ({ workspaceId, memberId, data }) => updateWorkspace(workspaceId, memberId, data),
|
||||
// onSuccess: (_, variables) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
export const useDeleteWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
// export const useDeleteWorkspace = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<void, Error, { workspaceId: number; memberId: number }>({
|
||||
mutationFn: ({ workspaceId, memberId }) => deleteWorkspace(workspaceId, memberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// return useMutation<void, Error, { workspaceId: number; memberId: number }>({
|
||||
// mutationFn: ({ workspaceId, memberId }) => deleteWorkspace(workspaceId, memberId),
|
||||
// onSuccess: (_, variables) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
export const useAddWorkspaceMember = () => {
|
||||
const queryClient = useQueryClient();
|
||||
// export const useAddWorkspaceMember = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<void, Error, { workspaceId: number; memberId: number; newMemberId: number }>({
|
||||
mutationFn: ({ workspaceId, memberId, newMemberId }) => addWorkspaceMember(workspaceId, memberId, newMemberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// return useMutation<void, Error, { workspaceId: number; memberId: number; newMemberId: number }>({
|
||||
// mutationFn: ({ workspaceId, memberId, newMemberId }) => addWorkspaceMember(workspaceId, memberId, newMemberId),
|
||||
// onSuccess: (_, variables) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
export const useRemoveWorkspaceMember = () => {
|
||||
const queryClient = useQueryClient();
|
||||
// export const useRemoveWorkspaceMember = () => {
|
||||
// const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<void, Error, { workspaceId: number; memberId: number; targetMemberId: number }>({
|
||||
mutationFn: ({ workspaceId, memberId, targetMemberId }) =>
|
||||
removeWorkspaceMember(workspaceId, memberId, targetMemberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
};
|
||||
// return useMutation<void, Error, { workspaceId: number; memberId: number; targetMemberId: number }>({
|
||||
// mutationFn: ({ workspaceId, memberId, targetMemberId }) =>
|
||||
// removeWorkspaceMember(workspaceId, memberId, targetMemberId),
|
||||
// onSuccess: (_, variables) => {
|
||||
// queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
16
frontend/src/queries/auth/useReissueTokenQuery.ts
Normal file
16
frontend/src/queries/auth/useReissueTokenQuery.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import useAuthStore from '@/stores/useAuthStore';
|
||||
import { reissueToken } from '@/api/authApi';
|
||||
|
||||
export default function useReissueTokenQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
const { setLoggedIn } = useAuthStore();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: reissueToken,
|
||||
onSuccess: (data) => {
|
||||
setLoggedIn(true, data.accessToken);
|
||||
queryClient.invalidateQueries({ queryKey: ['profile'] });
|
||||
},
|
||||
});
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
import { fetchFolder } from '@/api/folderApi';
|
||||
import { getFolder } from '@/api/folderApi';
|
||||
import { useSuspenseQuery } from '@tanstack/react-query';
|
||||
|
||||
export default function useFolderQuery(projectId: number, folderId: number, memberId: number) {
|
||||
return useSuspenseQuery({
|
||||
queryKey: ['folder', projectId, folderId, memberId],
|
||||
queryFn: () => fetchFolder(projectId, folderId, memberId),
|
||||
queryFn: () => getFolder(projectId, folderId, memberId),
|
||||
});
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import { getFolderReviewList } from '@/api/folderApi';
|
||||
import { useSuspenseQuery } from '@tanstack/react-query';
|
||||
|
||||
export function useFolderReviewListQuery(projectId: number, folderId: number, memberId: number) {
|
||||
export default function useFolderReviewListQuery(projectId: number, folderId: number, memberId: number) {
|
||||
return useSuspenseQuery({
|
||||
queryKey: ['folderReviewList', projectId, folderId, memberId],
|
||||
queryFn: () => getFolderReviewList(projectId, folderId, memberId),
|
22
frontend/src/queries/projects/useAddProjectMemberQuery.ts
Normal file
22
frontend/src/queries/projects/useAddProjectMemberQuery.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { addProjectMember } from '@/api/projectApi';
|
||||
import { ProjectMemberRequest } from '@/types';
|
||||
|
||||
export default function useAddProjectMemberQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
projectId,
|
||||
memberId,
|
||||
newMember,
|
||||
}: {
|
||||
projectId: number;
|
||||
memberId: number;
|
||||
newMember: ProjectMemberRequest;
|
||||
}) => addProjectMember(projectId, memberId, newMember),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projectMembers', variables.projectId] });
|
||||
},
|
||||
});
|
||||
}
|
15
frontend/src/queries/projects/useCreateProjectQuery.ts
Normal file
15
frontend/src/queries/projects/useCreateProjectQuery.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { createProject } from '@/api/projectApi';
|
||||
import { ProjectRequest } from '@/types';
|
||||
|
||||
export default function useCreateProjectQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ workspaceId, memberId, data }: { workspaceId: number; memberId: number; data: ProjectRequest }) =>
|
||||
createProject(workspaceId, memberId, data),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projects', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
}
|
14
frontend/src/queries/projects/useDeleteProjectQuery.ts
Normal file
14
frontend/src/queries/projects/useDeleteProjectQuery.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { deleteProject } from '@/api/projectApi';
|
||||
|
||||
export default function useDeleteProjectQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ projectId, memberId }: { projectId: number; memberId: number }) =>
|
||||
deleteProject(projectId, memberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projects', variables.projectId] });
|
||||
},
|
||||
});
|
||||
}
|
21
frontend/src/queries/projects/useRemoveProjectMemberQuery.ts
Normal file
21
frontend/src/queries/projects/useRemoveProjectMemberQuery.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { removeProjectMember } from '@/api/projectApi';
|
||||
|
||||
export default function useRemoveProjectMemberQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
projectId,
|
||||
memberId,
|
||||
targetMemberId,
|
||||
}: {
|
||||
projectId: number;
|
||||
memberId: number;
|
||||
targetMemberId: number;
|
||||
}) => removeProjectMember(projectId, memberId, targetMemberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projectMembers', variables.projectId] });
|
||||
},
|
||||
});
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { updateProjectMemberPrivilege } from '@/api/projectApi';
|
||||
import { ProjectMemberRequest } from '@/types';
|
||||
|
||||
export default function useUpdateProjectMemberPrivilegeQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
projectId,
|
||||
memberId,
|
||||
privilegeData,
|
||||
}: {
|
||||
projectId: number;
|
||||
memberId: number;
|
||||
privilegeData: ProjectMemberRequest;
|
||||
}) => updateProjectMemberPrivilege(projectId, memberId, privilegeData),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projectMembers', variables.projectId] });
|
||||
},
|
||||
});
|
||||
}
|
15
frontend/src/queries/projects/useUpdateProjectQuery.ts
Normal file
15
frontend/src/queries/projects/useUpdateProjectQuery.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { updateProject } from '@/api/projectApi';
|
||||
import { ProjectRequest } from '@/types';
|
||||
|
||||
export default function useUpdateProjectQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ projectId, memberId, data }: { projectId: number; memberId: number; data: ProjectRequest }) =>
|
||||
updateProject(projectId, memberId, data),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['project', variables.projectId] });
|
||||
},
|
||||
});
|
||||
}
|
22
frontend/src/queries/reviews/useCreateReviewQuery.ts
Normal file
22
frontend/src/queries/reviews/useCreateReviewQuery.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { createReview } from '@/api/reviewApi';
|
||||
import { ReviewRequest } from '@/types';
|
||||
|
||||
export default function useCreateReviewQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
projectId,
|
||||
memberId,
|
||||
reviewData,
|
||||
}: {
|
||||
projectId: number;
|
||||
memberId: number;
|
||||
reviewData: ReviewRequest;
|
||||
}) => createReview(projectId, memberId, reviewData),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['reviewList', variables.projectId, variables.memberId] });
|
||||
},
|
||||
});
|
||||
}
|
14
frontend/src/queries/reviews/useDeleteReviewQuery.ts
Normal file
14
frontend/src/queries/reviews/useDeleteReviewQuery.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { deleteReview } from '@/api/reviewApi';
|
||||
|
||||
export default function useDeleteReviewQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ projectId, reviewId, memberId }: { projectId: number; reviewId: number; memberId: number }) =>
|
||||
deleteReview(projectId, reviewId, memberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['reviewDetail', variables.projectId, variables.reviewId] });
|
||||
},
|
||||
});
|
||||
}
|
24
frontend/src/queries/reviews/useUpdateReviewQuery.ts
Normal file
24
frontend/src/queries/reviews/useUpdateReviewQuery.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { updateReview } from '@/api/reviewApi';
|
||||
import { ReviewRequest } from '@/types';
|
||||
|
||||
export default function useUpdateReviewQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
projectId,
|
||||
reviewId,
|
||||
memberId,
|
||||
reviewData,
|
||||
}: {
|
||||
projectId: number;
|
||||
reviewId: number;
|
||||
memberId: number;
|
||||
reviewData: ReviewRequest;
|
||||
}) => updateReview(projectId, reviewId, memberId, reviewData),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['reviewDetail', variables.projectId, variables.reviewId] });
|
||||
},
|
||||
});
|
||||
}
|
23
frontend/src/queries/reviews/useUpdateReviewStatusQuery.ts
Normal file
23
frontend/src/queries/reviews/useUpdateReviewStatusQuery.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { updateReviewStatus } from '@/api/reviewApi';
|
||||
|
||||
export default function useUpdateReviewStatusQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
projectId,
|
||||
reviewId,
|
||||
memberId,
|
||||
reviewStatus,
|
||||
}: {
|
||||
projectId: number;
|
||||
reviewId: number;
|
||||
memberId: number;
|
||||
reviewStatus: string;
|
||||
}) => updateReviewStatus(projectId, reviewId, memberId, reviewStatus),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['reviewDetail', variables.projectId, variables.reviewId] });
|
||||
},
|
||||
});
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { addWorkspaceMember } from '@/api/workspaceApi';
|
||||
|
||||
export default function useAddWorkspaceMemberQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
workspaceId,
|
||||
memberId,
|
||||
newMemberId,
|
||||
}: {
|
||||
workspaceId: number;
|
||||
memberId: number;
|
||||
newMemberId: number;
|
||||
}) => addWorkspaceMember(workspaceId, memberId, newMemberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
}
|
14
frontend/src/queries/workspaces/useCreateWorkspaceQuery.ts
Normal file
14
frontend/src/queries/workspaces/useCreateWorkspaceQuery.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { createWorkspace } from '@/api/workspaceApi';
|
||||
import { WorkspaceRequest } from '@/types';
|
||||
|
||||
export default function useCreateWorkspaceQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ memberId, data }: { memberId: number; data: WorkspaceRequest }) => createWorkspace(memberId, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspaceList'] });
|
||||
},
|
||||
});
|
||||
}
|
14
frontend/src/queries/workspaces/useDeleteWorkspaceQuery.ts
Normal file
14
frontend/src/queries/workspaces/useDeleteWorkspaceQuery.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { deleteWorkspace } from '@/api/workspaceApi';
|
||||
|
||||
export default function useDeleteWorkspaceQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ workspaceId, memberId }: { workspaceId: number; memberId: number }) =>
|
||||
deleteWorkspace(workspaceId, memberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { removeWorkspaceMember } from '@/api/workspaceApi';
|
||||
|
||||
export default function useRemoveWorkspaceMemberQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
workspaceId,
|
||||
memberId,
|
||||
targetMemberId,
|
||||
}: {
|
||||
workspaceId: number;
|
||||
memberId: number;
|
||||
targetMemberId: number;
|
||||
}) => removeWorkspaceMember(workspaceId, memberId, targetMemberId),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
}
|
15
frontend/src/queries/workspaces/useUpdateWorkspaceQuery.ts
Normal file
15
frontend/src/queries/workspaces/useUpdateWorkspaceQuery.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { updateWorkspace } from '@/api/workspaceApi';
|
||||
import { WorkspaceRequest } from '@/types';
|
||||
|
||||
export default function useUpdateWorkspaceQuery() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ workspaceId, memberId, data }: { workspaceId: number; memberId: number; data: WorkspaceRequest }) =>
|
||||
updateWorkspace(workspaceId, memberId, data),
|
||||
onSuccess: (_, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['workspace', variables.workspaceId] });
|
||||
},
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user