import React, { useContext, useState } from 'react'; import { FormSpy } from '@data-driven-forms/react-form-renderer'; import WizardContext from '@data-driven-forms/react-form-renderer/wizard-context'; import { Button } from '@patternfly/react-core'; import PropTypes from 'prop-types'; const CustomButtons = ({ buttonLabels: { cancel, next, submit, back }, handleNext, handlePrev, nextStep, }) => { const [isSaving, setIsSaving] = useState(false); const { currentStep, formOptions } = useContext(WizardContext); const onNextOrSubmit = () => { if (currentStep.id === 'wizard-review') { formOptions.onSubmit({ values: formOptions.getState().values, setIsSaving, }); } else { if (typeof nextStep === 'function') { handleNext(nextStep({ values: formOptions.getState().values })); } else { handleNext(nextStep); } } }; return ( {() => (
)}
); }; CustomButtons.propTypes = { buttonLabels: PropTypes.shape({ cancel: PropTypes.node, submit: PropTypes.node, back: PropTypes.node, next: PropTypes.node, }), handleNext: PropTypes.func, handlePrev: PropTypes.func, nextStep: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), isSaving: PropTypes.bool, }; export default CustomButtons;