"use client"; import { useCallback, useEffect, useState } from "react"; import { Database, Download, HardDrive, RefreshCw } from "lucide-react"; import { Card } from "@/components/ui/Card"; import { Button } from "@/components/ui/Button"; import { ErrorBanner } from "@/components/ui/ErrorBanner"; import { FullScreenLoader } from "@/components/ui/FullScreenLoader"; import { useToast } from "@/components/ui/Toast"; import { formatApiError } from "@/lib/hooks"; import { BackupInfo, listBackups, createBackup, downloadBackup } from "@/lib/api"; function formatSize(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } export default function BackupsPage() { const toast = useToast(); const [backups, setBackups] = useState(null); const [error, setError] = useState(null); const [creating, setCreating] = useState(false); const [downloadingFile, setDownloadingFile] = useState(null); const load = useCallback(async () => { try { setBackups(await listBackups()); setError(null); } catch (err) { setError(formatApiError(err)); } }, []); useEffect(() => { // eslint-disable-next-line react-hooks/set-state-in-effect load(); }, [load]); async function handleCreate() { setCreating(true); try { await createBackup(); toast.showSuccess("بک‌آپ جدید با موفقیت ساخته شد"); await load(); } catch (err) { toast.showError(formatApiError(err)); } finally { setCreating(false); } } async function handleDownload(filename: string) { setDownloadingFile(filename); try { await downloadBackup(filename); } catch (err) { toast.showError(formatApiError(err)); } finally { setDownloadingFile(null); } } if (!backups && !error) return ; return (

بک‌آپ دیتابیس 💾

یک نسخه‌ی کامل و فشرده از دیتابیس بگیر یا نسخه‌های قبلی رو دانلود کن.

{error && } {!backups || backups.length === 0 ? (

هنوز هیچ بک‌آپی گرفته نشده

با دکمه‌ی «ساخت بک‌آپ جدید» اولین نسخه رو بگیر.

) : (
{backups.map((b) => (

{b.filename}

{new Date(b.created_at).toLocaleString("fa-IR")} · {formatSize(b.size_bytes)}

))}
)}
); }