import { useMutation, useQuery } from "@tanstack/react-query"; import { useNavigate, useParams } from "react-router"; import { toast } from "sonner"; import { deleteRepositoryMutation, getRepositoryOptions } from "~/api-client/@tanstack/react-query.gen"; import { Button } from "~/components/ui/button"; import { Card } from "~/components/ui/card"; import { parseError } from "~/lib/errors"; import { getRepository } from "~/api-client/sdk.gen"; import type { Route } from "./+types/repository-details"; import { cn } from "~/lib/utils"; 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 { data } = useQuery({ ...getRepositoryOptions({ path: { name: name ?? "" } }), initialData: loaderData, refetchInterval: 10000, refetchOnWindowFocus: true, }); 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.name}
{repository.type}
{repository.compressionMode || "off"}
{repository.status || "unknown"}
{new Date(repository.createdAt).toLocaleString()}
{repository.lastChecked ? new Date(repository.lastChecked).toLocaleString() : "Never"}
{repository.lastError}
{JSON.stringify(repository.config, null, 2)}