feat: database management - auto/USB backup toggles, folder browser, cron jobs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import {
|
||||
Database,
|
||||
@@ -75,6 +76,40 @@ export default function DatabaseManagementPage() {
|
||||
}
|
||||
}
|
||||
|
||||
// ----- Auto backup setting query -----
|
||||
const { data: autoBackupData } = useQuery({
|
||||
queryKey: ["/db/auto-backup-setting"],
|
||||
queryFn: async () => {
|
||||
const res = await apiRequest("GET", "/api/database-management/auto-backup-setting");
|
||||
return res.json();
|
||||
},
|
||||
});
|
||||
|
||||
const autoBackupEnabled = autoBackupData?.autoBackupEnabled ?? true;
|
||||
|
||||
const autoBackupMutation = useMutation({
|
||||
mutationFn: async (enabled: boolean) => {
|
||||
const res = await apiRequest("PUT", "/api/database-management/auto-backup-setting", {
|
||||
autoBackupEnabled: enabled,
|
||||
});
|
||||
return res.json();
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
queryClient.setQueryData(["/db/auto-backup-setting"], data);
|
||||
toast({
|
||||
title: "Setting Saved",
|
||||
description: `Automatic backup ${data.autoBackupEnabled ? "enabled" : "disabled"}.`,
|
||||
});
|
||||
},
|
||||
onError: () => {
|
||||
toast({
|
||||
title: "Error",
|
||||
description: "Failed to update automatic backup setting.",
|
||||
variant: "destructive",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// ----- Backup mutation -----
|
||||
const backupMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
@@ -178,6 +213,22 @@ export default function DatabaseManagementPage() {
|
||||
including patients, appointments, claims, and all related data.
|
||||
</p>
|
||||
|
||||
<div className="flex items-center space-x-3">
|
||||
<Switch
|
||||
id="auto-backup-toggle"
|
||||
checked={autoBackupEnabled}
|
||||
onCheckedChange={(checked) => autoBackupMutation.mutate(checked)}
|
||||
disabled={autoBackupMutation.isPending}
|
||||
/>
|
||||
<label
|
||||
htmlFor="auto-backup-toggle"
|
||||
className="text-sm font-medium text-gray-700 cursor-pointer select-none"
|
||||
>
|
||||
Automatic Backup
|
||||
</label>
|
||||
<span className="text-xs text-gray-400">(daily at 8 PM to server backup folder)</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center space-x-4">
|
||||
<Button
|
||||
onClick={() => backupMutation.mutate()}
|
||||
|
||||
Reference in New Issue
Block a user