Skip to content

Commit

Permalink
Merge pull request #100 from hufs-sports-live/feat/admin-league
Browse files Browse the repository at this point in the history
[FEAT]: `/admin/league` 라우트 구현
  • Loading branch information
HiimKwak authored Nov 28, 2023
2 parents ff07153 + a6b1c15 commit 9af126b
Show file tree
Hide file tree
Showing 33 changed files with 1,202 additions and 179 deletions.
3 changes: 2 additions & 1 deletion .commitlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"style",
"chore"
]
]
],
"subject-case": [0]
}
}
48 changes: 48 additions & 0 deletions src/api/admin/league.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { adminInstance } from '@/api';
import {
DeleteLeaguePayload,
LeagueIdType,
LeagueType,
NewLeaguePayload,
PutLeaguePayload,
SportsCategoriesType,
SportsQuarterType,
} from '@/types/admin/league';

export const getAllLeaguesWithAuth = async () => {
const { data } = await adminInstance.get<LeagueType[]>('/league/all/');

return data;
};

export const postNewLeagueWithAuth = async (body: NewLeaguePayload) => {
const { data } = await adminInstance.post<LeagueIdType>('/league/', body);

return data;
};

export const deleteLeagueByIdWithAuth = async (body: DeleteLeaguePayload) => {
const { status } = await adminInstance.delete('/league/', { data: body });

return status;
};

export const putLeagueWithAuth = async (data: PutLeaguePayload) => {
await adminInstance.put('/league/', data);

return data.leagueId;
};

export const getSportsCategoriesWithAuth = async () => {
const { data } = await adminInstance.get<SportsCategoriesType[]>('/sport/');

return data;
};

export const getSportsQuarterByIdWithAuth = async (sportId: string) => {
const { data } = await adminInstance.get<SportsQuarterType[]>(
`/sport/${sportId}/quarter/`,
);

return data;
};
46 changes: 46 additions & 0 deletions src/api/admin/team.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { isAxiosError } from 'axios';

import { adminInstance } from '@/api';
import { TeamErrorType, TeamType } from '@/types/admin/team';

/* 리그 내 팀 관리 API */

export const getTeamListByLeagueIdWithAuth = async (leagueId: string) => {
try {
const { data } = await adminInstance.get<TeamType[]>(`/team/${leagueId}/`);

return data;
} catch (error) {
if (isAxiosError<TeamErrorType>(error)) {
return error.response?.data.detail;
} else {
throw new Error('리그 내 팀을 조회하는데 실패했습니다.');
}
}
};

export const postTeamByLeagueIdWithAuth = async (payload: {
leagueId: string;
body: FormData;
}) => {
await adminInstance.post(
`/team/register/${payload.leagueId}/`,
payload.body,
{
headers: {
'Content-Type': 'multipart/form-data',
},
},
);
};

export const putTeamByIdWithAuth = async (payload: {
teamId: string;
body: FormData;
}) => {
await adminInstance.put(`/team/${payload.teamId}/change/`, payload.body, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
};
26 changes: 26 additions & 0 deletions src/app/admin/league/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';

import Link from 'next/link';
import { Suspense } from 'react';

import LeagueList from '@/components/admin/league/LeagueList';
import Button from '@/components/common/Button';
import LeagueListFetcher from '@/queries/admin/useLeagueList/Fetcher';

export default function LeaguePage() {
return (
<div className="space-y-8 py-8">
<div className="text-2xl font-medium">전체 리그</div>
<Suspense fallback={<div>리그 로딩중...</div>}>
<LeagueListFetcher>
{data => <LeagueList data={data} />}
</LeagueListFetcher>
</Suspense>
<Button className="w-full rounded-lg bg-primary p-3 text-white hover:bg-[#303ECE]">
<Link href="/admin/register" className="w-full">
새 리그 등록
</Link>
</Button>
</div>
);
}
126 changes: 0 additions & 126 deletions src/app/admin/page.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions src/app/admin/register/[leagueId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client';

import { Suspense } from 'react';

import RegisterLeague from '@/components/admin/register/League';
import LeagueRegisterFetcher from '@/queries/admin/useLeagueRegister/Fetcher';
import useSportsListByLeagueId from '@/queries/useSportsListByLeagueId/query';

export default function EditLeague({
params,
}: {
params: { leagueId: string };
}) {
const { leagueId } = params;
const { sportsList: leagueSportsData } = useSportsListByLeagueId(leagueId);
return (
<div className="space-y-8 py-8">
<Suspense fallback={<div>리그 정보 로딩중...</div>}>
<LeagueRegisterFetcher>
{data => (
<RegisterLeague
data={{ ...data, leagueSportsData }}
leagueId={Number(leagueId)}
/>
)}
</LeagueRegisterFetcher>
</Suspense>
</div>
);
}
44 changes: 44 additions & 0 deletions src/app/admin/register/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use client';

import { Suspense } from 'react';

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';

export default function Register() {
const [Funnel, setStep] = useFunnel(['league', 'team', 'player'], 'league');

return (
<RegisterWrapper className="space-y-8 py-8">
<Funnel>
<Funnel.Step name="league">
<Suspense fallback={<div>리그 정보 로딩중...</div>}>
<LeagueRegisterFetcher>
{data => (
<RegisterLeague data={data} onNext={() => setStep('team')} />
)}
</LeagueRegisterFetcher>
</Suspense>
</Funnel.Step>
<Funnel.Step name="team">
<Suspense fallback={<div>팀 정보 로딩중...</div>}>
<TeamRegisterFetcher>
{data => <RegisterTeam data={data} />}
</TeamRegisterFetcher>
</Suspense>
</Funnel.Step>
<Funnel.Step name="player">
<Suspense fallback={<div>선수 정보 로딩중...</div>}>
{/* <LeagueRegisterFetcher leagueId={leagueId}>
{data => <RegisterLeague data={data} leagueId={leagueId} />}
</LeagueRegisterFetcher> */}
</Suspense>
</Funnel.Step>
</Funnel>
</RegisterWrapper>
);
}
Loading

0 comments on commit 9af126b

Please sign in to comment.