mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
delete backup.
This commit is contained in:
@@ -14,7 +14,7 @@ import {ReloadIcon} from "@radix-ui/react-icons";
|
||||
import {Backup} from "@prisma/client";
|
||||
import {getFileUrlPresignedLocal} from "@/features/upload/private/upload.action";
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
import {createRestorationAction} from "@/features/dashboard/restore/restore.action";
|
||||
import {createRestorationAction, deleteBackupAction} from "@/features/dashboard/restore/restore.action";
|
||||
import {toast} from "sonner";
|
||||
import {useRouter} from "next/navigation";
|
||||
import {StatusBadge} from "@/components/wrappers/common/status-badge";
|
||||
@@ -49,16 +49,8 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
||||
// @ts-ignore
|
||||
const {extendedProps} = table.options.meta;
|
||||
|
||||
|
||||
// const isRestoring = !!rowData.restorations.find(restoration => restoration.status === "waiting");
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const handleDownload = async (fileName: string) => {
|
||||
const url = await getFileUrlPresignedLocal(fileName)
|
||||
window.open(url, '_self');
|
||||
}
|
||||
|
||||
|
||||
const mutationRestore = useMutation({
|
||||
mutationFn: async () => {
|
||||
@@ -74,10 +66,34 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
||||
}
|
||||
}})
|
||||
|
||||
const mutationDeleteBackup = useMutation({
|
||||
mutationFn: async () => {
|
||||
const restoration = await deleteBackupAction({
|
||||
backupId: rowData.id,
|
||||
databaseId: rowData.databaseId
|
||||
})
|
||||
if (restoration.data.success) {
|
||||
toast.success(restoration.data.actionSuccess.message);
|
||||
router.refresh()
|
||||
} else {
|
||||
toast.error(restoration.data.actionError.message);
|
||||
}
|
||||
}})
|
||||
|
||||
const handleRestore = async () => {
|
||||
await mutationRestore.mutateAsync()
|
||||
}
|
||||
|
||||
const handleDelete = async () => {
|
||||
await mutationDeleteBackup.mutateAsync()
|
||||
}
|
||||
|
||||
const handleDownload = async (fileName: string) => {
|
||||
const url = await getFileUrlPresignedLocal(fileName)
|
||||
window.open(url, '_self');
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -106,7 +122,8 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
||||
</>
|
||||
: null}
|
||||
<DropdownMenuSeparator/>
|
||||
<DropdownMenuItem className="text-red-600" onClick={() => {
|
||||
<DropdownMenuItem className="text-red-600" onClick={async () => {
|
||||
await handleDelete()
|
||||
}}>
|
||||
<Trash2/> Delete
|
||||
</DropdownMenuItem>
|
||||
|
||||
@@ -4,7 +4,47 @@ import {userAction} from "@/safe-actions";
|
||||
import {z} from "zod";
|
||||
import {prisma} from "@/prisma";
|
||||
import {ServerActionResult} from "@/types/action-type";
|
||||
import {Restoration} from "@prisma/client";
|
||||
import {Backup, Restoration} from "@prisma/client";
|
||||
|
||||
|
||||
export const deleteBackupAction = userAction
|
||||
.schema(z.object({
|
||||
backupId: z.string(),
|
||||
databaseId: z.string(),
|
||||
}))
|
||||
.action(async ({parsedInput, ctx}): Promise<ServerActionResult<Backup>> => {
|
||||
|
||||
try {
|
||||
const backupDeleted = await prisma.backup.delete({
|
||||
where:{
|
||||
databaseId: parsedInput.databaseId,
|
||||
id: parsedInput.backupId
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
value: backupDeleted,
|
||||
actionSuccess: {
|
||||
message: "Backup has been successfully deleted.",
|
||||
messageParams: {message: "success"},
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error deleting backup:", error);
|
||||
return {
|
||||
success: false,
|
||||
actionError: {
|
||||
message: "Failed to delete backup.",
|
||||
status: 500,
|
||||
cause: error instanceof Error ? error.message : "Unknown error",
|
||||
messageParams: {message: "Error deleting the backup"},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
export const createRestorationAction = userAction
|
||||
@@ -28,7 +68,7 @@ export const createRestorationAction = userAction
|
||||
value: restoration,
|
||||
actionSuccess: {
|
||||
message: "Restoration has been successfully created.",
|
||||
messageParams: { restorationId: restoration.id },
|
||||
messageParams: {restorationId: restoration.id},
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -39,11 +79,10 @@ export const createRestorationAction = userAction
|
||||
message: "Failed to create backup.",
|
||||
status: 500,
|
||||
cause: error instanceof Error ? error.message : "Unknown error",
|
||||
messageParams: { message: "Error creating the restoration" },
|
||||
messageParams: {message: "Error creating the restoration"},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user