From ff67e5cf5a4380ee96b578397ea80bce0461ee06 Mon Sep 17 00:00:00 2001 From: jisangs Date: Sun, 5 Jul 2026 13:48:17 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A7=88=EC=97=90=EC=8A=A4=ED=8A=B8=EB=A1=9C?= =?UTF-8?q?=20=EC=83=81=EC=84=B8=ED=99=94=EB=A9=B4=EC=97=90=20=EC=95=94?= =?UTF-8?q?=ED=98=B8=20=EC=B4=88=EA=B8=B0=ED=99=94=20=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(=EC=95=94=ED=98=B8=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94:=20123456)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maestros/[maestroId]/MaestroEditForm.tsx | 51 ++++++++++++++++++- app/api/maestros/[id]/reset-password/route.ts | 33 ++++++++++++ lib/maestros.ts | 25 +++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 app/api/maestros/[id]/reset-password/route.ts diff --git a/app/(admin)/maestros/[maestroId]/MaestroEditForm.tsx b/app/(admin)/maestros/[maestroId]/MaestroEditForm.tsx index df44969..d2a403e 100644 --- a/app/(admin)/maestros/[maestroId]/MaestroEditForm.tsx +++ b/app/(admin)/maestros/[maestroId]/MaestroEditForm.tsx @@ -2,7 +2,7 @@ import { useState, useTransition } from "react"; import { useRouter } from "next/navigation"; -import { Save } from "lucide-react"; +import { KeyRound, Save } from "lucide-react"; import { Button } from "@/components/ui/button"; import { @@ -41,6 +41,7 @@ export function MaestroEditForm({ maestro, playerCount }: MaestroEditFormProps) const router = useRouter(); const [isPending, startTransition] = useTransition(); const [isSaving, setIsSaving] = useState(false); + const [isResettingPassword, setIsResettingPassword] = useState(false); const [name, setName] = useState(maestro.name); const [email, setEmail] = useState(maestro.email); @@ -56,7 +57,7 @@ export function MaestroEditForm({ maestro, playerCount }: MaestroEditFormProps) const [errorMessage, setErrorMessage] = useState(""); const [successMessage, setSuccessMessage] = useState(""); - const isDisabled = isSaving || isPending; + const isDisabled = isSaving || isPending || isResettingPassword; async function handleSubmit(event: React.FormEvent) { event.preventDefault(); @@ -107,6 +108,42 @@ export function MaestroEditForm({ maestro, playerCount }: MaestroEditFormProps) } } + async function handleResetPassword() { + if ( + !window.confirm( + `${maestro.name} 계정의 비밀번호를 123456으로 초기화 하시겠습니까?` + ) + ) + return; + + setIsResettingPassword(true); + setErrorMessage(""); + setSuccessMessage(""); + + try { + const response = await fetch( + `/api/maestros/${maestro.maestroID}/reset-password`, + { method: "POST" } + ); + + const body = (await response.json().catch(() => null)) as { + message?: string; + } | null; + + if (!response.ok) { + throw new Error(body?.message ?? "암호 초기화에 실패했습니다."); + } + + setSuccessMessage("암호 초기화 완료"); + } catch (error) { + setErrorMessage( + error instanceof Error ? error.message : "암호 초기화에 실패했습니다." + ); + } finally { + setIsResettingPassword(false); + } + } + return (
void handleSubmit(e)} className="mt-4 space-y-5">
@@ -216,6 +253,16 @@ export function MaestroEditForm({ maestro, playerCount }: MaestroEditFormProps)