import { useState } from "react"; import { LuHistory } from "react-icons/lu"; import { errorMessage } from "../../api/client.js"; import { useRevertWorkflowRevision } from "../../api/hooks.js"; import { formatTime } from "../../lib/format"; import { useNotifications } from "../../notifications.jsx"; import { ConfirmDialog } from "../ConfirmDialog.jsx"; import { SaveWorkflowWarningsDialog, isSaveWarningsError, saveWarningsFromError, } from "./SaveWorkflowWarningsDialog.jsx"; export function WorkflowRevisionBanner({ owner, file, revision, createdAt, onBackToCurrent, onReverted, }) { const { notify } = useNotifications(); const revert = useRevertWorkflowRevision(); const [confirmOpen, setConfirmOpen] = useState(false); const [warnings, setWarnings] = useState(null); function doRevert(saveAnyway = false) { revert.mutate( { owner, file, revision, saveAnyway }, { onSuccess: (data) => { setWarnings(null); setConfirmOpen(false); notify.success(`Restored revision #${revision}`); onReverted?.(data); }, onError: (err) => { if (isSaveWarningsError(err)) { setWarnings({ items: saveWarningsFromError(err) }); return; } notify.error(errorMessage(err)); }, }, ); } return ( <>