From 3c1b8ace08b5d8b52a4853322f9f97e6f2f743bc Mon Sep 17 00:00:00 2001 From: HiImConan Date: Thu, 30 Nov 2023 16:18:44 +0900 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20admin=EC=9A=A9=20=EC=83=81?= =?UTF-8?q?=EC=88=98=20=ED=8C=8C=EC=9D=BC=20=EB=B6=84=EA=B8=B0=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BF=BC=EB=A6=AC=ED=82=A4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/{adminDescription.ts => admin/description.ts} | 0 src/constants/admin/mutationKey.ts | 6 ++++++ src/constants/admin/queryKey.ts | 6 ++++++ 3 files changed, 12 insertions(+) rename src/constants/{adminDescription.ts => admin/description.ts} (100%) create mode 100644 src/constants/admin/mutationKey.ts create mode 100644 src/constants/admin/queryKey.ts diff --git a/src/constants/adminDescription.ts b/src/constants/admin/description.ts similarity index 100% rename from src/constants/adminDescription.ts rename to src/constants/admin/description.ts diff --git a/src/constants/admin/mutationKey.ts b/src/constants/admin/mutationKey.ts new file mode 100644 index 0000000..5087fab --- /dev/null +++ b/src/constants/admin/mutationKey.ts @@ -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; diff --git a/src/constants/admin/queryKey.ts b/src/constants/admin/queryKey.ts new file mode 100644 index 0000000..0a194c7 --- /dev/null +++ b/src/constants/admin/queryKey.ts @@ -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; From 1e3149af3fb551a5d9b71067ee6a6b090e483017 Mon Sep 17 00:00:00 2001 From: HiImConan Date: Thu, 30 Nov 2023 16:34:28 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20league/team=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=ED=8F=B4=EB=8D=94=20=EB=B6=84=EB=A6=AC,=20query.ts?= =?UTF-8?q?=20=EB=82=B4=20=EB=8B=A8=EC=9D=BC=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=EA=B0=80=EC=A7=80=EB=8F=84=EB=A1=9D=20=EB=B6=84=EB=A6=AC=20?= =?UTF-8?q?=EB=B0=8F=20=ED=98=B8=EC=B6=9C=EA=B5=AC=EB=AC=B8=20=EC=B5=9C?= =?UTF-8?q?=EC=8B=A0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/admin/league/page.tsx | 2 +- src/app/admin/register/[leagueId]/page.tsx | 2 +- src/app/admin/register/page.tsx | 4 +- .../admin/league/LeagueList/index.tsx | 4 +- .../admin/register/League/edit/index.tsx | 8 +-- .../admin/register/League/index.tsx | 8 +-- src/components/admin/register/Team/index.tsx | 2 +- .../league/useDeleteLeagueMutation/index.ts | 19 ++++++ .../{ => league}/useLeagueList/Fetcher.tsx | 2 +- .../admin/league/useLeagueList/query.ts | 16 +++++ .../useLeagueRegister/Fetcher.tsx | 6 +- .../admin/league/useLeagueRegister/query.ts | 42 +++++++++++++ .../league/usePostNewLeagueMutation/index.ts | 26 ++++++++ .../league/usePutLeagueMutation/index.ts | 22 +++++++ .../admin/team/usePostTeamMutation/index.ts | 19 ++++++ .../{ => team}/useTeamRegister/Fetcher.tsx | 2 +- .../admin/team/useTeamRegister/query.ts | 16 +++++ src/queries/admin/useLeagueList/query.ts | 40 ------------ src/queries/admin/useLeagueRegister/query.ts | 63 ------------------- src/queries/admin/useTeamRegister/query.ts | 40 ------------ 20 files changed, 178 insertions(+), 165 deletions(-) create mode 100644 src/queries/admin/league/useDeleteLeagueMutation/index.ts rename src/queries/admin/{ => league}/useLeagueList/Fetcher.tsx (90%) create mode 100644 src/queries/admin/league/useLeagueList/query.ts rename src/queries/admin/{ => league}/useLeagueRegister/Fetcher.tsx (75%) create mode 100644 src/queries/admin/league/useLeagueRegister/query.ts create mode 100644 src/queries/admin/league/usePostNewLeagueMutation/index.ts create mode 100644 src/queries/admin/league/usePutLeagueMutation/index.ts create mode 100644 src/queries/admin/team/usePostTeamMutation/index.ts rename src/queries/admin/{ => team}/useTeamRegister/Fetcher.tsx (91%) create mode 100644 src/queries/admin/team/useTeamRegister/query.ts delete mode 100644 src/queries/admin/useLeagueList/query.ts delete mode 100644 src/queries/admin/useLeagueRegister/query.ts delete mode 100644 src/queries/admin/useTeamRegister/query.ts diff --git a/src/app/admin/league/page.tsx b/src/app/admin/league/page.tsx index 01ca8cf..f997cf9 100644 --- a/src/app/admin/league/page.tsx +++ b/src/app/admin/league/page.tsx @@ -7,7 +7,7 @@ import { Suspense } from 'react'; import Button from '@/components/common/Button'; const LeagueListFetcher = dynamic( - () => import('@/queries/admin/useLeagueList/Fetcher'), + () => import('@/queries/admin/league/useLeagueList/Fetcher'), { ssr: false }, ); const LeagueList = dynamic( diff --git a/src/app/admin/register/[leagueId]/page.tsx b/src/app/admin/register/[leagueId]/page.tsx index daa3a9a..38ccc08 100644 --- a/src/app/admin/register/[leagueId]/page.tsx +++ b/src/app/admin/register/[leagueId]/page.tsx @@ -3,7 +3,7 @@ import { Suspense } from 'react'; import EditLeague from '@/components/admin/register/League/edit'; -import LeagueRegisterFetcher from '@/queries/admin/useLeagueRegister/Fetcher'; +import LeagueRegisterFetcher from '@/queries/admin/league/useLeagueRegister/Fetcher'; import useSportsListByLeagueId from '@/queries/useSportsListByLeagueId/query'; export default function Edit({ params }: { params: { leagueId: string } }) { diff --git a/src/app/admin/register/page.tsx b/src/app/admin/register/page.tsx index c8b9a2c..e28c303 100644 --- a/src/app/admin/register/page.tsx +++ b/src/app/admin/register/page.tsx @@ -6,8 +6,8 @@ import RegisterWrapper from '@/components/admin/register/context/RegisterWrapper import RegisterLeague from '@/components/admin/register/League/'; import RegisterTeam from '@/components/admin/register/Team'; import { useFunnel } from '@/hooks/useFunnel'; -import LeagueRegisterFetcher from '@/queries/admin/useLeagueRegister/Fetcher'; -import TeamRegisterFetcher from '@/queries/admin/useTeamRegister/Fetcher'; +import LeagueRegisterFetcher from '@/queries/admin/league/useLeagueRegister/Fetcher'; +import TeamRegisterFetcher from '@/queries/admin/team/useTeamRegister/Fetcher'; export default function Register() { const [Funnel, setStep] = useFunnel(['league', 'team', 'player'], 'league'); diff --git a/src/components/admin/league/LeagueList/index.tsx b/src/components/admin/league/LeagueList/index.tsx index 824f997..078f2cd 100644 --- a/src/components/admin/league/LeagueList/index.tsx +++ b/src/components/admin/league/LeagueList/index.tsx @@ -6,9 +6,9 @@ import { useEffect, useState } from 'react'; import Button from '@/components/common/Button'; import Card from '@/components/common/Card'; import LeagueContent from '@/components/common/Card/league/Content'; -import { DELETE_DESCRIPTION } from '@/constants/adminDescription'; +import { DELETE_DESCRIPTION } from '@/constants/admin/description'; import { useScrollLock } from '@/hooks/useScrollLock'; -import { useDeleteLeagueMutation } from '@/queries/admin/useLeagueList/query'; +import useDeleteLeagueMutation from '@/queries/admin/league/useDeleteLeagueMutation'; import { LeagueType } from '@/types/admin/league'; export default function LeagueList({ data }: { data: LeagueType[] }) { diff --git a/src/components/admin/register/League/edit/index.tsx b/src/components/admin/register/League/edit/index.tsx index e1dffcf..0fecb97 100644 --- a/src/components/admin/register/League/edit/index.tsx +++ b/src/components/admin/register/League/edit/index.tsx @@ -7,10 +7,8 @@ import Button from '@/components/common/Button'; import CheckboxItem from '@/components/common/Checkbox/Item'; import Input from '@/components/common/Input/Input'; import useValidate from '@/hooks/useValidate'; -import { - usePostLeagueMutation, - usePutLeagueMutation, -} from '@/queries/admin/useLeagueRegister/query'; +import usePostNewLeagueMutation from '@/queries/admin/league/usePostNewLeagueMutation'; +import usePutLeagueMutation from '@/queries/admin/league/usePutLeagueMutation'; import { LeagueDataType, LeagueRegisterDataType, @@ -39,7 +37,7 @@ export default function EditLeague({ const router = useRouter(); - const { mutate: postLeague } = usePostLeagueMutation(); + const { mutate: postLeague } = usePostNewLeagueMutation(); const { mutate: putLeague } = usePutLeagueMutation(); useEffect(() => { diff --git a/src/components/admin/register/League/index.tsx b/src/components/admin/register/League/index.tsx index db9182e..1688011 100644 --- a/src/components/admin/register/League/index.tsx +++ b/src/components/admin/register/League/index.tsx @@ -7,10 +7,8 @@ import Button from '@/components/common/Button'; import CheckboxItem from '@/components/common/Checkbox/Item'; import Input from '@/components/common/Input/Input'; import useValidate from '@/hooks/useValidate'; -import { - usePostLeagueMutation, - usePutLeagueMutation, -} from '@/queries/admin/useLeagueRegister/query'; +import usePostNewLeagueMutation from '@/queries/admin/league/usePostNewLeagueMutation'; +import usePutLeagueMutation from '@/queries/admin/league/usePutLeagueMutation'; import { LeagueDataType, LeagueRegisterDataType } from '@/types/admin/league'; import { updateSet } from '@/utils/set'; import { parseTimeString } from '@/utils/time'; @@ -34,7 +32,7 @@ export default function RegisterLeague({ const router = useRouter(); - const { mutate: postLeague } = usePostLeagueMutation(); + const { mutate: postLeague } = usePostNewLeagueMutation(); const { mutate: putLeague } = usePutLeagueMutation(); useEffect(() => { diff --git a/src/components/admin/register/Team/index.tsx b/src/components/admin/register/Team/index.tsx index 9573cf3..dc0bc6c 100644 --- a/src/components/admin/register/Team/index.tsx +++ b/src/components/admin/register/Team/index.tsx @@ -8,7 +8,7 @@ import { Icon } from '@/components/common/Icon'; import Input from '@/components/common/Input/Input'; import { useLeagueIdContext } from '@/hooks/useLeagueIdContext'; import useValidate from '@/hooks/useValidate'; -import { usePostTeamMutation } from '@/queries/admin/useTeamRegister/query'; +import usePostTeamMutation from '@/queries/admin/team/usePostTeamMutation'; import { TeamType } from '@/types/admin/team'; export default function RegisterTeam({ diff --git a/src/queries/admin/league/useDeleteLeagueMutation/index.ts b/src/queries/admin/league/useDeleteLeagueMutation/index.ts new file mode 100644 index 0000000..c8fc8e4 --- /dev/null +++ b/src/queries/admin/league/useDeleteLeagueMutation/index.ts @@ -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], + }); + }, + }); +} diff --git a/src/queries/admin/useLeagueList/Fetcher.tsx b/src/queries/admin/league/useLeagueList/Fetcher.tsx similarity index 90% rename from src/queries/admin/useLeagueList/Fetcher.tsx rename to src/queries/admin/league/useLeagueList/Fetcher.tsx index 6972ab2..82431e9 100644 --- a/src/queries/admin/useLeagueList/Fetcher.tsx +++ b/src/queries/admin/league/useLeagueList/Fetcher.tsx @@ -2,7 +2,7 @@ import { ReactNode } from 'react'; import { LeagueType } from '@/types/admin/league'; -import { useLeagueList } from './query'; +import useLeagueList from './query'; type LeagueListFetcherProps = { children: (data: LeagueType[]) => ReactNode; diff --git a/src/queries/admin/league/useLeagueList/query.ts b/src/queries/admin/league/useLeagueList/query.ts new file mode 100644 index 0000000..dd0a29a --- /dev/null +++ b/src/queries/admin/league/useLeagueList/query.ts @@ -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, + }; +} diff --git a/src/queries/admin/useLeagueRegister/Fetcher.tsx b/src/queries/admin/league/useLeagueRegister/Fetcher.tsx similarity index 75% rename from src/queries/admin/useLeagueRegister/Fetcher.tsx rename to src/queries/admin/league/useLeagueRegister/Fetcher.tsx index 5e906a6..8e32a70 100644 --- a/src/queries/admin/useLeagueRegister/Fetcher.tsx +++ b/src/queries/admin/league/useLeagueRegister/Fetcher.tsx @@ -1,9 +1,9 @@ import { ReactNode } from 'react'; -import { useLeagueList } from '@/queries/admin/useLeagueList/query'; +import useLeagueList from '@/queries/admin/league/useLeagueList/query'; import { LeagueRegisterDataType } from '@/types/admin/league'; -import { useSportsList } from './query'; +import useSportsList from './query'; type LeagueRegisterFetcherProps = { children: ({ @@ -16,7 +16,7 @@ export default function LeagueRegisterFetcher({ children, }: LeagueRegisterFetcherProps) { const { data: leagueData, error: leagueDataError } = useLeagueList(); - const { sportsListData, sportsListError } = useSportsList(); + const { data: sportsListData, error: sportsListError } = useSportsList(); if (leagueDataError) throw leagueDataError; if (sportsListError) throw sportsListError; diff --git a/src/queries/admin/league/useLeagueRegister/query.ts b/src/queries/admin/league/useLeagueRegister/query.ts new file mode 100644 index 0000000..9f7c380 --- /dev/null +++ b/src/queries/admin/league/useLeagueRegister/query.ts @@ -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), + }; + }, + }); +} diff --git a/src/queries/admin/league/usePostNewLeagueMutation/index.ts b/src/queries/admin/league/usePostNewLeagueMutation/index.ts new file mode 100644 index 0000000..9f186b9 --- /dev/null +++ b/src/queries/admin/league/usePostNewLeagueMutation/index.ts @@ -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], + }); + }, + }); +} diff --git a/src/queries/admin/league/usePutLeagueMutation/index.ts b/src/queries/admin/league/usePutLeagueMutation/index.ts new file mode 100644 index 0000000..aa4aa07 --- /dev/null +++ b/src/queries/admin/league/usePutLeagueMutation/index.ts @@ -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], + }); + }, + }); +} diff --git a/src/queries/admin/team/usePostTeamMutation/index.ts b/src/queries/admin/team/usePostTeamMutation/index.ts new file mode 100644 index 0000000..df953f1 --- /dev/null +++ b/src/queries/admin/team/usePostTeamMutation/index.ts @@ -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], + }); + }, + }); +} diff --git a/src/queries/admin/useTeamRegister/Fetcher.tsx b/src/queries/admin/team/useTeamRegister/Fetcher.tsx similarity index 91% rename from src/queries/admin/useTeamRegister/Fetcher.tsx rename to src/queries/admin/team/useTeamRegister/Fetcher.tsx index 48f78d8..3ca46c3 100644 --- a/src/queries/admin/useTeamRegister/Fetcher.tsx +++ b/src/queries/admin/team/useTeamRegister/Fetcher.tsx @@ -3,7 +3,7 @@ import { ReactNode } from 'react'; import { useLeagueIdContext } from '@/hooks/useLeagueIdContext'; import { TeamType } from '@/types/admin/team'; -import { useTeamListByLeagueId } from './query'; +import useTeamListByLeagueId from './query'; type TeamRegisterFetcherProps = { children: (data: TeamType[] | string | undefined) => ReactNode; diff --git a/src/queries/admin/team/useTeamRegister/query.ts b/src/queries/admin/team/useTeamRegister/query.ts new file mode 100644 index 0000000..e0756d8 --- /dev/null +++ b/src/queries/admin/team/useTeamRegister/query.ts @@ -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, + }; +} diff --git a/src/queries/admin/useLeagueList/query.ts b/src/queries/admin/useLeagueList/query.ts deleted file mode 100644 index 5403ccc..0000000 --- a/src/queries/admin/useLeagueList/query.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { - useMutation, - useQueryClient, - useSuspenseQuery, -} from '@tanstack/react-query'; - -import { - deleteLeagueByIdWithAuth, - getAllLeaguesWithAuth, -} from '@/api/admin/league'; - -export const QUERY_KEY = { - LEAGUE_LIST: 'league-list', -}; - -export function useLeagueList() { - const { data, error } = useSuspenseQuery({ - queryKey: [QUERY_KEY.LEAGUE_LIST], - queryFn: () => getAllLeaguesWithAuth(), - }); - - return { - data, - error, - }; -} - -export function useDeleteLeagueMutation() { - const queryClient = useQueryClient(); - - return useMutation({ - mutationKey: ['delete-league'], - mutationFn: deleteLeagueByIdWithAuth, - onSuccess: () => { - queryClient.invalidateQueries({ - queryKey: [QUERY_KEY.LEAGUE_LIST], - }); - }, - }); -} diff --git a/src/queries/admin/useLeagueRegister/query.ts b/src/queries/admin/useLeagueRegister/query.ts deleted file mode 100644 index ef52f0e..0000000 --- a/src/queries/admin/useLeagueRegister/query.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { - useMutation, - useQueryClient, - useSuspenseQuery, -} from '@tanstack/react-query'; - -import { - getSportsCategoriesWithAuth, - postNewLeagueWithAuth, - putLeagueWithAuth, -} from '@/api/admin/league'; -import { useLeagueIdContext } from '@/hooks/useLeagueIdContext'; - -export const QUERY_KEY = { - LEAGUE_LIST: 'league-list', - LEAGUE_SPORTS: 'league-sports', - SPORTS_LIST: 'sports-list', -}; - -export function useSportsList() { - const { data: sportsListData, error: sportsListError } = useSuspenseQuery({ - queryKey: [QUERY_KEY.SPORTS_LIST], - queryFn: () => getSportsCategoriesWithAuth(), - }); - - return { - sportsListData, - sportsListError, - }; -} - -export function usePostLeagueMutation() { - const queryClient = useQueryClient(); - const { setLeagueId } = useLeagueIdContext(); - - return useMutation({ - mutationKey: ['post-new-league'], - mutationFn: postNewLeagueWithAuth, - onSuccess: data => { - const { leagueId } = data; - setLeagueId(leagueId.toString()); - queryClient.invalidateQueries({ queryKey: [QUERY_KEY.LEAGUE_LIST] }); - queryClient.invalidateQueries({ - queryKey: [QUERY_KEY.LEAGUE_SPORTS, leagueId], - }); - }, - }); -} - -export function usePutLeagueMutation() { - const queryClient = useQueryClient(); - - return useMutation({ - mutationKey: ['put-league'], - mutationFn: putLeagueWithAuth, - onSuccess: leagueId => { - queryClient.invalidateQueries({ queryKey: [QUERY_KEY.LEAGUE_LIST] }); - queryClient.invalidateQueries({ - queryKey: [QUERY_KEY.LEAGUE_SPORTS, leagueId], - }); - }, - }); -} diff --git a/src/queries/admin/useTeamRegister/query.ts b/src/queries/admin/useTeamRegister/query.ts deleted file mode 100644 index 11e8f9c..0000000 --- a/src/queries/admin/useTeamRegister/query.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { - useMutation, - useQueryClient, - useSuspenseQuery, -} from '@tanstack/react-query'; - -import { - getTeamListByLeagueIdWithAuth, - postTeamByLeagueIdWithAuth, -} from '@/api/admin/team'; - -const QUERY_KEY = { - TEAM_LIST: 'team-list', -}; - -export function useTeamListByLeagueId(leagueId: string) { - const { data, error } = useSuspenseQuery({ - queryKey: [QUERY_KEY.TEAM_LIST, leagueId], - queryFn: () => getTeamListByLeagueIdWithAuth(leagueId), - }); - - return { - teamList: data, - error, - }; -} - -export function usePostTeamMutation(leagueId: string) { - const queryClient = useQueryClient(); - - return useMutation({ - mutationKey: ['post-team'], - mutationFn: postTeamByLeagueIdWithAuth, - onSuccess: () => { - queryClient.invalidateQueries({ - queryKey: [QUERY_KEY.TEAM_LIST, leagueId], - }); - }, - }); -} From b3894922b09186f033f5db9ff9a5d6ec9f20c531 Mon Sep 17 00:00:00 2001 From: HiImConan Date: Thu, 30 Nov 2023 17:13:45 +0900 Subject: [PATCH 3/5] =?UTF-8?q?style:=20=ED=97=A4=EB=8D=94,=ED=91=B8?= =?UTF-8?q?=ED=84=B0=20=ED=8C=A8=EB=94=A9=20=EB=B6=80=EC=97=AC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=9C=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=82=B4=20?= =?UTF-8?q?py-8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/admin/league/page.tsx | 2 +- src/app/admin/register/[leagueId]/page.tsx | 2 +- src/app/admin/register/page.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/admin/league/page.tsx b/src/app/admin/league/page.tsx index f997cf9..3ba2d47 100644 --- a/src/app/admin/league/page.tsx +++ b/src/app/admin/league/page.tsx @@ -16,7 +16,7 @@ const LeagueList = dynamic( export default function LeaguePage() { return ( -
+
전체 리그
리그 로딩중...
}> diff --git a/src/app/admin/register/[leagueId]/page.tsx b/src/app/admin/register/[leagueId]/page.tsx index 38ccc08..9b48968 100644 --- a/src/app/admin/register/[leagueId]/page.tsx +++ b/src/app/admin/register/[leagueId]/page.tsx @@ -10,7 +10,7 @@ export default function Edit({ params }: { params: { leagueId: string } }) { const { leagueId } = params; const { sportsList: leagueSportsData } = useSportsListByLeagueId(leagueId); return ( -
+
리그 정보 로딩중...
}> {data => ( diff --git a/src/app/admin/register/page.tsx b/src/app/admin/register/page.tsx index e28c303..b816a2c 100644 --- a/src/app/admin/register/page.tsx +++ b/src/app/admin/register/page.tsx @@ -13,7 +13,7 @@ export default function Register() { const [Funnel, setStep] = useFunnel(['league', 'team', 'player'], 'league'); return ( - + 리그 정보 로딩중...
}> From c241900c8d6ac0ac6a7f7529c0e0dd87198dd348 Mon Sep 17 00:00:00 2001 From: HiImConan Date: Thu, 30 Nov 2023 17:17:17 +0900 Subject: [PATCH 4/5] =?UTF-8?q?style:=20=EC=8A=A4=ED=81=AC=EB=A1=A4?= =?UTF-8?q?=EB=9D=BD=20=EC=82=AC=EC=9A=A9=EC=8B=9C=20main=20=EC=BB=B4?= =?UTF-8?q?=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EC=9D=B4=EB=8F=99=ED=95=98?= =?UTF-8?q?=EB=8D=98=20=EB=B2=84=EA=B7=B8=20-=20position:=20fixed=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=EB=A1=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useScrollLock.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hooks/useScrollLock.ts b/src/hooks/useScrollLock.ts index 222e92c..980c217 100644 --- a/src/hooks/useScrollLock.ts +++ b/src/hooks/useScrollLock.ts @@ -3,7 +3,6 @@ export function useScrollLock() { const disableScroll = () => { document.body.style.overflow = 'hidden'; - document.body.style.position = 'fixed'; document.body.style.top = `-${scrollPosition}px`; document.body.style.width = '100%'; }; From a3aa68f33db34e49b7853fb4f61503ff2969a801 Mon Sep 17 00:00:00 2001 From: HiImConan Date: Thu, 30 Nov 2023 18:05:31 +0900 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=EB=A7=A8=EB=A7=88=EC=A7=80=EB=A7=89?= =?UTF-8?q?=20=EB=A6=AC=EA=B7=B8=20=EC=82=AD=EC=A0=9C=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=ED=94=BD=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/admin/league/LeagueList/index.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/admin/league/LeagueList/index.tsx b/src/components/admin/league/LeagueList/index.tsx index 078f2cd..1032883 100644 --- a/src/components/admin/league/LeagueList/index.tsx +++ b/src/components/admin/league/LeagueList/index.tsx @@ -13,13 +13,16 @@ import { LeagueType } from '@/types/admin/league'; export default function LeagueList({ data }: { data: LeagueType[] }) { const [isModalOpen, setIsModalOpen] = useState(false); + const [selectedLeagueId, setSelectedLeagueId] = useState(null); const { disableScroll, enableScroll } = useScrollLock(); const { mutate } = useDeleteLeagueMutation(); - const toggleModal = () => { + const toggleModal = (leagueId: number) => { setIsModalOpen(!isModalOpen); + setSelectedLeagueId(leagueId); }; + const deleteLeague = async (leagueId: number) => { mutate({ leagueId }); setIsModalOpen(false); @@ -51,25 +54,26 @@ export default function LeagueList({ data }: { data: LeagueType[] }) {
- {isModalOpen && ( + {isModalOpen && selectedLeagueId === league.leagueId && (
리그 삭제 + {league.name} {DELETE_DESCRIPTION}