diff --git a/src/Components/CreateImageWizard/CreateImageWizard.tsx b/src/Components/CreateImageWizard/CreateImageWizard.tsx index 1f69d46318..cd822afb11 100644 --- a/src/Components/CreateImageWizard/CreateImageWizard.tsx +++ b/src/Components/CreateImageWizard/CreateImageWizard.tsx @@ -29,6 +29,7 @@ import Azure from './steps/TargetEnvironment/Azure'; import Gcp from './steps/TargetEnvironment/Gcp'; import { useFilesystemValidation, + useSnapshotValidation, useFirstBootValidation, useDetailsValidation, } from './utilities/useValidation'; @@ -62,8 +63,6 @@ import { selectImageTypes, selectRegistrationType, addImageType, - selectSnapshotDate, - selectUseLatest, } from '../../store/wizardSlice'; import { resolveRelPath } from '../../Utilities/path'; import { ImageBuilderHeader } from '../sharedComponents/ImageBuilderHeader'; @@ -180,13 +179,9 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => { const registrationType = useAppSelector(selectRegistrationType); const activationKey = useAppSelector(selectActivationKey); - const snapshotDate = useAppSelector(selectSnapshotDate); - const useLatest = useAppSelector(selectUseLatest); - - const snapshotStepRequiresChoice = !useLatest && !snapshotDate; - const [filesystemPristine, setFilesystemPristine] = useState(true); const fileSystemValidation = useFilesystemValidation(); + const snapshotValidation = useSnapshotValidation(); const firstBootValidation = useFirstBootValidation(); const detailsValidation = useDetailsValidation(); @@ -367,13 +362,15 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => { id="step-content" steps={[ } > @@ -383,7 +380,7 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => { name="Custom repositories" id="wizard-custom-repositories" key="wizard-custom-repositories" - isDisabled={snapshotStepRequiresChoice} + isDisabled={snapshotValidation.disabledNext} footer={} > @@ -392,7 +389,7 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => { name="Additional packages" id="wizard-additional-packages" key="wizard-additional-packages" - isDisabled={snapshotStepRequiresChoice} + isDisabled={snapshotValidation.disabledNext} footer={} > @@ -417,7 +414,6 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => { { } > {/* Intentional prop drilling for simplicity - To be removed */} diff --git a/src/Components/CreateImageWizard/steps/Snapshot/Snapshot.tsx b/src/Components/CreateImageWizard/steps/Snapshot/Snapshot.tsx index 2800cdb8f2..5d840c9f52 100644 --- a/src/Components/CreateImageWizard/steps/Snapshot/Snapshot.tsx +++ b/src/Components/CreateImageWizard/steps/Snapshot/Snapshot.tsx @@ -22,15 +22,7 @@ import { dateToMMDDYYYY, parseMMDDYYYYtoDate, } from '../../../../Utilities/time'; - -const dateValidators = [ - (date: Date) => { - if (date.getTime() > Date.now()) { - return 'Cannot set a date in the future'; - } - return ''; - }, -]; +import { isSnapshotDateValid } from '../../validators'; export default function Snapshot() { const dispatch = useAppDispatch(); @@ -89,7 +81,14 @@ export default function Snapshot() { placeholder="MM/DD/YYYY" dateParse={parseMMDDYYYYtoDate} dateFormat={dateToMMDDYYYY} - validators={dateValidators} + validators={[ + (date: Date) => { + if (!isSnapshotDateValid(date)) { + return 'Cannot set a date in the future'; + } + return ''; + } + ]} onChange={(_, val) => dispatch(changeSnapshotDate(val))} />