import { useRef, useState } from "react"; import { focusFirstInvalidControl } from "@/shared/lib/focus-first-invalid-control"; export function FanTalkReplyForm({ content, errorMessage, isSaving, isSubmitDisabled = false, onChange, onSubmit, submitLabel = "답변 등록" }: { readonly content: string; readonly errorMessage: string | null; readonly isSaving: boolean; readonly isSubmitDisabled?: boolean; readonly onChange: (content: string) => void; readonly onSubmit: () => void; readonly submitLabel?: string }) { const errorId = "fan-talk-reply-error"; const formRef = useRef(null); const [contentErrorMessage, setContentErrorMessage] = useState(null); const visibleErrorMessage = contentErrorMessage ?? errorMessage; function submit() { if (content.trim().length === 0) { setContentErrorMessage("답변 내용을 입력해 주세요."); queueMicrotask(() => focusFirstInvalidControl(formRef.current)); return; } setContentErrorMessage(null); onSubmit(); } return (
{ event.preventDefault(); submit(); }} ref={formRef} >