import React, { useEffect, useState } from 'react'; import { Button, Dropdown, Flex, MenuToggle, useWizardContext, WizardFooterWrapper, } from '@patternfly/react-core'; import { MenuToggleElement } from '@patternfly/react-core/dist/esm/components/MenuToggle/MenuToggle'; import useChrome from '@redhat-cloud-services/frontend-components/useChrome'; import { useStore } from 'react-redux'; import { useNavigate, useParams } from 'react-router-dom'; import { CreateSaveAndBuildBtn, CreateSaveButton } from './CreateDropdown'; import { EditSaveAndBuildBtn, EditSaveButton } from './EditDropdown'; import { useCreateBPWithNotification as useCreateBlueprintMutation, useGetUser, useUpdateBPWithNotification as useUpdateBlueprintMutation, } from '../../../../../Hooks'; import { resolveRelPath } from '../../../../../Utilities/path'; import { mapRequestFromState } from '../../../utilities/requestMapper'; import { useIsBlueprintValid } from '../../../utilities/useValidation'; const ReviewWizardFooter = () => { const { goToPrevStep, close } = useWizardContext(); const { isSuccess: isCreateSuccess, reset: resetCreate } = useCreateBlueprintMutation({ fixedCacheKey: 'createBlueprintKey' }); // initialize the server store with the data from RTK query const { isSuccess: isUpdateSuccess, reset: resetUpdate } = useUpdateBlueprintMutation({ fixedCacheKey: 'updateBlueprintKey' }); const { auth } = useChrome(); const { orgId } = useGetUser(auth); const { composeId } = useParams(); const [isOpen, setIsOpen] = useState(false); const store = useStore(); const onToggleClick = () => { setIsOpen(!isOpen); }; const navigate = useNavigate(); const isValid = useIsBlueprintValid(); useEffect(() => { if (isUpdateSuccess || isCreateSuccess) { resetCreate(); resetUpdate(); navigate(resolveRelPath('')); } }, [isUpdateSuccess, isCreateSuccess, resetCreate, resetUpdate, navigate]); const getBlueprintPayload = async () => { if (!process.env.IS_ON_PREMISE) { const requestBody = orgId && mapRequestFromState(store, orgId); return requestBody; } // NOTE: This is fine for on prem because we save the org id // to state through a form field in the registration step return mapRequestFromState(store, ''); }; return ( setIsOpen(isOpen)} toggle={(toggleRef: React.Ref) => ( , ] : [ , ] } /> )} shouldFocusToggleOnSelect > {composeId ? ( ) : ( )} ); }; export default ReviewWizardFooter;