Skip to content

Commit

Permalink
Fix: #165 중복 Generator 쿼리 키 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-bear98 committed Oct 9, 2024
1 parent 2dead7a commit 4b77d7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
12 changes: 6 additions & 6 deletions src/hooks/query/useTeamQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { generateCoworkersQueryKey, generateTeamsQueryKey } from '@utils/queryKeyGenerator';
import { generateTeamCoworkersQueryKey, generateTeamsQueryKey } from '@utils/queryKeyGenerator';

import { getTeamList } from '@services/userService';
import {
Expand Down Expand Up @@ -63,7 +63,7 @@ export function useLeaveTeam() {
export function useDeleteTeam(teamId: Team['teamId']) {
const queryClient = useQueryClient();
const { toastSuccess, toastError } = useToast();
const teamCoworkersQueryKey = generateCoworkersQueryKey(teamId);
const teamCoworkersQueryKey = generateTeamCoworkersQueryKey(teamId);

const mutation = useMutation({
mutationFn: (teamId: Team['teamId']) => deleteTeam(teamId),
Expand Down Expand Up @@ -166,7 +166,7 @@ export function useUpdateTeamInfo() {
export function useAddTeamCoworker(teamId: Team['teamId']) {
const queryClient = useQueryClient();
const { toastSuccess, toastError } = useToast();
const teamCoworkersQueryKey = generateCoworkersQueryKey(teamId);
const teamCoworkersQueryKey = generateTeamCoworkersQueryKey(teamId);

const mutation = useMutation({
mutationFn: ({ userId, roleName }: TeamCoworker) => addTeamMember(teamId, userId, roleName),
Expand All @@ -186,7 +186,7 @@ export function useAddTeamCoworker(teamId: Team['teamId']) {
export function useDeleteTeamCoworker(teamId: Team['teamId']) {
const queryClient = useQueryClient();
const { toastSuccess, toastError } = useToast();
const teamCoworkersQueryKey = generateCoworkersQueryKey(teamId);
const teamCoworkersQueryKey = generateTeamCoworkersQueryKey(teamId);

const mutation = useMutation({
mutationFn: (userId: number) => removeTeamMember(teamId, userId),
Expand All @@ -206,7 +206,7 @@ export function useDeleteTeamCoworker(teamId: Team['teamId']) {
export function useUpdateTeamCoworkerRole(teamId: Team['teamId']) {
const queryClient = useQueryClient();
const { toastSuccess, toastError } = useToast();
const teamCoworkersQueryKey = generateCoworkersQueryKey(teamId);
const teamCoworkersQueryKey = generateTeamCoworkersQueryKey(teamId);

const mutation = useMutation({
mutationFn: ({ userId, roleName }: TeamCoworker) => updateTeamRole(teamId, userId, roleName),
Expand All @@ -230,7 +230,7 @@ export function useReadTeamCoworkers(teamId: Team['teamId']) {
isLoading,
isError,
} = useQuery({
queryKey: generateCoworkersQueryKey(teamId),
queryKey: generateTeamCoworkersQueryKey(teamId),
queryFn: async () => {
const { data } = await findTeamCoworker(teamId);
return data;
Expand Down
35 changes: 1 addition & 34 deletions src/utils/queryKeyGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,7 @@ export function generateProjectsQueryKey(teamId: Team['teamId']) {
* @param {Team['teamId']} teamId - 팀 ID
* @returns {(string | number)[]}
*/
export function generateCoworkersQueryKey(teamId: Team['teamId']) {
return [queryKeys.teams, teamId, queryKeys.coworkers];
}

/**
* 팀원 추가에 대한 queryKey 생성 함수
*
* @export
* @param {Team['teamId']} teamId - 팀 ID
* @returns {(string | number)[]}
*/
export function generateAddCoworkerQueryKey(teamId: Team['teamId']) {
return [queryKeys.teams, teamId, queryKeys.coworkers];
}

/**
* 팀원 삭제에 대한 queryKey 생성 함수
*
* @export
* @param {Team['teamId']} teamId - 팀 ID
* @returns {(string | number)[]}
*/
export function generateDeleteCoworkerQueryKey(teamId: Team['teamId']) {
return [queryKeys.teams, teamId, queryKeys.coworkers];
}

/**
* 팀원 권한 수정에 대한 queryKey 생성 함수
*
* @export
* @param {Team['teamId']} teamId - 팀 ID
* @returns {(string | number)[]}
*/
export function generateUpdateRoleQueryKey(teamId: Team['teamId']) {
export function generateTeamCoworkersQueryKey(teamId: Team['teamId']) {
return [queryKeys.teams, teamId, queryKeys.coworkers];
}

Expand Down

0 comments on commit 4b77d7b

Please sign in to comment.