Agent image fallback added

This commit is contained in:
Lanthoiba22
2025-10-02 21:53:38 +05:30
parent cc9b4c2bcb
commit 045630b8a5
6 changed files with 50 additions and 28 deletions

View File

@@ -0,0 +1,34 @@
import { useState } from 'react';
import Robot from '../assets/robot.svg';
type AgentImageProps = {
src?: string | null;
alt?: string;
className?: string;
fallbackSrc?: string;
};
export default function AgentImage({
src,
alt = 'agent',
className = '',
fallbackSrc = Robot,
}: AgentImageProps) {
const initialSrc = src && src.trim() !== '' ? src : fallbackSrc;
const [currentSrc, setCurrentSrc] = useState(initialSrc);
return (
<img
src={currentSrc}
alt={alt}
className={className}
referrerPolicy="no-referrer"
crossOrigin="anonymous"
onError={() => {
if (currentSrc !== fallbackSrc) setCurrentSrc(fallbackSrc);
}}
/>
);
}