Skip to content

Commit

Permalink
feat: /challenges/attendance post API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
iOdiO89 committed Jul 1, 2024
1 parent 188db7b commit 6a7587c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apis/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export interface Program {
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;
Expand Down
11 changes: 11 additions & 0 deletions apis/hooks/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6a7587c

Please sign in to comment.