import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useNavigate, useParams, useSearchParams } from "react-router"; import { toast } from "sonner"; import { useState, useEffect } from "react"; import { deleteRepositoryMutation, getRepositoryOptions, listSnapshotsOptions, } from "~/api-client/@tanstack/react-query.gen"; import { Button } from "~/components/ui/button"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogHeader, AlertDialogTitle, } from "~/components/ui/alert-dialog"; import { parseError } from "~/lib/errors"; import { getRepository } from "~/api-client/sdk.gen"; import type { Route } from "./+types/repository-details"; import { cn } from "~/lib/utils"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs"; import { RepositoryInfoTabContent } from "../tabs/info"; import { RepositorySnapshotsTabContent } from "../tabs/snapshots"; export function meta({ params }: Route.MetaArgs) { return [ { title: params.name }, { name: "description", content: "View repository configuration, status, and snapshots.", }, ]; } export const clientLoader = async ({ params }: Route.ClientLoaderArgs) => { const repository = await getRepository({ path: { name: params.name ?? "" } }); if (repository.data) return repository.data; }; export default function RepositoryDetailsPage({ loaderData }: Route.ComponentProps) { const { name } = useParams<{ name: string }>(); const navigate = useNavigate(); const queryClient = useQueryClient(); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const [searchParams, setSearchParams] = useSearchParams(); const activeTab = searchParams.get("tab") || "info"; const { data } = useQuery({ ...getRepositoryOptions({ path: { name: name ?? "" } }), initialData: loaderData, refetchInterval: 10000, refetchOnWindowFocus: true, }); useEffect(() => { if (name) { queryClient.prefetchQuery(listSnapshotsOptions({ path: { name } })); } }, [name, queryClient]); const deleteRepo = useMutation({ ...deleteRepositoryMutation(), onSuccess: () => { toast.success("Repository deleted successfully"); navigate("/repositories"); }, onError: (error) => { toast.error("Failed to delete repository", { description: parseError(error)?.message, }); }, }); const handleConfirmDelete = () => { setShowDeleteConfirm(false); deleteRepo.mutate({ path: { name: name ?? "" } }); }; if (!name) { return
Repository not found
; } if (!data) { return
Loading...
; } return ( <>
{data.status || "unknown"} {data.type}
setSearchParams({ tab: value })}> Configuration Snapshots Delete repository? Are you sure you want to delete the repository {name}? This action cannot be undone and will remove all backup data.
Cancel Delete repository
); }