"use client"; import React, { useState } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Badge } from "@/components/ui/badge"; import { Checkbox } from "@/components/ui/checkbox"; import { TableCategoryValue } from "@/types/tableCategoryValue"; // 기본 색상 팔레트 const DEFAULT_COLORS = [ "#ef4444", // red "#f97316", // orange "#f59e0b", // amber "#eab308", // yellow "#84cc16", // lime "#22c55e", // green "#10b981", // emerald "#14b8a6", // teal "#06b6d4", // cyan "#0ea5e9", // sky "#3b82f6", // blue "#6366f1", // indigo "#8b5cf6", // violet "#a855f7", // purple "#d946ef", // fuchsia "#ec4899", // pink "#64748b", // slate "#6b7280", // gray ]; interface CategoryValueAddDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onAdd: (value: TableCategoryValue) => void; columnLabel: string; } export const CategoryValueAddDialog: React.FC< CategoryValueAddDialogProps > = ({ open, onOpenChange, onAdd, columnLabel }) => { const [valueLabel, setValueLabel] = useState(""); const [description, setDescription] = useState(""); const [color, setColor] = useState("none"); const [continuousAdd, setContinuousAdd] = useState(false); // 연속 입력 체크박스 // 라벨에서 코드 자동 생성 (항상 고유한 코드 생성) const generateCode = (): string => { // 항상 CATEGORY_TIMESTAMP_RANDOM 형식으로 고유 코드 생성 const timestamp = Date.now().toString().slice(-6); const random = Math.random().toString(36).substring(2, 6).toUpperCase(); return `CATEGORY_${timestamp}${random}`; }; const resetForm = () => { setValueLabel(""); setDescription(""); setColor("none"); }; const handleSubmit = () => { if (!valueLabel.trim()) { return; } const valueCode = generateCode(); onAdd({ tableName: "", // CategoryValueManager에서 오버라이드됨 columnName: "", // CategoryValueManager에서 오버라이드됨 valueCode, valueLabel: valueLabel.trim(), description: description.trim() || undefined, // 빈 문자열 대신 undefined color: color === "none" ? undefined : color, // "none"은 undefined로 isDefault: false, } as TableCategoryValue); // 연속 입력 체크되어 있으면 폼만 초기화하고 모달 유지 if (continuousAdd) { resetForm(); } else { // 연속 입력 아니면 모달 닫기 resetForm(); onOpenChange(false); } }; const handleClose = () => { resetForm(); onOpenChange(false); }; return ( { if (!isOpen) { resetForm(); } onOpenChange(isOpen); }}> 새 카테고리 값 추가 {columnLabel}에 새로운 값을 추가합니다
setValueLabel(e.target.value)} className="h-8 text-xs sm:h-10 sm:text-sm mt-1.5" autoFocus />
{DEFAULT_COLORS.map((c) => (
{color && color !== "none" ? ( 미리보기 ) : ( 배지 없음 )}