import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { toast } from "sonner"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Spinner } from "@/components/common/spinner"; import { ConfirmDialog } from "@/components/common/confirm-dialog"; import { CopyButton } from "@/components/common/copy-button"; import { ApiError } from "@/lib/api"; import type { Visibility } from "@/lib/api/types"; import { formatDate } from "@/lib/utils"; import { useRepoContext } from "../repo-context"; import { useUpdateRepository, useDeleteRepository } from "../repos-hooks"; type DeleteHook = ReturnType; export function RepoOverview({ onDelete }: { onDelete: DeleteHook }) { const { repo, canManage } = useRepoContext(); const navigate = useNavigate(); const [editOpen, setEditOpen] = useState(false); const [deleteOpen, setDeleteOpen] = useState(false); async function doDelete() { try { await onDelete.mutateAsync(repo.name); toast.success("Repository deleted"); navigate("/"); } catch (err) { toast.error( ApiError.isApiError(err) ? err.display() : "Failed to delete repository", ); } } return (
Details {canManage ? ( ) : null}
Description {repo.description || "—"}
{canManage ? ( Danger zone

Deleting this repository removes all its distributions, packages, and members. This cannot be undone.

) : null}
); } function Row({ label, value, mono }: { label: string; value: string; mono?: boolean }) { return (
{label}
{value} {mono ? : null}
); } function EditDialog({ open, onOpenChange, }: { open: boolean; onOpenChange: (o: boolean) => void; }) { const { repo } = useRepoContext(); const update = useUpdateRepository(repo.name); const navigate = useNavigate(); const [name, setName] = useState(repo.name); const [visibility, setVisibility] = useState(repo.visibility); const [description, setDescription] = useState(repo.description); useEffect(() => { if (open) { setName(repo.name); setVisibility(repo.visibility); setDescription(repo.description); } }, [open, repo]); async function onSubmit(e: React.FormEvent) { e.preventDefault(); try { const updated = await update.mutateAsync({ name: name !== repo.name ? name : undefined, visibility: visibility !== repo.visibility ? visibility : undefined, description: description !== repo.description ? description : undefined, }); toast.success("Repository updated"); onOpenChange(false); if (updated.name && updated.name !== repo.name) { navigate(`/repos/${updated.name}`); } } catch (err) { toast.error( ApiError.isApiError(err) ? err.display() : "Failed to update repository", ); } } return ( Edit repository Update repository settings.
setName(e.target.value)} autoCapitalize="none" spellCheck={false} /> {name !== repo.name ? (

Renaming changes the apt URL. Existing clients will need reconfiguration.

) : null}
setDescription(e.target.value)} maxLength={280} />
); }