import LoadingButton from '@/components/loading-button'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { router, useForm } from '@inertiajs/react'; import { AlertTriangle, Calendar, Download, HardDrive, RefreshCw, RotateCcw, Trash2 } from 'lucide-react'; import { useState } from 'react'; import BackupDownloader from './backgup-downloader'; interface Props { recentBackups: ApplicationBackup[]; } const ApplicationBackupList = ({ recentBackups }: Props) => { // Dialog state management const [isProcessing, setIsProcessing] = useState(false); const [showDeleteDialog, setShowDeleteDialog] = useState(false); const [showRestoreDialog, setShowRestoreDialog] = useState(false); const [selectedBackup, setSelectedBackup] = useState(null); const refreshForm = useForm({}); const handleRefreshServer = () => { refreshForm.post(route('system.refresh')); }; const handleDeleteClick = (backup: ApplicationBackup) => { setSelectedBackup(backup); setShowDeleteDialog(true); }; const handleRestoreClick = (backup: ApplicationBackup) => { setSelectedBackup(backup); setShowRestoreDialog(true); }; const { delete: deleteBackup, processing: deleteProcessing } = useForm({}); const handleConfirmDelete = (e: React.FormEvent) => { if (!selectedBackup) return; setIsProcessing(true); deleteBackup(route('system.backup.delete', selectedBackup.id), { onSuccess: () => { setShowDeleteDialog(false); setSelectedBackup(null); setIsProcessing(false); }, onError: () => { setIsProcessing(false); }, }); }; const handleConfirmRestore = () => { if (!selectedBackup) return; setIsProcessing(true); router.post( route('system.backup.restore', selectedBackup.id), {}, { onSuccess: () => { setShowRestoreDialog(false); setSelectedBackup(null); setIsProcessing(false); }, onError: () => { setIsProcessing(false); }, }, ); }; const handleCancelDialog = () => { if (!isProcessing) { setShowDeleteDialog(false); setShowRestoreDialog(false); setSelectedBackup(null); } }; const formatFileSize = (bytes: number) => { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }; const formatDate = (dateString: string) => { return new Date(dateString).toLocaleString(); }; return ( <> {/* Delete Confirmation Dialog */} { if (!isProcessing) { setShowDeleteDialog(open); if (!open) setSelectedBackup(null); } }} > { if (isProcessing) e.preventDefault(); }} onEscapeKeyDown={(e) => { if (isProcessing) e.preventDefault(); }} > {isProcessing && (

Deleting backup...

Please wait

)} Delete Backup

Are you sure you want to delete the backup "{selectedBackup?.backup_name}"?

⚠️ This action will:

  • Permanently delete the backup files from storage
  • Remove the backup record from the database
  • Cannot be undone or recovered

Backup Details:
Source Code: {selectedBackup ? formatFileSize(selectedBackup.source_code_size) : ''}
Database: {selectedBackup ? formatFileSize(selectedBackup.database_size) : ''}
Created: {selectedBackup ? formatDate(selectedBackup.created_at) : ''}

{/* Restore Confirmation Dialog */} { if (!isProcessing) { setShowRestoreDialog(open); if (!open) setSelectedBackup(null); } }} > { if (isProcessing) e.preventDefault(); }} onEscapeKeyDown={(e) => { if (isProcessing) e.preventDefault(); }} > {isProcessing && (

Restoring backup...

Please do not close this window

)} Restore Backup

Are you sure you want to restore the backup "{selectedBackup?.backup_name}"?

This restore will:

  • Put the site in maintenance mode
  • Overwrite all current application files
  • Replace the entire database with backup data
  • Process may take several minutes

⚠️ Critical Warning:

All current data and files will be lost! Make sure you have a recent backup of your current state if needed. This action cannot be undone.

Backup Details:
Created: {selectedBackup ? formatDate(selectedBackup.created_at) : ''}
Source Code: {selectedBackup ? formatFileSize(selectedBackup.source_code_size) : ''}
Database: {selectedBackup ? formatFileSize(selectedBackup.database_size) : ''}
Status: {selectedBackup?.status || ''}

Recent Backups

View and manage your recent application backups

Important Update Guidelines

  • Refresh Server: Every time refresh server before updating
{recentBackups && recentBackups.length > 0 ? (
{recentBackups.map((backup) => (
{backup.backup_name}
{backup.status}
{formatDate(backup.created_at)}
Source: {formatFileSize(backup.source_code_size)}
Database: {formatFileSize(backup.database_size)}
{backup.notes && (
Notes: {backup.notes}
)}
Refresh
))}
) : (

No recent backups found.

Create your first backup using the form above.

)}
); }; export default ApplicationBackupList;