import { Banner, Button, cn } from "@refs/design-system"; import { CheckCircleIcon, GitMergeIcon, InfoIcon, WarningCircleIcon } from "@refs/design-system/icons"; import type { Mergeability } from "@refs/backend/contract"; import { useState } from "react"; import { useFetcher } from "react-router"; function Status({ icon, tone, title, children }: { icon: React.ReactNode; tone: string; title: string; children?: React.ReactNode }) { return (
{icon}
{title} {children && {children}}
); } /** * The merge state of a pull request: clean, conflicts, unavailable or merged (`mergeability` is null). For people who * may merge, a clean state shows the one primary action. Posts `merge` to the current route. */ export function MergeBox({ mergeability, base, head, canMerge }: { mergeability: Mergeability | null; base: string; head: string; canMerge: boolean }) { const fetcher = useFetcher<{ intent: string; error: string | null }>(); const [confirming, setConfirming] = useState(false); const merging = fetcher.state !== "idle"; const panel = "flex min-w-0 flex-col gap-3 rounded-panel bg-panel p-4 shadow-card sm:flex-row sm:items-center sm:justify-between"; if (!mergeability) return (
} tone="text-success" title="Merged"> {head} is part of {base}.
); return (
{mergeability.state === "clean" ? ( <> } tone="text-success" title={`No conflicts with ${base}`}> Merging adds a merge commit to {base}. {canMerge ? ( {confirming ? ( <> ) : ( )} ) : ( Only people with write access can merge. )} ) : mergeability.state === "conflicts" ? ( } tone="text-caution" title={`${mergeability.paths.length === 1 ? "A file conflicts" : `${mergeability.paths.length} files conflict`} with ${base}`}> Merge {base} into {head} locally and push to resolve. Both sides changed {mergeability.paths.slice(0, 8).join(", ")} {mergeability.paths.length > 8 ? ` and ${mergeability.paths.length - 8} more` : ""}. ) : ( } tone="text-muted" title="Merge state unavailable"> {mergeability.reason} )}
{fetcher.data?.intent === "merge" && fetcher.data.error && }
); }