diff --git a/forms-flow-components/src/components/CustomComponents/HistoryModal.tsx b/forms-flow-components/src/components/CustomComponents/HistoryModal.tsx index 8b231529..9690cf55 100644 --- a/forms-flow-components/src/components/CustomComponents/HistoryModal.tsx +++ b/forms-flow-components/src/components/CustomComponents/HistoryModal.tsx @@ -3,6 +3,7 @@ import { useState, useRef, useEffect } from "react"; import Modal from "react-bootstrap/Modal"; import { CustomButton } from "./Button"; import { CloseIcon } from "../SvgIcons/index"; +import { ConfirmModal } from "./ConfirmModal"; interface HistoryModalProps { show: boolean; @@ -34,6 +35,8 @@ interface AllHistory { version: string; isMajor: boolean; processType?: string; + publishedOn?: string; + id?:string; } const formatDate = (dateString: string) => { @@ -73,25 +76,34 @@ export const HistoryModal: React.FC = React.memo( const [showConfirmModal, setShowConfirmModal] = useState(false); const [selectedVersion, setSelectedVersion] = useState(null); const [clonedFormId, setClonedFormId] = useState(null); + const [processId, setProcessId] = useState(null); const [hasLoadedMoreForm, setHasLoadedMoreForm] = useState(false); const [hasLoadedMoreWorkflow, setHasLoadedMoreWorkflow] = useState(false); const timelineRef = useRef(null); const loadMoreRef = useRef(null); const lastEntryRef = useRef(null); - const handleRevertClick = (version: string, cloned_form_id: string) => { + const handleRevertClick = (version: string, cloned_form_id: string, process_id: string) => { setSelectedVersion(version); setClonedFormId(cloned_form_id); + setProcessId(process_id); setShowConfirmModal(true); onClose(); }; + + const handleClose = () => { + onClose(); + setHasLoadedMoreForm(false); + setHasLoadedMoreWorkflow(false); + }; const handleKeepLayout = () => { setShowConfirmModal(false); }; const handleReplaceLayout = () => { - revertBtnAction(clonedFormId); + const idToRevert = categoryType === "FORM" ? clonedFormId : processId; + revertBtnAction(idToRevert); setShowConfirmModal(false); setHasLoadedMoreForm(false); setHasLoadedMoreWorkflow(false); @@ -150,6 +162,8 @@ export const HistoryModal: React.FC = React.memo( const version = `${entry.majorVersion}.${entry.minorVersion}`; const cloned_form_id = categoryType === "FORM" ? entry.changeLog.cloned_form_id : null; + const process_id = + categoryType === "WORKFLOW" ? entry.id : null; const isLastEntry = index === allHistory.length - 1; return ( @@ -173,7 +187,7 @@ export const HistoryModal: React.FC = React.memo(
Published On
-
{formatDate(entry.created)}
+
{formatDate(entry.publishedOn)}
{categoryType === "WORKFLOW" && (
@@ -186,7 +200,7 @@ export const HistoryModal: React.FC = React.memo( variant="secondary" size="sm" label={revertBtnText} - onClick={() => handleRevertClick(version, cloned_form_id)} + onClick={() => handleRevertClick(version, cloned_form_id, process_id)} dataTestid={revertBtndataTestid} ariaLabel={revertBtnariaLabel} /> @@ -213,7 +227,7 @@ export const HistoryModal: React.FC = React.memo(
Published On
-
{formatDate(entry.created)}
+
{formatDate(entry.publishedOn)}
{categoryType === "WORKFLOW" && (
@@ -226,7 +240,7 @@ export const HistoryModal: React.FC = React.memo( variant="secondary" size="sm" label={revertBtnText} - onClick={() => handleRevertClick(version, cloned_form_id)} + onClick={() => handleRevertClick(version, cloned_form_id, process_id)} dataTestid={revertBtndataTestid} ariaLabel={revertBtnariaLabel} /> @@ -241,7 +255,7 @@ export const HistoryModal: React.FC = React.memo( <> = React.memo( {title}
- +
@@ -298,43 +312,16 @@ export const HistoryModal: React.FC = React.memo(
{/* Confirmation Modal */} - {selectedVersion && ( - setShowConfirmModal(false)} - dialogClassName="modal-50w" - data-testid="history-revert-modal" - > - - - Use Layout from Version {selectedVersion} - - setShowConfirmModal(false)} /> - - - This will copy the layout from Version {selectedVersion}{" "} - overwriting your existing layout. - - - - - - - )} + {selectedVersion && ( setShowConfirmModal(false)} + primaryBtnText="Keep Current Layout" + secondaryBtnText="Replace Current Layout" + secondayBtnAction={handleReplaceLayout} + />)} ); }