diff --git a/packages/journey-manager/src/ui/components/index.tsx b/packages/journey-manager/src/ui/components/index.tsx index 1b6146e9..0aed4a66 100644 --- a/packages/journey-manager/src/ui/components/index.tsx +++ b/packages/journey-manager/src/ui/components/index.tsx @@ -284,6 +284,34 @@ const retrieveNudgeState = (conversationId: string): NudgeState => { return "hidden"; }; +const PinIcon: FC<{ iconUrl?: string }> = ({ iconUrl }) => { + const [isIconUrlValid, setIsIconUrlValid] = useState(null); + + useEffect(() => { + if (iconUrl == null) { + return; + } + const image = new Image(); + image.onload = () => { + setIsIconUrlValid(true); + }; + image.onerror = () => { + setIsIconUrlValid(false); + }; + image.src = iconUrl; + }, [iconUrl, setIsIconUrlValid]); + + if (iconUrl == null || isIconUrlValid === false) { + return ; + } + + if (isIconUrlValid == null) { + return null; + } + + return ; +}; + export const ControlCenter: FC<{ config: UiConfig; conversationId: string; @@ -384,15 +412,7 @@ export const ControlCenter: FC<{ setIsOpen((prev) => !prev); }} > - {config.iconUrl != null ? ( - - ) : ( - - )} +