From 6a7587c599d5b55a282722933ba6a5c42403b025 Mon Sep 17 00:00:00 2001 From: iOdiO89 <117376841+iOdiO89@users.noreply.github.com> Date: Tue, 2 Jul 2024 01:24:00 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20/challenges/attendance=20post=20API=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/admin.ts | 6 ++++++ apis/hooks/admin.ts | 11 +++++++++++ 2 files changed, 17 insertions(+) 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();