Files
sam-react-prod/src/components/items/ItemMasterDataManagement/dialogs/PathEditDialog.tsx
byeongcheolryu b73603822b refactor: 품목기준관리 hooks 분리 및 다이얼로그 개선
- ItemMasterDataManagement 컴포넌트에서 hooks 분리
- 다이얼로그 컴포넌트들 타입 및 구조 개선
- BOMManagementSection 개선
- HierarchyTab 업데이트

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 14:06:48 +09:00

86 lines
3.3 KiB
TypeScript

'use client';
import { useState } from 'react';
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';
import { toast } from 'sonner';
interface PathEditDialogProps {
editingPathPageId: number | null;
setEditingPathPageId: (id: number | null) => void;
editingAbsolutePath: string;
setEditingAbsolutePath: (path: string) => void;
updateItemPage: (id: number, updates: any) => void;
trackChange: (type: 'pages' | 'sections' | 'fields' | 'masterFields' | 'attributes' | 'sectionTemplates', id: string, action: 'add' | 'update', data: any, attributeType?: string) => void;
}
export function PathEditDialog({
editingPathPageId,
setEditingPathPageId,
editingAbsolutePath,
setEditingAbsolutePath,
updateItemPage,
trackChange,
}: PathEditDialogProps) {
const [isSubmitted, setIsSubmitted] = useState(false);
// 유효성 검사
const isPathEmpty = !editingAbsolutePath.trim();
const isPathInvalid = editingAbsolutePath.trim() && !editingAbsolutePath.startsWith('/');
const handleClose = () => {
setEditingPathPageId(null);
setEditingAbsolutePath('');
setIsSubmitted(false);
};
return (
<Dialog open={editingPathPageId !== null} onOpenChange={(open) => {
if (!open) handleClose();
}}>
<DialogContent>
<DialogHeader>
<DialogTitle> </DialogTitle>
<DialogDescription> (: //)</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div>
<Label> *</Label>
<Input
value={editingAbsolutePath}
onChange={(e) => setEditingAbsolutePath(e.target.value)}
placeholder="/제품관리/제품등록"
className={isSubmitted && (isPathEmpty || isPathInvalid) ? 'border-red-500 focus-visible:ring-red-500' : ''}
/>
{isSubmitted && isPathEmpty && (
<p className="text-xs text-red-500 mt-1"> </p>
)}
{isSubmitted && isPathInvalid && (
<p className="text-xs text-red-500 mt-1"> (/) </p>
)}
{!isSubmitted || (!isPathEmpty && !isPathInvalid) ? (
<p className="text-xs text-gray-500 mt-1">(/) , </p>
) : null}
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={handleClose}></Button>
<Button onClick={() => {
setIsSubmitted(true);
if (isPathEmpty || isPathInvalid) {
return;
}
if (editingPathPageId) {
updateItemPage(editingPathPageId, { absolutePath: editingAbsolutePath });
trackChange('pages', String(editingPathPageId), 'update', { absolutePath: editingAbsolutePath });
handleClose();
toast.success('절대경로가 수정되었습니다 (저장 필요)');
}
}}></Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}