This commit is contained in:
Duradundi Hadimani 2025-11-14 17:06:03 +05:30
commit 34f8581b29
2 changed files with 57 additions and 9 deletions

View File

@ -7,6 +7,11 @@ import type { CreateAssetData, AssetFinanceBookRow } from '../services/assetServ
import LinkField from '../components/LinkField'; import LinkField from '../components/LinkField';
import apiService from '../services/apiService'; // ✅ your ApiService import apiService from '../services/apiService'; // ✅ your ApiService
// Helper function to get the base URL for files
const getFileBaseUrl = () => {
// Always use the full URL to avoid proxy path duplication issues
return import.meta.env.VITE_FRAPPE_BASE_URL || 'https://seeraasm-med.seeraarabia.com';
};
const AssetDetail: React.FC = () => { const AssetDetail: React.FC = () => {
const { assetName } = useParams<{ assetName: string }>(); const { assetName } = useParams<{ assetName: string }>();
@ -137,6 +142,9 @@ const AssetDetail: React.FC = () => {
// Load asset data for editing or duplicating // Load asset data for editing or duplicating
useEffect(() => { useEffect(() => {
if (asset) { if (asset) {
// Debug: Log asset data to check if name field exists
console.log('Asset data loaded:', asset);
console.log('Asset name:', asset.name);
setFormData({ setFormData({
asset_name: isDuplicating ? `${asset.asset_name} (Copy)` : (asset.asset_name || ''), asset_name: isDuplicating ? `${asset.asset_name} (Copy)` : (asset.asset_name || ''),
company: asset.company || '', company: asset.company || '',
@ -1323,19 +1331,44 @@ const AssetDetail: React.FC = () => {
</div> </div>
{/* QR Code */} {/* QR Code */}
<div className="flex flex-col items-center my-6">
<div className="flex justify-center my-6"> <div className="border-2 border-gray-300 dark:border-gray-600 p-4 rounded-lg bg-white dark:bg-gray-700">
<div className="border-2 border-gray-300 dark:border-gray-600 p-4 rounded-lg">
{qrCodeUrl ? ( {qrCodeUrl ? (
<>
<img <img
src={qrCodeUrl} src={qrCodeUrl}
alt="QR Code" alt={`QR Code for ${asset?.name || 'Asset'}`}
className="w-40 h-40 object-contain" className="w-[120px] h-[120px] object-contain"
onError={(e) => {
// Hide image and show fallback icon if QR code doesn't exist
const target = e.target as HTMLImageElement;
target.style.display = 'none';
const fallback = target.nextElementSibling as HTMLElement;
if (fallback) {
fallback.style.display = 'flex';
}
}}
/> />
<div className="w-[120px] h-[120px] hidden items-center justify-center bg-gray-100 dark:bg-gray-700 rounded">
<FaQrcode size={80} className="text-gray-400 dark:text-gray-500" />
</div>
</>
) : ( ) : (
<FaQrcode size={120} className="text-gray-400 dark:text-gray-500" /> <div className="w-[120px] h-[120px] flex items-center justify-center bg-gray-100 dark:bg-gray-700 rounded">
<FaQrcode size={80} className="text-gray-400 dark:text-gray-500" />
</div>
)} )}
</div> </div>
{asset?.name && (
<p className="mt-2 text-xs text-gray-500 dark:text-gray-400 text-center">
Asset ID: {asset.name}
</p>
)}
{!asset && !loading && (
<p className="mt-2 text-xs text-red-500 dark:text-red-400 text-center">
Asset data not loaded
</p>
)}
</div> </div>

View File

@ -35,6 +35,21 @@ export default defineConfig({
proxyRes.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization, X-Frappe-CSRF-Token'; proxyRes.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization, X-Frappe-CSRF-Token';
}); });
}, },
},
// Proxy file requests to Frappe backend
'/files': {
target: process.env.VITE_FRAPPE_BASE_URL || 'https://seeraasm-med.seeraarabia.com',
changeOrigin: true,
secure: true,
// Keep the /files path as-is when forwarding to the target
configure: (proxy, _options) => {
proxy.on('proxyReq', (proxyReq, req, _res) => {
// Log for debugging
if (process.env.DEV) {
console.log('Proxying file request:', req.url, 'to', proxyReq.path);
}
});
},
} }
} }
}, },