Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:#225 팀 쿼리 키 userId 추가 및 프로젝트 목록 조회 teamId null시 처리 추가 #227

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/modal/project/UpdateModalProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ModalButton from '@components/modal/ModalButton';
import ModalProjectForm from '@components/modal/project/ModalProjectForm';

import type { SubmitHandler } from 'react-hook-form';
import type { Project } from '@/types/ProjectType';
import type { Project, ProjectForm } from '@/types/ProjectType';

type UpdateModalProjectProps = {
projectId: Project['projectId'];
Expand All @@ -14,7 +14,7 @@ type UpdateModalProjectProps = {
export default function UpdateModalProject({ projectId, onClose: handleClose }: UpdateModalProjectProps) {
const updateProjectFormId = 'updateProjectForm';

const handleSubmit: SubmitHandler<Project> = async (data) => {
const handleSubmit: SubmitHandler<ProjectForm> = async (data) => {
console.log('프로젝트 생성 폼 제출');
console.log(data);
handleClose();
Expand Down
1 change: 1 addition & 0 deletions src/hooks/query/useProjectQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function useReadProjects(teamId: Team['teamId']) {
const { data } = await getProjectList(teamId);
return data;
},
enabled: !!teamId,
});

return { projectList, isProjectLoading, isProjectError, projectError };
Expand Down
22 changes: 14 additions & 8 deletions src/hooks/query/useTeamQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@services/teamService';
import useToast from '@hooks/useToast';
import { useMemo } from 'react';
import useStore from '@stores/useStore';
import type {
Team,
TeamCoworker,
Expand All @@ -28,13 +29,14 @@ import type { User } from '@/types/UserType';

// 전체 팀 목록 조회
export function useReadTeams() {
const { userInfo } = useStore();
const {
data = [],
isLoading,
isError,
error,
} = useQuery<TeamListWithApproval[], Error>({
queryKey: generateTeamsQueryKey(),
queryKey: generateTeamsQueryKey(userInfo.userId),
queryFn: async () => {
const { data } = await getTeamList();
return data;
Expand All @@ -51,8 +53,8 @@ export function useReadTeams() {
export function useLeaveTeam() {
const queryClient = useQueryClient();
const { toastSuccess, toastError } = useToast();
const teamsQueryKey = generateTeamsQueryKey();

const { userInfo } = useStore();
const teamsQueryKey = generateTeamsQueryKey(userInfo.userId);
const mutation = useMutation({
mutationFn: (teamId: Team['teamId']) => leaveTeam(teamId),
onError: () => {
Expand Down Expand Up @@ -91,7 +93,8 @@ export function useDeleteTeam() {
export function useApproveTeamInvitation() {
const queryClient = useQueryClient();
const { toastSuccess, toastError } = useToast();
const teamsQueryKey = generateTeamsQueryKey();
const { userInfo } = useStore();
const teamsQueryKey = generateTeamsQueryKey(userInfo.userId);

const mutation = useMutation({
mutationFn: (teamId: Team['teamId']) => acceptTeamInvitation(teamId),
Expand All @@ -111,7 +114,8 @@ export function useApproveTeamInvitation() {
export function useRejectTeamInvitation() {
const queryClient = useQueryClient();
const { toastSuccess, toastError } = useToast();
const teamsQueryKey = generateTeamsQueryKey();
const { userInfo } = useStore();
const teamsQueryKey = generateTeamsQueryKey(userInfo.userId);

const mutation = useMutation({
mutationFn: (teamId: Team['teamId']) => declineTeamInvitation(teamId),
Expand All @@ -131,7 +135,8 @@ export function useRejectTeamInvitation() {
export function useCreateTeam() {
const queryClient = useQueryClient();
const { toastSuccess, toastError } = useToast();
const teamsQueryKey = generateTeamsQueryKey();
const { userInfo } = useStore();
const teamsQueryKey = generateTeamsQueryKey(userInfo.userId);

const mutation = useMutation({
mutationFn: async (data: TeamForm) => {
Expand All @@ -142,7 +147,7 @@ export function useCreateTeam() {
},
onSuccess: () => {
toastSuccess('팀을 성공적으로 생성했습니다.');
queryClient.invalidateQueries({ queryKey: teamsQueryKey });
queryClient.invalidateQueries({ queryKey: teamsQueryKey, exact: true });
},
});

Expand All @@ -153,7 +158,8 @@ export function useCreateTeam() {
export function useUpdateTeamInfo() {
const queryClient = useQueryClient();
const { toastSuccess, toastError } = useToast();
const teamsQueryKey = generateTeamsQueryKey();
const { userInfo } = useStore();
const teamsQueryKey = generateTeamsQueryKey(userInfo.userId);

const mutation = useMutation({
mutationFn: ({ teamId, teamInfo }: { teamId: Team['teamId']; teamInfo: TeamInfoForm }) =>
Expand Down
1 change: 1 addition & 0 deletions src/mocks/services/projectServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const projectServiceHandler = [
// 프로젝트 목록 조회 API
http.get(`${BASE_URL}/team/:teamId/project`, ({ request, params }) => {
const accessToken = request.headers.get('Authorization');

const teamId = Number(params.teamId);

// 유저 인증 확인
Expand Down
12 changes: 7 additions & 5 deletions src/utils/queryKeyGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Task } from '@/types/TaskType';
import type { Team } from '@/types/TeamType';
import type { Project } from '@/types/ProjectType';
import type { User } from '@/types/UserType';

export const queryKeys = {
userInfo: 'userInfo',
Expand Down Expand Up @@ -29,21 +30,22 @@ export function generateUserInfoQueryKey() {
* 유저 링크 queryKey 생성 함수
*
* @export
* @param {number} userId - 유저의 고유 ID
* @param {userId: User['userId']} userId - 유저의 고유 ID
* @returns {(string | number)[]}
*/
export function generateLinksQueryKey(userId: number) {
export function generateLinksQueryKey(userId: User['userId']) {
return [queryKeys.links, userId];
}

/**
* 유저의 팀 목록 queryKey 생성 함수
*
* @export
* @export\
* @param {userId: User['userId']} userId
* @returns {(string | number)[]}
*/
export function generateTeamsQueryKey() {
return [queryKeys.teams];
export function generateTeamsQueryKey(userId: User['userId']) {
return [queryKeys.teams, userId];
}

/**
Expand Down