import { Sync, SyncDisabled } from '@mui/icons-material' import { Box, Card, Chip, FormControl, FormHelperText, FormLabel, Switch, Typography, } from '@mui/joy' import { useSSEContext } from '../hooks/useSSEContext' import { useUserProfile } from '../queries/UserQueries' import { isPlusAccount } from '../utils/Helpers' import SSEConnectionStatus from './SSEConnectionStatus' const SSESettings = () => { const { data: userProfile } = useUserProfile() const { isConnected, isConnecting, error, getConnectionStatus, toggleSSEEnabled, isSSEEnabled, } = useSSEContext() const handleToggle = () => { console.log('=== TOGGLE CLICKED ===') if (!isPlusAccount(userProfile)) { console.log('Not a Plus account, returning early') return // Don't allow toggle for non-Plus users } const currentlyEnabled = isSSEEnabled() console.log('SSE Settings - Toggle clicked:', { currentlyEnabled, newState: !currentlyEnabled, userProfile, isPlusAccount: isPlusAccount(userProfile), }) toggleSSEEnabled(!currentlyEnabled) } const getStatusDescription = () => { if (!isPlusAccount(userProfile)) { return 'Real-time updates (SSE) are not available in the Basic plan. Upgrade to Plus to receive instant notifications when chores are updated.' } if (!isSSEEnabled()) { return 'Real-time updates (SSE) are disabled. Enable to see live changes when you or other circle members complete, skip, or modify chores.' } if (isConnected) { return "Real-time updates (SSE) are working. You'll see live changes when you or other circle members complete, skip, or modify chores." } if (isConnecting) { return 'Connecting to real-time updates (SSE)...' } if (error) { return `Real-time updates (SSE) are enabled but not working: ${error}` } return 'Real-time updates (SSE) are enabled but not currently connected.' } return ( {isSSEEnabled() && isPlusAccount(userProfile) ? ( ) : ( )} Real-time Updates (SSE) {!isPlusAccount(userProfile) && ( Plus Feature )} Get instant notifications via Server-Sent Events {isSSEEnabled() && isPlusAccount(userProfile) && ( )} Enable Real-time Updates (SSE) {getStatusDescription()} {isSSEEnabled() && isPlusAccount(userProfile) && ( Status: {getConnectionStatus()} {error && ( {error} )} )} {!isPlusAccount(userProfile) && ( Real-time updates (SSE) are not available in the Basic plan. Upgrade to Plus to receive instant notifications when you or other circle members complete, skip, or modify chores. )} ) } export default SSESettings