import React, { useState } from 'react'; import type { CompetitorSnapshot } from '../../service/visibility/visibility.interface'; import { excludeCompetitor } from '../../service/visibility/visibility.service'; import Modal from './Modal'; /** Props for {@link ConfirmExcludeCompetitorModal}. */ interface ConfirmExcludeCompetitorModalProps { /** Modal open flag. */ open: boolean; /** Competitor row whose delete button was clicked. ``null`` hides the body. */ competitor: CompetitorSnapshot | null; /** Close handler. Fires on cancel and after a successful exclude. */ onClose: () => void; /** * Called after the backend confirms the exclusion. Parent should use it * to refetch the leaderboard so the excluded row disappears. */ onExcluded: () => void; /** Recomaze client id. */ clientId: string; /** Recomaze JWT. */ token: string; /** Brand the competitor belongs to. */ brandId: string; } /** * Confirmation dialog for the per-row "delete" button on the competitor * leaderboard. Sends ``POST /excluded-competitors`` which (a) drops the * rival from the current leaderboard view and (b) tells the scanner to * skip the domain on future weeks. * * @param {ConfirmExcludeCompetitorModalProps} props - Dialog props. * @returns {JSX.Element} The modal. */ const ConfirmExcludeCompetitorModal = ({ open, competitor, onClose, onExcluded, clientId, token, brandId, }: ConfirmExcludeCompetitorModalProps): JSX.Element => { const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); const handleConfirm = async (): Promise => { if (!competitor) return; setSubmitting(true); setError(null); try { await excludeCompetitor(clientId, token, brandId, { domain: competitor.competitor_domain, }); onExcluded(); onClose(); } catch (err) { setError( err instanceof Error ? err.message : 'Failed to remove competitor.' ); } finally { setSubmitting(false); } }; const displayName = competitor?.competitor_name || competitor?.competitor_domain || ''; return ( } >
{error && (
{error}
)} {competitor && (

{displayName} will disappear from the leaderboard and we'll stop counting it on future scans. You can add it back manually under “Tracked competitors” if you change your mind.

)}
); }; export default ConfirmExcludeCompetitorModal;