전체 코드, 구조 검토 - P1-6 코드 수정 진행
This commit is contained in:
@@ -108,19 +108,16 @@ function ExtensionRequestActions({
|
||||
const router = useRouter();
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
const [emailWarning, setEmailWarning] = useState(false);
|
||||
const isRequested = request.status === REQUEST_STATUSES.REQUESTED;
|
||||
|
||||
if (!isRequested) {
|
||||
if (!isRequested && !emailWarning) {
|
||||
return <span className="text-xs text-muted-foreground">처리 완료</span>;
|
||||
}
|
||||
|
||||
async function submitAction(action: "approve" | "cancel") {
|
||||
const actionLabel = action === "approve" ? "승인" : "취소";
|
||||
const confirmed = window.confirm(
|
||||
`${request.maestroName} 연장 신청을 ${actionLabel}하시겠습니까?`
|
||||
);
|
||||
|
||||
if (!confirmed) {
|
||||
if (!window.confirm(`${request.maestroName} 연장 신청을 ${actionLabel}하시겠습니까?`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,14 +133,19 @@ function ExtensionRequestActions({
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const body = (await response.json().catch(() => null)) as {
|
||||
message?: string;
|
||||
} | null;
|
||||
const body = (await response.json().catch(() => null)) as {
|
||||
message?: string;
|
||||
emailSent?: boolean;
|
||||
} | null;
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(body?.message ?? "연장 신청 처리에 실패했습니다.");
|
||||
}
|
||||
|
||||
if (action === "approve" && body?.emailSent === false) {
|
||||
setEmailWarning(true);
|
||||
}
|
||||
|
||||
startTransition(() => {
|
||||
router.refresh();
|
||||
});
|
||||
@@ -158,27 +160,36 @@ function ExtensionRequestActions({
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
disabled={isPending}
|
||||
onClick={() => void submitAction("approve")}
|
||||
size="sm"
|
||||
type="button"
|
||||
>
|
||||
<Check className="size-4" aria-hidden="true" />
|
||||
승인
|
||||
</Button>
|
||||
<Button
|
||||
disabled={isPending}
|
||||
onClick={() => void submitAction("cancel")}
|
||||
size="sm"
|
||||
type="button"
|
||||
variant="outline"
|
||||
>
|
||||
<X className="size-4" aria-hidden="true" />
|
||||
취소
|
||||
</Button>
|
||||
</div>
|
||||
{isRequested ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
disabled={isPending}
|
||||
onClick={() => void submitAction("approve")}
|
||||
size="sm"
|
||||
type="button"
|
||||
>
|
||||
<Check className="size-4" aria-hidden="true" />
|
||||
승인
|
||||
</Button>
|
||||
<Button
|
||||
disabled={isPending}
|
||||
onClick={() => void submitAction("cancel")}
|
||||
size="sm"
|
||||
type="button"
|
||||
variant="outline"
|
||||
>
|
||||
<X className="size-4" aria-hidden="true" />
|
||||
취소
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground">처리 완료</span>
|
||||
)}
|
||||
{emailWarning ? (
|
||||
<p className="max-w-56 text-xs text-amber-600 dark:text-amber-400">
|
||||
이메일 발송 실패 — 수동 확인 필요
|
||||
</p>
|
||||
) : null}
|
||||
{errorMessage ? (
|
||||
<p className="max-w-56 text-xs text-destructive">{errorMessage}</p>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user