"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Loader2 } from "lucide-react"; interface YardLayoutCreateModalProps { isOpen: boolean; onClose: () => void; onCreate: (name: string, description: string) => Promise; } export default function YardLayoutCreateModal({ isOpen, onClose, onCreate }: YardLayoutCreateModalProps) { const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [isCreating, setIsCreating] = useState(false); const [error, setError] = useState(""); // 생성 실행 const handleCreate = async () => { if (!name.trim()) { setError("야드 이름을 입력하세요"); return; } setIsCreating(true); setError(""); try { await onCreate(name.trim(), description.trim()); setName(""); setDescription(""); } catch (error: any) { console.error("야드 생성 실패:", error); setError(error.message || "야드 생성에 실패했습니다"); } finally { setIsCreating(false); } }; // 모달 닫기 const handleClose = () => { if (isCreating) return; setName(""); setDescription(""); setError(""); onClose(); }; // Enter 키 처리 const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleCreate(); } }; return ( 새 야드 생성 야드의 이름과 설명을 입력하세요
{/* 야드 이름 */}
{ setName(e.target.value); setError(""); }} onKeyDown={handleKeyDown} placeholder="예: A구역, 1번 야드" disabled={isCreating} autoFocus />
{/* 설명 */}