diff --git a/apis/admin.ts b/apis/admin.ts index 7da91b8..73a36b5 100644 --- a/apis/admin.ts +++ b/apis/admin.ts @@ -11,6 +11,12 @@ export interface Program { schedule: string; description: string; } + +async function postAttendanceCode(challengeIdx: number): Promise { + const { data } = await client.post(`/challenges/attendance/${challengeIdx}`); + return data; +} + async function postProgram(body: Program): Promise { const { data } = await client.post(`/programs`, body); return data; diff --git a/apis/hooks/admin.ts b/apis/hooks/admin.ts index 2f040c7..6e9d0af 100644 --- a/apis/hooks/admin.ts +++ b/apis/hooks/admin.ts @@ -2,6 +2,17 @@ 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();