import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useNavigate, useParams, useSearchParams } from "react-router"; import { toast } from "sonner"; import { deleteRepositoryMutation, getRepositoryOptions, listSnapshotsOptions, } from "~/api-client/@tanstack/react-query.gen"; import { Button } from "~/components/ui/button"; 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"; import { useEffect } from "react"; export function meta({ params }: Route.MetaArgs) { return [ { title: `Ironmount - ${params.name}` }, { name: "description", content: "Manage your restic backup repositories with ease.", }, ]; } 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 [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 handleDeleteConfirm = (name: string) => { if ( confirm( `Are you sure you want to delete the repository "${name}"? This action cannot be undone and will remove all backup data.`, ) ) { deleteRepo.mutate({ path: { name } }); } }; if (!name) { return
Repository not found
; } if (!data) { return
Loading...
; } const { repository } = data; return ( <>
{repository.status || "unknown"} {repository.type}
setSearchParams({ tab: value })}> Configuration Snapshots ); }