"use client"; import { useState } from "react"; import { IconGitCommit, IconLoader2, IconCheck } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogClose, } from "@kandev/ui/dialog"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@kandev/ui/alert-dialog"; import { Label } from "@kandev/ui/label"; import { Input } from "@kandev/ui/input"; import { Textarea } from "@kandev/ui/textarea"; import { RadioGroup, RadioGroupItem } from "@kandev/ui/radio-group"; // --- Discard Confirmation Dialog --- type DiscardDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; fileToDiscard: string | null; onConfirm: () => void; }; export function DiscardDialog({ open, onOpenChange, fileToDiscard, onConfirm, }: DiscardDialogProps) { return ( Discard changes? This will permanently discard all changes to{" "} {fileToDiscard}. This action cannot be undone. Cancel Discard ); } // --- Amend Commit Message Dialog --- type AmendDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; amendMessage: string; onAmendMessageChange: (value: string) => void; onAmend: () => void; isLoading: boolean; }; export function AmendDialog({ open, onOpenChange, amendMessage, onAmendMessageChange, onAmend, isLoading, }: AmendDialogProps) { return ( Amend Commit Message Edit the message for the most recent commit. onAmendMessageChange(e.target.value)} rows={4} className="resize-none" autoFocus /> Cancel {isLoading ? ( <> Amending... > ) : ( <> Amend > )} ); } // --- Reset to Commit Dialog --- type ResetDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; commitSha: string | null; onReset: (mode: "soft" | "hard") => void; isLoading: boolean; }; export function ResetDialog({ open, onOpenChange, commitSha, onReset, isLoading, }: ResetDialogProps) { const shortSha = commitSha?.slice(0, 7) ?? ""; const [mode, setMode] = useState<"soft" | "hard">("soft"); const [confirmation, setConfirmation] = useState(""); const isHardResetConfirmed = mode === "hard" && confirmation === shortSha; const canReset = !!commitSha && (mode === "soft" || isHardResetConfirmed); const handleOpenChange = (newOpen: boolean) => { if (!newOpen) { // Reset state when closing setMode("soft"); setConfirmation(""); } onOpenChange(newOpen); }; const handleReset = () => { if (canReset) { onReset(mode); } }; return ( Reset to commit {shortSha} setMode(v as "soft" | "hard")} className="space-y-3" > Soft Reset Move HEAD to this commit. Keep all changes staged. Hard Reset Discard all changes permanently. This cannot be undone. {mode === "hard" && ( Type {shortSha} to confirm: setConfirmation(e.target.value)} placeholder={shortSha} className="font-mono h-8 text-sm" autoComplete="off" /> )} Cancel {isLoading ? ( <> Resetting... > ) : ( <>Reset> )} ); }
Edit the message for the most recent commit.
Move HEAD to this commit. Keep all changes staged.
Discard all changes permanently. This cannot be undone.
Type {shortSha} to confirm:
{shortSha}