import StyledSectionHeader from '~/components/StyledSectionHeader' import Switch from '~/components/inputs/Switch' import api from '~/lib/api' import { useMutation, useQueryClient } from '@tanstack/react-query' import { useNotifications } from '~/context/NotificationContext' import { useAppAutoUpdateStatus } from '~/hooks/useAppAutoUpdateStatus' export default function AppAutoUpdateSection() { const { addNotification } = useNotifications() const queryClient = useQueryClient() const { data: status, isLoading } = useAppAutoUpdateStatus() const enabled = status?.enabled ?? false const toggleMutation = useMutation({ mutationFn: (value: boolean) => api.updateSetting('appAutoUpdate.enabled', value), onSuccess: (_data, value) => { queryClient.invalidateQueries({ queryKey: ['app-auto-update-status'] }) addNotification({ type: 'success', message: value ? 'App automatic updates enabled.' : 'App automatic updates disabled.', }) }, onError: () => { addNotification({ type: 'error', message: 'Failed to update app auto-update setting.' }) }, }) return ( <>
toggleMutation.mutate(value)} disabled={toggleMutation.isPending || isLoading} label="Enable Automatic App Updates" description="Automatically install minor and patch updates for apps you've opted in (toggle each app in Supply Depot). Major versions always require a manual update. Uses the same update window and cool-off period as the core schedule above." /> {enabled && status && (

Update window: {status.windowStart}–{status.windowEnd} ( {status.withinWindow ? 'currently inside' : 'currently outside'}); cool-off{' '} {status.cooloffHours}h. {status.lastResult && ( <> {' '} Last run: {status.lastResult} {status.lastAttemptAt ? ` (${new Date(status.lastAttemptAt).toLocaleString()})` : ''} )}

{status.apps.length === 0 ? (

No apps are opted in yet. Enable auto-update on individual apps from the Supply Depot.

) : (
    {status.apps.map((app) => (
  • {app.friendly_name || app.service_name}

    {app.current_version} {app.available_update_version ? ` → ${app.available_update_version}` : ' (up to date)'}

    {app.auto_disabled_reason && (

    {app.auto_disabled_reason}

    )}
    {app.reason}
  • ))}
)}
)}
) }