/** * SettingsBackup page — Backup & Restore management with automation config. * * Features: * - Backup automation config (enabled, interval, retention, destination) * - "Backup jetzt" button (POST /backup-now) * - List of backups: date, size, status badge, restore/delete buttons * - Backup history (last 10 backup results from audit log) * - Restore dialog with warning text + type "RESTORE" to confirm * - Auto-refresh when backup is pending */ import React, { useState, useCallback, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import clsx from 'clsx'; import { Plus, Download, Trash2, AlertTriangle, HardDrive, CheckCircle, XCircle, Clock, Settings, Play, History, Save, } from 'lucide-react'; import { useBackups, useCreateBackup, useRestoreBackup, useDeleteBackup, useBackupConfig, useUpdateBackupConfig, useTriggerBackupNow, useBackupHistory, type Backup, type BackupConfig, type BackupHistoryEntry, } from '@/api/backups'; import { Card } from '@/components/ui/Card'; import { Button } from '@/components/ui/Button'; import { Modal } from '@/components/ui/Modal'; // ─── Helpers ──────────────────────────────────────────────────────────────── function formatFileSize(bytes: number | null): string { if (bytes === null || bytes === undefined) return '—'; if (bytes === 0) return '0 B'; const units = ['B', 'KB', 'MB', 'GB']; let size = bytes; let unitIndex = 0; while (size >= 1024 && unitIndex < units.length - 1) { size /= 1024; unitIndex++; } return `${size.toFixed(1)} ${units[unitIndex]}`; } function formatDate(dateStr: string | null): string { if (!dateStr) return '—'; const d = new Date(dateStr); return d.toLocaleString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', }); } function StatusBadge({ status }: { status: string }) { const { t } = useTranslation(); const config: Record = { pending: { icon: