import { useState, useEffect } from 'react'; import ReactDOM from 'react-dom'; import { useAuth } from '../../contexts/AuthContext'; export interface SeoConsentModalProps { onClose: () => void; } const SeoConsentModal = ({ onClose }: SeoConsentModalProps) => { const { seoConsent, updateSeoConsent } = useAuth(); const [isEnabled, setIsEnabled] = useState(seoConsent); const [isSubmitting, setIsSubmitting] = useState(false); useEffect(() => { setIsEnabled(seoConsent); }, [seoConsent]); const toggleConsent = async () => { if (isSubmitting) return; const newValue = !isEnabled; setIsEnabled(newValue); // Optimistic update setIsSubmitting(true); try { await updateSeoConsent(newValue); } catch (error) { console.error("Failed to update consent:", error); setIsEnabled(!newValue); // Revert on error } finally { setIsSubmitting(false); } }; const modalContent = (
To help the WordPress community, we may publish anonymized versions of helpful conversations as articles.
Your choice is saved automatically.