import { useMutation } from "@tanstack/react-query"; import { useState } from "react"; import { toast } from "sonner"; import { Card } from "~/components/ui/card"; import { Button } from "~/components/ui/button"; import { AlertDialog, AlertDialogContent, AlertDialogDescription, AlertDialogHeader, AlertDialogTitle, } from "~/components/ui/alert-dialog"; import { Loader2 } from "lucide-react"; import type { Repository } from "~/lib/types"; import { parseError } from "~/lib/errors"; import { doctorRepositoryMutation } from "~/api-client/@tanstack/react-query.gen"; import { cn } from "~/lib/utils"; type Props = { repository: Repository; }; export const RepositoryInfoTabContent = ({ repository }: Props) => { const [showDoctorResults, setShowDoctorResults] = useState(false); const doctorMutation = useMutation({ ...doctorRepositoryMutation(), onSuccess: (data) => { if (data) { setShowDoctorResults(true); if (data.success) { toast.success("Repository doctor completed successfully"); } else { toast.warning("Doctor completed with some issues", { description: "Check the details for more information", richColors: true, }); } } }, onError: (error) => { toast.error("Failed to run doctor", { description: parseError(error)?.message, }); }, }); const handleDoctor = () => { doctorMutation.mutate({ path: { name: repository.name } }); }; const getStepLabel = (step: string) => { switch (step) { case "unlock": return "Unlock Repository"; case "check": return "Check Repository"; case "repair_index": return "Repair Index"; case "recheck": return "Re-check Repository"; default: return step; } }; return ( <>

Repository Information

Name

{repository.name}

Backend

{repository.type}

Compression Mode

{repository.compressionMode || "off"}

Status

{repository.status || "unknown"}

Created At

{new Date(repository.createdAt).toLocaleString()}

Last Checked

{repository.lastChecked ? new Date(repository.lastChecked).toLocaleString() : "Never"}

{repository.lastError && (

Last Error

{repository.lastError}

)}

Configuration

{JSON.stringify(repository.config, null, 2)}
Doctor Results {doctorMutation.data?.message || "Repository doctor operation completed"} {doctorMutation.data && (
{doctorMutation.data.steps.map((step) => (
{getStepLabel(step.step)} {step.success ? "Success" : "Warning"}
{step.error &&

{step.error}

}
))}
)}
); };