import React, { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { ArrowUpCircle, X, ExternalLink } from 'lucide-react'; import { api } from '../../config/api'; interface UpdateInfo { enabled: boolean; current: string; channel: 'stable' | 'beta'; latest: { stable: string; beta: string; forChannel: string; }; updateAvailable: boolean; newerBetaAvailable?: boolean; lastChecked: string; error?: string; message?: string; } async function fetchUpdateInfo(): Promise { const response = await api.get('/admin/system/updates'); return response.data; } interface UpdateNotificationProps { onDismiss?: () => void; } export const UpdateNotification: React.FC = ({ onDismiss }) => { const { t } = useTranslation(); const [dismissed, setDismissed] = useState(false); const { data: updateInfo } = useQuery({ queryKey: ['update-check'], queryFn: fetchUpdateInfo, staleTime: 60 * 60 * 1000, // 1 hour retry: false, refetchOnWindowFocus: false }); // Don't render if no update available, not enabled, or dismissed if (!updateInfo?.enabled || !updateInfo?.updateAvailable || dismissed) { return null; } const handleDismiss = () => { setDismissed(true); onDismiss?.(); }; const channelLabel = updateInfo.channel === 'beta' ? t('admin.updates.channelBeta', 'Beta') : t('admin.updates.channelStable', 'Stable'); return (

{t('admin.updates.available', 'Update Available')}

{t('admin.updates.newVersion', 'Version {{version}} is available', { version: updateInfo.latest.forChannel })} ({t('admin.updates.currentVersion', 'Current: {{version}}', { version: updateInfo.current })})

{t('admin.updates.channel', 'Channel: {{channel}}', { channel: channelLabel })}

{t('admin.updates.viewReleaseNotes', 'View Release Notes')}
); };