/** * @file RewriteDone.tsx * @description What a finished rebase / interactive rebase / reset leaves on * screen: the result, a force-push reminder when the rewrite touched pushed * commits, and the recovery button — **Undo** = `undo-rewrite` (`reset --keep` * back to the recorded `before`), which the server runs only while HEAD is * still the `after` this dialog saw (409 ESTALE otherwise). * @author Nguyễn Ngọc Trí Vĩ */ import { useState } from "react"; import { useTranslation } from "react-i18next"; import { CheckCircle2, Undo2 } from "lucide-react"; import type { GitTarget } from "../../../lib/api"; import { errText, gitRewrite, type RewriteResult } from "../../../lib/gitRewrite"; import { toast } from "../../../lib/toast"; import { useArmed } from "../../../hooks/useArmed"; import { BTN, ErrorLine, Warn } from "./GitModal"; export function RewriteDone({ target, result, onChanged, onUndone, }: { target: GitTarget; result: RewriteResult; onChanged: () => void; onUndone: () => void; }) { const { t } = useTranslation(["gitTools"]); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const { isArmed, arm, disarm } = useArmed(); const canUndo = !!result.before && !!result.after && result.before !== result.after; const undo = async () => { if (!isArmed("undo")) return arm("undo"); disarm(); setBusy(true); setError(null); try { await gitRewrite.run(target, "undo-rewrite", { to: result.before, head: result.after, confirm: true, }); toast.success(t("undone")); onChanged(); onUndone(); } catch (e) { setError(errText(e)); } finally { setBusy(false); } }; return (

{t("doneTitle")}

{result.output && (
          {result.output}
        
)} {result.needsForcePush && {t("needsForcePushAfter")}} {canUndo && (
{t("undoHint", { sha: result.before!.slice(0, 7) })}
)}
); }