137 lines · 5.0 KB
import { useState } from "react";
import { mergePull, recheckMergeability, updatePull } from "~/fns/pulls";
import { useAction } from "~/hooks/use-action";
import { StatusList } from "./StatusList";
import { Badge, Panel, StatusDot } from "./ui/Primitives";
import { Button } from "./ui/Button";
import { CheckboxField, ErrorBanner, SelectField, TextAreaField } from "./ui/Field";
import type { usePull } from "~/hooks/use-pull";

type PullData = ReturnType<typeof usePull>;

const METHODS = [
  { value: "merge", label: "Create a merge commit" },
  { value: "squash", label: "Squash and merge" },
  { value: "rebase", label: "Rebase and merge" },
] as const;

export function MergeBox({ owner, repo, data }: { owner: string; repo: string; data: PullData }) {
  const { pull, gate, checks, checksState } = data;
  const [method, setMethod] = useState<(typeof METHODS)[number]["value"]>("merge");
  const merge = useAction(mergePull);
  const recheck = useAction(recheckMergeability);
  const ready = useAction(updatePull);
  const number = pull.number;

  if (pull.merged) {
    return (
      <Panel>
        <div className="flex items-center gap-3 p-4 text-sm">
          <Badge tone="purple">Merged</Badge>
          <span className="text-gray-300">
            {pull.mergedBy?.name ?? "Someone"} merged commit{" "}
            <code className="font-mono text-accent-300">{pull.mergeCommitSha?.slice(0, 7)}</code> into {pull.baseRef}.
          </span>
        </div>
      </Panel>
    );
  }
  if (data.conversation.issue.state === "closed") return null;