import Modal from '@app/components/Common/Modal'; import useSettings from '@app/hooks/useSettings'; import { Permission, useUser } from '@app/hooks/useUser'; import globalMessages from '@app/i18n/globalMessages'; import { Transition } from '@headlessui/react'; import { RefreshIcon, SparklesIcon } from '@heroicons/react/outline'; import type { StatusResponse } from '@server/interfaces/api/settingsInterfaces'; import { useEffect, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import useSWR from 'swr'; const messages = defineMessages({ appUpdated: '{applicationTitle} Updated', appUpdatedDescription: 'Please click the button below to reload the application.', reloadApp: 'Reload {applicationTitle}', restartRequired: 'Server Restart Required', restartRequiredDescription: 'Please restart the server to apply the updated settings.', }); const StatusChecker = () => { const intl = useIntl(); const settings = useSettings(); const { hasPermission } = useUser(); const { data, error } = useSWR('/api/v1/status', { refreshInterval: 60 * 1000, }); const [alertDismissed, setAlertDismissed] = useState(false); useEffect(() => { if (!data?.restartRequired) { setAlertDismissed(false); } }, [data?.restartRequired]); if (!data && !error) { return null; } if (!data) { return null; } return ( {hasPermission(Permission.ADMIN) && data.restartRequired ? ( } title={intl.formatMessage(messages.restartRequired)} backgroundClickable={false} onOk={() => { setAlertDismissed(true); if (data.commitTag !== process.env.commitTag) { location.reload(); } }} okText={intl.formatMessage(globalMessages.close)} > {intl.formatMessage(messages.restartRequiredDescription)} ) : ( } title={intl.formatMessage(messages.appUpdated, { applicationTitle: settings.currentSettings.applicationTitle, })} onOk={() => location.reload()} okText={intl.formatMessage(messages.reloadApp, { applicationTitle: settings.currentSettings.applicationTitle, })} backgroundClickable={false} > {intl.formatMessage(messages.appUpdatedDescription)} )} ); }; export default StatusChecker;