mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on the hidde restore action if already a restauration is waiting.
This commit is contained in:
@@ -13,7 +13,12 @@ import {Button} from "@/components/ui/button";
|
||||
import {Download, MoreHorizontal, Trash2} from "lucide-react";
|
||||
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 {createRestaurationAction} from "@/features/restore/restore.action";
|
||||
import {toast} from "sonner";
|
||||
import {useRouter} from "next/navigation";
|
||||
import {TooltipCustom} from "@/components/wrappers/TooltipCustom/TooltipCustom";
|
||||
|
||||
|
||||
export const backupColumns: ColumnDef<Backup>[] = [
|
||||
@@ -37,7 +42,41 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
cell: ({row}) => {
|
||||
cell: ({row, table}) => {
|
||||
const status = row.getValue("status")
|
||||
const rowData: Backup = row.original
|
||||
const fileName = rowData.file
|
||||
// @ts-ignore
|
||||
const {extendedProps} = table.options.meta;
|
||||
|
||||
|
||||
const isRestauring = !!rowData.restaurations.find(restauration => restauration.status === "waiting");
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const handleDownload = async (fileName: string) => {
|
||||
const url = await getFileUrlPresignedLocal(fileName)
|
||||
window.open(url, '_self');
|
||||
}
|
||||
|
||||
|
||||
const mutationRestore = useMutation({
|
||||
mutationFn: async () => {
|
||||
const restauration = await createRestaurationAction({
|
||||
backupId: rowData.id,
|
||||
databaseId: rowData.databaseId
|
||||
})
|
||||
if (restauration.data.success) {
|
||||
toast.success(restauration.data.actionSuccess?.message || "Restauration created successfully!");
|
||||
router.refresh()
|
||||
} else {
|
||||
toast.error(restauration.serverError || "Failed to create restauration.");
|
||||
}
|
||||
}})
|
||||
|
||||
const handleRestore = async () => {
|
||||
await mutationRestore.mutateAsync()
|
||||
}
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
@@ -49,24 +88,28 @@ export const backupColumns: ColumnDef<Backup>[] = [
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||
|
||||
<DropdownMenuItem onClick={() => {
|
||||
}}>
|
||||
<ReloadIcon/> Restore
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem onClick={() => {
|
||||
}}>
|
||||
<Download/> Download
|
||||
</DropdownMenuItem>
|
||||
|
||||
{status == "success" ?
|
||||
<>
|
||||
<TooltipCustom disabled={extendedProps} text="Already a restauration waiting">
|
||||
<DropdownMenuItem disabled={mutationRestore.isPending || extendedProps}
|
||||
onClick={async () => {
|
||||
await handleRestore()
|
||||
}}>
|
||||
<ReloadIcon/> Restore
|
||||
</DropdownMenuItem>
|
||||
</TooltipCustom>
|
||||
<DropdownMenuItem onClick={async () => {
|
||||
await handleDownload(fileName)
|
||||
}}>
|
||||
<Download/> Download
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
: null}
|
||||
<DropdownMenuSeparator/>
|
||||
|
||||
<DropdownMenuItem className="text-red-600" onClick={() => {
|
||||
}}>
|
||||
<Trash2/> Delete
|
||||
</DropdownMenuItem>
|
||||
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user