2025-05-16 15:54:17 +02:00
|
|
|
"use client";
|
2024-12-14 17:54:03 +01:00
|
|
|
|
2025-08-03 12:17:10 +02:00
|
|
|
import {Tabs, TabsContent, TabsList, TabsTrigger} from "@/components/ui/tabs";
|
|
|
|
|
import {useEffect, useState} from "react";
|
|
|
|
|
import {useRouter, useSearchParams} from "next/navigation";
|
|
|
|
|
import {eventUpdate} from "@/types/events";
|
2025-08-29 15:31:23 +02:00
|
|
|
import {Backup, Database, DatabaseWith, Restoration} from "@/db/schema/07_database";
|
|
|
|
|
import {Setting} from "@/db/schema/01_setting";
|
2025-09-22 20:31:29 +02:00
|
|
|
import {DatabaseBackupList} from "@/components/wrappers/dashboard/projects/database/database-backup-list";
|
|
|
|
|
import {DatabaseRestoreList} from "@/components/wrappers/dashboard/projects/database/database-restore-list";
|
2025-11-01 14:50:08 +01:00
|
|
|
import {MemberWithUser} from "@/db/schema/03_organization";
|
2024-12-01 20:56:19 +01:00
|
|
|
|
|
|
|
|
export type DatabaseTabsProps = {
|
2025-11-01 14:50:08 +01:00
|
|
|
settings: Setting,
|
|
|
|
|
backups: Backup[],
|
|
|
|
|
restorations: Restoration[],
|
|
|
|
|
isAlreadyRestore: boolean,
|
|
|
|
|
database: DatabaseWith,
|
|
|
|
|
activeMember: MemberWithUser
|
2025-05-16 15:54:17 +02:00
|
|
|
};
|
2024-12-01 20:56:19 +01:00
|
|
|
|
|
|
|
|
export const DatabaseTabs = (props: DatabaseTabsProps) => {
|
2024-12-14 17:49:50 +01:00
|
|
|
const router = useRouter();
|
2025-08-03 12:17:10 +02:00
|
|
|
const searchParams = useSearchParams();
|
|
|
|
|
|
|
|
|
|
const [tab, setTab] = useState<string>(() => searchParams.get("tab") ?? "backup");
|
|
|
|
|
|
2024-12-14 17:49:50 +01:00
|
|
|
useEffect(() => {
|
2025-05-16 15:54:17 +02:00
|
|
|
const eventSource = new EventSource("/api/events");
|
|
|
|
|
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();
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
2025-08-03 12:17:10 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
const newTab = searchParams.get("tab") ?? "backup";
|
|
|
|
|
setTab(newTab);
|
|
|
|
|
}, [searchParams]);
|
|
|
|
|
|
|
|
|
|
const handleChangeTab = (value: string) => {
|
|
|
|
|
router.push(`?tab=${value}`);
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-01 20:56:19 +01:00
|
|
|
return (
|
2025-08-03 12:17:10 +02:00
|
|
|
<Tabs className="flex flex-col flex-1" value={tab} onValueChange={handleChangeTab}>
|
2024-12-01 20:56:19 +01:00
|
|
|
<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-09-22 20:31:29 +02:00
|
|
|
<DatabaseBackupList
|
|
|
|
|
isAlreadyRestore={props.isAlreadyRestore}
|
|
|
|
|
settings={props.settings}
|
|
|
|
|
database={props.database}
|
|
|
|
|
backups={props.backups}
|
2025-11-01 14:50:08 +01:00
|
|
|
activeMember={props.activeMember}
|
2025-08-03 12:17:10 +02:00
|
|
|
/>
|
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-09-22 20:31:29 +02:00
|
|
|
<DatabaseRestoreList
|
|
|
|
|
isAlreadyRestore={props.isAlreadyRestore}
|
|
|
|
|
restorations={props.restorations}
|
2025-11-01 14:50:08 +01:00
|
|
|
activeMember={props.activeMember}
|
2025-08-03 12:17:10 +02:00
|
|
|
/>
|
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
|
|
|
);
|
|
|
|
|
};
|