lhj #354

Merged
hjlee merged 2 commits from lhj into main 2026-01-13 10:04:42 +09:00
2 changed files with 63 additions and 23 deletions

View File

@ -14,6 +14,7 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea"; import { Textarea } from "@/components/ui/textarea";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { Checkbox } from "@/components/ui/checkbox";
import { TableCategoryValue } from "@/types/tableCategoryValue"; import { TableCategoryValue } from "@/types/tableCategoryValue";
// 기본 색상 팔레트 // 기본 색상 팔레트
@ -51,6 +52,7 @@ export const CategoryValueAddDialog: React.FC<
const [valueLabel, setValueLabel] = useState(""); const [valueLabel, setValueLabel] = useState("");
const [description, setDescription] = useState(""); const [description, setDescription] = useState("");
const [color, setColor] = useState("none"); const [color, setColor] = useState("none");
const [continuousAdd, setContinuousAdd] = useState(false); // 연속 입력 체크박스
// 라벨에서 코드 자동 생성 (항상 고유한 코드 생성) // 라벨에서 코드 자동 생성 (항상 고유한 코드 생성)
const generateCode = (): string => { const generateCode = (): string => {
@ -60,6 +62,12 @@ export const CategoryValueAddDialog: React.FC<
return `CATEGORY_${timestamp}${random}`; return `CATEGORY_${timestamp}${random}`;
}; };
const resetForm = () => {
setValueLabel("");
setDescription("");
setColor("none");
};
const handleSubmit = () => { const handleSubmit = () => {
if (!valueLabel.trim()) { if (!valueLabel.trim()) {
return; return;
@ -77,14 +85,28 @@ export const CategoryValueAddDialog: React.FC<
isDefault: false, isDefault: false,
} as TableCategoryValue); } as TableCategoryValue);
// 초기화 // 연속 입력 체크되어 있으면 폼만 초기화하고 모달 유지
setValueLabel(""); if (continuousAdd) {
setDescription(""); resetForm();
setColor("none"); } else {
// 연속 입력 아니면 모달 닫기
resetForm();
onOpenChange(false);
}
};
const handleClose = () => {
resetForm();
onOpenChange(false);
}; };
return ( return (
<Dialog open={open} onOpenChange={onOpenChange}> <Dialog open={open} onOpenChange={(isOpen) => {
if (!isOpen) {
resetForm();
}
onOpenChange(isOpen);
}}>
<DialogContent className="max-w-[95vw] sm:max-w-[500px]"> <DialogContent className="max-w-[95vw] sm:max-w-[500px]">
<DialogHeader> <DialogHeader>
<DialogTitle className="text-base sm:text-lg"> <DialogTitle className="text-base sm:text-lg">
@ -165,24 +187,42 @@ export const CategoryValueAddDialog: React.FC<
</div> </div>
</div> </div>
<DialogFooter className="gap-2 sm:gap-0"> <DialogFooter className="flex-col gap-3 sm:flex-row sm:gap-0">
<Button {/* 연속 입력 체크박스 */}
variant="outline" <div className="flex items-center gap-2 w-full sm:w-auto sm:mr-auto">
onClick={() => onOpenChange(false)} <Checkbox
className="h-8 flex-1 text-xs sm:h-10 sm:flex-none sm:text-sm" id="continuousAdd"
> checked={continuousAdd}
onCheckedChange={(checked) => setContinuousAdd(checked as boolean)}
</Button> />
<Button <label
onClick={handleSubmit} htmlFor="continuousAdd"
disabled={!valueLabel.trim()} className="text-xs sm:text-sm text-muted-foreground cursor-pointer"
className="h-8 flex-1 text-xs sm:h-10 sm:flex-none sm:text-sm" >
>
</label>
</Button> </div>
<div className="flex gap-2 w-full sm:w-auto">
<Button
type="button"
variant="outline"
onClick={handleClose}
className="h-8 flex-1 text-xs sm:h-10 sm:flex-none sm:text-sm"
>
</Button>
<Button
type="button"
onClick={handleSubmit}
disabled={!valueLabel.trim()}
className="h-8 flex-1 text-xs sm:h-10 sm:flex-none sm:text-sm"
>
</Button>
</div>
</DialogFooter> </DialogFooter>
</DialogContent> </DialogContent>
</Dialog> </Dialog>
); );
}; };

View File

@ -123,7 +123,7 @@ export const CategoryValueManager: React.FC<CategoryValueManagerProps> = ({
if (response.success && response.data) { if (response.success && response.data) {
await loadCategoryValues(); await loadCategoryValues();
setIsAddDialogOpen(false); // 모달 닫기는 CategoryValueAddDialog에서 연속 입력 체크박스로 제어
toast({ toast({
title: "성공", title: "성공",
description: "카테고리 값이 추가되었습니다", description: "카테고리 값이 추가되었습니다",
@ -142,7 +142,7 @@ export const CategoryValueManager: React.FC<CategoryValueManagerProps> = ({
title: "오류", title: "오류",
description: error.message || "카테고리 값 추가에 실패했습니다", description: error.message || "카테고리 값 추가에 실패했습니다",
variant: "destructive", variant: "destructive",
}); });
} }
}; };