From 18ed88bff086070f2bed9f33871fc784abaa59c6 Mon Sep 17 00:00:00 2001 From: Duradundi Hadimani Date: Thu, 13 Nov 2025 17:42:28 +0530 Subject: [PATCH] Updated src/pages/AssetDetail.tsx file --- src/pages/AssetDetail.tsx | 873 ++++++++++++++------------------------ 1 file changed, 307 insertions(+), 566 deletions(-) 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 (
@@ -162,7 +169,7 @@ const AssetDetail: React.FC = () => { Source Asset Not Found

- 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.

@@ -218,7 +225,7 @@ const AssetDetail: React.FC = () => { setIsEditing(false); } }} - className="bg-gray-300 hover:bg-gray-400 text-gray-700 dark:text-gray-800 px-6 py-2 rounded-lg" + className="bg-gray-300 hover:bg-gray-400 text-gray-700 px-6 py-2 rounded-lg" disabled={saving} > Cancel @@ -236,32 +243,6 @@ const AssetDetail: React.FC = () => {
-<<<<<<< HEAD -
- {/* 4-Column Grid Layout */} -
- - {/* COLUMN 1: Asset Information */} -
-

- Asset Information -

-
-
- - -=======
{/* Left Column - Asset Information & Technical Specs & Location */} @@ -311,7 +292,6 @@ const AssetDetail: React.FC = () => { doctype="Asset Type" value={formData.custom_asset_type || ''} onChange={(val) => setFormData({ ...formData, custom_asset_type: val })} - disabled={!isEditing} /> @@ -376,29 +356,9 @@ const AssetDetail: React.FC = () => {

)}
->>>>>>> 225d63e (Added Linkfield.tsx)
+
-<<<<<<< HEAD -
- - -======= {/* Technical Specs */}

Technical Specs

@@ -490,29 +450,9 @@ const AssetDetail: React.FC = () => { className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 dark:disabled:bg-gray-700 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" />
->>>>>>> 225d63e (Added Linkfield.tsx)
+
-<<<<<<< HEAD -
- - -======= {/* Location */}

Location

@@ -616,237 +556,301 @@ const AssetDetail: React.FC = () => { className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 dark:disabled:bg-gray-700 bg-white dark:bg-gray-700 text-gray-900 dark:text-white" />
->>>>>>> 225d63e (Added Linkfield.tsx)
+
-
- - + {/* Coverage */} +
+

Coverage

+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +