import { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import { Warning as WarningIcon } from '@openedx/paragon/icons'; import { useIntl } from '@edx/frontend-platform/i18n'; import { RequestStatus } from '../../data/constants'; import AlertMessage from '../alert-message'; import messages from './messages'; const SavingErrorAlert = ({ savingStatus, errorMessage, }) => { const intl = useIntl(); const [showAlert, setShowAlert] = useState(false); const [isOnline, setIsOnline] = useState(window.navigator.onLine); const isQueryFailed = savingStatus === RequestStatus.FAILED; useEffect(() => { const handleOnlineStatus = () => setIsOnline(window.navigator.onLine); const events = ['online', 'offline']; events.forEach((event) => { window.addEventListener(event, handleOnlineStatus); }); return () => { events.forEach((event) => { window.removeEventListener(event, handleOnlineStatus); }); }; }, [isOnline]); useEffect(() => { setShowAlert((!isOnline && isQueryFailed) || isQueryFailed); }, [isQueryFailed, isOnline]); return (