2025-05-16 15:54:17 +02:00
|
|
|
"use client";
|
2024-12-14 17:54:03 +01:00
|
|
|
|
2025-05-16 15:54:17 +02:00
|
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { eventUpdate } from "@/types/events";
|
|
|
|
|
import { backupColumns } from "@/features/dashboard/backup/columns";
|
|
|
|
|
import { restoreColumns } from "@/features/dashboard/restore/columns";
|
|
|
|
|
import { DataTable } from "@/components/wrappers/common/table/data-table";
|
2025-07-16 12:36:11 +02:00
|
|
|
import {Backup, Database, Restoration} from "@/db/schema/06_database";
|
2024-12-01 20:56:19 +01:00
|
|
|
|
|
|
|
|
export type DatabaseTabsProps = {
|
2025-05-16 15:54:17 +02:00
|
|
|
backups: Backup[];
|
|
|
|
|
restorations: Restoration[];
|
|
|
|
|
isAlreadyRestore: boolean;
|
|
|
|
|
database: Database;
|
|
|
|
|
};
|
2024-12-01 20:56:19 +01:00
|
|
|
|
|
|
|
|
export const DatabaseTabs = (props: DatabaseTabsProps) => {
|
2024-12-14 17:49:50 +01:00
|
|
|
const router = useRouter();
|
|
|
|
|
useEffect(() => {
|
2025-05-16 15:54:17 +02:00
|
|
|
const eventSource = new EventSource("/api/events");
|
2024-12-14 17:49:50 +01:00
|
|
|
|
2025-05-16 15:54:17 +02:00
|
|
|
eventSource.addEventListener("modification", (event) => {
|
|
|
|
|
const data: eventUpdate = JSON.parse(event.data);
|
2024-12-14 17:54:03 +01:00
|
|
|
if (data.update) {
|
2025-05-16 15:54:17 +02:00
|
|
|
router.refresh();
|
2024-12-14 17:49:50 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
eventSource.close();
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
2024-12-01 20:56:19 +01:00
|
|
|
return (
|
|
|
|
|
<Tabs className="flex flex-col flex-1" defaultValue="backup">
|
|
|
|
|
<TabsList className="grid w-full grid-cols-2">
|
|
|
|
|
<TabsTrigger value="backup">Backup</TabsTrigger>
|
|
|
|
|
<TabsTrigger value="restore">Restoration</TabsTrigger>
|
|
|
|
|
</TabsList>
|
|
|
|
|
|
|
|
|
|
<TabsContent className="h-full justify-between" value="backup">
|
2025-07-16 20:16:18 +02:00
|
|
|
|
|
|
|
|
{/*<DataTable columns={backupColumns} data={props.backups} extendedProps={props.isAlreadyRestore} />*/}
|
|
|
|
|
<DataTable columns={backupColumns(props.isAlreadyRestore)} data={props.backups} enablePagination />
|
2024-12-01 20:56:19 +01:00
|
|
|
</TabsContent>
|
|
|
|
|
|
2024-12-10 11:22:36 +01:00
|
|
|
<TabsContent className="h-full justify-between" value="restore">
|
2025-05-16 15:54:17 +02:00
|
|
|
<DataTable columns={restoreColumns} data={props.restorations} enablePagination />
|
2024-12-10 11:22:36 +01:00
|
|
|
</TabsContent>
|
2024-12-01 20:56:19 +01:00
|
|
|
</Tabs>
|
2025-05-16 15:54:17 +02:00
|
|
|
);
|
|
|
|
|
};
|