마에스트로 상세화면에 암호 초기화 버튼 추가 (암호 초기화: 123456)
This commit is contained in:
@@ -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<HTMLFormElement>) {
|
||||
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 (
|
||||
<form onSubmit={(e) => void handleSubmit(e)} className="mt-4 space-y-5">
|
||||
<div className="grid gap-x-8 gap-y-4 text-sm md:grid-cols-2 xl:grid-cols-3">
|
||||
@@ -216,6 +253,16 @@ export function MaestroEditForm({ maestro, playerCount }: MaestroEditFormProps)
|
||||
<Save aria-hidden="true" className="size-4" />
|
||||
저장
|
||||
</Button>
|
||||
<Button
|
||||
disabled={isDisabled}
|
||||
onClick={() => void handleResetPassword()}
|
||||
size="sm"
|
||||
type="button"
|
||||
variant="outline"
|
||||
>
|
||||
<KeyRound aria-hidden="true" className="size-4" />
|
||||
암호 초기화
|
||||
</Button>
|
||||
{successMessage ? (
|
||||
<p className="text-sm text-green-700 dark:text-green-400">
|
||||
{successMessage}
|
||||
|
||||
Reference in New Issue
Block a user