-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from hufs-sports-live/feat/admin-league
[REFACTOR]: 관리자 리그 쿼리, 스크롤락, 리그 삭제 버그픽스
- Loading branch information
Showing
24 changed files
with
201 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const ADMIN_MUTATION_KEY = { | ||
POST_NEW_LEAGUE: 'POST_NEW_LEAGUE', | ||
PUT_LEAGUE: 'PUT_LEAGUE', | ||
DELETE_LEAGUE: 'DELETE_LEAGUE', | ||
POST_TEAM: 'POST_TEAM', | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const ADMIN_QUERY_KEY = { | ||
LEAGUE_LIST: 'LEAGUE_LIST', | ||
LEAGUE_SPORTS: 'LEAGUE_SPORTS', | ||
SPORTS_LIST: 'SPORTS_LIST', | ||
TEAM_LIST: 'TEAM_LIST', | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { deleteLeagueByIdWithAuth } from '@/api/admin/league'; | ||
import { ADMIN_MUTATION_KEY } from '@/constants/admin/mutationKey'; | ||
import { ADMIN_QUERY_KEY } from '@/constants/admin/queryKey'; | ||
|
||
export default function useDeleteLeagueMutation() { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: [ADMIN_MUTATION_KEY.DELETE_LEAGUE], | ||
mutationFn: deleteLeagueByIdWithAuth, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [ADMIN_QUERY_KEY.LEAGUE_LIST], | ||
}); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
|
||
import { getAllLeaguesWithAuth } from '@/api/admin/league'; | ||
import { ADMIN_QUERY_KEY } from '@/constants/admin/queryKey'; | ||
|
||
export default function useLeagueList() { | ||
const { data, error } = useSuspenseQuery({ | ||
queryKey: [ADMIN_QUERY_KEY.LEAGUE_LIST], | ||
queryFn: () => getAllLeaguesWithAuth(), | ||
}); | ||
|
||
return { | ||
data, | ||
error, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useSuspenseQueries, useSuspenseQuery } from '@tanstack/react-query'; | ||
|
||
import { | ||
getAllLeaguesWithAuth, | ||
getSportsCategoriesWithAuth, | ||
} from '@/api/admin/league'; | ||
import { ADMIN_QUERY_KEY } from '@/constants/admin/queryKey'; | ||
|
||
export default function useSportsList() { | ||
const { data, error } = useSuspenseQuery({ | ||
queryKey: [ADMIN_QUERY_KEY.SPORTS_LIST], | ||
queryFn: () => getSportsCategoriesWithAuth(), | ||
}); | ||
|
||
return { | ||
data, | ||
error, | ||
}; | ||
} | ||
|
||
export function useLeagueRegisterData() { | ||
// leagueRegisterFetcher에서 각 쿼리의 data를 지명해서 변수로 쓰고 싶은데, 아래와 같이 작성하면 array 데이터로 묶여서 사용하기 불편해짐 | ||
// TODO: 복수 쿼리들의 결과값을 1:1 네이밍해 내보낼 수 있는 방법 찾기 | ||
return useSuspenseQueries({ | ||
queries: [ | ||
{ | ||
queryKey: [ADMIN_QUERY_KEY.LEAGUE_LIST], | ||
queryFn: getAllLeaguesWithAuth, | ||
}, | ||
{ | ||
queryKey: [ADMIN_QUERY_KEY.SPORTS_LIST], | ||
queryFn: getSportsCategoriesWithAuth, | ||
}, | ||
], | ||
combine: results => { | ||
return { | ||
data: results.map(result => result.data), | ||
error: results.some(result => result.error), | ||
}; | ||
}, | ||
}); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/queries/admin/league/usePostNewLeagueMutation/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { postNewLeagueWithAuth } from '@/api/admin/league'; | ||
import { ADMIN_MUTATION_KEY } from '@/constants/admin/mutationKey'; | ||
import { ADMIN_QUERY_KEY } from '@/constants/admin/queryKey'; | ||
import { useLeagueIdContext } from '@/hooks/useLeagueIdContext'; | ||
|
||
export default function usePostNewLeagueMutation() { | ||
const queryClient = useQueryClient(); | ||
const { setLeagueId } = useLeagueIdContext(); | ||
|
||
return useMutation({ | ||
mutationKey: [ADMIN_MUTATION_KEY.POST_NEW_LEAGUE], | ||
mutationFn: postNewLeagueWithAuth, | ||
onSuccess: data => { | ||
const { leagueId } = data; | ||
setLeagueId(leagueId.toString()); | ||
queryClient.invalidateQueries({ | ||
queryKey: [ADMIN_QUERY_KEY.LEAGUE_LIST], | ||
}); | ||
queryClient.invalidateQueries({ | ||
queryKey: [ADMIN_QUERY_KEY.LEAGUE_SPORTS, leagueId], | ||
}); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { putLeagueWithAuth } from '@/api/admin/league'; | ||
import { ADMIN_MUTATION_KEY } from '@/constants/admin/mutationKey'; | ||
import { ADMIN_QUERY_KEY } from '@/constants/admin/queryKey'; | ||
|
||
export default function usePutLeagueMutation() { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: [ADMIN_MUTATION_KEY.PUT_LEAGUE], | ||
mutationFn: putLeagueWithAuth, | ||
onSuccess: leagueId => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [ADMIN_QUERY_KEY.LEAGUE_LIST], | ||
}); | ||
queryClient.invalidateQueries({ | ||
queryKey: [ADMIN_QUERY_KEY.LEAGUE_SPORTS, leagueId], | ||
}); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { postTeamByLeagueIdWithAuth } from '@/api/admin/team'; | ||
import { ADMIN_MUTATION_KEY } from '@/constants/admin/mutationKey'; | ||
import { ADMIN_QUERY_KEY } from '@/constants/admin/queryKey'; | ||
|
||
export default function usePostTeamMutation(leagueId: string) { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: [ADMIN_MUTATION_KEY.POST_TEAM], | ||
mutationFn: postTeamByLeagueIdWithAuth, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [ADMIN_QUERY_KEY.TEAM_LIST, leagueId], | ||
}); | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
|
||
import { getTeamListByLeagueIdWithAuth } from '@/api/admin/team'; | ||
import { ADMIN_QUERY_KEY } from '@/constants/admin/queryKey'; | ||
|
||
export default function useTeamListByLeagueId(leagueId: string) { | ||
const { data, error } = useSuspenseQuery({ | ||
queryKey: [ADMIN_QUERY_KEY.TEAM_LIST, leagueId], | ||
queryFn: () => getTeamListByLeagueIdWithAuth(leagueId), | ||
}); | ||
|
||
return { | ||
teamList: data, | ||
error, | ||
}; | ||
} |
Oops, something went wrong.