import { useState } from 'react' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { Plus, Edit, Trash2, X } from 'lucide-react' import { getTemplates, createTemplate, updateTemplate, deleteTemplate } from '../api/client' export default function TemplateList() { const qc = useQueryClient() const [modal, setModal] = useState(null) const { data: templates = [], isLoading } = useQuery({ queryKey: ['templates'], queryFn: () => getTemplates(), }) const saveMut = useMutation({ mutationFn: (d: any) => d.id ? updateTemplate(d.id, d) : createTemplate(d), onSuccess: () => { qc.invalidateQueries({ queryKey: ['templates'] }); setModal(null) }, }) const deleteMut = useMutation({ mutationFn: deleteTemplate, onSuccess: () => qc.invalidateQueries({ queryKey: ['templates'] }), }) if (isLoading) return
로딩 중...
return (

ESL 템플릿

{(templates as any[]).map((t: any) => (

{t.templateName}

{t.tenantCode} · {t.templateType}

{t.width}×{t.height}px

{t.description}

코드: {t.templateCode}

))} {(templates as any[]).length === 0 && (
템플릿이 없습니다
)}
{modal && (

{modal.id ? '템플릿 수정' : '템플릿 추가'}

saveMut.mutate(d)} />
)}
) } function TemplateForm({ initial, onSave }: { initial: any; onSave: (d: any) => void }) { const isEdit = !!initial.id const [f, setF] = useState({ tenantCode: initial.tenantCode || 'EMART', templateCode: initial.templateCode || '', templateName: initial.templateName || '', templateType: initial.templateType || 'PRICE', width: initial.width ?? 250, height: initial.height ?? 122, description: initial.description || '', layoutJson: initial.layoutJson || '', active: initial.active !== false, id: initial.id, }) const set = (k: string) => (e: React.ChangeEvent) => setF(p => ({ ...p, [k]: e.target.value })) const submit = (e: React.FormEvent) => { e.preventDefault() onSave({ ...f, width: f.width === ('' as any) ? null : Number(f.width), height: f.height === ('' as any) ? null : Number(f.height), active: f.active === true || (f as any).active === 'true', }) } return (
{[ { label: '너비(px)', key: 'width' }, { label: '높이(px)', key: 'height' }, ].map(({ label, key }) => (
))}