diff --git a/src/pages/AssetDetail.tsx b/src/pages/AssetDetail.tsx index 7b3cb23..c3064fc 100644 --- a/src/pages/AssetDetail.tsx +++ b/src/pages/AssetDetail.tsx @@ -16,6 +16,7 @@ const AssetDetail: React.FC = () => { const isNewAsset = assetName === 'new'; const isDuplicating = isNewAsset && !!duplicateFromAsset; + // If duplicating, fetch the source asset const { asset, loading, error } = useAssetDetails( isDuplicating ? duplicateFromAsset : (isNewAsset ? null : assetName || null) ); @@ -43,12 +44,13 @@ const AssetDetail: React.FC = () => { custom_total_amount: 0 }); + // Load asset data for editing or duplicating useEffect(() => { if (asset) { setFormData({ asset_name: isDuplicating ? `${asset.asset_name} (Copy)` : (asset.asset_name || ''), company: asset.company || '', - custom_serial_number: isDuplicating ? '' : (asset.custom_serial_number || ''), + custom_serial_number: isDuplicating ? '' : (asset.custom_serial_number || ''), // Clear serial number for duplicates location: asset.location || '', custom_manufacturer: asset.custom_manufacturer || '', department: asset.department || '', @@ -79,6 +81,7 @@ const AssetDetail: React.FC = () => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); + // Validate required fields if (!formData.asset_name) { alert('Please enter an Asset Name'); return; @@ -89,6 +92,7 @@ const AssetDetail: React.FC = () => { return; } + // Show console log for debugging console.log('Submitting asset data:', formData); try { @@ -106,8 +110,10 @@ const AssetDetail: React.FC = () => { } } catch (err) { console.error('Asset save error:', err); + const errorMessage = err instanceof Error ? err.message : 'Unknown error'; + // Check if it's an API deployment issue if (errorMessage.includes('404') || errorMessage.includes('not found') || errorMessage.includes('has no attribute') || errorMessage.includes('417')) { alert( @@ -153,7 +159,8 @@ const AssetDetail: React.FC = () => { ); } - + + // Show error for duplicate if source asset not found if (error && isDuplicating) { return (
- The asset you're trying to duplicate could not be found. + The asset you're trying to duplicate could not be found. It may have been deleted or you may not have permission to access it.