'use client';
import { useMutation, useQuery } from '@tanstack/react-query';
import { ExternalLink, RefreshCw, Sparkles } from 'lucide-react';
import { toast } from 'sonner';
import { useTranslations } from 'next-intl';
import services from '@/lib/services';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@/components/ui/card';
import { Spinner } from '@/components/ui/spinner';
function InfoRow({ label, value }: { label: string; value: React.ReactNode }) {
return (
{label}
{value || '-'}
);
}
export function InfoTab() {
const t = useTranslations('settings.info');
const updateQuery = useQuery({
queryKey: ['admin', 'update'],
queryFn: () => services.adminStatus.getUpdateStatus(),
refetchInterval: 30 * 60 * 1000,
staleTime: 5 * 60 * 1000,
});
const applyUpdateMutation = useMutation({
mutationFn: () => services.adminStatus.applyUpdate(),
onSuccess: () => {
toast.success(t('upgradeVerified'));
},
onError: (error: Error) => {
toast.error(error.message || t('applyUpgradeFailed'));
},
});
const update = updateQuery.data;
return (
{t('appUpdate')}
{t('appUpdateDesc')}
{update?.update_available ? (
{t('newVersionAvailable')}
) : update ? (
{t('alreadyLatest')}
) : null}
{updateQuery.isLoading ? (
) : updateQuery.isError ? (
{updateQuery.error.message || t('cannotGetVersion')}
) : update ? (
<>
{update.build_time && (
)}
{update.release_notes && (
{t('releaseNotes')}
{update.release_notes}
)}
{update.release_url && (
)}
{t('upgradeTo', { version: update.latest_version })}
{t('upgradeDesc', { asset: update.asset_name })}
{t('cancel')}
applyUpdateMutation.mutate()}
>
{t('confirmUpgrade')}
{!update.can_upgrade && (
{update.current_version === 'dev'
? t('devBuildNoUpgrade')
: update.update_available
? t('platformNotSupported')
: t('noUpgradeNeeded')}
)}
>
) : null}
);
}