import React, { useState } from 'react'; import { Card } from '../../../shared/ui/Card'; import { Button } from '../../../shared/ui/Button'; import { ArrowLeft, Save, Upload, X, Printer, ZoomIn, Trash2, Plus } from 'lucide-react'; import { assetApi } from '../../../shared/api/assetApi'; import type { Asset } from '../../../shared/api/assetApi'; import { SERVER_URL } from '../../../shared/api/client'; import { createPortal } from 'react-dom'; import { useAuth } from '../../../shared/auth/AuthContext'; interface AssetBasicInfoProps { asset: Asset & { image?: string, consumables?: any[] }; onRefresh: () => void; } export function AssetBasicInfo({ asset, onRefresh }: AssetBasicInfoProps) { const { user } = useAuth(); // User role is now allowed to edit assets const canEdit = user?.role === 'admin' || user?.role === 'supervisor' || user?.role === 'user'; const [isEditing, setIsEditing] = useState(false); const [editData, setEditData] = useState(asset); const [isZoomed, setIsZoomed] = useState(false); const handleChange = ( e: React.ChangeEvent ) => { const { name, value } = e.target; setEditData(prev => ({ ...prev, [name]: value })); }; const handleSave = async () => { try { await assetApi.update(asset.id, editData); setIsEditing(false); onRefresh(); // Refresh data from server } catch (error) { console.error("Failed to update asset:", error); alert("저장에 실패했습니다."); } }; const handleImageUpload = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; try { const res = await assetApi.uploadImage(file); setEditData(prev => ({ ...prev, image: res.data.url })); } catch (error) { console.error("Failed to upload image:", error); alert("이미지 업로드에 실패했습니다."); } }; const handleDeleteImage = () => { if (confirm("이미지를 삭제하시겠습니까?")) { setEditData(prev => ({ ...prev, image: '' })); } }; const handleCancel = () => { setEditData(asset); setIsEditing(false); }; return ( <>
{isEditing ? ( <> ) : ( canEdit && )}
{/* Left: Image Area */}
!isEditing && editData.image && setIsZoomed(true)} > {editData.image ? ( <> {asset.name} {!isEditing && (
)} ) : (
이미지 없음
)} {isEditing && (
e.stopPropagation()}> {editData.image && ( )}
)}
{/* Right: Info Table */}
관리번호
{editData.id}
구입가격 {isEditing ? ( ) : (
{editData.purchasePrice ? `${Number(editData.purchasePrice).toLocaleString()} 원` : '-'}
)}
설비명 {isEditing ? ( ) : (
{editData.name}
)}
S/N {isEditing ? ( ) : (
{editData.serialNumber}
)}
입고일 {isEditing ? ( ) : (
{editData.purchaseDate}
)}
모델명 {isEditing ? ( ) : (
{editData.model}
)}
제작사 {isEditing ? ( ) : (
{editData.manufacturer}
)}
교정주기 {isEditing ? ( ) : (
{editData.calibrationCycle}
)}
스펙/사양 {isEditing ? ( ) : (
{editData.specs}
)}
설치위치 {isEditing ? ( ) : (
{editData.location}
)}
관리책임자 {isEditing ? ( ) : (
{editData.manager}
)}
관리상태 {isEditing ? (
) : (
{editData.status === 'active' ? '정상 가동' : editData.status === 'disposed' ? '폐기 (말소)' : editData.status === 'maintain' ? '점검 중' : '수리 필요'}
)}
{/* Consumables Section */}

관련 소모품 관리

{canEdit && }
{asset.consumables?.map(item => ( ))}
품명 규격 현재고 관리
{item.name} {item.spec} {item.qty}개
{/* Image Zoom Modal - Moved to Portal */} {isZoomed && editData.image && createPortal(
setIsZoomed(false)} >
e.stopPropagation()} > {/* Modal Header */}

{asset.name} - 이미지 상세

{/* Modal Content */}
{asset.name}
, document.body )} ); }