-
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 #32 from team-Ollie/14-feature-Admin-API
feat: 관리자용 api 연결
- Loading branch information
Showing
32 changed files
with
361 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { CalendarDate } from "./calendar"; | ||
import client, { ResponseBody } from "./client"; | ||
|
||
export interface Program { | ||
name: string; | ||
dueDate: CalendarDate; | ||
openDate: CalendarDate; | ||
location: string; | ||
category: string; | ||
host: string; | ||
schedule: string; | ||
description: string; | ||
} | ||
|
||
async function postAttendanceCode(challengeIdx: number): Promise<ResponseBody> { | ||
const { data } = await client.post(`/challenges/attendance/${challengeIdx}`); | ||
return data; | ||
} | ||
|
||
async function postProgram(body: Program): Promise<ResponseBody> { | ||
const { data } = await client.post(`/programs`, body); | ||
return data; | ||
} | ||
|
||
export { postAttendanceCode, postProgram }; |
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,36 @@ | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { Program, postAttendanceCode, postProgram } from "../admin"; | ||
import { useRouter } from "next/router"; | ||
|
||
function usePostAttendanceCode(challengeIdx: number) { | ||
const { mutate } = useMutation({ | ||
mutationKey: ["postAttendanceCode", challengeIdx], | ||
mutationFn: () => postAttendanceCode(challengeIdx), | ||
onSuccess: (data) => window.alert(`인증번호: ${data}`), | ||
onError: () => window.alert("에러 발생. 앱 관리자에게 문의해주세요."), | ||
}); | ||
|
||
return { mutate }; | ||
} | ||
|
||
function usePostProgram() { | ||
const router = useRouter(); | ||
const queryclient = useQueryClient(); | ||
|
||
const { mutate } = useMutation({ | ||
mutationKey: ["postProgram"], | ||
mutationFn: (body: Program) => postProgram(body), | ||
onSuccess: () => { | ||
queryclient.invalidateQueries({ | ||
queryKey: ["getMyChallengeList"], | ||
}); | ||
window.alert("프로그램이 성공적으로 등록되었습니다."); | ||
router.push("/"); | ||
}, | ||
onError: () => router.push("/404"), | ||
}); | ||
|
||
return { mutate }; | ||
} | ||
|
||
export { usePostAttendanceCode, usePostProgram }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { NextPage } from "next"; | ||
import FlexBox from "../Flexbox"; | ||
import { useRouter } from "next/router"; | ||
import { Challenge as ChallengeType } from "@/apis/challenge"; | ||
import { usePostAttendanceCode } from "@/apis/hooks/admin"; | ||
|
||
interface ChallengeProps { | ||
setIsModalVisible: React.Dispatch<React.SetStateAction<boolean>>; | ||
challengeInfo: ChallengeType; | ||
} | ||
|
||
const AdminChallenge: NextPage<ChallengeProps> = ({ | ||
setIsModalVisible, | ||
challengeInfo, | ||
}) => { | ||
const router = useRouter(); | ||
const { mutate } = usePostAttendanceCode(challengeInfo.challengeIdx); | ||
|
||
const showAttendanceCode = () => mutate(); | ||
|
||
return ( | ||
<FlexBox direction="col" className="p-4 w-full rounded-lg border gap-4"> | ||
<FlexBox direction="col" className="w-full gap-1"> | ||
<FlexBox className="w-full justify-between items-start"> | ||
<div className="h2">{challengeInfo.name}</div> | ||
</FlexBox> | ||
<div className="h4 self-start"> | ||
{challengeInfo.location} | {challengeInfo.schedule} | ||
</div> | ||
</FlexBox> | ||
<FlexBox direction="col" className="w-full gap-2"> | ||
<FlexBox className="gap-1 w-full"> | ||
<div className="h5 text-grey-500">전체달성률</div> | ||
<div className="h3"> | ||
{challengeInfo.totalAttendanceRate}%( | ||
{challengeInfo.participantsNum}명) | ||
</div> | ||
</FlexBox> | ||
<FlexBox className="w-full gap-2"> | ||
<div | ||
className="w-full border border-main-color rounded-lg py-2 text-center text-main-color h3" | ||
onClick={showAttendanceCode} | ||
> | ||
인증번호 보기 | ||
</div> | ||
<div | ||
className="w-full border border-main-color rounded-lg py-2 text-center text-main-color h3" | ||
onClick={() => router.push("/challenge")} | ||
> | ||
현황 보러가기 | ||
</div> | ||
</FlexBox> | ||
</FlexBox> | ||
</FlexBox> | ||
); | ||
}; | ||
|
||
export default AdminChallenge; |
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
Oops, something went wrong.