2025-10-17 15:26:21 +09:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
2025-11-05 16:36:32 +09:00
|
|
|
|
|
|
|
|
|
2025-10-17 15:26:21 +09:00
|
|
|
DialogHeader,
|
2025-11-05 16:36:32 +09:00
|
|
|
|
|
|
|
|
} from "@/components/ui/resizable-dialog";
|
2025-10-17 15:26:21 +09:00
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { Label } from "@/components/ui/label";
|
2025-10-17 18:00:27 +09:00
|
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
|
|
|
import { Loader2, AlertCircle } from "lucide-react";
|
2025-10-17 15:26:21 +09:00
|
|
|
|
|
|
|
|
interface YardLayoutCreateModalProps {
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
onClose: () => void;
|
2025-10-17 18:00:27 +09:00
|
|
|
onCreate: (name: string) => Promise<void>;
|
2025-10-17 15:26:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function YardLayoutCreateModal({ isOpen, onClose, onCreate }: YardLayoutCreateModalProps) {
|
|
|
|
|
const [name, setName] = useState("");
|
|
|
|
|
const [isCreating, setIsCreating] = useState(false);
|
|
|
|
|
const [error, setError] = useState("");
|
|
|
|
|
|
|
|
|
|
// 생성 실행
|
|
|
|
|
const handleCreate = async () => {
|
|
|
|
|
if (!name.trim()) {
|
|
|
|
|
setError("야드 이름을 입력하세요");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsCreating(true);
|
|
|
|
|
setError("");
|
|
|
|
|
|
|
|
|
|
try {
|
2025-10-17 18:00:27 +09:00
|
|
|
await onCreate(name.trim());
|
2025-10-17 15:26:21 +09:00
|
|
|
setName("");
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error("야드 생성 실패:", error);
|
|
|
|
|
setError(error.message || "야드 생성에 실패했습니다");
|
|
|
|
|
} finally {
|
|
|
|
|
setIsCreating(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 모달 닫기
|
|
|
|
|
const handleClose = () => {
|
|
|
|
|
if (isCreating) return;
|
|
|
|
|
setName("");
|
|
|
|
|
setError("");
|
|
|
|
|
onClose();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Enter 키 처리
|
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
|
|
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
handleCreate();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2025-11-05 16:36:32 +09:00
|
|
|
<ResizableDialog open={isOpen} onOpenChange={handleClose}>
|
|
|
|
|
<ResizableDialogContent className="sm:max-w-[500px]" onPointerDown={(e) => e.stopPropagation()}>
|
|
|
|
|
<ResizableDialogHeader>
|
|
|
|
|
<ResizableDialogTitle>새 야드 생성</ResizableDialogTitle>
|
|
|
|
|
<ResizableDialogDescription>야드 이름을 입력하세요</ResizableDialogDescription>
|
|
|
|
|
</ResizableDialogHeader>
|
2025-10-17 15:26:21 +09:00
|
|
|
|
|
|
|
|
<div className="space-y-4 py-4">
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<Label htmlFor="yard-name">
|
2025-10-29 17:53:03 +09:00
|
|
|
야드 이름 <span className="text-destructive">*</span>
|
2025-10-17 15:26:21 +09:00
|
|
|
</Label>
|
|
|
|
|
<Input
|
|
|
|
|
id="yard-name"
|
|
|
|
|
value={name}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setName(e.target.value);
|
|
|
|
|
setError("");
|
|
|
|
|
}}
|
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
|
placeholder="예: A구역, 1번 야드"
|
|
|
|
|
disabled={isCreating}
|
|
|
|
|
autoFocus
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-10-17 18:00:27 +09:00
|
|
|
{error && (
|
|
|
|
|
<Alert variant="destructive">
|
|
|
|
|
<AlertCircle className="h-4 w-4" />
|
|
|
|
|
<AlertDescription>{error}</AlertDescription>
|
|
|
|
|
</Alert>
|
|
|
|
|
)}
|
2025-10-17 15:26:21 +09:00
|
|
|
</div>
|
|
|
|
|
|
2025-11-05 16:36:32 +09:00
|
|
|
<ResizableDialogFooter>
|
2025-10-17 15:26:21 +09:00
|
|
|
<Button variant="outline" onClick={handleClose} disabled={isCreating}>
|
|
|
|
|
취소
|
|
|
|
|
</Button>
|
|
|
|
|
<Button onClick={handleCreate} disabled={!name.trim() || isCreating}>
|
|
|
|
|
{isCreating ? (
|
|
|
|
|
<>
|
|
|
|
|
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
|
|
|
생성 중...
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
"생성"
|
|
|
|
|
)}
|
|
|
|
|
</Button>
|
2025-11-05 16:36:32 +09:00
|
|
|
</ResizableDialogFooter>
|
|
|
|
|
</ResizableDialogContent>
|
|
|
|
|
</ResizableDialog>
|
2025-10-17 15:26:21 +09:00
|
|
|
);
|
|
|
|
|
}
|