mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Add button to control automatic backup settings
Add a toggle button to the UI and corresponding backend logic to enable/disable automatic database backups. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 1e4433b5-47ab-464c-b663-fea2e53367dd Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: 7c778f43-d69d-489c-a2a9-3e95d35cce43 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/1e4433b5-47ab-464c-b663-fea2e53367dd/7RN8LqE
This commit is contained in:
1 parent
21f0895125
commit
43ca5d617a
3 files changed
+99
-3749
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -3,6 +3,8 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { useAuthUnified } from "@/hooks/useAuthUnified";
|
||||
import { apiRequest } from "@/lib/queryClient";
|
||||
@@ -16,7 +18,8 @@ import {
|
||||
FileText,
|
||||
AlertTriangle,
|
||||
CheckCircle,
|
||||
Loader2
|
||||
Loader2,
|
||||
Settings
|
||||
} from "lucide-react";
|
||||
import { format } from "date-fns";
|
||||
import { fr } from "date-fns/locale";
|
||||
@@ -33,6 +36,14 @@ interface BackupFile {
|
||||
backupType: string;
|
||||
}
|
||||
|
||||
interface UtilitiesConfig {
|
||||
id?: number;
|
||||
salesAnalysisUrl?: string | null;
|
||||
automaticBackupsEnabled?: boolean;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
||||
export default function BackupManager() {
|
||||
const { user } = useAuthUnified();
|
||||
const { toast } = useToast();
|
||||
@@ -50,6 +61,34 @@ export default function BackupManager() {
|
||||
refetchInterval: 30000, // Refresh every 30 seconds
|
||||
});
|
||||
|
||||
// Fetch utilities configuration
|
||||
const { data: config } = useQuery<UtilitiesConfig>({
|
||||
queryKey: ['/api/utilities'],
|
||||
enabled: canManageBackups,
|
||||
});
|
||||
|
||||
// Toggle automatic backups
|
||||
const toggleAutomaticBackupsMutation = useMutation({
|
||||
mutationFn: (enabled: boolean) =>
|
||||
apiRequest('/api/utilities', 'POST', { automaticBackupsEnabled: enabled }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/utilities'] });
|
||||
toast({
|
||||
title: "Configuration mise à jour",
|
||||
description: config?.automaticBackupsEnabled
|
||||
? "Sauvegardes automatiques désactivées"
|
||||
: "Sauvegardes automatiques activées",
|
||||
});
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast({
|
||||
title: "Erreur",
|
||||
description: error.message || "Impossible de mettre à jour la configuration",
|
||||
variant: "destructive",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// Create manual backup
|
||||
const createBackupMutation = useMutation({
|
||||
mutationFn: () => apiRequest('/api/backups', 'POST'),
|
||||
@@ -185,6 +224,40 @@ export default function BackupManager() {
|
||||
|
||||
{/* Content */}
|
||||
<div className="flex-1 p-6 overflow-auto">
|
||||
{/* Configuration des backups automatiques */}
|
||||
<Card className="mb-6">
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Settings className="w-5 h-5" />
|
||||
Configuration des Sauvegardes Automatiques
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Activez ou désactivez les sauvegardes automatiques quotidiennes à 2h00
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="automatic-backups" className="text-base font-medium">
|
||||
Sauvegardes automatiques
|
||||
</Label>
|
||||
<p className="text-sm text-gray-600">
|
||||
{config?.automaticBackupsEnabled === false
|
||||
? "Les sauvegardes automatiques sont actuellement désactivées"
|
||||
: "Les sauvegardes automatiques sont actives"}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="automatic-backups"
|
||||
checked={config?.automaticBackupsEnabled !== false}
|
||||
onCheckedChange={(checked) => toggleAutomaticBackupsMutation.mutate(checked)}
|
||||
disabled={toggleAutomaticBackupsMutation.isPending}
|
||||
data-testid="switch-automatic-backups"
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Status Cards */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
|
||||
<Card>
|
||||
@@ -228,12 +301,20 @@ export default function BackupManager() {
|
||||
<CardTitle className="text-sm font-medium">
|
||||
Statut Système
|
||||
</CardTitle>
|
||||
<CheckCircle className="h-4 w-4 text-green-500" />
|
||||
{config?.automaticBackupsEnabled !== false ? (
|
||||
<CheckCircle className="h-4 w-4 text-green-500" />
|
||||
) : (
|
||||
<AlertTriangle className="h-4 w-4 text-orange-500" />
|
||||
)}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold text-green-600">Actif</div>
|
||||
<div className={`text-2xl font-bold ${config?.automaticBackupsEnabled !== false ? 'text-green-600' : 'text-orange-600'}`}>
|
||||
{config?.automaticBackupsEnabled !== false ? 'Actif' : 'Désactivé'}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Sauvegarde automatique 2h00
|
||||
{config?.automaticBackupsEnabled !== false
|
||||
? 'Sauvegarde automatique 2h00'
|
||||
: 'Backups automatiques désactivés'}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -214,6 +214,20 @@ export class BackupService {
|
||||
// Nouvelle méthode : Vérifier et effectuer une sauvegarde quotidienne si nécessaire
|
||||
async checkAndPerformDailyBackup(userId: string = 'system'): Promise<{ backupPerformed: boolean; message: string }> {
|
||||
try {
|
||||
// Vérifier si les backups automatiques sont activés
|
||||
const [config] = await db.select()
|
||||
.from(utilities)
|
||||
.limit(1);
|
||||
|
||||
// Si les backups automatiques sont désactivés, ne rien faire
|
||||
if (config && config.automaticBackupsEnabled === false) {
|
||||
console.log('ℹ️ Sauvegardes automatiques désactivées - Aucune action effectuée');
|
||||
return {
|
||||
backupPerformed: false,
|
||||
message: 'Sauvegardes automatiques désactivées'
|
||||
};
|
||||
}
|
||||
|
||||
const today = new Date().toISOString().split('T')[0]; // Format YYYY-MM-DD
|
||||
|
||||
// Vérifier s'il y a déjà une sauvegarde automatique aujourd'hui
|
||||
|
||||
Reference in new issue
Block a user