2025-11-05 15:23:57 +09:00
|
|
|
"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";
|
2025-11-06 12:09:28 +09:00
|
|
|
import { Label } from "@/components/ui/label";
|
2025-11-05 15:23:57 +09:00
|
|
|
import { Textarea } from "@/components/ui/textarea";
|
2025-11-06 12:09:28 +09:00
|
|
|
import { Badge } from "@/components/ui/badge";
|
2025-11-05 15:23:57 +09:00
|
|
|
import { TableCategoryValue } from "@/types/tableCategoryValue";
|
|
|
|
|
|
2025-11-06 12:09:28 +09:00
|
|
|
// 기본 색상 팔레트
|
|
|
|
|
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
|
|
|
|
|
];
|
|
|
|
|
|
2025-11-05 15:23:57 +09:00
|
|
|
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("");
|
2025-11-13 15:24:31 +09:00
|
|
|
const [color, setColor] = useState("none");
|
2025-11-05 18:08:51 +09:00
|
|
|
|
2025-12-02 18:03:52 +09:00
|
|
|
// 라벨에서 코드 자동 생성 (항상 고유한 코드 생성)
|
|
|
|
|
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}`;
|
2025-11-05 18:08:51 +09:00
|
|
|
};
|
2025-11-05 15:23:57 +09:00
|
|
|
|
|
|
|
|
const handleSubmit = () => {
|
2025-11-05 18:08:51 +09:00
|
|
|
if (!valueLabel.trim()) {
|
2025-11-05 15:23:57 +09:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-02 18:03:52 +09:00
|
|
|
const valueCode = generateCode();
|
2025-11-05 18:08:51 +09:00
|
|
|
|
2025-11-05 15:23:57 +09:00
|
|
|
onAdd({
|
2025-11-17 16:48:42 +09:00
|
|
|
tableName: "", // CategoryValueManager에서 오버라이드됨
|
|
|
|
|
columnName: "", // CategoryValueManager에서 오버라이드됨
|
2025-11-05 18:08:51 +09:00
|
|
|
valueCode,
|
|
|
|
|
valueLabel: valueLabel.trim(),
|
2025-11-17 16:48:42 +09:00
|
|
|
description: description.trim() || undefined, // 빈 문자열 대신 undefined
|
|
|
|
|
color: color === "none" ? undefined : color, // "none"은 undefined로
|
2025-11-05 18:08:51 +09:00
|
|
|
isDefault: false,
|
2025-11-17 16:48:42 +09:00
|
|
|
} as TableCategoryValue);
|
2025-11-05 15:23:57 +09:00
|
|
|
|
|
|
|
|
// 초기화
|
|
|
|
|
setValueLabel("");
|
|
|
|
|
setDescription("");
|
2025-11-13 15:24:31 +09:00
|
|
|
setColor("none");
|
2025-11-05 15:23:57 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
|
|
|
<DialogContent className="max-w-[95vw] sm:max-w-[500px]">
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle className="text-base sm:text-lg">
|
|
|
|
|
새 카테고리 값 추가
|
|
|
|
|
</DialogTitle>
|
|
|
|
|
<DialogDescription className="text-xs sm:text-sm">
|
|
|
|
|
{columnLabel}에 새로운 값을 추가합니다
|
|
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-3 sm:space-y-4">
|
2025-11-06 12:09:28 +09:00
|
|
|
<div>
|
|
|
|
|
<Label htmlFor="valueLabel" className="text-xs sm:text-sm">
|
|
|
|
|
이름
|
|
|
|
|
</Label>
|
|
|
|
|
<Input
|
|
|
|
|
id="valueLabel"
|
|
|
|
|
placeholder="예: 개발, 긴급, 진행중"
|
|
|
|
|
value={valueLabel}
|
|
|
|
|
onChange={(e) => setValueLabel(e.target.value)}
|
|
|
|
|
className="h-8 text-xs sm:h-10 sm:text-sm mt-1.5"
|
|
|
|
|
autoFocus
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<Label className="text-xs sm:text-sm">배지 색상</Label>
|
2025-11-13 15:24:31 +09:00
|
|
|
<div className="mt-1.5 space-y-2">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="grid grid-cols-9 gap-2">
|
|
|
|
|
{DEFAULT_COLORS.map((c) => (
|
|
|
|
|
<button
|
|
|
|
|
key={c}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setColor(c)}
|
|
|
|
|
className={`h-7 w-7 rounded-md border-2 transition-all ${
|
|
|
|
|
color === c ? "border-foreground scale-110" : "border-transparent hover:scale-105"
|
|
|
|
|
}`}
|
|
|
|
|
style={{ backgroundColor: c }}
|
|
|
|
|
title={c}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
{color && color !== "none" ? (
|
|
|
|
|
<Badge style={{ backgroundColor: color, borderColor: color }} className="text-white">
|
|
|
|
|
미리보기
|
|
|
|
|
</Badge>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="text-xs text-muted-foreground">배지 없음</span>
|
|
|
|
|
)}
|
2025-11-06 12:09:28 +09:00
|
|
|
</div>
|
2025-11-13 15:24:31 +09:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setColor("none")}
|
|
|
|
|
className={`text-xs px-3 py-1.5 rounded-md border transition-colors ${
|
|
|
|
|
color === "none"
|
|
|
|
|
? "border-primary bg-primary/10 text-primary font-medium"
|
|
|
|
|
: "border-border hover:bg-accent"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
배지 없음
|
|
|
|
|
</button>
|
2025-11-06 12:09:28 +09:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-11-05 15:23:57 +09:00
|
|
|
|
2025-11-06 12:09:28 +09:00
|
|
|
<div>
|
|
|
|
|
<Label htmlFor="description" className="text-xs sm:text-sm">
|
|
|
|
|
설명 (선택사항)
|
|
|
|
|
</Label>
|
|
|
|
|
<Textarea
|
|
|
|
|
id="description"
|
|
|
|
|
placeholder="설명을 입력하세요"
|
|
|
|
|
value={description}
|
|
|
|
|
onChange={(e) => setDescription(e.target.value)}
|
|
|
|
|
className="text-xs sm:text-sm mt-1.5"
|
|
|
|
|
rows={3}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-11-05 15:23:57 +09:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<DialogFooter className="gap-2 sm:gap-0">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
onClick={() => onOpenChange(false)}
|
|
|
|
|
className="h-8 flex-1 text-xs sm:h-10 sm:flex-none sm:text-sm"
|
|
|
|
|
>
|
|
|
|
|
취소
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={handleSubmit}
|
2025-11-05 18:08:51 +09:00
|
|
|
disabled={!valueLabel.trim()}
|
2025-11-05 15:23:57 +09:00
|
|
|
className="h-8 flex-1 text-xs sm:h-10 sm:flex-none sm:text-sm"
|
|
|
|
|
>
|
|
|
|
|
추가
|
|
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|