import React, { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { LuSparkles, LuX } from 'react-icons/lu'; import { getStoreContext } from '../../service/visibility/visibility.service'; interface StoreContextAnnounceModalProps { clientId: string; token: string; brandId: string | null; } const PROFILE_PATH = '/ai-visibility'; const seenKey = (brandId: string): string => `reco_store_context_seen_${brandId}`; const StoreContextAnnounceModal = ({ clientId, token, brandId, }: StoreContextAnnounceModalProps): JSX.Element | null => { const navigate = useNavigate(); const [open, setOpen] = useState(false); const [identity, setIdentity] = useState(''); useEffect(() => { if (!brandId) return; if ( typeof window !== 'undefined' && window.localStorage.getItem(seenKey(brandId)) ) { return; } let cancelled = false; getStoreContext(clientId, token, brandId) .then(context => { if (cancelled) return; if (context.exists && !context.edited && context.identity.trim()) { setIdentity(context.identity.trim()); setOpen(true); } }) .catch(() => {}); return () => { cancelled = true; }; }, [clientId, token, brandId]); const markSeen = () => { if (brandId && typeof window !== 'undefined') { window.localStorage.setItem(seenKey(brandId), '1'); } }; const handleDismiss = () => { markSeen(); setOpen(false); }; const handleReview = () => { markSeen(); setOpen(false); navigate(PROFILE_PATH); }; if (!brandId || !open) return null; return (
How Recomaze Co-pilot sees your store Beta

{identity}

); }; export default StoreContextAnnounceModal;