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)